一、校验安装历史
1、查看是否已安装mysql
rpm -qa | grep mysql
2、 如果已安装,则删除
rpm -e --nodeps mysql-community-release-el7-7.noarch
二、下载并安装Mysql
1、下载8.0版本的mysql
wget http://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm
2、安装rpm包
rpm -ivh mysql80-community-release-el7-7.noarch.rpm
3、更新插件版本
yum -y update
4、安装mysql服务端
yum -y install mysql-server
5、 配置权限
chown -R mysql:mysql /var/lib/mysql/
6、初始化mysql
mysqld --initialize
7、启动mysql
systemctl start mysqld
8、查看mysql状态
systemctl status mysqld
注:mysql会自动生成一个默认密码在日志文件中
#查看mysql日志:cat /var/log/mysqld.log
[Server] A temporary password is generated for root@localhost: B>iCWF#Ff5Vl
9、Mysql升级问题
mysql5.7升级到8.0如果报错
2023-03-09T00:43:22.731223Z 1 [ERROR] [MY-013856] [InnoDB] The redo log file ./ib_logfile0 is empty, which indicates it was not generated by InnoDB or become corrupted. Please restore the correct file or try recovering without the redo files, in read-only mode, by providing --innodb-force-recovery=6.
2023-03-09T00:43:22.731284Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Generic error.
2023-03-09T00:43:23.170973Z 1 [ERROR] [MY-011013] [Server] Failed to initialize DD Storage Engine.
2023-03-09T00:43:23.171331Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2023-03-09T00:43:23.171370Z 0 [ERROR] [MY-010119] [Server] Aborting
解决方式:
执行命令:rm -rf /var/lib/mysql,再重启mysql服务可完成:systemctl start mysql
三、修改密码
1、进入mysql内部
mysql -uroot -p
2、查询root账户的host
use mysql;
select user,host from user;
3、修改密码
host为步骤二查询出来的root账户的host
alter user 'root'@'host' identified with mysql_native_password by '新密码';
4、刷新内存
flush privileges;
5、重启mysql
systemctl restart mysql;
四、Navicat连接
修改root账户的host为‘%’即可。
update user set host = '%' where user = 'root';
如果navicat还连接不上,则进入mysql的配置文件进行修改,将bind_address = 127.0.0.1注掉或删除,重启mysql服务(systemctl restart mysql)
vim /etc/mysql/mysql.conf.d/mysqld.cnf
五、开放防火墙端口
#查看是否开启端口
firewall-cmd --list-all
#开启端口3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
#重新加载防火墙
firewall-cmd --reload