php - 使用 MySQL 和 Redis 处理大数据

标签 php mysql apache redis centos

我需要数据库专家的帮助。

我有一个大数据库,在 MySQL 中导出为 SQL 文件时超过 1.5 GB。

我现在面临的问题是,对包含数百万数据的统计表等表的查询只会使服务器崩溃。

我现在正在考虑一些解决方案,我倾向于使用 Redis 实现大型表,然后让 Redis 和 MySQL 一起工作。我认为我应该保留 MySQL,因为它设置了很多复杂的关系,特别是在定义权限和访问控制列表时。另外,我不确定 Redis 是否可以安全地存储支付等敏感数据。

这是解决问题的最佳方法吗?

我听说 MySQL 分片的替代方案是它对于性能提升非常有效。

遇到这种情况你会怎么做?

更新 - 这是我从 MySQLTuner 获得的内容:

-------- Performance Metrics -------------------------------------------------
[--] Up for: 9d 1h 9m 33s (98M q [126.517 qps], 2M conn, TX: 354B, RX: 15B)
[--] Reads / Writes: 82% / 18%
[--] Total buffers: 232.0M global + 2.8M per thread (151 max threads)
[OK] Maximum possible memory usage: 647.2M (10% of installed RAM)
[OK] Slow queries: 0% (876/98M)
[!!] Highest connection usage: 100%  (152/151)
[OK] Key buffer size / total MyISAM indexes: 8.0M/294.2M
[OK] Key buffer hit rate: 100.0% (148B cached / 2M reads)
[OK] Query cache efficiency: 81.0% (64M cached / 79M selects)
[!!] Query cache prunes per day: 36845
[OK] Sorts requiring temporary tables: 0% (27 temp sorts / 7M sorts)
[!!] Joins performed without indexes: 8358004
[!!] Temporary tables created on disk: 44% (8M on disk / 18M total)
[!!] Thread cache is disabled
[!!] Table cache hit rate: 0% (400 open / 266K opened)
[OK] Open file limit used: 38% (398/1K)
[OK] Table locks acquired immediately: 99% (42M immediate / 42M locks)
[OK] InnoDB data size / buffer pool: 67.8M/128.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    Enable the slow query log to troubleshoot bad queries
    Reduce or eliminate persistent connections to reduce connection usage
    Adjust your join queries to always utilize indexes
    When making adjustments, make tmp_table_size/max_heap_table_size equal
    Reduce your SELECT DISTINCT queries without LIMIT clauses
    Set thread_cache_size to 4 as a starting value
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    max_connections (> 151)
    wait_timeout (< 28800)
    interactive_timeout (< 28800)
    query_cache_size (> 64M)
    join_buffer_size (> 128.0K, or always use indexes with joins)
    tmp_table_size (> 16M)
    max_heap_table_size (> 16M)
    thread_cache_size (start at 4)
    table_cache (> 400)

最佳答案

没有通用限制,但 1.5GB 甚至不应该被视为大数据。您没有提供 TPS(每秒事务数)数量,这可能表明您的工作负载。

但是,切换到非关系型解决方案会比尝试优化 RDBMS 带来更多问题。所以,你应该问自己:

  • 哪些查询会破坏服务器?
  • 您的查询使用了良好的索引吗?
  • 您的长时间运行查询是否会锁定表?
  • 您的服务器配置良好吗?您是否将 innodb_buffer_pool_size 设置为使用 80% 的可用内存? 看看 Percona 的这些幻灯片:http://www.percona.com/files/presentations/WEBINAR2012-03-Optimizing-MySQL-Configuration.pdf
  • 您是否使用了导致系统变慢的东西?例如,当你需要良好的性能时,SELinux 就很糟糕。

如果所有答案都是"is",则考虑使用其他解决方案:

  • 升级硬件(按重要性顺序:更多 RAM、更快磁盘、更多具有快速总线的 CPU)
  • MySQL 分区
  • XtraDB 集群,来自 Percona
  • Shard Query 存储引擎,可实现一些分片和负载平衡

关于php - 使用 MySQL 和 Redis 处理大数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16695567/

相关文章:

javascript - 按下按钮时从 sql &php 获取行内容,即使调用 id

apache - 如何获得编辑apache2.conf文件的权限? [Ubuntu]

apache - httpd 使用 SSL 和子域/虚拟主机重定向

javascript - 在重复表单上使用 jQUERY,随后增加 ID

php - 为什么 jQuery 使用 UTF-16 进行 POSTing?

php - 更改文本 woocommerce minicart 按钮

当一个值存在于一个表中时,mysql连接两个表

php - 运行复杂的多表mysql查询时出现问题

php - 如何在文件夹中托管 Laravel 项目

php - 跳过值以防空