MySQL資料庫及表的備份與還原,mysqlDatabase Backup

來源:互聯網
上載者:User

MySQL資料庫及表的備份與還原,mysqlDatabase Backup
備份

匯出資料庫所有表結構

mysqldump -uroot -ppassword -d dbname > db.sql

匯出資料庫某個表結構

mysqldump -uroot -ppassword -d dbname tablename > db.sql

匯出資料庫所有表結構及資料

mysqldump -uroot -ppassword dbname > db.sql

匯出資料庫某個表結構及資料

mysqldump -uroot -ppassword dbname tablename > db.sql

匯出部分資料

--where="條件"mysqldump -uroot -ppassword dbname tablename -w "條件" > db.sql

-w或–where,條件一定要用雙引號包圍,單引號不行。

注意
匯出資料不需要-d

可能會出現如下錯誤

mysqldump: Got error 1044: Access denied for use ‘zndw’@’localhost’ to database ‘scilibrary’ when doing LOCK TABLES

出現這個錯誤的原因是該使用者無lock tables許可權。

解決辦法
(1) 給該使用者賦予lock tables許可權
(2) 加上--skip-lock-tables,如

mysqldump -uroot -ppassword dbname --skip-lock-tables > db.sql
匯入
source xxx.sql

(1) 語句後面不能有分號;
(2) 使用者要有insert等許可權

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.