2.2.2 Slave 端设置
和 master 端一样创建一个相同的数据库:abc
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 5
- Server version: 5.0.45-log Source distribution
-
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
-
- mysql> create database abc;
- Query OK, 1 row affected (0.31 sec)
|
修改配置文件:
root@test2 ~: vi /etc/my.cnf |
- [mysqld]
- datadir=/var/lib/mysql
- socket=/var/lib/mysql/mysql.sock
- user=mysql
- old_passwords=1
-
- ###增加下面内容
- server_id=2 log-bin=mysql-bin master-host=192.168.7.67 master-user=test1 master-password=test1 master-port=3306 master-connect-retry=10 ###连接次数 replicate-do-db=abc ###接受的数据库名 replicate-ignore-db=mysql ###不要接受的数据库
-
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
|
重启服务:
root@test2~: /etc/init.d/mysqld restart |
备注:
配置成功 后会在 mysql 目录(/var/lib/mysql/)下生成 master.info 文件,如果要更改 slave 设置,要先将该文件删除才会起作用。
进入 mysql,输入下面命令:
- root@test2~: mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 4
- Server version: 5.0.45-log Source distribution
-
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
-
- mysql> slave start;
- Query OK, 0 rows affected, 1 warning (0.00 sec)
- ###查看同步情况
- mysql > show slave status; 或 show master status;
|
2.3 结果测试
在 Master 端进行数据库 abc 的一些操作,如下所示:
- jian.ma@camlit ~: mysql -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3
- Server version: 5.0.77-log Source distribution
-
- Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
-
- mysql> use abc;
- Database changed
- mysql> create table test1 (IP VARCHAR(20),USER VARCHAR(100), MAIL
- VARCHAR(100));
- Query OK, 0 rows affected (1.20 sec)
- mysql> insert into test1(IP,USER,MAIL) values('192.168.7.66', 'test', 'test@test.com.cn');
- Query OK, 1 row affected (0.06 sec)
|