MySQL Error “Too many connections”

后端 未结 7 2148
猫巷女王i
猫巷女王i 2020-11-30 05:37

I am using MySQL 5.0 for a site that is hosted by GoDaddy (linux).

I was doing some testing on my web app, and suddenly I noticed that the pages were refreshing rea

7条回答
  •  情歌与酒
    2020-11-30 06:35

    I had about 18 months of dealing with this (http://ianchanning.wordpress.com/2010/08/25/18-months-of-dealing-with-a-mysql-too-many-connections-error/)

    The solutions I had (that would apply to you) in the end were:

    1. tune the database according to MySQLTuner.
    2. defragment the tables weekly based on this post

    Defragmenting bash script from the post:

    #!/bin/bash
    
    # Get a list of all fragmented tables
    FRAGMENTED_TABLES="$( mysql -e `use information_schema; SELECT TABLE_SCHEMA,TABLE_NAME
    FROM TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND
    Data_free > 0` | grep -v '^+' | sed 's,t,.,' )"
    
    for fragment in $FRAGMENTED_TABLES; do
      database="$( echo $fragment | cut -d. -f1 )"
      table="$( echo $fragment | cut -d. -f2 )"
      [ $fragment != "TABLE_SCHEMA.TABLE_NAME" ] && mysql -e "USE $database;
      OPTIMIZE TABLE $table;" > /dev/null 2>&1
    done
    

提交回复
热议问题