Simple Example of MySQL Data export and import under Ubuntu command line

Source: Internet
Author: User

Mysqldump-h host-u username-p Database Name> exported database name. SQL
Mysqldump-h host-u user name-p database name Table Name> exported table name. SQL
Several common parameters are as follows:
 
-P or -- port: the server port to be connected. this parameter is required if MySQL port is not 3306.
-D or -- no-data does not have detailed data. Only the data structure is exported.
-- Add-drop-database: when creating a database, first drop the existing database with the same name [usually after the-d parameter]
-- Add-drop-table when creating a table, drop the existing table with the same name first [usually after the-d parameter]
The following uses the emlog database as an example to export data.
1. Export all data of the entire emlog database (including data structures, including data)
 
Mysqldump-h127.0.0.1-u root-p emlog> emlog_all. SQL
 
2. Export emlog_blog table (including table structure and table data)
 
Mysqldump-h 127.0.0.1-u root-p peerrecom> peerrecom. SQL
3. Only export the database structure
 
Mysqldump-h127.0.0.1-uroot-p-d -- add-drop-table emlog> emlog_all_structure. SQL
4. Only export the table structure
 
Mysqldump-h127.0.0.1-uroot-p-d -- add-drop-table emlog emlog_blog> emlog_blog_structure. SQL
There are many ways to import data. The most single command is the source command. Use the mysql command to connect to the database, and then use the source command to import the files in the specified path.
Connect to MySQL
 
Mysql-h127.0.0.1-uroot-p
Create a database first, because the exported file does not contain statements for creating a database. If the database has been created, you do not need to create a database.
 
Create database emlog COLLATE 'utf8 _ general_ci ';
Switch Database
 
Use emlog;
Import a specified SQL File
 
Mysql> source/path/.../source. SQL

From a strange blog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.