[MySQL] Basic use

Installation process: [MySQL] Win8 installation process and problems encountered.
Course: Learn MySQL database in one day.
Instruction quick check: MySQL tutorial

MySQL commands are not case sensitive~

Login and logout

The account name is root and the password is 100

mysql -uroot -p110
exit;
Create, delete, display, select database

create

create DATABASE test;

delete

drop database test;

display

show databases;

select

use test
View, create, delete data tables

PS First enter the specified database to
view all tables

show tables;

View specific information of a form

desc tablename

Basic creation

CREATE TABLE student(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id))

Advanced creation

CREATE TABLE IF NOT EXISTS student(id INT NOT NULL AUTO_INCREMENT,
gender VARCHAR(100) NOT NULL,
name VARCHAR(100) NOT NULL,
date DATE,
PRIMARY KEY(id))ENGINE=InnoDB DEFAULT CHARSET=utf8;

delete

DROP TABLE student;
Add, delete, check and modify data

Increase (id will automatically increase, so no need to set)

INSERT INTO student(gender, name, date) VALUES('boy','Tom',NOW());

check

SELECT column_name,column_name
FROM table_name
[WHERE Clause]
[LIMIT N][ OFFSET M]
  1. You can use one or more tables, use a comma (,) to separate the tables, and use the WHERE statement to set the query conditions
  2. You can use an asterisk (*) to replace other fields, the SELECT statement will return all the field data of the table
  3. You can use the WHERE statement to include any conditions
  4. You can use the LIMIT attribute to set the number of records returned
  5. You can use OFFSET to specify the data offset at which the SELECT statement starts to query. The offset is 0 by default

delete

DELETE FROM student WHERE id=1;

change

UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]

例如:
update student set gender='gril', name='GiGi' where id=2;
Special query conditions

WHERE to conditionally select data

SELECT field1, field2,...fieldN FROM table_name1, table_name2...
[WHERE condition1 [AND [OR]] condition2.....
  1. To specify one or more conditions using AND or OR
  2. The WHERE clause can also be used in SQL DELETE or UPDATE commands

LIKE


  1. Use the percent sign% character to represent any character, similar to the asterisk * in UNIX or regular expressions.
  2. If the percent sign% is not used, the LIKE clause has the same effect as the equal sign =

'%a' //Data ending with
a'a%' //Data starting with a
'%a%' //Data containing a
' a ' //Three digits and the middle letter is a
' a'/ /
'A
' with two digits and the end letter is a //Two digits and the beginning letter is a

Insert picture description here
Insert picture description here
The database is composed of a sheet of tables. The
Insert picture description here
primary key is the unique identifier that distinguishes the data. The
Insert picture description here
basic type of the database is
Insert picture description here
accurate to the day
timestamp and accurate to the second

Guess you like

Origin blog.csdn.net/weixin_38705903/article/details/107961987