【转】mysql只读模式的设置方法与实验
时间:2021-07-01 10:21:17
帮助过:5人阅读
- (test01@172.32.1.200) [data03]> show tables;
- +------------------+
- | Tables_in_data03 |
- +------------------+
- | t01 |
- | t02 |
- | user |
- +------------------+
- 3 rows in set (0.00 sec)
-
- (test01@172.32.1.200) [data03]>
- (test01@172.32.1.200) [data03]>
- (test01@172.32.1.200) [data03]> show global variables like "%read_only%";
- +------------------+-------+
- | Variable_name | Value |
- +------------------+-------+
- | innodb_read_only | OFF |
- | read_only | ON |
- | tx_read_only | OFF |
- +------------------+-------+
- 3 rows in set (0.00 sec)
-
- (test01@172.32.1.200) [data03]>
- (test01@172.32.1.200) [data03]>
- (test01@172.32.1.200) [data03]> delete from t01 where id1=3;
- <span style="color:#ff0000;">ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement</span>
- (test01@172.32.1.200) [data03]> update t01 set id1=id1+30 where id1=3;
- ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement
- (test01@172.32.1.200) [data03]> insert into t01(id1,a1,b1) values(9,9,9);
- ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement
- (test01@172.32.1.200) [data03]>
- (test01@172.32.1.200) [data03]> select * from t01;
- +-----+------+------+
- | id1 | a1 | b1 |
- +-----+------+------+
- | 1 | 1 | 1 |
- | 2 | 2 | 2 |
- | 4 | 4 | 4 |
- | 5 | 5 | 5 |
- | 6 | 6 | 6 |
- +-----+------+------+
- 5 rows in set (0.00 sec)
-
- (test01@172.32.1.200) [data03]>
实验二:设定了全局读写后,具有super权限的用户进行数据修改后,也会提示错误ERROR 1223:
[html] view plain
copy
- mysql> use data03;
- 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_data03 |
- +------------------+
- | t01 |
- | t02 |
- | user |
- +------------------+
- 3 rows in set (0.00 sec)
-
- mysql> select * from t01;
- +-----+------+------+
- | id1 | a1 | b1 |
- +-----+------+------+
- | 1 | 1 | 1 |
- | 2 | 2 | 2 |
- | 4 | 4 | 4 |
- | 5 | 5 | 5 |
- | 6 | 6 | 6 |
- +-----+------+------+
- 5 rows in set (0.00 sec)
-
- mysql>
- mysql> show global variables like "%read_only%";
- +------------------+-------+
- | Variable_name | Value |
- +------------------+-------+
- | innodb_read_only | OFF |
- | read_only | ON |
- | tx_read_only | OFF |
- +------------------+-------+
- 3 rows in set (0.00 sec)
-
- mysql>
- mysql>
- mysql> insert into t01(id1,a1,b1) values(8,8,8);
- Query OK, 1 row affected (0.00 sec)
-
- mysql> update t01 set a1=a1+10 where id1=2;
- Query OK, 1 row affected (0.00 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
-
- mysql> delete from t01 where id1=4;
- Query OK, 1 row affected (0.00 sec)
-
- mysql> select * from t01;
- +-----+------+------+
- | id1 | a1 | b1 |
- +-----+------+------+
- | 1 | 1 | 1 |
- | 2 | 12 | 2 |
- | 5 | 5 | 5 |
- | 6 | 6 | 6 |
- | 8 | 8 | 8 |
- +-----+------+------+
- 5 rows in set (0.00 sec)
-
- mysql>
- mysql> flush tables with read lock;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql>
- mysql> insert into t01(id1,a1,b1) values(9,9,9);
- <span style="color:#ff0000;">ERROR 1223 (HY000): Can‘t execute the query because you have a conflicting read lock</span>
- mysql>
- mysql> update t01 set a1=a1+10 where id1=5;
- ERROR 1223 (HY000): Can‘t execute the query because you have a conflicting read lock
- mysql>
- mysql> delete from t01 where id1=5;
- ERROR 1223 (HY000): Can‘t execute the query because you have a conflicting read lock
- mysql>
- mysql>
实验三:MySQL从库设定read_only=1后主从同步正常,设定表读锁后,不能同步,解除读锁后,主从同步恢复。
[html] view plain
copy
- mysql>
- mysql> show databases;
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | bitvc |
- | data03 |
- | ga |
- | jiradb |
- | meibi |
- | meibi02 |
- | mysql |
- | performance_schema |
- | sbtest |
- +--------------------+
- 10 rows in set (0.00 sec)
-
- mysql>
- mysql>
- mysql>
- mysql> show global variables like "%read_only%";
- +------------------+-------+
- | Variable_name | Value |
- +------------------+-------+
- | innodb_read_only | OFF |
- | read_only | ON |
- | tx_read_only | OFF |
- +------------------+-------+
- 3 rows in set (0.00 sec)
-
- mysql>
- mysql> show slave status\G
- *************************** 1. row ***************************
- Slave_IO_State: Waiting for master to send event
- Master_Host: 172.32.1.200
- Master_User: repl
- Master_Port: 3307
- Connect_Retry: 60
- Master_Log_File: mysql-bin.000009
- Read_Master_Log_Pos: 5853
- Relay_Log_File: huobiDBtest-relay-bin.000002
- Relay_Log_Pos: 6016
- Relay_Master_Log_File: mysql-bin.000009
- Slave_IO_Running: Yes
- Slave_SQL_Running: Yes
- Replicate_Do_DB:
- Replicate_Ignore_DB:
- Replicate_Do_Table:
- Replicate_Ignore_Table:
- Replicate_Wild_Do_Table:
- Replicate_Wild_Ignore_Table:
- Last_Errno: 0
- Last_Error:
- Skip_Counter: 0
- Exec_Master_Log_Pos: 5853
- Relay_Log_Space: 6195
- Until_Condition: None
- Until_Log_File:
- Until_Log_Pos: 0
- Master_SSL_Allowed: No
- Master_SSL_CA_File:
- Master_SSL_CA_Path:
- Master_SSL_Cert:
- Master_SSL_Cipher:
- Master_SSL_Key:
- Seconds_Behind_Master: 0
- Master_SSL_Verify_Server_Cert: No
- Last_IO_Errno: 0
- Last_IO_Error:
- Last_SQL_Errno: 0
- Last_SQL_Error:
- Replicate_Ignore_Server_Ids:
- Master_Server_Id: 2003307
- Master_UUID: 6f68eea7-76e9-11e4-8f99-00221904cd5d
- Master_Info_File: /data/mysqldata/3308/data/master.info
- SQL_Delay: 0
- SQL_Remaining_Delay: NULL
- Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
- Master_Retry_Count: 86400
- Master_Bind:
- Last_IO_Error_Timestamp:
- Last_SQL_Error_Timestamp:
- Master_SSL_Crl:
- Master_SSL_Crlpath:
- Retrieved_Gtid_Set:
- Executed_Gtid_Set:
- Auto_Position: 0
- 1 row in set (0.00 sec)
-
- mysql>
- mysql> flush tables with read lock;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> show slave status\G
- *************************** 1. row ***************************
- Slave_IO_State: Waiting for master to send event
- Master_Host: 172.32.1.200
- Master_User: repl
- Master_Port: 3307
- Connect_Retry: 60
- <span style="color:#ff0000;"> Master_Log_File: mysql-bin.000009
- Read_Master_Log_Pos: 6531</span>
- Relay_Log_File: huobiDBtest-relay-bin.000002
- Relay_Log_Pos: 6016
- Relay_Master_Log_File: mysql-bin.000009
- Slave_IO_Running: Yes
- Slave_SQL_Running: Yes
- Replicate_Do_DB:
- Replicate_Ignore_DB:
- Replicate_Do_Table:
- Replicate_Ignore_Table:
- Replicate_Wild_Do_Table:
- Replicate_Wild_Ignore_Table:
- Last_Errno: 0
- Last_Error:
- Skip_Counter: 0
- <span style="color:#ff0000;"> Exec_Master_Log_Pos: 5853</span>
- Relay_Log_Space: 6873
- Until_Condition: None
- Until_Log_File:
- Until_Log_Pos: 0
- Master_SSL_Allowed: No
- Master_SSL_CA_File:
- Master_SSL_CA_Path:
- Master_SSL_Cert:
- Master_SSL_Cipher:
- Master_SSL_Key:
- Seconds_Behind_Master: 120
- Master_SSL_Verify_Server_Cert: No
- Last_IO_Errno: 0
- Last_IO_Error:
- Last_SQL_Errno: 0
- Last_SQL_Error:
- Replicate_Ignore_Server_Ids:
- Master_Server_Id: 2003307
- Master_UUID: 6f68eea7-76e9-11e4-8f99-00221904cd5d
- Master_Info_File: /data/mysqldata/3308/data/master.info
- SQL_Delay: 0
- SQL_Remaining_Delay: NULL
- Slave_SQL_Running_State: Waiting for global read lock
- Master_Retry_Count: 86400
- Master_Bind:
- Last_IO_Error_Timestamp:
- Last_SQL_Error_Timestamp:
- Master_SSL_Crl:
- Master_SSL_Crlpath:
- Retrieved_Gtid_Set:
- Executed_Gtid_Set:
- Auto_Position: 0
- 1 row in set (0.00 sec)
-
- mysql>
- mysql>
- mysql> select * from data03.t01;
- +-----+------+------+
- | id1 | a1 | b1 |
- +-----+------+------+
- | 1 | 1 | 1 |
- | 2 | 2 | 2 |
- | 4 | 4 | 4 |
- | 5 | 5 | 5 |
- | 6 | 6 | 6 |
- +-----+------+------+
- 5 rows in set (0.00 sec)
-
- mysql>
- mysql> unlock tables;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> show slave status\G
- *************************** 1. row ***************************
- Slave_IO_State: Waiting for master to send event
- Master_Host: 172.32.1.200
- Master_User: repl
- Master_Port: 3307
- Connect_Retry: 60
- <span style="color:#ff0000;"> Master_Log_File: mysql-bin.000009
- Read_Master_Log_Pos: 6531</span>
- Relay_Log_File: huobiDBtest-relay-bin.000002
- Relay_Log_Pos: 6694
- Relay_Master_Log_File: mysql-bin.000009
- Slave_IO_Running: Yes
- Slave_SQL_Running: Yes
- Replicate_Do_DB:
- Replicate_Ignore_DB:
- Replicate_Do_Table:
- Replicate_Ignore_Table:
- Replicate_Wild_Do_Table:
- Replicate_Wild_Ignore_Table:
- Last_Errno: 0
- Last_Error:
- Skip_Counter: 0
- <span style="color:#ff0000;"> Exec_Master_Log_Pos: 6531</span>
- Relay_Log_Space: 6873
- Until_Condition: None
- Until_Log_File:
- Until_Log_Pos: 0
- Master_SSL_Allowed: No
- Master_SSL_CA_File:
- Master_SSL_CA_Path:
- Master_SSL_Cert:
- Master_SSL_Cipher:
- Master_SSL_Key:
- Seconds_Behind_Master: 0
- Master_SSL_Verify_Server_Cert: No
- Last_IO_Errno: 0
- Last_IO_Error:
- Last_SQL_Errno: 0
- Last_SQL_Error:
- Replicate_Ignore_Server_Ids:
- Master_Server_Id: 2003307
- Master_UUID: 6f68eea7-76e9-11e4-8f99-00221904cd5d
- Master_Info_File: /data/mysqldata/3308/data/master.info
- SQL_Delay: 0
- SQL_Remaining_Delay: NULL
- Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
- Master_Retry_Count: 86400
- Master_Bind:
- Last_IO_Error_Timestamp:
- Last_SQL_Error_Timestamp:
- Master_SSL_Crl:
- Master_SSL_Crlpath:
- Retrieved_Gtid_Set:
- Executed_Gtid_Set:
- Auto_Position: 0
- 1 row in set (0.00 sec)
-
- mysql> select * from data03.t01;
- +-----+------+------+
- | id1 | a1 | b1 |
- +-----+------+------+
- | 1 | 1 | 1 |
- | 2 | 12 | 2 |
- | 5 | 5 | 5 |
- | 6 | 6 | 6 |
- | 8 | 8 | 8 |
- +-----+------+------+
- 5 rows in set (0.00 sec)
【转】mysql只读模式的设置方法与实验
标签:man nod key 关系 mat 知识库 insert target trie