时间:2021-07-01 10:21:17 帮助过:15人阅读
环境为最小化安装
初始化环境 yum install -y vim net-tools wget tree lrzsz
关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
关闭selinux
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config
1 安装5.6
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install -y mysql mysql-server
systemctl start mysqld.service
systemctl enable mysqld.service
查找默认密码: W&.?r1P5cTiZ
grep password /var/log/mysqld.log
2021-06-28T09:09:41.827898Z 1 [Note] A temporary password is generated for root@localhost: W&.?r1P5cTiZ
#特殊符号转义
mysql -uroot -pW\&\.\?r1P5cTiZ
修改密码
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Mysql&123‘;
2 安装5.7
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
rpm -ivh mysql57-community-release-el7-10.noarch.rpm
yum install -y mysql mysql-server
systemctl start mysqld.service
systemctl enable mysqld.service
查找默认密码: W&.?r1P5cTiZ
grep password /var/log/mysqld.log
2021-06-28T09:09:41.827898Z 1 [Note] A temporary password is generated for root@localhost: W&.?r1P5cTiZ
#特殊符号转义
mysql -uroot -pW\&\.\?r1P5cTiZ
修改密码
ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘Mysql&123‘;
小知识
设置简单密码
如下命令进入数据库:
[root@localhost ~]# mysql -uroot -p
输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库:
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘new password‘;
这里有个问题,新密码设置的时候如果设置的过于简单会报错:
原因是因为MySQL有密码设置的规范,具体是与validate_password_policy的值有关:
MySQL完整的初始密码规则可以通过如下命令查看:
mysql> SHOW VARIABLES LIKE ‘validate_password%‘;
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 4 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
7 rows in set (0.01 sec)
密码的长度是由validate_password_length决定的,而validate_password_length的计算公式是:
validate_password_length = validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
我的是已经修改过的,初始情况下第一个的值是ON,validate_password_length是8。可以通过如下命令修改:
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
centos 7 yum 安装mysql 5.6或 5.7
标签:特殊符号 命令 rate 原因 install 关闭 spec comm 关闭selinux