A, SQL structured query language
1. What is SQL?
SQL, English stands for Structured Query Language, Chinese meaning is Structured Query Language, which is a relational database for data definition language and methods of operation.
2, SQL classification
SQL Structured Query Language consists of six parts:
1) Data Query Language (DQL):
DQL stands for Data Query Language, which statement is also called "data retrieval statement", to obtain data from the table, the application to determine how the data is given. Reserved words SELECT is DQL (but for all SQL) is the most used verbs, other DQL commonly reserved words have WHERE, ORDER BY, GROUP BY and HAVING. These DQL reserved word often used in conjunction with other types of SQL statements.
mysql> select user,host,password from mysql.user order by user asc; +------+-----------------------+-------------------------------------------+ | user | host | password | +------+-----------------------+-------------------------------------------+ | | localhost | | | | localhost.localdomain | | | root | localhost | *8B27C4BCAD7F539091156319763740D798B44466 | | root | localhost.localdomain | | | root | 127.0.0.1 | | | root | ::1 | | +------+-----------------------+-------------------------------------------+ 6 rows in set (0.11 sec) mysql> select user,host,password from mysql.user order by user desc; +------+-----------------------+-------------------------------------------+ | user | host | password | +------+-----------------------+-------------------------------------------+ | root | localhost | *8B27C4BCAD7F539091156319763740D798B44466 | | root | localhost.localdomain | | | root | 127.0.0.1 | | | root | ::1 | | | | localhost | | | | localhost.localdomain | | +------+-----------------------+-------------------------------------------+ 6 rows in set (0.00 sec)
2) Data Manipulation Language (DML)
DML stands for Data Manipulation Language, which include statements verb INSERT, UPDATE, and DELETE. They are used to add, modify, and delete rows in the table (data). Also called action query language. Specifically, for example, the statement: delete from mysql.user where user = 'root' and host = '127.0.0.1';
3) Transaction Processing Language (TPL)
Its language to ensure that the table is the impact of DML statements in a timely manner of all the rows to be updated. TPL statements include KEGIN TRANSACTION, COMMIT, and ROLLBACK.
4) Data Control Language (DCL)
DCL full name (Data Control Language), which is licensed by the statement GRANT or REVOKE, determine individual users and groups of users access to database objects. Some RDBMS can be used to control access to GRANT or REVOKE form a column.
5) Data Definition Language (DDL)
Full name, (Data Definition Language), which includes a verb CREATE statement and DROP. Create a new table or delete the table (CREAT TABLE or DROP TABLE) in the database; a table join indexes. DDL includes a number of reserved words related to obtaining data with people database directory. It is also part of the action query.
6) Control Pointer Language (CCL)
Full CURSOR Control Language, it statements like DECLARE CUROR, FETCH INTO and UPDATE WHERE CURRENT is used alone to form the one or more operations.
Summary: The most common SQL statement is generally classified into three categories:
DDL-- data definition language (CREATE, ALTER, DROP) --------- operation and maintenance
DML-- data manipulation language (SELECT, INSERT, DELETE, UPDATE ) --- Development
DCL-- Data Control Language (GRANT, REVOKE, COMMIT, ROLLBACK ) - operation and maintenance
Two, MySQL database management application common
1. Create a database
Command Syntax: create database <database name> <= data not pay attention to the beginning of the library name
In the following test to establish a database MySQL default character set of circumstances:
a. the establishment of a database named oldboy
mysql> create database oldboy; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | oldboy | | performance_schema | | test | +--------------------+ 5 rows in set (0.00 sec) mysql> show create database oldboy \G *************************** 1. row *************************** Database: oldboy Create Database: CREATE DATABASE `oldboy` /*!40100 DEFAULT CHARACTER SET latin1 */ 1 row in set (0.00 sec)
b. Establish a database called GBK character set of oldboy_
mysql> create database oldboy_gbk DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; Query OK, 1 row affected (0.11 sec) mysql> show create database oldboy_gbk \G *************************** 1. row *************************** Database: oldboy_gbk Create Database: CREATE DATABASE `oldboy_gbk` /*!40100 DEFAULT CHARACTER SET gbk */ 1 row in set (0.00 sec)
c. the establishment of a named UTF8 database oldboy_utf8
mysql> create database oldboy_utf8 CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.00 sec) mysql> show create database oldboy_utf8 ; +-------------+----------------------------------------------------------------------+ | Database | Create Database | +-------------+----------------------------------------------------------------------+ | oldboy_utf8 | CREATE DATABASE `oldboy_utf8` /*!40100 DEFAULT CHARACTER SET utf8 */ | +-------------+----------------------------------------------------------------------+ 1 row in set (0.00 sec)
d. Create a database command different character set formats