官網[下載地址](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