<?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>Orz DBA</title>
	<atom:link href="http://chenxu.yo2.cn/feed" rel="self" type="application/rss+xml" />
	<link>http://chenxu.yo2.cn</link>
	<description>折腾...</description>
	<lastBuildDate>Fri, 24 Feb 2012 15:06:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>【Linux】lsof查看被打开的文件</title>
		<link>http://chenxu.yo2.cn/articles/lsof.html</link>
		<comments>http://chenxu.yo2.cn/articles/lsof.html#comments</comments>
		<pubDate>Fri, 24 Feb 2012 15:06:02 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[Linux & Unix]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[lsof]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55718</guid>
		<description><![CDATA[今天一同事说文件系统/tmp目录下空间用满了，当时du统计目录所有文件的时候去很小。听到这个现象，第一感觉就是应该有大文件被删除，但是这个文件可能依然被其他程序打开，导致这个文件不能被清除。登上服务器使用lsof看了一下，果然如此，具体排查过程如下： $df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 8.6G 1.5G 6.7G 18% / /dev/sda10 784G 325G 420G 44% /u01 /dev/sda5 8.7G 7.9G 407M 96% /tmp /dev/sda2 15G 2.8G 11G 21% /usr /dev/sda1 122M 12M 104M 10% /boot tmpfs 7.9G 4.0K 7.9G 1% /dev/shm $sudo lsof &#124; grep /tmp &#124; sort -k7 -nr [...]]]></description>
			<content:encoded><![CDATA[<p>今天一同事说文件系统/tmp目录下空间用满了，当时du统计目录所有文件的时候去很小。听到这个现象，第一感觉就是应该有大文件被删除，但是这个文件可能依然被其他程序打开，导致这个文件不能被清除。登上服务器使用<a href="http://www.ibm.com/developerworks/cn/aix/library/au-lsof.html" target="_blank">lsof</a>看了一下，果然如此，具体排查过程如下：</p>
<blockquote>
<p>$df -h<br>
Filesystem Size Used Avail Use% Mounted on<br>
/dev/sda3 8.6G 1.5G 6.7G 18% /<br>
/dev/sda10 784G 325G 420G 44% /u01<br>
<span style="color: #ff0000;">/dev/sda5 8.7G 7.9G 407M 96% /tmp</span><br>
/dev/sda2 15G 2.8G 11G 21% /usr<br>
/dev/sda1 122M 12M 104M 10% /boot<br>
tmpfs 7.9G 4.0K 7.9G 1% /dev/shm</p>
<p>$<strong><span style="color: #000000;">sudo lsof | grep /tmp | sort -k7 -nr</span></strong><br>
<span style="color: #ff0000;">sleep 18833 peien.htg 1w REG 8,5 8321143673 54 /tmp/netstat.log (deleted)<br>
netstat_2 13571 peien.htg 1w REG 8,5 8321143673 54 /tmp/netstat.log (deleted)</span><br>
tcprstat 18823 root 2w REG 8,5 43632 49 /tmp/myrt.daemon.log<br>
sh 18822 mysql 2w REG 8,5 43632 49 /tmp/myrt.daemon.log<br>
sh 18822 mysql 1w REG 8,5 43632 49 /tmp/myrt.daemon.log<br>
myrt.pl 26045 mysql 2w REG 8,5 43632 49 /tmp/myrt.daemon.log<br>
myrt.pl 26045 mysql 1w REG 8,5 43632 49 /tmp/myrt.daemon.log<br>
check_age 25298 mysql 2w REG 8,5 22049 33 /tmp/check_agent.log<br>
check_age 25298 mysql 1w REG 8,5 22049 33 /tmp/check_agent.log<br>
mysqld 3784 mysql 6u REG 8,5 15156 13 /tmp/ibH3IFN9 (deleted)</p>
</blockquote>
<p>上面lsof输出结果的第二列是PID,倒数第三列是占用空间大小<br>
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME<br>
可以看到文件/tmp/netstat.log (deleted)占用7个多G的空间，虽然被删除了，但是还是有进程打开它。</p>
<p><span id="more-55718"></span> 然后，用PID看看是哪个程序占用这个文件：</p>
<blockquote>
<p>$ps -ef | grep 13571<br>
<span style="color: #ff0000;">51717 13571 1 0 2011 ? 00:15:00 /bin/bash /tmp/netstat_20110829.sh</span><br>
51717 21456 13571 0 09:40 ? 00:00:00 sleep 10<br>
zhuxu 21458 17014 0 09:40 pts/0 00:00:00 grep 13571</p>
</blockquote>
<p>将这个进程KILL掉后，就OK了：</p>
<blockquote>
<p>$sudo kill -9 13571<br>
$sudo lsof | grep /tmp | sort -k7 -nr | head<br>
tcprstat 22084 root 2w REG 8,5 49339 49 /tmp/myrt.daemon.log<br>
sh 22083 mysql 2w REG 8,5 49339 49 /tmp/myrt.daemon.log<br>
sh 22083 mysql 1w REG 8,5 49339 49 /tmp/myrt.daemon.log<br>
myrt.pl 26045 mysql 2w REG 8,5 49339 49 /tmp/myrt.daemon.log<br>
myrt.pl 26045 mysql 1w REG 8,5 49339 49 /tmp/myrt.daemon.log<br>
check_age 25298 mysql 2w REG 8,5 24583 33 /tmp/check_agent.log<br>
check_age 25298 mysql 1w REG 8,5 24583 33 /tmp/check_agent.log<br>
mysqld 3784 mysql 6u REG 8,5 15156 13 /tmp/ibH3IFN9 (deleted)<br>
su 17013 root cwd DIR 8,5 4096 2 /tmp<br>
sort 22090 zhuxu cwd DIR 8,5 4096 2 /tmp</p>
<p>$df -h<br>
Filesystem Size Used Avail Use% Mounted on<br>
/dev/sda3 8.6G 1.5G 6.7G 18% /<br>
/dev/sda10 784G 325G 420G 44% /u01<br>
<span style="color: #ff0000;">/dev/sda5 8.7G 56M 8.2G 1% /tmp</span><br>
/dev/sda2 15G 2.8G 11G 21% /usr<br>
/dev/sda1 122M 12M 104M 10% /boot<br>
tmpfs 7.9G 4.0K 7.9G 1% /dev/shm</p>
</blockquote>
<p>--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/lsof.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【MySQL】数据目录权限问题导致服务重启</title>
		<link>http://chenxu.yo2.cn/articles/priv_mysqld_restart.html</link>
		<comments>http://chenxu.yo2.cn/articles/priv_mysqld_restart.html#comments</comments>
		<pubDate>Sat, 04 Feb 2012 06:26:59 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55717</guid>
		<description><![CDATA[今天一同事在进入mysql实例中某个数据库的时候，碰到ERROR 1018 (HY000): Can't read dir of './xx/' (errno: 13)错误，导致不能对该库进行相关操作（如：show tables时候也报同样的错），通过perror查看具体错误原因： $perror 13 OS error code 13: Permission denied 发现是权限问题，数据目录及其文件的用户和属组都是root，修改正确的权限后，可以show tables操作，但是进行count(*)表的时候，mysql实例重启了。 后面测试了一下： （1）mysql实例启动的时候，修改数据目录权限，然后访问报ERROR，还原权限后，都正常。 （2）mysql实例启动之前，修改数据目录权限，启动后，然后访问报ERROR，还原权限后，对表进行操作，mysql实例异常重启。 具体测试过程如下： 在mysql实例启动前修改异常权限： $ps -ef &#124; grep mysqld &#124; grep -v mysql &#124; wc -l 0 $ll total 10906156 -rw-rw---- 1 mysql dba 5368709120 Feb 3 21:03 ibdata1 -rw-rw---- 1 mysql dba [...]]]></description>
			<content:encoded><![CDATA[<p>今天一同事在进入mysql实例中某个数据库的时候，碰到<strong>ERROR 1018 (HY000): Can't read dir of './xx/' (errno: 13)</strong>错误，导致不能对该库进行相关操作（如：show tables时候也报同样的错），通过perror查看具体错误原因：</p>
<blockquote>
<p>$perror 13<br>
OS error code 13: Permission denied</p>
</blockquote>
<p>发现是权限问题，数据目录及其文件的用户和属组都是root，修改正确的权限后，可以show tables操作，但是进行count(*)表的时候，mysql实例重启了。<br>
后面测试了一下：<br>
（1）mysql实例启动的时候，修改数据目录权限，然后访问报ERROR，还原权限后，都正常。<br>
（2）mysql实例启动之前，修改数据目录权限，启动后，然后访问报ERROR，还原权限后，对表进行操作，mysql实例异常重启。</p>
<p><span id="more-55717"></span>具体测试过程如下：<br>
在mysql实例启动前修改异常权限：</p>
<blockquote>
<p>$ps -ef | grep mysqld | grep -v mysql | wc -l<br>
0<br>
$ll<br>
total 10906156<br>
-rw-rw---- 1 mysql dba 5368709120 Feb 3 21:03 ibdata1<br>
-rw-rw---- 1 mysql dba 5368709120 Feb 3 21:03 ibdata2<br>
-rw-rw---- 1 mysql dba 104857600 Feb 3 21:03 ib_logfile0<br>
-rw-rw---- 1 mysql dba 104857600 Feb 2 11:05 ib_logfile1<br>
-rw-rw---- 1 mysql dba 104857600 Feb 2 11:05 ib_logfile2<br>
-rw-rw---- 1 mysql dba 104857600 Feb 2 11:05 ib_logfile3<br>
drwx------ 2 mysql dba 4096 Oct 28 15:20 mysql<br>
drwx------ 2 mysql dba 4096 Dec 30 14:07 test<br>
<strong>drwx------ 2 <strong><span style="color: #ff0000;">root root</span></strong> 4096 Feb 3 12:47 zx_test</strong></p>
<p>$sudo -u mysql /u01/mysql/bin/mysqld_unsafe &amp;</p>
</blockquote>
<p>启动mysql实例时候，alert.log有错误信息：</p>
<blockquote>
<p>120203 21:07:24 InnoDB: highest supported file format is Barracuda.<br>
120203 21:07:25 InnoDB: Warning: allocated tablespace 12, old maximum was 0<br>
120203 21:07:25 InnoDB: Operating system error number 13 in a file operation.<br>
InnoDB: The error means mysqld does not have the access rights to<br>
InnoDB: the directory.<br>
<span style="color: #ff0000;"><strong>120203 21:07:25 InnoDB: Error: trying to open a table, but could not<br>
InnoDB: open the tablespace file './zx_test/tmp.ibd'!</strong></span><br>
InnoDB: Have you moved InnoDB .ibd files around without using the<br>
InnoDB: commands DISCARD TABLESPACE and IMPORT TABLESPACE?<br>
InnoDB: It is also possible that this is a temporary table #sql...,<br>
InnoDB: and MySQL removed the .ibd file for this.<br>
InnoDB: Please refer to<br>
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/innodb-troubleshooting-datadict.html<br>
InnoDB: for how to resolve the issue</p>
</blockquote>
<p>访问该库的时候，报错：</p>
<blockquote>
<p>$mysql -uroot zx_test<br>
Welcome to the MySQL monitor. Commands end with ; or \g.<br>
Your MySQL connection id is 9<br>
Server version: 5.1.48-log Source distribution</p>
<p>Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br>
This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br>
and you are welcome to modify and redistribute it under the GPL v2 license</p>
<p>Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</p>
<p>root@zx_test 09:11:53&gt;<strong>show tables;<br>
ERROR 1018 (HY000): Can't read dir of './zx_test/' (errno: 13)</strong><br>
root@zx_test 09:11:57&gt;<br>
root@zx_test 09:11:59&gt;<strong>create table tmp_zx (a int);<br>
ERROR 1005 (HY000): Can't create table 'tmp_zx' (errno: 13)</strong></p>
</blockquote>
<p>修改回原来权限之后，对库中已经存在的表进行访问时候，mysql实例重启了，重启后可以正常访问了：</p>
<blockquote>
<p>$<strong>sudo chown -R mysql:dba zx_test</strong><br>
$mysql -uroot zx_test<br>
Welcome to the MySQL monitor. Commands end with ; or \g.<br>
Your MySQL connection id is 10<br>
Server version: 5.1.48-log Source distribution</p>
<p>Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.<br>
This software comes with ABSOLUTELY NO WARRANTY. This is free software,<br>
and you are welcome to modify and redistribute it under the GPL v2 license</p>
<p>Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</p>
<p>root@zx_test 09:14:06&gt;show tables;<br>
+-------------------+<br>
| Tables_in_zx_test |<br>
+-------------------+<br>
| tmp |<br>
+-------------------+<br>
1 row in set (0.00 sec)</p>
<p>root@zx_test 09:14:11&gt;<strong>create table tmp_zx (a int);<br>
Query OK, 0 rows affected (0.01 sec)</strong></p>
<p>root@zx_test 09:14:21&gt;show tables;<br>
+-------------------+<br>
| Tables_in_zx_test |<br>
+-------------------+<br>
| tmp |<br>
| tmp_zx |<br>
+-------------------+<br>
2 rows in set (0.00 sec)</p>
<p>root@zx_test 09:14:24&gt;<strong>select * from tmp;</strong><br>
<span style="color: #ff0000;"><strong>ERROR 2013 (HY000): Lost connection to MySQL server during query<br>
root@zx_test 09:14:35&gt;120203 21:14:35 mysqld_safe Number of processes running now: 0<br>
120203 21:14:35 mysqld_safe mysqld restarted</strong></span></p>
<p>root@zx_test 09:16:42&gt;<br>
root@zx_test 09:16:44&gt;<br>
root@zx_test 09:16:48&gt;select * from tmp;<br>
ERROR 2006 (HY000): MySQL server has gone away<br>
No connection. Trying to reconnect...<br>
Connection id: 1<br>
Current database: zx_test</p>
<p>Empty set (0.02 sec)</p>
<p>root@zx_test 09:16:48&gt;select * from tmp;<br>
Empty set (0.00 sec)</p>
</blockquote>
<p>alert.log报错信息如下：</p>
<blockquote>
<p><span style="color: #ff0000;"><strong>120203 21:14:35 &nbsp;InnoDB: error: space object of table'zx_test/tmp',<br>
InnoDB: space id 990 did not exist in memory. Retrying an open.<br>
120203 21:14:35 &nbsp;InnoDB: Assertion failure in thread 1242745152 in file fil/fil0fil.c line 2982<br>
InnoDB: Failing assertion: flags != DICT_TF_COMPACT<br>
InnoDB: We intentionally generate a memory trap.</strong></span><br>
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.<br>
InnoDB: If you get repeated assertion failures or crashes, even<br>
InnoDB: immediately after the mysqld startup, there may be<br>
InnoDB: corruption in the InnoDB tablespace. Please refer to<br>
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html<br>
InnoDB: about forcing recovery.<br>
120203 21:14:35 - mysqld got signal 6 ;<br>
This could be because you hit a bug. It is also possible that this binary<br>
or one of the libraries it was linked against is corrupt, improperly built,<br>
or misconfigured. This error can also be caused by malfunctioning hardware.<br>
We will try our best to scrape up some info that will hopefully help diagnose<br>
the problem, but since we have already crashed, something is definitely wrong<br>
and this may fail.</p>
<p>key_buffer_size=2147483648<br>
read_buffer_size=1048576<br>
max_used_connections=1<br>
max_threads=1100<br>
threads_connected=1<br>
It is possible that mysqld could use up to<br>
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 3344878 K<br>
bytes of memory<br>
Hope that's ok; if not, decrease some variables in the equation.</p>
<p>thd: 0x1ef29df0<br>
Attempting backtrace. You can use the following information to find out<br>
where mysqld died. If you see no messages after this, something went<br>
terribly wrong...<br>
stack_bottom = 0x4a12c0f0 thread_stack 0x80000<br>
/u01/mysql/libexec/mysqld(my_print_stacktrace+0x35)[0x884b95]<br>
/u01/mysql/libexec/mysqld(handle_segfault+0x31d)[0x5bcfcd]<br>
/lib64/libpthread.so.0[0x351660e7c0]<br>
/lib64/libc.so.6(gsignal+0x35)[0x3515a30265]<br>
/lib64/libc.so.6(abort+0x110)[0x3515a31d10]<br>
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca1630f]<br>
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca0bc24]<br>
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca06b5a]<br>
/u01/mysql/lib/mysql/plugin/ha_innodb_plugin.so[0x2aab2ca32b0c]<br>
/u01/mysql/libexec/mysqld(_ZN7handler7ha_openEP8st_tablePKcii+0x3e)[0x6b760e]<br>
/u01/mysql/libexec/mysqld(_Z21open_table_from_shareP3THDP14st_table_sharePKcjjjP8st_tableb+0x592)[0x61b012]<br>
/u01/mysql/libexec/mysqld[0x613747]<br>
/u01/mysql/libexec/mysqld(_Z10open_tableP3THDP10TABLE_LISTP11st_mem_rootPbj+0x716)[0x616036]<br>
/u01/mysql/libexec/mysqld(_Z11open_tablesP3THDPP10TABLE_LISTPjj+0x627)[0x616c27]<br>
/u01/mysql/libexec/mysqld(_Z28open_and_lock_tables_derivedP3THDP10TABLE_LISTb+0x37)[0x616fd7]<br>
/u01/mysql/libexec/mysqld[0x5c7b2e]<br>
/u01/mysql/libexec/mysqld(_Z21mysql_execute_commandP3THD+0x33e1)[0x5ced01]<br>
/u01/mysql/libexec/mysqld(_Z11mysql_parseP3THDPKcjPS2_+0x20b)[0x5d3a2b]<br>
/u01/mysql/libexec/mysqld(_Z16dispatch_command19enum_server_commandP3THDPcj+0x3e0)[0x5d3e10]<br>
/u01/mysql/libexec/mysqld(_Z10do_commandP3THD+0xe6)[0x5d5066]<br>
/u01/mysql/libexec/mysqld(handle_one_connection+0x5c6)[0x5c55c6]<br>
/lib64/libpthread.so.0[0x35166064a7]<br>
/lib64/libc.so.6(clone+0x6d)[0x3515ad3c2d]<br>
Trying to get some variables.<br>
Some pointers may be invalid and cause the dump to abort...<br>
thd-&gt;query at 0x1eec18b0 = select * from tmp<br>
thd-&gt;thread_id=10<br>
thd-&gt;killed=NOT_KILLED<br>
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains<br>
information that should help you find out what is causing the crash.<br>
120203 21:14:35 mysqld_safe Number of processes running now: 0<br>
120203 21:14:35 mysqld_safe mysqld restarted<br>
...<br>
InnoDB: The InnoDB memory heap is disabled<br>
InnoDB: Mutexes and rw_locks use GCC atomic builtins<br>
InnoDB: Compressed tables use zlib 1.2.3<br>
120203 21:14:35 &nbsp;InnoDB: highest supported file format is Barracuda.<br>
InnoDB: The log sequence number in ibdata files does not match<br>
InnoDB: the log sequence number in the ib_logfiles!<br>
120203 21:14:35 &nbsp;InnoDB: Database was not shut down normally!<br>
InnoDB: Starting crash recovery.<br>
InnoDB: Reading tablespace information from the .ibd files...<br>
120203 21:14:35 &nbsp;InnoDB: Warning: allocated tablespace 343, old maximum was 0<br>
InnoDB: Restoring possible half-written data pages from the doublewrite<br>
InnoDB: buffer...<br>
InnoDB: Last MySQL binlog file position 0 302421247, file name /u01/mysql/log/mysql-bin.000340<br>
120203 21:14:36 InnoDB Plugin 1.0.9 started; log sequence number 16439604278<br>
120203 21:14:36 [Note] Recovering after a crash using /u01/mysql/log/mysql-bin<br>
120203 21:14:36 [Note] Starting crash recovery...<br>
120203 21:14:36 [Note] Crash recovery finished.<br>
120203 21:14:36 [Note] Event Scheduler: Loaded 0 events<br>
120203 21:14:36 [Note] /u01/mysql/libexec/mysqld: ready for connections.<br>
Version: '5.1.48-log' &nbsp;socket: '/u01/mysql/run/mysql.sock' &nbsp;port: 3306 &nbsp;Source distribution</p>
</blockquote>
<p>--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/priv_mysqld_restart.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【MySQL】Query Cache的使用问题</title>
		<link>http://chenxu.yo2.cn/articles/query_cache.html</link>
		<comments>http://chenxu.yo2.cn/articles/query_cache.html#comments</comments>
		<pubDate>Thu, 02 Feb 2012 06:58:08 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[query cache]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55714</guid>
		<description><![CDATA[在mysql version : 5.1.48-log的测试的时候，原来打算使用query cache，结果一直使用不了，后面测试发现是参数的配置不合理导致的。 原参数配置如下： root@test 01:47:31&#62;show variables like '%query_cache%'; +------------------------------+----------+ &#124; Variable_name &#124; Value &#124; +------------------------------+----------+ &#124; have_query_cache &#124; YES &#124; &#124; query_cache_limit &#124; 1024 &#124; &#124; query_cache_min_res_unit &#124; 1024 &#124; &#124; query_cache_size &#124; 31457280 &#124; &#124; query_cache_type &#124; DEMAND &#124; &#124; query_cache_wlock_invalidate &#124; OFF &#124; +------------------------------+----------+ 6 rows in set (0.00 sec) [...]]]></description>
			<content:encoded><![CDATA[<p>在mysql version : 5.1.48-log的测试的时候，原来打算使用query cache，结果一直使用不了，后面测试发现是参数的配置不合理导致的。</p>
<p>原参数配置如下：</p>
<blockquote>
<p>root@test 01:47:31&gt;show variables like '%query_cache%';<br>
+------------------------------+----------+<br>
| Variable_name | Value |<br>
+------------------------------+----------+<br>
| have_query_cache | YES |<br>
| query_cache_limit | 1024 |<br>
| query_cache_min_res_unit | 1024 |<br>
| query_cache_size | 31457280 |<br>
<strong>| query_cache_type | DEMAND |</strong><br>
| query_cache_wlock_invalidate | OFF |<br>
+------------------------------+----------+<br>
6 rows in set (0.00 sec)</p>
</blockquote>
<p>由于参数<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_query_cache_min_res_unit">query_cache_min_res_unit</a>值设置和<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_query_cache_limit">query_cache_limit</a>值设置一样大小，导致<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_query_cache_type">query_cache_type</a>=DEMAND时候，就是SQL中添加SQL_CACHE选项，还是不缓存。</p>
<p><span id="more-55714"></span></p>
<p style="display: inline !important;">下面测试看到Qcache_hits值一直没有增加，也就是不能命中query cache ：</p>
<blockquote>
<p>root@test 02:00:20&gt;flush status;<br>
Query OK, 0 rows affected (0.00 sec)</p>
<p>root@test 02:00:27&gt;show global status like '%qcache%';<br>
+-------------------------+----------+<br>
| Variable_name | Value |<br>
+-------------------------+----------+<br>
| Qcache_free_blocks | 1 |<br>
| Qcache_free_memory | 31437704 |<br>
<strong>| Qcache_hits | 0 |<br>
| Qcache_inserts | 0 |</strong><br>
| Qcache_lowmem_prunes | 0 |<br>
| Qcache_not_cached | 23 |<br>
| Qcache_queries_in_cache | 1 |<br>
| Qcache_total_blocks | 4 |<br>
+-------------------------+----------+<br>
8 rows in set (0.00 sec)</p>
<p>root@test 02:00:30&gt;<strong>select <span style="color: #ff0000;">sql_cache</span> * from test where id = 2 ;</strong><br>
+----+------+<br>
| id | col |<br>
+----+------+<br>
| 2 | b |<br>
+----+------+<br>
1 row in set (0.00 sec)</p>
<p>root@test 02:00:52&gt;show global status like '%qcache%';<br>
+-------------------------+----------+<br>
| Variable_name | Value |<br>
+-------------------------+----------+<br>
| Qcache_free_blocks | 1 |<br>
| Qcache_free_memory | 31437704 |<br>
<strong>| Qcache_hits | 0 |<br>
| Qcache_inserts | 0 |</strong><br>
| Qcache_lowmem_prunes | 0 |<br>
| Qcache_not_cached | 256 |<br>
| Qcache_queries_in_cache | 1 |<br>
| Qcache_total_blocks | 4 |<br>
+-------------------------+----------+<br>
8 rows in set (0.00 sec)</p>
<p>root@test 02:00:56&gt;<strong>select <span style="color: #ff0000;">sql_cache</span> * from test where id = 2 ;</strong><br>
+----+------+<br>
| id | col |<br>
+----+------+<br>
| 2 | b |<br>
+----+------+<br>
1 row in set (0.01 sec)</p>
<p>root@test 02:00:59&gt;show global status like '%qcache%';<br>
+-------------------------+----------+<br>
| Variable_name | Value |<br>
+-------------------------+----------+<br>
| Qcache_free_blocks | 1 |<br>
| Qcache_free_memory | 31437704 |<br>
<strong>| Qcache_hits | 0 |<br>
| Qcache_inserts | 0 |</strong><br>
| Qcache_lowmem_prunes | 0 |<br>
| Qcache_not_cached | 308 |<br>
| Qcache_queries_in_cache | 1 |<br>
| Qcache_total_blocks | 4 |<br>
+-------------------------+----------+<br>
8 rows in set (0.00 sec)</p>
</blockquote>
<p><span style="color: #ff0000;">设置参数query_cache_min_res_unit值小于和query_cache_limit值的时候，查询就可以命中了</span>，可以看到第一次查询之后Qcache_inserts+1，第二次查询之后命中Qcache_hits+1 ：</p>
<blockquote>
<p>root@test 02:03:43&gt;<strong>set global query_cache_min_res_unit = 1000;</strong><br>
Query OK, 0 rows affected (0.00 sec)</p>
<p>root@test 02:03:51&gt;show variables like '%query_cache%';<br>
+------------------------------+----------+<br>
| Variable_name | Value |<br>
+------------------------------+----------+<br>
| have_query_cache | YES |<br>
<strong>| query_cache_limit | 1024 |<br>
| query_cache_min_res_unit | 1000 |</strong><br>
| query_cache_size | 31457280 |<br>
| query_cache_type | DEMAND |<br>
| query_cache_wlock_invalidate | OFF |<br>
+------------------------------+----------+<br>
6 rows in set (0.00 sec)</p>
<p>root@test 02:04:14&gt;show global status like '%qcache%';<br>
+-------------------------+----------+<br>
| Variable_name | Value |<br>
+-------------------------+----------+<br>
| Qcache_free_blocks | 1 |<br>
| Qcache_free_memory | 31437704 |<br>
| Qcache_hits | 0 |<br>
| Qcache_inserts | 0 |<br>
| Qcache_lowmem_prunes | 0 |<br>
| Qcache_not_cached | 1965 |<br>
| Qcache_queries_in_cache | 1 |<br>
| Qcache_total_blocks | 4 |<br>
+-------------------------+----------+<br>
8 rows in set (0.00 sec)</p>
<p>root@test 02:04:14&gt;<strong>select <span style="color: #ff0000;">sql_cache</span> * from test where id = 2 ;</strong><br>
+----+------+<br>
| id | col |<br>
+----+------+<br>
| 2 | b |<br>
+----+------+<br>
1 row in set (0.00 sec)</p>
<p>root@test 02:04:20&gt;show global status like '%qcache%';<br>
+-------------------------+----------+<br>
| Variable_name | Value |<br>
+-------------------------+----------+<br>
| Qcache_free_blocks | 1 |<br>
| Qcache_free_memory | 31436192 |<br>
<strong>| Qcache_hits | 0 |<br>
| Qcache_inserts | <span style="color: #ff0000;">1</span> |</strong><br>
| Qcache_lowmem_prunes | 0 |<br>
| Qcache_not_cached | 2145 |<br>
| Qcache_queries_in_cache | 2 |<br>
| Qcache_total_blocks | 6 |<br>
+-------------------------+----------+<br>
8 rows in set (0.00 sec)</p>
<p>root@test 02:04:32&gt;<strong>select sql_cache * from test where id = 2 ;</strong><br>
+----+------+<br>
| id | col |<br>
+----+------+<br>
| 2 | b |<br>
+----+------+<br>
1 row in set (0.00 sec)</p>
<p>root@test 02:04:36&gt;show global status like '%qcache%';<br>
+-------------------------+----------+<br>
| Variable_name | Value |<br>
+-------------------------+----------+<br>
| Qcache_free_blocks | 1 |<br>
| Qcache_free_memory | 31436192 |<br>
<strong>| Qcache_hits | <span style="color: #ff0000;">1</span> |<br>
| Qcache_inserts | 1 |</strong><br>
| Qcache_lowmem_prunes | 0 |<br>
| Qcache_not_cached | 2175 |<br>
| Qcache_queries_in_cache | 2 |<br>
| Qcache_total_blocks | 6 |<br>
+-------------------------+----------+<br>
8 rows in set (0.00 sec)</p>
</blockquote>
<p>另外，对于query_cache_type=DEMAND的时候，即使SQL不加SQL_CACHE选项，也是需要到query cache中去查询一下，具体如下：</p>
<blockquote>
<p>root@test 02:04:37&gt;show global variables like '%query_cache%';<br>
+------------------------------+----------+<br>
| Variable_name | Value |<br>
+------------------------------+----------+<br>
| have_query_cache | YES |<br>
| query_cache_limit | 1024 |<br>
| query_cache_min_res_unit | 1000 |<br>
| query_cache_size | 31457280 |<br>
<strong>| query_cache_type | DEMAND |</strong><br>
| query_cache_wlock_invalidate | OFF |<br>
+------------------------------+----------+<br>
6 rows in set (0.00 sec)</p>
<p>root@test 02:10:58&gt;set profiling = 1;<br>
Query OK, 0 rows affected (0.00 sec)</p>
<p>root@test 02:11:15&gt;<strong>select * from test where id = 2 ;</strong><br>
+----+------+<br>
| id | col |<br>
+----+------+<br>
| 2 | b |<br>
+----+------+<br>
1 row in set (0.00 sec)</p>
<p>root@test 02:11:29&gt;show profile source for query 1;<br>
+--------------------------------+----------+------------------+---------------+-------------+<br>
| Status | Duration | Source_function | Source_file | Source_line |<br>
+--------------------------------+----------+------------------+---------------+-------------+<br>
| starting | 0.000086 | NULL | NULL | NULL |<br>
<strong>| <span style="color: #ff0000;">checking query cache for query</span> | 0.000058 | unknown function | sql_cache.cc | 1446 |</strong><br>
| Opening tables | 0.000021 | unknown function | sql_base.cc | 4517 |<br>
| System lock | 0.000010 | unknown function | lock.cc | 258 |<br>
| Table lock | 0.000016 | unknown function | lock.cc | 269 |<br>
| init | 0.000032 | unknown function | sql_select.cc | 2484 |<br>
| optimizing | 0.000016 | unknown function | sql_select.cc | 820 |<br>
| statistics | 0.000070 | unknown function | sql_select.cc | 1011 |<br>
| preparing | 0.000021 | unknown function | sql_select.cc | 1033 |<br>
| executing | 0.000010 | unknown function | sql_select.cc | 1755 |<br>
| Sending data | 0.000020 | unknown function | sql_select.cc | 2309 |<br>
| end | 0.000011 | unknown function | sql_select.cc | 2530 |<br>
| query end | 0.000009 | unknown function | sql_parse.cc | 4986 |<br>
| freeing items | 0.000019 | unknown function | sql_parse.cc | 6012 |<br>
| logging slow query | 0.000009 | unknown function | sql_parse.cc | 1687 |<br>
| cleaning up | 0.000009 | unknown function | sql_parse.cc | 1655 |<br>
+--------------------------------+----------+------------------+---------------+-------------+<br>
16 rows in set (0.00 sec)</p>
</blockquote>
<p>其中上面status : checking query cache for query 中对应的source_function就是send_result_to_client，在MYSQL源码中有如下信息：</p>
<blockquote>
<p>int Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)<br>
{<br>
...<br>
<strong>if (thd-&gt;locked_tables || <span style="color: #ff0000;">thd-&gt;variables.query_cache_type == 0 ||<br>
query_cache_size == 0</span>)</strong><br>
goto err;<br>
...<br>
}</p>
</blockquote>
<p>所以,只有query_cache_type=OFF，关掉query cache时候，才不会再去query cache中查询一次，具体如下：</p>
<blockquote>
<p>root@test 02:14:20&gt;show variables like '%query_cache%';<br>
+------------------------------+----------+<br>
| Variable_name | Value |<br>
+------------------------------+----------+<br>
| have_query_cache | YES |<br>
| query_cache_limit | 1024 |<br>
| query_cache_min_res_unit | 1000 |<br>
| query_cache_size | 31457280 |<br>
<strong>| query_cache_type | OFF |</strong><br>
| query_cache_wlock_invalidate | OFF |<br>
+------------------------------+----------+<br>
6 rows in set (0.00 sec)</p>
<p>root@test 02:14:31&gt;set profiling=1;<br>
Query OK, 0 rows affected (0.00 sec)</p>
<p>root@test 02:14:33&gt;<strong>select * from test where id = 2 ;</strong><br>
+----+------+<br>
| id | col |<br>
+----+------+<br>
| 2 | b |<br>
+----+------+<br>
1 row in set (0.00 sec)</p>
<p>root@test 02:14:52&gt;show profile source for query 1;<br>
+--------------------+----------+------------------+---------------+-------------+<br>
| Status | Duration | Source_function | Source_file | Source_line |<br>
+--------------------+----------+------------------+---------------+-------------+<br>
| starting | 0.000125 | NULL | NULL | NULL |<br>
| Opening tables | 0.000035 | unknown function | sql_base.cc | 4517 |<br>
| System lock | 0.000012 | unknown function | lock.cc | 258 |<br>
| Table lock | 0.000016 | unknown function | lock.cc | 269 |<br>
| init | 0.000034 | unknown function | sql_select.cc | 2484 |<br>
| optimizing | 0.000017 | unknown function | sql_select.cc | 820 |<br>
| statistics | 0.000066 | unknown function | sql_select.cc | 1011 |<br>
| preparing | 0.000023 | unknown function | sql_select.cc | 1033 |<br>
| executing | 0.000010 | unknown function | sql_select.cc | 1755 |<br>
| Sending data | 0.000022 | unknown function | sql_select.cc | 2309 |<br>
| end | 0.000011 | unknown function | sql_select.cc | 2530 |<br>
| query end | 0.000009 | unknown function | sql_parse.cc | 4986 |<br>
| freeing items | 0.000035 | unknown function | sql_parse.cc | 6012 |<br>
| logging slow query | 0.000010 | unknown function | sql_parse.cc | 1687 |<br>
| cleaning up | 0.000010 | unknown function | sql_parse.cc | 1655 |<br>
+--------------------+----------+------------------+---------------+-------------+<br>
15 rows in set (0.00 sec)</p>
<p>root@test 02:15:01&gt;show profiles;<br>
+----------+------------+---------------------------------+<br>
| Query_ID | Duration | Query |<br>
+----------+------------+---------------------------------+<br>
| 1 | 0.00043500 | select * from test where id = 2 |<br>
+----------+------------+---------------------------------+<br>
1 row in set (0.00 sec)</p>
</blockquote>
<p>【附】<br>
<a href="http://www.alidba.net/index.php/archives/423">http://www.alidba.net/index.php/archives/423</a><br>
<a href="http://www.mysqlops.com/2011/08/10/mysql-query-cache.html">http://www.mysqlops.com/2011/08/10/mysql-query-cache.html</a><br>
--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/query_cache.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【Linux】oprofile安装使用笔记</title>
		<link>http://chenxu.yo2.cn/articles/oprofile.html</link>
		<comments>http://chenxu.yo2.cn/articles/oprofile.html#comments</comments>
		<pubDate>Sat, 14 Jan 2012 07:54:35 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[Linux & Unix]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[oprofile]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55712</guid>
		<description><![CDATA[一、oprofile的相关链接：oprofile的&#160;manual &#124; 下载 。 二、oprofile的安装使用 2.1 安装 wget http://prdownloads.sourceforge.net/oprofile/oprofile-0.9.7.tar.gz tar -zxvf oprofile-0.9.7.tar.gz cd oprofile-0.9.7 sudo yum install binutils-devel&#160; --说明：configure报错时候需要装一下这个包 (参考这个网址) ./configure make sudo make install 2.2 使用 开始： sudo opcontrol --deinit; sudo /sbin/modprobe oprofile timer=1 sudo opcontrol --setup --no-vmlinux &#38;&#38; sudo opcontrol --init &#38;&#38; sudo opcontrol --reset &#38;&#38; sudo opcontrol --start 采集期间跑程序： $mysqlslap --no-defaults --query=" [...]]]></description>
			<content:encoded><![CDATA[<p>一、oprofile的相关链接：oprofile的&nbsp;<a href="http://oprofile.sourceforge.net/doc/index.html">manual</a> | <a href="http://oprofile.sourceforge.net/download/">下载</a> 。<br>
二、oprofile的安装使用<br>
<strong>2.1 安装</strong></p>
<blockquote>
<p>wget http://prdownloads.sourceforge.net/oprofile/oprofile-0.9.7.tar.gz<br>
tar -zxvf oprofile-0.9.7.tar.gz<br>
cd oprofile-0.9.7<br>
sudo yum install binutils-devel&nbsp; <strong>--说明：configure报错时候需要装一下这个包</strong> (参考这个<a href="http://hi.baidu.com/9longl/blog/item/255b59205aeb5f449922ed51.html">网址</a>)<br>
./configure<br>
make<br>
sudo make install</p>
</blockquote>
<p><span id="more-55712"></span></p>
<p><strong>2.2 使用</strong><br></p>
<div id="_mcePaste" style="display: inline !important;">开始：</div>
<blockquote>
<div id="_mcePaste">sudo opcontrol --deinit; sudo /sbin/modprobe oprofile timer=1</div>
<div id="_mcePaste">sudo opcontrol --setup --no-vmlinux &amp;&amp; sudo opcontrol --init &amp;&amp; sudo opcontrol --reset &amp;&amp; sudo opcontrol --start</div>
</blockquote>
<div id="_mcePaste">采集期间跑程序：</div>
<blockquote>
<div id="_mcePaste">$mysqlslap --no-defaults --query=" select count(*) as num from vid_film left join vid_class_map on vid_film.id=vid_class_map.v_id and vid_class_map.s_type=1 and vid_class_map.class_id=1;" --number-of-queries=5000 --concurrency=50 -uroot --socket=/u01/mysql/run/mysql.sock</div>
</blockquote>
<div id="_mcePaste">结束，生成报告tmp.log：</div>
<blockquote>
<div id="_mcePaste">sudo opcontrol --shutdown</div>
<div id="_mcePaste">opreport -g -l -p /u01/mysql /u01/mysql/libexec/mysqld --merge all -o tmp.log</div>
</blockquote>
<p><strong>2.3 遇到的问题</strong><br>
（1）使用opreport报错：</p>
<blockquote>
<p>1、error: no sample files found: profile specification too strict<br>
2、opreport error: No sample file found: try running opcontrol --dump&nbsp;or specify a session containing sample files</p>
</blockquote>
<p>的时候，需要删除下面配置</p>
<blockquote>
<p>sudo rm -f /root/.oprofile/daemonrc</p>
</blockquote>
<p>参考：<a href="http://blog.yufeng.info/archives/1283">http://blog.yufeng.info/archives/1283</a></p>
<p>（2）报告的结果无具体符号表相关信息</p>
<blockquote>
<p>$more tmp.log<br>
CPU: CPU with timer interrupt, speed 0 MHz (estimated)<br>
Profiling through timer interrupt<br>
samples % linenr info symbol name<br>
16823 100.000 (no location information) /u01/mysql/libexec/mysqld</p>
</blockquote>
<p>问题：这个时候只看到mysqld，看不到线程具体跑的函数统计。通过命令( objdump -t /u01/mysql/libexec/mysqld | head )查看是无符号表。<br>
原因：这个mysql是rpm直接安装的，虽然在configure时候也是有加-g，rpmbuild时候问题<br>
解决：源码重新编译一下，重新跑上面的就OK了，结果如下：</p>
<blockquote>
<p>$head -n15 tmp.log<br>
CPU: CPU with timer interrupt, speed 0 MHz (estimated)<br>
Profiling through timer interrupt<br>
samples % linenr info symbol name<br>
4589 16.4628 mf_keycache.c:1666 find_key_block<br>
4123 14.7910 mf_keycache.c:2542 key_cache_read<br>
3781 13.5641 my_handler.c:124 ha_key_cmp<br>
3554 12.7498 bmove512.c:40 bmove512<br>
2403 8.6206 mf_keycache.c:1349 unreg_request<br>
2238 8.0287 mi_search.c:184 _mi_bin_search<br>
679 2.4359 mi_search.c:64 _mi_search<br>
618 2.2170 mi_key.c:220 _mi_pack_key<br>
615 2.2063 sql_select.cc:11896 join_read_key(st_join_table*)<br>
469 1.6825 sql_select.cc:11345 sub_select(JOIN*, st_join_table*, bool)<br>
466 1.6717 sql_select.cc:11413 evaluate_join_record(JOIN*, st_join_table*, int)<br>
409 1.4673 mi_key.c:468 _mi_read_key_record</p>
</blockquote>
<p><span style="font-family: Tahoma; font-size: small;"><span style="line-height: normal;"><br></span></span></p>
<p>--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/oprofile.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>【MySQL】Innodb行记录格式</title>
		<link>http://chenxu.yo2.cn/articles/innodb_file_format.html</link>
		<comments>http://chenxu.yo2.cn/articles/innodb_file_format.html#comments</comments>
		<pubDate>Sun, 24 Jul 2011 08:32:22 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Inodb_File/Row_Format]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55705</guid>
		<description><![CDATA[一、compact和redundant行记录模式 MySQL 5.1中Innodb存储引擎（Built-in-InnoDB）提供了compact和redundant两种格式来记录行数据，redundant是为了兼容之前版本保留的。默认情况下保存的格式为compact格式。可以通过命令show table staus like 'table_name'查看当前表使用的行格式（对应查询结果中的Row_format值）。 对于compact行记录模式：不管char还是varchar类型，NULL值都不占用存储空间。 对于redundant行记录模式：varchar类型的NUL值不占用存储空间，而char类型需要占用存储空间。 二、dynamic和compressed行记录模式 Innodb plugin引入新的文件格式Barracuda，并将以前支持的compact和redundant行记录模式称为Antelope文件格式。 Barracuda文件格式包含两种新的行记录格式：Dynamic和Compressed。 这两种文件格式在处理行溢出时候，Antelope会存放768个前缀字节，Barracuda只会存放20个字节的指针，见下图。 同时，选择文件格式对应的参数innodb_file_format，默认为Antelope。 其他详细的可以参考：http://dev.mysql.com/doc/innodb/1.1/en/innodb-row-format-dynamic.html 再来一张图： 上面的笔记来自： 1、《MySQL技术内幕InnoDB存储引擎》 2、《InnoDB Internals: InnoDB File Formats and Source Code Structure》 三、问题解决 在一次机器升级中涉及到数据库迁移，MYSQL版本都是5.1.x，从一个没有装innodb plugin的版本的数据库A通过mysqldump出来，恢复到装有innodb plugin版本的数据库B中其中一张表报错，B中报错类似如下： root@test 04:10:58&#62;create table tmp_zx ( a int) engine = innodb row_format = dynamic; ERROR 1005 (HY000): Can't create table 'test.tmp_zx' (errno: 1478 ) [...]]]></description>
			<content:encoded><![CDATA[<p><strong>一、compact和redundant行记录模式</strong></p>
<p>MySQL 5.1中Innodb存储引擎（Built-in-InnoDB）提供了compact和redundant两种格式来记录行数据，redundant是为了兼容之前版本保留的。默认情况下保存的格式为compact格式。可以通过命令show table staus like 'table_name'查看当前表使用的行格式（对应查询结果中的Row_format值）。</p>
<p>对于compact行记录模式：不管char还是varchar类型，NULL值都不占用存储空间。</p>
<p>对于redundant行记录模式：varchar类型的NUL值不占用存储空间，而char类型需要占用存储空间。</p>
<p><strong>二、dynamic和compressed行记录模式</strong></p>
<p>Innodb plugin引入新的文件格式<strong>Barracuda</strong>，并将以前支持的compact和redundant行记录模式称为<strong>Antelope</strong>文件格式。</p>
<p>Barracuda文件格式包含两种新的行记录格式：Dynamic和Compressed。</p>
<p>这两种文件格式在处理行溢出时候，Antelope会存放768个前缀字节，Barracuda只会存放20个字节的指针，见下图。</p>
<p><span id="more-55705"></span><img class="alignnone size-full wp-image-55707" title="innodb_rows" src="http://files.blogcn.com/wp06/M00/01/FE/wKgKDE4rytkAAAAAAAB8WC88n0M140.png" alt="" width="519" height="368"></p>
<p>同时，选择文件格式对应的参数<a href="http://dev.mysql.com/doc/refman/5.5/en/innodb-parameters.html#sysvar_innodb_file_format" target="_blank">innodb_file_format</a>，默认为Antelope。</p>
<p>其他详细的可以参考：<a href="http://dev.mysql.com/doc/innodb/1.1/en/innodb-row-format-dynamic.html">http://dev.mysql.com/doc/innodb/1.1/en/innodb-row-format-dynamic.html</a></p>
<p>再来一张图：</p>
<p><img class="alignnone size-full wp-image-55708" title="file_format" src="http://files.blogcn.com/wp01/M00/01/50/wKgKC04rz34AAAAAAAA_TCA-HyE959.png" alt="" width="489" height="216"></p>
<p>上面的笔记来自：</p>
<p>1、《MySQL技术内幕InnoDB存储引擎》</p>
<p>2、《<a href="http://www.innodb.com/wp/wp-content/uploads/2009/05/innodb-file-formats-and-source-code-structure.pdf" target="_blank">InnoDB Internals: InnoDB File Formats and Source Code Structure</a>》</p>
<p><strong>三、问题解决</strong></p>
<p>在一次机器升级中涉及到数据库迁移，MYSQL版本都是5.1.x，从一个没有装innodb plugin的版本的<strong>数据库A</strong>通过mysqldump出来，恢复到装有innodb plugin版本的<strong>数据库B</strong>中其中一张表报错，B中报错类似如下：</p>
<blockquote>
<p>root@test 04:10:58&gt;create table tmp_zx ( a int) engine = innodb <strong>row_format = dynamic</strong>;<br>
ERROR 1005 (HY000): Can't create table 'test.tmp_zx' (errno: 1478 )</p>
</blockquote>
<p>原因是B中innodb_file_format中默认值为默认的Antelope：</p>
<blockquote>
<p>root@test 04:17:58&gt;<strong>show variables where variable_name in ('innodb_file_per_table','innodb_file_format','innodb_version');</strong><br>
+-----------------------+----------+<br>
| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value&nbsp;&nbsp;&nbsp; |<br>
+-----------------------+----------+<br>
| <strong>innodb_file_format&nbsp;&nbsp;&nbsp; | <span style="color: #ff0000;">Antelope</span> |</strong><br>
| innodb_file_per_table | ON&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<br>
| <strong>innodb_version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | 1.0.9&nbsp;&nbsp;&nbsp; |</strong><br>
+-----------------------+----------+<br>
3 rows in set (0.00 sec)</p>
</blockquote>
<p>动态修改为innodb_file_format 为 Barracuda 就可以。</p>
<p>但是原来A中没有装plugin怎么能有row_format = dynamic的表？</p>
<p>其实原因在于开发创建时候，虽然选择row_format = dynamic但是实际上转换为Compact（可以参考说明：<a href="http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-compression-syntax-warnings.html">http://dev.mysql.com/doc/innodb-plugin/1.0/en/innodb-compression-syntax-warnings.html</a>），但是在Create_options: row_format=DYNAMIC中保留这个选项，mysqldump导出表结构时候就保留原来创建时候的选项。在A中情况如下：</p>
<blockquote>
<p>root@localhost 16:25:40&gt;<strong>show variables where variable_name in ('innodb_file_format','innodb_version');</strong><br>
Empty set (0.00 sec)</p>
<p>root@localhost 16:25:42&gt;create table tmp_zx ( a int) engine = innodb <strong>row_format = dynamic</strong>;<br>
Query OK, 0 rows affected (0.20 sec)</p>
<p>root@localhost 16:25:50&gt;show table status like 'tmp_zx'\G<br>
*************************** 1. row ***************************<br>
Name: tmp_zx<br>
Engine: InnoDB<br>
Version: 10<br>
<span style="color: #ff0000;"><strong>Row_format: Compact</strong></span><br>
Rows: 0<br>
Avg_row_length: 0<br>
Data_length: 16384<br>
Max_data_length: 0<br>
Index_length: 0<br>
Data_free: 0<br>
Auto_increment: NULL<br>
Create_time: 2011-07-24 16:25:50<br>
Update_time: NULL<br>
Check_time: NULL<br>
Collation: gbk_chinese_ci<br>
Checksum: NULL<br>
<span style="color: #ff0000;"><strong>Create_options: row_format=DYNAMIC</strong></span><br>
Comment:<br>
1 row in set (0.00 sec)</p>
<p>root@localhost 16:25:56&gt;show create table tmp_zx\G<br>
*************************** 1. row ***************************<br>
Table: tmp_zx<br>
Create Table: CREATE TABLE `tmp_zx` (<br>
`a` int(11) DEFAULT NULL<br>
) ENGINE=InnoDB DEFAULT CHARSET=gbk <span style="color: #ff0000;"><strong>ROW_FORMAT=DYNAMIC</strong></span><br>
1 row in set (0.00 sec)</p>
</blockquote>
<p>--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/innodb_file_format.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>【Perl】连接MySQL</title>
		<link>http://chenxu.yo2.cn/articles/perl_mysql.html</link>
		<comments>http://chenxu.yo2.cn/articles/perl_mysql.html#comments</comments>
		<pubDate>Sat, 09 Apr 2011 08:25:08 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[DBI_MySQL]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55704</guid>
		<description><![CDATA[Perl连接MySQL需要安装Perl的DBI和DBD:mysql模块。 记录一下连接MySQL的脚本，供以后参考： #!/bin/env perl use strict; use warnings; use DBI; # ------------------------------------------------------------------- # Func &#160; : Main() # ------------------------------------------------------------------- my $user &#160; = "root"; my $passwd = ""; my $host &#160; = "10.254.5.151"; my $db &#160; &#160; = "test"; my $port &#160; = 3306; # connect database my $dbh = &#38;connet_mysql($host,$port,$db,$user,$passwd); # execute sql my [...]]]></description>
			<content:encoded><![CDATA[<p>Perl连接MySQL需要<a href="http://chenxu.yo2.cn/articles/perl_dbi_dbdmysql.html" target="_blank">安装Perl的DBI和DBD:mysql模块</a>。</p>
<p>记录一下连接MySQL的脚本，供以后参考：</p>
<blockquote>
<div id="_mcePaste">#!/bin/env perl</div>
<div id="_mcePaste">use strict;</div>
<div id="_mcePaste">use warnings;</div>
<div id="_mcePaste"><span style="color: #ff0000;"><strong>use DBI;</strong></span></div>
<div id="_mcePaste"><span style="color: #008000;"># -------------------------------------------------------------------</span></div>
<div id="_mcePaste"><span style="color: #008000;"># Func &nbsp; : Main()</span></div>
<div id="_mcePaste"><span style="color: #008000;"># -------------------------------------------------------------------</span></div>
<div id="_mcePaste">my $user &nbsp; = "root";</div>
<div id="_mcePaste">my $passwd = "";</div>
<div id="_mcePaste">my $host &nbsp; = "10.254.5.151";</div>
<div id="_mcePaste">my $db &nbsp; &nbsp; = "test";</div>
<div id="_mcePaste">my $port &nbsp; = 3306;</div>
<div id="_mcePaste"><span style="color: #008000;"># connect database</span></div>
<div id="_mcePaste">my $dbh = <strong><em>&amp;connet_mysql($host,$port,$db,$user,$passwd);</em></strong></div>
<div id="_mcePaste"><span id="more-55704"></span></div>
<div><span style="color: #008000;"># execute sql</span></div>
<div id="_mcePaste">my $sql = qq{select * from tmp_zx limit 10};</div>
<div id="_mcePaste">my $sth = <strong><em>&amp;execute_sql($dbh,$sql);</em></strong></div>
<div id="_mcePaste"><span style="color: #008000;"># get sql result</span></div>
<div id="_mcePaste">while ( my $result_ref = <span style="color: #ff0000;">$sth-&gt;fetchrow_hashref()</span> ) {</div>
<div id="_mcePaste">my $delim = "";</div>
<div id="_mcePaste">foreach ( keys %{$result_ref} ) {</div>
<div id="_mcePaste">print $delim,$_,"=",$result_ref-&gt;{$_};</div>
<div id="_mcePaste">$delim = " , ";</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">print "\n";</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste"><span style="color: #008000;"># end sql</span></div>
<div id="_mcePaste"><span style="color: #ff0000;">$sth-&gt;finish();</span></div>
<div id="_mcePaste"><span style="color: #008000;"># disconnect from database</span></div>
<div id="_mcePaste"><span style="color: #ff0000;">$dbh-&gt;disconnect();</span></div>
<div id="_mcePaste"><span style="color: #008000;"># -------------------------------------------------------------------</span></div>
<div id="_mcePaste"><span style="color: #008000;"># Func &nbsp; : Connect Database</span></div>
<div id="_mcePaste"><span style="color: #008000;"># Sample :</span></div>
<div id="_mcePaste"><span style="color: #008000;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;connet_mysql($host,$port,$db,$user,$passwd);</span></div>
<div id="_mcePaste"><span style="color: #008000;"># -------------------------------------------------------------------</span></div>
<div id="_mcePaste">sub <strong><em>connet_mysql</em></strong> {</div>
<div id="_mcePaste"><span style="color: #008000;"># setup database connection variables</span></div>
<div id="_mcePaste">my ($host,$port,$db,$user,$passwd) = @_;</div>
<div id="_mcePaste">my $driver = "mysql";</div>
<div id="_mcePaste"><span style="color: #008000;"># connect to database</span></div>
<div id="_mcePaste">my $dsn = <span style="color: #ff0000;">"DBI:$driver:database=$db;host=$host;port=$port"</span>;</div>
<div id="_mcePaste">my $mysql_dbh = <span style="color: #ff0000;">DBI-&gt;connect($dsn,$user,$passwd)</span> or die "Connect to mysql database error:". <span style="color: #ff0000;">DBI-&gt;errstr</span>;</div>
<div id="_mcePaste"><span style="color: #ff0000;">$mysql_dbh-&gt;{AutoCommit} = 0</span>;</div>
<div id="_mcePaste">$mysql_dbh-&gt;{RaiseError} = 1;</div>
<div id="_mcePaste">$mysql_dbh-&gt;{PrintError} = 1;</div>
<div id="_mcePaste"><span style="color: #ff0000;">$mysql_dbh-&gt;do("set names gbk");</span></div>
<div id="_mcePaste">return $mysql_dbh;</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste"><span style="color: #008000;"># -------------------------------------------------------------------</span></div>
<div id="_mcePaste"><span style="color: #008000;"># Func &nbsp; : Execute SQL</span></div>
<div id="_mcePaste"><span style="color: #008000;"># Sample :</span></div>
<div id="_mcePaste"><span style="color: #008000;"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;execute_sql($dbh,$sql);</span></div>
<div id="_mcePaste"><span style="color: #008000;"># -------------------------------------------------------------------</span></div>
<div id="_mcePaste">sub <strong><em>execute_sql</em></strong> {</div>
<div id="_mcePaste">my ($dbh, $sql) = @_;</div>
<div id="_mcePaste">my $sth = <span style="color: #ff0000;">$dbh-&gt;prepare($sql);</span></div>
<div id="_mcePaste"><span style="color: #ff0000;">$sth-&gt;execute();</span></div>
<div id="_mcePaste">return $sth;</div>
<div id="_mcePaste">}</div>
</blockquote>
<p>【附】Perl的引用：<a href="http://search.cpan.org/~nwclark/perl-5.8.6/pod/perlreftut.pod">http://search.cpan.org/~nwclark/perl-5.8.6/pod/perlreftut.pod</a></p>
<p>--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/perl_mysql.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【Perl】fork子进程</title>
		<link>http://chenxu.yo2.cn/articles/perl_fork.html</link>
		<comments>http://chenxu.yo2.cn/articles/perl_fork.html#comments</comments>
		<pubDate>Fri, 08 Apr 2011 04:58:12 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[fork]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55699</guid>
		<description><![CDATA[Perl中可以通过fork函数来创建一个子进程。如果fork成功的话，这个时候就存在父进程和子进程，接下来2个进程会同时开始执行perl脚本中fork函数后面的代码。例子如下： #!/usr/local/bin/perl use Term::ANSIColor; use strict; use warnings; $SIG{CHLD} = 'IGNORE'; #忽略SIGCHLD信号,回收僵尸子进程 print color('green'),"Program started... pid = $$ \n\n"; print "fork process...\n"; # 如果fork失败，则返回undefined defined ( my $child = fork() ) or die "Fork Error : $!\n" ; # 如果fork成功: # 如果是父进程，则把生成的子进程PID赋值给$child。 # 如果是子进程，则把0赋值给$child。 if ($child == 0){ print color('yellow'),"\n-&#62; child process running ...\n"; print [...]]]></description>
			<content:encoded><![CDATA[<p>Perl中可以通过<a href="http://perldoc.perl.org/functions/fork.html" target="_blank">fork</a>函数来创建一个子进程。如果fork成功的话，这个时候就存在父进程和子进程，接下来2个进程会同时开始执行perl脚本中fork函数后面的代码。例子如下：</p>
<blockquote>
<div id="_mcePaste">#!/usr/local/bin/perl</div>
<div id="_mcePaste">use Term::ANSIColor;</div>
<div id="_mcePaste">use strict;</div>
<div id="_mcePaste">use warnings;</div>
<div id="_mcePaste"><strong>$SIG{CHLD} = 'IGNORE';</strong> <span style="color: #008000;">#忽略SIGCHLD信号,回收僵尸子进程</span></div>
<div>print color('green'),"Program started... pid = $$ \n\n";</div>
<div>print "fork process...\n";</div>
<div><span style="color: #008000;"># 如果fork失败，则返回undefined</span></div>
<div id="_mcePaste"><strong>defined ( my $child = <span style="color: #ff0000;">fork()</span> ) or die "Fork Error : $!\n" ;</strong></div>
<div id="_mcePaste"><span style="color: #008000;"># 如果fork成功:</span></div>
<div><span style="color: #008000;"># 如果是父进程，则把生成的子进程PID赋值给$child。</span></div>
<div><span style="color: #008000;"><span style="color: #000000;"><span style="color: #008000;"># 如果是子进程</span></span></span><span style="color: #008000;">，则把0赋值给$child。</span></div>
<div>if ($child == 0){</div>
<div id="_mcePaste">print color('yellow'),"\n-&gt; child process running ...\n";</div>
<div id="_mcePaste">print "child process pid : <strong>$$</strong> !\n";</div>
<div><span style="color: #008000;"># 退出子进程，如果前面没有对子进程处理的话，那么在父进程还没退出期间，子进程就变成</span><span style="color: #008000;">僵尸子进程。</span></div>
<div id="_mcePaste"><strong>exit 0;</strong></div>
<div id="_mcePaste">} else {</div>
<div id="_mcePaste">print color('blue'),"\n-&gt; parent process running ...\n";</div>
<div id="_mcePaste">print "child process pid : $child ; parent process pid : <strong>$$</strong> !\n",color('reset');</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">#sleep(10);</div>
<div id="_mcePaste">print "\nHello World!\n";</div>
</blockquote>
<p>执行结果如下：</p>
<p><span id="more-55699"></span></p>
<blockquote>
<p><span style="color: #888888;">[zhuxu@xentest8-vm1 my_perl_test]$ ./fork.pl</span></p>
<p><span style="color: #008000;">Program started... pid = <strong><em>30881</em></strong></span></p>
<p><span style="color: #008000;">fork process...</span></p>
<p><span style="color: #ff9900;"><span style="color: #ff9900;">-&gt; child process running ...</span></span></p>
<p><span style="color: #ff9900;"><span style="color: #ff9900;">child process pid : <strong><em>30882</em></strong> !</span></span></p>
<p><span style="color: #0000ff;">-&gt; parent process running ...</span></p>
<p><span style="color: #0000ff;">child process pid : <strong><em>30882</em></strong> ; parent process pid : <strong><em>30881</em></strong> !</span></p>
<p>Hello World!</p>
<p><span style="color: #888888;">[zhuxu@xentest8-vm1 my_perl_test]$</span></p>
</blockquote>
<p>【参考】：<a href="http://hi.baidu.com/yafeiie/blog/item/540112a87ab3d8bacb130cbc.html" target="_blank">Perl fork()</a></p>
<p>--EOF--</p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/perl_fork.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【MySQL】LOAD DATA</title>
		<link>http://chenxu.yo2.cn/articles/mysql_load-data.html</link>
		<comments>http://chenxu.yo2.cn/articles/mysql_load-data.html#comments</comments>
		<pubDate>Wed, 16 Mar 2011 16:51:13 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[LOAD DATA]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55697</guid>
		<description><![CDATA[在使用LOAD DATA到MySQL的时候，有2种情况： （1）在远程客户端（需要添加选项：--local-infile=1）导入远程客户端文本到MySQL，需指定LOCAL（默认就是ignore）,加ignore选项会放弃数据，加replace选项会更新数据，都不会出现唯一性约束问题。 （2）在本地服务器导入本地服务器文本到MySQL，不指定LOACL，出现唯一性约束冲突，会失败回滚，数据导入不进去，这个时候就需要加ignore或者replace来导入数据。 测试如下： （1）本地服务器导入本地服务器文本 mysql&#62; show create table tmp_loaddata\G; *************************** 1. row *************************** Table: tmp_loaddata Create Table: CREATE TABLE `tmp_loaddata` ( `id` int(11) NOT NULL, `name` varchar(10) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec) ERROR: No query specified mysql&#62; select * from tmp_loaddata; +----+------+ &#124; [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;">在使用<span lang="EN-US"><a style="color: blue; text-decoration: underline;" href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html">LOAD DATA</a></span>到<span lang="EN-US">MySQL</span>的时候，有<span lang="EN-US">2</span>种情况： </span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;">（<span lang="EN-US">1</span>）在远程客户端（需要添加选项：<strong><span style="color: red;" lang="EN-US">--local-infile=1</span></strong>）导入远程客户端文本到<span lang="EN-US">MySQL</span>，需指定<span lang="EN-US">LOCAL</span>（默认就是<span lang="EN-US">ignore</span>）<span lang="EN-US">,</span>加<span lang="EN-US">ignore</span>选项会放弃数据，加<span lang="EN-US">replace</span>选项会更新数据，都不会出现唯一性约束问题。 </span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;">（<span lang="EN-US">2</span>）在本地服务器导入本地服务器文本到<span lang="EN-US">MySQL</span>，不指定<span lang="EN-US">LOACL</span>，出现唯一性约束冲突，会失败回滚，数据导入不进去，这个时候就需要加<span lang="EN-US">ignore</span>或者<span lang="EN-US">replace</span>来导入数据。</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;">测试如下：</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;"><span id="more-55697"></span><br></span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><strong><span style="font-family: 幼圆;">（<span lang="EN-US">1</span>）本地服务器导入本地服务器文本</span></strong></p>
<blockquote>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt; show create table tmp_loaddata\G;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">*************************** 1. row ***************************</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">Table: tmp_loaddata</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">Create Table:</span> <span style="font-family: 幼圆;" lang="EN-US">CREATE TABLE `tmp_loaddata` (</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">`id` int(11) NOT NULL,</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">`name` varchar(10) DEFAULT NULL,</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US"><span style="color: red;">PRIMARY KEY (`id`)</span></span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">) ENGINE=InnoDB DEFAULT CHARSET=latin1</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">1 row in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">ERROR:</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">No query specified</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">| id | name |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | test |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">1 row in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">system cat /home/zhuxu/1.txt</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">1,new update</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">2,new update</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <strong><span style="font-family: 幼圆;" lang="EN-US">LOAD DATA INFILE '/home/zhuxu/1.txt' INTO TABLE tmp_loaddata FIELDS TERMINATED BY ',';</span></strong></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span> <span style="font-family: 幼圆; color: #00b050;">出现唯一性约束冲突，会失败回滚</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">| id | name |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | test |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">1 row in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <strong><span style="font-family: 幼圆;" lang="EN-US">LOAD DATA INFILE '/home/zhuxu/1.txt'&nbsp;<span style="color: red;">IGNORE</span> INTO TABLE tmp_loaddata FIELDS TERMINATED BY ',';</span></strong></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">Query OK,</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">1 row affected</span> <span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">(0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">Records: 2</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Deleted: 0</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Skipped: 1</span> <span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">Warnings: 0</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span> <span style="font-family: 幼圆; color: #00b050;">使用<span lang="EN-US">IGNORE</span>对于冲突的数据丢弃掉。</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">| id | name</span> <span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | test</span> <span style="font-family: 幼圆;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">2 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">2 rows in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <strong><span style="font-family: 幼圆;" lang="EN-US">LOAD DATA INFILE '/home/zhuxu/1.txt'&nbsp;<span style="color: red;">REPLACE</span> INTO TABLE tmp_loaddata FIELDS TERMINATED BY ',';</span></strong></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">Query OK,</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">3 rows affected</span> <span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">(0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">Records: 2</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Deleted: 1</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Skipped: 0</span> <span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">Warnings: 0</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span> <span style="font-family: 幼圆; color: #00b050;">使用<span lang="EN-US">REPLACE</span>对于冲突的数据进行更新。</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">| id | name</span> <span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">2 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #a6a6a6;" lang="EN-US">2 rows in set (0.00 sec)</span></p>
</blockquote>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><strong><span style="font-family: 幼圆;">（<span lang="EN-US">2</span>）远程客户端导入远程客户端文本</span></strong></p>
<blockquote>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">[zhuxu@xentest9-vm1 tmp]$</span> <span style="font-family: 幼圆;" lang="EN-US">mysql -uzhuxu -pzhuxu test -h10.254.5.151</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Welcome to the MySQL monitor.</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">Commands end with ; or \g.</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Your MySQL connection id is 15</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Server version: 5.1.47-log Source distribution</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">This software comes with ABSOLUTELY NO WARRANTY. This is free software,</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">and you are welcome to modify and redistribute it under the GPL v2 license</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">| id | name |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | test |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">1 row in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">system cat /tmp/2.txt</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">1,new update</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">2,new update</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">3,new update</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">LOAD DATA INFILE '/tmp/2.txt' INTO TABLE tmp_loaddata FIELDS TERMINATED BY ',';</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">ERROR 13 (HY000): Can't get stat of '/tmp/2.txt' (Errcode: 2)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span> <span style="font-family: 幼圆; color: #00b050;">由于数据库服务器没有对应的文本文件，所以报错。</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">LOAD DATA&nbsp;<span style="color: red;">LOCAL</span> INFILE '/tmp/2.txt' INTO TABLE tmp_loaddata FIELDS TERMINATED BY ',';</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">ERROR 1148 (42000): The used command is not allowed with this MySQL version</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span> <span style="font-family: 幼圆; color: #00b050;">进去<span lang="EN-US">mysql</span>远程客户端，还需要加<strong><span lang="EN-US">--local-infile=1</span></strong>参数指定。</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt; exit</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Bye</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">[zhuxu@xentest9-vm1 tmp]$</span> <span style="font-family: 幼圆;" lang="EN-US">mysql -uzhuxu -pzhuxu test -h10.254.5.151 <strong><span style="color: red;">--local-infile=1</span></strong> --show-warnings -v -v -v \</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">&gt; -e "LOAD DATA LOCAL INFILE '/tmp/2.txt' INTO TABLE tmp_loaddata FIELDS TERMINATED BY ','";</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">--------------</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">LOAD DATA LOCAL INFILE '/tmp/2.txt' INTO TABLE tmp_loaddata FIELDS TERMINATED BY ','</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">--------------</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Query OK,</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">2 rows affected</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">(0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">Records: 3</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Deleted: 0</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Skipped: 1</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">Warnings: 0</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Bye</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">| id | name</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | test</span> <span style="font-family: 幼圆;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">2 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">3 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">3 rows in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">[zhuxu@xentest9-vm1 tmp]$</span> <span style="font-family: 幼圆;" lang="EN-US">mysql -uzhuxu -pzhuxu test -h10.254.5.151&nbsp;<strong><span style="color: red;">--local-infile=1</span></strong> --show-warnings -v -v -v \</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">&gt; -e "LOAD DATA LOCAL INFILE '/tmp/2.txt'&nbsp;<span style="color: red;">IGNORE</span> INTO TABLE tmp_loaddata FIELDS TERMINATED BY ','";</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">--------------</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">LOAD DATA LOCAL INFILE '/tmp/2.txt' IGNORE INTO TABLE tmp_loaddata FIELDS TERMINATED BY ','</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">--------------</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Query OK,</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">0 rows affected</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">(0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">Records: 3</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Deleted: 0</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Skipped: 3</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">Warnings: 0</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Bye</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt;</span> <span style="font-family: 幼圆;" lang="EN-US">select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">| id | name</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">1 | test</span> <span style="font-family: 幼圆;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">2 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">|</span> <span style="font-family: 幼圆;" lang="EN-US">3 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">3 rows in set (0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: #00b050;" lang="EN-US">#</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">[zhuxu@xentest9-vm1 tmp]$</span> <span style="font-family: 幼圆;" lang="EN-US">mysql -uzhuxu -pzhuxu test -h10.254.5.151&nbsp;<strong><span style="color: red;">--local-infile=1</span></strong> --show-warnings -v -v -v \</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">&gt; -e "LOAD DATA LOCAL INFILE '/tmp/2.txt'&nbsp;<span style="color: red;">REPLACE</span> INTO TABLE tmp_loaddata FIELDS TERMINATED BY ','";</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">--------------</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">LOAD DATA LOCAL INFILE '/tmp/2.txt' REPLACE INTO TABLE tmp_loaddata FIELDS TERMINATED BY ','</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">--------------</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Query OK,</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">4 rows affected</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">(0.00 sec)</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">Records: 3</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Deleted: 1</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">Skipped: 0</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">Warnings: 0</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">Bye</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">mysql&gt; select * from tmp_loaddata;</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">| id | name</span> <span style="font-family: 幼圆; color: gray;" lang="EN-US">|</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">|</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">1 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">|</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">2 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: red;" lang="EN-US">|</span> <span style="font-family: 幼圆; color: red;" lang="EN-US">3 | new update |</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">+----+------------+</span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆; color: gray;" lang="EN-US">3 rows in set (0.00 sec)</span></p>
</blockquote>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US"><br></span></p>
<p style="margin-top: 0cm; margin-right: 0cm; margin-left: 0cm; margin-bottom: 0.0001pt; text-align: justify; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal;"><span style="font-family: 幼圆;" lang="EN-US">--EOF--</span></p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/mysql_load-data.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【MySQL】关于table cache的相关参数</title>
		<link>http://chenxu.yo2.cn/articles/mysql_table_cache.html</link>
		<comments>http://chenxu.yo2.cn/articles/mysql_table_cache.html#comments</comments>
		<pubDate>Tue, 15 Mar 2011 04:51:32 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[lsof]]></category>
		<category><![CDATA[Table Cache]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55695</guid>
		<description><![CDATA[一、状态值和变量： 1.1 在MySQL的show status中有2个状态值：Open_tables和Opened_tables。这2个值代表的意思如下： Open_tables&#160; ：代表当前打开表的数量。 Opened_tables：代表自从MySQL启动后，打开表的数量。 关于MySQL怎么打开关闭表的具体细节参考文档：&#60;How MySQL Opens and Closes Tables&#62;。 （1）对于myisam存储引擎，打开1张表需要2个文件描述符（一个.MYD文件，一个.MYI文件）。 （2）对于innodb存储引擎，开启表的独立表空间（innodb_file_per_table）打开1张表只需要1个文件描述符（一个.ibd文件）。 【MySQL Variable】 对于上面的状态值，对应的5.1.3版本后的MySQL变量参数为table_open_cache，而早期版本为：table_cache，该参数值的代表MySQL可以缓存的打开表时候的最大文件描述符。 1.2 在MySQL 5.1.3之后，还添加了2个状态值：Open_table_definitions和Opened_table_definitions。这2个值代表的意思如下： Open_table_definitions&#160; ：代表当前缓存了多少.frm文件。 Opened_table_definitions：代表自从MySQL启动后，缓存了.frm文件的数量。 需要注意的是.frm文件是MySQL用于存放表结构的文件，对应myisam和innodb存储引擎都必须有的。 【MySQL Variable】 对于上面的状态值，对应的5.1.3版本后的MySQL变量参数为table_definition_cache，该参数值的代表MySQL可以缓存的表定义的数量。和前面的table cache不同的是，表定义的缓存占用空间很小，而且不需要使用文件描述符，也就是只要打开.frm文件，缓存表定义，然后就可以关闭.frm文件。 1.3 另外，还有2个状态值：Open_files和Opened_files。这2个值的意思同上类似： Open_files&#160; ：代表当前打开的文件。对应存储引擎（如：innodb）使用存储引擎自己内部函数打开的话，这个值是不会增加的。 Opened_files：代表使用MySQL的my_open()函数打开过的文件数。如果不是使用这个函数打开文件的话，这个值是不会增加的。 【MySQL Variable】 对于上面的状态值，对应的MySQL变量参数为open_files_limit。 二、测试 测试的MySQL版本： mysql&#62; select version(); +------------+ &#124; version()&#160; &#124; +------------+ &#124; 5.1.47-log &#124; +------------+ 1 row in set [...]]]></description>
			<content:encoded><![CDATA[<p><strong>一、状态值和变量：</strong></p>
<p><strong>1.1</strong></p>
<p>在MySQL的show status中有2个状态值：<a href="http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Open_tables">Open_tables</a>和<a href="http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Opened_tables">Opened_tables</a>。这2个值代表的意思如下：</p>
<p>Open_tables&nbsp; ：代表当前打开表的数量。</p>
<p>Opened_tables：代表自从MySQL启动后，打开表的数量。</p>
<p>关于MySQL怎么打开关闭表的具体细节参考文档：&lt;<a href="http://dev.mysql.com/doc/refman/5.1/en/table-cache.html">How MySQL Opens and Closes Tables</a>&gt;。</p>
<p><span style="color: #ff0000;">（1）对于myisam存储引擎，打开1张表需要2个文件描述符（一个.MYD文件，一个.MYI文件）。</span></p>
<p><span style="color: #ff0000;">（2）对于innodb存储引擎，开启表的独立表空间（<a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-parameters.html#sysvar_innodb_file_per_table">innodb_file_per_table</a>）打开1张表只需要1个文件描述符（一个.ibd文件）。</span></p>
<p>【MySQL Variable】</p>
<p>对于上面的状态值，对应的5.1.3版本后的MySQL变量参数为<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_table_open_cache">table_open_cache</a>，而早期版本为：<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_table_cache">table_cache</a>，该参数值的代表MySQL可以缓存的打开表时候的最大<a href="http://en.wikipedia.org/wiki/File_descriptor">文件描述符</a>。</p>
<p><span id="more-55695"></span></p>
<p><strong>1.2</strong></p>
<p>在MySQL 5.1.3之后，还添加了2个状态值：<a href="http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Open_table_definitions">Open_table_definitions</a>和<a href="http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Opened_table_definitions">Opened_table_definitions</a>。这2个值代表的意思如下：</p>
<p>Open_table_definitions&nbsp; ：代表当前缓存了多少.frm文件。</p>
<p>Opened_table_definitions：代表自从MySQL启动后，缓存了.frm文件的数量。</p>
<p>需要注意的是.frm文件是MySQL用于存放表结构的文件，对应myisam和innodb存储引擎都必须有的。</p>
<p>【MySQL Variable】</p>
<p>对于上面的状态值，对应的5.1.3版本后的MySQL变量参数为<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_table_definition_cache">table_definition_cache</a>，该参数值的代表MySQL可以缓存的表定义的数量。<span style="color: #ff0000;">和前面的table cache不同的是，表定义的缓存占用空间很小，而且不需要使用文件描述符，也就是只要打开.frm文件，缓存表定义，然后就可以关闭.frm文件。</span></p>
<p><strong>1.3</strong></p>
<p>另外，还有2个状态值：<a href="http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Open_files">Open_files</a>和<a href="http://dev.mysql.com/doc/refman/5.1/en/server-status-variables.html#statvar_Opened_files">Opened_files</a>。这2个值的意思同上类似：</p>
<p>Open_files&nbsp; ：代表当前打开的文件。对应存储引擎（如：innodb）使用存储引擎自己内部函数打开的话，这个值是不会增加的。</p>
<p>Opened_files：代表使用MySQL的my_open()函数打开过的文件数。如果不是使用这个函数打开文件的话，这个值是不会增加的。</p>
<p>【MySQL Variable】</p>
<p>对于上面的状态值，对应的MySQL变量参数为<a href="http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html#sysvar_open_files_limit">open_files_limit</a>。</p>
<p><strong>二、测试</strong></p>
<p>测试的MySQL版本：</p>
<blockquote>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">select version();</span></span></p>
<p><span style="color: #999999;">+------------+</span></p>
<p><span style="color: #999999;">| version()&nbsp; |</span></p>
<p><span style="color: #999999;">+------------+</span></p>
<p><span style="color: #999999;">| <span style="color: #000000;">5.1.47-log</span> |</span></p>
<p><span style="color: #999999;">+------------+</span></p>
<p><span style="color: #999999;">1 row in set (0.00 sec)</span></p>
</blockquote>
<p><strong>2.1 myisam</strong><strong>存储引擎</strong></p>
<p><strong>2.1.1</strong></p>
<p>重启MySQL服务器，可以看到启动时候MySQL已经自动打开相关的系统表。</p>
<blockquote>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show global status like 'Open%_table_definitions';show global status like 'Open%_tables';show global status like 'Open%_files';</span> </span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value |</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #000000;">| Open_table_definitions&nbsp;&nbsp; | 15&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_table_definitions | 15&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name | Value |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_tables&nbsp;&nbsp; | 8&nbsp;&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_tables | 15&nbsp; &nbsp;&nbsp;|</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name | Value |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_files&nbsp;&nbsp;&nbsp; | 19&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_files&nbsp; | 62&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
</blockquote>
<p>在上面的状态输出，可以看到Open_tables的值为8，代表了当前打开了8张表，同样的通过mysqladmin status命令也可以看到：</p>
<blockquote>
<p><span style="color: #999999;">[mysql@xentest8-vm1 test]$ <span style="color: #000000;">mysqladmin status</span></span></p>
<p><span style="color: #999999;">Uptime: 631&nbsp; Threads: 2&nbsp; Questions: 14&nbsp; Slow queries: 0&nbsp; Opens: 15&nbsp; Flush tables: 1&nbsp; <span style="color: #000000;">Open tables: 8</span> Queries per second avg: 0.22</span></p>
</blockquote>
<p>可以通过<a href="http://dev.mysql.com/doc/refman/5.1/en/show-open-tables.html">SHOW OPEN TABLES</a>命令查看，当前的table cache到底打开了哪些表：</p>
<blockquote>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show open tables;</span></span></p>
<p><span style="color: #999999;">+----------+--------------+--------+-------------+</span></p>
<p><span style="color: #999999;">| Database | Table&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | In_use | Name_locked |</span></p>
<p><span style="color: #999999;">+----------+--------------+--------+-------------+</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | servers&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | db&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | host&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | columns_priv |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | user&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | procs_priv&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | event&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">| mysql&nbsp;&nbsp;&nbsp; | tables_priv&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">+----------+--------------+--------+-------------+</span></p>
<p><span style="color: #999999;"><span style="color: #000000;">8 rows in set</span> (0.00 sec)</span></p>
</blockquote>
<p>可以看到打开了mysql库里面的8张系统表（都是myisam存储引擎），另外，还可以通过lsof（lsof的用法参见&lt;<a href="http://www.ibm.com/developerworks/cn/aix/library/au-lsof.html">使用lsof查找打开的文件</a>&gt;）查看MySQL打开的对应文件：</p>
<blockquote>
<p><span style="color: #999999;">[zhuxu@xentest8-vm1 ~]$ <span style="color: #000000;">sudo lsof -u mysql | grep /home/mysql/mysql-5.1.47/data/<span style="color: #ff0000;">mysql</span>/</span></span></p>
<p><span style="color: #000000;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 16u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2048 87889757 /home/mysql/mysql-5.1.47/data/mysql/host.MYI</span></p>
<p><span style="color: #000000;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 17u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87889758 /home/mysql/mysql-5.1.47/data/mysql/host.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 18u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2048 87889760 /home/mysql/mysql-5.1.47/data/mysql/user.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 19u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 380 87889761 /home/mysql/mysql-5.1.47/data/mysql/user.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 20u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5120 87889754 /home/mysql/mysql-5.1.47/data/mysql/db.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 21u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 880 87889755 /home/mysql/mysql-5.1.47/data/mysql/db.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 22u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4096 87889772 /home/mysql/mysql-5.1.47/data/mysql/tables_priv.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 23u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87889773 /home/mysql/mysql-5.1.47/data/mysql/tables_priv.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 24u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4096 87889775 /home/mysql/mysql-5.1.47/data/mysql/columns_priv.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 25u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87889776 /home/mysql/mysql-5.1.47/data/mysql/columns_priv.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 26u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4096 87889808 /home/mysql/mysql-5.1.47/data/mysql/procs_priv.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 27u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87889809 /home/mysql/mysql-5.1.47/data/mysql/procs_priv.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 28u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1024 87889769 /home/mysql/mysql-5.1.47/data/mysql/servers.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 29u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87889770 /home/mysql/mysql-5.1.47/data/mysql/servers.MYD</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 30u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2048 87889817 /home/mysql/mysql-5.1.47/data/mysql/event.MYI</span></p>
<p><span style="color: #999999;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; 31u&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87889818 /home/mysql/mysql-5.1.47/data/mysql/event.MYD</span></p>
</blockquote>
<p><strong>2.1.2</strong></p>
<p>接着打开一张myisam存储引擎的表：</p>
<blockquote>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">select count(*) from myisam_1;</span></span></p>
<p><span style="color: #999999;">+----------+</span></p>
<p><span style="color: #999999;">| count(*) |</span></p>
<p><span style="color: #999999;">+----------+</span></p>
<p><span style="color: #999999;">|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">+----------+</span></p>
<p><span style="color: #999999;">1 row in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show global status like 'Open%_table_definitions';show global status like 'Open%_tables';show global status like 'Open%_files';</span></span></p>
<p><span style="color: #008000;"># 可以看到Opened_table_definitions/Opened_table_definitions/Open_tables/Opened_tables的值都加1</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value |</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #000000;">| Open_table_definitions&nbsp;&nbsp; | 16&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_table_definitions | 16&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name | Value |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_tables&nbsp;&nbsp; | 9&nbsp;&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_tables | 16&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #008000;"># 可以看到Open_files的值（19+2）加2，Opened_files的值（62+3）加3</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name | Value |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_files&nbsp;&nbsp;&nbsp; | 21&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_files&nbsp; | 65&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show create table myisam_1\G</span></span></p>
<p><span style="color: #999999;">*************************** 1. row ***************************</span></p>
<p><span style="color: #999999;">Table: myisam_1</span></p>
<p><span style="color: #000000;">Create Table: CREATE TABLE `myisam_1` (</span></p>
<p><span style="color: #000000;">`a` int(11) DEFAULT NULL,</span></p>
<p><span style="color: #000000;">KEY `idx_myisam_1` (`a`)</span></p>
<p><span style="color: #000000;">) ENGINE=MyISAM DEFAULT CHARSET=latin1</span></p>
<p><span style="color: #999999;">1 row in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show open tables from test;</span></span></p>
<p><span style="color: #999999;">+----------+----------+--------+-------------+</span></p>
<p><span style="color: #999999;">| Database | Table&nbsp;&nbsp;&nbsp; | In_use | Name_locked |</span></p>
<p><span style="color: #999999;">+----------+----------+--------+-------------+</span></p>
<p><span style="color: #000000;">| test&nbsp;&nbsp;&nbsp;&nbsp; | myisam_1 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #999999;">+----------+----------+--------+-------------+</span></p>
<p><span style="color: #999999;">1 row in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">[zhuxu@xentest8-vm1 ~]$ <span style="color: #000000;">sudo lsof -u mysql | grep /home/mysql/mysql-5.1.47/data/<span style="color: #ff0000;">test</span>/</span></span></p>
<p><span style="color: #000000;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp; <span style="color: #ff0000;">33u</span> REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1024 87851510 /home/mysql/mysql-5.1.47/data/test/myisam_1.MYI</span></p>
<p><span style="color: #000000;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; <span style="color: #ff0000;">34u</span> REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;253,1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 87851511 /home/mysql/mysql-5.1.47/data/test/myisam_1.MYD</span></p>
<p><span style="color: #008000;"># 可见，除了需要打开.frm文件（打开，缓存后，就关闭），对于myisam存储引擎，打开1张表需要2个文件描述符（一个.MYD文件，一个.MYI文件）</span></p>
</blockquote>
<p><strong>2.1.3</strong></p>
<p>对应table cache中的缓存的表，可以通过<a href="http://dev.mysql.com/doc/refman/5.1/en/flush.html">flush tables</a>命令来把它人工移出table cache:</p>
<blockquote>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">flush tables myisam_1;</span></span></p>
<p><span style="color: #999999;">Query OK, 0 rows affected (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show open tables from test;</span></span></p>
<p><span style="color: #999999;"><span style="color: #000000;">Empty set</span> (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">mysql&gt; <span style="color: #000000;">show global status like 'Open%_table_definitions';show global status like 'Open%_tables';show global status like 'Open%_files';</span></span></p>
<p><span style="color: #008000;"># 可以看到Open_table_definitions和Open_tables的值都减1</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value |</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #000000;">| Open_table_definitions&nbsp;&nbsp; | 15&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">| Opened_table_definitions | 16&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+--------------------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name | Value |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_tables&nbsp;&nbsp; | 8&nbsp;&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">| Opened_tables | 16&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #008000;"># 可以看到Open_files的值（21-2）减2</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">| Variable_name | Value |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_files&nbsp;&nbsp;&nbsp; | 19&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #999999;">| Opened_files&nbsp; | <span style="color: #000000;">65</span> |</span></p>
<p><span style="color: #999999;">+---------------+-------+</span></p>
<p><span style="color: #999999;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #999999;"><br></span></p>
<p><span style="color: #999999;">[zhuxu@xentest8-vm1 ~]$ <span style="color: #000000;">sudo lsof -u mysql | grep /home/mysql/mysql-5.1.47/data/test/ | wc -l</span></span></p>
<p><span style="color: #000000;">0</span></p>
</blockquote>
<p><strong>2.2 innodb</strong><strong>存储引擎</strong></p>
<p><strong>2.2.1</strong></p>
<p>打开一张innodb存储引擎的表：</p>
<blockquote>
<p><span style="color: #888888;">mysql&gt; <span style="color: #000000;">show variables like 'innodb_file_per_table';</span></span></p>
<p><span style="color: #888888;">+-----------------------+-------+</span></p>
<p><span style="color: #888888;">| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value |</span></p>
<p><span style="color: #888888;">+-----------------------+-------+</span></p>
<p><span style="color: #000000;">| innodb_file_per_table | ON&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #888888;">+-----------------------+-------+</span></p>
<p><span style="color: #888888;">1 row in set (0.00 sec)</span></p>
<p><span style="color: #888888;">mysql&gt; <span style="color: #000000;">select count(*) from t0001;</span></span></p>
<p><span style="color: #888888;">+----------+</span></p>
<p><span style="color: #888888;">| count(*) |</span></p>
<p><span style="color: #888888;">+----------+</span></p>
<p><span style="color: #888888;">|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 |</span></p>
<p><span style="color: #888888;">+----------+</span></p>
<p><span style="color: #888888;">1 row in set (0.01 sec)</span></p>
<p><span style="color: #888888;">mysql&gt; <span style="color: #000000;">show global status like 'Open%_table_definitions';show global status like 'Open%_tables';show global status like 'Open%_files';</span></span></p>
<p><span style="color: #008000;"># 可以看到Opened_table_definitions/Opened_table_definitions/Open_tables/Opened_tables的值都加1</span></p>
<p><span style="color: #888888;">+--------------------------+-------+</span></p>
<p><span style="color: #888888;">| Variable_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Value |</span></p>
<p><span style="color: #888888;">+--------------------------+-------+</span></p>
<p><span style="color: #000000;">| Open_table_definitions&nbsp;&nbsp; | 16&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_table_definitions | 17&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #888888;">+--------------------------+-------+</span></p>
<p><span style="color: #888888;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #888888;">+---------------+-------+</span></p>
<p><span style="color: #888888;">| Variable_name | Value |</span></p>
<p><span style="color: #888888;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_tables&nbsp;&nbsp; | 9&nbsp;&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_tables | 17&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #888888;">+---------------+-------+</span></p>
<p><span style="color: #888888;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #008000;"># 可以看到Open_files的值不变（即innodb使用存储引擎自己内部函数打开的话，这个值是不会增加）</span></p>
<p><span style="color: #008000;"># Opened_files的值（65+1）加1（需要打开.frm文件，缓存后，就关闭）</span></p>
<p><span style="color: #888888;">+---------------+-------+</span></p>
<p><span style="color: #888888;">| Variable_name | Value |</span></p>
<p><span style="color: #888888;">+---------------+-------+</span></p>
<p><span style="color: #000000;">| Open_files&nbsp;&nbsp;&nbsp; | 19&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #000000;">| Opened_files&nbsp; | 66&nbsp;&nbsp;&nbsp; |</span></p>
<p><span style="color: #888888;">+---------------+-------+</span></p>
<p><span style="color: #888888;">2 rows in set (0.00 sec)</span></p>
<p><span style="color: #888888;">mysql&gt; <span style="color: #000000;">show open tables from test;</span></span></p>
<p><span style="color: #888888;">+----------+-------+--------+-------------+</span></p>
<p><span style="color: #888888;">| Database | Table | In_use | Name_locked |</span></p>
<p><span style="color: #888888;">+----------+-------+--------+-------------+</span></p>
<p><span style="color: #000000;">| test&nbsp;&nbsp;&nbsp;&nbsp; | t0001 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 |</span></p>
<p><span style="color: #888888;">+----------+-------+--------+-------------+</span></p>
<p><span style="color: #888888;">1 row in set (0.00 sec)</span></p>
<p><span style="color: #888888;">mysql&gt; <span style="color: #000000;">show create table t0001\G</span></span></p>
<p><span style="color: #888888;">*************************** 1. row ***************************</span></p>
<p><span style="color: #888888;">Table: t0001</span></p>
<p><span style="color: #000000;">Create Table: CREATE TABLE `t0001` (</span></p>
<p><span style="color: #000000;">`a` int(11) DEFAULT NULL</span></p>
<p><span style="color: #000000;">) ENGINE=InnoDB DEFAULT CHARSET=latin1</span></p>
<p><span style="color: #888888;">1 row in set (0.00 sec)</span></p>
<p><span style="color: #888888;">[zhuxu@xentest8-vm1 ~]$ <span style="color: #000000;">sudo lsof -u mysql | grep /home/mysql/mysql-5.1.47/data/test/</span></span></p>
<p><span style="color: #000000;">mysqld&nbsp;&nbsp;&nbsp; 14683 mysql&nbsp;&nbsp; <span style="color: #ff0000;">33uW</span> REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 253,1&nbsp;&nbsp;&nbsp;&nbsp; 98304 87851074 /home/mysql/mysql-5.1.47/data/test/t0001.ibd</span></p>
</blockquote>
<p><strong>2.2.2</strong></p>
<p>对于innodb存储引擎，table cache对其影响其实不是很大，innodb有自己的数据字典，可以缓存相关表信息。</p>
<p>其他相关资料：</p>
<p>（1）在&lt;<a href="http://oreilly.com/catalog/9780596101718">High.Performance.MySQL</a>&gt;中的The InnoDB Data Dictionary（P280页）中描述：</p>
<p>InnoDB has its own per-table cache, variously called a table definition cache or data dictionary, which you cannot configure. When InnoDB opens a table, it adds a corresponding object to the data dictionary. Each table can take up 4 KB or more of memory (although much less space is required in MySQL 5.1). Tables are not removed from the data dictionary when they are closed.</p>
<p>The main performance issue—besides memory requirements—is opening and computing statistics for the tables, which is expensive because it requires a lot of I/O. In contrast to MyISAM, InnoDB doesn’t store statistics in the tables permanently; it recomputes them each time it starts. This operation is serialized by a global mutex in current versions of MySQL, so it can’t be done in parallel. If you have a lot of tables, your server can take hours to start and fully warm up, during which time it might not be doing much other than waiting for one I/O operation after another. We mention this to make sure you know about it, even though there’s nothing you can do to change it. It’s normally a problem only when you have many (thousands or tens of thousands) large tables, which cause the process to be I/O-bound.</p>
<p>If you use InnoDB’s innodb_file_per_table option (described later in “Configuring the tablespace” on page 291), there’s also a separate limit on the number of .ibd files InnoDB can keep open at any time. This is handled by the InnoDB storage engine, not the MySQL server, and is controlled by innodb_open_files. InnoDB doesn’t open files the same way MyISAM does: whereas MyISAM uses the table cache to hold file descriptors for open tables, in InnoDB there is no direct relationship between open tables and open files. InnoDB uses a single, global file descriptor for each .ibd file. If you can afford it, it’s best to set innodb_open_files large enough that the server can keep all .ibd files open simultaneously.</p>
<p>（2）&lt;<a href="http://www.mysqlperformanceblog.com/2009/11/18/how-innodb_open_files-affects-performance/">How innodb_open_files affects performance</a>&gt;</p>
<p>（3）&lt;<a href="http://www.mysqlperformanceblog.com/2008/12/14/show-open-tables-what-is-in-your-table-cache/">SHOW OPEN TABLES – what is in your table cache</a>&gt;里面有一句描述：</p>
<p>Note however if you’re starting MySQL Command line client without “-A” option it opens all tables in the active database to allow tab completion which can screw results.</p>
<p>在实际的测试中，对于5.0.67-log版本会出现上面的情况，对于5.1版本的测试，上面的现象是不存在。</p>
<p>--EOF--</p>
<p class="MsoNormal"></p>
<p class="MsoNormal"></p>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/mysql_table_cache.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>【Linux】free命令</title>
		<link>http://chenxu.yo2.cn/articles/free_buffers_cached.html</link>
		<comments>http://chenxu.yo2.cn/articles/free_buffers_cached.html#comments</comments>
		<pubDate>Thu, 10 Mar 2011 05:12:42 +0000</pubDate>
		<dc:creator>Orz DBA</dc:creator>
				<category><![CDATA[Linux & Unix]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://chenxu.yo2.cn/?p=55694</guid>
		<description><![CDATA[记录linux下，free命令的执行结果的意思： [zhuxu@xentest8-vm1 ~]$ free total &#160; &#160; &#160; used &#160; &#160; &#160; free &#160; &#160; shared &#160; &#160;buffers &#160; &#160; cached Mem: &#160; &#160; &#160; 4194304 &#160; &#160;4164812 &#160; &#160; &#160;29492 &#160; &#160; &#160; &#160; &#160;0 &#160; &#160; 248892 &#160; &#160;2148968 -/+ buffers/cache: &#160; &#160;1766952 &#160; &#160;2427352 Swap: &#160; &#160; &#160; 524280 &#160; &#160; 343820 [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">记录linux下，free命令的执行结果的意思：</div>
<blockquote>
<div id="_mcePaste"><span style="color: #c0c0c0;">[zhuxu@xentest8-vm1 ~]$</span> <strong>free</strong></div>
<div id="_mcePaste">total &nbsp; &nbsp; &nbsp; used &nbsp; &nbsp; &nbsp; free &nbsp; &nbsp; shared &nbsp; &nbsp;buffers &nbsp; &nbsp; cached</div>
<div id="_mcePaste">Mem: &nbsp; &nbsp; &nbsp; 4194304 &nbsp; &nbsp;4164812 &nbsp; &nbsp; &nbsp;29492 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; 248892 &nbsp; &nbsp;2148968</div>
<div id="_mcePaste">-/+ buffers/cache: &nbsp; &nbsp;1766952 &nbsp; &nbsp;2427352</div>
<div id="_mcePaste"><span style="color: #888888;">Swap: &nbsp; &nbsp; &nbsp; 524280 &nbsp; &nbsp; 343820 &nbsp; &nbsp; 180460</span></div>
</blockquote>
<div id="_mcePaste"><strong>（1）第一行（Mem）中，</strong></div>
<div id="_mcePaste">total：代表总的内存大小。</div>
<div id="_mcePaste">used ：代表已经使用的内存大小，其中buffers和cached的值已经包含在used里面。</div>
<div id="_mcePaste">free ：代表未分配使用的内存大小。</div>
<div id="_mcePaste"><span style="color: #008000;">其中：</span></div>
<div id="_mcePaste"><span style="color: #008000;">total = used + free = 4164812 + 29492 = 4194304</span></div>
<div id="_mcePaste"><span style="color: #008000;">这边的used可以理解为从操作系统层面使用的内存大小（包括缓存）。</span></div>
<div id="_mcePaste"><span id="more-55694"></span></div>
<div>shared ：代表共享的内存大小。</div>
<div id="_mcePaste">buffers：代表Buffer Cache使用内存的大小。</div>
<div id="_mcePaste">cached ：代表Page Cache使用内存的大小。</div>
<div id="_mcePaste"><span style="color: #008000;">其中：</span></div>
<div id="_mcePaste"><span style="color: #008000;">Buffer Cache和Page Cache都是为了操作系统为了提高磁盘读取的速度，进行的缓存，是可以释放使用的内存。</span></div>
<div id="_mcePaste"><span style="color: #008000;">二者区别（来自<a href="http://www.penglixun.com/tech/system/buffer_and_cache_diff.html" target="_blank">http://www.penglixun.com/tech/system/buffer_and_cache_diff.html</a>）：</span></div>
<div id="_mcePaste"><span style="color: #008000;">Buffer Cache以块形式缓冲了块设备的操作，定时或手动的同步到硬盘，它是为了缓冲写操作然后一次性将很多改动写入硬盘，避免频繁写硬盘，提高写入效率。</span></div>
<div id="_mcePaste"><span style="color: #008000;">Page Cache以页面形式缓存了文件系统的文件，给需要使用的程序读取，它是为了给读操作提供缓冲，避免频繁读硬盘，提高读取效率。</span></div>
<div id="_mcePaste"><strong>（2）第二行（-/+ buffers/cache）中，</strong></div>
<div id="_mcePaste">used：即 - buffers/cache 的内存大小：used（第一行） –buffers –cached = 4164812 - 248892 - 2148968 = 1766952</div>
<div id="_mcePaste">free：即 + buffers/cache 的内存大小: free（第一行） + buffers + cached = 29492 + 248892 + 2148968 = 2427352</div>
<div id="_mcePaste"><span style="color: #008000;">其中：</span></div>
<div id="_mcePaste"><span style="color: #008000;">这边的used可以理解为应用程序使用的内存大小（不包括缓存）。</span></div>
<div id="_mcePaste"><span style="color: #008000;">这边的free也就是真正的可以使用的剩余内存大小。</span></div>
<div>另外，可以通过watch命令来动态的显示，下面每0.5s执行一次free命令，并高亮显示变化的地方：</div>
<blockquote>
<div><span style="color: #c0c0c0;">[zhuxu@dbadb1 ~]$</span> <strong>watch --help</strong></div>
<div><span style="color: #c0c0c0;">Usage: watch [-dhntv] [--differences[=cumulative]] [--help] [--interval=&lt;n&gt;] [--no-title] [--version] &lt;command&gt;</span></div>
<div><span style="color: #c0c0c0;"><span style="color: #000000;">-d, --differences[=cumulative] &nbsp; &nbsp; &nbsp; &nbsp;highlight changes between updates</span></span></div>
<div><span style="color: #c0c0c0;">(cumulative means highlighting is cumulative)</span></div>
<div><span style="color: #c0c0c0;">-h, --help &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print a summary of the options</span></div>
<div><span style="color: #c0c0c0;"><span style="color: #000000;">-n, --interval=&lt;seconds&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;seconds to wait between updates</span></span></div>
<div><span style="color: #c0c0c0;">-v, --version &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print the version number</span></div>
<div><span style="color: #c0c0c0;">-t, --no-title &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;turns off showing the header</span></div>
<div><span style="color: #c0c0c0;">[zhuxu@dbadb1 ~]$</span></div>
<div><span style="color: #c0c0c0;">[zhuxu@dbadb1 ~]$</span> <strong><span style="color: #ff0000;">watch -d -n 0.5 free</span></strong></div>
</blockquote>
<div>--</div>
]]></content:encoded>
			<wfw:commentRss>http://chenxu.yo2.cn/articles/free_buffers_cached.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

