赞
踩
下载对应版本MySQL :: Download MySQL Community Server (Archived Versions)
这里我选择的是Linux - Generic (glibc 2.12) (x86, 64-bit), TAR
解压到服务器 只需要里面的mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz
文末有新版本安装的持续更新
在目录下创建需要的文件夹
这里我改名为mysql-8.0.24
- cd /mysql-8.0.24
- mkdir data
- mkdir temp
- mkdir log
- cd /mysql-8.0.24/log
- touch error.log
-
- chown -R mysql:mysql /mysql-8.0.24
- chmod -R 750 /mysql-8.0.24
-
- cd /mysql-8.0.24
- ./bin/mysqld --initialize --console --user=mysql --basedir=/mysql-8.0.24 --datadir=/mysql-8.0.24/data
在log/error.log中找到默认密码
启动服务
- su mysql
-
- /mysql-8.0.24/bin/mysqld --defaults-file=/mysql-8.0.24/my.cnf &
使用密码登录
- cd /mysql-8.0.24
- ./bin/mysql -uroot -h 127.0.0.1 -p
-
- alter user 'root'@'localhost' identified by 'xxxx';
-
- #设置远程登录
- create user root@'%' identified by 'xxxx';
- grant all privileges on *.* to root@'%' with grant option;
- flush privileges;
补上使用的配置文件 里面的路径需要更换成实际使用的目录
- [mysql]
- #设置mysql客户端默认字符集
- default-character-set=utf8
-
- [mysqld]
- sql_mode=NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO
- user=mysql
- skip-name-resolve
-
- #设置3306端口
- port = 3306
-
- #缓存配置
- tmp_table_size=1024M
- max_heap_table_size=1024M
-
- #设置mysql的安装目录
- basedir=/mysql-8.0.24
- #设置mysql数据库的数据的存放目录 错误日志
- datadir=/mysql-8.0.24
- tmpdir=/mysql-8.0.24/temp
- pid-file=/mysql-8.0.24/mysql.pid
- log-error=/mysql-8.0.24/log/error.log
- pid-file=/mysql-8.0.24/mysql.pid
-
- #允许最大连接数
- max_connections=200
-
- #服务端使用的字符集默认为8比特编码的latin1字符集
- character-set-server=utf8
- init_connect='SET NAMES utf8'
- default_authentication_plugin=mysql_native_password
-
- #创建新表时将使用的默认存储引擎
- default-storage-engine=INNODB
-
- #此处是区分大写的,但是mysql8只有在初始化时设置lower_case_table_names=1才有效
- #lower_case_table_names=1
- max_allowed_packet=500M
-
- #取消binlog
- skip-log-bin
-
- #开启load file
- local-infile=1
- secure_file_priv=
ps 最新更新 8.0.36安装
新版初始化语句需要调整
- cd /mysql-8.0.36
- ./bin/mysqld --initialize --console --user=mysql --basedir=/your path/mysql-8.0.36 --datadir=/data
若出现 [ERROR] [MY-010338] [Server] Can't find error-message file '/mysql-8.0.36/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
则需要把文件放在指定目录
2024-04-03:新版本(8.2.0)的初始化需要指定error的路径
./bin/mysqld --initialize --console --user=mysql --basedir=/mysql-8.0.24 --datadir=/mysql-8.0.24/data --log-error=/mysql-8.0.24/log/error.log
2024-05-22:新版本(8.4.0)初始化需要拷贝一份可以使用的my.cnf到 /etc目录,并且设置[mysqld]
user=root
这里可以直接使用上面的,该文件只作为初始化处理使用,,不然会一直报错he designated data directory /xxx/data/ is unusable. 或者该data文件无权限
初始化完毕后需要重新赋予权限给data目录下的文件,新版初始化后权限不对
- chown -R mysql:mysql /mysql-8.4.0
- chmod -R 750 /mysql-8.4.0
这里没赋权时日志内报错
[ERROR] [MY-012273] [InnoDB] Can't create file './ibdata1' when --innodb-read-only is set
[Warning] [MY-012197] [InnoDB] Unable to open './data/mysql.ibd'
最后一个大坑就是data目录
上文中提到的示例my.cnf在之前的版本都是可以正常使用的,新版4.0需要将data目录写完整
- [mysqld]
- basedir=/mysql-8.4.0
- #这里需要注意,需要完整路径
- datadir=/mysql-8.4.0/data
- tmpdir=/mysql-8.4.0/temp
- pid-file=/mysql-8.4.0/mysql.pid
- log-error=/mysql-8.4.0/log/error.log
- pid-file=/mysql-8.4.0/mysql.pid
报错信息
- [ERROR] [MY-012592] [InnoDB] Operating system error number 2 in a file operation.
- [ERROR] [MY-012593] [InnoDB] The error means the system cannot find the path specified.
- [ERROR] [MY-012594] [InnoDB] If you are installing InnoDB, remember that you must create directories yourself, InnoDB does not create them.
- [ERROR] [MY-012646] [InnoDB] File ./ibdata1: 'open' returned OS error 71. Cannot continue operation
- [ERROR] [MY-012981] [InnoDB] Cannot continue operation.
命令登录时不再需要-h指定127.0.0.1来登录了,会报错无法登录去掉就可以了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。