<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>蓝色数据 &#187; mysql</title>
	<atom:link href="http://bluedata.org/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://bluedata.org</link>
	<description>奋斗是幸福的……</description>
	<lastBuildDate>Mon, 14 Sep 2009 01:53:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL 复制集群动态添加 slave</title>
		<link>http://bluedata.org/2009/08/13/mysql-replication-cluster-add-slave/</link>
		<comments>http://bluedata.org/2009/08/13/mysql-replication-cluster-add-slave/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 01:37:01 +0000</pubDate>
		<dc:creator>Bluedata</dc:creator>
				<category><![CDATA[存储备份]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[快照]]></category>
		<category><![CDATA[集群]]></category>

		<guid isPermaLink="false">http://bluedata.org/?p=241</guid>
		<description><![CDATA[MySQL 数据文件需要存放在 LVM 逻辑卷上才能进行如下操作。
创建快照：
master 作为源：
## 对 master 进行读锁定
mysql> flush tables with read lock;
## 在新终端中（退出锁会失效）创建 MySQL 数据 逻辑卷 的快照
modprobe dm-snapshot
lvcreate -l 486 -s -n mysql_snap /dev/vg/mysql
## 记录当前 binlog 名称及 POS
mysql> show master status;
+------------------+-----------+
&#124; File             &#124; Position  &#124;
+------------------+-----------+
&#124; mysql-bin.000018 &#124; 235667001 &#124;
+------------------+-----------+
## 解锁
mysql> unlock [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL 数据文件需要存放在 LVM 逻辑卷上才能进行如下操作。</p>
<p>创建快照：<br />
master 作为源：<br />
<coolcode linenum="off">## 对 master 进行读锁定<br />
mysql> flush tables with read lock;</p>
<p>## 在新终端中（退出锁会失效）创建 MySQL 数据 逻辑卷 的快照<br />
modprobe dm-snapshot<br />
lvcreate -l 486 -s -n mysql_snap /dev/vg/mysql</p>
<p>## 记录当前 binlog 名称及 POS<br />
mysql> show master status;<br />
+------------------+-----------+<br />
| File             | Position  |<br />
+------------------+-----------+<br />
| mysql-bin.000018 | 235667001 |<br />
+------------------+-----------+</p>
<p>## 解锁<br />
mysql> unlock tables;</coolcode></p>
<p>slave 作为源：</p>
<p><coolcode linenum="off">## 停止 slave 复制进程<br />
mysql -e 'slave stop'</p>
<p>## 创建 MySQL 数据 逻辑卷 的快照<br />
modprobe dm-snapshot<br />
lvcreate -l 486 -s -n mysql_snap /dev/vg/mysql</p>
<p>## 记录当前 master binlog 名称及 POS<br />
mysql -e 'show slave status\G'<br />
Master_Log_File: mysql-bin.000018<br />
Read_Master_Log_Pos: 235667001</p>
<p>## 启动 slave 复制进程<br />
mysql -e 'slave start'</coolcode></p>
<p>## 同步数据库文件<br />
mount /dev/vg/mysql_snap /mnt<br />
rsync -ae ssh --delete --exclude "mysql-bin.*" /mnt/ mysql2:/mysql/ &#038;</p>
<p>## 在源上删除快照<br />
umount /mnt<br />
lvremove -f /dev/vg/mysql_snap<br />
rmmod dm-snapshot</p>
<p>## 在新的 slave 上启动数据库及复制进程<br />
<coolcode linenum="off">/etc/init.d/mysqld start<br />
mysql -e 'slave stop'<br />
mysql -e 'change master to master_host="192.168.0.201", master_user="slave", master_password="slave", master_log_file="mysql-bin.000018", master_log_pos=235667001'<br />
mysql -e 'slave start'</coolcode></p>
]]></content:encoded>
			<wfw:commentRss>http://bluedata.org/2009/08/13/mysql-replication-cluster-add-slave/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用 MySQL-Proxy 实现 MySQL 主从模式下的读写分离</title>
		<link>http://bluedata.org/2008/07/13/mysql-proxy-rw-splitting/</link>
		<comments>http://bluedata.org/2008/07/13/mysql-proxy-rw-splitting/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 14:48:51 +0000</pubDate>
		<dc:creator>Bluedata</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[daemontools]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql-proxy]]></category>
		<category><![CDATA[supervise]]></category>
		<category><![CDATA[读写分离]]></category>

		<guid isPermaLink="false">http://blog.bluedata.org/?p=41</guid>
		<description><![CDATA[准备所需的软件：
读写分离脚本是由 lua 语言编写的，需要安装 lua
http://www.lua.org/
下载适合的 MySQL-Proxy 版本
http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/
安装依赖的库：
yum -y install readline-devel
Installing for dependencies: libtermcap-devel
安装 lua:
tar zxvf lua-5.1.3.tar.gz
cd lua-5.1.3
make linux
make install
安装 MySQL-Proxy:
tar zxvf mysql-proxy-0.6.1-linux-rhel4-x86-32bit.tar.gz
cd mysql-proxy-0.6.1-linux-rhel4-x86-32bit
mv sbin/mysql-proxy /usr/local/sbin/
mv share/mysql-proxy /usr/local/share/
strip /usr/local/sbin/mysql-proxy
创建一个启动脚本，方便管理：
vi /etc/init.d/mysql-proxy

#!/bin/sh
export LUA_PATH=/usr/local/share/mysql-proxy/?.lua
case "$1" in
    start)
        /usr/local/sbin/mysql-proxy --daemon \
        --proxy-address=:3306 \
  [...]]]></description>
			<content:encoded><![CDATA[<p>准备所需的软件：<br />
读写分离脚本是由 lua 语言编写的，需要安装 lua<br />
http://www.lua.org/<br />
下载适合的 MySQL-Proxy 版本<br />
http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/</p>
<p>安装依赖的库：<br />
yum -y install readline-devel<br />
Installing for dependencies: libtermcap-devel</p>
<p>安装 lua:<br />
tar zxvf lua-5.1.3.tar.gz<br />
cd lua-5.1.3<br />
make linux<br />
make install</p>
<p>安装 MySQL-Proxy:<br />
tar zxvf mysql-proxy-0.6.1-linux-rhel4-x86-32bit.tar.gz<br />
cd mysql-proxy-0.6.1-linux-rhel4-x86-32bit<br />
mv sbin/mysql-proxy /usr/local/sbin/<br />
mv share/mysql-proxy /usr/local/share/<br />
strip /usr/local/sbin/mysql-proxy</p>
<p>创建一个启动脚本，方便管理：<br />
vi /etc/init.d/mysql-proxy<br />
<coolcode lang="cpp" linenum="off"><br />
#!/bin/sh<br />
export LUA_PATH=/usr/local/share/mysql-proxy/?.lua</p>
<p>case "$1" in<br />
    start)<br />
        /usr/local/sbin/mysql-proxy --daemon \<br />
        --proxy-address=:3306 \<br />
        --proxy-backend-addresses=192.168.0.9:3306 \<br />
        --proxy-read-only-backend-addresses=192.168.0.10:3307 \<br />
        --proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua<br />
        ;;<br />
    stop)<br />
        killall mysql-proxy<br />
        ;;<br />
    *)<br />
        echo "Usage: mysql-proxy {start|stop}"<br />
        exit 1<br />
esac<br />
</coolcode></p>
<p>chmod +x /etc/init.d/mysql-proxy</p>
<p>参数解释：<br />
--proxy-address=:3306  代理监听在本机所有 IP 的 3306 端口。<br />
--proxy-backend-addresses=192.168.0.9:3306  写入操作连接 master - 192.168.0.9 的 3306 端口。<br />
--proxy-read-only-backend-addresses=192.168.0.10:3307  读取操作连接 slave - 192.168.0.10 的 3307 端口。<br />
--proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua  使用的读写分离脚本。</p>
<p>因为 MySQL-Proxy 还是 Alpha 版的，实际使用中并不稳定，运行一段时间后 mysql-proxy 的进程就会死掉。<br />
所以，用 daemontools 来管理 mysql-proxy 进程比较保险。</p>
<p>在 Redhat 9 和 CentOS 3.x 上用源码编译安装 daemontools 是可以的，但在 CentOS 4.x 上就不行了。<br />
可以下载 RPM 包安装：<br />
http://www.qmail.org/rpms/daemontools.html<br />
http://untroubled.org/supervise-scripts/</p>
<p>wget http://www.qmail.org/rpms/RPMS/daemontools-0.76-112memphis.i386.rpm<br />
wget http://untroubled.org/supervise-scripts/supervise-scripts-3.5-1.noarch.rpm</p>
<p>rpm -Uvh daemontools-0.76-112memphis.i386.rpm supervise-scripts-3.5-1.noarch.rpm</p>
<p>注意：<br />
Daniel J. Bernstein 的软件包不是依照 FHS(Filesystem Hierarchy Standard) 标准创建的。<br />
rpm -ql daemontools 可以看到那“怪异”的文件分布状况。</p>
<p>安装 supervise-scripts 包会在 /etc/inittab 的 si::sysinit:/etc/rc.d/rc.sysinit 行下添加如下两行：<br />
SV:2345:respawn:/usr/bin/svscan-start /service<br />
SX:S016:wait:/usr/bin/svscan-stopall /service</p>
<p>重新检查 /etc/inittab 文件：<br />
telinit q</p>
<p>应该可以看到 svscan 进程了：<br />
ps -ef | grep svscan<br />
root      2269     1  0 21:25 ?        00:00:00 svscan /service</p>
<p>创建 mysql-proxy 运行脚本：<br />
mkdir /service/mysql-proxy<br />
vi /service/mysql-proxy/run<br />
<coolcode lang="cpp" linenum="off"><br />
#!/bin/sh<br />
export LUA_PATH=/usr/local/share/mysql-proxy/?.lua<br />
/usr/local/sbin/mysql-proxy \<br />
--proxy-address=:3306 \<br />
--proxy-backend-addresses=192.168.0.9:3306 \<br />
--proxy-read-only-backend-addresses=192.168.0.10:3307 \<br />
--proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua<br />
</coolcode></p>
<p>chmod 755 /service/mysql-proxy/run</p>
<p>马上就可以看到 mysql-proxy 进程被启动了，并且是由 supervise 管理的：<br />
<coolcode linenum="off"><br />
ps -ef | grep mysql-proxy<br />
root      2309  2269  0 21:27 ?        00:00:00 supervise mysql-proxy<br />
root     29442 29441 32 21:27 ?        00:00:00 /usr/local/sbin/mysql-proxy --proxy-address=:3306 --proxy-backend-addresses=192.168.0.9:3306 --proxy-read-only-backend-addresses=192.168.0.10:3307 --proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua<br />
</coolcode></p>
<p>杀死 mysql-proxy 进程再查看：<br />
<coolcode linenum="off"><br />
killall mysql-proxy<br />
ps -ef | grep mysql-proxy<br />
root      2309  2269  0 21:27 ?        00:00:00 supervise mysql-proxy<br />
root     29640 29639 36 21:31 ?        00:00:01 /usr/local/sbin/mysql-proxy --proxy-address=:3306 --proxy-backend-addresses=192.168.0.9:3306 --proxy-read-only-backend-addresses=192.168.0.10:3307 --proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua<br />
</coolcode></p>
<p>可以看到，mysql-proxy 进程依然还在，不过 PID 已经变了。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedata.org/2008/07/13/mysql-proxy-rw-splitting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iconv 解决 MySQL 乱码问题</title>
		<link>http://bluedata.org/2006/07/27/iconv-mysql-charset/</link>
		<comments>http://bluedata.org/2006/07/27/iconv-mysql-charset/#comments</comments>
		<pubDate>Thu, 27 Jul 2006 09:03:13 +0000</pubDate>
		<dc:creator>Bluedata</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://blog.bluedata.org/iconv/</guid>
		<description><![CDATA[从 Windows 下的 MySQL 导出的 sql 文件再导入到 Linux 下的 MySQL ，所有字段的中文内容都变成了乱码。
 
$ file -i sql1.sql
sql1.sql: text/plain; charset=utf-8
 
发现 sql 文件的编码是 utf-8 ，这与 Linux 下 MySQL 数据库默认的 gbk 编码不相符。
 
$ iconv -f utf-8 -t gbk -o sql2.sql sql1.sql
生成编码为 gbk 的 sql 文件再导入就可以了。
 
不过，发现个问题：
$ file -i sql2.sql
sql2.sql: text/plain; charset=unknown
 
看来，file 不支持 gbk 编码。
]]></description>
			<content:encoded><![CDATA[<p>从 Windows 下的 MySQL 导出的 sql 文件再导入到 Linux 下的 MySQL ，所有字段的中文内容都变成了乱码。<br />
 <br />
$ file -i sql1.sql<br />
sql1.sql: text/plain; charset=utf-8<br />
 <br />
发现 sql 文件的编码是 utf-8 ，这与 Linux 下 MySQL 数据库默认的 gbk 编码不相符。<br />
 <br />
$ iconv -f utf-8 -t gbk -o sql2.sql sql1.sql<br />
生成编码为 gbk 的 sql 文件再导入就可以了。<br />
 <br />
不过，发现个问题：<br />
$ file -i sql2.sql<br />
sql2.sql: text/plain; charset=unknown<br />
 <br />
看来，file 不支持 gbk 编码。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedata.org/2006/07/27/iconv-mysql-charset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mtop 实时监控 MySQL</title>
		<link>http://bluedata.org/2006/07/17/mtop-monitoring-mysql/</link>
		<comments>http://bluedata.org/2006/07/17/mtop-monitoring-mysql/#comments</comments>
		<pubDate>Mon, 17 Jul 2006 03:30:52 +0000</pubDate>
		<dc:creator>Bluedata</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mtop]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[实时监控]]></category>

		<guid isPermaLink="false">http://blog.bluedata.org/mtop/</guid>
		<description><![CDATA[Requires the following perl modules:
 
    Module             Available At
    ------------     --------------------------------------------------------
    Curses              http://cpan.linuxforum.net/authors/id/G/GI/GIRAFFED
    DBI                  Distributed as Bundle::DBI: http://www.cpan.org/authors/id/TIMB
    DBD::mysql        http://www.cpan.org/modules/by-module/DBD
    Getopt::Long     (Distributed with Perl 5)
    Net::Domain      Part of libnet: http://www.cpan.org/authors/id/GBARR
# perl -e 'use Curses'
# perl -e 'use DBI'
# perl -e 'use DBD::mysql'
# perl -e 'use Getopt::Long'
# perl -e 'use Net::Domain'
 
没有输出就是模块已经安装了，有错误就是相应的模块没有安装。
可以在上面给出的地址下载相应模块的最新版本。
安装所需的 Perl 模块：
# tar zxvf Curses-x.xx.tar.gz
# cd [...]]]></description>
			<content:encoded><![CDATA[<p>Requires the following perl modules:<br />
 <br />
    Module             Available At<br />
    ------------     --------------------------------------------------------<br />
    Curses              <a target="_blank" href="http://cpan.linuxforum.net/authors/id/G/GI/GIRAFFED">http://cpan.linuxforum.net/authors/id/G/GI/GIRAFFED</a><br />
    DBI                  Distributed as Bundle::DBI: <a target="_blank" href="http://www.cpan.org/authors/id/TIMB">http://www.cpan.org/authors/id/TIMB</a><br />
    DBD::mysql        <a target="_blank" href="http://www.cpan.org/modules/by-module/DBD">http://www.cpan.org/modules/by-module/DBD</a><br />
    Getopt::Long     (Distributed with Perl 5)<br />
    Net::Domain      Part of libnet: <a target="_blank" href="http://www.cpan.org/authors/id/GBARR">http://www.cpan.org/authors/id/GBARR</a></p>
<p># perl -e 'use Curses'<br />
# perl -e 'use DBI'<br />
# perl -e 'use DBD::mysql'<br />
# perl -e 'use Getopt::Long'<br />
# perl -e 'use Net::Domain'<br />
 <br />
没有输出就是模块已经安装了，有错误就是相应的模块没有安装。<br />
可以在上面给出的地址下载相应模块的最新版本。</p>
<p>安装所需的 Perl 模块：<br />
# tar zxvf Curses-x.xx.tar.gz<br />
# cd Curses*<br />
# perl Makefile.PL<br />
# make<br />
# make install<br />
 <br />
yum 仓库里有 perl-DBI ，所以直接 yum 安装，<br />
# yum -y install perl-DBI<br />
 <br />
因为是编译安装的 MySQL ，所以需要把 lib 的路径加入 ld.so.conf ，<br />
# vi /etc/ld.so.conf<br />
/usr/local/mysql/lib/mysql<br />
# ldconfig<br />
 <br />
虽然 yum 仓库里有 perl-DBD-MySQL ，但其依赖 mysql ，所以还是编译安装，<br />
# tar zxvf DBD-mysql-x.xxxx.tar.gz<br />
# cd DBD-mysql*<br />
# perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config<br />
# make<br />
# make install<br />
 <br />
安装 mtop ：<br />
# tar zxvf mtop-0.6.6.tar.gz<br />
# cd mtop-0.6.6<br />
# perl Makefile.PL<br />
# make<br />
# make install<br />
 <br />
添加相应的 MySQL 数据库用户：<br />
# mysql -uroot -pPASSWORD<br />
mysql&gt; GRANT RELOAD,PROCESS,SUPER ON *.* TO 'mtop'@'localhost' IDENTIFIED BY 'mtop';<br />
mysql&gt; FLUSH PRIVILEGES;<br />
mysql&gt; exit<br />
 <br />
运行：<br />
因为自定义了 mysql.sock 的位置，所以需要做个链接 mtop 才能运行，<br />
# ln -s /var/run/mysqld/mysql.sock /tmp/mysql.sock<br />
 <br />
# mtop --dbuser=mtop --password=mtop<br />
 <br />
参考资料：<a target="_blank" href="http://mtop.sourceforge.net/">http://mtop.sourceforge.net/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bluedata.org/2006/07/17/mtop-monitoring-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ProFTPD &amp; MySQL 4.0 的超时中断连接问题</title>
		<link>http://bluedata.org/2006/05/18/proftpd-mysql-timeout/</link>
		<comments>http://bluedata.org/2006/05/18/proftpd-mysql-timeout/#comments</comments>
		<pubDate>Thu, 18 May 2006 14:57:28 +0000</pubDate>
		<dc:creator>Bluedata</dc:creator>
				<category><![CDATA[应用技术]]></category>
		<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[proftpd]]></category>
		<category><![CDATA[timeoutidle]]></category>

		<guid isPermaLink="false">http://blog.bluedata.org/proftpd-mysql-timeout/</guid>
		<description><![CDATA[MySQL 的 interactive timeout 缺省设置为 28800 秒，这个值实在太大了，根据程序与数据库交互的状况把这个值改小了，结果使用 MySQL 4.0 的 ProFTPD 频繁断线。
SHOW PROCESSLIST;
发现操作 ProFTPD 数据库进程的运行时间在不停增加，直到达到 interactive timeout 参数定义的时间后才断开，这时，客户端与 ProFTPD 的连接也就断开了。
 
其它使用 MySQL 4.1 的 ProFTPD 没有这样的问题，看不到操作 ProFTPD 数据库的进程。（ProFTPD 的版本都是相同的）
 
也就是说，ProFTPD 使用 MySQL 4.0 验证用户时是建立的“持久”连接，只要客户端有操作就会去查询数据库，对客户端身份进行验证；而在使用 MySQL 4.1 时，只是在登陆时查询数据库验证身份，成功登陆后便由 ProFTPD 自己维护这个 session ，不再查询数据库了。
 
修改 MySQL 4.0 的  interactive timeout ，改为和 ProFTPD 设定的 TimeoutIdle 时间同一值后解决问题。
]]></description>
			<content:encoded><![CDATA[<p>MySQL 的 interactive timeout 缺省设置为 28800 秒，这个值实在太大了，根据程序与数据库交互的状况把这个值改小了，结果使用 MySQL 4.0 的 ProFTPD 频繁断线。<br />
SHOW PROCESSLIST;<br />
发现操作 ProFTPD 数据库进程的运行时间在不停增加，直到达到 interactive timeout 参数定义的时间后才断开，这时，客户端与 ProFTPD 的连接也就断开了。<br />
 <br />
其它使用 MySQL 4.1 的 ProFTPD 没有这样的问题，看不到操作 ProFTPD 数据库的进程。（ProFTPD 的版本都是相同的）<br />
 <br />
也就是说，ProFTPD 使用 MySQL 4.0 验证用户时是建立的“持久”连接，只要客户端有操作就会去查询数据库，对客户端身份进行验证；而在使用 MySQL 4.1 时，只是在登陆时查询数据库验证身份，成功登陆后便由 ProFTPD 自己维护这个 session ，不再查询数据库了。<br />
 <br />
修改 MySQL 4.0 的  interactive timeout ，改为和 ProFTPD 设定的 TimeoutIdle 时间同一值后解决问题。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluedata.org/2006/05/18/proftpd-mysql-timeout/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
