5、安装MySql
# 在http://dev.mysql.com/downloads/repo/yum/找到对应的版本并下载
# 如:https://repo.mysql.com//mysql57-community-release-el7-10.noarch.rpm
# 安装源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
yum install mysql-community-server
systemctl start mysqld
systemctl enable mysqld
systemctl daemon-reload
grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
# 在MySql命令行下
mysql> set password for 'root'@'localhost'=password('NewPass1!');
mysql> exit
systemctl restart mysqld
# 在MySql命令行下
# 查看编码
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
# 修改/etc/my.cnf配置文件,在[mysqld]下添加编码配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
# 重启MySql,再次查看编码
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
# 在MySql命令行下
mysql> 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 |
+--------------------------------------+--------+
mysql> SET GLOBAL validate_password_length = 3;
mysql> SET GLOBAL validate_password_number_count = 0;
mysql> SET GLOBAL validate_password_mixed_case_count = 0;
mysql> SET GLOBAL validate_password_special_char_count = 0;
# 然后就可以修改简易密码了
mysql> set password for 'root'@'localhost'=password('root');
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "root";
Query OK, 0 rows affected (0.00 sec)
update user set host='%' where user ='root';
flush privileges;