MySQL study notes. Basic operations of mysql


)

Preface

Since I have to learn database this semester, MySQL is particularly important, and I have been very interested in this aspect for a long time. I have been learning python crawlers before, and the data I have crawled have always wanted to be placed in the database. How can I not learn this aspect due to a number of reasons , So here, start recording your own learning today.

1. What is MySQL?

Baidu Encyclopedia explained this.

MySQL is an open source relational database management system (RDBMS) that uses the most commonly used database management language-Structured Query Language (SQL) for database management.
MySQL is open source, so anyone can download it under the General Public License and modify it according to individual needs.
MySQL has attracted much attention because of its speed, reliability and adaptability. Most people think that MySQL is the best choice for managing content when transactional processing is not required.

Two, installation steps

The installation process is not described here, please move to the network disk: https://pan.baidu.com/s/10qAbvv7we8zZnE_F2U_37Q
Extraction code: 94rc

Two, commonly used commands

1. Vignette

After the installation of MySQL is complete, open mysql
Insert picture description here
Insert picture description here
password and input is complete, and a crash occurs when you press Enter.
At the beginning, I didn't know the reason, and the environment variables were also well matched.
Insert picture description here
After checking a lot of information, I finally found a solution.
Windows+R Enter cmd to open the terminal.
Enter: mysql -u root -pEnter
Insert picture description here
to be resolved and enter MySQL.

2. Command usage

1. View all databases

show databases;

Insert picture description here
2. Create a database
named here with momo

create database momo;

Insert picture description here
3. Check it again.
Insert picture description here
Here is a newly created database momo.
4. Delete the database

drop database yingmo; 

Insert picture description here
It can be seen that the database yingmo has been completely deleted, and the mosaic is my mistyped command.
5. Use the database momo

use momo; 

Insert picture description here
6. Create a table, table name: student

Insert picture description here
7. Query the content in the table
Insert picture description here
Because the content in the table has not been created at this time, it is empty at this time.

8. Insert student information

insert into 表名(id,name,gender,grade) values ('1','lihua','M','95');

Insert picture description here
Continue to insert two more pieces of data.

insert into student(id,name,gender,grade) values ('2','lucy','F','85');
insert into student(id,name,gender,grade) values ('3','lina','F','90');

Insert picture description here
9. Modify the table name: student_grade

rename table 原表名 to 新表名;

Insert picture description here
At this time, the modification has been successful, and an error will occur if the original table name is entered again.
10. Delete a column of content in the table, here delete the gender column

alter table student_grade drop gender;

Insert picture description here
It has been deleted.
11. Modify the name length in the table (10->20)

alter table student_grade modify name varchar(20);

Insert picture description here
12. Modify the character set of the table

alter table student_grade character set gb2312;

13. Modify the information in the table,
modify all the scores to 90

update student_grade set grade=90;

Insert picture description here
All results will change at this time.
Modify the score of a single student, for example, modify the score with id 2 to 80.

update student_grade set grade=80 where id='2';

Insert picture description here

update student_grade set grade=80,name='libai' where id='2';

Insert picture description here
Several pieces of data have been modified.
14. Delete all records in the table

delete from student_grade;
或者
truncate table student_grade; 

Insert picture description here
Table has been deleted

to sum up

Be regarded as the beginning of learning MySQL! The rivers and lakes are far away, meet at high places. One day you can become the person you want to be.

Guess you like

Origin blog.csdn.net/qq_44862120/article/details/108609962