[root@db200 ~]# mkdir /data/330{7..9} –p
[root@db01 ~]# touch /data/330{7..9}/my.cnf
[root@db01 ~]# vim /data/3307/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
log_error=/data/3307/mysql.log
log-bin=/data/3307/mysql-bin
server_id=7
port=3307
[client]
socket=/data/3307/mysql.sock //指定了3307数据库的sock的文件
[root@db01 ~]# vim /data/3307/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3308/data
socket=/data/3308/mysql.sock
log_error=/data/3308/mysql.log
log-bin=/data/3308/mysql-bin
server_id=8
port=3308
[client]
socket=/data/3308/mysql.sock
[root@db01 ~]# vim /data/3309/my.cnf
[mysqld]
basedir=/application/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
log_error=/data/3309/mysql.log
log-bin=/data/3309/mysql-bin
server_id=9
port=3309
[client]
socket=/data/3309/mysql.sock
[root@db01 ~]#/application/mysql/scripts/mysql_install_db \
--user=mysql \
--defaults-file=/data/3307/my.cnf \
--basedir=/application/mysql --datadir=/data/3307/data
[root@db01 ~]#/application/mysql/scripts/mysql_install_db \
--user=mysql \
--defaults-file=/data/3308/my.cnf \
--basedir=/application/mysql --datadir=/data/3308/data
[root@db01 ~]#/application/mysql/scripts/mysql_install_db \
--user=mysql \
--defaults-file=/data/3309/my.cnf \
--basedir=/application/mysql --datadir=/data/3309/data
[root@db01]# chown -R mysql.mysql /data/330*
[root@db01]# mysqld_safe --defaults-file=/data/3307/my.cnf &
[root@db01]# mysqld_safe --defaults-file=/data/3308/my.cnf &
[root@db01]# mysqld_safe --defaults-file=/data/3309/my.cnf &
[root@db01]# mysql -S /data/3307/mysql.sock -e "show variables like ‘server_id‘"
[root@db01]# mysql -S /data/3308/mysql.sock -e "show variables like ‘server_id‘"
[root@db01]# mysql -S /data/3309/mysql.sock -e "show variables like ‘server_id‘"
[root@db01]# mysql -S /data/3307/mysql.sock -e "show variables like ‘server_id‘" //登陆主库
grant replication slave on *.* to slave@‘localhost‘ identified by ‘123‘;
mysql> show master status;
导出主库的内容
mysqldump -uroot -p3307 -S /data/3307/mysql.sock -A >/root/3307.sql
mysql -uroot -p3308 -S /data/3308/mysql.sock </root/3307.sql
mysql -S /data/3308/mysql.sock -e "show variables like ‘server_id‘"
mysql> change master to
-> master_host=‘localhost‘,
-> master_port=3307,
-> master_user=‘slave‘,
-> master_password=‘123‘,
-> master_log_file=‘mysql-bin.000008‘, // 一定要和主库的授权表信息表示一致
-> master_log_pos=521; // 一定要和主库的授权表信息表示一致
mysql> start slave;
mysql> show slave status\G;
mysql -uroot -p3309 -S /data/3309/mysql.sock </root/3307.sql
mysql -S /data/3309/mysql.sock -e "show variables like ‘server_id‘"
mysql> change master to
-> master_host=‘localhost‘,
-> master_port=3307,
-> master_user=‘slave‘,
-> master_password=‘123‘,
-> master_log_file=‘mysql-bin.000008‘, // 一定要和主库的授权表信息表示一致
-> master_log_pos=521; // 一定要和主库的授权表信息表示一致
mysql> start slave;
mysql> show slave status\G;
原文:http://blog.51cto.com/14083743/2322284