Loading...

We've detected that your browser language is Chinese. Would you like to visit our Chinese website? [ Dismiss ]
By: Dylan

Why need to copy MySQL Table from one database to another?

In real-world database management, it’s common to face situations where you need to copy a MySQL table from one database to another. Maybe you’re migrating data from a development environment to production, creating a safety backup, or simply sharing a specific dataset across multiple applications. Whatever the reason, knowing how to copy tables efficiently between databases can save you hours of manual work and prevent costly errors.

When managing large systems or multiple projects, developers often maintain several databases — for example, one for testing, one for staging, and another for live production. In these cases, being able to copy MySQL tables between databases ensures data consistency and smooth transitions between environments. It also helps when reorganizing data, merging systems, or exporting a subset of information for analytics.

In this guide, you’ll learn the most effective methods to copy a table from one MySQL database to another. It will be divided into on the same server or across different servers. We’ll cover both command-line and graphical approaches, from quick SQL statements like CREATE TABLE … SELECT to powerful tools like mysqldump and MySQL Workbench — all designed to help you transfer data safely and efficiently.

Copy a Table from One Database to Another on the Same MySQL Server

When both the source and target databases are on the same MySQL server, you can use native SQL statements. Try the methods below.

Method 1. Using “CREATE TABLE…SELECT (Copy a Table with Structure and Data)

“CREATE TABLE … SELECT” statement is one of the fastest ways to copy a table between databases on the same MySQL server. It creates a new table in the target database and immediately fills it with data from the source table.

Syntax:

sql
CREATE TABLE IF NOT EXISTS destination_db.new_table
SELECT * FROM source_db.existing_table;
  • destination_db.new_table: The name of the target database and the new table to create.
  • source_db.existing_table: The source database and table to copy from.
  • IF NOT EXISTS: Optional clause that prevents duplicate-table errors if the target table already exists.

Example:

To copy the full “offices” table from the “classicmodels” sample database to a “testdb” database:

bash
CREATE TABLE IF NOT EXISTS testdb.offices_quick
SELECT * FROM classicmodels.offices; 

✅ Pros:

  • Simple and quick — just one command.
  • Copies both table structure and all data.

⚠️ Cons:

  • Does not copy indexes, primary keys, or foreign key constraints.
  • Not suitable for complex tables that depend on relational integrity.

This method is best for quick copies of a table and its data, test snapshots, temporary backups, and scenarios where indexes and formal constraints aren’t required.

Method 2. Using “CREATE TABLE … LIKE” + “INSERT” (Copy Full Structure & Data)

When you need an exact structural replica of the source table, including all indexes, primary keys, unique constraints, foreign keys, and column-level attributes, use the two-step LIKE + INSERT approach. This method produces a structurally identical table in the target database.

Step 1. Duplicate the table structure

First, create an empty new table with the same schema as the source table:

sql
CREATE TABLE IF NOT EXISTS destination_db.new_table
LIKE source_db.existing_table;

Step 2. Copy all data into the new table

Second, insert all rows from the source table into the newly created structure:

sql
INSERT INTO destination_db.new_table
SELECT * FROM source_db.existing_table; 

Example:

To create a full structural copy of “offices” in “testdb” and load all data:

sql
-- Create empty table with full structure (indexes, keys, constraints)
CREATE TABLE IF NOT EXISTS testdb.offices_full
LIKE classicmodels.offices;

-- Copy all data from source to destination
INSERT INTO testdb.offices_full
SELECT * FROM classicmodels.offices;

✅ Pros:

  • Preserves 100% of the source table’s schema, including primary keys, indexes, foreign key constraints, triggers, character sets, and default values.

⚠️ Cons:

  • Requires two separate SQL statements.
  • For very large tables, the “INSERT” step may take a long time and consume system resources on the server.

It is best for production-level copies, staging environment setup, merging, or updating existing tables.

Tip: Using a “WHERE” Clause (Copy Partial Data)

In some cases, you may only want a subset of data, instead of copying every row. Both methods above support row-level filtering with a WHERE clause.

Example with “CREATE TABLE … SELECT”.

Copy only offices located in the USA from “classicmodels” to “testdb”:

sql
CREATE TABLE IF NOT EXISTS testdb.offices_usa
SELECT * 
FROM classicmodels.offices 
WHERE country = 'USA'; 

Example with “CREATE TABLE … LIKE + INSERT”

For a structurally complete table with filtered data:

bash
CREATE TABLE IF NOT EXISTS testdb.offices_usa_structured
LIKE classicmodels.offices;

INSERT INTO testdb.offices_usa_structured SELECT *
FROM classicmodels.offices
WHERE country = 'USA';
Note: For large source tables, ensure the filter column has an appropriate index to speed up the SELECT portion of the operation and reduce load on the source database.

This is best for creating region-specific data subsets, test data sampling, incremental data copies, and isolating data for individual development teams.

Method 3. Using phpMyAdmin

Step 1. Select the source table.

Step 2. Click the “Operations” button.

Phpadmin Operations

Step 3. Under “Copy table to (database.table), choose the content you want to copy, such as table structure only, the data only, or both.

Phpmyadmin copy table to

Step 4. Enter a name for the new table and click Go.

✅ Pros:

  • Web-based and user-friendly.
  • Free, open-source.
  • Flexible options to copy structure only, data only, or both.

⚠️ Cons:

  • No direct cross-server table copy.
  • Slow performance with large datasets.

Copy MySQL Table from One Database to Another Server

When the source and destination databases run on separate MySQL servers, physical hosts, or cloud instances, use the methods in this section. 

Method 1. “mysqldump” + MySQL Client (Recommended for Large or Remote Transfers)

The “mysqldump” command-line tool is perfect when you need to copy tables between different servers or when dealing with large datasets. It exports the table as SQL statements, which can then be imported into another database.

Prerequisites:

  • The mysqldump and mysql client tools are installed on your local or jump machine (both are included with standard MySQL Server installations).
  • Network access to both servers on the MySQL port (default 3306), with firewall and security group rules allowing your client IP to connect.
  • A source database user with SELECT and SHOW CREATE TABLE privileges on the target table.
  • A destination database user with CREATE and INSERT privileges on the target database.

Step 1. Export the Table from the source Database

Run mysqldump on your working machine to export the source table to a .sql dump file. This file will contain the full CREATE TABLE definition and all INSERT statements for the table data.

Syntax:

bash
mysqldump -u [source_user] -p -h [source_host] -P [source_port] [source_database] [table_name] > [dump_file.sql]
  • -u [source_user]: Username for the source MySQL server.
  • -p: Triggers an interactive password prompt. Never include the plaintext password in the command line to avoid exposing credentials in shell history.
  • -h [source_host]: Hostname or IP address of the source database server. Use localhost if running directly on the source machine.
  • -P [source_port]: MySQL port number. Omit this flag if using the default port 3306.
  • [source_database]: Name of the database containing the source table.
  • [table_name]: Name of the table to export.
  • > [dump_file.sql]: Writes the exported SQL output to the specified local file.

Example:

To export a customers table from an e-commerce database on a remote production server:

bash
mysqldump -u source_user -p -h source-db.example.com ecommerce customers > customers_dump.sql

When prompted, enter the password for “source_user”. The tool will generate “customers_dump.sql” in your working directory.

Step 2. Import the Dump File into the Destination Database

Use the MySQL client to execute the SQL dump file on the destination server. This will recreate the table with its full schema and populate it with all exported rows.

Note: Ensure the destination database already exists on the target server. If not, create it first with “CREATE DATABASE IF NOT EXISTS destination_database;”

Syntax:

bash
mysql -u [dest_user] -p -h [dest_host] -P [dest_port] [dest_database] < [dump_file.sql]
  • -u [dest_user]: Username for the destination MySQL server.
  • -p: Interactive password prompt for the destination user.
  • -h [dest_host]: Hostname or IP of the destination database server.
  • [dest_database]: Name of the target database where the table will be created.
  • < [dump_file.sql]: Reads and executes all SQL statements from the dump file sequentially.

Example:

To import the “customers_dump.sql” file into an “ecommerce_staging” database on a local staging server:

bash
mysql -u dest_user -p -h localhost ecommerce_staging < customers_dump.sql

Enter the destination user’s password when prompted. The MySQL client will create the customers table and insert all exported records.

✅ Pros:

  • Works across different servers.
  • Keeps table structure, indexes, and data.
  • Good for backups and production migrations.

⚠️ Cons:

  • Requires command-line access.
  • Slightly slower for massive tables.

This is best for production-grade table migrations between separate server instances, copies between databases with different user accounts and permission models, transfer across different MySQL versions, etc.

Method 2. Using MySQL Workbench (GUI Method)

For those who prefer graphical tools, MySQL Workbench provides user-friendly interfaces to copy MySQL tables between servers.

Step 1. Right-click the table you want to copy. Select “Table Data Export Wizard”.

Copy MySQL Workbench Table Data Export

Step 2. Browse and choose your CSV file, and click “Next”. 

Step 3. Choose the target database. Check “Create New Table”, and you can rename the table. Click “Next”.

Step 4. Check the import settings, and you can reconfigure them. Click “Next”. 

Step 5. Follow the prompts to finish and process the operation.

✅ Pros:

  • No SQL knowledge required.
  • Great for quick one-time transfers.

⚠️ Cons:

  • Slower than SQL or command-line methods for large datasets.
  • May time out with huge tables on shared hosting.

i2Stream: Real-Time MySQL Table Copy for Enterprise & Large-Scale Datasets

For teams managing multiple databases or large-scale MySQL environments, continuous synchronization between MySQL databases is necessary. you can turn to a professional database replication software – i2Stream. This solution offers a powerful, automated way to copy and synchronize tables and data between different MySQL databases in real time.

Info2soft i2Stream provides log-based change data capture (CDC) for real-time database synchronization. It captures database changes from transaction logs and replicates them to the target database without requiring application changes.

This solution captures data changes (such as inserts, updates, and deletes) from the source MySQL database and applies them automatically to the target database. This ensures both databases remain synchronized, even while transactions are ongoing.

Key Advantages of i2Stream

  • Real-time CDC: Capture and replicate INSERT, UPDATE, DELETE, and supported DDL changes.
  • Low-impact replication: Use database logs to track changes without continuously querying the source tables.
  • Cross-server and cross-region synchronization: Keep MySQL databases synchronized across different servers, environments, or locations.
  • Flexible replication: Support one-to-one, one-to-many, and other replication topologies for different data distribution requirements.
  • Broad database support: Work with MySQL and many other databases and big data platforms, such as SQL Server, Oracle.

You can click the button below to request a 60-day free trial.

FREE Trial for 60-Day

Conclusion

Choosing the right method to copy a MySQL table from one database to another depends on your environment, the size of the data, and the frequency of updates. For one-off tasks, built-in SQL commands are sufficient. For ongoing, real-time, or enterprise-level replication, investing in a robust solution like Info2soft‘s i2Stream ensures data integrity, reduces manual overhead, and keeps multiple databases in sync effortlessly.

Dylan has 8+ years of experience in enterprise data management, server optimization, and disaster recovery. He specializes in translating complex technical concepts into actionable guides for IT administrators and DevOps teams, with a focus on data security, cloud migration, and business continuity.

More Related Articles

Ready to Enhance Business Data Security?

· Enterprise & Mid-market Customers Worldwide

· Support team available to assist you throughout your trial

· Start a 60-day free trial or view demo to see how Info2Soft protects enterprise data.

Please fill out the form and submit it, our customer service representative will contact you soon.
By submitting this form, I confirm that I have read and agree to the Privacy Notice.
{{ isSubmitting ? 'Submitting...' : 'Submit' }}