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. source 源码下载

    http://blog.csdn.net/zlgydx/article/details/50781258 经常需要查看某些第三方的源码,一直在用的一个网站,功能比较简介.好用. http://grep ...

  2. 数据结构与算法(1)支线任务4——Lowest Common Ancestor of a Binary Tree

    题目如下:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ Given a binary tree, fin ...

  3. RealTimePerformanceDemoView

    using System;using System.Diagnostics;using System.Timers;using System.Windows;using System.Windows. ...

  4. C语音常用库和函数

    #include <assert.h> //设定插入点 #include <ctype.h> //字符处理 #include <errno.h> //定义错误码 # ...

  5. python 2day

    一 优化 username='alex' password=‘alex123’ 可以写成 username,password =‘alex’,'alex123' 二.再次优化 for i in ran ...

  6. ADC测试matlab代码

    前面有做过ADC性能测试,测试方式是先使用ADC采集一个单频信号,然后利用matlab进行性能分析. 下面把matlab分析的代码记录下来: %The following program code p ...

  7. C/C++二维数组分配内存

    //C++方式 double **Q=new double*[row];    //初始化Q矩阵 for(int i=0;i<row;++i) Q[i]=new double[POS_NUM]( ...

  8. 使用微软CORS包不能跨域访问的问题

    使用jquery的ajax异步调用的时候会出现不能跨域访问的问题,这个问题一般有两种方法. 1:使用jsonp跨域 2:使用html5的CORS 在这里只谈论第二种,微软对CORS提供的了支持,在Nu ...

  9. Samba日志分析

    Samba日志分析 随着我们文件共享安全级别的提高,越来越多的情况下需要对日志进行记录并审计.Linux平台下的Samba服务的配置文件是smb.conf,有不少图形化配置工具例如Webmin.smb ...

  10. Java集合框架(常用类) JCF

    Java集合框架(常用类) JCF 为了实现某一目的或功能而预先设计好一系列封装好的具有继承关系或实现关系类的接口: 集合的由来: 特点:元素类型可以不同,集合长度可变,空间不固定: 管理集合类和接口 ...