Offline Data Migration

Last updated: 2019-11-19 18:18:28

PDF

Migrating Data in the Console

  1. Log in to the TencentDB for MySQL Console and download backup files and logs. For more information, see Downloading a Backup File.
  2. A database can be restored with the MySQL command line tool by running the following command:
    shell > mysql -h hostname -P port -u username -p < bak_pathname
    Here, "hostname" is the target server for data restoration, "port" is the port of target server, "username" is the username of the database on the target server, and "bak_pathname" is the full path to the backup file.
  3. Log in to the MySQL database and restore the tables by running the shell > source bak_pathname command.
    Here, "bak_pathname" is the full path to the backup file.

Migrating Data with the Command Line Tool

  1. Generate the SQL file to be imported with the MySQL command line tool "mysqldump" in the following way:

    The data files exported using mysqldump must be compatible with the SQL specification of your purchased TencentDB for MySQL version. You can log in to the database and get the MySQL version information by running the select version(); command. The name of the generated SQL file can contain letters, digits, and underscores but not "test".

    shell > mysqldump [options] db_name [tbl_name ...] > bak_pathname

    Here, "options" is the export option, "db_name" is the database name, "tbl_name" is the table name, and "bak_pathname" is the export path.
    For more information on how to export data with mysqldump, see
    MySQL's official documentation.

  2. A database can be restored with the MySQL command line tool by running the following command:

    shell > mysql -h hostname -P port -u username -p < bak_pathname

    Here, "hostname" is the target server for data restoration, "port" is the port of target server, "username" is the username of the database on the target server, and "bak_pathname" is the full path to the backup file.

Migrating Data on Windows

  1. Export the data using the mysqldump tool on Windows.

    Make sure that the same database version, mysqldump tool version, and database character set are used. You can specify the character set using the parameter --default-character-set.

  2. Enter the command prompt and restore the data with the MySQL command line tool.
  3. Log in to the MySQL database and you can see the backed up database has already been restored to the server.

Migrating Data on a Linux CVM Instance

For more information on how to access a database on a CVM instance, see Accessing a MySQL Database.

  1. Take the db_blog database in TencentDB for example. Log in to the CVM instance and generate the SQL file to be imported with the MySQL command line tool "mysqldump".
  2. Restore the data with the MySQL command line tool. In this example, data is restored to the CVM instance. You can see that the backed up database has been imported to the database corresponding to the target CVM instance.

Issues with Character Set of Imported Data Files

  1. If no character set is specified for during data file import to the TencentDB instance, the one set by the database will be used.
  2. Otherwise, the specified character set will be used.
  3. If the specified character set is different from that of the TencentDB instance, garbled text will be displayed.

For more information, see the character set description in Use Limits.