查看是否安装有MySQL
[root@localhost ~]# rpm -qa | grep mysql-*
卸载mysql
[root@localhost ~]# yum -y remove mysql-*
查找之前安装文件
[root@localhost ~]# find / -name mysql
删除文件(rm -rf 目录文件)
配置文件删除
[root@localhost ~]# rm -rf /etc/my.cnf
密码配置删除
[root@localhost ~]# rm -rf /root/.mysql_sercret
1.添加Mysql 8.0安装源
[root@localhost ~]# sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
2.安装Mysql 8.0
[root@localhost ~]# sudo yum --enablerepo=mysql80-community install mysql-community-server
注意:国内镜像安装太慢可以按照以下方法做
安装清华镜像mysql release
获取版本号
[root@localhost ~]# releasever=$(cat /etc/redhat-release |awk '{print $(NF-1)}'|awk -F. '{print$1}')
安装rpm
[root@localhost ~]# yum install http://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql80-community-el${releasever}/mysql80-community-release-el${releasever}-3.noarch.rpm
备份配置
[root@localhost ~]# cp /etc/yum.repos.d/mysql-community.repo /etc/yum.repos.d/mysql-community.repo.bak
通过sed 改为清华大学软件源
[root@localhost ~]# sed -i 's#repo.mysql.com/yum#mirrors.tuna.tsinghua.edu.cn/mysql/yum#; s/mysql-\([0-9]\)\.\([0-9]\)/mysql\1\2/; s#/el/\([0-9]\)/#-el\1/#; s#$basearch/##' /etc/yum.repos.d/mysql-community.repo
3.启动Mysql 8.0
[root@localhost ~]# sudo service mysqld start
[root@localhost ~]# service mysqld status
[root@localhost ~]# grep "A temporary password" /var/log/mysqld.log
6.登录(粘贴刚才获取的临时密码)
[root@localhost ~]# mysql -u root -p
7.修改密码
修改密码策略(可忽略)
validate_password.length 是密码的最小长度,默认是8,改成6
mysql>set global validate_password.length=6;
validate_password.policy 验证密码的复杂程度,它改成0
mysql>set global validate_password.policy=0;
validate_password.check_user_name 用户名检查,用户名和密码不能相同,把它关掉
mysql>set global validate_password.check_user_name=off;
更新密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
刷新权限
mysql> flush privileges;
使用mysql数据库
mysql> use mysql;
更新root用户登录地址
mysql> update user set host='%' where user='root';
权限刷新
mysql> flush privileges;
退出
mysql> exit;
添加3306端口号
[root@localhost ~]# sudo firewall-cmd --add-port=3306/tcp --permanent
防火墙重载配置
[root@localhost ~]# sudo firewall-cmd --reload