linux系统是CentOS-5.6,mysql的my.cnf配置文件如下:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
lower_case_table_names=1
query_cache_size=32M
#Query cache type to use.
query_cache_type=2
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 2
max_connections = 100
lower_case_table_names=1
#skip-networking
innodb_log_buffer_size=3M
innodb_buffer_pool_size=64M
innodb_log_file_size=16M
innodb_flush_log_at_trx_commit=1
innodb_additional_mem_pool_size=2M
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0#Set the default character set.
default-character-set=utf8[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
测试的sql语句:
select sql_cache id,name,type from yl_npc;
测试的java程序代码片段:/**
* 查询缓存测试
*/
public void queryCacheTest() {
Connection conn = null;
PreparedStatement prepar = null;
ResultSet result = null;
String sql = "select sql_cache id,name,type from yl_npc";
try {
conn = openConnect();
prepar = conn.prepareStatement(sql);
result = prepar.executeQuery();
while (result.next()) {
System.out.println("id:"+result.getInt("id")+",name:"+result.getString("name"));
}
} catch (Exception e) {
e.printStackTrace();
log.error("",e);
} finally {
closeConnect(result, null, prepar, conn);
}
}
问题是:
在终端里多次执行上面的sql语句,查询是Qcache_hits 是可以命中的,同样的sql语句,但不知道为什么在应用程序里就命中不了。而且在window系统下就不会有这问题,只有在linux下才命中不了,很困惑
淡痛啊,百思不解,请教各位大牛帮忙,小弟谢谢了。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
lower_case_table_names=1
query_cache_size=32M
#Query cache type to use.
query_cache_type=2
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 2
max_connections = 100
lower_case_table_names=1
#skip-networking
innodb_log_buffer_size=3M
innodb_buffer_pool_size=64M
innodb_log_file_size=16M
innodb_flush_log_at_trx_commit=1
innodb_additional_mem_pool_size=2M
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0#Set the default character set.
default-character-set=utf8[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
测试的sql语句:
select sql_cache id,name,type from yl_npc;
测试的java程序代码片段:/**
* 查询缓存测试
*/
public void queryCacheTest() {
Connection conn = null;
PreparedStatement prepar = null;
ResultSet result = null;
String sql = "select sql_cache id,name,type from yl_npc";
try {
conn = openConnect();
prepar = conn.prepareStatement(sql);
result = prepar.executeQuery();
while (result.next()) {
System.out.println("id:"+result.getInt("id")+",name:"+result.getString("name"));
}
} catch (Exception e) {
e.printStackTrace();
log.error("",e);
} finally {
closeConnect(result, null, prepar, conn);
}
}
问题是:
在终端里多次执行上面的sql语句,查询是Qcache_hits 是可以命中的,同样的sql语句,但不知道为什么在应用程序里就命中不了。而且在window系统下就不会有这问题,只有在linux下才命中不了,很困惑
淡痛啊,百思不解,请教各位大牛帮忙,小弟谢谢了。
解决方案 »
- mysql查询统计的问题,请大家帮我看看,谢谢
- sql explain语句
- 急急急!!请问references sort(id) on delete cascade 产生了错误,要怎么解决?
- MySql如何按时间段来分组
- mysql如何同时分组查询两个表
- 询问取某个字段小数点后面超过3位的字段值的sql
- 请教一句SQL语句
- mysql中文乱码,解决马上给分
- 把mysql的data目录下的数据库文件拷贝到另一台机器的mysql的data目录下,为什么myisam的表可以用,innoDB却出错?
- 能否在同一台机器起动 两个mysql 服务
- Mysql查询三张表中指定列的数据~在线等。。
- mysql 查询 延时
mysql> show variables like '%cache%';
+------------------------------+------------+
| Variable_name | Value |
+------------------------------+------------+
| bdb_cache_size | 8384512 |
| binlog_cache_size | 32768 |
| have_query_cache | YES |
| key_cache_age_threshold | 300 |
| key_cache_block_size | 1024 |
| key_cache_division_limit | 100 |
| max_binlog_cache_size | 4294963200 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 33554432 |
| query_cache_type | DEMAND |
| query_cache_wlock_invalidate | OFF |
| table_cache | 64 |
| thread_cache_size | 0 |
+------------------------------+------------+
14 rows in set (0.00 sec)就是系统不同啊,一个window,一个linux;不过应该不关系统的事。
就是不明白同样的sql语句,为什么在终端可以命中,而在java应用程序里却命中不了,
在WINDOWS下可以命中,LINUX下不能,是这样?
连接字串是什么
DRIVER_CLASS = com.mysql.jdbc.Driver
URL = jdbc\:mysql\://127.0.0.1\:3306/pgameUSER = root
PASS_WORD = 123456 MAX_STATEMENTS = 0
CHECKOUT_TIMEOUT = 0
CONNECTION_TEST_PERIOD = 60
INIT_POOL_SIZE = 10
MAX_IDLE_TIME = 60
MAX_POOL_SIZE = 100
MinPoolSize=3
window下有mysql,linux下也有mysql,相同的java程序。
出现的情况是:
在window下是没有问题,不管是在程序,还是在控制台都可以命中。
而在linux下,只有在终端才能命中,而在程序就命中不了。
判断命中,我是通过这个:SHOW STATUS LIKE ’Qcache_hits’;
以做对比。
mysql> show variables like '%cache%';
+------------------------------+------------+
| Variable_name | Value |
+------------------------------+------------+
| binlog_cache_size | 32768 |
| have_query_cache | YES |
| key_cache_age_threshold | 300 |
| key_cache_block_size | 1024 |
| key_cache_division_limit | 100 |
| max_binlog_cache_size | 4294963200 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 268435456 |
| query_cache_type | DEMAND |
| query_cache_wlock_invalidate | OFF |
| table_definition_cache | 256 |
| table_open_cache | 256 |
| thread_cache_size | 8 |
+------------------------------+------------+
14 rows in set (0.00 sec)Linux:
mysql> show variables like '%cache%';
+------------------------------+------------+
| Variable_name | Value |
+------------------------------+------------+
| bdb_cache_size | 8384512 |
| binlog_cache_size | 32768 |
| have_query_cache | YES |
| key_cache_age_threshold | 300 |
| key_cache_block_size | 1024 |
| key_cache_division_limit | 100 |
| max_binlog_cache_size | 4294963200 |
| query_cache_limit | 1048576 |
| query_cache_min_res_unit | 4096 |
| query_cache_size | 33554432 |
| query_cache_type | DEMAND |
| query_cache_wlock_invalidate | OFF |
| table_cache | 64 |
| thread_cache_size | 0 |
+------------------------------+------------+
14 rows in set (0.00 sec)
是啊,用的是c3p0的连接池。
window下有mysql,linux下也有mysql,相同的java程序。
出现的情况是:
在window下是没有问题,不管是在程序,还是在控制台都可以命中。
而在linux下,只有在终端才能命中,而在程序就命中不了。还有一点不同的就是window下的mysql是5.1,linux下的mysql是5.0;
后来我把linux下的mysql升级到5.1,就没有问题了。
只是不明白为什么mysql5.0只有在linux终端才能命中,而在程序就命中不了。
其他的有没有不同。
这些都不重要了,把linux下的mysql升级到5.1之后就没问题了。
5.0的只有在终端才能命中,而在程序就命中不了,可能是字符集不一样吧。