MySQL server has gone away after no changes - mysql

I'm currently writing a laravel application (7.4) and haven't had that many problems, then I cam back from the just gone weekend, booted up the local environment with artisan serve, and I've gotten the following;
SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: select * from actions where date(time) = CURDATE() and type = hitBudget order by time desc)
That error comes up whenever the main page loads, which has a controller on it to fire off a query to populate something. The table is most certainly still there, as is the database as the LIVE version us still up and running. the IP in the .env file still points to the same server, the database credentials haven't changed at all, the only thing I recall valley is updating composer packages on the server a day or so before this happened.
Most solutions so far have pointed to timeouts, but the error occurs instantly and local works off the exact same database and tables that live does, yet live works fine.
Edit; I've done some fiddling and discovered that this error comes up regardless of what is set as the databases credentials in the .env file, I can set the host to 8.8.8.8 and its the same error, yet if I replace this ENV with a copy of the live one, it still persists.
Any ideas would be appreciated.

Related

Flask Security Too Mysql connection problem

I'm using Flask Security Too (https://flask-security-too.readthedocs.io/en/stable/index.html) to authenticate users on a test server. I followed the instructions in the documentations to get it up and running. It all works perfect, however for some reason the application is losing the connection to the MySQL server and starts returning an Internal Server Error. In Sentry I see the following error message:
(sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
[SQL: SELECT anon_1.user_id AS anon_1_user_id, anon_1.user_email AS anon_1_user_email, anon_1.user_first_name AS anon_1_user_first_name, anon_1.user_last_name AS anon_1_user_last_name, anon_1.user_password AS anon_1_user_password, anon_1.user_last_login_at AS anon_1_user_last_login_at, anon_1.user_current_login_at AS anon_1_user_current_login_at, anon_1.user_last_login_ip AS anon_1_user_last_login_ip, anon_1.use...
This error usually appears when the site has not been accessed for several hours during night. Restarting the Flask app solves the problem.
I tried changing the SqlAlchemy options, without success. Since I'm using a MySQL database on a dedicated server I also tried using a local MySQL database, I'm having the same issue here.
I would like to solve this issue before spending more time on integrating this into my website.
Does anyone know what can cause this problem?
I have seen this (and there have been bugs) when using psycopg2 - where a PRIOR error (such as select on a column with an incompatible type - causes the connection to permanently be unusable. From my testing - there wasn't an obvious way to even know this had happened until the query that throws this error - since it was a coding error - I fixed a few bugs in that area. Note that was with psycopg2 - which I don't think you are using.
I would look at logs or turn on complete mysql query logging to look at what might be querying it during the evening.
Another thought - which I don't think would cause THIS error - is that many DBs drop connections after some period of time out. Make sure you are using Flask-SQLAlchemy 2.4.0 or greater and put in the config:
app.config["SQLALCHEMY_ENGINE_OPTIONS"] = {"pool_pre_ping": True}
which will make sure the connection is valid PRIOR to returning the connection to be used.

Issue with connecting to database on Wordpress

I am trying to get Wordpress up and running but I get the "Error establishing a database connection" page pop up.
Here is the setup and what I've done:
I have a server running Wordpress fine. I took a snapshot from the AWS volume that had the wp-config.php information from the running server and spawned a new server with a volume that is snapshotted. I've checked all my settings and it all looks fine.
On the SQL sever side (MYSQL), I added the new IP with all the correct username/passwords so the database server will allow it to connect. I also have put print statements while wordpress tries to load the database. The values returned are all correct. Based on some threads I read, I also deleted my wp-config file and re-copied it from the original server.
I also made sure the permissions are correct. Any other suggestions on what I could be missing?
I was able to fix this. The issue had nothing to do with Wordpress or the server, but with MYSQL. The database have Schema privileges and I hadn't set it for my new IP address. Adding the privileges fixed the issue.

MySQL server keeps going away even after wait_timeout set to a year

I've got a Cloud SQL server instance running through Google App Engine and the MySQL server keeps going away. This was never an issue before but for some reason it has just decided to rear its ugly head.
In the server-side script I set the wait_timeout to 31536000.
I also created a wait_timeout flag in the Dev Console of GAE.
Still this issue crops up, and it does so very inconsistently, sometimes working for a day or two, then dropping off the face of the planet. I redeploy the script and then it works for an hour, and then goes away. It makes no sense to me.
Has anyone had this happen to them before?
The first error I get is this:
OperationalError: (2013, 'Lost connection to MySQL server during query')
Then:
OperationalError: (2006, 'MySQL server has gone away')
If I were to have one theory it would be that, on the client side, a function was being called to the mysql server and then the client called another function before the MySQL server had finished the first, and this somehow screwed it up?
I have no idea.

Warning: mysql_query(): MySQL server has gone away

I have a php script that updates a database table as soon as i fill up a form through localhost. I am able to access my localhost homepage and then fill up the respective form, but as soon as i hit submit, i get the above error. When i check for the wamp icon that time, it turns form green to orange. This is creepy, it is green all the time but as soon as that particular php file is called, it turns orange. There is nothing wrong with the script cuz i had used it many times before. I had to reinstall wamp in betweeen and its giving error since then.
Also, phpmyadmin page does not open everytime, it says #2002 Cannot log in to the MySQL server many times. Maybe this is the reason, my php script cannot connect to the MYsql server, i have tried solutions from other threads but none of them in working :( :(
Please help me i am stuck and have an important work to do. Is anybody willing to help me out with temaviewer?
The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection.
ini_set('mysql.connect_timeout', 300);
ini_set('default_socket_timeout', 300);
they are set to default at 60 seconds and this caused my problem.
see here for more details

PHP MySQL Connection Timed Out on private network

I am getting intermittent 'Connection Timed Out' errors when a php script on my web server connects to the MySQL database server over the private network. However, if I tell the script to use the public network to connect, these errors do not appear.
My connection script is setup so that whenever I try to connect to mysql, it checks for errors, if there is an error, it sends me an email then automatically switches to the public network to try that connection. If the public connection fails, it sends me another email and displays a custom web page to the user.
I get about 5 to 10 connection errors every hour. There are hundreds of successful connections every minute.
These machines are dedicated machines. I contacted our hosting company and they tested the routers and cables and said everything is fine. I tried pinging the servers both ways and there are no errors at all for test periods over an hour.
I am using the latest Nginx with the latest PHP and PHP-FPM. Mysql is 5.5.27. These are Centos 6 64bit systems with that latest updates.
I've tried many network configuration options, adjustments to php-fpm & mysql config file and no matter what I do or change, nothing fixes it.
The weird thing is, everything works great over the public network and pings and file transfer work great over the private network between both machines.
Any ideas?
** UPDATE **
I made some changes to the PHP-FPM config file and to the MySQL config file and the errors are now about 2 to 3 per hour but still unresolved.
I'm not sure this is your case but still worth mentioning as it helped me in a similar situation. Basically, there is a cap on max number of connections in linux kernel: https://serverfault.com/questions/10852/what-limits-the-maximum-number-of-connections-on-a-linux-server
Not sure if it is shared between all the networks, but if you think it's worth checking I'd just raise those variable values say twice and see if it had any effect on how frequently the error happens.