Mysql database backup and recovery command mysqldump, source usage, you can refer.
Mysql database backup and recovery command mysqldump, source usage, you can refer.
Restore A Database: mysql-h localhost-u root-p123456 www
Back up a database: mysqldump-h localhost-u root-p123456 www> d: \ www2008-2-26. SQL
// Test in the program
// $ Command = "mysqldump -- opt-h $ dbhost-u $ dbuser-p $ dbpass $ dbname | gzip> $ backupFile ";
$ Command = "mysqldump-h localhost-u root-p123456 guestbook> guestbook2-29. SQL ";
System ($ command );
Echo "success ";
**************************************** ********
Command for backing up MySQL database
Mysqldump-hhostname-uusername-ppassword databasename> backupfile. SQL
Back up the MySQL database in the format of a table with deletion
Backing up a MySQL database is in the format of a table with deletion, so that the backup can overwrite existing databases without the need to manually delete the original database.
Mysqldump -- add-drop-table-uusername-ppassword databasename> backupfile. SQL
Directly compress and back up the MySQL database
Mysqldump-hhostname-uusername-ppassword databasename | gzip> backupfile. SQL .gz
Back up a MySQL database table
Mysqldump-hhostname-uusername-ppassword databasename specific_table1 specific_table2> backupfile. SQL
Back up multiple MySQL databases at the same time
Mysqldump-hhostname-uusername-ppassword-databases databasename1 databasename2 databasename3> multibackupfile. SQL
Back up database structures only
Mysqldump-no-data-databases databasename1 databasename2 databasename3> structurebackupfile. SQL
Back up all databases on the server
Mysqldump-all-databases> allbackupfile. SQL
Command for restoring MySQL database
Mysql-hhostname-uusername-ppassword databasename <backupfile. SQL
Restore a compressed MySQL database
Gunzip <backupfile. SQL .gz | mysql-uusername-ppassword databasename
Transfer database to new server
Mysqldump-uusername-ppassword databasename | mysql-host = *. *-C databasename
Several common use cases:
1. Export the entire database
Mysqldump-u username-p Database Name> exported file name
Mysqldump-u root-p dataname> dataname. SQL
At this time, you will be prompted to enter the password of the root user name. after entering the password, the dataname database will be successfully backed up in the mysql/bin/directory.
2. Export a table
Mysqldump-u user name-p database name Table Name> exported file name
Mysqldump-u root-p dataname users> dataname_users. SQL
3. Export a database structure
Mysqldump-u wcnc-p-d-add-drop-table smgp_apps_wcnc> d: \ wcnc_db. SQL
-D no data-add-drop-table add a drop table before each create statement
4. Import the database
Common source commands
Go to the mysql Database Console,
For example, mysql-u root-p
Mysql> use Database
Then run the source command. The following parameter is the script file (for example,. SQL used here)
Mysql> source d: \ wcnc_db. SQL
Mysqldump supports the following options:
-Add-locks
Add lock tables and unlock table before each TABLE is exported. (To make it faster to insert data to MySQL ).
-Add-drop-table
Add a drop table before each create statement.
-Allow-keywords
Names of columns allowed to be created as keywords. This is done by the table name prefix on each column name.
-C,-complete-insert
Use the complete insert Statement (with the column name ).
-C,-compress
If both the client and server support compression, all information is compressed between the two.
-Delayed
Use the Insert DELAYED command to Insert rows.
-E,-extended-insert
Use the new multiline Insert syntax. (A more compact and faster insert statement is provided)
-#,-Debug [= option_string]
Tracking Program usage (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 options are used with-T options and have the same meaning as the load data infile clause.
Load data infile syntax.
-F,-flush-logs
Wash Out the log files on the MySQL server before starting the export.
-F,-force,
Even if we get an SQL error while exporting 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 start export.
-T,-no-create-info
Create TABLE statement)
-D,-no-data
No row information is written to the table. If you only want to export the structure of a table, this is very useful!
-Opt
Same as-quick-add-drop-table-add-locks-extended-insert-lock-tables.
You should be given the fastest export possible for reading a MySQL server.
-Pyour_pass,-password [= your_pass]
The password used to connect to the server. If you do not specify "= your_pass", mysqldump requires a password from the terminal.
-P port_num,-port = port_num
The TCP/IP Port used to connect to a host. (This is used to connect to a host other than localhost because it uses Unix sockets .)
-Q,-quick
Directly export the data to stdout without buffering the query; Use mysql_use_result () to do it.
-S/path/to/socket,-socket =/path/to/socket
The socket file used when connecting to localhost (which 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 data. Note: This only works when mysqldump runs on the same machine where the mysqld daemon is running .. The format of the txt file is determined by the-fields-xxx and-lines-xxx options.
-U user_name,-user = user_name
The username used by MySQL to connect to the server. The default value is your Unix login name.
-O var = option,-set-variable var = option
Set the value of a variable. Possible variables are listed below.
-V,-verbose
Lengthy mode. Print out more information about the program.
-V,-version
Print the version information and exit.
-W,-where = 'where-condition'
Only selected records are exported. Note that the quotation marks are mandatory!
"-Where = user = 'jimf '" "-wuserid> 1"-wuserid <1 ″
The most common use of mysqldump may make a backup of the entire database:
Mysqldump-opt database> backup-file. SQL
However, it is also useful for enriching another MySQL database with information from one database:
Mysqldump-opt database | mysql-host = remote-host-C database
Mysqldump exports complete SQL statements, so it is easy to import data into mysql client programs:
Shell> mysqladmin create target_db_name
Shell & gt; mysql target_db_name &
Yes
Shell> mysql database name <file name