I have a drupal application that uses the database named db1. Each time a drupal request is sent, a new connection to database will be established.So after a certain number of conneections has reached the site turns offline showing the following error:
User db1 already has more than 'max_user_connections' active connections.
So my aim is to close the database connection and thereafter avoiding the offline error. For this I need to find the number of active connections made to my database.I have tried with the SHOW PROCESSLIST command. But it is not showing the number of connections.
Is there any method to find the number of database connections made to a mysql database?
Thanks,
SHOW STATUS LIKE 'threads_connected';
Although if your Drupal (or the webserver to be precise) is not closing connections automatically after each request, there's probably something that is not configured correctly.
Related
Pretty much every single Wordpress site I've set up with MySQL, sooner or later gives the message Error establishing database connection.
Restarting MySQL fixes it. Until it gets to a certain point, where rebooting the whole server is required, as it just hangs trying to restart it.
This has been various versions of Wordpress, on various versions of Linux.
What is it causing this, and what's the cure?
Can you check the number of open connections using - SHOW STATUS WHERE variable_name = 'Threads_connected';. You can use SHOW processlist to get the number of running process which will show you the number of users. Mostly it is because the credentials are incorrect or the number of open connections have reached the maximum.
Already running web app on kubernetes and facing issue, after new pod come with autoscale.
First touches on web are slower. I am already using shared caches&tmp for web. But when I look on database logs, there is issue:
2020-06-01T10:00:32.605088Z 3069191 Connect database#ip-of-node on database using TCP/IP
2020-06-01T10:00:32.673244Z 3069191 Query SET NAMES 'utf8mb4'
2020-06-01T10:00:34.272685Z 3069193 Connect database#ip-of-node on database using TCP/IP
When I have only one pod, there is literally no time between first and second connect.
But when new pod come, there is "lag" when I try browse our web.
This "lag" is visible on database where time, between Query SET NAMES and second Connect ... TCP/IP,
take more time then normal. After enter something on web, 2nd time is running without "lag".
thanks for any advice
for some reason when I open a connection the the Percona MySQL database on my HostGator website, after fetching the query, it will disconnect/ close the connection about 10 seconds later.
I typically wouldn't care, but HeidiSQL freezes up, preventing exporting or sorting the returned rows with it's UI unless I connect again.
Any thoughts on making the connection last longer? is it something I can do myself, or will it require a dedicated server or some upgrade? (I'm currently on a shared one). Thanks!
Sounds like it may be the "wait" timeout on the MySQL connection.
SHOW VARIABLES LIKE 'wait_timeout'
That's the amount of time (in seconds) that MySQL will leave the session (the database connection) open while it's idle, waiting for another statement to be issued. After this amount of time expires, MySQL can close the connection.
You should be able to change this for a session, to change the timeout to 5 minutes
SET wait_timeout = 300
Verify the setting with the SHOW VARIABLES statement again.
NOTE: This is per connection. It only affects the current session. Every new connection will inherit their own wait_timeout value from the global setting.
(This is only a guess. There's insufficient information in the question to make a precise diagnosis. It could be something other than MySQL server that's closing the database connection, e.g. it could be your connection pool settings (if you are using a connection pool).
I'm facing a really weird problem to me.
I'm trying to connect with an user to my mysql 5.5 instance but it keep saying to me that user already exceeded the max_user_connections
ERROR 1226 (42000): User 'xpto' has exceeded the 'max_user_connections' resource (current value: 100)
But,
show processlist
doesn't shows any connection used by that user. I'm pretty sure that user is not using any connection at all.
If i increase the current value to 110 for example i can connect. Then if i lower i can't connect.
EDIT: the global connections usage is 500 and only a few (10/20) are being used.
Any clue?
The server has too many open connections already. A MySQL server can only handle a specific number of open connections before refusing to allow any more, and this limit is shared amongst all users of the server. It's usually set quite high, although it's easily possible for someone to effectively DoS a MySQL server by making lots of connections.
If you got the error message (code 1226) indicates that the entire MySQL server has run out of connection slots - this is the DoS scenario.
Your database must have a user ‘A’ using which you have configured your wordpress blog.
Now the problem is that user ‘A’ has exceeded maximum_questions resource (current value: 40)
Create a new user ‘B’ in your database through your domain control panel and update the same user name you wp-config.php file in
wordpress installation directory.
Now you got the problem fixed in few minutes. It will not disturb the database or the posts you have in your wordpress or phpbb.
Copied from neuronring blog
Are you on MySQL 5, and you've set the user's MAX_USER_CONNECTIONS, and the user recently disconnected?
From MySQL docs:
For the MAX_USER_CONNECTIONS limit, an edge case can occur if the
account currently has open the maximum number of connections permitted
to it: A disconnect followed quickly by a connect can result in an
error (ER_TOO_MANY_USER_CONNECTIONS or ER_USER_LIMIT_REACHED) if the
server has not fully processed the disconnect by the time the connect
occurs. When the server finishes disconnect processing, another
connection will once more be permitted.
I am confused with MySQL connections. I have site that receives heavy requests during working hours. I use PHP to connect to MySQL database using persistant connection.
Few weeks back, I increased mysql connections to 500 that crashed my server then I put it back to 150.
Now users complaints that sometimes they cannot get on the site. I believe that this is due to limited connections.
Can you please give me some information that whether I use persistant or non-persistant? What sections of mysql do I need to tune to get optimized connection processing?
I have attached a screenshot that shows 11K Failed Attempts.
http://i.stack.imgur.com/GkxHP.jpg
Thank you so much...
Update Dec 17, 2011
When I asked this question, I changed the connection type to "non-persistant" and everything starts working fine. Today I surprised to see that the stats from phpmyadmin. Below are the values given by Phpmyadmin:
max. concurrent connections :: 16
Failed Attempts :: 43k
Please suggest some possible solutions? Which parameter should be optimized to avoid/minimize Failed attempts?
High traffic sites should not use persistent connections. I changed DB connection from persistent to non-persistent in php and problem solved!
Thanks for your help.
EDIT:
After changing connection type to non-persistent, don't forget to increase number of connections. In my case, I increased them to 500 with type set to non-persistent and that solved the issue.