初识:
show databases; //显示数据库
create database XX;//创建数据库
drop XX; //删除
use XX; //切换数据库
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| itm |
| mysql |
| performance_schema |
| sakila |
| sys |
+--------------------+
6 rows in set (0.02 sec)
mysql> creat database itcast;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat database itcast' at line 1
mysql> creat database aaa;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat database aaa' at line 1
mysql> creat database aaaaa
-> sss
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat database aaaaa
sss' at line 1
mysql> creat database mydate;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'creat database mydate' at line 1
mysql> create database mydata01;
Query OK, 1 row affected (0.02 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| itm |
| mydata01 |
| mysql |
| performance_schema |
| sakila |
| sys |
+--------------------+
7 rows in set (0.01 sec)
mysql> create database mydata01;
ERROR 1007 (HY000): Can't create database 'mydata01'; database exists
mysql> create database if not exist mydata01;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'exist mydata01' at line 1
mysql> create database if not exists mydata01;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql>
mysql> create database mydata01 charset utf8mb4;
ERROR 1007 (HY000): Can't create database 'mydata01'; database exists
mysql> create database mydata02 charset utf8mb4;
Query OK, 1 row affected (0.01 sec)
mysql> show
-> show databases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'show databases' at line 2
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| itm |
| mydata01 |
| mydata02 |
| mysql |
| performance_schema |
| sakila |
| sys |
+--------------------+
8 rows in set (0.00 sec)
mysql> dropdatabase mydata01;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'dropdatabase mydata01' at line 1
mysql> drop database mydatabase01;
ERROR 1008 (HY000): Can't drop database 'mydatabase01'; database doesn't exist
mysql> drop database mydata01 if exists mydata01;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'if exists mydata01' at line 1
mysql> use mydata02;
Database changed
mysql> select database();
+------------+
| database() |
+------------+
| mydata02 |
+------------+
1 row in set (0.00 sec)
mysql> select database;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> use mydata01;
Database changed
mysql>