Centos安装mysql8.0和配置
一、准备安装包
有两种方式
1.光盘拷贝出来mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar
2.从官网下载。
下载mysql官网地址:https://dev.mysql.com/downloads/file/?id=484537.点击页面底部No thanks, just start my download.开始下载。
二、安装
1.解压tar包
tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar
2.rpm安装,顺序如下:
rpm -ivh mysql-community-common-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.12-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.12-1.el7.x86_64.rpm
一定要按照这个顺序,否则会提示报错,缺少上一步的依赖
注意:安装libs时可能会提示如图
需要移除之前安装过的依赖之后,再次安装
yum remove mysql-libs
3.启动mysql8
systemctl start mysqld.service
4.获取默认密码
cat /var/log/mysqld.log | grep password
5.登录数据库进行配置
修改权限
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0
修改密码并设置密码验证方式,否则客户端无法连接
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'XXXXXX';
如果使用默认密码方式,可能会报如下错误
注意:mysql8密码不允许太简单,否则提示
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
6.打开防火墙3306端口
查看当前防火墙开放端口:firewall-cmd --zone=public --list-ports
开启3306端口:firewall-cmd --zone=public --add-port=3306/tcp --permanent
重新加载防火墙:firewall-cmd --reload