XMission Control Panel/Server/MySQLdump

From XMission Wiki
Jump to: navigation, search

What is MySQLdump

MySQLdump is a tool used to dump a database or a collection of databases for backup or transfer to another SQL server. It can be used to migrate databases to and from your Cloud Servers.

Simply put, MySQLdump outputs the SQL statements that were used to create a database, tables and all of the data in the tables. It can output these statements in multiple formats and with more or less output information as needed.


Usage

  • Since mysqldump just outputs SQL statements it is usually helpful to truncate the output to a file. A common mysqldump may look like this:
mysqldump -h'localhost' -u'b_89756' -p 'databasename' > databasename.sql

Looking at this command piece by piece makes it easy to understand.

mysqldump: invokes the mysqldump command
-h: specifies what host to connect to, but is not needed if connecting to localhost. Still we recommend using it to be sure of where content is obtained from
-u: specifies the user to login to mysql as
-p: tells mysql to ask for a password
databasename: specifies which database to dump
> databasename.sql: truncates the output of the mysql command to a file

Switches


Helpful Tips

  • The -D switch can be used to dump a skeleton of a database without any data in it.
  • The --add-drop-table switch will ensure that when the SQL is uploaded to another SQL server it drops the tables before creating them.