准备工作
创建目录/opt/src用来存储各种安装包
mkdir /opt/src
yum -y install lrzsz wget vim #lrzsz 用于虚拟环境上传和下载安装包,wget用于虚拟环境远程下载包,vim 个人习惯不用vi
cd /opt/src
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar
也可以用网盘 链接:https://pan.baidu.com/s/1M0g5WbZybzGIfu9OuWmbig
提取码:xin7
因centos自带mariadb,会出现占用3306端口的问题导致初始化失败,需将其卸载
rpm -qa | grep mariadb
yum -y remove mariadb*
若是用于从5版本MySQL升级至8版本的MySQL,需将原有的MySQL数据清理干净
方式如下:
rpm -qa | grep mysql
yum -y remove mysql*
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql
若是原有8版本MySQL升级,需将mysql模块禁止
开始安装MySQL8
mkdir /usr/local/mysql
cd /opt/src && tar -xf mysql-8.0.23-1.el7.x86_64.rpm-bundle.tar -C /usr/local/mysql
cd /usr/local/mysql && ll
rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm
若出现如下warning
执行 rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm -nodeps --force 即可
MySQL的安装包
rpm -qa | grep mysql
初始化MySQL和启动MySQL
mysqld --initialize;
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld.service
systemctl enable mysqld
获取MySQL初始化后的密码
cat /var/log/mysqld.log | grep password
进入MySQL数据库
mysql -urrot -p <password>
show databases;会出现报错显示未修改MySQL密码
在MySQL数据库内进行修改MySQL密码
把密码修改成root
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
exit或者\q后重新登录MySQL,进行远程登录授权
远程登录密码为root
create user 'root'@'%' identified with mysql_native_password by 'root';
对该用户授予所有权限
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
可视化工具
命令修改加密规则
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root' PASSWORD EXPIRE NEVER;
MySql8.0 版本 和 5.0 的加密规则不一样,而现在的可视化工具只支持旧的加密方式。
关闭firewalld
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
下载iptables
yum -y install iptables-services
systemctl enable iptables
systemctl start iptables
通过 vim /etc/sysconfig/iptables 命令编辑防火墙,添加端口
vim /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8090 -j ACCEPT
重启iptables服务
systemctl restart iptables.service
接着使用可视化工具进行登录
连接成功