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. ThrottleAttribute

    /// <summary> /// Decorates any MVC route that needs to have client requests limited by time. ...

  2. 【转】apache DateFormatUtils 与 DateUtils 的使用

    在Apache Commons项目的Lang里面,有两个类:DateUtils和DateFormatUtils,专门用于处理时间日期转换.它们在 org.apache.commons.lang.tim ...

  3. 区分LocalStorage和偏好数据

    偏好数据类似于web.config或者session,cookie之类的值,一般用于保存一些状态值,不推荐大量的数据通过此方式存储 Local Storage不仅可以寸字符串,还可以寸JSON对象

  4. oracle ebs应用产品安全性-交叉验证规则

    转自: http://blog.itpub.net/298600/viewspace-625138/ 定义: Oracle键弹性域可以根据自定义键弹性域时所定义的规则,执行段值组合的自动交叉验证.使用 ...

  5. 安装部署完office web apps 后,无法浏览Word

    安装部署完office web apps 后,在sharepoint 2010浏览器中浏览Word提示:“由于出现意外错误,Word Web App 无法打开此 文档 进行查看. 要查看此 文档,请在 ...

  6. android 程序代码执行adb

    Runtime.getRuntime().exec("adb pull /dev/graphics/fb0 C:/fb1"); Runtime. getRuntime().exec ...

  7. css3动画3

    1.transition过渡动画 2.@keyframes关键帧动画,配合transform.animation使用

  8. Chrome Dev Tools :成为更高效的开发人员

    原文出处 http://blog.jobbole.com/22065/ 实时CSS Style编辑 选择一个Dom,可以对Dom进行编辑和操作,实时修改Css Style, 同时CssStyle可以保 ...

  9. 区块 Blocks

    Structure / Blocks / Demonstrate block regions

  10. HTML。CSS浮动元素详解

    浮动定位是指 1.1将元素排除在普通流之外,即元素将脱离标准文档流 1.2元素将不在页面占用空间 1.3将浮动元素放置在包含框的左边或者右边 1.4浮动元素依旧位于包含框之内 2. 浮动的框可以向左或 ...