数据库相关命令

查看当前有多少个连接数:

show status like ‘connections ‘;


查看数据库运行时间:

show status like ‘uptime’;


查询慢查询:

show status like ‘slow_queries’;


开启慢查询:

service mysqld start --safe-mode --slow-query-log


查询慢查询时间:

show variables like ‘long_query_time’;


修改慢查询时间:

set long_query_time=2


查看执行了多少次 insert select update delete:

show status like ‘com_select’; //其它依次类推


查询当前对话:

show session status ….


如果要查询从数据库启动到现在:

show global status …


竖着显示查询结果:

\G


创建索引:

create index 索引名 on 表名 (字段名)


查看索引:

show index from 表名

show indexes form 表名

show keys from 表名



索引操作:

① 主键索引

新增:alter table 表名 addd priamry key (字段名)

删除:alter table 表名 drop primary key;


② 普通索引

新增:create index 索引名 on 表名( 字段名,..)

删除:alter table 表名 drop index 索引名


③ 唯一索引

新增:create table aaa ( id int priamry key, name varchar(20) unique);

create unique index 索引名 on 表名 (字段)

删除:alter table 表名 drop index 索引名



你可能感兴趣的:(数据库,命令)