官网[下载地址](https://downloads.mysql.com/archives/community/)
- 版本选择:5.5.48
- 操作系统:Linux - Generic
- 系统版本:Linux - Generic 2.6 (x86, 64-bit)
1. 选择 `RPM Package, MySQL Server` [下载](https://downloads.mysql.com/archives/get/p/23/file/MySQL-server-5.5.48-1.linux2.6.x86_64.rpm) 服务端
2. 选择 `RPM Package, Client Utilities` [下载](https://downloads.mysql.com/archives/get/p/23/file/MySQL-client-5.5.48-1.linux2.6.x86_64.rpm) 客户端
检查MySQL是否已经安装
```bash
rpm -qa | grep mariadb # mariadb是CentOS7自带的一种MySQL版本。查看是否已经安装?
rpm -e --nodeps mariadb-libs-* # 强制卸载mariadb数据库。
```
安装MySQL服务端
```bash
rpm -ivh MySQL-server-5.5.48-1.linux2.6.x86_64.rpm
```
```bash
[root@gosuncn opt]# rpm -ivh MySQL-server-5.5.48-1.linux2.6.x86_64.rpm
警告:MySQL-server-5.5.48-1.linux2.6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
错误:依赖检测失败:
/usr/bin/perl 被 MySQL-server-5.5.48-1.linux2.6.x86_64 需要
```
```bash
yum install -y perl*
```
```bash
[root@gosuncn opt]# rpm -ivh MySQL-server-5.5.48-1.linux2.6.x86_64.rpm
警告:MySQL-server-5.5.48-1.linux2.6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:MySQL-server-5.5.48-1.linux2.6 ################################# [100%]
200513 15:36:03 [Note] /usr/sbin/mysqld (mysqld 5.5.48) starting as process 2250 ...
200513 15:36:03 [Note] /usr/sbin/mysqld (mysqld 5.5.48) starting as process 2257 ...
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h gosuncn password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
Please report any problems at http://bugs.mysql.com/
```
安装MySQL客户端
```bash
rpm -ivh MySQL-client-5.5.48-1.linux2.6.x86_64.rpm
```
```bash
[root@gosuncn opt]# rpm -ivh MySQL-client-5.5.48-1.linux2.6.x86_64.rpm
警告:MySQL-client-5.5.48-1.linux2.6.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:MySQL-client-5.5.48-1.linux2.6 ################################# [100%]
```
启动MySQL
```bash
[root@gosuncn opt]# service mysql start
Starting MySQL.. SUCCESS!
```
设置密码
```bash
/usr/bin/mysqladmin -u root password 'root'
```
开放端口
```bash
firewall-cmd --zone=public --add-port=3306/tcp --permanent;
firewall-cmd --reload;
firewall-cmd --list-port;
```
允许root远程连接
```mysql
use mysql;
update user set host = '%' where user = 'root';
select host, user from user;
flush privileges;
```
设置开机自启
```bash
chkconfig mysql on
```
> chkconfig --list | grep mysql