39

案例:教你迁移MySQL数据库

 5 years ago
source link: https://www.linuxprobe.com/migrate-database-between.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
导读 在虚拟专用服务器之间传输数据库可以使用SCP(安全拷贝)来实现,该方法是复制从SSH Shell派生的文件。 请记住,您需要知道两个虚拟服务器的密码。

为了迁移数据库,有如下三个步骤:

第一步 - 执行MySQL转储

在将数据库文件传输到新的VPS之前,我们首先需要使用mysqldump命令在原始虚拟服务器上备份它。

mysqldump -u root -p --opt [database name] > [database name].sql

执行转储后,即可准备传输数据库。

第二步 - 复制数据库

SCP帮助您复制数据库。 如果使用上一个命令,则将数据库导出到主文件夹。

SCP命令具有以下语法:

scp [database name].sql [username]@[servername]:path/to/database/

样本传输可能如下所示:

scp newdatabase.sql [email protected]:~/

连接后,数据库将传输到新的虚拟专用服务器。

第三步:导入数据库

一旦数据已传输到新服务器,您可以将数据库导入MySQL:

mysql -u root -p newdatabase 

With that, your transfer via SCP will be complete. 

By Etel Sverdlov

这样,您通过SCP转移将完成。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK