MySql 操作记录

发布时间 2023-07-06 17:53:34作者: primaryC

1, 一些特殊表

  1. 查询表的存在
select * from information_schema.tables where table_schema = 'databaseName' table_name like '%tableName%'
  1. 查询字段的存在
select * from information_schema.columns where table_schema='databaseName' and table_name='tableName' and column_name ='columnName';

2,查询配置

  1. 查询支持的数据库引擎
show engines;
  1. 查看 mysql 物理文件位置
show variables like 'datadir';

3,一些设置

  1. 关闭mysql5.7新特性对衍生表的合并优化
set session optimizer_switch='derived_merge=off';

4,一些 sql 经验

  1. 大数据量表分页优化

用覆盖索引代替全部

SELECT
	* 
FROM
	pro2 
WHERE
	id >= ( SELECT id FROM pro2 LIMIT 10000000, 1 ) 
	LIMIT 10