MySQL是一個(gè)簡單易用的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),享受高效可靠、高速穩(wěn)定等優(yōu)良特性。在CentOS系統(tǒng)中,MySQL多實(shí)例安裝配置的方法如下:
1.首先進(jìn)行安裝
# yum install mysql mysql-server
2.創(chuàng)建數(shù)據(jù)目錄和my.cnf配置文件
# mkdir -p /data/mysql3306/data # touch /data/mysql3306/my.cnf
3.修改my.cnf配置文件
[mysqld] basedir=/usr datadir=/data/mysql3306/data port=3306 socket=/var/lib/mysql/mysql.sock [client] port=3306 socket=/var/lib/mysql/mysql.sock [mysql] socket=/var/lib/mysql/mysql.sock
4.初始化mysql3306實(shí)例
# mysqld --initialize-insecure --user=root --basedir=/usr --datadir=/data/mysql3306/data
5.啟動(dòng)mysql服務(wù)
# systemctl start mysqld.service
6.設(shè)置mysql3306實(shí)例root密碼
# mysqladmin -u root password "new_password"
7.創(chuàng)建mysql3306實(shí)例的systemd啟動(dòng)文件
# vim /usr/lib/systemd/system/mysqld3306.service [Unit] Description=MySQL3306 Server After=syslog.target After=network.target [Service] User=mysql Group=mysql Type=forking PIDFile=/var/run/mysql/mysql.pid ExecStart=/usr/sbin/mysqld --defaults-file=/data/mysql3306/my.cnf --pid-file=/var/run/mysql/mysql.pid --socket=/var/lib/mysql3306/mysql.sock --datadir=/data/mysql3306/data --port=3306 TimeoutSec=300 Restart=on-failure [Install] WantedBy=multi-user.target
8.啟動(dòng)mysql3306實(shí)例
# systemctl daemon-reload # systemctl start mysqld3306.service
9.創(chuàng)建mysql3307實(shí)例
# mkdir -p /data/mysql3307/data # touch /data/mysql3307/my.cnf
10.修改my.cnf配置文件
[mysqld] basedir=/usr datadir=/data/mysql3307/data port=3307 socket=/var/lib/mysql/mysql.sock [client] port=3307 socket=/var/lib/mysql/mysql.sock [mysql] socket=/var/lib/mysql/mysql.sock
11.初始化mysql3307實(shí)例
# mysqld --initialize-insecure --user=root --basedir=/usr --datadir=/data/mysql3307/data
12.啟動(dòng)mysql服務(wù)
# systemctl start mysqld.service
13.設(shè)置mysql3307實(shí)例root密碼
# mysqladmin -u root password "new_password"
14.創(chuàng)建mysql3307實(shí)例的systemd啟動(dòng)文件
# vim /usr/lib/systemd/system/mysqld3307.service [Unit] Description=MySQL3307 Server After=syslog.target After=network.target [Service] User=mysql Group=mysql Type=forking PIDFile=/var/run/mysql/mysql.pid ExecStart=/usr/sbin/mysqld --defaults-file=/data/mysql3307/my.cnf --pid-file=/var/run/mysql/mysql.pid --socket=/var/lib/mysql3307/mysql.sock --datadir=/data/mysql3307/data --port=3307 TimeoutSec=300 Restart=on-failure [Install] WantedBy=multi-user.target
15.啟動(dòng)mysql3307實(shí)例
# systemctl daemon-reload # systemctl start mysqld3307.service
至此,CentOS系統(tǒng)中的MySQL多實(shí)例安裝配置完成。