Cainiao database (5) MySQL essential commands

Source: Internet
Author: User
Tags mysql download
Today, we will share with you a series of common commands for connecting MySQL to specific operations. Some people may think that there are a lot of visual tools and there is no need to learn the specific commands, but I don't think so. It is undeniable that these tools make our work more convenient and convenient, however, if you really want to learn these things well, these commands cannot be bypassed.

Today, we will share with you a series of common commands for connecting MySQL to specific operations. Some people may think that there are a lot of visual tools and there is no need to learn the specific commands, but I don't think so. It is undeniable that these tools make our work more convenient and convenient, however, if you really want to learn these things well, these commands cannot be bypassed.

Today, we will share with you a series of common commands for connecting MySQL to specific operations. Some people may think that there are a lot of visual tools and there is no need to learn the specific commands, but I don't think so. It is undeniable that these tools make our work more convenient and convenient, however, if you really want to learn these things well, these commands cannot be bypassed. In short, it is very important for a programmer to be proficient in these commands. Let's take a look at the various commands I have prepared for you!


To perform operations on MySQL, you must first enable the MySQL service. Win + R --> cmd --> net start mysql (stop is to replace start with stop) will enable the MySQL service. Next we can perform a series of operations on MySQL.


1. Connect to MYSQL.

1. Connect to MySQL on the local machine.

First, we need to jump the DOS window to the mysql/bin directory. At this time, we need to create a password for the default account root, mysqladmin-u root-password 123456. Enter the mysql-uroot-p123456 command and press enter to prompt you to enter the password. note that there can be spaces or spaces before the user name, but there must be no spaces before the password. Otherwise, you can re-enter the password.


2. Connect to MYSQL on the remote host. Assume that the IP address of the remote host is 192.168.1.2, the user name is root, and the password is 123456. Enter the following command:

Mysql-h192.168.1.2-u root-p123456


3. exit MYSQL command: exit (Press ENTER)


2. Change the password.
Format: mysqladmin-u username-p old password New password
Change the password of the root user to 654321.

Mysqladmin-u root-p123456 password 654321 (here-p cannot be followed by spaces)


3. Add new users.(Note: Unlike the preceding commands, the following commands are used in the MYSQL environment. Therefore, you must first log on to MYSQL and end each command with a semicolon .)
Format: grant select on database. * to username @ login host identified by "password"

Add a user named mytest as abc to log on to any host, and grant the query, insert, modify, and delete permissions to all databases. First, use the root user to connect to MYSQL, and then type the following command:

Mysql> grant select, insert, update, delete on *. * tomytest @ "%" Identified by "abcdef ";

However, it is very dangerous to add a user. If someone knows the password of mytest, he can log on to your mysql database on any computer on the internet, you can do whatever you want. You only need to make the following changes to solve this problem:

Mysql> grant select, insert, update, delete on *. * to mytest @ localhost Identified by "abcdef ";

If you do not want mytest to have a password, you can run another command to remove the password.

Mysql> grant select, insert, update, delete on mydb. * to user1 @ localhost identified "";


Operation Skills
1. If you forget the extra points after you press Enter when making the command, you don't have to repeat the command. You just need to press a semicolon to press Enter.
That is to say, you can divide a complete command into several lines, and then use a semicolon as the end sign to complete the operation.

2. You can use the cursor to bring up or down the previous commands.


Operations on databases and data tables
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 the records in the table:
Mysql> SELECT * FROM table name;
10. insert records into the table:
Mysql> insert into table name VALUES ("data 1", "Data 2 ");
11. Update table data:

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


The basic operations have been introduced almost, and commands have been put here. The most important thing is to practice more. It is useless to look at it. When it comes to use more, you will naturally be confident. The so-called practice makes perfect. I still remember the word "oil man" in junior high school. The oil man said: "No, but he is familiar with it ." Nothing, just skillful.


MySQL download



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.