MySQL backup - How to backup a MySQL database

來源:互聯網
上載者:User

標籤:

 

MySQL backup FAQ: How do I backup a MySQL database?

I can‘t speak about backing up MySQL databases that are modified twenty-four hours a day seven days a week, but on all the MySQL databases I currently work with, there are always times when I can guarantee that there won‘t be any SQL INSERTs, DELETEs, or UPDATEs occurring, so I find it‘s really easy to perform a MySQL backup using the mysqldump utility program. Here‘s how it works.

Create a MySQL backup with mysqldump

I was just working on a Drupal database, and decided that I wanted to make a backup of Drupal‘s MySQL database before I did something that might screw up the database (converting a WordPressdatabase to a Drupal database). So, I made a backup of my current MySQL Drupal database using the following mysqldump command:

mysqldump --opt --user=root --password drupaldb > drupaldb-20090505.sql

  

Note that in this command, drupaldb is the name of my database, not the password. The --passwordargument just tells MySQL to prompt me for the password, because I don‘t want to type it right here on the command line. So, immediately after I enter that command, MySQL prompts me for the rootuser‘s password, like this:

Enter password: _

  

Once I enter that password, my drupaldb database is dumped to a file in the current directory nameddrupaldb-20090505.sql.

MySQL backup - A slightly different syntax

Note that you can also enter your mysqldump command as shown next, which is equivalent to the previous command:

mysqldump --opt -u root -p drupaldb > drupaldb-20090505.sql

  

In both of these examples, the 20090505 portion of the filename just indicates today‘s date, May 5, 2009. (Happy Cinco de Mayo. :)

MySQL backup - The general form of mysqldump

That was one specific example of the mysqldump command. The general form of the backup command is shown here:

mysqldump --opt -u username -p database-name > backup-file-name

  

where:

  • username can be root, if you know the root password, or it can be the name of the MySQL user that owns your database.
  • database-name is the name of your database, which in my case was drupaldb.
  • backup-file-name is the name of the backup file you want to create. This will be a plain text file that the mysqldump command creates for you.
MySQL database backup shell script

I just created a new MySQL database backup (dump) shell script to automate MySQL backups. In addition to creating this shell script, I‘ve added new MySQL command line options not shown in this example. If you need to use additional mysqldump command line options, see that article for more information.

 

MySQL backup - How to backup a MySQL database

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.