MySQL数据库的操作
创建数据库
语法
CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name [create_specification] ... create_specification: [DEFAULT] CHARACTER SET [=] charset_name | [DEFAULT] COLLATE [=] collation_name
实践
mysql> CREATE DATABASE IF NOT EXISTS sty_data -> CHARACTER SET utf8mb4 -> COLLATE utf8mb4_general_ci; Query OK, 1 row affected (0.02 sec)
查看数据库
语法
SHOW DATABASES [LIKE ‘模式’ WHERE ‘条件’]
实践
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | data1 | | information_schema | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.03 sec)
选择数据库
语法
USE 数据库名
实践
mysql> USE test;Database changed
删除库
语法
DROP DATABASE [IF EXISTS] 库名
实践
mysql> DROP DATABASE IF EXISTS data1; Query OK, 0 rows affected (0.02 sec)
修改库
语法
ALTER DATABASE 库名
[DEFAULT] CHARACTER SET 字符集 |
[DEFAULT] COLLATE 校对集
实践
mysql> ALTER DATABASE test -> CHARACTER SET utf8mb4 -> COLLATE utf8mb4_general_ci; Query OK, 1 row affected (0.00 sec)