mysql的多例項配置

lsq_008發表於2015-08-17
mysqld_multi被設計為了管理實現多個mysqld服務程式 

配置如下:
1.建立資料目錄

[root@mysqldb test]# cd /u01/mysql
[root@mysqldb test]# mkdir data1
[root@mysqldb test]# mkdir data2

2.初始化資料庫
[root@mysqldb test]# mysql_install_db   --datadir=/mysql/data1/  --user=mysql
[root@mysqldb test]# mysql_install_db   --datadir=/mysql/data2/  --user=mysql

3.配置mysqld的多例項my.cnf檔案

[mysqld_multi]
mysqld =/usr/bin/mysqld_safe
mysqladmin =/usr/bin/mysqladmin
#user =test
#password =test

[mysqld1]
port            = 3307
socket          = /tmp/mysql1.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
binlog_format=mixed
datadir = /u01/mysql/data1
server-id       = 1

[mysqld2]
port            = 3308
socket          = /tmp/mysql2.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
binlog_format=mixed
datadir = /u01/mysql/data2
server-id       = 1

4.多例項資料庫的啟停
---啟動單個例項
[root@mysqldb mysql]# mysqld_multi --defaults-file=/etc/my.cnf start 1
[root@mysqldb mysql]# ps -ef|grep mysql
avahi     2689     1  0 Aug16 ?        00:00:00 avahi-daemon: running [mysqldb.local]
root      8388     1  3 02:12 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --port=3307 --socket=/tmp/mysql1.sock --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --log-bin=mysql-bin --binlog_format=mixed --datadir=/u01/mysql/data1 --server-id=1
mysql     8782  8388 20 02:12 pts/1    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/u01/mysql/data1 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-external-locking --key-buffer-size=16M --max-allowed-packet=1M --table-open-cache=64 --sort-buffer-size=512K --net-buffer-length=8K --read-buffer-size=256K --read-rnd-buffer-size=512K --myisam-sort-buffer-size=8M --log-bin=mysql-bin --binlog-format=mixed --server-id=1 --log-error=/u01/mysql/data1/mysqldb.err --pid-file=/u01/mysql/data1/mysqldb.pid --socket=/tmp/mysql1.sock --port=3307
root      8807  5772  0 02:12 pts/1    00:00:00 grep mysql

---停止單個例項
[root@mysqldb mysql]# mysqld_multi --defaults-file=/etc/my.cnf stop 1
[root@mysqldb mysql]# 
[root@mysqldb mysql]# 
[root@mysqldb mysql]# ps -ef|grep mysql
avahi     2689     1  0 Aug16 ?        00:00:00 avahi-daemon: running [mysqldb.local]
root      8382  5772  0 02:12 pts/1    00:00:00 grep mysql

--啟動多個例項
[root@mysqldb mysql]# mysqld_multi --defaults-file=/etc/my.cnf start 1-2
[root@mysqldb mysql]# ps -ef|grep mysql
avahi     2689     1  0 Aug16 ?        00:00:00 avahi-daemon: running [mysqldb.local]
root      8388     1  0 02:12 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --port=3307 --socket=/tmp/mysql1.sock --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --log-bin=mysql-bin --binlog_format=mixed --datadir=/u01/mysql/data1 --server-id=1
mysql     8782  8388  0 02:12 pts/1    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/u01/mysql/data1 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-external-locking --key-buffer-size=16M --max-allowed-packet=1M --table-open-cache=64 --sort-buffer-size=512K --net-buffer-length=8K --read-buffer-size=256K --read-rnd-buffer-size=512K --myisam-sort-buffer-size=8M --log-bin=mysql-bin --binlog-format=mixed --server-id=1 --log-error=/u01/mysql/data1/mysqldb.err --pid-file=/u01/mysql/data1/mysqldb.pid --socket=/tmp/mysql1.sock --port=3307
root      8827     1  0 02:13 pts/1    00:00:00 /bin/sh /usr/bin/mysqld_safe --port=3308 --socket=/tmp/mysql2.sock --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --log-bin=mysql-bin --binlog_format=mixed --datadir=/u01/mysql/data2 --server-id=1
mysql     9588  8827  4 02:13 pts/1    00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/u01/mysql/data2 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --skip-external-locking --key-buffer-size=16M --max-allowed-packet=1M --table-open-cache=64 --sort-buffer-size=512K --net-buffer-length=8K --read-buffer-size=256K --read-rnd-buffer-size=512K --myisam-sort-buffer-size=8M --log-bin=mysql-bin --binlog-format=mixed --server-id=1 --log-error=/u01/mysql/data2/mysqldb.err --pid-file=/u01/mysql/data2/mysqldb.pid --socket=/tmp/mysql2.sock --port=3308
root      9613  5772  0 02:13 pts/1    00:00:00 grep mysql

--停止多個例項
[root@mysqldb mysql]# mysqld_multi --defaults-file=/etc/my.cnf stop 1-2
[root@mysqldb mysql]# ps -ef|grep mysql
avahi     2689     1  0 Aug16 ?        00:00:00 avahi-daemon: running [mysqldb.local]
root      9634  5772  0 02:14 pts/1    00:00:00 grep mysql

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10972173/viewspace-1774045/,如需轉載,請註明出處,否則將追究法律責任。

相關文章