
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to copy tables or databases from one MySQL server to another MySQL server?
If we want to copy tables or databases from one MySQL server to another, then use the mysqldump with database name and table name.
Run the following command at the source host. This will dump the complete database into dump.txt file.
$ mysqldump -u root -p database_name table_name > dump.txt password *****
We can copy complete database without using a particular table name as explained above.
Now, ftp dump.txt file on another host and use the following command. Before running this command, make sure we have created database_name on the destination server.
$ mysql -u root -p database_name < dump.txt password *****
Another way to accomplish this without using an intermediary file is to send the output of the MySQL dump directly over the network to the remote MySQL server. If we can connect to both the servers from the host where the source database resides, use the following command (Make sure we have access to both the servers).
$ mysqldump -u root -p database_name \ | mysql -h other-host.com database_name
In mysqldump, half of the command connects to the local server and writes the dump output to the pipe. The remaining half of the command connects to the remote MySQL server on the other-host.com. It reads the pipe for input and sends each statement to the other-host.com server.
- Related Articles
- How to copy files from one server to another using Python?
- How to GRANT SELECT ON all tables in all databases on a server with MySQL?
- Copy from one column to another (different tables same database) in MySQL?
- How to restart MySQL server?
- How to upgrade MySQL server from command line?
- How to copy a table from one MySQL database to another?
- How to copy rows from one table to another in MySQL?
- MySQL Server and Server-Startup Programs
- Connecting to and Disconnecting from the MySQL Server
- Which tables are used to control the privileges of MySQL database server?
- How to Update Two Tables in One Statement in SQL Server?
- How can we analyze the tables of a particular database from MySQL Server command line?
- How to copy data from one field to another on every row in MySQL?
- How to find out port of MySQL Server?
- How to Display System Variables of MySQL Server?
