One, database connection
1. Connect to the database through the command line
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
Two, create a database
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
Three, display the database
Example: View all databases served by mysql
Fourth, delete the database
Use the drop delete database command with caution. Once deleted, all data is gone.
The following example: delete a database named test.
Five, select the database
Example: Select the database lemon to operate.
Six, create a table
Example: Need to create a student information table to store student ID, name, gender, class, and age.
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
Eight, view the table structure
Nine, delete the table
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.
Ten, insert table data
Example:
1. Insert a piece of student information into the student information table
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
11. Modify table data
Example: Modify the student’s name as Mao Mao’s gender to male
12. Query single table data
1. Query all column information
Example: Query the information of students who are female and over 20 years old in the student table
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
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
Thirteen, query multi-table related data
Example:
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
operation result:
2. Read all data in the left table, even if there is no associated data in the right table
operation result:
3. Based on the right table, opposite to LEFT JOIN
operation result:
14. Delete table data
Example: Delete user information in the student table who are younger than 18 years old
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