The code is as follows |
Copy Code |
Mysqldump-hhostname-uusername-ppassword databasename > Backupfile.sql |
Back up the MySQL database to back up the MySQL database in a format with a delete table in the format with the deleted table, you can have the backup overwrite the existing database without manually deleting the original database.
Mysqldump---add-drop-table-uusername-ppassword databasename > Backupfile.sql to compress and backup MySQL database directly
The code is as follows |
Copy Code |
Mysqldump-hhostname-uusername-ppassword DatabaseName | gzip > backupfile.sql.gz |
Backing up a MySQL database (some) tables
The code is as follows |
Copy Code |
Mysqldump-hhostname-uusername-ppassword databasename specific_table1 specific_table2 > Backupfile.sql |
Backup multiple MySQL databases at the same time
The code is as follows |
Copy Code |
Mysqldump-hhostname-uusername-ppassword--databases databasename1 databasename2 databasename3 > Multibackupfile.sql |
Just back up the database structure
The code is as follows |
Copy Code |
Mysqldump--no-data--databases databasename1 databasename2 databasename3 > Structurebackupfile.sql |
Back up all databases on the server
The code is as follows |
Copy Code |
Mysqldump--all-databases allbackupfile.sql Restore the MySQL database command MySQL database for mysql-hhostname-uusername-ppassword databasename < backupfile.sql restore compression Gunzip < backupfile.sql.gz | Mysql-uusername-ppassword databasename Transfer the database to a new server Mysqldump-uusername-ppassword DatabaseName | MySQL--host=*.*.*.*-c databasename Compressed backup |
Backup and use gzip compression:
The code is as follows |
Copy Code |
mysqldump < mysqldump options> | gzip > outputfile.sql.gz recovery from gzip Backup: Gunzip < outputfile.sql.gz | MySQL < MySQL options> backup and use bZIP compression: mysqldump < mysqldump options> | bzip2 > outputfile.sql.bz2 Restore from bzip2 backup: Bunzip2 < OUTPUTFILE.SQL.BZ2 | MySQL < MySQL options> |
Mysqldump supports the following options:
--add-locks
Add lock tables before each table is exported and then unlock table. (in order to allow faster insertion into MySQL).
--add-drop-table
Add a drop table before each create statement.
--allow-keywords
Allow creation of column names that are keywords. This is done by the table name prefix in each column name.
-C,--complete-insert
Use the full INSERT statement (with the column name).
-C,--compress
If both the client and the server support compression, compress all the information between the two.
--delayed
Inserts a row with the insert delayed command.
-E,--extended-insert
Use the new multiple-line insert syntax. (Gives a tighter and faster insert statement)
-#,--debug[=option_string]
Trace the use of the program (for debugging).
--help
Displays a help message and exits.
--fields-terminated-by= ...
--fields-enclosed-by= ...
--fields-optionally-enclosed-by= ...
--fields-escaped-by= ...
--fields-terminated-by= ...
These selections are used with the-T selection and have the same meaning as the corresponding load DATA infile clause.
The LOAD DATA infile syntax.
-F,--flush-logs
Before you start exporting, wash the log files in the MySQL server.
-F,--force,
Even if we get a SQL error during the export of a table, continue.
----H,--host=.
Export data from the MySQL server on the named host. The default host is localhost.
-L,--lock-tables.
Lock all tables for starting export.
-T,--no-create-info
Do not write table creation information (CREATE TABLE statement)
-D,--no-data
Any row information that does not write to the table. This is useful if you want to export only the structure of a table!
--opt
--extended-insert--lock-tables with--quick--add-drop-table--add-locks.
Should give you the fastest possible export for reading into a MySQL server.
-pyour_pass,--password[=your_pass]
The password to use when connecting to the server. If you do not specify the "=your_pass" section, the mysqldump requires a password from the terminal.
-P Port_num,--port=port_num
The TCP/IP port number to use when connecting to a host. (This is used to connect to a host other than localhost because it uses a UNIX socket.) )
-Q,--quick
Do not buffer queries, export directly to stdout; use Mysql_use_result () to do it.
-s/path/to/socket,--socket=/path/to/socket
The socket file used by the localhost when it is connected (it is the default host).
-T,--tab=path-to-some-directory
For each given table, create a Table_name.sql file that contains the SQL create command, and a table_name.txt file that contains the data. Note: This works only when Mysqldump is running on the same machine that the mysqld daemon is running. The format of the. txt file is based on the--fields-xxx and--LINES--XXX options.
-U user_name,--user=user_name
The user name that MySQL uses when connecting to the server. The default value is your UNIX login name.
-O var=option,--set-variable var=option Sets the value of a variable. The possible variables are listed below.
-V,--verbose
Verbose mode. Print out more information about what the program is doing.
-V,--version
Print version information and exit.
-W,--where=@ #where-condition@#
Only the selected records are exported; Note that the quotation marks are mandatory!
"--where=user=@ #jimf @#" "-wuserid>1" "-wuserid<1"
MySQL Dump/restore
Dump all MySQL Databases
The code is as follows |
Copy Code |
Mysqldump--user=xxxxxxxx--password=xxxxxxx-a >/path/to/dumpfile. Sql
|
Dump individual or multiple MySQL Databases
The code is as follows |
Copy Code |
Mysqldump--user=xxxxxxxx--password=xxxxxxx--databases db_name1 db_name2 db_name3 >/PATH/TO/DUMPFILE. Sql
|
Dump only certain tables from a MySQL Database
The code is as follows |
Copy Code |
Mysqldump--user=xxxxxxxx--password=xxxxxxxx--databases db_name--tables table_name >/PATH/TO/DUMPFILE. Sql
|
I ' m using MySQL 4.1.8 on my development server, but am behind a few releases on our production server. In order to make dumps compatible with the old MySQL version, add the following switch: --compatible=mysql323
- -------------------------------------------------------------------------------
Use the following procedure to Reload the contents of a database:
Unzip The backup file you are wish to use.
Open it up and pull out of the information that you'll need.
Save this text file.
Use the following command to feed back in the contents of a text file:
The code is as follows |
Copy Code |
MySQL--verbose--user=xxxxxxxx--password=xxxxxxxx db_name </path/to/dumpfile. Sql |
Restoring MySQL database.
The Mysqldump utility is used only to take the MySQL dump. To restore the database from the dump file, created in previous, and use the MySQL command.
The code is as follows |
Copy Code |
shell> MySQL--u [username]--password=[password] [database name] < [dump file]
|
Example:
code is as follows |
copy code |
Shell > mysql--user root--password=myrootpassword new_db < db_test.sql |