1.配置Mysql 8.0安装源:
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
2,装Mysql 8.0:
sudo yum install mysql-server --nogpgcheck
3,下载过程中都选中:y
4.启动mysql服务
service mysqld start
5,查看运行状态:
service mysqld status
6.查看root临时密码:
grep "A temporary password" /var/log/mysqld.log
7.更改临时密码:
第一件事就是改成我自己容易记得密码啦。先用临时密码登录mysql
输入:mysql -uroot -p 复制刚才查看的密码登入即可
如果想要查看MySQL完整的初始密码规则,登陆后执行以下命令:
先修改密码:(一个满足他条件的密码)
alter user 'root'@'localhost' identified by 'MYsql123/*';
再把他的密码规则进行修改:
1-validate_password.length 是密码的最小长度,默认是8,我们把它改成4
set global validate_password.length=4;
2-validate_password.policy 验证密码的复杂程度,我们把它改成0
set global validate_password.policy=0;
3-validate_password.check_user_name 用户名检查,用户名和密码不能相同,我们也把它去掉
set global validate_password.check_user_name=off;
现在再执行修改密码的命令:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
需要进入到 mysql这个库进行修改操作
use mysql
update user set Host = '%' where Host = 'localhost' and User='root';
flush privileges
navicat连接mysql 用navicat连接mysql还是会报错:
原因是mysql8的加密方式规则不一样,是caching_sha2_password
把加密方式改成mysql_native_password就行了:
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
加密方式以及改成了mysql_native_password: (连接成功)!!!
注意:连接不成功就是你防火墙打开的,或者3306端口没打开
关闭防火墙,打开3306端口连接成功!!!
MySQL开机自启动:
systemctl enable mysqld.service
使用yum安装MySQL,如果想要完全卸载mysql,可以采用如下方式:
1.查看MySQL安装了哪些东西
rpm -qa |grep -i mysql
[root@localhost /]# rpm -qa |grep -i mysql
mysql-community-client-plugins-8.0.29-1.el7.x86_64
mysql-community-client-8.0.29-1.el7.x86_64
mysql-community-server-8.0.29-1.el7.x86_64
mysql80-community-release-el8-2.noarch
mysql-community-common-8.0.29-1.el7.x86_64
mysql-community-libs-8.0.29-1.el7.x86_64
mysql-community-icu-data-files-8.0.29-1.el7.x86_64
2.全部卸载
yum remove mysql-community-client-plugins-8.0.29-1.el7.x86_64
yum remove mysql-community-client-8.0.29-1.el7.x86_64
yum remove mysql-community-server-8.0.29-1.el7.x86_64
yum remove mysql80-community-release-el8-2.noarch
yum remove mysql-community-common-8.0.29-1.el7.x86_64
yum remove mysql-community-libs-8.0.29-1.el7.x86_64
yum remove mysql-community-icu-data-files-8.0.29-1.el7.x86_64
3.查看是否卸载完成
rpm -qa |grep -i mysql
4.查找MySQL相关目录
find / -name mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/lib64/mysql
5.删除这些目录
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
rm -rf /usr/lib64/mysql
6.删除/var/log/mysqld.log(如果不删除这个文件,会导致新安装的mysql无法生存新密码,导致无法登陆)
rm -rf /var/log/mysqld.log