因为我的数据库很大,并且会实时向数据库插入大量的数据,我担心在做完全备份的时候,会不会因为锁定了表而导致数据无法插入?

解决方案 »

  1.   

    可以通过参数控制--add-locks 这个选项会在INSERT语句中捆上一个LOCK TABLE和UNLOCK TABLE语句。这就防止在这些记录被再次导入数据库时其他用户对表进行的操作如果一定要在服务运行期间备份,请添加 -skip-opt选项,以免造成了锁表。
      

  2.   

    参考一下mySQL的官方文档。http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#backup5.9.1. 数据库备份
    因为MySQL表保存为文件方式,很容易备份。要想保持备份的一致性,对相关表执行LOCK TABLES操作,然后对表执行FLUSH TABLES。参见13.4.5节,“LOCK TABLES和UNLOCK TABLES语法”和13.5.5.2节,“FLUSH语法”。你只需要读锁定;这样当你复制数据库目录中的文件时,允许其它客户继续查询表。需要FLUSH TABLES语句来确保开始备份前将所有激活的索引页写入硬盘。
      

  3.   

    LS所说的应该就是最好的解决方案。
    如果不方便,而且你采用了innodb引擎的话,可以试试single-transaction--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.