1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to handle the "many connections -mysql_connect"

Discussion in 'Site & Server Administration' started by energetic, Sep 24, 2007.

Thread Status:
Not open for further replies.
  1. #1
    I have received the following error in loading my site:

    Warning: mysql_connect() [function.mysql-connect]: Too many connections in /home/vtc/domains/v1000.org/public_html/settings.php on line 10
    Too many connections

    Any solution to fix it ?
     
    energetic, Sep 24, 2007 IP
  2. tanfwc

    tanfwc Peon

    Messages:
    579
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    increase the connections in /etc/my.cnf

    max_connections=1000
     
    tanfwc, Sep 24, 2007 IP
    energetic likes this.
  3. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #3
    Thanks.
    REP was given

     
    energetic, Sep 25, 2007 IP
  4. tanfwc

    tanfwc Peon

    Messages:
    579
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Most welcome!
     
    tanfwc, Sep 25, 2007 IP
  5. agnivo007

    agnivo007 Peon

    Messages:
    4,290
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Why not use mysql persistent connections?

    mysql_pconnect()
     
    agnivo007, Sep 26, 2007 IP
  6. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #6
    can you tell me how to do ?
    I cannot find the file /etc/my.cnf


     
    energetic, Oct 1, 2007 IP
  7. chickens

    chickens Peon

    Messages:
    242
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    mysql_pconnect() is a php function that will replace mysql_connect() in the script. I would suggest agsinst using persistent connections as it will increase the amount of memory used by mysql.

    The location of my.cnf will vary, it can even go by different names. The easiest way to find it is to do a search on the computer for it.

    Run this command as a super user (root) or via sudo.
    find / | grep my.cnf
    Code (markup):
    This should tell you the location of any file called my.cnf. Find / will list every single file on the computer. | grep my.cnf pipes that data through grep which limits the output to anything with the name my.cnf.

    If it is called that name it will be found. If for some reason it is named something else, it is probably my.conf

    find / | grep my.conf
    Code (markup):
    You could also use the locate command, but that requires a database to be updated and I find it to not be worth the resources.
     
    chickens, Oct 1, 2007 IP
  8. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #8
    I have following error ?

    login as: root
    root@64.'s password:
    Last login: Mon Oct 1 10:30:44 2007 from 218.
    [root@64 ~]# find / | grep my.cnf
    find: WARNING: Hard link count is wrong for /proc: this may be a bug in your fil esystem driver. Automatically turning on find's -noleaf option. Earlier result s may have failed to include directories that should have been searched.
    find: /proc/19255: No such file or directory
    find: /proc/19257: No such file or directory
    find: /proc/19259: No such file or directory
    find: /proc/19265: No such file or directory
    find: /proc/19266: No such file or directory
    /etc/.my.cnf.swp
     
    energetic, Oct 2, 2007 IP
  9. agnivo007

    agnivo007 Peon

    Messages:
    4,290
    Likes Received:
    289
    Best Answers:
    0
    Trophy Points:
    0
    #9
    For redhat based os try :

    # updatedb
    # locate my.cnf
    # locate my.conf

    BTW, for dedicated server/VPS, using pconnect shouldn't be a big issue...provided your script supports.
    Scripts like vbulletin has option to use pconnect or mysqli to maximize performance.
     
    agnivo007, Oct 2, 2007 IP
    energetic likes this.
  10. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #10
    [root@64 ~]# updatedb
    [root@64 ~]# locate my.cnf
    /etc/.my.cnf.swp
    [root@64 ~]# vi /etc/.my.cnf.swp
    [root@64 ~]#


    Still no idea how to do
     
    energetic, Oct 2, 2007 IP
  11. chickens

    chickens Peon

    Messages:
    242
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #11
    This tells me that your my.cnf file has gone missing for some reason. You should create a new one. The contents of this file will vary depending on your server, I would suggest taking a look around the forum as there are quite a few good posts on the subject.
     
    chickens, Oct 2, 2007 IP
  12. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #12
    so bad.

    anybody can help me ?


     
    energetic, Oct 2, 2007 IP
  13. Scriptona

    Scriptona Notable Member

    Messages:
    4,957
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    280
    #13
    Why not asking for his current/max RAM first ?

    He might not be able to handle those 1000 connections simultaneously


    persistent connections can kill the machine if not limited
     
    Scriptona, Oct 2, 2007 IP
  14. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #14
    How do I create the /etc/my.cnf myself?
    what is the correct content inside this file ?
     
    energetic, Oct 2, 2007 IP
  15. chickens

    chickens Peon

    Messages:
    242
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Below is the my.cnf from my server. I've tweaked this file a ton to get it working just right for my VPS with 256mb of ram. I know for a fact that this file will not work for many people as it is set for my specific server.

    [mysqld]
    skip-networking
    skip-innodb
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    max_connections = 500
    wait_timeout = 1800
    connect_timeout = 10
    max_allowed_packet = 8M
    max_connect_errors = 10
    key_buffer = 48M
    max_connect_errors = 10
    key_buffer = 16M
    query_cache_limit = 1M
    query_cache_size = 6M
    query_cache_type = 1
    table_cache = 128
    
    [mysql.server]
    user=mysql
    
    [safe_mysqld]
    err-log=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    open_files_limit = 8192
    Code (markup):
     
    chickens, Oct 3, 2007 IP
    energetic likes this.
  16. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #16
    Thanks to Chicken. REP was given.

    Can anyone tell me how to customize it to a P4 3G server with 1G RAM ?
     
    energetic, Oct 3, 2007 IP
  17. sodium

    sodium Banned

    Messages:
    57
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    please try my setting:

     
    sodium, Oct 3, 2007 IP
    energetic likes this.
  18. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #18
    Thank you very much :)

     
    energetic, Oct 3, 2007 IP
  19. Scriptona

    Scriptona Notable Member

    Messages:
    4,957
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    280
    #19
    Just letting you know that those numbers can't be ideal for every machine - tweak it yourself by changing individual variable every time and notice the server performance in peak hours until you get to the figures that work for you the best.
     
    Scriptona, Oct 3, 2007 IP
  20. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #20
    any tips to optimize this setting ?

    Thanks anyway

     
    energetic, Oct 3, 2007 IP
Thread Status:
Not open for further replies.