注意:以下中括号的内容可以省略不输入,如果要输入中括号里面的内容,那么不要把[]也输入进去
查询 1、查询所有数据库
show databases;
2、查询当前数据库
select database();
例如当我们使用了很多use命令,不知道当前在哪个数据库,就可以使用上述命令查询当前所处的数据库
创建
create database [if not exists] 数据库名 [default charset 字符集] [collate 排序规则]
例如一般情况下创建数据库:create database itcast; 例如先进行判断存在,避免重复创建报错:create database if not exists itcast2; 例如创建指定字符集的数据库:create database itcast3 default charset utf8mb4; 注意数据库服务可以创建多个数据库,一个数据库可以创建多张表
删除
xxxxxxxxxx
drop database [if exists] 数据库名;
例如一般情况下删除数据库:drop database itcast3; 例如先进行判断存在,避免删除空的报错:drop database if exists itcast3;
使用
use 数据库名;