Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Sep 012010
 

Can't connect to local MySQL server through socket

Answer:

Sometimes when you type the mysql command, it shows:

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

The cause of this problem is the MySQL socket file is not in the default location, e.g. /tmp/mysql.sock

To fix, edit the MySQL configurations, e.g. /etc/my.cnf, add the following lines

[client]
socket=/tmp/mysql.sock
Aug 232010
 

Set the auto increment start value in MySQL?

Answer:

In MySQL, you can change the table's auto increment start value by the following command.

mysql> ALTER TABLE `my_table` AUTO_INCREMENT = 2000;

Query OK, 2 rows affected (0.06 sec)
Records: 2  Duplicates: 0  Warnings: 0
Aug 202010
 

Block a client from connecting to MySQL if too many errors

Answer:

You can block a client from connecting to MySQL if they introduced too many errors, e.g. sending incorrect password for authentication, insufficient privileges when connecting to a database etc.

To set the number of maximum allowed error, edit the MySQL configurations, e.g. /etc/my.cnf

..
max_connect_errors=100
..

So if a client exceeded this value, they will be blocked from connecting to the server.

Don't forget to restart MySQL to take effect.

# /sbin/service mysqld restart

Aug 172010
 

Set the maximum allowed number of connections in MySQL

Answer:

MySQL has a setting which prevent the database from overloaded due to too many concurrent connections. This value should depends on the processing power of your database server, e.g. CPU, memory, disks I/O.

To change the value, edit the MySQL configurations, e.g. /etc/my.cnf

..
max_connections=100
..

So if a client connecting to the database exceeded this value, they will be blocked.

Don't forget to restart MySQL to take effect.

# /sbin/service mysqld restart