MySQL basically uses the five major commands in the Command (1)

Source: Internet
Author: User

The following articles mainly describe the basic usage commands of MySQL. If you are interested in the basic usage commands of MySQL, you can better understand them through the following articles, the following is a description of the specific solution. I hope it will help you in your future study.

MySQL basic use command 1. Connect to MYSQL

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

1. Connect to the local MYSQL

First, open the DOS window, enter the mysql \ bin directory, type the mysql-u root-p command, and press enter to prompt you to enter the password. The MYSQL prompt is: mysql>.

2. Connect to MYSQL on the remote host

Assume that the IP address of the remote host is 110.110.110.110, the user name is root, and the password is abcd123. Run the following command: mysql-h110.110.110.110-u root-p 123. Note: you do not need to add spaces between u and root. The same applies to other commands ).

3. Start and Stop mysql

Start the MYSQL service.

Stop the MYSQL service. net stop mysql.

4. check whether a port conflict exists.

Netstat-na | findstr 8080 check the listening port. findstr is used to check whether the following port exists.

5. Exit MYSQL Command

Exit and press Enter ).

MySQL Uses command 2 to change the password.

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

1. Add a password ab12 to the root user.

Enter the mysql \ bin directory in DOS and enter the command mysqladmin-u root-password ab12.

2. Change the root password to djg345.

Mysqladmin-u root-p ab12 password djg345.

MySQL basic use command 3. Add new users

Note: 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 ".

1. Add a user test1 with a password of abc.

You can log on to any host and have the permission to query, insert, modify, and delete all databases. Run the following command to connect to MYSQL as the root user: grant select, insert, update, delete on *. * to test1 @ "%" Identified by "abc ".

2. Add a user named "test2" and set the password to "abc ".

You can only log on to localhost and query, insert, modify, and delete the database mydb.

Command:

 
 
  1. grant select,insert,update,delete on mydb.* 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. command:

 
 
  1. grant select,insert,update,delete on mydb.* to test2@localhost identified by “” ; 

MySQL basic command 4. Display command

1. display the list of databases on the Current Database Server

Mysql> show databases ;.

Note: the mysql database contains the MYSQL system information. We change the password and add new users to use this database for operations.

2. display data tables in the database

Mysql> USE Database Name ;.

Mysql> show tables ;.

3. display the data table structure

Mysql> DESCRIBE table name ;.

4. Create a database

Mysql> create database name ;.

5. Create a data table

Mysql> USE Database Name ;.

Mysql> create table Name (field name: VARCHAR (20); field name: CHAR (1 ));.

6. delete a database

Mysql> drop database name ;.

7. delete a data table

Mysql> drop table name ;.

8. Clear records in the table

Mysql> delete from table name ;.

9. Display records in the table

Mysql> SELECT * FROM table name ;.

10. insert records into the table

Mysql> insert into table name VALUES ("hyq", "M ");.

11. Update table data

Mysql-> UPDATE table name: SET field name: 1 = 'a'; field name: 2 = 'B' WHERE field name: 3 = 'C ';.

12. load data into a data table in text mode

Mysql> load data local infile "D:/mysql.txt" into table name;

13. Import the. SQL FILE command

Mysql> USE Database Name;

 
 
  1. mysql> SOURCE d:/mysql.sql; 

14. Change the root password through the command line

 
 
  1. Mysql> UPDATE mysql. user SET password = PASSWORD ('new password') WHERE User = 'root ';
  2. Mysql> flush privileges;

15. display the Database Name of use

Mysql> select database ();.

16. display the current user

Mysql> select user ();


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.