I'm trying to cope with MySQL's error MySQL server has gone away in a django env.
The quick workaround was to set the global wait_timeout MySQL variable to a huge value, but in the long run this would accumulate to many open connections.
I figured I'll get the wait_timeout variable and poll the server in smaller intervals. After implementing this I tried to test it but am failing to get the error.
I set global wait_timeout=15 and even set global interactive_timeout=15 but the connection refuses to disappear. I'm sure I'm polling the database in larger intervals than 15sec.
What could be the cause for not being able to recreate this error?
Run below dirty-and-quick script and test your django project or whatever. I think this is not an elegant approach, but it works well.
<?php
mysql_connect( "127.0.0.1", "id", "pw" ); // should be changed to yours
while(1)
{
$r = mysql_query( "SHOW PROCESSLIST" );
while( $d = mysql_fetch_row( $r ) )
{
if( $d[7] != "SHOW PROCESSLIST" )
{
mysql_query( "KILL ". $d[0] );
echo( $d[0]." was killed.\n" );
}
}
}
?>
And here is the result.
mysql> select * from foo;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 337
Current database: test
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 338
Current database: test
ERROR 2006 (HY000): MySQL server has gone away
mysql>
I've made a few modifications to #lqez code to be used with mysqli:
<?php
$mysql = new mysqli("127.0.0.1", "user", "password", "database"); //should be changed to yours
while (1) {
$r = $mysql->query("SHOW PROCESSLIST");
while ($d = $r->fetch_row()) {
if ($d[7] != "SHOW PROCESSLIST") {
$mysql->query("KILL " . $d[0]);
echo($d[0] . " was killed.\n");
}
}
}
?>
Related
Perl codes always connecting to same MySQL(local but in error showing FQDN of server) database although it is configured to connect to different server.
please see the codes.
$datasetname="DBI:mysql:database=applications;host=entdb"
$$dbobject = DBI -> connect ($datasetname, $username, $password,
{RaiseError => 0, PrintError => 0})
or $errflg2 = 1;
print TT (" : ".time()."\n");
close (TT);
if ($errflg2 > 0)
{
$errmsg = "ERROR opening up the database: $datasetname\n";
$errmsg .= " Error number: " . $DBI::err . "\n";
$errmsg .= " Error text : " . $DBI::errstr . "\n";
print "$errmsg";
ilog ($ifile, $errmsg);
mail_it ($errmsg);
if ($debug != 0) { close (DB); }
exit (1);
}
else
{ print "Opened the '" . $datasetname . "' database.\n"; }**
enter code here
error
ERROR opening up the database: DBI:mysql:database=applications;host=entdb
Error number: 1045
Error text : Access denied for user 'entdb'#'vpl121' (using password: YES)
see in code i referred entdb, but Perl connecting to VPL121. Perl codes are running on vpl121.
In mysql all user accounts are identified via username#hostname format, where hostname is the host name or ip address of the computer from which the code connects to the mysql database.
You did write that the perl code runs on vpl121, therefore this is the hostname that mysql uses. Apparently, you do not have any user account that matches the 'entdb'#'vpl121' or the password is incorrect or the given user does not have access to the entdb database.
My guess is that you do not have any matching user accounts. Consider perhaps creating an 'entdb'#'%' user account, where % as hostname stands for any host name or ip address.
Today I was trying to use sphinxsearch with SphinxQL but something going bad =\
First I installed sphinxsearch then I configured it, after that I created index forum_index using indexer --all. All finished without errors.
Then I included SphinxQl to my project, typed host and port which is listening sphinx and tried to make a query like in ReadMe of SphinxQL:
// create a SphinxQL Connection object to use with SphinxQL
$conn = new Connection();
$conn->setParams(array('host' => 'localhost', 'port' => 9306))
;
But it caused a database access error:
access denied www-data#localhost password NO
After that I set parameters of username and password in SphinxQL using
mysqli::real_connect()
Previous errors disappeared
Then I tried to make a test query:
$query = SphinxQL::create($conn)->select('column_one', 'colume_two')
->from('forum_index');
$result = $query->execute();
But I get an error:
table forum_index doesn't exists
I have a feel that my SphinxQL doesn't see sphinx or sphinx config and tries to make a simple query.
Have you any idea what's going wrong?
Please go to command line use the following command
mysql -P9306 --protocol=tcp --prompt='sphinxQL> '
Once get sphinxQL prompt enter the following command
sphinxQL> show tables;
If you set up everything correctly you can see the forum_index table in the list. Else check your searchd configuration section in your sphinx.conf file for proper configuration. My configuration look like this
searchd {
listen = 9315
listen = 9306:mysql41
log = /Users/XXXX/projects/sphinx/data/searchd.log
query_log = /Users/XXXX/projects/sphinx/data/query.log
read_timeout = 5
max_children = 30
pid_file = /Users/XXXX/projects/sphinx/data/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
workers = threads
thread_stack = 1024K
}
I solved my problem by setting host = '127.0.0.1' in SphinxQL params
Warning: mysql_connect(): (HY000/2002): Connection refused in
/home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line
7
Warning: mysql_select_db(): No such file or directory in
/home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line
8
Warning: mysql_select_db(): A link to the server could not be
established in
/home/vol14_1/byethost31.com/b31_16461744/htdocs/Mysql/con.php on line
8
I have the below code
<?php
$localhost="localhost";
$username=b31_16461744;
$pass=test123;
$dbname=b31_16461744_user;
$a= mysqli_connect($localhost,$user,$pass);
mysql_select_db($dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!";
}
?>
Sidenote: Assuming the credentials are correct, given to you by your web host.
There are several problems with this code (taken from a comment you left).
Firstly, three of your declarations are not quoted and are being treated as constants.
PHP error reporting would have thrown notices of undefined constants.
These are treated as constants:
$username=b31_16461744;
$pass=test123;
$dbname=b31_16461744_user;
You are also referencing the wrong variable for the username being $user which should be $username. Error reporting would have signabled an undefined variable notice.
Then you're mixing mysql_ with mysqli_ syntax. Those different MySQL APIs do NOT intermix. You must use the same one throughout your code.
Sidenote: The other question you posted Access denied for user 'test123'#'192.168.0.38' (using password: NO) you are using sql306.byethost31.com for the host. Make sure that is correct. I have no idea what settings that host wants you to use.
<?php
$localhost="localhost";
$username="b31_16461744";
$pass="test123";
$dbname="b31_16461744_user";
$a= mysqli_connect($localhost, $username, $pass);
mysqli_select_db($a, $dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!";
}
?>
or just use all four parameters:
<?php
$localhost="localhost";
$username="b31_16461744";
$pass="test123";
$dbname="b31_16461744_user";
$a= mysqli_connect($localhost, $username, $pass, $dbname);
if($a)
{
echo "connected..";
}
else
{
echo "not...!!" . mysqli_error($a);
}
?>
However, your else with the echo does not help you. Use mysqli_error() to get the real error.
I.e.: or die("Error " . mysqli_error($a));
Example from the manual
$link = mysqli_connect("myhost","myuser","mypassw","mydb")
or die("Error " . mysqli_error($link));
References:
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/mysqli.error.php
http://php.net/manual/en/function.mysqli-connect.php
http://php.net/manual/en/language.constants.php
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Displaying errors should only be done in staging, and never production
I Think Credentials are not correctly set. See Your connection statement.
For Reference :
While Working On Localhost, We write connection statement as :
$con=mysql_connect("localhost","root","");
$db1=mysql_select_db("DatabaseName",$con);
But, While working on server, we need to change the following credential.
Username and password values are must.
$con=mysql_connect("localhost","Username","password");
$db1=mysql_select_db("DatabaseName",$con);
I'm having a problem to connect my DB cloud sql with php.
I've tried every possible way to connect (pdo, mysqli & mysql)
none of them worked.
I've put an IPv4 for the could sql instance and authorized the compute engine IP in the allowed networks section.
When I'm trying to connect from the compute engine with
mysql --host=cloud_sql_IP --user=my_user --password
it's working and I'm able to see the tables.
On the php side I've put this code:
$db = mysql_connect(<CLOUD_SQL_IPV4>, 'root', '');
if (!$db){
die('Connect Error (' . mysql_error());
}
and I get "Connect Error (Permission denied)"
when I'm trying this way:
$conn = mysql_connect(":/cloudsql/<COMPUTE_INSTANCE>:<DB>", "root", "");
if (!$conn) {
die('Connect Error (' . mysql_error());
}
I'm getting:
"Connect Error (No such file or directory"
What else should I do?
Thanks!
Well after diggin into it for 2 days I managed to connect cloud DB
first run this for the permission fix (centos)
setsebool httpd_can_network_connect=1
And for the php it should be written this way:
new mysqli(
<IP_V4>, // host
'root', // username
'', // password
<DB_NAME>, // database name
null,
'/cloudsql/<GCE_INSTANCE>:<DB>'
);
Need help to restore a Magento Website into new server.
I already restore the files to new server and tried to restore the MySQL via phpMyAdmin. But every time I try to import the MySQL, I am getting the following error:
SQL query:
Warning : USING UNIQUE OPTION prefix pass instead of PASSWORD IS deprecated AND will be removed IN a future release.Please USE the FULL name instead.-- MySQL dump 10.13 Distrib 5.5.42, for Linux (x86_64)
--
-- Host: localhost Database: XXXXXX
-- ------------------------------------------------------
-- Server version 5.5.42-cll
/*!40101 SET #OLD_CHARACTER_SET_CLIENT=##CHARACTER_SET_CLIENT */;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Warning: Using unique option prefix pass instead of password is deprecated and w' at line 1
AT First Check your Server As following script:
extension_check(array(
'curl',
'dom',
'gd',
'hash',
'iconv',
'mcrypt',
'pcre',
'pdo',
'pdo_mysql',
'simplexml'
));
function extension_check($extensions) {
$fail = '';
$pass = '';
if(version_compare(phpversion(), '5.2.0', '<')) {
$fail .= '<li>You need<strong> PHP 5.2.0</strong> (or greater;<strong>Current Version:'.phpversion().')</strong></li>';
}
else {
$pass .='<li>You have<strong> PHP 5.2.0</strong> (or greater; <strong>Current Version:'.phpversion().')</strong></li>';
}
if(!ini_get('safe_mode')) {
$pass .='<li>Safe Mode is <strong>off</strong></li>';
preg_match('/[0-9]\.[0-9]+\.[0-9]+/', shell_exec('mysql -V'), $version);
if(version_compare($version[0], '4.1.20', '<')) {
$fail .= '<li>You need<strong> MySQL 4.1.20</strong> (or greater; <strong>Current Version:.'.$version[0].')</strong></li>';
}
else {
$pass .='<li>You have<strong> MySQL 4.1.20</strong> (or greater; <strong>Current Version:'.$version[0].')</strong></li>';
}
}
else { $fail .= '<li>Safe Mode is <strong>on</strong></li>'; }
foreach($extensions as $extension) {
if(!extension_loaded($extension)) {
$fail .= '<li> You are missing the <strong>'.$extension.'</strong> extension</li>';
}
else{ $pass .= '<li>You have the <strong>'.$extension.'</strong> extension</li>';
}
}
if($fail) {
echo '<p><strong>Your server does not meet the following requirements in order to install Magento.</strong>';
echo '<br>The following requirements failed, please contact your hosting provider in order to receive assistance with meeting the system requirements for Magento:';
echo '<ul>'.$fail.'</ul></p>';
echo 'The following requirements were successfully met:';
echo '<ul>'.$pass.'</ul>';
} else {
echo '<p><strong>Congratulations!</strong> Your server meets the requirements for Magento.</p>';
echo '<ul>'.$pass.'</ul>';
}
}
##Test What Exact Version PHP & MySQL
echo "<h2>Exact Version PHP & MySQL: </h2>";
printf("PHP version: %s\n", PHP_VERSION);
##### Without DB Access
ob_start();
phpinfo(INFO_MODULES);
$info = ob_get_contents();
ob_end_clean();
$info = stristr($info, 'Client API version');
preg_match('/[1-9].[0-9].[1-9][0-9]/', $info, $match);
$gd = $match[0];
echo '</br>MySQL: '.$gd.' <br />';