"MySQL server has gone away" in mysqli - mysql

My web threw the error "MySQL server has gone away". I google it, find a method that use mysql_ping function, but I use extension mysqli, not mysql.
How can I fix this problem?

There is a mysqli_ping method for this, as well:
http://us3.php.net/manual/en/mysqli.ping.php
However, in my experience, ping was not needed. All I had to do was add mysqli.reconnect = "1" to my php.ini.
Ref. check if mysql connection is valid

You may get this error when your query is crashing MySQL server check MySQL error log file for that.
If values for wait_timeout & interactive_timeout MySQL server variables is set to very low in MySQL configuration file. Try increasing values for them and then restart MySQL server.
This is basically a time between two queries and after opening new connection if you don't execute next query before this timeout then your connection will be automatically closed by the MySQL server and you will get this error.

Stop and start mysql server to fix this problem.

Related

MySQL server has gone away after Shutdown and Startup Server

I am using MySQL Workbench. I shut down and restart my server. After that I was not able to execute any queries as the error always come up immediately.
Error 2006:MySQL server has gone away
I have started the MySQL57 services manually so I am sure the server is running. Looking up SO, two solutions come up - (1) set max_allowed_packet = 128M in my.ini [Failed], (2) set wait_timeout to a larger number - I cannot find the my.cnf file so this doesn't work.
What I encountered is pretty different from others as they usually had this error after a long piece of queries, but mine just comes up immediately after a query is sent. Appreciate any help (include finding the my.cnf file).
Update:
Discovered something that may help, what I have done:
Start MySQL57 from services.msc manually
Open MySQL Workbench, connect to database
Test the connection, and said "Successfully made the MySQL Connection"
Run a query, return "Error 2013: Cannot connect to MySQL Server on local host"
Run the query again, return "Error 2006: MySQL Server has gone away"
Check services.msc, the MySQL57 has been switched off.

Same query times out - Lost connection to MySQL server during query

I know this question has been asked on here before, but it seems like I've tried everything suggested in this answer and this answer, and still no luck. I'm trying to use MySQL Workbench 6.3 on a Windows 10 client, connecting to a Linux MySQL server hosted by GoDaddy/cPanel.
I can connect to the MySQL server with no problems, and usually I have time to run a query or two. Then, within a minute of inactivity between Workbench and the server, I'll run into Error 2013: Lost connection to MySQL server during query. This even happens when running the exact same query, back to back about a minute apart, as shown here (even when the original query is quick; only 0.03 seconds to run):
The same problem persists when I run select sleep(60) immediately upon connecting to the MySQL Server; the connection is usually lost between 30-40 seconds into the execution of the query:
I've checked the MySQL docs, but with no luck. I don't think the problem can be related to packet size, as others have suggested (since the same query will work and then fail later), and my Workbench timeout settings look okay:
Anyone have any idea? The only other thing I can think of is maybe the wait_timeout variable listed in the MySQL docs needs to be increased too, but I guess that would be somewhere on the server side (some have mention my.ini) and I can't find where any MySQL Server files live in the cPanel hosting admin interface. There's a MySQL online client provided through cPanel (phpMyAdmin I think), but it's not nearly as robust and is becoming cumbersome to use. Any help would be appreciated!
I was having the same problem, using MySQL Workbench 6.3.6 on Win10 to connect to a MySQL server on a shared hosting system (Arvixe).
In addition to to the problem described by the OP (lost connection to server), I was also getting an error when attempting to import data from a prior export (similar to what is described here):
Unhandled exception: Error querying security information: Error executing 'SELECT * FROM mysql.user WHERE user = '[username]' and Host = '[host]' ORDER BY User, Host' SELECT command denied to user '[username]'#'[host]' for table 'user' SQL Error: 1142
Apparently, a bug was introduced in MySQL Workbench 6.3.5 (bug report). From the bug report:
It appears the problem arise if connecting with an user with no privileges on the mysql schema.
In other words: users connecting to a shared hosting system.
The proposed solution is to uninstall MySQL Workbench 6.3.6, and install 6.3.4 instead. (6.3.4 can be found in the archives). This solution worked for me.

Mysql not generating log when connection fails

I am continuously getting below error while connecting to mysql-
Can\'t connect to MySQL server on /ip/address
but mysql is not generating any log for this error. I have below entries in my.cnf file
log=/var/log/mysql_err.log
log-error=/var/log/mysql/mysql_error.log
I am using correct credentials. No issue of conections.
Now how will I determine the exact issue If I'll not get any log ?
Any Idea, how to solve this ?
This is not surprising:
the server can only log an incident it is aware of. However your client does not even reach the server at all! So how should the server know some client has attempted to contact it?
The error message you get clearly indicates that you do have a connection issue.
You can easily make a test to check the most common problems: just open a telnet connection from the system trying to connect to the system the sql server runs on, connect to the mysql port: telnet <ip-of-mysql-server> mysql
On typical unixoid systems "mysql" will be substituted by the "well known port number of mysql, which is 3306. otherwise you have to specify it manually. Do you get a connection at all? I would guess not. This means either the mysql server is not listening where expected (not running or configured otherwise) or the connection is blocked on network level (firewall).

Difference In Phpmyadmin Mysql web client and Terminal client

I got problem (#2006 Mysql server gone away) with mysql while connecting and performing some operations through web browser.
Operation Listed below:
When Executing big procedure
Importing database dump
When Access some particular tables It immediately throws "Server gone away".
Refer this question for Scenarios: Record Not Inserted - #2006 Mysql server gone away
Note : The above operations are works fine when I perform through terminal.
I tried some configuration as googing stated. That is set wait_timeout, max_allowed_packet. I checked for the bin_log but it is not available.
But the issues will not rectified.
What is the problem & How can I figure out & fix the issue?
what is the different between access phpmyadmin mysql server from web browser and terminal?
Where I can find the mysql server log file?
Note: If you know about any one of the above questions. Please post here. It would be helpful to trace.
Please help me to figure this out..
Thanks in advance...
Basically nothing except phpMyAdmin is limited by PHP's timeout and resource limits (limits to keep a runaway script from bogging down your entire machine for all eternity; see the docs for details of those values. In some cases, you might be authenticating through a different user account (for instance, root#localhost and root#127.0.0.1 aren't the same user), but as long as you're using a user with the same permissions the differences are minimal.
You can read more about logs in the MySQL manual, note that "By default, no logs are enabled (except the error log on Windows)".
Below are answer for question
From my research the problem is that browser have some limit to disconnect the connection i.e timeout connection. So that the above problem raised.
To resolve this problem
Go to /opt/lampp/phpmyadmin and open config.inc.php
add the command $cfg['ExecTimeLimit'] = 0;
Restart the xamp server. Now you can perform any operations.
`
2. Web client is differ from terminal because Terminal client will not getting timeout. Terminal client maintain the connection till the progress completed. I recommenced to use command prompt to import/export/run process by safe way.
Basically phpmyadmin will not have any log file. If you wanna see warnings and error you should configure the log file.
Configuration steps:
Go to /opt/lampp/etc/my.cnf
Add log_bin = /opt/lampp/var/mysql/filename.log
Restart the xamp server. You can get the log information.

"MySQL server has gone away" error after few hours of inactivity

I have a Django app running on Apache with wsgi module.
After few hours of inactivity I get that error and I have to restart the Apache.
Any ideas?
Thanks
This error message mean that the database server has closed the connection to you. I guess this is caused because the connection is idle.
I believe you can get this fixed by adjusting the wait_timeout inside the configuration file of your mysql database server. The file is most commonly named "my.cnf".
This, however, is not considered as a good practice. I would like to suggest you to optimize the application you are writing to open the connection to mysql on demand - there's no point to keep it open if you are not actively using it for a long time.
If you need a quick fix, use the mysql_ping() function to check whether the connection is still alive and re-open if necessary.