安装mysql5.7


下载安装文档:

http://www.scriptjc.com/article/850

设置默认字符集为utf8:

vi /etc/my.cnf
character-set-server=utf8

安装好后启动mysql:

systemctl start mysqld

密码文件位置:

vim /var/log/mysqld.log

输入密码并登陆:

mysql -uroot -p

关闭安全策略:否者需要设置复杂的密码,根据需求来决定。

set global validate_password_policy=0;

        如果不关闭安全策略就去设置密码的话会报出如下错误:Your password does not satisfy the current policy requirements。

设置密码长度:

set global validate_password_length=6;

修改密码:

alter user 'root'@'localhost' identified by '123456';

查看密码相关设置选项:

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             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.01 sec)

开启远程登录

mysql> use mysql;
mysql> update user set host = '%' where user ='root';
mysql> flush privileges;

或者:

mysql> grant all privileges on *.*  to  'root'@'%'  identified by 'mima'  with grant option;
mysql> flush privileges;

查看建库语句:

show create database chuxiangyi;


安装mysql8.0


安装yum源:

rpm -i https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm

安装:

yum install mysql-server -y

设置默认字符集:

vi /etc/my.cnf
character-set-server=utf8

启动:

systemctl enable mysqld --now

密码:

cat /var/log/mysqld.log | grep password

登陆并改密码:

alter user 'root'@'localhost' identified by '1qaz@WSX';

远程登录:

mysql> use mysql;
mysql> update user set host = '%' where user ='root';
mysql> flush privileges;

查看密码策略:

mysql> show variables like '%validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| 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      |
+--------------------------------------+--------+
7 rows in set (0.00 sec)

设置策略:

set global validate_password.length=6;