2014年2月27日

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 阅读(393) 评论(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 阅读(260) 评论(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 阅读(259) 评论(0) 推荐(0) 编辑

mysql共享表空间和独立表空间

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

posted @ 2014-02-27 17:29 Still water run deep 阅读(440) 评论(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 阅读(169) 评论(0) 推荐(0) 编辑

2014年2月26日

关于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 阅读(756) 评论(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 阅读(220) 评论(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 阅读(1362) 评论(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 阅读(388) 评论(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 阅读(1465) 评论(0) 推荐(0) 编辑

导航