CentOS 7 部署 MySQL 5.7

参考文档:A Quick Guide to Using the MySQL Yum Repository

进入 https://dev.mysql.com/downloads/repo/yum/,根据 Linux 的版本选择相对应的 rpm 文件,比如我的机器是 CentOS 7.6,那么我选择 mysql80-community-release-el7-5.noarch.rpm。

$ wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm

$ rpm -Uvh mysql80-community-release-el7-5.noarch.rpm

关键步骤
禁用 MySQL 8.0 并开启 MySQL 5.7(有两种方式)
方式一:

$ yum repolist all | grep mysql
$ yum install -y yum-utils 
$ yum-config-manager --disable mysql80-community
$ yum-config-manager --enable mysql57-community

方式二:
如果不想通过 yum-config-manager 的话,还可以通过手动编辑 /etc/yum.repos.d/mysql-community.repo 文件的方式(该文件是在执行 rpm 命令时自动创建的),设置 mysql80-community 下的 enabled 为 0 表示禁用,同时设置 mysql57-community 下 enabled 为 1 表示启用。 下面仅节选部分关键内容:

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
 
 
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
       file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

再次检查下,确保当前启用的版本是 MySQL 5.7

$ yum repolist enabled | grep mysql

安装

$ yum install mysql-community-server
$ systemctl start mysqld
$ systemctl status mysqld
$ systemctl enable mysqld

获取MySQL 'root'@'localhost' 的临时密码

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

使用临时密码,登录到 MySQL 并修改密码

$ mysql -uroot -p

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码;

开启 MySQL 远程连接

mysql> use mysql;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码';
mysql> FLUSH PRIVILEGES;	

可以通过查询表来确认下修改是否生效

$ mysql -uroot -p
Enter password:

mysql> use mysql;
mysql> SELECT Host, User FROM user;
+-----------+---------------+
| Host      | User          |
+-----------+---------------+
| %         | root          |
| localhost | mysql.session |
| localhost | mysql.sys     |
+-----------+---------------+

腾讯云的防火墙开启 3306 端口
在这里插入图片描述

使用 Navicat 等客户端连接即可,Host 需要填 公网 IP

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值