安装 Mysql

在一个文件夹中下载 rpm

cd /usr/src
wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

安装 yum 源

yum localinstall mysql80-community-release-el7-1.noarch.rpm

更新 yum 源

yum clean all
yum makecache

开始安装 MySQL

yum install mysql-community-server

启动 MySQL

systemctl enable mysqld # 开机自启
systemctl start mysqld # 启动

登录以及初始化配置

启动成功后可以查看初始化密码随机生成的

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

登录 MySQL 修改 mysql 用户密码

mysql -u root -p

这里应该会出现报错
Your password does not satisfy the current policy requirements
mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘yourpassword’;

改成下面的形式

先把密码改成有大写字母,数字,小写字母和符号的密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'X2x.123456';
Query OK, 0 rows affected (0.02 sec)
# 查看密码策略
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.01 sec)
# 百度的错误方法
# mysql> set global validate_password_policy=LOW;
# ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
# 将策略改成低
mysql> set global validate_password.policy=LOW;
Query OK, 0 rows affected (0.00 sec)
# 把密码改成之前想要的
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.02 sec)

远程设置

mysql> use mysql;
mysql> update user set host='%' where user='root';
# 授权用户名的权限,赋予任何主机访问数据的权限
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';
mysql> FLUSH PRIVILEGES;

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!

Centos 安装 redis 上一篇
TODO 下一篇