-
查询当前所有存在的数据库
show databases; -
查询数据库支持哪些引擎
show engines; -
查询数据库当前使用的引擎
show variables like '%storage_engine%'; -
导入数据库
source 文件路径; -
导出整个数据库
mysqldump -u用户名 –p密码 数据库名 > 导出的文件名;注意:该命令不能在MySQL内执行,需要退出MySQL,在终端窗口命令行下执行 -
导出数据库表
mysqldump -u用户名 -p密码 数据库名 数据库表名> 导出的文件名;注意:该命令不能在MySQL内执行,需要退出MySQL,在终端窗口命令行下执行 -
新建数据库
create database 数据库名; -
删除数据库
drop databas 数据库名; -
选择数据库
use 数据库名; -
新建数据库表
create table 表名 (字段名 类型(长度) <是否为空> <是否主键(primary key)> <自动增加(auto_increment)> <default(默认值)> [, ... 字段名 类型(长度) ...])<ENGINE=指定引擎名> <DEFAULT CHARSET=字符集>; -
查询数据表结构
desc 数据库表名; -
删除数据库表
drop table 数据库表名; -
创建单值索引
create index 索引名 on 数据库表名(字段名);或者alter table 数据库表名 add index 索引名(字段名); -
创建唯一索引
create unique index 索引名 on 数据库表名(字段名);或者alter table 数据库表名 add unique index 索引名(字段名); -
创建复合索引
create index 索引名字 on 数据库表名(字段名1, 字段名2, ...);或者alter table 数据库表名 add index 索引名(字段名1, 字段名2, ...); -
查询索引
show index from 数据库表名; -
删除索引
drop index 索引名 on 数据库表名; -
分析SQL的执行计划
explain SQL语句;分析字段介绍: id: 编号 select_type: 查询类型 table: 数据库表名 partitions: 该列显示的为分区表命中的分区情况,非分区表该字段为空(null) type: 类型 (从优到差依次为:system > const > eq_ref > ref > fulltext > ref_or_null > index_merge > unique_subquery > index_subquery > range > index > ALL) possible_keys: 预测使用的索引 key: 实际使用的索引 key_len: 实际使用的索引长度 ref: 表之间的引用 rows: 查到的数据个数 filtered: 表示存储引擎返回的数据在server层过滤后,剩下多少满足查询的记录数量的比例,注意是百分比,不是具体记录数 Extra: 额外的数据信息 -
清屏
system clear;或者Ctrl + L




