centos7安装mysql5.7操作步骤
下载mysql的repo源
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
安装源
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
安装数据库
yum install mysql-server
启动数据库
systemctl start mysqld
登录到mysql
-
5.7版本默认对于root帐号有一个随机密码,可以通过
grep "password" /var/log/mysqld.log获得,root@localhost: 此处为随机密码 -
运行mysql -uroot -p 回车
-
粘贴随机密码
-
修改密码
-
重启
Open & Edit /etc/my.cnf or /etc/mysql/my.cnf, depending on your distro.
Add skip-grant-tablesunder [mysqld]
Restart Mysql
service mysqld restart
You should be able to login to mysql now using the below command mysql -u root -p
Run mysql>flush privileges;
Set new password by ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Go back to /etc/my.cnf and remove/comment skip-grant-tables
Restart Mysql
service mysqld restart
Now you will be able to login with the new password mysql -u root -p
操作
- 默认的随机密码是没办法直接对数据库做操作的,需要修改密码,然后,5.7版本用了validate_password密码加强插件,因此在修改密码的时候绝对不是 123456 能糊弄过去的。需要严格按照规范去设置密码
- 但是,如果想让密码简单点也可以,降低安全策略, 登录到mysql客户端执行如下两条命令
set global validate_password_length=1;
set global validate_password_policy=0;
- 这样就能设置简单的密码了,但是密码长度必须是大于等于4位
赋权操作
默认情况下其他服务器的客户端不能直接访问mysql服务端,需要对ip授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
FLUSH PRIVILEGES;
本文介绍CentOS7安装MySQL5.7的操作步骤,包括下载repo源、安装源、数据库,启动数据库等。还提及登录MySQL,修改密码,因5.7版本有密码加强插件,可降低安全策略设简单密码。此外,说明了默认随机密码无法操作数据库,以及对IP进行赋权操作。

被折叠的 条评论
为什么被折叠?



