1.选择对应的目录 我是直接在家目录下设置的
[root@xiaomu ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
如果没有wget的话,可以先执行
yum -y install wget
再执行上述的wget的指令
2.检查是否下载完毕
[root@xiaomu ~]# ls
mysql57-community-release-el7-11.noarch.rpm
3.安装MySQL安装源
[root@xiaomu ~]# yum -y localinstall mysql57-community-release-el7-11.noarch.rpm
4.安装MySQL服务【这个稍微耗时】
[root@xiaomu ~]# yum -y install mysql-community-server
5.启动服务
[root@xiaomu ~]# systemctl start mysqld
6.设置开机启动
[root@xiaomu ~]# systemctl enable mysqld
[root@xiaomu ~]# systemctl daemon-reload
7.获取登陆数据库时root用户的默认密码
mysql安装完成之后,会在/var/log/mysqld.log文件中给root生成了一个临时的默认密码
[root@xiaomu ~]# cat /var/log/mysqld.log
8.使用这个密码登陆数据库
[root@xiaomu ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.29
Copyright (c) 2000, 2020, 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>
9.修改数据库root用户对应的密码
mysql> alter user 'root'@'localhost' identified by '要设置的密码';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
注意:这个问题说的是密码策略问题: 权限过高 或者密码长度不够(默认8位)
解决方案
mysql> set global validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)
然后再执行
mysql> alter user 'root'@'localhost' identified by '要设置的密码';
Query OK, 0 rows affected (0.00 sec)
10.设置允许远程链接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你设置的密码' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
退出
mysql> exit
Bye
之后再使用新密码登陆即可