Use commands to export/import table structures and data from mysql

Source: Internet
Author: User

In the command line, mysql DATA export has a very useful command mysqldump. Its parameters include the handler, which can be viewed as follows:
Mysqldump
Most commonly used:
Mysqldump-uroot-pmysql databasefoo table1 table2> foo. SQL
In this way, table1 and table2 of database databasefoo can be imported into foo in SQL format. in SQL, the-uroot parameter indicates that the user name used to access the database is root. If there is a password, the-p parameter must be added.
Eg:
 
C: \ Users \ jack> mysqldump-uroot-pmysql sva_rec date_drv> e: \ date_drv. SQL
 
 
Mysql DATA import is also quite convenient, such:
Mysql-uroot databasefoo <foo. SQL
In this way, all data of foo. SQL can be imported into database databasefoo.
 
 
1. Export the entire database
Mysqldump-u username-p Password Database Name> exported file name
C: \ Users \ jack> mysqldump-uroot-pmysql sva_rec> e: \ sva_rec. SQL
 
2. Export a table, including the table structure and data
Mysqldump-u user name-p Password Database Name Table Name> exported file name
C: \ Users \ jack> mysqldump-uroot-pmysql sva_rec date_rec_drv> e: \ date_rec_drv. SQL
 
3. Export a database structure
C: \ Users \ jack> mysqldump-uroot-pmysql-d sva_rec> e: \ sva_rec. SQL

4. Export a table with only the table structure
Mysqldump-u username-p password-d database name Table Name> exported file name
C: \ Users \ jack> mysqldump-uroot-pmysql-d sva_rec date_rec_drv> e: \ date_rec_drv. SQL
 
 
5. Import the database
Common source commands
Go to the mysql Database Console,
For example, mysql-u root-p
Mysql> use Database
Then run the source command. The following parameter is the script file (for example,. SQL used here)
Mysql> source d: wcnc_db. SQL
 
Sometimes, you can write an import program and a java Script to import data to mysql.

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.