MySQL case combat--Basic operation of MySQL database

1. Statement basics

1.1 Introduction to SQL

Structured Query Language (Structured Query Language)

Standard language for performing data operations, data retrieval and data maintenance on relational databases

1.2 SQL statement classification

classification effect content
DDL (Data Definition Language): Data Definition Language Define operations on database objects (libraries, tables, columns, indexes) CREATE、DROP、ALTER、RENAME、 TRUNCATE等
DML (Data Manipulation Language): Data Manipulation Language Define operations on database records INSERT、DELETE、UPDATE、SELECT等
DCL (Data Control Language): Data Control Language

Define access rights and security levels to databases, tables, fields, and users

GRANT、REVOKE等
Transaction Control: Transaction Control   COMMIT、ROLLBACK、SAVEPOINT等

1.3 Writing specifications of SQL statements

  • Not case sensitive (uppercase is recommended);
  • String constants are reversed case;
  • SQL statements can be written in single or multiple lines, ending with ";";
  • Keywords cannot span multiple lines or be abbreviated;
  • Use spaces and indentation to improve the readability of statements;
  • The clauses are usually located on separate lines for easy editing and improved readability.

2. Database operations

2.1 View

SHOW DATABASES

语法:SHOW DATABASES [LIKE wild];

2.2 Create

CRATE DATABASE

语法:CREATE DATABASE [IF NOT EXISTS]数据库名;


示例:

mysql> create database if not exists db2 character set utf8;

Query OK, 1 row affected (0.00 sec)


创建一个名为school指定默认的字符集为utf8,指定了校对规则为utf8,ci表示对大小写不敏感:

create database school DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

2.3 Delete

Only one library can be deleted at a time​​​​​​​

DROP DATABASE

语法: DROP DATABASE [IF EXISTS]数据库名;

2.4 Switch

语法:USE 数据库名;

3. MySQL Character Set

The MySQL character set includes two concepts: CHARACTER and COLLATION.

View character set:

mysql> show variables like 'character%';

View proofreading rules:

mysql> SHOW COLLATION;

MySQL character sequence naming rules are: start with the name of the character set corresponding to the character sequence, center the country name (or center general), and end with ci, cs, or bin.

ci means case-insensitive, cs means case-sensitive, and bin means compare by binary code value.

Guess you like

Origin blog.csdn.net/XY0918ZWQ/article/details/113177466