First, install the MySQL/Mariadb server and client, and connect to the server.
In the command, uppercase letters are the keywords of SQL, and lowercase letters are their own attributes and data.
0X00 connect to the database
Connect to 127.0.0.1 using mysql and log on with the root user. The password is waiting for input.
Mysql-h 127.0.0.1-u root-p
0X01 create a database
Create a database named school
Create database school;
0X02 create a table
Create a table named student
Index:
Name with a length of 10 characters cannot be blank
The number of 11 characters cannot be blank
Age of int type cannot be blank
Use school;
Use the school database
Create table student (
Name VARCHAR (10) not null,
Number VARCHAR (11) not null,
Age int not null,
Primary key (number)
);
0X03 query databases and tables
Show databases;
View all databases
Show bales;
View tables in the database in use
0X04 insert data
Insert into student VALUES ('lilei', '20140901', 15 );
Insert new data and write data in sequence
INSERT student (name) VALUES ('hanmeimei ');
Custom sequential write
0X05 query data
SELECT name FROM student;
Query all names in the student table
SELECT name FROM student WHERE number = 0002;
Query the name with number 0002 in the student table
SELECT name FROM student WHERE age BETWEEN 20 and 30;
Query the name of the age in the student table between 20 and 30
0X06 update data
UPDATE student SET name = 'xiaohei' WHERE number = '000000 ';
Update all the names with 0002 to xiaohei.
0X07 delete data
Delete from student WHERE number = '123'
Delete all data whose number is 0002