Common directives
instruction function |
Instructions |
View/Query |
Show,select,desc |
Create |
Create |
Delete |
Drop,delete,truncate |
Toggle/Enter |
Use |
Add a record |
Insert |
View the list of databases
show databases;
View current database The user logged in
Select User ();
See which tables are in the current database
Show tables;
To view the encoding type of the test database
Show create DATABASE test;
View the type of test table
Show create TABLE test;
View the definition information for the test table
DESC test;
Create a database
Create Database db1;
Create a database of type UTF8MB4
Create DATABASE DB2 DEFAULT CHARACTER SET UTF8MB4;
Create a table
CREATE TABLE students (ID int UNSIGNED not NULL PRIMARY key,name VARCHAR (a) not null,age tinyint UNSIGNED);
Add record for EMP table (with Id,name,sex,age field)
INSERT into EMP (id,name,sex,age) VALUES (1, ' xiaoming ', ' m ', 30);
Modify the contents of the EMP table (number of fields in the first few lines)
Update emp set age=18 where id=4;
Deleting a database
Drop database db1;
Delete Test table
DROP TABLE Test
Delete records in an EMP table
Delete from emp where name= ' Lvdou ';
Delete EMP entire table record
Delete from EMP;
Note: This command is slow to delete tens of thousands of records (because he logs, you can use the log to restore)
TRUNCATE TABLE emp; This command deletes tens of thousands of records, particularly quickly.
Because he doesn't record logs.
Empty the EMP table
TRUNCATE TABLE EMP;
Bulk Execute SQL Program
MySQL < Hellodb_innodb.sql
Note: You can also view the database without entering the database
Mysql-e ' Show databases '
Linux-mysql basic instructions-Adding and deleting changes