1.下载并安装MySQL官方的Yum Repository
wget http://repo.mysql.com/mysql-community-release-el7-9.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-9.noarch.rpm
yum update
2.卸载Mariadb
列出所有被安装的rpm package
rpm -qa | grep mariadb
如果没有就无需卸载。
3.安装Mysql
sudo yum install mysql-server
4.启动Mysql
systemctl start mysqld.service
5.获取root用户的初始密码
grep "password" /var/log/mysqld.log
6.设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
出错,错误信息如下
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
关闭Mysql密码校验
Policy | Tests Performed |
---|---|
0 or LOW | Length |
1 or MEDIUM | Length; numeric, lowercase/uppercase, and special characters |
2 or STRONG | Length; numeric, lowercase/uppercase, and special characters; dictionary file |
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
有时候,只是为了自己测试,不想密码设置得那么复杂,譬如说,我只想设置root的密码为123456。
必须修改两个全局参数:
首先,修改validate_password_policy参数的值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
这样,判断密码的标准就基于密码的长度了。这个由validate_password_length参数来决定。
修改参数前先重置密码,必须和大于等于默认长度
mysql> SET PASSWORD = PASSWORD('12345678');
查看validate_password_length参数
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
validate_password_length参数默认为8,它有最小值的限制,最小值为:
validate_password_number_count
+ validate_password_special_char_count
+ (2 * validate_password_mixed_case_count)
其中,validate_password_number_count指定了密码中数据的长度,validate_password_special_char_count指定了密码中特殊字符的长度,validate_password_mixed_case_count指定了密码中大小字母的长度。
这些参数,默认值均为1,所以validate_password_length最小值为4,如果你显性指定validate_password_length的值小于4,尽管不会报错,但validate_password_length的值将设为4。如下所示:
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)
重新设置密码
mysql> SET PASSWORD = PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
7.Mysql无法远程连接
出错:1130-host . is not allowed to connect to this MySql server,MySQL
mysql> select host from user where user='root';
+-----------+
| host |
+-----------+
| localhost |
+-----------+
1 row in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select host,user from user;
+-----------+-----------+
| host | user |
+-----------+-----------+
| % | root |
| localhost | mysql.sys |
+-----------+-----------+
2 rows in set (0.00 sec)