Penner Blog

Sarah & Penner’s happy life ;)

Archive for the ‘MySQL’ Category

MySQL Proxy 编译安装 By CentOS

星期一
6 9,2008

MySQL Proxy Download: http://dev.mysql.com/downloads/mysql-proxy/
MySQL Proxy Wiki: http://forge.mysql.com/wiki/MySQL_Proxy

1、lua 安装
Get lua from: http://www.lua.org/

  1. vi Makefile (将 "INSTALL_TOP= /usr/local" 变为 "INSTALL_TOP= /yourpath/lua")
  2. make ansi
  3. make install

2、GLib 安装
Get GLib from: http://www.gtk.org/

  1. ./configure --prefix=/yourpath/glib2
  2. make
  3. make install

Note: newer version need newer pkg-conifg 0.xx
Get pkg-config from: http://pkg-config.freedesktop.org/releases/

  1. ./configure
  2. make
  3. make install

3、libevent 安装
Get libevent from: http://monkey.org/~provos/libevent/

  1. ./configure --prefix=/yourpath/libevent
  2. make;make install

4、check 安装
Get check lib from: http://check.sourceforge.net/

  1. ./configure --prefix=/yourpath/check
  2. make
  3. make install

5、MySQL Proxy 安装
编译前先要设置一下环境变量(export),类似于 Windows 下的 PATH

  1. export LUA_CFLAGS="-I/yourpath/lua/include" LUA_LIBS="-L/yourpath/lua/lib -llua -ldl" LDFLAGS="-lm"
  2.  
  3. export GLIB_CFLAGS="-I/yourpath/glib2/include/glib-2.0 -I/yourpath/glib2/lib/glib-2.0/include"
  4. export GLIB_LIBS="-L/yourpath/glib2/lib -lglib-2.0"
  5.  
  6. export CPPFLAGS="$CPPFLAGS -I/yourpath/libevent/include"
  7. export CFLAGS="$CFLAGS -I/yourpath/libevent/include"
  8. export LDFLAGS="$LDFLAGS -L/yourpath/libevent/lib -lm"
  9.  
  10. ./configure --prefix=/yourpath/mysql-proxy --with-mysql=/yourpath/mysql --with-check=/yourpath/check
  11. make
  12. make install

测试是否安装成功,看下边这条语句是否可以正常输出 MySQL Proxy 的帮助

  1. /yourpath/mysql-proxy/sbin/mysql-proxy --help-all

Linux 64位, MySQL, Swap & Memory 优化

星期日
5 25,2008

MySQL的性能优化文章有很多,这里介绍个通过优化Swap & Memory来提高性能的方法。

The VM for Linux prefers system cache over application memory. What does this mean? The best way I can explain is by example.

Imagine you have 32 GB of RAM
MySQL is set to take 20 GB of RAM for a process based buffer and up to 6M for the various thread buffers.

Over a period of time the box swaps. The only thing that is running is mysql and its memory size is around 21GB for resident memory. Why does swap grow when there is plenty of memory? The reason is when a memory alloc is needed (thread based buffer is tickled) the VM will choose to use swap over allocating from the system cache, when there is not enough free memory.

DO NOT TURN OFF SWAP to prevent this. Your box will crawl, kswapd will chew up a lot of the processor, Linux needs swap enabled, lets just hope its not used.

So how do you stop Nagios pages because of swap usage? Well if you have a few choices.

reboot the box

or

stop mysql && swapoff -a;swapon -a;

or just

swapoff -a;swapon -a;
(注意!如果你在MySQL正在使用Swap时执行,会把MySQL搞死,所以执行前一定要反复确认Swap没有被使用。)

Doing the latter command is rather scary and fun at the same time. Because you can either crash mysql or not. I just did the swap* commands live, I was very certain nothing was using swap and it worked. YAY no more pages and I didn’t have to shut down the service!

参考文章:
http://mysqldba.blogspot.com/2008/05/linux-64-bit-mysql-swap-and-memory.html

星期日
6 11,2006

不区分英文大小写,汉字按拼音顺序排列的字段
数据库中的字段整理(collation)类型设为 gbk_chinese_ci

区分英文大小写,汉字按拼音顺序排列的字段
数据库中的字段整理(collation)类型设为 gbk_bin

今天卸载Mysql时碰到的问题

星期六
1 22,2005

最近一次配置php环境,偶然在网上看到mysql的版本已经更新到了4.1.9,谁知安装过后发现从库中读取中文字段全都是”?”,在网上找了n种解决方法尝试无果后,心想还是老老实实的用旧版吧,结果版本更换当中时又出问题,mysql程序驻留在了windows services中,每次都卸不干净。

经过几次的安装和上网查询资料终于解决了,步骤如下:

1.卸载Mysql.
2.删除系统盘下的my.ini文件
3.删除注册表中\HEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Mysql
4.重新安装Mysql(安装后注意my.ini中的base和data路径要与安装的一致,否则仍然不能启动)

如碰到apache启动时显示php_mysql.dll 找不到指定的模块,那就将php5目录中的libmysql.dll复制到C:\windows\system32下,重启apache后一般即可恢复正常。