記一次 mysqldump 備份數據庫

這幾天公司的一個網站交易了,昨天客戶讓給它數據庫作一下備份,本想用mysqldump就完事了,沒想到趕上一些問題,如下記錄了遇到的問題和解決方法。html

在linux 命令行下執行mysql

mysqldump -h127.0.0.1 -uroot -p密碼  數據庫  > /data/backup/xxx.sql

結果報錯:linux

Warning: Using a password on the command line interface can be insecure.

   緣由是mysql5.6及以上版本不建議在命令行中輸入密碼? 那怎麼解決呢? 百度來的方法說 修改mysql配置文件my.cnf添加 sql

重啓mysql,而後執行數據庫

mysqldump --defaults-extra-file=/etc/my.cnf database > database.sql

沒想到又報錯了0.0。api

Getting mysqldump: got error: 1045: access denied for user 'dev'@'localhost' (using password: YES) when deploying from capistrano task

後來在 stackoverflow 網站上找到一篇相關文章,給出說法是密碼中若是有特殊字符須要加反斜槓,但我試一下並無做用(有待繼續驗證)。 那怎麼辦? 只能跳過帳號密碼驗證了。打開my.cnf 在[mysqld]這個條目下加入skip-grant-tables ,重啓mysql,再執行網站

mysqldump --defaults-extra-file=/etc/my.cnf database > database.sql

能夠導出來。命令行

  導出完畢後別忘了去掉my.cnf 中的skip-grant-tables,並重啓mysqlcode

參考網站:htm

  1. http://www.laozuo.org/6799.html 解決MySQL5.6出現"Using a password on the command line interface..."
  2. https://stackoverflow.com/questions/15424911/getting-mysqldump-got-error-1045-access-denied-for-user-devlocalhost-us Getting mysqldump: got error: 1045: access denied for user 'dev'@'localhost' (using password: YES) when deploying from capistrano task
相關文章
相關標籤/搜索