3)导入Master上导出的数据
[root@server136 ~]# /etc/init.d/mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[root@server136 ~]# mysql -uroot -p123456 < /tmp/tb01.sql
下面进入MySQL数据库查看一下导入的数据:
[root@server136 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * from tb01.staff;
+----+-------+
| id | name |
+----+-------+
| 1 | Tom |
| 2 | Jerry |
+----+-------+
2 rows in set (0.01 sec)
[root@heartbeat01 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use tb01;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create table test01( id int not null, name varchar(100), age int, sex varchar(20), city varchar(40) );
Query OK, 0 rows affected (0.05 sec)
mysql> insert into test01 values (001,'zhangsan',20,'Male','Beijing');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test01 values (002,'lisi',25,'Male','Shanghai');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test01 values (003,'wangwu',28,'Female','Shenzhen');
Query OK, 1 row affected (0.00 sec)
mysql> select * from test01;
+----+----------+------+--------+----------+
| id | name | age | sex | city |
+----+----------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 2 | lisi | 25 | Male | Shanghai |
| 3 | wangwu | 28 | Female | Shenzhen |
+----+----------+------+--------+----------+
3 rows in set (0.00 sec)
然后到Slave上去查看,是否存在对应的表和数据:
[root@server136 ~]# mysql -uroot -p123456
mysql> use tb01;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+----------------+
| Tables_in_tb01 |
+----------------+
| staff |
+----------------+
1 row in set (0.00 sec)
mysql> show tables;
+----------------+
| Tables_in_tb01 |
+----------------+
| staff |
| test01 |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from test01;
+----+----------+------+--------+----------+
| id | name | age | sex | city |
+----+----------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 2 | lisi | 25 | Male | Shanghai |
| 3 | wangwu | 28 | Female | Shenzhen |
+----+----------+------+--------+----------+
3 rows in set (0.00 sec)
[root@heartbeat02 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * from tb01.test01;
+----+----------+------+--------+----------+
| id | name | age | sex | city |
+----+----------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 2 | lisi | 25 | Male | Shanghai |
| 3 | wangwu | 28 | Female | Shenzhen |
+----+----------+------+--------+----------+
3 rows in set (0.04 sec)
mysql> use tb01;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> insert into test01 values(4,'zhaosi',40,'Male','Tieling');
Query OK, 1 row affected (0.00 sec)
mysql> insert into test01 values(5,'xiaoshenyang',34,'Male','Shenyang');
Query OK, 1 row affected (0.00 sec)
mysql> select * from tb01.test01;
+----+--------------+------+--------+----------+
| id | name | age | sex | city |
+----+--------------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 2 | lisi | 25 | Male | Shanghai |
| 3 | wangwu | 28 | Female | Shenzhen |
| 4 | zhaosi | 40 | Male | Tieling |
| 5 | xiaoshenyang | 34 | Male | Shenyang |
+----+--------------+------+--------+----------+
5 rows in set (0.01 sec)
然后到Slave上进行查看同步状况:
mysql> show tables;
+----------------+
| Tables_in_tb01 |
+----------------+
| staff |
| test01 |
+----------------+
2 rows in set (0.00 sec)
mysql> select * from test01;
+----+--------------+------+--------+----------+
| id | name | age | sex | city |
+----+--------------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 2 | lisi | 25 | Male | Shanghai |
| 3 | wangwu | 28 | Female | Shenzhen |
| 4 | zhaosi | 40 | Male | Tieling |
| 5 | xiaoshenyang | 34 | Male | Shenyang |
+----+--------------+------+--------+----------+
5 rows in set (0.00 sec)
mysql> select * from tb01.test01;
+----+--------------+------+--------+----------+
| id | name | age | sex | city |
+----+--------------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 2 | lisi | 25 | Male | Shanghai |
| 3 | wangwu | 28 | Female | Shenzhen |
| 4 | zhaosi | 40 | Male | Tieling |
| 5 | xiaoshenyang | 34 | Male | Shenyang |
+----+--------------+------+--------+----------+
5 rows in set (0.03 sec)
mysql> delete from tb01.test01 where name = 'lisi';
Query OK, 1 row affected (0.00 sec)
mysql> select * from tb01.test01;
+----+--------------+------+--------+----------+
| id | name | age | sex | city |
+----+--------------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 3 | wangwu | 28 | Female | Shenzhen |
| 4 | zhaosi | 40 | Male | Tieling |
| 5 | xiaoshenyang | 34 | Male | Shenyang |
+----+--------------+------+--------+----------+
4 rows in set (0.00 sec)
6)在Slave节点(server136)上进行查询
[root@server136 ~]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * from tb01.test01;
+----+--------------+------+--------+----------+
| id | name | age | sex | city |
+----+--------------+------+--------+----------+
| 1 | zhangsan | 20 | Male | Beijing |
| 3 | wangwu | 28 | Female | Shenzhen |
| 4 | zhaosi | 40 | Male | Tieling |
| 5 | xiaoshenyang | 34 | Male | Shenyang |
+----+--------------+------+--------+----------+
4 rows in set (0.00 sec)
mysql> quit
Bye
[root@server136 ~]#