Import a Web Hosting MySQL backup to another server
This topic describes how to import a MySQL backup file from Web Hosting to a MySQL database on another cloud server, such as an ECS instance that runs a Linux operating system.
Background
Importing data from your Web Hosting MySQL database to another cloud server, such as an ECS instance running a Linux operating system, allows you to perform tasks like debugging and data analysis on the target database.
To import the backup file, perform the following steps:
-
Use the backup and recovery feature in the Host Management Console to extract the MySQL backup file from your Web Hosting instance and download it to your local machine.
-
Upload the downloaded backup file to the target ECS instance that runs a Linux operating system and decompress the file.
-
Use database commands to import the backup file.
Procedure
-
Extract and download the compressed MySQL backup file from your Web Hosting instance.
-
Log on to the Web Hosting console.
-
Find your Web Hosting instance and click Manage in the Actions column.
-
In the left-side navigation pane, choose .
-
On the Backup and Recovery page, on the Database Backup tab, find the backup file and click Extract in the Actions column.
-
In the Extract Backup dialog box, click OK.
The system automatically redirects you to the My Tasks tab. Wait until the task Status changes to Extraction successful.
-
Click the Database Backup tab, find the extracted backup file, and then click Download in the Actions column.
-
In the Download File dialog box, right-click Download and select Save link as....
-
In the Save As dialog box, select a path to save the backup file and click Save.
NoteDownload the backup file to a known path on your local host for easy access during the upload step.
-
In the Download File dialog box, click OK.
-
-
Upload the compressed backup file from your local host to the target ECS instance that runs a Linux operating system.
-
Log on to the ECS instance that runs a Linux operating system.
For more information, see Select a method to connect to an ECS instance.
-
Upload and decompress the backup file on the ECS instance.
This example describes how to upload the compressed backup file bak.zip to the /opt directory of an ECS instance that runs a Linux operating system. For detailed instructions, see Transfer files to a Linux instance by using scp, rsync, or sftp.
-
Navigate to the directory that contains the compressed backup file, such as /opt, and run the following command to decompress it.
unzip <compressed_backup_file>For example, decompress the bak.zip file.
[root@gp-cm5001a-ud1 opt]# unzip bak.zip Archive: bak.zip extracting: qdm123557567_db/qdm123557567_db.sqlImportantThe
unzipcommand is required. If it is not installed, run the following command to install it:sudo yum install unzip -
Run the
lscommand to view the decompressed backup folder.[root@gp-cm5001a-ud1 opt]# ls bak.zip qdm123557567_db -
Run the following commands to navigate to the backup folder and view the SQL backup file.
cd <backup_folder> lsFor example, go to the decompressed backup folder qdm123557567_db to view the backup file qdm123557567_db.sql.
-
-
Import the backup file into the MySQL database on the ECS instance.
-
Run the following command to connect to the MySQL database.
mysql -u <mysql_database_username> -pEnter the password when prompted.
-
Run the following command to create a new database.
create database <new_database_name>;For example, to create a new database named test, run the following command:
create database test; -
Run the following command to verify that the test database was created.
show databases;mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.02 sec) mysql> -
Run the following commands to import the backup file into the newly created database.
use <new_database_name> source <SQL_backup_file_name>For example, to import the backup file qdm123557567_db.sql into the test database, run the following commands:
use test source qdm123557567_db.sql
-
Results
When the import is complete, the output is similar to the following:
Query OK, 0 rows affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql>
To view the tables in the new database, run the following command:
show tables;
The following output shows that the tables from the Web Hosting database were successfully imported into the new database:
mysql> show tables;
+----------------------------+
| Tables_in_test |
+----------------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_terms |
| wp_usermeta |
| wp_users |
+----------------------------+
11 rows in set (0.00 sec)
mysql>
Migrate to ECS
To migrate a website from Web Hosting to Elastic Compute Service (ECS), complete the following steps.
Step 1: Back up the website files
-
Log on to the Web Hosting console, find your instance, and then click Manage in the Actions column.
-
Connect to your Web Hosting instance by using an FTP client, such as FileZilla, and download all website files in the
htdocsdirectory. For more information, see Manage website files by using FileZilla.
Step 2: Export the database
-
On the instance management page, choose Tools > Backup and Recovery to back up the database and download the backup file to your local computer.
-
Import the downloaded database backup file into the MySQL database on the ECS instance. For more information, see the Procedure section in this topic.
Step 3: Set up the ECS web environment
Deploy a LAMP or LNMP environment on the ECS instance. For more information, see Build a LAMP environment or Manually build a LAMP environment in the ECS documentation.
Step 4: Upload the files and database to ECS
Upload the website files that you backed up in Step 1 to the web root directory on the ECS instance. Then import the database backup file that you exported in Step 2 into the MySQL database on the ECS instance by running MySQL commands.
Step 5: Switch the domain name resolution
Point the DNS resolution of your domain name to the public IP address of the ECS instance. For more information, see Add DNS records for website domain name resolution in the Alibaba Cloud DNS documentation.
If you have no experience operating and maintaining Linux, use a visual management tool such as BT Panel to manage the ECS instance, or consider using Simple Application Server instead.