Import and export SQL files directly using the MySQL command

Source: Internet
Author: User
Tags mysql command line

Reference: http://blog.csdn.net/jiary5201314/article/details/52026816

1.MYSQL exporting a database to a SQL file

Actually very simple, is a statement on it, first we open the CMD, do not go into the MySQL command interface, directly according to the following format to knock the export statement into, and then enter the password can be:

mysqldump-h[Host IP]-u[user name]-p [Database to export]>[exported path//[filename].sql]

Well, it might be a bit of an abstraction, so let's take an example, now that I have a database bookinfodb in MySQL, I'm going to export it and save it to the D drive.

This time we go to the D-disk directory, we can see a bookinfodb.sql file.

2. Import data from a SQL file into MySQL

1> First, we should enter the MySQL command interface in CMD, the format is very simple, that is, mysql-u[user name]-h[host address, default does not write localhost]-p and then enter the password can be

2> creating a database using Create DATRABSE [database name] and selecting the database to use using the use [database name]

3> to import SQL files directly using source [path//*.sql]

The next step is to output a large list of query OK messages.

3. Deposit the results of the query into a table

INSERT INTO TableB select * from TableA;

4. Write the result of the query to the file

Go to MySQL command line, mysql > select * from TableA to OUTFILE '/home/out.txt ';

Import and export SQL files directly using the MySQL command (GO)

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.