How to Backup and Restore (Export and Import) MySQL Databases » -::: MITRAMSI :::-

Control Panel


Login Panel!


 
Register Forgot your password
User Panel
Navigation on the site: MitraMSI » Tutorial » How to Backup and Restore (Export and Import) MySQL Databases

Navitgation

Top News

Calendar

Our Friends

How to Backup and Restore (Export and Import) MySQL Databases Category: Tutorial
Added: 19 January 2011

How to Export or Backup or Dump A MySQL Database

To export a MySQL database into a dump file, simply type the following command syntax in the shell. You can use Telnet or SSH to remotely login to the machine if you don’t have access to the physical box.

mysqldump -u username -ppassword database_name > dump.sql

Replace username with a valid MySQL user ID, password with the valid password for the user (IMPORTANT: no space after -p and the password, else mysqldump will prompt you for password yet will treat the password as database name, so the backup will fail) and database_name with the actual name of the database you want to export. Finally, you can put whatever name you like for the output SQL dump file, here been dump.sql.

The while data, tables, structures and database of database_name will be backed up into a SQL text file named dump.sql with the above command.

How to Export A MySQL Database Structures Only

If you no longer need the data inside the database’s tables (unlikely), simply add –no-data switch to export only the tables’ structures. For example, the syntax is:

mysqldump -u username -ppassword –no-data database_name > dump.sql

How to Backup Only Data of a MySQL Database

If you only want the data to be backed up, use –no-create-info option. With this setting, the dump will not re-create the database, tables, fields, and other structures when importing. Use this only if you pretty sure that you have a duplicate databases with same structure, where you only need to refresh the data.

mysqldump -u username -ppassword –no-create-info database_name > dump.sql

How to Dump Several MySQL Databases into Text File

–databases option allows you to specify more than 1 database. Example syntax:

mysqldump -u username -ppassword –databases db_name1 [db_name2 ...] > dump.sql

How to Dump All Databases in MySQL Server

To dump all databases, use the –all-databases option, and no databases’ name need to be specified anymore.

mysqldump -u username -ppassword –all-databases > dump.sql

How to Online Backup InnoDB Tables

Backup the database inevitable cause MySQL server unavailable to applications because when exporting, all tables acquired a global read lock using FLUSH TABLES WITH READ LOCK at the beginning of the dump until finish. So although READ statements can proceed, all INSERT, UPDATE and DELETE statements will have to queue due to locked tables, as if MySQL is down or stalled. If you’re using InnoDB, –single-transaction is the way to minimize this locking time duration to almost non-existent as if performing an online backup. It works by reading the binary log coordinates as soon as the lock has been acquired, and lock is then immediately released.

Syntax:

mysqldump -u username -ppassword –all-databases –single-transaction > dump.sql

How to Restore and Import MySQL Database

You can restore from phpMyAdmin, using Import tab. For faster way, upload the dump file to the MySQL server, and use the following command to import the databases back into the MySQL server.

mysql -u username -ppassword database_name < dump.sql

The import and export of MySQL database not only is important to recover the data when disaster strikes, but also provides an easy way to migrate or move to another server, such as when switching web hosting providers. However, do note that one common problem – character set encoding. Newer release of mysqldump uses UTF8 as its default charset if nothing is specified, while older versions (older than 4.1 typically) use Latin1 as default characterset. If you database charset is Latin1 and dump in UTF8 collation, the data may ends up become simply rubbish, garbled, or unreadable (frequently happen with Wordpress blog). If this case, use –default-character-set=charset_name option to specify the character set or convert the database to UTF8.



Key tags : backup, 00 export MySQL database
Dear visitor, you went to the site as unregistered user. to register (it only takes 1 minute), or enter the site under your login.

Other publications on the topic:


Author: mas_sas    Views: 2032 Comments: 0 Print
Information
   Members of Guest cannot leave comments.
Ïîäïèñàòüñÿ íà íîâîñòè

Site Info

Articles
Top Contributors:
  1    mas_sas 277
  2    mitramsi 210
  3    brigs 67
  4    vint57 25
  5    kangmas 15
  6    odobbybix 15
  7    ynior07 9
  8    seregarulit 8
  9    KIN 8
  10    post78962 7
  11    emmet24son 3
  12    sn2012 2
  13    msidot 1
  14    qwert777 1
  15    vipmoneys2012 1
  16    shino 1
  17    SuperNews2011 1
  18    dlavzroslihhh 1
  19    andersen 1
  20    tahumie87 1


Articles:
  This Hour: 0
  Today: 2
  This Month: 18
  All Time: 656


Membership:
  Registered Today :143
  This Hour:19
  This Month:3408
  Total:35440
  Banned:0

User
Online Users: 9

Visit
Today Visits: 10184
This Week Visits: 32328
This Month Visits: 253705
This Year Visits: 1514789
All Visits: 3792555
Record: 26355 In 27.06.2011

Latest News

Referer

Google: mitrams69
Google: motherboard
Google: Powered by Article Dashboard samsung product suppo...
Google: Powered by Article Dashboard brothers in arms onli...
Google: Powered by Article Dashboard art glass windows
Google: mini+pci-e
Google: Powered by Article Dashboard 151st regional suppor...
Google: Powered by Article Dashboard radio controlled rigs
Google: Powered by Article Dashboard reinstall sound card
Google: pt. alfa artha andhaya
Google: Powered by Article Dashboard $20 entertainment boo...
Google: Powered by Article Dashboard 3800 performance part...
Google: Powered by Article Dashboard 580 am radio
Google: Powered by Article Dashboard you belong with me mu...
Google: Powered by Article Dashboard bluetooth audio recei...
Google: Powered by Article Dashboard cf card gps receiver
Google: Powered by Article Dashboard movies #16
Google: Powered by Article Dashboard movies #16
Yahoo!: amd phenom II kombinasi Nvidia Gforce
Google: Powered by Article Dashboard receiver reviews
Google: Powered by Article Dashboard hitch receiver
Google: Powered by Article Dashboard 740 am radio
Google: Powered by Article Dashboard comcast hd receiver
Google: Powered by Article Dashboard onkyo receivers
Google: Powered by Article Dashboard best long-distance tv...
Google: Powered by Article Dashboard receiver hitch adapte...
Yndex.ru: mitramsi.com
Google: Powered by Article Dashboard trade show display sy...
Google: Powered by Article Dashboard surround sound instal...
Google: Powered by Article Dashboard first television tran...
Google: Powered by Article Dashboard comcast hd cable box
Google: Powered by Article Dashboard movies of 2005
Google: Powered by Article Dashboard engine mod
Google: unlock phenom x2 550 ms-7599
Google: Powered by Article Dashboard totally off topic
Google: Powered by Article Dashboard way off topic
Google: Powered by Article Dashboard horsepower rating
Google: core i5 stats
Google: how to clear the cmos on an msi 785gtm-e45
Google: board msi 785gtm-e45
Google: Powered by Article Dashboard yahoo games collapse
Google: basement+home+theater+pictures
Google: Powered by Article Dashboard the game of bridge qu...
Google: Powered by Article Dashboard ing direct
Google: Powered by Article Dashboard toys rus
Google: Powered by Article Dashboard multi member online r...
Google: Powered by Article Dashboard mountain view center ...
Google: Powered by Article Dashboard roleplaying topics
Google: Powered by Article Dashboard recalled toys forum
Google: Powered by Article Dashboard gambling losses
Theme Created by Arya.
Copyright 2009-10 MitraMSI.com. All Rights Reserved.