A study guide for common MySQL commands that testers must have

One, database connection

1. Connect to the database through the command line

A study guide for common MySQL commands that testers must have

 

Enter the above command, press Enter, enter the password, and press Enter.

If the mysql> command prompt window appears, the login is successful.

You can enter any sql statement under mysql>.

2. Exit mysql

A study guide for common MySQL commands that testers must have

 

Two, create a database

A study guide for common MySQL commands that testers must have

 

After connecting to the mysql service, use the sql statement.

You can connect through commands or through client tools such as Navicat. The following creates a database named lemon

A study guide for common MySQL commands that testers must have

 

Three, display the database

A study guide for common MySQL commands that testers must have

 

Example: View all databases served by mysql

A study guide for common MySQL commands that testers must have

 

Fourth, delete the database

A study guide for common MySQL commands that testers must have

 

Use the drop delete database command with caution. Once deleted, all data is gone.

The following example: delete a database named test.

A study guide for common MySQL commands that testers must have

 

Five, select the database

A study guide for common MySQL commands that testers must have

 

Example: Select the database lemon to operate.

A study guide for common MySQL commands that testers must have

 

Six, create a table

A study guide for common MySQL commands that testers must have

 

Example: Need to create a student information table to store student ID, name, gender, class, and age.

A study guide for common MySQL commands that testers must have

 

Analysis:

◆ int is an integer, where the student number sno and class number sclass are set to integer;

◆ Varchar character type, where the name sname, gender ssex, age sage are set to character type;

◆ The field property is set to not null, which means that the field value is not allowed to be empty;

◆ The primary key keyword is used to define the column as the primary key. The primary key is unique and non-repetitive, and the number is generally used as the primary key;

◆ auto_increment defines the column attribute as self-increment, which is generally used for the primary key, and the value will automatically increase by 1 when inserting data;

◆ comment is equivalent to adding a note to the column;

◆ DEFAULT CHARSET set the code, utf8 can prevent garbled characters in Chinese.

Seven, display the database

A study guide for common MySQL commands that testers must have

 

Eight, view the table structure

A study guide for common MySQL commands that testers must have

 

Nine, delete the table

A study guide for common MySQL commands that testers must have

 

Please be careful when deleting a table with drop, because the table and the data contained in it will disappear after the delete command is executed.

The following example: delete a data table named student.

A study guide for common MySQL commands that testers must have

 

Ten, insert table data

A study guide for common MySQL commands that testers must have

 

Example:

1. Insert a piece of student information into the student information table

A study guide for common MySQL commands that testers must have

 

Note: If the data value is a character type, it must be enclosed in single quotation marks or double quotation marks.

2. Batch insert, insert multiple pieces of student information

A study guide for common MySQL commands that testers must have

 

11. Modify table data

A study guide for common MySQL commands that testers must have

 

Example: Modify the student’s name as Mao Mao’s gender to male

A study guide for common MySQL commands that testers must have

 

12. Query single table data

A study guide for common MySQL commands that testers must have

 

1. Query all column information

Example: Query the information of students who are female and over 20 years old in the student table

A study guide for common MySQL commands that testers must have

 

2. Query the column information of the specified field

Example: query the student table, the gender of female or the name of the student who is over 20 years old

A study guide for common MySQL commands that testers must have

 

3. Query the first few lines of information

Example: Query the first 2 rows of student information in the student table, whose gender is female and who is over 20 years old

A study guide for common MySQL commands that testers must have

 

Thirteen, query multi-table related data

A study guide for common MySQL commands that testers must have

 

Example:

A study guide for common MySQL commands that testers must have

 

1. The above left table user table, the right table is the object information user_lover table of the left table, query the information of the object relationship in the two tables

A study guide for common MySQL commands that testers must have

 

operation result:

A study guide for common MySQL commands that testers must have

 

2. Read all data in the left table, even if there is no associated data in the right table

A study guide for common MySQL commands that testers must have

 

operation result:

A study guide for common MySQL commands that testers must have

 

3. Based on the right table, opposite to LEFT JOIN

A study guide for common MySQL commands that testers must have

 

operation result:

A study guide for common MySQL commands that testers must have

 

14. Delete table data

A study guide for common MySQL commands that testers must have

 

Example: Delete user information in the student table who are younger than 18 years old

A study guide for common MySQL commands that testers must have

 

Recommend a software testing learning exchange group: 785128166, there are shared videos, interview guidance, test materials, mind maps, and videos in the group. They are all dry goods, you can download and watch. Mainly share test foundation, interface test, performance test, automated test, TestOps architecture, Jmeter, LoadRunner, Fiddler, MySql, Linux, resume optimization, interview skills, and actual video data of large-scale test projects. Use every minute and every second of your time to learn to improve yourself, and don't use "no time" to conceal your mental laziness! Try hard while you are young, and give your future self an explanation!

Public number: Programmer Erhei, after paying attention, you can receive a large amount of learning materials for free.

Good things should be shared with friends
 

Guess you like

Origin blog.csdn.net/m0_52668874/article/details/114850306