How to Backup and Restore (Export and Import) MySQL Databases Tutorial如何备份和恢复(出口和进口)的MySQL数据库补习
phpMyAdmin can be used to export or backup MySQL databases easily. phpmyadmin可以用来出口或备份的MySQL数据库容易。 However, if the database size is very big, it probably won’t 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 user’s computer. phpmyadmin允许用户保存数据库转储文件或显示在屏幕上,其中涉及出口的SQL语句,从服务器,并转递数据慢,网络连接或互联网用户的计算机上。 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 system’s resources.这个过程缓慢,出口过程中,增加数据库锁定时间,从而MySQL的欠缺,缓慢服务器和可能只是坠毁的Apache的httpd服务器如果有太多传入的Web连接荒加工系统的资源。
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.该更好的方式来备份和出口MySQL数据库是这样做的任务,本地的服务器上,因此该表的数据可以即时弃置于本地磁盘,以免延误。 Thus export speed will be faster and reduce the time MySQL database or table is locked for accessing.因此,出口速度将更快的时间缩短MySQL数据库或表锁定访问。 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.本教程是指导就如何备份(出口)和恢复(进口) MySQL数据库( )对数据库服务器本身的使用mysqldump与MySQL事业。 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.有基本上是两种方法来备份MySQL的,一个是由复制所有表文件( *. frm , *. myd , *. myi文件) ,或使用mysqlhotcopy实用工具,但它仅适用于myisam表。 Below tutorial will concentrate on mysqldump which works for both MyISAM and InnoDB tables.下面的教程将集中在mysqldump ,其中工程都myisam和InnoDB表。
How to Export or Backup or Dump A MySQL Database 如何导出或备份或转储一个MySQL数据库
To export a MySQL database into a dump file, simply type the following command syntax in the shell.出口MySQL数据库成为一个转储文件,只需键入以下命令语法在蚬壳公司。 You can use Telnet or SSH to remotely login to the machine if you don’t have access to the physical box.您可以使用Telnet或SSH远程登录到机器如果您还没有接触到身体中。
mysqldump -u username -p password database_name > dump.sql mysqldump中美用户名 - 密码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.取代使用者名称与一个有效的MySQL用户ID , 密码与有效的用户的密码(重要:没有空间后- P和密码,否则, mysqldump会提示您密码,但对待的密码资料库名称,因此,备份将失败)和database_name与实际资料库的名称,您要汇出。 Finally, you can put whatever name you like for the output SQL dump file, here been dump.sql .最后,您可以放置任何您喜欢的名称为输出的SQL转储文件,在这里被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.同时,资料,统计表,结构和数据库database_name将备份到一个SQL的文本文件,命名为dump.sql与上述命令。
How to Export A MySQL Database Structures Only 如何导出一个MySQL数据库结构,只有
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 -p password –no-data database_name > dump.sql mysqldump中美用户名 - 密码 -无数据database_name > dump.sql
How to Backup Only Data of a MySQL Database 如何备份数据只有一个MySQL数据库
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 -p password –no-create-info database_name > dump.sql mysqldump中美用户名 - 密码 -没有创建-信息database_name > dump.sql
How to Dump Several MySQL Databases into Text File 如何转储几个MySQL的数据库到文本文件
–databases option allows you to specify more than 1 database. -数据库选项可让您指定多于1数据库。 Example syntax:例如语法:
mysqldump -u username -p password –databases db_name1 [db_name2 ...] > dump.sql mysqldump中美用户名 - 密码 -数据库db_name1 [ db_name2 ... ] > dump.sql
How to Dump All Databases in MySQL Server 如何转储所有数据库在MySQL服务器
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 mysqldump中美用户名 - 密码 -所有-数据库> dump.sql
How to Online Backup InnoDB Tables 如何联机备份InnoDB表
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.备份数据库的必然原因MySQL服务器无法申请,因为当出口国,所有表格,获得了全球读锁使用冲水表读锁定在开始转储,直到完成。 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.所以,虽然读报表可以进行,所有的INSERT , UPDATE和DELETE语句将有排队,由于锁定表,如果MySQL的下降或停滞不前。 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.如果您使用的InnoDB软件, 单交易的方式,以尽量减少锁定时间,这时间,以几乎不存在,因为如果执行联机备份。 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 mysqldump中美用户名 - 密码 -所有-数据库-单交易> dump.sql
How to Restore and Import MySQL Database 如何恢复和进口MySQL数据库
You can restore from phpMyAdmin, using Import tab.您可以恢复从phpmyadmin ,使用进口标签。 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服务器,并使用下列命令导入数据库回复到MySQL服务器。
mysql -u username -p password database_name < dump.sql MySQL的中美用户名 - 密码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.进口和出口MySQL数据库不仅是重要的是要恢复数据灾难时的罢工,但也提供一个简单的方式迁移或移动到另一台服务器,如切换时的Web托管服务提供商。 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.较新版本的mysqldump使用utf8进行其默认的字符集,如果没有指定,而旧版本(年纪比4.1通常)使用以latin1作为默认的字符集。 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).如果您的数据库字符集是拉丁文和转储在utf8进行整理,该数据可能最终成为纯粹的垃圾,乱码,或无法读取(经常发生的WordPress所博客) 。 If this case, use –default-character-set=charset_name option to specify the character set or如果这种情况下,使用默认的字符集= charset_name选项来指定字符集或 convert the database to UTF8转换数据库,以utf8进行 . 。
IMPORTANT : This is a machine translated page which is provided "as is" without warranty. 重要说明 :这是一个机器翻译网页是“按原样”提供的担保。 Machine translation may be difficult to understand.机器翻译可能很难理解。 Please refer to请参阅 original English article英文原版的文章 whenever possible.只要有可能。
Share and contribute or get technical support and help at分享和贡献,或取得技术的支持和帮助,在 My Digital Life Forums 我的数字生活论坛 . 。
Related Articles相关文章
- Restore Full Backup or cpmove File in cPanel Web Host恢复完整备份或cpmove文件中的cPanel Web主机
- How to Export Firefox Bookmarks to IE Internet Explorer Favorites (or Import From)如何导出Firefox书签IE浏览器Internet Explorer收藏夹(或进口)
- IMP-00013 Oracle Import Error进出口- 00013甲骨文进口错误
- IMP-00016 Required Character Set Conversion Not Supported Error when Import to Oracle Database进出口- 00016所需的字符集转换不支持时出现错误,导入到Oracle数据库
- Check and Optimize MySQL Database Automatically with Crontab/Cron检查和优化MySQL数据库自动与crontab /玉米
- MySQL Database Performance Tuning Best Practices Video Tutorial MySQL数据库性能调整的最佳做法视频教程
- Export, Backup or Copy Out the IE7 Search Providers List出口,备份或复制出的IE7搜索服务提供商名单
- Backup an iTunes Playlist备份iTunes播放列表
- Oracle EXP-00091 Error When Export Database甲骨文进出口- 00091时发生错误,进出口数据库
- Firefox Passwords Exporter and Importer (also for Thunderbird, Songbird and Flock) Firefox的密码,出口商和进口商的(也为雷鸟,鸣禽和羊群)



















January 26th, 2008 01:32 2008年1月26日1时32分
Nice post..尼斯邮政.. I usually just copy the files..我通常只是将文件复制.. for temporary..临时.. and get all mysql queries for permanent backup..并让所有的MySQL查询永久备份..
February 4th, 2008 12:48 2008年2月4日12时48分
It shows how to backup all-databases… but how to restore all of them at once from the same file?它显示了如何备份所有数据库… …但如何还原他们都在一次由相同的档案? … I tried restoring the same way but receive a msg: unknown database: all-databases (I’ve done it before but I forget, it’s been a while… I’ll keep looking around) … …我试图恢复相同的方式,但收到消息:未知数据库:所有数据库(我已经这样做之前,但我忘记了,这是一个虽然… …我将继续环顾)
February 4th, 2008 13:17 2008年2月4日13时17分
mysql -u root -p < all-databases.sql MySQL的中美根- P的<全databases.sql
done.做完。
February 6th, 2008 03:43 2008年2月6日3时43分
mysqldump worked.工作mysqldump 。
But ‘mysql’ to import data did not.但' MySQL的'导入数据没有。 The error is:错误是:
ERROR at line 1: Unknown command ‘\m’误差在1号线:未知命令' \米'
any ideas?任何想法?
February 16th, 2008 02:46 2008年2月16日2时46分
thanks alot ..感谢了很多.. you saved my time and money both ..你救了我时间和金钱都.. hat off to you .小康的帽子,给您。
April 14th, 2008 16:31 2008年4月14日16时31分
Good post.良好的职位。 But you can add some advanced tips to it, to make it better.但您可以添加一些先进的秘诀,到它,让它变得更加完美。 Goog luck! goog运气!
May 27th, 2008 23:45 2008年5月27日23时45分
Good post, but what about backing up the mysql users them selves?良好的职位,但如何备份MySQL的用户,他们守土有责?
July 21st, 2008 07:57 2008年7月21日7时57分
[...] Enlace [...] [ … … ] enlace [ … … ]