yum安装mysql
一、配置Mysql扩展源
rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
二、yum安装mysql
yum install mysql-community-server -y
三、启动Mysql,并加入开机自启
systemctl start mysqld
systemctl enable mysqld
四、使用Mysq初始密码登录数据库
mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
五、修改数据库密码
数据库默认密码规则必须携带大小写字母、特殊符号,字符长度大于8否则会报错。
查看密码规则
show variables like 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| 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 |
+--------------------------------------+--------+
参数解释
validate_password_dictionary_file
插件用于验证密码强度的字典文件路径。
validate_password_length
密码最小长度,参数默认为8,它有最小值的限制,最小值为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
validate_password_mixed_case_count
密码至少要包含的小写字母个数和大写字母个数。
validate_password_number_count
密码至少要包含的数字个数。
validate_password_policy
密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。有以下取值:
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,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
validate_password_special_char_count
密码至少要包含的特殊字符数。
因此设定较为简单的密码时需要首先修改set global
validate_password_policy和_length参数值。
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
六、修改密码
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
开启远程访问
grant all privileges on *.* to root@'%' identified by 'password';
flush privileges;