MySQL Import and Export. SQL file and common command summary, mysql. SQL

Source: Internet
Author: User
Tags mysql import

MySQL Import and Export. SQL file and common command summary, mysql. SQL

Directly import the *. SQL script in MySQL Qurey Brower. You cannot execute multiple SQL commands at a time. Execute the SQL FILE command in mysql:

Mysql> source c: \ test. SQL;

The following is a common mysql command:

(1) connecting to MYSQL:

Format: mysql-h host address-u user name-p User Password

1. Example 1: connect to MYSQL on the local machine

First, open the DOS window, enter the bin directory under the mysql installation directory, for example, D:/mysql/bin, and then type the command mysql-uroot-p, after you press enter, you are prompted to enter the password. If you have just installed MYSQL, the Super User root does not have a password, so you can directly press enter to enter MYSQL. The MYSQL prompt is: mysql>

2. Example 2: connect to MYSQL on the remote host (Remote: IP address)

Assume that the IP address of the remote host is 10.0.0.1, the user name is root, and the password is 123. Enter the following command:

Mysql-h10.0.0.1-uroot-p123

(Note: you do not need to add spaces for u and root. The same applies to others)

3. Exit MYSQL Command

Exit (Press ENTER)

(2) Change the password:

Format: mysqladmin-u username-p old password New password

1. Example 1: Add a 123 password to the root user. First enter the directory C:/mysql/bin in DOS, and then type the following command:

Mysqladmin-uroot-password 123

Note: because the root account does not have a password at the beginning, the old-p password can be omitted.

2. Example 2: change the password of root to 456.

Mysqladmin-uroot-pab12 password 456

(3) Add new users:(Note: Unlike the above, the following commands in the MYSQL environment are followed by a semicolon as the command Terminator)

Format: grant select on database. * to username @ login host identified by "password"

Example 1: Add a user named "test1" with the password "abc" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MYSQL, and then type the following command: grant select, insert, update, delete on *. * to test2 @ localhost identified by "abc ";

If you do not want test2 to have a password, you can run another command to remove the password. Grant select, insert, update, delete on mydb. * to test2 @ localhost identified "";

(4) display commands

1. display the Database List:

Show databases; At the beginning, there were only two databases: mysql and test. The mysql database contains the MYSQL system information. We change the password and add new users to use this database for operations.

2. display the data tables in the database:

Use mysql; // open the show tables library;

3. display the data table structure:

Describe table name;

4. database creation:

Create database name;

5. Create a table:

Use Database Name; create table Name (field setting list );

6. Delete databases and tables:

Drop database name; drop table name;

7. Clear records in the table:

Delete from table name;

8. Display records in the table:

Select * from table name;

Export SQL scripts

Mysqldump-u username-p Database Name> storage location

Mysqldump-u root-p test> c:/a. SQL

Import SQL scripts

Mysql-u username-p database name <storage location

Mysqljump-u root-p test <c:/a. SQL

Note: The test database must already exist.

Use Cases for MySQL Export Import commands

1. Export the entire database

Mysqldump-u username-p Database Name> exported file name

Mysqldump-u wcnc-p smgp_rj_wcnc> wcnc. SQL

2. Export a table

Mysqldump-u user name-p Database Name> exported file name

Mysqldump-u wcnc-p smgp_rj_wcnc users> wcnc_users. SQL

3. Export a database structure

Mysqldump-u wcnc-p-d -- add-drop-table smgp_apps_wcnc> d: wcnc_db. SQL

-D no data -- add-drop-table adds a drop table before each create statement.

4. 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


How does mysql import the database of the SQL file through the command line?

First, a command should be followed by a plus sign;
In addition, you can use the source command to execute the SQL file, for example, source d:/carelife. SQL;

How does mysql import SQL files?

After entering mysql, run the following command to import the SQL script file:
Mysql> source test. SQL;
In fact, test. SQL is the SQL file you want to import.
Source is the command to import SQL files
For example, if you have a test. SQL file on drive F, the import command is as follows:
Source F:/test. SQL;

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.