Created
October 26, 2015 10:24
-
-
Save kittolau/c8be342b5a9761da8ab4 to your computer and use it in GitHub Desktop.
mysql command cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 使用mysqldump 指令備份資料庫,會產生一長串重建資料庫所需的SQL指令... | |
# ( 站長使用 MySQL 5 ) | |
# 產生的指令前面的SET會先存下目前的字集設定,然後將字集改成Unicode(UTF8) <-- 這個方便的是 若要轉移到其他資料庫的話 比較不需要為字集煩惱 | |
# -- 備份某個資料庫 | |
mysqldump -u root -p db_name > backup.sql; | |
# -- 備份資料庫中的某個資料表 | |
mysqldump -u root -p db_name table_name > backup.sql; | |
# -- 備份所有資料庫 | |
mysqldump -u root -p --all-databases > backup.sql; | |
# -- 復原一個資料庫 (需先建好db_name 這個資料庫, 若沒建立請先執行 mysqladmin create db_name 建立即可) | |
mysql -u root -p db_name < backup.sql | |
# -- 復原多個資料庫 ( 因為backup.sql 內已有 CREATE DATABASE指令,因此不需先建DB) | |
mysql -u root -p < backup.sql | |
# 注意: | |
# 因為新版mysqldump預設會使用UTF8,所以還原較沒問題, 若為舊版的mysqldump, 則需要使用--default-character-set 指定字集 | |
mysql -u root -p --default-character-set=latin1 db_name < backup.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mysql -uroot -p$SQLROOTPW |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment