MySQL是一個簡單易用的關系型數據庫管理系統,享受高效可靠、高速穩定等優良特性。在CentOS系統中,MySQL多實例安裝配置的方法如下:
1.首先進行安裝
# yum install mysql mysql-server
2.創建數據目錄和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實例
# mysqld --initialize-insecure --user=root --basedir=/usr --datadir=/data/mysql3306/data
5.啟動mysql服務
# systemctl start mysqld.service
6.設置mysql3306實例root密碼
# mysqladmin -u root password "new_password"
7.創建mysql3306實例的systemd啟動文件
# 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.啟動mysql3306實例
# systemctl daemon-reload # systemctl start mysqld3306.service
9.創建mysql3307實例
# 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實例
# mysqld --initialize-insecure --user=root --basedir=/usr --datadir=/data/mysql3307/data
12.啟動mysql服務
# systemctl start mysqld.service
13.設置mysql3307實例root密碼
# mysqladmin -u root password "new_password"
14.創建mysql3307實例的systemd啟動文件
# 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.啟動mysql3307實例
# systemctl daemon-reload # systemctl start mysqld3307.service
至此,CentOS系統中的MySQL多實例安裝配置完成。