安装Mysql,版本5.7

一、查找源仓库文件

进入mysql中国官网

https://www.mysql.com/cn/

点击 左上角“产品”,进入新界面后,点击左侧的“MySQL 社区版”,然后点击新界面下方的“立即下载”,进入MySQL Community Download,再次点击“MySQL Yum Repository”, 进入以下界面:

网址为

https://dev.mysql.com/downloads/repo/yum/

1.点击“Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package”右侧的“Download”,进入“Login Now or Sign Up for a free account”页面,右键点击下方的“No thanks, just start my download”,拷贝链接为

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

2.点击上方“i”图标,再点击“A Quick Guide to Using the MySQL Yum Repository”,进入网址:

https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

为安装说明。

二、添加源仓库

1.添加之前复制的源地址,下载源仓库文件,查看源仓库包文件清单

rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
yum repolist all | grep mysql

2.设置下载5.7版本,禁用8.0版本

yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community

设置后,/etc/yum.repos.d/mysql-community.repo文件部分内容如下:

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$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

# 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/6/$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

4.校验设置结果

查看生效的安装包

yum repolist enabled | grep mysql

mysql-connectors-community/x86_64 MySQL Connectors Community                 230
mysql-tools-community/x86_64      MySQL Tools Community                      138
mysql57-community/x86_64          MySQL 5.7 Community Server                 564 

三、安装、启动

1.安装软件包

yum install -y mysql-community-server

2.启动mysql服务

systemctl start mysqld.service
systemctl status mysqld.service

 3.设置开机启动

systemctl enable mysqld.service

四、更改密码

1.查询临时密码

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

2.以root角色登录

mysql -uroot -p

3.修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

mysql> quit;

注意:(1)“;”不能省略

(2)密码为8位以上,含大小写字母、数字、特殊符号等

五、特殊情况

安装部署完MySQL后通过命令mysql -u root -p登录时报错如下:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

解决方案:

找到MySQL的配置文件/etc/my.cnf

[mysqld]

skip-grant-tables

在此配置文件中添加命令skip-grant-tables实现免密登录

添加命令后保存配置文件,重启MySQL服务:systemctl restart mysqld

再通过命令mysql -u root -p登录MySQL,输入密码时直接按Enter键登录,登录后修改密码、刷新、退出MySQL

mysql>update mysql.user set authentication_string=password('Mysql@123') where user='root' and host='localhost';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 1

mysql>

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

mysql> quit;

修改密码退出后将配置文件中前面添加的命令:skip-grant-tables注释或删除

再次重启MySQL服务:systemctl restart mysqld

即可正常登录MySQL

六、版本更新

进入mysql中国官网

https://www.mysql.com/cn/

点击 上方“下载”,进入新界面后,点击下方的“MySQL Community (GPL) Downloads”,进入MySQL Community Download,再次点击“MySQL Community Server”, 进入以下界面:

网址为

https://dev.mysql.com/downloads/mysql/

点击右侧的“Looking for previous GA versions?”,进入“MySQL Community Server 5.7.39”页面,操作系统选择“Red Hat Enterprise Linux  / Oracle Linux ”,系统版本选择“Red Hat Enterprise Linux 7 / Oracle Linux 7 (X86,64 bit)”,下载需要的rmp包即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值