<MySQL>《MySQL高级命令(补充)》

1 查看存储引擎

// 查看当前默认存储引擎
mysql > show variables like 'table_type';
// 查看当前数据库支持的存储引擎
// -- 方法1:
mysql > show engines \G
// -- 方法2:
mysql > show variables like 'have%';

2 表

2.1 表的索引

// 查看索引
mysql > show index from tabname \G;

// 删除索引
mysql > drop index mem_hash on tabname;

2.2 建表语句

mysql > show create table emp \G;

3 创造测试数据

mysql > insert into t values(1,repeat('haha',100));

4 对表进行优化

mysql  > optimize table t;

5 blob

mysql  > create table t(id varchar(100),context blob ,hash_value varchar(40));
mysql  > insert into t values(1,repeat('beijing',2),md5(context);

6 查看可用的字符集

mysql > show character set;
// 查看字符集和校对规则
mysql > desc information_schema.character_set;
// 查看校对规则
mysql > show collation like 'gbk%';
// 字符集设置
-- my.cnf 
character-set-server=gbk
-- 启动项中指定
mysqld --character-set-server=gbk
-- 编译时指定
shell>cmake . -DDEFAULY_CHARSET=gbk
// 查看当前服务器字符集和校验规则
mysql > show variables like 'character_set_server';
mysql > show variables like 'collation_server';

7 执行计划explain

mysql > explain select * from city where city='zhengzhou' \G

8 查看视图

// 视图的定义语句
mysql > show create view staff_list \G
mysql > select * from views where table_name='staff_list' \G

9 修改语句结束符DELIMITER

// 将语句结束符由;改为$$
mysql > DELIMITER $$ 

10 查看触发器

mysql > show triggers \G

11 分布式事务XA命令

// 启动分支事务
-- xa的grtid 为test,bqual为db1
mysql > xa start 'test1','db1';
// 分支事务1为:
mysql > insert into actor(actor_id,first_name,last_name) values (301,'Simon','Tom');
// 结束分支事务
mysql > xa end 'test1','db1';
// 进入prepare状态
mysql > xa prepare 'test1','db1';
// 查看分支事务
mysql > xa recover \G
// 提交分支事务
mysql > xa commit 'test1','db1';

12 查看warning

mysql > insert into values('12798723048309','beijing');
Query OK,1 row affected, 1 warning(0.00 sec)
mysql > show warning;

13 严格模式

mysql > set session sql_mode='STRICT_TRANS_TABLES'

猜你喜欢

转载自blog.csdn.net/tangcoolcole/article/details/131050270