博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL 查询大表注意事项
阅读量:2498 次
发布时间:2019-05-11

本文共 919 字,大约阅读时间需要 3 分钟。

在执行查询时,Mysql默认把结果全部load到内存后再返回(这种模式可理解为Oracle的ALL_ROWS优化模式),如果表数据量太大的话,会导致内存溢出。

1、mysql console连接数据库时:

  加入-q选项,mysql -h hostname -u root -p -q

2、jdbc连接数据库时:

在连接串中加入useCursorFetch=true

在创建的语句中,加入setFetchSize,如

stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);

stmt.setFetchSize(Integer.MIN_VALUE);

注意:

The Integer.MIN_VALUE is used by the MySQL driver as a signal to switch to streaming result set mode. It is not used as a value.

See the documentation, under "Resultset".In summary:

By default, ResultSets are completely

retrieved and stored in memory. You can tell the driver to stream the

results back one row at a time by setting

stmt.setFetchSize(Integer.MIN_VALUE); (in combination with a

forward-only, read-only result set).

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/6906/viewspace-2374933/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/6906/viewspace-2374933/

你可能感兴趣的文章
openstack报错解决二
查看>>
linux source命令
查看>>
openstack报错解决三
查看>>
乙未年年终总结
查看>>
子网掩码
查看>>
第一天上班没精神
查看>>
启动eclipse报错:Failed to load the JNI shared library
查看>>
eclipse安装插件的两种方式在线和离线
查看>>
linux下源的相关笔记(suse)
查看>>
linux系统分区文件系统划分札记
查看>>
Linux(SUSE 12)安装Tomcat
查看>>
Linux(SUSE 12)安装jboss4并实现远程访问
查看>>
Neutron在给虚拟机分配网络时,底层是如何实现的?
查看>>
netfilter/iptables全攻略
查看>>
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>
在eclipse上用tomcat部署项目404解决方案
查看>>
web.xml 配置中classpath: 与classpath*:的区别
查看>>
suse如何修改ssh端口为2222?
查看>>
详细理解“>/dev/null 2>&1”
查看>>