设为首页 加入收藏

TOP

MySQL数据库优化(三)
2015-07-24 10:19:50 来源: 作者: 【 】 浏览:3
Tags:MySQL 数据库 优化
至于memory,哈哈,还是比较好用的。在批处理种作临时表是个不错的选择(如果内存够大)。在我的一个批处理中,速度比近乎1:10。

?

 三、数据库参数配置

数据库是基于OS的,目前大多数MySQL都是安装在Linux系统之上的,所以对于OS的一些参数配置也会影响MySQL的性能。

\

\

最重要的参数就是内存,我们主要用的innodb引擎,所以下面两个参数调的很大

  # Additional memory pool that is used by InnoDB to store metadata

  # information. If InnoDB requires more memory for this purpose it will

  # start to allocate it from the OS. As this is fast enough on most

  # recent operating systems, you normally do not need to change this

  # value. SHOW INNODB STATUS will display the current amount used.

  innodb_additional_mem_pool_size = 64M

  # InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and

  # row data. The bigger you set this the less disk I/O is needed to

  # access data in tables. On a dedicated database server you may set this

  # parameter up to 80% of the machine physical memory size. Do not set it

  # too large, though, because competition of the physical memory may

  # cause paging in the operating system. Note that on 32bit systems you

  # might be limited to 2-3.5G of user level memory per process, so do not

  # set it too high.

  innodb_buffer_pool_size = 5G

  对于myisam,需要调整key_buffer_size

  当然调整参数还是要看状态,用show status语句可以看到当前状态,以决定改调整哪些参数

  Cretated_tmp_disk_tables 增加tmp_table_size

  Handler_read_key 高表示索引正确 Handler_read_rnd高表示索引不正确

  Key_reads/Key_read_requests 应小于0.01 计算缓存损失率,增加Key_buffer_size

  Opentables/Open_tables 增加table_cache

  select_full_join 没有实用索引的链接的数量。如果不为0,应该检查索引。

  select_range_check 如果不为0,该检查表索引。

  sort_merge_passes 排序算法已经执行的合并的数量。如果该值较大,应增加sort_buffer_size

  table_locks_waited 不能立即获得的表的锁的次数,如果该值较高,应优化查询

  Threads_created 创建用来处理连接的线程数。如果Threads_created较大,要增加 thread_cache_size值。

  缓存访问率的计算方法Threads_created/Connections。

 

四、合理的硬件资源和操作系统

  如果你的机器内存超过4G,那么毋庸置疑应当采用64位操作系统和64位mysql,成本高效果不明显。

  读写分离

  如果数据库压力很大,一台机器支撑不了,那么可以用mysql复制实现多台机器同步,将数据库的压力分散。  

\

  Master

  Slave1

  Slave2

  Slave3

   主库master用来写入,slave1—slave3都用来做select,每个数据库分担的压力小了很多。

   要实现这种方式,需要程序特别设计,写都操作master,读都操作slave,给程序开发带来了额外负担。当然目前已经有中间件来实现这个代理,对程 序来读写哪些数据库是透明的。官方有个mysql-proxy,但是还是alpha版本的。新浪有个amobe for mysql,也可达到这个目的,结构如下  

\

  使用方法可以看amobe的手册。


首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇mysql5.5.17源码安装 下一篇MySQL数据库管理(二)单机环境下..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C/C++ 类模板与模板 (2025-12-27 01:49:52)
·C语言 模板化<templ (2025-12-27 01:49:49)
·C/C++模板类模板与函 (2025-12-27 01:49:46)
·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)