Centos 安装 mysql

安装 Mysql

在一个文件夹中下载 rpm

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

安装 yum 源

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

更新 yum 源

1
2
yum clean all
yum makecache

开始安装 MySQL

1
yum install mysql-community-server

启动 MySQL

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

登录以及初始化配置

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

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

登录 MySQL 修改 mysql 用户密码

1
mysql -u root -p

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

改成下面的形式

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)

远程设置

1
2
3
4
5
6
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;

Centos 安装 mysql
https://bubao.github.io/posts/7fb62aef.html
作者
一念
发布于
2020年3月4日
许可协议