将mysql数据库从一台服务器移动到另一台服务器

时间:2014-07-21 09:31:12

标签: mysql database amazon-web-services backup database-backups

我想将我的mysql数据库从rackspace服务器移动到aws服务器。有什么办法可以轻松完成。它包含或多或少的100万行数据

2 个答案:

答案 0 :(得分:1)

如果您的网站不是实际网站,停机不是问题,您可以尝试以下

#step1: take a dump of your db
>mysqldump –-user root –-password=myrootpassword db_test > db_test.sql

#step2: zip the .sql file - this is optional
>gzip db_test.sql

#step3: transfer the file to AWS using .pem file
>scp -i myAmazonKey.pem db_test.sql.gz ec2-user@<ur_ip_address>:~/.

#step4: login to your AWS instance 

#step5: unzip the file
>gunzip db_test.sql.gz

#step6: import the db to your AWS mysql instance
>mysql -u username -p password db_name < db_test.sql 

答案 1 :(得分:0)

请完成以下步骤,

Old Server

    Stop mysql server
    Copy contents of datadir to another location on disk (~/mysqldata/*)
    Start mysql server again (downtime was 10-15 minutes)
    compress the data (tar -czvf mysqldata.tar.gz ~/mysqldata)
    copy the compressed file to new server

New Server

    install mysql (don't start)
    unzip compressed file (tar -xzvf mysqldata.tar.gz)
    move contents of mysqldata to the datadir
    Make sure your innodb_log_file_size is same on new server, or if it's not, don't copy the old log files (mysql will generate these)
    Start mysql