mysql dump --single transaction 命令

一、

mysql打开general log的办法
 
mysql打开general log之后,所有的查询语句都可以在general log
文件中以可读的方式得到,但是这样general log文件会非常大,所以默认
都是关闭的。有的时候为了查错等原因,还是需要暂时打开general log的。 
 www.2cto.com  
 
mysql@localhost.(none)>show global variables like "%genera%";
+------------------+------------------------------+
| Variable_name | Value |
+------------------+------------------------------+
| general_log | OFF |
| general_log_file | /data1/mysql9999/etch171.log |
+------------------+------------------------------+
2 rows in set (0.00 sec)
 
mysql@localhost.(none)>set global general_log=on;
Query OK, 0 rows affected (0.02 sec)
 
mysql@localhost.(none)>set global general_log=off;
Query OK, 0 rows affected (0.00 sec)
二、--single transaction命令的解释

mysqldump :
--single-transaction 
                      Creates a consistent snapshot by dumping all tables in a
                      single transaction. Works ONLY for tables stored in
                      storage engines which support multiversioning (currently
                      only InnoDB does); the dump is NOT guaranteed to be
                      consistent for other storage engines. While a
                      --single-transaction dump is in process, to ensure a
                      valid dump file (correct table contents and binary log
                      position), no other connection should use the following
                      statements: ALTER TABLE, DROP TABLE, RENAME TABLE,
                      TRUNCATE TABLE, as consistent snapshot is not isolated
                      from them. Option automatically turns off --lock-tables.

 创建一个一致性的快照通过dump 所有的表到一个单独的transaction.

只能用于支持多版本的(目前只有InnoDB)

对他的存储引擎 dump 是不能保证一直的。 当带上了 --single-transaction参数,

确保一个正确的dump 文件(正确的表内容和binary log 位置)

 没有其他的连接来使用下面的语句;ALTER TABLE,DROP TABLE,RENAME TABLE ,TRUNCATE TABLE

 [mysql@master ~]$ mysqldump  test t3 >t3.sql

 mysql> insert into t3 values(25255,'a','a','20110101')

    -> ; --HANG

默认锁表:

 [mysql@master ~]$ mysqldump  --single-transaction  test t3 >t3.sql

mysql> insert into t3 values(25255,'a','a','20110101');
Query OK, 1 row affected (0.10 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)

---可以看到加了 --single-transaction 参数后就可以进行insert 操作

表是可以 update, insert, delete, select 表中的数据的,

只是不能 ALTER TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE, 就是说锁是在表级别的,不能修改数据库表

的结构而已

[mysql@master ~]$ mysqldump  --single-transaction  test t3 >t3.sql

 alter table t3  modify column name varchar(50); --此时HANG。

-

转载于:https://www.cnblogs.com/zhxiaoxiao/p/10521186.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值