复制 MySQL 数据库的最简单方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1586911/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easiest way to copy a MySQL database?
提问by igul222
Does anyone know of an easy way to copy a database from one computer to a file, and then import it on another computer?
有谁知道一种将数据库从一台计算机复制到文件,然后将其导入另一台计算机的简单方法?
回答by James McNellis
Here are a few options:
这里有几个选项:
mysqldump
转储
The easiest, guaranteed-to-work way to do it is to use mysqldump
. See the manual pages for the utility here:
最简单、保证工作的方法是使用mysqldump
. 请在此处查看该实用程序的手册页:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
Basically, it dumps the SQL scripts required to rebuild the contents of the database, including creation of tables, triggers, and other objects and insertion of the data (it's all configurable, so if you already have the schema set up somewhere else, you can just dump the data, for example).
基本上,它转储重建数据库内容所需的 SQL 脚本,包括创建表、触发器和其他对象以及插入数据(这都是可配置的,因此如果您已经在其他地方设置了架构,则可以例如,只需转储数据)。
Copying individual MyISAM table files
复制单个 MyISAM 表文件
If you have a large amount of data andyou are using the MyISAM storage engine for the tables that you want to copy, you can just shut down mysqld and copy the .frm, .myd, and .myi files from one database folder to another (even on another system). This will not work for InnoDB tables, and may or may not work for other storage engines (with which I am less familiar).
如果您有大量数据并且您正在为要复制的表使用 MyISAM 存储引擎,则只需关闭 mysqld 并将 .frm、.myd 和 .myi 文件从一个数据库文件夹复制到另一个数据库文件夹(即使在另一个系统上)。这不适用于 InnoDB 表,并且可能适用于也可能不适用于其他存储引擎(我不太熟悉)。
mysqlhotcopy
mysqlhotcopy
If you need to dump the contents of a database while the database server is running, you can use mysqlhotcopy
(note that this only works for MyISAM and Archive tables):
如果您需要在数据库服务器运行时转储数据库的内容,您可以使用mysqlhotcopy
(请注意,这仅适用于 MyISAM 和存档表):
http://dev.mysql.com/doc/refman/5.0/en/mysqlhotcopy.html
http://dev.mysql.com/doc/refman/5.0/en/mysqlhotcopy.html
Copying the entire data folder
复制整个数据文件夹
If you are copying the entire database installation,so, all of the databases and the contents of every database, you can just shut down mysqld, zip up your entire MySQL data directory, and copy it to the new server's data directory.
如果您要复制整个数据库安装,因此,所有数据库和每个数据库的内容,您只需关闭 mysqld,压缩整个 MySQL 数据目录,并将其复制到新服务器的数据目录。
This is the only way (that I know of) to copy InnoDB files from one instance to another. This will work fine if you're moving between servers running the same OS family and the same version of MySQL; it maywork for moving between operating systems and/or versions of MySQL; off the top of my head, I don't know.
这是将 InnoDB 文件从一个实例复制到另一个实例的唯一方法(据我所知)。如果您在运行相同操作系统系列和相同 MySQL 版本的服务器之间移动,这将正常工作;它可能适用于在操作系统和/或 MySQL 版本之间移动;我不知道。
回答by Richie
You may very well use SQL yog - a product of web yog.. it uses similar techniques mentioned above but gives you a good GUI making you know what you are doing. You can get a community project of the same or a trial version from site
您可以很好地使用 SQL yog - 网络 yog 的产品。它使用了上面提到的类似技术,但为您提供了一个很好的 GUI,让您知道自己在做什么。您可以从站点获取相同或试用版的社区项目
http://www.webyog.com/en/downloads.php#sqlyog
http://www.webyog.com/en/downloads.php#sqlyog
This has option for creating backups to a file and restoring the file into new server. Even better option of exporting database from one server to another is there..
这具有用于创建文件备份并将文件恢复到新服务器的选项。将数据库从一台服务器导出到另一台服务器的更好选择是存在的。
Cheers,
干杯,
RDJ
RDJ