Use Mysql command line statements to import and export database files

Source: Internet
Author: User
Tags import database

Today, a student asked me if I could migrate the database. I thought I should have to re-create the table, but it is too inefficient and I still need to import many records from the table, so I thought that mysql bin provided two commands, mysqldump and resource.

Mysql Command LineExport Database:

1. Run the command to enter the bin directory of the mysql installation directory. For example, run the command cd C: \ Program Files \ MySQL Server 5.5 \ bin.

(If it is Windows 7 and mysql is installed in the C directory, if the above command prompts that access is denied, it is enough to run the command prompt as an administrator)

2.Export Database: Mysqldump-u username-p Database Name> exported file name
For example, if the command line I entered is mysqldump-u root-p atm> atm. SQL (after entering the command, you will be asked to enter the MySQL password)
(If you export a single table, enter the table name after the database name)

3. After executing the preceding command, we can see the exported atm. SQL database file in the bin directory, which contains all the tables and records in the database.

Mysql command line import database:

1. First, we will import the. SQL file to the database and put it in the bin directory, which is convenient.

2. Go to MySQL Command Line Client, enter the password, go to "mysql>", and create a new database (mysql> create database test ;)

3. use the newly created database mysql> use test;

4. Import file: the file name imported from mysql> source. For example, I want to import the exported atm. SQL data file: mysql> source atm. SQL;

5. If no error message is displayed, run the show tables command. You can see that the content in the newly created test database has been imported into the atm database.

Related Article

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.