VPS侦探论坛

 找回密码
 注册
查看: 3240|回复: 5

MySQL 经常连接不上,应该怎么优化

[复制链接]
发表于 2021-3-9 11:41:17 | 显示全部楼层 |阅读模式

MySQL 经常连接不上,每次重启MySQL才可以,/etc/my.cnf 应该怎么优化

服务器配置:

CPU:intel xeon E5-2420(两个)
内存:16G (4*4)
硬盘:600GB SAS (3个 300GB  RAID 5)

MySQL 8.0.20

美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2021-3-9 20:19:18 | 显示全部楼层


配置文件都是自动优化过了的
看一下mysql日志和系统日志中mysql停止工作时间的日志
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2021-3-11 09:26:42 | 显示全部楼层

licess 发表于 2021-3-9 20:19
配置文件都是自动优化过了的
看一下mysql日志和系统日志中mysql停止工作时间的日志 ...

mysqli::real_connect(): (08004/1040): Too many connections

max_connections=1000
还需要加大码?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2021-3-11 09:53:37 | 显示全部楼层



  1. [client]
  2. #password   = your_password
  3. port        = 3306
  4. socket      = /tmp/mysql.sock

  5. [mysqld]
  6. port        = 3306
  7. socket      = /tmp/mysql.sock
  8. datadir = /home/mysql
  9. skip-external-locking
  10. key_buffer_size = 256M
  11. max_allowed_packet = 1M
  12. table_open_cache = 1024
  13. sort_buffer_size = 4M
  14. net_buffer_length = 8K
  15. read_buffer_size = 4M
  16. read_rnd_buffer_size = 512K
  17. myisam_sort_buffer_size = 64M
  18. thread_cache_size = 128
  19. tmp_table_size = 128M
  20. performance_schema_max_table_instances = 6000

  21. explicit_defaults_for_timestamp = true
  22. #skip-networking
  23. max_connections = 1000
  24. max_connect_errors = 100
  25. open_files_limit = 65535
  26. default_authentication_plugin = mysql_native_password

  27. wait_timeout = 60
  28. interactive_timeout = 60

  29. log-bin=mysql-bin
  30. binlog_format=mixed
  31. server-id   = 1
  32. binlog_expire_logs_seconds = 864000
  33. early-plugin-load = ""

  34. default_storage_engine = InnoDB
  35. innodb_file_per_table = 1
  36. innodb_data_home_dir = /home/mysql
  37. innodb_data_file_path = ibdata1:10M:autoextend
  38. innodb_log_group_home_dir = /home/mysql
  39. innodb_buffer_pool_size = 1024M
  40. innodb_log_file_size = 256M
  41. innodb_log_buffer_size = 8M
  42. innodb_flush_log_at_trx_commit = 1
  43. innodb_lock_wait_timeout = 50

  44. sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

  45. [mysqldump]
  46. quick
  47. max_allowed_packet = 16M

  48. [mysql]
  49. no-auto-rehash

  50. [myisamchk]
  51. key_buffer_size = 256M
  52. sort_buffer_size = 4M
  53. read_buffer_size = 4M
  54. write_buffer_size = 2M

  55. [mysqlhotcopy]
  56. interactive-timeout

  57. [mysqld_safe]
  58. malloc-lib=/usr/lib/libjemalloc.so
复制代码
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2021-3-11 12:38:42 | 显示全部楼层

可以增大试试,日志里什么内容?

军哥运维代购:http://shop63846532.taobao.com/

发表于 2021-3-12 14:19:38 | 显示全部楼层

licess 发表于 2021-3-11 12:38
可以增大试试,日志里什么内容?

mysql远程连接慢,就是使用工具连接Mysql比较慢,有什么优化方案吗?????
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-8 08:41 , Processed in 0.027010 second(s), 17 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表