mysql 常用查询
1.unix时间戳的使用
unix_timesamp、from_unixtime 函数 和 datatime_format函数。
// 从datetime 类型取做整形 unixtime时间戳;
select unix_timestamp( datetime ) from examplestables;
// 从整形转换成datetime类型,时间格式
select from_unixtime( datetime ) from exampletables;
// 对unix 时间戳自定义时间段分组统计 distinct 不重复 dateformat 时间串自定义格式输出
select count(distinct(roleid)), dateformat( from_unixtime(datetime),"%Y-%m-%d" ) days from tmptable group by days;
// 表合并 重复键值的时候只更新不报错
insert into tmptable2 select * from tmptable on duplicate key update set A=a;
// 查询结果字符串拼接
select concat("s1_", strName ) from tmptable;
2. sleep连接超时时间 --避免过多的sleep连接占用资源
set global wait_timeout=305;
3.创建索引 表不加主键,不加索引的查询非常慢
create index idx_datarow on exampletables(datarow);
4.myisam 引擎 和 innodb引擎
myisam在 update insert 使用表级锁
innodb 在update ,insert时使用 的是按照索引和键值的行级锁,并发性更高
innodb 在创建的表行属性 为fixed的时候,blob类型字段过长,过多会报错。
Row size too large. The maximum row size for the used table type, not counting BLOBs, is 1982. You have to change some columns to TEXT or BLOBs。
需要改成dynamic。动态长度的行数据。
5.查询某列数据重复的数据值 exampletables 表中,exrow行重复的列
select * from exampletables where exrow in ( select exrow from exampletables group by exrow having count(exrow) > 1 );
6.修改表的引擎,修改表的列类型
alter table exampletable ENGINE=InnoDB;
alter table exampletable modify column exrowname varchar(64);
7.查看正在执行的sql命令,show processlist
select * from information_schema.processlist where command <> 'Sleep';
8.查看慢查询日志,有助于捕捉耗时查询,异常查询
show variables like 'slow';
log-slow-queries=/data/mysqldata/slowquery。log
long_query_time=2
9.GTID(Global Transaction ID)是对于一个已提交事务的编号,并且是一个全局唯一的编号。
GTID实际上是由UUID+TID组成的。其中UUID是一个MySQL实例的唯一标识。TID代表了该实例上已经提交的事务数量,并且随着事务提交单调递增。下面是一个GTID的具体形式
3E11FA47-71CA-11E1-9E33-C80AA9429562:23
9.mysql 备份--set-gtid-purged=OFF 是忽略 变量中记录的是本机上已经执行过,但是已经被purge binary logs to命令清理的gtid_set。
mysqldump -uexuser -p -h127.0.0.1 --databases --no-data dbname --set-gtid-purged=OFF >/data/bk.sql
附上备份和恢复脚本:命令行执行
mysqldump -uroot -p -h 11.111.111.111 -P3306 --default-character-set=utf8 --set-gtid-purged=OFF --password --databases test > /home/sqlbackup
mysql -h11.111.111.111 -uroot -P3306 -p --default-character-set=utf8 < /home/sqlbackup
注意,上述脚本中,备份的部分要加入--set-gtid-purged=OFF参数,防止在备份出的sql脚本中生成 SET @@global.gtid_purged 语句:
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF.
官方文档关于set-gtid-purged是这样写的:
This option enables control over global transaction ID (GTID) information written to the dump file, by indicating whether to add a SET @@global.gtid_purged statement to the output.
10.查询目前的 执行非sleep命令
select * from information_schema.processlist where command <>'Sleep';
mysql 常用查询的更多相关文章
- 23个MySQL常用查询语句
23个MySQL常用查询语句 一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!> ...
- mysql常用查询归纳
一.mysql查询的五种子句 where(条件查询).having(筛选).group by(分组).order by(排序).limit(限制结果数) .where常用运算符: 比较运算符 > ...
- mysql—常用查询语句总结
关于MySQL常用的查询语句 一查询数值型数据: ; 查询谓词:>,=,<,<>,!=,!>,!<,=>,=< 二查询字符串 SELECT * FROM ...
- MySQL常用查询语句汇总(不定时更新)
在这篇文章中我会通过一些例子来介绍日常编程中常用的SQL语句 目录: ## 1.数据库的建立 ## 1.数据库的建立 实例将ER图的形式给出: 由此转换的4个关系模式: ...
- mysql常用查询命令
转引自:https://www.cnblogs.com/widows/p/7137184.html 常用mysql命令 show variables like 'character_set_clien ...
- [转]MySQL常用查询
单表查询 ①查询所有 * mysql> select * from student; ②查询选中字段记录 mysql> select s_name from student; ③条 ...
- MySQL常用查询语句集合《转》
一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!>,!<,=>,= ...
- Mysql 常用查询语句
SELECT * FROM table1 ,,,,,,,,) ) SELECT * FROM table3 WHERE t3Date >= '2011-08-10' SELECT * FROM ...
- MySQL常用查询语句积累
>>MySQL某列插入递增值 SET @i := 100; UPDATE auge_item_classification SET c_code=(@i:=(@i+1)); >> ...
随机推荐
- mysql数据库的一些基本操作
下面列出一些做项目时常用到的一些mysql操作. 1.对数据库的操作 查看所有的数据库:show databases; 新建一个数据库:create database database_name; 此 ...
- Google Font字体本地化使用提高网站访问速度
Google Web font在国内经常不稳定,速度在国内延迟也很高,而引发网页打开速度慢. 一.常见的字体格式介绍 不同的浏览器对字体格式支持是不一致的,常见的如下: 1.TureTpe(.ttf) ...
- WinForms中的Label的AutoSize属性
当大量使用UserControl组合UI时,如果更改了Label的Text属性,Label.AutoSize属性会影响UserControl的OnLoad事件的发生顺序; public overrid ...
- SpringMVC 自动封装枚举类的方法
springmvc默认无法自动封装枚举类,解决方法如下: 1.枚举类 public enum GoodsPromoteEnum { /** * 0 精品 */ fine("精品", ...
- ionic tabs置顶
找了好久怎么解决这问题,终于找到了一哥们留下来的经验,万分感谢,特此拷贝过来,留着下次以免忘记 我在主页ion-nav-bar元素上添加hide-nav-bar=“true”;然后又在ion-view ...
- 最长公共子序列LCS问题
很经典的一个问题,也是常考的问题
- ios https适配(单向验证)
版权声明:本文为博主原创文章,未经博主允许不得转载. https是http+tls.是在http和tcp之间添加了一层ssl加密验证,ssl将http发送的信息在将要发到传输层时进行了加密,同样数据从 ...
- 一个简单的 MVVM 实现
简介 一个简单的带有双向绑定的 MVVM 实现. 例子 使用 新建一个 ViewModel 对象, 参数分别为 DOM 元素以及绑定的数据即可. 指令 本 MVVM 的指令使用 data 数据, 即 ...
- TCP、UDP、IP 协议分析
http://rabbit.xttc.edu.cn/rabbit/htm/artical/201091145609.shtml http://bhsc881114.github.io/2015/06 ...
- cx_Oracle 中文乱码问题解决
设置NLS_LANG环境变量 import os os.environ['NLS_LANG'] = 'SIMPLIFIED CHINESE_CHINA.UTF8'