将现有数据库迁移到 Amazon RDS
如何将现有 MySQL 数据库导入 Amazon RDS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何将现有 MySQL 数据库导入 Amazon RDS?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(9)
我在 AWS 文档上找到了 此页面,其中解释了如何使用 mysqldump 并将其通过管道传输到 RDS 实例。
这是他们的示例代码(在命令行/shell/ssh 中使用):
mysqldump acme | mysqldump acme | mysqldump acme | mysqldump acme | mysqldump acme | mysqldump acme mysql --host=主机名 --user=用户名 --password acme
其中
acme
是您要迁移的数据库,主机名
/username
是来自您的 RDS 实例的用户名。您可以像连接常规 mysql 服务器一样连接到 RDS,只需确保将您的 EC2 IP 添加到您的安全组 此论坛帖子。
我必须包含本地 mysqldump 的密码,所以我的命令最终看起来更像这样:
mysqldump --password=local_mysql_pass acme | mysqldump --password=local_mysql_pass acme | mysqldump --password=local_mysql_pass acme | mysql --host=主机名 --user=用户名 --password acme
FWIW,我刚刚完成了数据库的移动。我使用了 此 mysql 命令参考,例如创建用户和授予权限。
希望这有帮助!
I found this page on the AWS docs which explains how to use mysqldump and pipe it into an RDS instance.
Here's their example code (use in command line/shell/ssh):
mysqldump acme | mysql --host=hostname --user=username --password acme
where
acme
is the database you're migrating over, andhostname
/username
are those from your RDS instance.You can connect to RDS as if it were a regular mysql server, just make sure to add your EC2 IPs to your security groups per this forum posting.
I had to include the password for the local mysqldump, so my command ended up looking more like this:
mysqldump --password=local_mysql_pass acme | mysql --host=hostname --user=username --password acme
FWIW, I just completed moving my databases over. I used this reference for mysql commands like creating users and granting permissions.
Hope this helps!
导入数据有两种方式:
mysqldump
:如果您的数据大小小于1GB,您可以直接使用mysqldump命令将数据导入到RDS中。mysqlimport
:如果您的数据大小超过 1GB 或任何其他格式,您可以将数据压缩为平面文件并使用 sqlimport 命令上传数据。There are two ways to import data :
mysqldump
: If you data size is less than 1GB, you can directly make use of mysqldump command and import your data to RDS.mysqlimport
: If your data size is more than 1GB or in any other format, you can compress the data into flat files and upload the data using sqlimport command.我是 SqlYog 工具的忠实粉丝。它允许您连接到源和目标数据库并同步架构和/或数据。我还使用过 SQLWave,但改用了 SqlYog。自从我做出转变以来已经很久了,我已经不记得为什么要转变了。无论如何,这是我的两分钱。我知道有些人会反对我对 MySQL 的 Windows GUI 工具的建议。事实上,我非常喜欢 SqlYog 产品,所以我从 Wine 运行它(对我来说,在 Ubuntu 上的 Wine 上运行完美)。
此博客可能会有所帮助。
I'm a big fan of the SqlYog tool. It lets you connect to your source and target databases and sync schema and/or data. I've also used SQLWave, but switched to SqlYog. Been so long since I made the switch that I can't remember exactly why I switched. Anyway, that's my two cents. I know some will object to my suggestion of Windows GUI tools for MySQL. I actually like the SqlYog product so much that I run it from Wine (works flawlessly from Wine on Ubuntu for me).
This blog might be helpful.
GoSquared 工程帖子的快速摘要:
配置 + 启动
数据迁移+准备
backup.sql
将数据导入到您的 RDS 实例中(这可能需要一段时间,具体取决于您的数据库大小)CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000003′, MASTER_LOG_POS=350789121;< /code>
backup.sql
以来的差异mysqlbinlog /var/log/mysql/mysql-bin.000003 --start-position=350789121 --base64-output=从不> output.sql
cat output.sql | mysql -h RDS_endpoint -u username -p DB_name
output.sql
文件末尾查找end_log_pos
来获取新的日志位置。output.sql
以来的差异(如步骤 6)并重复步骤 7 + 8。实际迁移
来自
output.sql
的 end_log_posFLUSH TABLES WITH READ LOCK;
以停止所有写入结论
使用此方法,您将有少量时间(取决于部署应用程序所需的时间 + MySQL 实例提供的写入次数) - 可能只有一两分钟),旧服务器的写入被拒绝,但您将获得一致的迁移,而不会出现读取停机时间。
此处提供了完整详细的帖子,解释了我们 (GoSquared) 如何以最短的停机时间(包括错误调试)迁移到 RDS:https://engineering.gosquared.com/migration-mysql-to-amazon-rds。
A quick summary of a GoSquared Engineering post:
Configuration + Booting
Data migration + preparation
mysqldump --single-transaction --master-data=2 -C -q dbname -u username -p > backup.sql
on the old instance to take a dump of the current datamysql -u username -p -h RDS_endpoint DB_name < backup.sql
to import the data into your RDS instance (this may take a while depending on your DB size)master-data=2
and binlogging comes inCHANGE MASTER TO MASTER_LOG_FILE=’mysql-bin.000003′, MASTER_LOG_POS=350789121;
backup.sql
as an SQL filemysqlbinlog /var/log/mysql/mysql-bin.000003 --start-position=350789121 --base64-output=NEVER > output.sql
cat output.sql | mysql -h RDS_endpoint -u username -p DB_name
end_log_pos
at the end of the latestoutput.sql
file.output.sql
(like step 6) and repeat steps 7 + 8.The actual migration
end_log_pos
fromoutput.sql
FLUSH TABLES WITH READ LOCK;
on the old instance to stop all writesConclusion
Using this method, you'll have a small amount of time (depending on how long it takes to deploy your apps + how many writes your MySQL instance serves - probably only a minute or two) with writes being rejected from your old server, but you will have a consistent migration with no read downtime.
A full and detailed post explaining how we (GoSquared) migrated to RDS with minimal downtime (including error debugging) is available here: https://engineering.gosquared.com/migrating-mysql-to-amazon-rds.
我完全同意@SanketDangi。
有两种方法可以做到这一点,其中一种方法是使用 mysqldump 或 mysqlimport 。
我见过在云上恢复数据损坏时产生问题的情况。
然而,现在在云上导入应用程序变得更加容易。您尝试通过 ravello 将数据库服务器上传到公共云。
您可以使用 ravello 在 Amazon 上导入数据库服务器本身。
披露:我为 ravello 工作。
I am completely agree with @SanketDangi.
There are two ways of doing this one way is as suggested using either
mysqldump
ormysqlimport
.I have seen cases where it creates problem while restoring data on cloud gets corrupt.
However importing applications on cloud has became much easier now a days. You try uploading your DB server on to public cloud through ravello.
You can import your database server itself on Amazon using ravello.
Disclosure: I work for ravello.
最简单的例子:
Simplest example:
适用于 Mysql 的 AWS RDS 客户数据导入指南可在此处获取:http://aws.amazon.com/articles/2933
AWS RDS Customer data Import guide for Mysql is available here : http://aws.amazon.com/articles/2933
如果您使用终端,这对我有用:
然后我使用 MYSQL WorkBench(免费下载)来检查它是否正常工作,因为按提交后命令行是静态的,我可能可以将 -v 放在末尾以查看它是否有效输出
注意:-p后面没有空格
If you are using the terminal this is what worked for me:
and then i used MYSQL WorkBench (free download) to check it was working because the command line was static after pressing submit, i could have probably put -v at end to see it's output
Note: there is no space after -p
这是我已经完成并取得成功的步骤。
获取所需数据库的 MySQLdump。
mysqldump -u username -p databasename --single-transaction --quick --lock-tables=false >databasename-backup-$(date +%F).sql
(不要忘记替换用户名为 root – 大多数情况下,数据库名称 -> 您要迁移到 RDS 的数据库的数据库名称)
出现提示后,输入您的密码。
完成后,从 MySQL 服务器登录到 RDS 实例(确保安全组配置为允许从 Ec2 到 RDS 的连接)
mysql -h 主机地址 -P 3306 -u rdsusername -p
(不要忘记将主机地址替换为地址您的 RDS 实例和 rdsusernmae 以及您的 RDS 实例的用户名,当提示时也提供密码)
您可以在 – Connectivity & 下找到该主机地址。安全->端点& AWS 控制台中 RDS 数据库下的端口。
登录后,使用 MySQL 命令创建数据库:
create database databasename;
\q
在 RDS 中创建数据库后,导入在步骤 1 中创建的 SQL 文件:
mysql -h 主机地址 -u rdsusername -p 数据库名称 backupfile.sql
这应该将 SQL 文件导入到 RDS 并将内容恢复到新数据库中。
参考来源:
Here are the steps which i have done and had sucess.
Take the MySQLdump of the needed database.
mysqldump -u username -p databasename --single-transaction --quick --lock-tables=false >databasename-backup-$(date +%F).sql
( Dont forget to replace the username as root – most of the times, and databasename -> Db name of database which you are going to migrate to RDS )
Once prompted, enter your password.
Once done, login to the RDS Instance from your MySQL server ( Make sure the security groups are configured to allow the connection from Ec2 to RDS )
mysql -h hostaddress -P 3306 -u rdsusername -p
( Dont forget to replace hostaddress with the address of your RDS Instance and rdsusernmae with username for your RDS Instance, when prompted give the password too )
You find that hostaddress under – Connectivity & security -> Endpoint & port under RDS Database From AWS Console.
Once logged in, create the database using MySQL commands :
create database databasename;
\q
Once Database is created in RDS, Import the SQL file created in Step 1 :
mysql -h hostaddress -u rdsusername -p databasename < backupfile.sql
This should import the SQL file to RDS and restore the contents into the new database.
Reference from : https://k9webops.com/blog/migrate-an-existing-database-on-mysql-mariadb-to-an-already-running-rds-instance-on-the-aws/