目录
注:本文主要是看了这位大佬安装MySQL,才想着写一篇记录一下。
一、卸载mysql
(1)关闭mysql
(2)使用rpm查看已经安装的安装包
(3)移除第二步查询到的安装包
(4)继续查找,是否有剩余文件
(5)删除第四步查找到的文件
#以实际查询到的为准
rm -rf /var/lib/mysql
rm -rf /var/lib/mysql/mysql
到这里基本上卸载已经完成了,不确定可以再用上面的命令查看一下。
二、安装mysql
(1)下载MySQL的yum包
cd ~
wget http://repo.mysql.com/mysql80-community-release-el7-7.noarch.rpm
(2)安装mysql源
rpm -Uvh mysql80-community-release-el7-7.noarch.rpm
(3)安装MySQL服务端
yum -y install mysql-community-server --nogpgcheck
(4)启动MySQL
systemctl start mysqld.service
(5)查看MySQL是否启动
systemctl status mysqld.service
(6)获取临时密码(一开始MySQL给的是随机密码)
grep 'temporary password' /var/log/mysqld.log
(7)通过临时密码登录MySQL
mysql -u root -p
(8)全局修改密码规则
1:下面这是错误的哦
mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> set global validate_password_length=1;
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
正确如下:
mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;
-
分析:可以看到,修改 policy 和 length 的值,在MySQL5.7中好使,在MySQL8.0中无效。‘validate_password_policy’ 变量不存在。
-
解决:先修改一个满足规则的密码(如:Root_root123)。
(9)执行命令查看密码规则是否修改
mysql> SHOW VARIABLES LIKE 'validate_password%';
+-------------------------------------------------+--------+
| Variable_name | Value |
+-------------------------------------------------+--------+
| validate_password.changed_characters_percentage | 0 |
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+-------------------------------------------------+--------+
8 rows in set (0.13 sec)
(10)修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';