MYSQL study notes three (basic database operations)

First, create a database
created on the database, in a note has been done in a visual explanation. Visual creation is relatively simple, mainly here to illustrate how to create a database using T-SQL commands.

1.1 The syntax to create a database
to create a database using the CREATE DATABASE statement

1.1.1 SQL CREATE DATABASE Syntax
CREATE DATABASE database_name []
1
above and CREATE DATABASE two keywords. database_name is the name of the database, such as creating a firstDB, the command is as follows:

CREATE DATABASE firstDB #firstDB for the name of the database
1

MYSQL study notes three (basic database operations)
1.1.2 CREATE DATABASE IF NOT EXISTS syntax
method 1.1.1 Create a new database is not a problem, but if at the time of executing the command, if the database is created already exists, it will fail to create the database, its message as shown below (here to re-create a firstDB the database as an example):
MYSQL study notes three (basic database operations)
when creating a database, a lot of the time, we hope that the logic is: if the database (firstDB) to create the database (firstDB) in the case does not exist. This time we need to use the following syntax structure:

CREATE DATABASE IF NOT EXISTS [database_name]
1
is added in the judgment ----- IF NOT EXISTS statement to create the database. E.g:

CREATE DATABASE IF NOT EXISTS firstdb
1

MYSQL study notes three (basic database operations)
1.1.3 CREATE DATABASE test DEFAULT CHARACTER
here using the following statement to create secondDB database, as follows:

CREATE DATABASE secondDB DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci.
1
above statements can be viewed as three parts: CREATE DATABASE secondDB, DEFAULT CHARACTER SET utf8, COLLATE utf8_general_ci.

CREATE DATABASE secondDB: representatives is to create a database secondDB.
DEFAULT CHARACTER SET utf8: representatives is to set the default encoding format library to utf8 format.
COLLATE utf8_general_ci: represents the database collation, the utf8_bin each character string with binary data, case sensitive.
utf8_genera_ci case insensitive, CI is an abbreviation for case insensitive, i.e., case-insensitive. utf8_general_cs case-sensitive, the abbreviation CS is case sensitive, i.e., case sensitive.
Second, select the database view and
2.1 to view database
2.1.1 SHOW DATABASES statement
SHOW DATABASES # enumerate all databases (see all database equivalent to select schema_name from information_schema.schemata \ G. \ G replacement;, output in the form of longitudinal reports As a result, there is conducive to reading.)
1

MYSQL study notes three (basic database operations)
2.1.2 select database () statement to
select database () # to view the current use of the database
MYSQL study notes three (basic database operations)
2.1.3 show variables LIKE 'port'; statement
SHOW VARIABLES LIKE 'port'; # view the database uses port
MYSQL study notes three (basic database operations)
2.1.4 show variables like 'character% 'statements
show variables like' character% '# View database coding
MYSQL study notes three (basic database operations)
2.2 select database
2.2.1 visualization
MYSQL study notes three (basic database operations)
2.2.2 commands
use the keyword [database_name] #use
MYSQL study notes three (basic database operations)
Third, delete the database
3.1 visualization
you want to delete the database, with firstdb here as an example.
MYSQL study notes three (basic database operations)
Click on the delete key on the keyboard. The following pop-up message box, click OK, the database normally be deleted.
MYSQL study notes three (basic database operations)
MYSQL study notes three (basic database operations)
3.2 Command
3.2.1 DROP DATABASE [database_name]
Use this command to delete firstdb database (if the library does not exist, create the library);
MYSQL study notes three (basic database operations)
the main attention is that the command is a simple command to delete the database, delete a non-existent when when the database, the command will be prompted to err, as follows:
MYSQL study notes three (basic database operations)
3.2.2 DROP dATABASE [IF eXISTS] database_name
command to solve in 3.2.1, when you delete a database, there is a problem. The meaning of this command is: When you want to delete the database exists, delete the database to perform the action. as follows:
MYSQL study notes three (basic database operations)

Guess you like

Origin blog.51cto.com/14525650/2436566