如何使用mysqldump完成mysql數據庫的備份? 當我進行備份時,我的表只能從指定的數據庫進行備份。程序和功能不是。如何使用mysqldump命令行實用程序完成mysql數據庫的備份
下面是我使用的備份命令:
(操作系統是Windows Vista中。)
mysqldump -u username -p db1 > backup.sql
如何使用mysqldump完成mysql數據庫的備份? 當我進行備份時,我的表只能從指定的數據庫進行備份。程序和功能不是。如何使用mysqldump命令行實用程序完成mysql數據庫的備份
下面是我使用的備份命令:
(操作系統是Windows Vista中。)
mysqldump -u username -p db1 > backup.sql
這取決於你的版本了一下。在5.0.13之前,這對於mysqldump是不可能的。
從mysqldump的手冊頁(V 5.1.30)
--routines, -R
Dump stored routines (functions and procedures) from the dumped
databases. Use of this option requires the SELECT privilege for the
mysql.proc table. The output generated by using --routines contains
CREATE PROCEDURE and CREATE FUNCTION statements to re-create the
routines. However, these statements do not include attributes such
as the routine creation and modification timestamps. This means that
when the routines are reloaded, they will be created with the
timestamps equal to the reload time.
...
This option was added in MySQL 5.0.13. Before that, stored routines
are not dumped. Routine DEFINER values are not dumped until MySQL
5.0.20. This means that before 5.0.20, when routines are reloaded,
they will be created with the definer set to the reloading user. If
you require routines to be re-created with their original definer,
dump and load the contents of the mysql.proc table directly as
described earlier.
使用「-R」備份存儲過程,也請記住,如果你希望你的數據庫的轉儲一致,而其正修改你需要使用--single-transaction
(如果你只備份InnoDB的)或--lock-all-tables
(如果你還需要MyISAM表)
使用以下命令: -
mysqldump <other mysqldump options> --routines > outputfile.sql
如果我們要只備份存儲過程和觸發器,而不是MySQL表和數據,那麼,我們應該運行類似:
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql
如果你需要將它們導入到另一個數據庫/服務器,你將不得不運行類似:
mysql <database> < outputfile.sql
除了--routines標誌,您將需要授予備份用戶權限來讀取存儲過程:
GRANT SELECT ON `mysql`.`proc` TO <backup user>@<backup host>;
我的最小集合的授予權限爲備份用戶有:
GRANT USAGE ON *.* TO ...
GRANT SELECT, LOCK TABLES ON <target_db>.* TO ...
GRANT SELECT ON `mysql`.`proc` TO ...
如果你想充分的備份,即所有的數據庫,程序,例程,事件不中斷任何連接。
mysqldump -u <username> -p -A -R -E --triggers --single-transaction > full_backup.sql
--all-databases
)。確認你想僅對數據庫進行備份。
mysqldump -u <username> -p <Database_Name1><database2> -R -e --triggers --single-transaction > Database_backup.sql
因爲您希望獲取數據庫中特定表的備份。
mysqldump -u <username> -p <database_name> <Table_name> > table_backup.sql
櫃面你想利用數據庫結構的備份纔剛剛--no數據添加到以前的命令。
mysqldump -u [username] –p[password] –-no-data [database_name] > [dump_file.sql]
同樣地,這個工具還有很多選項。更多信息可以在以下鏈接中找到 - mysqldump information
我正在使用MySQL 5.5.40。這個版本有選擇--all-databases
mysqldump -u<username> -p<password> --all-databases --events > /tmp/all_databases__`date +%d_%b_%Y_%H_%M_%S`.sql
此命令將在MySQL服務器的所有數據庫的完整備份文件命名爲當前日期時間。
授予特權,這是我失蹤! +1 – carla 2015-12-17 13:50:58