CentOS 7.2 yum方式安装MySQL 5.7

CentOS 7之后的版本yum的默认源中使用MariaDB替代原先MySQL,因此安装方式较为以往有一些改变:

下载mysql的源

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

 

安装yum库

yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

 

安装MySQL

yum install -y mysql-community-server

 

启动MySQL服务

systemctl start mysqld.service

 

MySQL5.7加强了root用户的安全性,因此在第一次安装后会初始化一个随机密码,以下为查看初始随机密码的方式

grep 'temporary password' /var/log/mysqld.log

结果如下:

 

使用初始随机密码登录后MySQL会强制要求修改密码,否则无法正常使用,(密码必须包含小写、大写字母及特殊字符,当然也有其他方法不受此限制,再次不多做描述),修改方法如下:

SET PASSWORD = PASSWORD('your new password');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;

然后退出后即可用新密码登录。

远程连接授权:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;

 

开通端口(默认3306):

firewall-cmd --add-port=3306/tcp

 

posted on 2016-11-16 21:51  longrui  阅读(10075)  评论(1编辑  收藏  举报