CentOS7.4安装mysql5.7

安装

添加源

rpm -Uvh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

安装

yum install mysql-community-server

设置

防火墙设置

firewall-cmd --zone=public --permanent --add-service=mysql
firewall-cmd --reload

启动

systemctl start mysqld

开机自启动

systemctl enable mysqld

在更改root默认密码前,可以根据需要,关闭密码策略。 如果没有关闭密码策略,则新密码要求是大小写字母+数字+字符的组合。

vi /etc/my.cnf
[mysqld]
validate_password = off

重启,使修改后的密码策略生效

systemctl restart mysqld

更改root默认密码前,先查看root默认密码是什么

grep 'temporary password' /var/log/mysqld.log
//这里可以看到root默认密码是:o-2i#Otgt.Vy
[Note] A temporary password is generated for root@localhost: o-2i#Otgt.Vy

运行安全设置向导,同时更改root默认密码。

mysql_secure_installation
//输入root默认密码
Enter password for user root: ***
//设置新密码
New password:***
Re-enter new password: ***
//是否更改root密码
Change the password for root ? ((Press y|Y for Yes,any other key for No) ://直接回车,表示No
//是否删除匿名用户
Remove anonymous users? (Press y|Y for Yes,any other key for No) : y
//禁止root远程登录
Disallow root login remotely? (Press y|Y for Yes,any other key for No) : y
//删除test数据库
Remove test database and access to it? (Press y|Y for Yes,any other key for No) : y
//重新加载权限表
Reload privilege tables now? (Press y|Y for Yes,any other key for No) : y

也可以使用mysql直接更改root密码

mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 
exit;

为安全root仅限本地登录,根据需要可以新建一个有管理员权限的远程用户

mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO '用户名'@'%' IDENTIFIED BY '登录密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

相关文章

文章浏览阅读903次。4.清除缓存目录(/var/cache/yum)下的软件...
文章浏览阅读1.5k次。Python 是一种高级解释性编程语言,已被...
文章浏览阅读2.6k次。打开终端或控制台,以root或具有sudo权...
文章浏览阅读744次,点赞24次,收藏26次。目标:通过AppSrv为...
文章浏览阅读1.1w次,点赞8次,收藏26次。chmod命令来自于英...
文章浏览阅读1.2k次。yum源的URL地址,本例中是文件系统的路...