mysql
>
desc
t
;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| c_str | char(64) | NO | | | |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
2
rows
in
set
(
0
.
00 sec
)
我在
B
上插入一条记录
mysql> insert into t(c_str) values('B');
Query OK, 1 row affected (0.00 sec)
在
C
上同样插入一条记录
mysql> insert into t(c_str) value('C');
Query OK, 1 row affected (0.00 sec)
mysql
>
insert
into
t
(
c_str
)
values
(
'wangwang'
);
Query OK
,
1
row
affected
(
0
.
01 sec
)
mysql> show processlist;
+----+-------------+---------------------+--------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+---------------------+--------+---------+------+-------+------------------+
| 12 | t_girl_user | 192.168.0.234:44975 | t_girl | Sleep | 28 | | NULL |
| 13 | t_girl_user | 192.168.0.234:44976 | t_girl | Sleep | 15 | | NULL |
| 14 | t_girl_user | 192.168.0.234:44977 | t_girl | Sleep | 19 | | NULL |
| 15 | t_girl_user | 192.168.0.234:44978 | t_girl | Query | 0 | NULL | show processlist |
+----+-------------+---------------------+--------+---------+------+-------+------------------+
4 rows in set (0.00 sec)
4
rows
in
set
(
0
.
00 sec
)
读数据(现在还是写和读都在
B
上)
mysql> select * from t;
+----+----------+
| id | c_str |
+----+----------+
| 1 | B |
| 2 | wangwang |
+----+----------+
2 rows in set (0.00 sec)
再增加一个客户端连接。
1
row
in
set
(
0
.
00 sec
)
mysql> show processlist;
+----+-------------+---------------------+--------+---------+------+-----------------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+---------------------+--------+---------+------+-----------------------------------------------------------------------+------------------+
| 2 | system user | | NULL | Connect | 1842 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
| 5 | root | localhost | t_girl | Query | 0 | NULL | show processlist |
| 12 | t_girl_user | 192.168.0.234:44975 | t_girl | Sleep | 446 | | NULL |
| 13 | t_girl_user | 192.168.0.234:44976 | t_girl | Sleep | 188 | | NULL |
| 14 | t_girl_user | 192.168.0.234:44977 | t_girl | Sleep | 206 | | NULL |
| 15 | t_girl_user | 192.168.0.234:44978 | t_girl | Sleep | 203 | | NULL |
| 16 | t_girl_user | 192.168.0.234:44979 | t_girl | Sleep | 164 | | NULL |
| 17 | t_girl_user | 192.168.0.234:44980 | t_girl | Sleep | 210 | | NULL |
+----+-------------+---------------------+--------+---------+------+-----------------------------------------------------------------------+------------------+
8 rows in set (0.00 sec)
现在我们来读数据。
mysql> select * from t;
+----+-------+
| id | c_str |
+----+-------+
| 1 | C |
+----+-------+
1 row in set (0.00 sec)
这个数据很明显是来自
C
的。
再插入一条记录
mysql
>
insert
into
t
(
c_str
)
values
(
'wangwei'
);
Query OK
,
1
row
affected
(
0
.
00 sec
)
mysql> select * from t;
+----+-------+
| id | c_str |
+----+-------+
| 1 | C |
+----+-------+
1 row in set (0.00 sec)
C
上的数据没有变。
还是没有数据。
现在跑到
B
上看看。
mysql
>
show
processlist
;
+----+-------------+---------------------+--------+---------+------+-----------------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------------+---------------------+--------+---------+------+-----------------------------------------------------------------------+------------------+
| 2 | system user | | NULL | Connect | 1842 | Has read all relay log; waiting for the slave I/O thread to update it | NULL |
| 5 | root | localhost | t_girl | Query | 0 | NULL | show processlist |
| 12 | t_girl_user | 192.168.0.234:44975 | t_girl | Sleep | 446 | | NULL |
| 13 | t_girl_user | 192.168.0.234:44976 | t_girl | Sleep | 188 | | NULL |
| 14 | t_girl_user | 192.168.0.234:44977 | t_girl | Sleep | 206 | | NULL |
| 15 | t_girl_user | 192.168.0.234:44978 | t_girl | Sleep | 203 | | NULL |
| 16 | t_girl_user | 192.168.0.234:44979 | t_girl | Sleep | 164 | | NULL |
| 17 | t_girl_user | 192.168.0.234:44980 | t_girl | Sleep | 210 | | NULL |
+----+-------------+---------------------+--------+---------+------+-----------------------------------------------------------------------+------------------+
8
rows
in
set
(
0
.
00 sec
)
mysql
>
select
*
from
t
;
+----+----------+
| id | c_str |
+----+----------+
| 1 | B |
| 2 | wangwang |
| 3 | wangwei |
+----+----------+
3
rows
in
set
(
0
.
00 sec
)
本文出自 “峰云,就她了。” 博客,谢绝转载!