Error establishing a database connection to Cloud SQL - php

please forgive a novice question:
I have Wordpress up and running on my development server with no problems. When I try to upload it using appengine, I get the following error output from WP_DEBUG, where MYSITEID is the name of my site:
Warning: mysqli_connect(): (HY000/2002): Unable to find the socket transport "tcp" -
did you forget to enable it when you configured PHP? in
/base/data/home/apps/s~MYSITEID/wp.370505361471441320/wordpress/wp-content/db.php on line 176
It goes on:
"This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at :/cloudsql/MYSITEID:wordpress. This could mean your host's database server is down."
My Cloud SQL instance is up and running and I followed the tutorial steps 7 and 8 exactly.
My wp_config db_host section reads:
/** MySQL hostname */
if(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
define('DB_HOST', ':/cloudsql/MYSITEID:wordpress');
}else{
define('DB_HOST', 'localhost');
}
From the looks of it my error text is almost verbatim what a phpmyadmin user encountered, but I'm still not sure how to resolve it. Do I need to change something on the DB_HOST line? See phpMyAdmin on GAE - Authentication
Thanks for any help - really appreciate that GAE for PHP exists!

Turns out the issue was in db.php - which I had installed in wp-content per the instructions here: http://wordpress.org/plugins/mysqli/installation/
I'm not sure why I originally installed mysqli instead of using mysql; it seemed to fix an earlier php error I was having on my development server. But after removing db.php both my dev version and the Cloud SQL instance work just fine!

Related

After snapshot boot : Informix Client -23101 / Oracle instant client -28759

Not to waste your time, I'll describe what I had && what I have now. My apps are written on php. They live on redhat6 server with nginx + apache web servers. We store data in MySQL DB, but we have lots of imports from Oracle and IBM Informix DB's, & mssql. For Oracle & Informix I have installed clients && compiled libraries pdo_oci.so & pdo_informix.so . For a few months they were working as expected.
But a week ago, admins made a snapshot of out virtual server, and reloaded it. Now only MySQL and mssql connectors work, and Oracle & IBM clients thows errors.
Oracle : -28759
Failed : SQLSTATE[HY000]: pdo_oci_handle_factory: ORA-28759: failure to open file (/usr/local/src/php-5.3.3/ext/pdo_oci/oci_driver.c:579)/opt/project/www/test.php149
IBM Informix : -23101
Failed : SQLSTATE=HY000, SQLDriverConnect: -23101 [Informix][Informix ODBC Driver][Informix]Unspecified System Error = -23101./opt/project/www/test.php146
Well, as official documentations says, Informix error is connected with the lost env variables of DB_LOACALE & CLIENT_LOCALE...etc.
This is strange, because all this time I was using this string for my connections :
$dbh = new PDO ("informix:host=example.ru; database=some_db; server=db_net; CursorBehavior=0; DB_LOCALE=en_US.57372; CLIENT_LOCALE=en_US.57372;", "db_login", "pass");
I tried to set up this env variables for apache (httpd) , but this error still accures. Now I have this variables set after server reboot, but no success. May be I'am doing something wrong or at the wrong place or user name...
About Oracle , documentation says that it is connected with files loading:
And the web doc says that it is mostly ssl error and is connected with the trouble of the client, that can not find SSL Wallet files. I Have TCPS secure connection to Oracle DB with wallet, and I remember that it was a real trouble to make Instant client to look at the right place. More than that, I have client tracing enabled, but it is writing log only when I use sqlplus directly from terminal. When I run my php scripts, I got only errors and no log.
Questions:
How to enable Informix variables correctly, or how to resolve this
issue in different way.
How to enable "net tracing" for oracle, to
see what he is looking for?
How to store this variables for future
reboots/reloads/snapshots...etc. ?
People. Enable tracing of all what is possible and use "strace" command to check where programm is failing!!!
Thanks to Luís Marques! I found gls in my logs and tried to make link for it.. to real IBM/informix/gls... than another msg trouble acured.../ I made soft link from /usr/informix to my real /opt/IBM/informix and all connections successfully woke up!
Thank you man. You really helped me to finish this trouble. I post this as ansver but will accept yours as thanks to you! =)
This may be related to file / dir permissions rather than env variables.
The oracle error seems to indicated that it can no longer open/read the files it requires.
The informix -23101 error can also be caused by the driver being unable to read GLS files required for locale support.
Does the apache user have access to the Informix Client SDK directories and files?

phpGrid "Error: Could not connect to the database" debugging

I have implemented a phpGrid that works in my dev environment but just keeps saying:
Error: Could not connect to the database
in production
I am logging failed attempts at MySQL connections in the logs on and if I put in a dodgy username and password in the conf.php files username/password it does not show up in the log (I've tested the log is working by attempting to connect with bad credentials via a terminal.
The host is just "localhost" I am using PDO connections elsewhere within my code and the are all connecting using "localhost" so I see now reason why this would be a problem.
In the conf.php I've turned on:
define('DEBUG', true);
And on my grid I have:
$dg -> enable_debug(true);
But I just keep getting this stupid error that tells me nothing about what's really going on...
It happened to me as well. Finally I was able to figure out. The reason is mySQLi was not enabled on the server. I enabled it and it works now.
Sorry, i cannot add a commant and sorry for my english.
If you are using PHP 5.5 try:
error_reporting=E_ALL^E_DEPRECATED
at top of the page for the time being.
For the files on your production machine: proof if they are still in utf-8 encoding

MySQL No Route to Host, mysqli_connect(): (HY000/2002)

I am trying to install BugZilla on Mac OS X 10.9 (Mavericks).
I'm hitting a snag with my MySQL configuration.
I have installed MySQL from the DMG Image mysql-5.6.14-osx10.7-x86_64
MySQL seems to be installed and running ok.
I have created a user called bugs, and a database called bugs.
I confirm that I can login to MySql from the terminal command line, using the bugs username and password, and access the bugs database.
However the installation of BugZilla fails with an error connecting to MySQL. I tried a simple test and wrote this php file:
<?php
// Create connection
$con=mysqli_connect(“localhost”,”bugs”,”********”,”bugs”);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
But it fails at line 3 with:
Warning: mysqli_connect(): (HY000/2002): No route to host in /Users/bugzilla/Sites/test_my.php on line 11
Failed to connect to MySQL: No route to host
Why is it that I can connect from the command line, but not from php?
We experienced this error because the ip subnet used by our vagrant environment was the same as the subnet of the database server. We needed to recreate the database server on a different subnet.
I just experienced a similar problem but through which it looks like there was a different problem case. I was getting the same error:
Failed to connect to the database, please check your credentials: No route to host
And we were able to figure out the problem was actually that the disk space of our database was full (our server administrator was out sick for a while, and we automatically make snapshots, but only manually delete them on a regular basis. After a few days, the snapshots took up the space of the entire server and rendered it unresponsive).
I don't know if this will be the answer to anyone with this issue, but if someone does stumble upon this same error, hopefully this might help.

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

everyone. I'm a student and very inexperience newbie with PHP . Before you mark this as irrelevant or duplicate or anything. Hear me out please, I need to connect to my school host to test out my codes, I have installed XAMPP, phpmyadmin 4.0.4.1 using notepad++ text editor, PHP5.4.19 and FTP WinSCP a program similar to filezilla
uploaded all the files to the server side public html and tried to run the file in browser
by using: my_school_link/my_username/
and I have this error
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
<?php
mysql_connect('host_name', 'user_name', 'password');
mysql_select_db('my_database_name');
?>
I cannot locate my /tmp/mysql.sock, * i have tmp folder in xampp folder but inside i cant find mysql.sock*
and I have tried the following
view nearly every post on this matter (i don't understand what is being said, thou i did try out some of the suggestions and answers)
have entered the correct hostname, username and password
run as admin
checked if mysql is running ( it is so is Apache)
MySQL socket specified in php.ini was never edited so it is in default mode
cant locate mysql config file, or my.cnf, or etc folder
What could the problem be? Please if anyone could help me, please tell me what's wrong.
Please provide a step-by-step guide. and file extensions if need to save files....
Is there any additional things i can add to help anyone understand my problem better?
if yes, please let me know...this is my last resort so Thank you so very much in advance for any help.
Warning: mysql_connect(): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2) in /my_full_filepath..../connect.php on
line 3 and this is my connect.php file.
This error appear when your mysql server is not running. If you are on an shared hosting, it means that your provider has temporary stopped mysql server (some hacks needed to be solved, or doing updates etc.)
If you are on WAMP or local machine, you should check your /etc/my.cnf file it contains something like this:
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
Another reason may be that you are using the wrong host name while connect.
Don't use mysql_connect it is deprecated and instead you should use MySqli

Confusing PDO-only problem : Can't connect through socket/Access denied/Can't connect to server (shared host)

So the problem changed from what it was, i'll leave the original question below to prevent bad reviews on answers like I had after someone editing his question I answered :
So I am working on a (really lame) shared hosting which has PDO installed, but it doesn't work.
With default parameters
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
it throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
With a simple mysql_connect, it works.
And the socket path seems correct (both phpinfo and this query :
show variables like 'socket';
confirm.
Localhost redirects to 10.103.0.14 (this data comes from mysql_get_host_info() and in phpMyAdmin)
In the PDO, if i replace localhost by 127.0.0.1 i will get
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
And if i replace localhost by 10.103.0.14 :
Access denied for user 'USER_NAME'#'10.103.0.14' (using password: YES
Both IP adress (127.0.0.1 and 10.103.0.14) work with mysql_connect.
So apparently the problem comes from the PDO connection.
Does somebody knows where this could come from, or/and any way to fix it ?
Some server datas :
The PHP Version : 5.2.10
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
No command line possible.
(i know it should be the tech suport's job, but they're reaaaaaly slow)
Thanks
Previous question :
How to find the mysql.sock on a shared host (tricky way needed...)
So today's problem is : The PDO connection doesn't work on a shared host, and it's supposed to (it's installed on the server).
Just a basic PDO connection :
<?php
try {
$dbh = new PDO('mysql:host=localhost;dbname=THE_DB_NAME', 'THE_USER', 'THE_PASSWORD');
echo 'Connected to database';
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
throws this message :
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
A regular mysql connection :
mysql_connect("localhost", "THE_USER", "THE_PWD") or die(mysql_error());
mysql_select_db("24DLJLRR1") or die(mysql_error());;
echo 'Connected to database <br/>';
works fine.
So apparently it cannot find the .sock.
I think specifying the correct address should work, i tried some "classic" mysql path that I found on internet, without success.
The phpinfo says it is at this adress (/var/lib/mysql/mysql.sock)
(The PHP Version is 5.2.10)
You can see the server's phpinfo : http://web.lerelaisinternet.com/abcd.php?v=5
So i am trying to figure out where the hell it is !!!
I tried to look in the phpMyAdmin interface, but i couldn't find the info, plus it seems that phpMyAdmin connects to a different server (it has a different IP adress, and trying to connect to it with php gives a "Wrong password" error). The mysql_connect also connects to this adress, i think it redirects to a different server with some internal password/login.
Well if you have any idea of how to obtain this info (the provider's technical support is "fixing the problem"... it's been 1 month...).
Also maybe the problem comes from somewhere else, but the same stuff works on other shared hosts...
The need of PDO is because I use the Symfony framework with Doctrine for this website, and the Doctrine plugin needs PDO... I don't want to redo the website from scratch !
Thanks for your help !
This was already marked as answered, but not really solved (without changing databases).
So, just in case someone like me also experiences this problem...
The easiest way to fix this is to first get the socket path (either by looking in the php.ini file or by using: phpmyadmin or the console (or construct it in mysql or mysqli)
...to run the following query (anything but PDO):
show variables like 'socket'; //as mentioned by symcbean
THEN, in the PDO connection string, change it to use the socket instead of a hostname:
$dbc = new
PDO("mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=$DBName",
$User, $Password, array(PDO::ATTR_PERSISTENT => true)); // using
persistent connections
This worked for me.
FWIW, I had this issue and changed my host from 'localhost' to '127.0.0.1'.
I have no clue why localhost wasn't working, but that did the trick.
Odd thing is, we have tons of servers and it works on almost every one using 'localhost'
Is your server running with SeLinux enabled (enforcing)? If it is, try running as root:
# setsebool -P httpd_can_network_connect on
Can you try 127.0.0.1 as the server name instead of localhost?
IIRC, with some mySQL drivers / adapters, this decides whether the socket is used for establishing the connection or not.
Using the connection which works, run the query:
show variables like 'socket';
(this behaves just like a select statement)...and you'll get the path of the running socket.
Then check the file permissions.
I had the problem that production version worked just fine and a test version wasn't able to connect PDO :/
both versions was located at same servers, test in a sub directory.
The fix was replacing in DSN the localhost for ip.
'mysql:host=localhost;dbname=db'
became
'mysql:host=127.0.0.1;dbname=db'
try:
exec('`which mysql_config` --socket');
this should show you the configured socket.
I found the reason for the strange behaviour. If bind-address is different to 127.0.0.1 or 0.0.0.0 (all addresses) PDO can't connect to 127.0.0.1.
For what it's worth, I found this page after having the exact same issue. I am on a server running Apache & PHP only - MySQL is installed on another machine. I tried both the DNS name of the server and its IP and confirmed I could ping it. A PHP app on the same machine is talking to the database fine, using old syntax mysql_connect( ). But PDO from the CLI was throwing this error.
The solution for me was to check my DSN. Any typo in the DSN itself is ignored silently, and PDO assumes you mean localhost. My issue was I had "name=" instead of "dbname=" in the DSN.
The Issue In the Mysql configuration It you need to disable the option of skip-networking
in my.conf configuration file this should work fine
reference
http://www.wolfcms.org/forum/post7098.html#p7098
I just solved a similar issue. My guess is you probably replaced your mysql_connect() statement with the PDO equivalent. Don't forget you still have lots of other code dependent on that old connection statement. Try keeping the mysql_connect in place while writing in the PDO code.
What worked for me was specifying the port number like so:
mysql:hostname;port=3306;dbname=dbname;
This got it to work when connecting to a local database. Now I'm working on getting it to work with a remote db.
My problem may be different to the OP, but I thought it was worth posting. I did a software upgrade on a VM, then rebooted and got the OP's error message. It turned out to be an out-of-memory problem preventing mysql from starting. Deleting a few large files made the problem go away.
One year later, I found a solution for this issue : using a SQLite database. PDO worked fine, but not with MySQL
** EDIT ** as everyone is downvoting this: This solved my issue (I'm the OP). I was using Doctrine, so switching RDBMS was easy and quick. Also the website was some a home made CMS, with very few trafic, so SQLite was fine.
I know it's not a real "Answer" to the problem, but if someone is in the same context: a crappy shared hosting which you can't change with this weird PDO-MySQL bug AND is using doctrine. This IS a solution. I can delete this answer, but if I had thought of this at the time of the OP, I would have saved a lot of time.

Categories