Centos 6上 安装 Mysql 5.7.13

1. 下载mysql的repo源

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
 
 
  • 1
2. 安装mysql57-community-release-el7-8.noarch.rpm包
rpm -ivh mysql57-community-release-el7-8.noarch.rpm  --nodeps --force
 
 
  • 1

安装这个包后,会获得两个mysql的yum repo源:

            /etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo

3.安装mysql
yum install mysql-server
 
 
  • 1
4. 启动mysql服务

查看MySQL服务是否已启动

service mysqld status
 
 
  • 1

启动服务

systemctl start mysqld
 
 
  • 1
5. 重置root密码

MySQL5.7会在安装后为root用户生成一个随机密码,而不是像以往版本的空密码。 
可以安全模式修改root登录密码或者用随机密码登录修改密码。下面用随机密码方式

MySQL为root用户生成的随机密码通过mysqld.log文件可以查找到:

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

 
 
  • 1
  • 2

修改root用户密码:(MySQL的密码策略比较复杂,过于简单的密码会被拒绝)

mysql -u root -p
mysql> Enter password: (输入刚才查询到的随机密码)
mysql> SET PASSWORD FOR 'root'@'localhost'= "Root-123";
mysql> exit
 
 
  • 1
  • 2
  • 3
  • 4

用root新密码登录:

mysql -u root -pRoot-123
 
 
  • 1

如果上面的方式不能修改可以使用下面安全模式修改root:

关闭服务
systemctl stop mysqld.service
vi /etc/my.cnf 
mysqld下面添加skip-grant-tables 保存退出启动服务
systemctl start mysqld.service
mysql -u root 不用密码直接回车
use mysql
update user set authentication_string=password('Root-123') where User='root' and Host='localhost';
flush privileges;
exit;
vi /etc/my.cnf 把 skip-grant-tables 一句删除保存退出重启mysql服务 
systemctl restart mysqld.service
再次登录即可
mysql -u root -pRoot-123

如果进行操作出现下面的提示:
You must reset your password using ALTER USER statement before executing this statement.
就再设置一遍密码
set password = password('Root-123');
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
6. 开放3306端口

允许使用用户名root密码Root-123456从任何主机连接到mysql服务器

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root-123456' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
mysql>exit;
 
 
  • 1
  • 2
  • 3

开启防火墙mysql 3306端口的外部访问

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值