Posts Tagged mysql

Limit number of connections for MySQL user

Posted on October 19, 2009 with No Comments

To limit number of mysql connection per user, edit /etc/my.cnf

vi /etc/my.cnf

In [mysqld] section, set value for max_user_connections.

[mysqld]
max_user_connections=40

This will limit mysql connections at a time for any user to 40.

Zend Framework error MySQL server through socket /tmp/mysql.sock

Posted on September 18, 2009 with No Comments

On a new apache/mysql installation, i got following error when connecting to mysql database in zend framework.

An error occurred
Application error
Exception information:
 
Message: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

This is because no socket /tmp/mysql.sock exists. Can be fixed by symlink to actual socket.

To find mysql socket, in mysql command prompt run

mysql> SHOW VARIABLES LIKE '%socket%';
+---------------+-----------------------------+
| Variable_name | Value                       |
+---------------+-----------------------------+
| socket        | /var/run/mysqld/mysqld.sock | 
+---------------+-----------------------------+
1 row IN SET (0.00 sec)
 
mysql>

Now we got actual socket location. Now create a symlink with command

sudo ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

This will make it work, but a reboot will lose the changes, so permanent solution is to edit /etc/mysql/my.cnf

vi /etc/mysql/my.cnf

Find

socket          = /var/run/mysqld/mysqld.sock

Replace with (all occurrence, 3 times)

socket          = /tmp/mysql.sock