Learning MySQL - database operations

Create a database
Syntax
1 create database [if not exists] database name
2 [default] character set and character set
3 [default] collate collation name;
instance
Copy the code
1 MySQL> the Create Database IF not EXISTS Demo
2 -> default Character the SET utf8
3 -> default COLLATE utf8_general_ci;
4 query the OK, 1 Row affected (0.00 sec)
5
6 MySQL>
copy the code
view the definition of a statement of the database
syntax
1 show create database demo;
to query all database
syntax
1 show databases;
instance
copy the code
1 mysql > Show Databases;
2 + -------------------- +
. 3 | Database |
. 4 ----------------- + + ---
5 | information_schema |
6 | Demo |
7 | MySQL |
. 8 | performance_schema |
. 9 -------------------- + +
10 rows in SET. 4 (0.00 sec)
. 11
12 is MySQL>
copy the code
to select which database to use
syntax
1 use Demo;
example
. 1 MySQL> use Demo;
2 database changed
. 3 MySQL>
modify database
syntax
1 alter database database name
2 [default] character set and character set
3 [default] collate the collation name;
example
copy the code
1 mysql> show create database Demo;
2 + ---------- + ----------------------------------- + ----------------------------
3 | Database | the Create Database |
4 + ---------- + - -------------------------------------------------- + ------------
5 | Demo | the CREATE DATABASE demo/!40100 DEFAULT CHARACTER SET utf8 / |
6 +----------+---------------------------------------------------------------+
7 1 row in set (0.00 sec)
8
9 mysql> alter database demo
10 -> character set gb2312
11 -> collate gb2312_chinese_ci;
12 Query OK, 1 row affected (0.00 sec)
13
14 mysql> show create database demo;
15 +----------+-----------------------------------------------------------------+
16 | Database | Create Database |
17 +----------+-----------------------------------------------------------------+
18 | demo | CREATE DATABASE demo /!40100 DEFAULT CHARACTER SET gb2312 / |
19 + ---------- + ------------------------------------- + ----------------------------
20 Row 1 in the SET (0.00 sec)
21
22 MySQL>
copy the code
to delete the database
syntax
1 drop database [if exists] the database name;
example
. 1 MySQL> database drop Demo;
2 Query the OK, 0 rows affected, 2 Represents warnings (0.00 sec)
. 3
. 4 MySQL>

Guess you like

Origin blog.51cto.com/14551317/2440344