1、创建数据库
1.1 CREATE {DATABASE|SCHEMA} db_name;
mysql> CREATE DATABASE bingwu;或CREATE SCHEMA bingwu;
Query OK, 1 row affected (0.00 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| bingwu |
1.2检查数据库是否存在,不存在则创建CREATE DATABASE[IF NOT EXISTS] db_name;
mysql> CREATE DATABASE IF NOT EXISTS bingwu;
Query OK, 1 row affected, 1 warning (0.00 sec)
1.3 创建数据的同时指定编码方式;
CREATE DATABASE [IF NO EXISTS] db_name [DEFAULT] CHARCTER SET [=] charset;
注意:数据库的名称要有意义;名称不能包含特殊字符或者是MySQL关键字
2、 查看全部数据库 SHOW DATABASES|SCHEMAS;
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bingwu |
3、查看指定的数据库详细信息 SHOW CREATE DATABASE db_name;
mysql> SHOW CREATE DATABASE bingwu;
+----------+-----------------------------------------------------------------+
| Database | Create Database |
+----------+-----------------------------------------------------------------+
| bingwu | CREATE DATABASE `bingwu` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------+-----------------------------------------------------------------+
1 row in set (0.00 sec)
4、修改指定数据库编码方式 alter database db_name [default] character set [=] charset;
mysql> ALTER DATABASE bingwu DEFAULT CHARACTER SET=utf8;
Query OK, 1 row affected (0.00 sec)
mysql>
5、打开指定数据库 use db_name;
mysql> USE bingwu;
Database changed
6、得到当前打开的数据库 select databse()|schema();
mysql> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| bingwu |
+------------+
1 row in set (0.00 sec)
mysql>
7、删除指定的数据库drop database db_name; 如果数据库存在删除:drop database [if exists] db_name;
mysql> DROP DATABASE bingwu1;
Query OK, 0 rows affected (0.01 sec)
mysql> DROP DATABASE IF EXISTS bingwu1;# 不存在会有警告
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
8、查看警告warning
mysql> show warnings;
+-------+------+-------------------------------------------------------+
| Level | Code | Message |
+-------+------+-------------------------------------------------------+
| Note | 1008 | Can't drop database 'bingwu1'; database doesn't exist |
+-------+------+-------------------------------------------------------+
1 row in set (0.00 sec)
mysql