• 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。

    -

  • 相关阅读:
    Vue在移动端App中使用的问题总结
    CSS中的自适应单位vw、vh、vmin、vmax
    sass、less中的scoped属性
    CSS中的 , > + ~
    Git 使用的问题总结
    Vux的安装使用
    React-router的基本使用
    React使用的扩展
    React使用的思考总结
    React的基本使用
  • 原文地址:https://www.cnblogs.com/zhxiaoxiao/p/10521186.html
Copyright © 2020-2023  润新知