准备安装包
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm
依次安装
yum remove mariadb
yum install net-tools
rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
# 其他依赖缺啥yum install啥
启动&开机自启
systemctl enable mysqld
systemctl start mysqld
获取随机root密码
grep password /var/log/mysqld.log
2020-02-27T04:00:21.085146Z 1 [Note] A temporary password is generated for root@localhost: 1Hm%fferpq_:
mysql -u root -p
Enter password: 1Hm%fferpq_:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.28
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
# 还无法操作
初始化
mysql> ALTER USER USER() IDENTIFIED BY '1Hm%fferpq_:';
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '112233@AbC';
Query OK, 0 rows affected (0.00 sec)
# 或者先关闭其密码策略修改
mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.01 sec)
mysql> select @@validate_password_policy;
+----------------------------+
| @@validate_password_policy |
+----------------------------+
| MEDIUM |
+----------------------------+
1 row in set (0.00 sec)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER USER() IDENTIFIED BY '12345678';
Query OK, 0 rows affected (0.00 sec)
validate_password_policy有以下取值:
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,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
-
2. 使用mysql_secure_installation
mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: 1Hm%fferpq_:
# 下略
创建用户
mysql> use mysql;
mysql> create user 'admin'@'%' identified by '12345678';
Query OK, 0 rows affected (0.00 sec)
授权
grant select ,insert,update on db1.t1 to "admin"@'%';
grant all privileges on db1.* to "admin"@'%';
grant all privileges on *.* to "admin"@'%';
取消授权
revoke all on db1.t1 from 'admin'@"%";
revoke all on db1.* from 'admin'@"%";
revoke all privileges on *.* from 'admin'@'%';
网友评论