JAVA技术交流QQ群:170933152

1.出现这个问题以后,重启Centos7 都不行,启动了还是报错

2.解决方案:

错误信息如下:
Can not connect to MySQL server

Error: Too many connections
Errno.: 1040

Similar error report has beed dispatched to administrator before.

从官方文档知道Linux上面编译安装的mysql默认的连接为100个
文档:http://dev.mysql.com/doc/refman/5.0/en/too-many-connections.html

mysql官方告诉我们需要修改max_connections的值,那么我们怎么去修改呢?有两种方法
1、修改配置文件文件
修改/etc/my.cnf这个文件,在[mysqld] 中新增max_connections=N,如果你没有这个文件请从编译源码中的support-files文件夹中复制你所需要的*.cnf文件为到 /etc/my.cnf。我使用的是my-medium.cnf,中型服务器配置。例如我的[mysqld]的内容如下
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 160M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
max_connections=1000 //注意就是加上这个,还是不行

wait_timeout=5//再加上这个,这个文件中有可能,没有这两个值,再后边添加上就行了,注意

要添加到:[mysqld]这个部分

然后重新进一下:
[root@localhost etc]# mysql -u root -p
Enter password: 
ERROR 1040 (HY000): Too many connections

上面如果配置了那个文件,就应该可以进去了

然后再根据下面,去设置一下就可以了:

最近写javaee项目的时候,mysql报了too many connections的错误,百度的内容有一些有问题,所以我重新写一下我的解决方法。

  1. mysql -u root -p 回车输入密码进入mysql 

  2. show processlist; 
    查看连接数,可以发现有很多连接处于sleep状态,这些其实是暂时没有用的,所以可以kill掉

  3. show variables like "max_connections"; 
    查看最大连接数,应该是与上面查询到的连接数相同,才会出现too many connections的情况

  4. set GLOBAL max_connections=1000; 
    修改最大连接数,但是这不是一劳永逸的方法,应该要让它自动杀死那些sleep的进程。

  5. show global variables like 'wait_timeout'; 
    这个数值指的是mysql在关闭一个非交互的连接之前要等待的秒数,默认是28800s

  6. set global wait_timeout=300; 
    修改这个数值,这里可以随意,最好控制在几分钟内 

  7. set global interactive_timeout=500; 
    修改这个数值,表示mysql在关闭一个连接之前要等待的秒数,至此可以让mysql自动关闭那些没用的连接,但要注意的是,正在使用的连接到了时间也会被关闭,因此这个时间值要合适

  8. 批量kill之前没用的sleep连接,在网上搜索的方法对我都不奏效,因此只好使用最笨的办法,一个一个kill

    • select concat('KILL ',id,';') from information_schema.processlist where user='root'; 先把要kill的连接id都查询出来
    • 复制中间的kill id;内容到word文档
    • 替换掉符号“|”和回车符(在word中查询^p即可查询到回车符)
    • 把修改过的内容复制回终端,最后按回车执行!

[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# systemctl restart mysqld.service
[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 530
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show processlist
    -> ;
+-----+------+---------------------+------+---------+------+-------+------------------+
| Id  | User | Host                | db   | Command | Time | State | Info             |
+-----+------+---------------------+------+---------+------+-------+------------------+
| 530 | root | localhost           | NULL | Query   |    0 | init  | show processlist |
| 536 | root | 172.19.128.67:56319 | NULL | Sleep   |   30 |       | NULL             |
| 537 | root | 172.19.128.67:56320 | dbo  | Sleep   |   25 |       | NULL             |
+-----+------+---------------------+------+---------+------+-------+------------------+
3 rows in set (0.00 sec)

mysql> show variables like "max_connections"
    -> ;
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 214   |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> set GLOBAL max_connections=1000;
Query OK, 0 rows affected (0.00 sec)

mysql> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 5     |
+---------------+-------+
1 row in set (0.01 sec)

mysql> set gloabl interactive_timeout =500
    -> ;
ERROR 1193 (HY000): Unknown system variable 'gloabl'
mysql> set global interactive_timeout = 500;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@localhost ~]#

Linux学习笔记021---Centos7 下 MySql too many connections 报错相关推荐

  1. centos 7 mysql 中文,解决centOS7 下mysql插入中文字符报错相关问题

    解决centOS7 下mysql插入中文字符报错相关问题 在刚装完mysql,就建立了数据库abc,然后新建一个abc表,插入英文没有问题,但是插入中文就有问题,会报错: ERROR 1366 (HY ...

  2. 学习笔记(1)centos7 下安装nginx

    学习笔记(1)centos7 下安装nginx 这里我是通过来自nginx.org的nginx软件包进行安装的. 1.首先为centos设置添加nginx的yum存储库 1.通过vi命令创建一个rep ...

  3. 学习笔记(2)centos7 下安装mysql

    centos7安装mysql 本文通过yum方式安装mysql 1.添加mysql yum 仓库 去mysql开发者中心(http://dev.mysql.com/downloads/repo/yum ...

  4. Linux学习笔记之CentOS7学习(一)

    CentOS7学习笔记(一):基础知识 学习Linux版本CentOS-7-x86_64-Minimal-1804.iso,目前比较新的一个版本. VMware安装镜像文件,设置网络连接方式为桥接模式 ...

  5. 【Linux学习】虚拟机VMware 安装ROS 一条龙教程+部分报错解决

    前言 Linux下安装ROS真是太多坑了,如何在Linux下安装ROS呢?博主带你少走弯路! 目录 前言 第一步:配置软件源 1.打开设置 2.打开软件与更新 3.选源 第二步:设置sources.l ...

  6. php报错致命错误203,Centos7 下安装PHP7 phpredis扩展报错解决办法 致命错误:ext/standard/php_smart_str.h...

    php7编译安装phpredis扩展报一下错误的解决办法 [root@************ phpredis-2.2.8]# make /bin/sh /usr/local/src/phpredi ...

  7. Android(java)学习笔记133:Eclipse中的控制台不停报错Can't bind to local 8700 for debugger...

    [DDMS] Can't bind to local 8600 for debugger  经常出现这种问题,这是因为电脑中某个进程占了8600的端口,可能是电脑分配进程占用这个8600端口(这个进程 ...

  8. CentOs7下php7装redis拓展报错

    遇到PHP Startup: Unable to load dynamic library:undefined symbol: zval_used_for_init in Unknown on lin ...

  9. Linux学习笔记12——配置ftp、squid、Tomcat、Samba、MySQL主从

    Linux学习笔记12 Linux学习笔记12 配置FTP服务 配置pure-ftpd 开机启动 上传下载文件 配置vsftpd CentOS 70安装配置Vsftp服务器 搭好vsftp之后出现55 ...

最新文章

  1. PHP 读取数据库内容并以二维数组按指定列输出实例
  2. oracle sqlstate 22023,DB2 开发常遇到一些错误
  3. 每天一个linux命令-touch
  4. Windows 2000/NT/XP管理员密码丢失解决方法
  5. linux下的代码比较工具下载,linux下的代码工具比较
  6. MySQL查询所有字段
  7. java包 类 方法_Java中包与包之间方法的调用及其关键字区分(基础)
  8. Spring IOC 如何解决循环依赖?
  9. 开启灯光就是近光吗_有用!科目三灯光模拟操作大全
  10. 生成验证码的一段源代码
  11. 【Docker】Redis 安装使用教程
  12. c# 的messageBox的各种用法
  13. RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds
  14. 第一阶段:Java基础
  15. 手游最佳搭档:高续航音质卓越,高颜值精品蓝牙耳机推荐
  16. STM32触摸屏校准数据的存取
  17. Flutter中,解决按下返回键将应用挂起到后台,并不会退出的问题
  18. lilo.conf - lilo 配置文件
  19. (接上)将txt中的一组时间转换为简化儒略日的小工具
  20. 模糊图片(动漫)转高清 (aardio GUI),优质图片处理软件

热门文章

  1. Matploblib work5
  2. python记录(4)- lxml模块创建xml文件
  3. mac下mysql忘记root密码的解决办法
  4. QT QComboBox使用总结
  5. CSS文件的三种引入方式
  6. leetcode-345-Reverse Vowels of a String
  7. 《Java程序员面试秘笈》—— 面试题10 类继承的建模表示方法
  8. linux操作系统-SSH原理介绍与免密运用与远程命令操作
  9. 针对不同包之间的action跳转,怎么配置?
  10. UITableView的重用