Академический Документы
Профессиональный Документы
Культура Документы
phpMyAdmin can be used to export or backup MySQL databases easily. However, if the database size is very big, it probably wont be a good idea. phpMyAdmin allows users to save database dump as file or display on screen, which involves exporting SQL statements from the server, and transmitting the data across slower network connection or Internet to users computer. This process slow the exporting process, increase database locking time and thus MySQL unavailability, slow the server and may simply crash the Apache HTTPD server if too many incoming web connections hogging the systems resources. The better way to backup and export MySQL database is by doing the task locally on the server, so that the tables data can be instantly dumped on the local disk without delay. Thus export speed will be faster and reduce the time MySQL database or table is locked for accessing. This tutorial is the guide on how to backup (export) and restore (import) MySQL database(s) on the database server itself by using the mysqldump and mysql utilities. There are basically two methods to backup MySQL, one is by copying all table files (*.frm, *.MYD, and *.MYI files) or by using mysqlhotcopy utility, but it only works for MyISAM tables. Below tutorial will concentrate on mysqldump which works for both MyISAM and InnoDB tables.
mysqldump -u username p password -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 p password -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 p password -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 youre 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 p password -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.
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.