150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from /home/data/mysql3309/data
6,查看多实例
[mysql@data02 ~]$ mysqld_multi--defaults-extra-file=/etc/my.cnf report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
[mysql@data02 ~]$
?
后台日志信息:
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
7,停止多实例
mysqld_multi--defaults-extra-file=/etc/my.cnf stop 1,2,3
后台日志信息:
Stopping MySQL servers
150514 09:35:43 mysqld_safe mysqld from pidfile /usr/local/mysql3309/mysqld.pid ended
150514 09:35:43 mysqld_safe mysqld from pidfile /usr/local/mysql3307/mysqld.pid ended
150514 09:35:43 mysqld_safe mysqld from pidfile /usr/local/mysql3308/mysqld.pid ended
8,各自登录mysql实例
需要指定启动的socket就可以登录到各自的mysql实例,如下所示:
[mysql@data02 ~]$ mysql --socket=/usr/local/mysql3308/mysql.sock
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.12-log Sourcedistribution
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql> select @@port;
+--------+
| @@port |
+--------+
|? 3308 |
+--------+
1 row in set (0.00 sec)
mysql>
mysql> create database d3308;
Query OK, 1 row affected (0.04 sec)
mysql>
9,可以在多端口上搭建主从、主主服务
9.1,在3307实例建立账号
? ? ? ? 复制账号
? ? ? ? GRANTREPLICATION SLAVE,RELOAD,SUPER ON *.*TO repl@'192.168.52.%' IDENTIFIED BY'repl_1234';
? ? ? ?
? ? ? ? 备份账号
? ? ? ? GRANTRELOAD, SUPER, LOCK TABLES, REPLICATION CLIENT, CREATE TABLESPACE ON *.* TO'backup'@'192.168.%' IDENTIFIED BY '123456';
? ? ? ? GRANTALL PRIVILEGES ON `mysql`.* TO 'backup'@'192.168.%';
? ? ? ? GRANTEVENT ON *.* TO 'backup'@'192.168.%';
9.2,将数据从3307实例同步到3308端口?
? ? ? ? 备份:
? ? ? ? /usr/local/mysql/bin/mysqldump-ubackup --password=123456 --host=192.168.52.138--socket=/usr/local/mysql3307/mysql.sock --port=3307 -R -E --skip-opt--single-transaction --flush-logs --master-data=2 --add-drop-table--create-option --quick --extended-insert=false --set-charset --disable-keys-A? > /tmp/alldbfullbackup.sql
? ? ? ? 导入:
? ? ? ? /usr/local/mysql/bin/mysql-uroot -p --socket=/usr/local/mysql3308/mysql.sock --port=3308
9.3,在3308实例上建立复制链接
? ? ? ? 找到复制点
? ? ? ? more/tmp/alldbfullbackup.sql
? ? ? ? 开始建立复制链接
? ? ? ? ? CHANGE MASTER TOMASTER_HOST='192.168.52.138',MASTER_PORT=3307,
? ? ? ? MASTER_USER='repl',
? ? ? ? MASTER_PASSWORD='repl_1234',
? ? ? ? MASTER_LOG_FILE='mysql-bin.000006',
? ? ? ? MASTER_LOG_POS=120;
? ? ? ? 开启复制
? ? ? ? startslave;
? ? ? ? 查看复制状态
? ? ? ? showslave status\G;
mysql> show slave status\G
*************************** 1. row***************************
? ? ? ? ? ? ? Slave_IO_State: Waiting formaster to send event
? ? ? ? ? ? ? ? ? Master_Host: 192.168.52.138
? ? ? ? ? ? ? ? ? Master_User: repl
? ? ? ? ? ? ? ? ? Master_Port: 3307
? ? ? ? ? ? ? ? Connect_Retry: 60
? ? ? ? ? ? ? Master_Log_File: mysql-bin.000011
? ? ? ? Read_Master_Log_Pos: 120
? ? ? ? ? ? ? Relay_Log_File:mysql-relay-bin.000005
? ? ? ? ? ? ? ? Relay_Log_Pos: 283
? ? ? Relay_Master_Log_File: mysql-bin.000011
? ? ? ? ? ? Slave_IO_Running: Yes
? ? ? ? ? ? Slave_SQL_Running: Yes
? ? ? ? ? ? ? ? ? ……
Seconds_Behind_Master: 0
10,管理单个实例
停止实例2:
[root@data03 ~]# mysqld_multi--