tencent cloud

TDSQL for MySQL

Announcements
Alarm Upgrade
Product Introduction
Overview
Strengths
Use Cases
Regions and AZs
InnoDB engine
Purchase Guide
Billing Overview (InnoDB)
Product Pricing (InnoDB)
Purchase and Upgrade
Refund
Payment Overdue
Backup Space Billing
Getting Started
InnoDB Engine
Operation Guide(InnoDB)
Instance Management
Disaster Recovery Read-Only Instance
Changing Networks
Account Management
Security Management
Slow Query Analysis
Backup and Rollback
Data Migration
Database Audit
Practical Tutorial
Import from Standalone Instance to TDSQL Instance
Import Between TDSQL Instances
Selection of TDSQL Instance and Shard Configuration
Security White Paper
Platform Security Design
Tenant Security Features
Development Guide
InnoDB
API Documentation
History
Introduction
API Category
Security Group APIs
Other APIs
Making API Requests
TDSQL APIs
Data Types
Error Codes
FAQs
InnoDB
General References
Performance Comparison Data for Strong Sync
Glossary
Contact Us

Import Between TDSQL Instances

PDF
フォーカスモード
フォントサイズ
最終更新日: 2024-01-06 17:34:55
The solution for data importing from one distributed database to another is special. mysqldump is used as an example below to summarize the importing steps:

1. Install mysqldump (for MariaDB)

Purchase a Linux CVM instance and run yum install mariadb-server to install mysqldump.

2. Export the table structure

mysqldump --compact --single-transaction -d -uxxx -pxxx -hxxx.xxx.xxx.xxx -Pxxxx db_name table_name > schema.sql
Note:
Please select the db_name and table_name parameters as needed.

3. Export data

Export data by using mysqldump: Set the net_write_timeout parameter in the parameter settings in the TDSQL for MySQL Console: set global net_write_timeout=28800
mysqldump --compact --single-transaction --no-create-info -c -uxxx -pxxx -hxxx.xxx.xxx.xxx -Pxxxx db_name table_name > data.sql
Note:
The db_name and table_name parameters should be selected as needed. If the exported data is to be imported into another set of TDSQL for MySQL environment, the -c option must be added, and there should be a space between -c and db_name.


4. Create a database in the target instance

mysql --default-character-set=utf8 -uxxx -pxxx -hxxx.xxx.xxx.xxx -Pxxxx -e "create database dbname;";
--default-character-set=utf8: set based on your target table.
-uxxx: a privileged account (-u is a keyword).
-pxxx: password (-p is a keyword).
-hxxx.xxx.xxx.xxx -Pxxxx: IP and port of the database instance.
dbname: database name.

5. Import the table structure into the target instance

mysql --default-character-set=utf8 -uxxx -pxxx -hxxx.xxx.xxx.xxx -Pxxxx dbname < schema.sql
--default-character-set=utf8: set based on your target table.
-uxxx: a privileged account (-u is a keyword).
-pxxx: password (-p is a keyword).
-hxxx.xxx.xxx.xxx -Pxxxx: IP and port of the database instance.
dbname: database name.

6. Import table data into the target instance

mysql --default-character-set=utf8 -uxxx -pxxx -hxxx.xxx.xxx.xxx -Pxxxx dbname < data.sql
Note:
If an auto-increment field is used in the source table, and the "Column 'xx' specified twice" error occurs during import, the schema.sql needs to be processed. Remove the back quotes from the auto-increment field (cat schema.sql | tr "" " " > schema_tr.sql), drop database, and repeat steps 3–5 by using the processed schema_tr.sql`.


ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック