1.多实例配置方案:
datadir 目录分开
port 端口号分开
socket 文件分开
[mysqld_multi]
mysqld=mysqld_safe
log=/usr/local/mysql/mysqld_mulit.log
[mysqld3306]
port=3306datadir=/data/3306socket=/data/3306/mysql.sock[mysqld3307]
port=3307datadir=/data/3307socket=/data/3307/mysql.sock
[mysqld3308]
port=3308datadir=/data/3308socket=/data/3308/mysql.sock
[mysqld3309]
port=3309datadir=/data/3309socket=/data/3309/mysql.sock
2.目录规划:
mkdir /data/{3306,3307,3308,3309} -p
chown -R mysql.mysql /data
3.mysql多次初始化
mysqld --initialize --user=mysql --datadir=/data/3306/mysqld--initialize --user=mysql --datadir=/data/3307/mysqld--initialize --user=mysql --datadir=/data/3308/mysqld--initialize --user=mysql --datadir=/data/3309/
4.mysqld_multi管理mysql多实例
mysqld_mulit report查看配置的mysql多实例状态
[root@mysql01 mysql]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is not running
MySQL server from group: mysqld3307 is not running
MySQL server from group: mysqld3308 is not running
MySQL server from group: mysqld3309 is not running
mysqld_multi start n 启动指定mysql
mysqld_mulit start 启动所有mysql
[root@mysql01 mysql]# ps -ef|grep mysql |grep -v 'root'mysql9025 8812 0 22:00 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3307 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql01.err --pid-file=mysql01.pid --socket=/data/3307/mysql.sock --port=3307mysql9041 8806 0 22:00 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql01.err --pid-file=mysql01.pid --socket=/data/3306/mysql.sock --port=3306mysql9229 9111 0 22:00 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3308 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql01.err --pid-file=mysql01.pid --socket=/data/3308/mysql.sock --port=3308mysql9375 9272 0 22:00 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3309 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=mysql01.err --pid-file=mysql01.pid --socket=/data/3309/mysql.sock --port=3309[root@mysql01 mysql]#
mysqld_multi stop停止mysql 需要在配置文件中配置mysql用户名和密码,或者指定用户名和密码;用户名和密码一样才能停止mysql
5.登陆mysql
1.指定socket登陆
mysql -S /data/3306/mysql.sock -p'123'
2.指定端口登陆
mysql -h127.0.0.1 -P3307 -uroot -p'123'
6.停止mysql
mysqladmin shutdown -S /data/3306/mysql.sock -p'123'
通过mysqld_multi stop [n]一次停止所有mysql实例或停止指定实例
1.所有实例用户名密码统一,写在配置文件当中
[mysqld_multi]
mysqld=mysqld_safe
log=/usr/local/mysql/mysqld_mulit.log
user=root
pass=123
运行命令:
[root@mysql01 mysql]# mysqld_multi stop
[root@mysql01 mysql]#ps -ef|grepmysql
root9506 7499 0 22:15 pts/0 00:00:00 grep --color=auto mysql