- cd /usr/local/
- mkdir mysql
- cd mysql
- 获取MySQL8.0
- 把下载的MySQL8.0上传至/usr/local/mysql
- 第一次解压 xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
- 第二次解压tar xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar
- 重命名MySQL目录mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql8.0
- cd mysql8.0
- mkdir data
- 创建用户组以及用户和密码
- groupadd mysql
- useradd -g mysql mysql
- 赋予权限chown -R mysql.mysql /usr/local/mysql/mysql8.0/
- 初始化信息./mysqld --user=mysql --basedir=/usr/local/mysql/mysql8.0 --datadir=/usr/local/mysql/mysql8.0/data/ --initialize
2021-12-21T20:43:19.253428Z 0 [System] [MY-013169] [Server] /usr/local/mysql/mysql8.0/bin/mysqld (mysqld 8.0.20) initializing of server in progress as process 5416 2021-12-21T20:43:19.271054Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-12-21T20:43:19.883567Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2021-12-21T20:43:20.817117Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: jbhQtj3Zer=p
- 14中root@localhost: 后面的是临时密码,复制粘贴出来有用
- vi /etc/my.cnf
# # This group is read both both by the client and the server # use it for options that affect everything # #[client-server] # # include all files from the config directory # !includedir /etc/my.cnf.d [mysqld] basedir=/usr/local/mysql/mysql8.0/ datadir=/usr/local/mysql/mysql8.0/data/ socket=/tmp/mysql.sock character-set-server=UTF8MB4
- 添加mysqld服务到系统
cd ..
cp -a ./support-files/mysql.server /etc/init.d/mysql -
授权以及添加服务
chmod +x /etc/init.d/mysql
chkconfig --add mysq
-
启动MySQL systemctl start mysql 并查看状态 systemctl status mysql
-
将mysql命令添加到服务 ln -s /usr/local/mysql-8.0/bin/mysql /usr/bin
-
使用刚才复制粘贴的密码进行登录 mysql -uroot -p,但此时出现了报错显示缺少库
mysql -uroot -p mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
-
将缺少的库(libtinfo.so.5)放入/usr/lib64/下,然后连接
-
进入MySQL后在里面执行ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql'; 其中mysql是你的新密码
-
在MySQL中执行使其密码生效 flush privileges;
-
修改数据库使你能在其他地方连接数据库
use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set host='%' where user='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select host,user from user; +-----------+------------------+ | host | user | +-----------+------------------+ | % | root | | localhost | mysql.infoschema | | localhost | mysql.session | | localhost | mysql.sys | +-----------+------------------+ 4 rows in set (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
-
至此centos8.0安装MySQL8.0结束
centos8.0安装MySQL8.0
最新推荐文章于 2024-05-21 23:57:18 发布