02 2014 档案

Mysql History list length 值太大引起的问题
摘要:1.环境Mysql主从Mysql版本:5.1.49-log系统:RedHatEnterpriseLinuxServerrelease5.464bit2.表面现象数据库操作变慢,如用主键作为条件查询,有时也会超过1秒;主库IO使用率一直在90%以上(平常io比较低20%以内),dirty页占总数的90%左右,脏页刷不完;持续了几个小时~3.从系统上看主库的iostat的使用率一直在90%以上,Mysqldata所在目录的大小一直没变;主库的ib_logfile20分钟切换一次(主库上面的innodblog写得还是比较频繁),而从库的ib_logfile4小时切换一次。4.从mysql上看在主库B 阅读全文

posted @ 2014-02-28 01:07 Still water run deep 阅读(2190) 评论(0) 推荐(0)

Why is the ibdata1 file continuously growing in MySQL?
摘要:We receive this question about the ibdata1 file in MySQL very often inPercona Support.The panic starts when the monitoring server sends an alert about the storage of the MySQL server – saying that the disk is about to get filled.After some research you realize that most of the disk space is used by 阅读全文

posted @ 2014-02-28 00:42 Still water run deep 阅读(426) 评论(0) 推荐(0)

How to reclaim space in InnoDB when innodb_file_per_table is ON
摘要:Wheninnodb_file_per_tableisOFFand all data is going to be stored inibdatafiles. If you drop some tables of delete some data then there is no any other way to reclaim that unused disk space exceptdump/reloadmethod.WhenInnodb_file_per_tableisON, each table stores data and indexes in it’s owntablespace 阅读全文

posted @ 2014-02-27 23:55 Still water run deep 阅读(407) 评论(0) 推荐(0)

Bash script: report largest InnoDB files
摘要:The following script will report the largest InnoDB tables under the data directory: schema, table & length in bytes. The tables could be non-partitioned, in which case this is simply the size of the corresponding.ibdfile, or they can be partitioned, in which case the reported size is the sum of 阅读全文

posted @ 2014-02-27 23:45 Still water run deep 阅读(270) 评论(0) 推荐(0)

Reasons to use innodb_file_per_table
摘要:When working with InnoDB, you have two ways for managing the tablespace storage:Throw everything in one big file (optionally split).Have one file per table.I will discuss the advantages and disadvantages of the two options, and will strive to convince thatinnodb_file_per_tableis preferable.A single 阅读全文

posted @ 2014-02-27 23:41 Still water run deep 阅读(273) 评论(0) 推荐(0)

mysql共享表空间和独立表空间
摘要:innodb这种引擎,与MYISAM引擎的区别很大。特别是它的数据存储格式等.对于innodb的数据结构,首先要解决两个概念性的问题: 共享表空间以及独占表空间。什么是共享表空间和独占表空间共享表空间以及独占表空间都是针对数据的存储方式而言的。共享表空间: 某一个数据库的所有的表数据,索引文件全部放在一个文件中,默认这个共享表空间的文件路径在data目录下。 默认的文件名为:ibdata1 初始化为10M。独占表空间: 每一个表都将会生成以独立的文件方式来进行存储,每一个表都有一个.frm表描述文件,还有一个.ibd文件。 其中这个文件包括了单独一个表的数据内容以及索引内容,默认情况下它的存储 阅读全文

posted @ 2014-02-27 17:29 Still water run deep 阅读(461) 评论(0) 推荐(0)

How do I see what character set a database / table / column is in MySQL?
摘要:Q:How do I see what the character set that a MySQL database, table and column are in? Is there something likeSHOW CHARACTER SETFOR mydatabase;andSHOW CHARACTER SETFOR mydatabase.mytable;andSHOW CHARACTER SETFOR mydatabase.mytable.mycolumn;A:How do I see what the character set that a MySQL database, 阅读全文

posted @ 2014-02-27 00:46 Still water run deep 阅读(175) 评论(0) 推荐(0)

关于session variables 和 global variables
摘要:背景有同学问到这样一个问题:原来的binlog格式是statement,为什么执行了set global binlog_format='row'和set binlog_format='row',在binlog里面还是会看到有生成statement格式的事件?变量分类很多文章都说到MySQL的按照可见性范围分成两类session和global。实际上是三类session_only, both, global_only.如下图见到的关系。session_only是仅线程级别意义的,比如last_insert_idglobal_only是仅全局级别有意义的,比如syn 阅读全文

posted @ 2014-02-26 01:49 Still water run deep 阅读(773) 评论(0) 推荐(0)

MySQL的字符集小结
摘要:正确了解MySQL的字符集问题,能够从根本上解决乱码的困扰。首先,MySQL的字符集问题主要是两个概念,一个是Character Sets,一个是Collations,前者是字符内容及编码,后者是对前者进行比较操作的一些规则。这两个参数集可以在数据库实例、单个数据库、表、列等四个级别指定。对于使用者来说,一般推荐使用utf8编码来存储数据。而要解决乱码问题,不单单是MySQL数据的存储问题,还和用户的程序文件的编码方式、用户程序和MySQL数据库的连接方式都有关系。首先,MySQL有默认的字符集,这个是安装的时候确定的,在编译MySQL的时候可以通过DEFAULT_CHARSET=utf8和D 阅读全文

posted @ 2014-02-26 01:35 Still water run deep 阅读(229) 评论(0) 推荐(0)

修改innodb_flush_log_at_trx_commit参数提升insert性能
摘要:最近,在一个系统的慢查询日志里发现有个insert操作很慢,达到秒级,并且是比较简单的SQL语句,把语句拿出来到mysql中直接执行,速度却很快。这种问题一般不是SQL语句本身的问题,而是在具体的应用环境中,由于并发等原因导致的。最可怀疑的地方就是在等待表级锁。加上监控的日志来看,很多SQL是在同一时间完成的,下面的第三列是结束时间,第四列是开始时间:14:27:30 bizId30905 1355812050 135581204514:27:30 bizId28907 1355812050 135581204314:27:30 bizId30905 1355812050 1355812... 阅读全文

posted @ 2014-02-26 00:47 Still water run deep 阅读(1382) 评论(0) 推荐(0)

通过init-connect + binlog 实现MySQL审计功能
摘要:背景:假设这么一个情况,你是某公司mysql-DBA,某日突然公司数据库中的所有被人为删了。尽管有数据备份,但是因服务停止而造成的损失上千万,现在公司需要查出那个做删除操作的人。但是拥有数据库操作权限的人很多,如何排查,证据又在哪?是不是觉得无能为力?mysql本身并没有操作审计的功能,那是不是意味着遇到这种情况只能自认倒霉呢?本文就将讨论一种简单易行的,用于mysql访问审计的思路。关键字:init—connect,binlog,trigger概述:其实mysql本身已经提供了详细的sql执行记录–general log ,但是开启它有以下几个缺点无论sql有无语法错误,只要执行了就会记录, 阅读全文

posted @ 2014-02-26 00:20 Still water run deep 阅读(423) 评论(0) 推荐(0)

init_connect基本用法
摘要:服务器为每个连接的客户端执行的字符串。字符串由一个或多个SQL语句组成。要想指定多个语句,用分号间隔开。例如,每个客户端开始时默认启用autocommit模式。没有全局服务器变量可以规定autocommit默认情况下应禁用,但可以用init_connect来获得相同的效果:SET GLOBAL init_connect='SET AUTOCOMMIT=0';还可以在命令行或选项文件中设置该变量。要想使用选项文件设置变量,应包括下述行:[mysqld]init_connect='SET AUTOCOMMIT=0'请注意init_connect的内容并不为拥有SUP 阅读全文

posted @ 2014-02-26 00:13 Still water run deep 阅读(1532) 评论(0) 推荐(0)

MySQL备份之mysqlhotcopy与注意事项
摘要:此文章主要向大家介绍的是MySQL备份之mysqlhotcopy与其在实际操作中应注意事项的描述,我们大家都知道实现MySQL数据库备份的常用方法有三个,但是我们今天主要向大家介绍的是其中的一个比较好用的方案,以下就是详细内容介绍。mysqlhotcopy备份mysqlhotcopy是一个Perl脚本,最初由Tim Bunce编写并提供。它使用LOCK TABLES、FLUSH TABLES和cp或scp来快速备份数据库。它是MySQL备份数据库或单个表的最快的途径,但它只能运行在数据库目录所在的机器上。mysqlhotcopy只用于备份MyISAM。它运行在Unix和NetWare中使用方法 阅读全文

posted @ 2014-02-25 23:36 Still water run deep 阅读(487) 评论(0) 推荐(0)

Backup and Restore MySQL Database using mysqlhotcopy
摘要:mysqlhotcopy is a perl script that comes with MySQL installation. This locks the table, flush the table and then performs a copy of the database. You can also use the mysqlhotcopy to automatically copy the backup directly to another server using scp.1. mysqlhotcopy command:[local-host]# /usr/bin/mys 阅读全文

posted @ 2014-02-25 22:53 Still water run deep 阅读(459) 评论(0) 推荐(0)

How to turn off the binary log for mysqld_multi instances?
摘要:Q:MySQL supports running multiplemysqldon the same server. One of the ways is to usemysqld_multi.If the default MySQL server instance (as configured in the[mysqld]section inmy.cnf) useslog-bin, it enables the binary log for all the other instances ([mysqld1],[mysqld2], etc).How can we override the s 阅读全文

posted @ 2014-02-25 22:39 Still water run deep 阅读(328) 评论(0) 推荐(0)

MySQL 数据库性能优化之缓存参数优化
摘要:在平时被问及最多的问题就是关于 MySQL 数据库性能优化方面的问题,所以最近打算写一个MySQL数据库性能优化方面的系列文章,希望对初中级 MySQL DBA 以及其他对 MySQL 性能优化感兴趣的朋友们有所帮助。这是MySQL数据库性能优化专题系列的第一篇文章:MySQL 数据库性能优化之缓存参数优化数据库属于 IO 密集型的应用程序,其主要职责就是数据的管理及存储工作。而我们知道,从内存中读取一个数据库的时间是微秒级别,而从一块普通硬盘上读取一个IO是在毫秒级别,二者相差3个数量级。所以,要优化数据库,首先第一步需要优化的就是 IO,尽可能将磁盘IO转化为内存IO。本文先从 MySQL 阅读全文

posted @ 2014-02-25 22:01 Still water run deep 阅读(403) 评论(0) 推荐(0)

innodb log file与binlog的区别在哪里?
摘要:Q:innodb log file与binlog的区别在哪里?有人说1。mysql的innodb引擎实际上是包装了inno base存储引擎。而innodb log file是由 inno base自身带来。 而mysql自身因为还有myisam等存储引擎,需要设置自己的日志文件来用于所有的存储引擎记录日志信 息,因此增加了binlog。从某种意义上说binlog对于innodb存储引擎来说与innodb log是有些重复的。2。binlog应该是mysql真正的redo日志A:1. binlog是MySQL Server层记录的日志, redo log是InnoDB存储引擎层的日志。... 阅读全文

posted @ 2014-02-25 21:56 Still water run deep 阅读(666) 评论(0) 推荐(0)

mysql explain 中key_len的计算
摘要:今天丁原问我mysql执行计划中的key_len是怎么计算得到的,当时还没有注意,在高性能的那本书讲到过这个值的计算,但是自己看执行计划的时候一直都没有太在意这个值,更不用说深讨这个值的计算了:ken_len表示索引使用的字节数,根据这个值,就可以判断索引使用情况,特别是在组合索引的时候,判断所有的索引字段都被查询用到。在查看官方文档的时候,也没有发现详细的key_len的计算介绍,后来做了一些测试,在咨询了丁奇关于变长数据类型的值计算的时候,突然想到innodb 行的格式,在这里的计算中有点类似,总结一下需要考虑到以下一些情况:(1).索引字段的附加信息:可以分为变长和定长数据类型讨论,当索 阅读全文

posted @ 2014-02-25 21:38 Still water run deep 阅读(251) 评论(0) 推荐(0)

last_query_cost
摘要:The total cost of the last compiled query as computed by the query optimizer. This is useful for comparing the cost of different query plans for the same query. The default value of 0 means that no query has been compiled yet. The default value is 0.Last_query_costhas session scope.TheLast_query_cos 阅读全文

posted @ 2014-02-24 21:52 Still water run deep 阅读(861) 评论(0) 推荐(0)

[MySQL] explain执行计划解读
摘要:Explain语法EXPLAIN SELECT ……变体:1. EXPLAIN EXTENDED SELECT ……将执行计划“反编译”成SELECT语句,运行SHOW WARNINGS 可得到被MySQL优化器优化后的查询语句 2. EXPLAIN PARTITIONS SELECT ……用于分区表的EXPLAIN执行计划包含的信息id包含一组数字,表示查询中执行select子句或操作表的顺序id相同,执行顺序由上至下如果是子查询,id的序号会递增,id值越大优先级越高,越先被执行id如果相同,可以认为是一组,从上往下顺序执行;在所有组中,id值越大,优先级越高,越先执行select_ty. 阅读全文

posted @ 2014-02-21 23:16 Still water run deep 阅读(352) 评论(0) 推荐(0)

innodb_stats_on_metadata and slow queries on INFORMATION_SCHEMA
摘要:INFORMATION_SCHEMA is usually the place to go when you want to get facts about a system (how many tables do we have? what are the 10 largest tables? What is data size and index size for table t?, etc). However it is also quite common that such queries are very slow and create lots of I/O load. Here 阅读全文

posted @ 2014-02-20 00:19 Still water run deep 阅读(669) 评论(0) 推荐(0)

MySQL里执行SHOW INDEX结果中Cardinality的含义
摘要:今天在写一个Perl脚本,想自动化查找出MySQL数据库中可能无效的索引,于是根据朝阳的书上提到的一些规则,我来设计了一些判断方法,其中发现某个我想要的值就是SHOW INDEX FROM table里的Cardinality,于是查了下它的含义以验证我的想法。MySQL中SHOW INDEX FROM table 会有以下结果列| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comme 阅读全文

posted @ 2014-02-19 22:56 Still water run deep 阅读(3181) 评论(0) 推荐(0)

innodb_force_recovery
摘要:WarningBefore using innodb_force_recovery ensure that you have a backup copy of your database in case you need to start over. You should always begin by setting innodb_force_recovery to a lower value. Incrementally increase the setting as required. Only use an innodb_force_recovery setting of 3 or g 阅读全文

posted @ 2014-02-19 22:09 Still water run deep 阅读(659) 评论(0) 推荐(0)

SELECT LOCK IN SHARE MODE and FOR UPDATE
摘要:Baronwrotenice article comparing locking hints in MySQL and SQL Server.In MySQL/Innodb LOCK IN SHARE MODE and SELECT FOR UPDATE are more than hints. Behavior will be different from normal SELECT statements. Here is simple example: 1 SESSION1: 2 mysql> begin; 3 Query OK, 0 rows affected (0.00 sec) 阅读全文

posted @ 2014-02-19 01:25 Still water run deep 阅读(403) 评论(0) 推荐(0)

To pack or not to pack – MyISAM Key compression
摘要:MyISAM storage engine has key compression which makes its indexes much smaller, allowing better fit in caches and so improving performance dramatically. Actually packed indexes not a bit longer rows is frequent reason of MyISAM performing better than Innodb. In this article I’ll get in a bit more de 阅读全文

posted @ 2014-02-19 00:04 Still water run deep 阅读(341) 评论(0) 推荐(0)

open_table与opened_table
摘要:好多人在调优Mysql的时候,总是对open_tables和opend_tables两个参数分别不清。网上好多解释都是这样的:open_tables:当前打开表的数量opened_tables:当前已经打开表的数量很简单的解释,可是这两句话看起来有点类似。下面我来解释一下:open_tables:是当前在缓存中打开表的数量。opened_tables:是mysql自启动起,打开表的数量。我们知道,假如没有缓存的话,那么mysql服务在每次执行一个语句的时候,都会先打开一个表。当sql语句执行完成后,则把这个表关掉。这就是opend_tables中的值。而open_tables这个值,是mysq 阅读全文

posted @ 2014-02-18 22:20 Still water run deep 阅读(917) 评论(0) 推荐(0)

SHOW OPEN TABLES – what is in your table cache
摘要:One command, which few people realize exists isSHOW OPEN TABLES– it allows you to examine what tables do you have open right now:1 mysql> show open tables from test;2 +----------+-------+--------+-------------+3 | Database | Table | In_use | Name_locked |4 +----------+-------+--------+----------- 阅读全文

posted @ 2014-02-18 20:52 Still water run deep 阅读(394) 评论(0) 推荐(0)

导航