在CentOS8上,默认情况下直接使用yum安装mysql,安装的是Mysql 8.0,在一些比较老的项目中,我们需要使用的mysql版本是5.7,下面我分享一个在CentOS8中安装Myslq5.7的方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| ··· Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 11 M Installing dependencies: mysql-common x86_64 8.0.17-3.module_el8.0.0+181+899d6349 AppStream 143 k Enabling module streams: mysql 8.0
Transaction Summary ================================================================================ Install 2 Packages ···
|
下载Mysql5.7的RPM包
进入https://downloads.mysql.com/archives/community/,选择对应的mysql版本和操作系统版本,下载以下包:
- RPM Package, MySQL Server
- RPM Package, Client Utilities
- RPM Package, Shared Libraries
- RPM Package, MySQL Configuration
安装Mysql Server需要这些包。
安装过程
安装时需要按以下顺序安装,因为这些包存在依赖关系:
MySQL Configuration -> Shared Libraries -> Client Utilities -> MySQL Server
1 2 3 4
| yum localinstall mysql-community-common-5.7.30-1.el7.x86_64.rpm yum localinstall mysql-community-libs-5.7.30-1.el7.x86_64.rpm yum localinstall mysql-community-client-5.7.30-1.el7.x86_64.rpm yum localinstall mysql-community-server-5.7.30-1.el7.x86_64.rpm
|
配置Mysql
系统启动时自启动:
启动mysql服务:
查看mysqld服务运行状态:
输出内容:
1 2 3 4 5 6 7 8 9 10 11 12
| ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-08-21 02:07:18 EDT; 41min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 55384 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 55366 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 55386 (mysqld) Tasks: 28 (limit: 24984) Memory: 178.1M CGroup: /system.slice/mysqld.service └─55386 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
|
如果忘记root密码需要重置root密码可参考《如何重置Mysql5.7 root密码》。