目录
2) create as select 复制表的结构、数据,不复制索引
4) 只复制部分列(id,name)(部分表结构),不要数据
一、库的管理
1.创建
普通创建:create 【if not exists】database 库名;
创建时设置编码:create database 库名 default character set 字符集(如:gbk)【collate utf8_unicode_ci defalut encryption='N'】; //collate-校验规则, defalut encryption是否加密
2.查看
查看创建信息(含数据库编码等信息):show create database 库名 ; //最后加 “空格\G”,显示更美观
查看编码:先use数据库,再执行:show VARIABLES LIKE '%character_set_database%';
查看端口:show global variables like 'port';
查看指定数据库大小:
select
table_schema as '数据库',
sum(table_rows) as '记录条数',
sum(truncate(data_length/1024/1024, 2)) as '数据容量(MB)',
sum(truncate(index_length/1024/1024, 2)) as '索引容量(MB)'
from information_schema.tables
where table_schema='指定数据库名'
group by table_schema
order by sum(data_length) desc, sum(index_length) desc;
查看指定数据库各表大小:
select
table_schema as '数据库',
table_name as '表名',
table_rows as '记录条数',
truncate(data_length/1024/1024, 2) as '数据容量(MB)',
truncate(index_length/1024/1024, 2) as '索引容量(MB)'
from information_schema.tables
where table_schema='指定数据库名'
order by data_length desc, index_length desc;
3.使用
4.修改
改库名:rename database 旧库名 to 新旧库名; //注意: mysql 5.1.23之后的版本,该sql不可用
改编码:alter database 库名 character set 字符集(如:gbk)【collate utf8mb4_0900_ai_ci】; //collate-校验规则
5.删除
6.设置大小写
1) windows下
2) linux下
第一步:show variables like '%case_table%'; //查看mysql是否区分大小写: