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 常用查询的更多相关文章

  1. 23个MySQL常用查询语句

    23个MySQL常用查询语句 一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!> ...

  2. mysql常用查询归纳

    一.mysql查询的五种子句 where(条件查询).having(筛选).group by(分组).order by(排序).limit(限制结果数) .where常用运算符: 比较运算符 > ...

  3. mysql—常用查询语句总结

    关于MySQL常用的查询语句 一查询数值型数据: ; 查询谓词:>,=,<,<>,!=,!>,!<,=>,=< 二查询字符串 SELECT * FROM ...

  4. MySQL常用查询语句汇总(不定时更新)

    在这篇文章中我会通过一些例子来介绍日常编程中常用的SQL语句   目录: ## 1.数据库的建立     ## 1.数据库的建立   实例将ER图的形式给出:   由此转换的4个关系模式:      ...

  5. mysql常用查询命令

    转引自:https://www.cnblogs.com/widows/p/7137184.html 常用mysql命令 show variables like 'character_set_clien ...

  6. [转]MySQL常用查询

    单表查询 ①查询所有     * mysql> select * from student; ②查询选中字段记录 mysql> select s_name from student; ③条 ...

  7. MySQL常用查询语句集合《转》

    一查询数值型数据: SELECT * FROM tb_name WHERE sum > 100; 查询谓词:>,=,<,<>,!=,!>,!<,=>,= ...

  8. Mysql 常用查询语句

    SELECT * FROM table1 ,,,,,,,,) ) SELECT * FROM table3 WHERE t3Date >= '2011-08-10' SELECT * FROM ...

  9. MySQL常用查询语句积累

    >>MySQL某列插入递增值 SET @i := 100; UPDATE auge_item_classification SET c_code=(@i:=(@i+1)); >> ...

随机推荐

  1. [REP]AWS Regions and Availability Zones: the simplest explanation you will ever find around

    When it comes to Amazon Web Services, there are two concepts that are extremely important and spanni ...

  2. 网页WEB打印控件制作-开放源码

    在WEB系统中,打印的确是比较烦人的问题,如果我们能制作一个属于自己的自定义的打印插件,那么我们在后续自定义打印的时候能随心所欲的控制打印,这样的效果对于程序员来说是非常开心的一件事件,本文将自己开发 ...

  3. QTP处理各类鼠标事件fireEvent

    在做web测试时,页面上的HTML标签会包含各类事件:单击(onclick).双击(onDblClick).光标聚集(OnBlur).onchange.onfocus.onmousedown.onmo ...

  4. pthon在Notepad++中执行方式

    使用 Notepad++ 编辑运行 Python 程序         Notepad++是一个开源的文本编辑器,功能强大而且使用方便.编辑和调试 Python 程序使用什么编辑器或者 IDE不同人有 ...

  5. ffmpeg relocation error

    在向imx6移植ffmpeg后,一般的编解码操作没有问题,但是当从摄像头录视频时, ffmpeg -f video4linux2 -s 640*480 -r 10 -i /dev/video0 tes ...

  6. mongoDB学习笔记:了解与安装

    初次使用mongoDB是在2013年,项目组为了新产品的研发,使用了mongoDB,作为项目组的一名测试员,也就跟着学起来了. 1.了解mongoDB Mongo DB ,是目前在IT行业非常流行的一 ...

  7. 一些bug总结

    1:IE浏览器低版本的parseInt问题; 开发中遇到把月份转为小数时出现bug 例子:parseInt('08')-1; 本来应该得7,但是最后的结果却是-1,月份得-1,根据得到的月份获取的日历 ...

  8. 在线c++编译器(gcc)

    这几年c++标准委员会活跃起来,C++11.14标准相续推出.对于想尝鲜又怕麻烦(visual studio 更新慢,对标准的支持力度也不够.对于使用gcc的,替换系统的gcc版本或者安装个mingw ...

  9. 【转】ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台

    [转自]https://my.oschina.net/itblog/blog/547250 摘要: 前段时间研究的Log4j+Kafka中,有人建议把Kafka收集到的日志存放于ES(ElasticS ...

  10. php开发环境

    php一般使用xampp(apache+mysql+php+perl)部署,下载地址https://www.apachefriends.org/zh_cn/index.html.本文不用集成包,搭建P ...