Common MySQL import commands for exporting data

Source: Internet
Author: User

To export

Export the data for the specified db_name:

$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql

To export the data for the entire library:

$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql

Export data for a specified table

$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql

Export the packaged data file (if the file is large)

$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz

To export data on a remote machine:

$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql

如果只导出sql语句,不需要数据,可加参数 --no-data
To import

Type the following command to import SQL data file:

$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql

In this example, the import ' data.sql ' file into ' blog ' database using sathish as Username:

$ mysql -u sat -p -h localhost blog < data.sql

If you have a dedicated database server, replace the localhost hostname with with actual server name or IP address as follows:

$ mysql -u username -p -h 202.54.1.10 databasename < data.sql

OR use hostname such as mysql.cyberciti.biz

$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql

If you don't know the database name or database name is included in SQL dump you can try out something as follows:

$ mysql -u username -p -h 202.54.1.10 < data.sql

Common MySQL import commands for exporting data

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.