Mysql import SQL file command and mysql remote login use details _ MySQL

Source: Internet
Author: User
Tags mysql import
Mysql SQL file import commands and mysql remote login instructions in MySQL Qurey Brower direct import *. SQL scripts cannot execute multiple SQL commands at a time. execute the SQL file command in mysql:

Mysql> source d:/myprogram/database/db. SQL;

The following is a common mysql command:

1) connect 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 a new user: (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

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.