After a php verison change i have the following error
Warning: mysqli::mysqli(): (HY000/2005): Unknown MySQL server host
'clouddb.myhost.gr:3306' (2) in
/var/www/vhosts/mywebside.gr/httpdocs/system/library/db/mysqli.php on
line 7Warning: DB\MySQLi::__construct(): Couldn't fetch mysqli in
/var/www/vhosts/mywebside.gr/httpdocs/system/library/db/mysqli.php on
line 10Warning: DB\MySQLi::__construct(): Couldn't fetch mysqli in
/var/www/vhosts/mywebside.gr/httpdocs/system/library/db/mysqli.php on
line 10 .
And i cant understand what is the problem
You might be passing the clouddb.myhost.gr:3306 all together, on the mysqlcli, the port have its own parameter:
mysql:host=clouddb.myhost.gr;port=3306;
Related question:
SQLSTATE[HY000] [2005] Unknown MySQL server host 'mysql1.alwaysdata.com:3306' (2)
Related
I tried to use php to connect to a MySQL sever running on another computer on the same network.
Server IP: 192.168.0.111
My IP: 192.168.0.109
I am currently using XAMPP which I just upgraded to version 8.0.0. After the upgrade, I got a few errors on my screen:
Warning: Packets out of order. Expected 0 received 1. Packet size=72 in C:\xampp\htdocs\submit.php on line 95
Warning: mysqli::__construct(): Error while reading greeting packet. PID=28684 in C:\xampp\htdocs\submit.php on line 95
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\submit.php on line 95
Connection failed: MySQL server has gone away
MySQL server is running on the default port 3306 and here are the latest logs:
2020-12-27 16:11:21 29 [Warning] IP address '192.168.0.109' has been resolved to the host name '192.168.0.109', which resembles IPv4-address itself.
2020-12-27 16:11:21 29 [Warning] Aborted connection 29 to db: 'unconnected' user: 'unauthenticated' host: '192.168.0.109' (This connection closed normally without authentication)
The server is not using any password at the moment.
What can I do to fix this issue?
Thanks.
[update] I see no errors when I use server name as 'localhost' when the php file is on the MySQL server.
This question already has answers here:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
(17 answers)
Closed 2 years ago.
I'm totally stuck having spent a couple of days trying to figure this out...
I have set up an Apache web server (version 2.4.34) on my Mac OS running Mojave (10.14.3) and have installed the current version of MySQL Community Server (8.0.15). Both running perfectly as I can determine (from command line). I have PHP 7.1.23 installed. When I create a .php file with the following code and put it in my Sites directory and then in Safari go to http://localhost/~dave/hello.php I get this error:
"Warning: mysqli::__construct(): (HY000/2002): No such file or
directory in /Users/dave/Sites/hello.php on line 7 Connection failed:
No such file or directory".
Code in hello.php:
<?php
$servername = "localhost";
$username = "dave";
$password = "*****";
//Create connection
$conn = new mysqli($servername, $username, $password);
//Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
I have tried everything I can think of, including those suggestions in the other two similar posts (this one: My database user exists, but I still get an (HY000/2002): No such file or directory and this one: PHP Warning: mysqli::__construct(): (HY000/2002): No such file or directory (Debian GNU/Linux 9)), and I cannot connect to MySQl with php. In particular, I checked with the php info page and the socket for mysqli is given as var/mysql/mysql.sock. In the relevant table in mysql the value for socket is given as /tmp/mysql.sock. I tried changing the php.ini.default file by adding each of these sockets (in place of the empty value) and neither worked (still generates the same error). I thought that the 2002 MySQL socket error might be the problem, so I made a symlink by doing this:
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
but all that did was generate a new error:
Warning: mysqli::__construct(): The server requested authentication
method unknown to the client [caching_sha2_password] in
/Users/dave/Sites/hello.php on line 7
Warning: mysqli::__construct(): (HY000/2054): The server requested
authentication method unknown to the client in
/Users/dave/Sites/hello.php on line 7 Connection failed: The server
requested authentication method unknown to the client
So I removed the symlink...and returned to the original error.
I also tried replacing "localhost" with the IP address 127.0.0.1 as well as "localhost:3306" as other question threads have suggested. Nothing worked here either.
Please help, I am new to this kind of use of the computer/web design and I'm out of obvious (googleable/understandable) options.
Use 127.0.0.1 instead of localhost.
I got some help from some local tech guys in my area and it turns out that fixing the socket error was the first step, like I tried to do above. I eventually did it this way, using the solution by noun:
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
The second error message was then generated (same one as in my question, here again):
mysqli::__construct(): The server requested authentication method unknown to the client [caching_sha2_password] in /Users/dave/Sites/hello.php on line 7
Warning: mysqli::__construct(): (HY000/2054): The server requested authentication method unknown to the client in /Users/dave/Sites/hello.php on line 7
This was fixed by the SQL-based solution (June 9 2018 answer) to this question:
php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
This SQL statement was simply run in MySQL from the terminal. After restarting the Apache server I reloaded the .php file in Safari and this resulted in a successful mysqli connection to MySQL with PHP. I also tried a PDO connection and this also worked.
I have a problem with mysqli connection, in my project sometimes appears the following error:
Warning: mysqli_connect(): (HY000/2001): Can't create UNIX socket (12)
line error code is as follows:
$this->cnx_ = mysqli_connect($this->server_, $this->user_, $this->pass_,$this->db_);
I searched about it and can't find the solution...
Thanks!
Ive set up phpmyadmin and mySql on my windows server but when i try to connect via php i get this error :
Warning: mysqli::mysqli(): MySQL server has gone away in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Warning: mysqli::mysqli(): Error while reading greeting packet. PID=15852 in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Warning: mysqli::mysqli(): (HY000/2006): MySQL server has gone away in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 5
Catchable fatal error: Object of class mysqli could not be converted to string in C:\xampp\htdocs\newservertest\dbscripts\sqlconnection.php on line 14
I know by default mySql only allows local connections but following tutorials online they are all saying to uncomment a line in a "my.ini" file. All i have in my sql folder is a my-default.ini with the following :
How can i open this up to connections from an external php script?
Try adding this to your php.ini:
mysqli.reconnect = 1
I am developing on mac using MAMP
I try to connect to my local mysql database from php:
$con=mysqli_connect("localhost","root","root","testDB");
this is the error I get:
Warning: mysqli_connect(): (HY000/2002): No such file or directory in
/Users/tshahar/Documents/Dev/server/test.php on line 20 Failed to
connect to MySQL: No such file or directory
To summarize, use:
127.0.0.1
Instead of:
localhost
The reason is that "localhost" is a special name for the mysql driver making it use the unix socket to connect to mysql instead of the a tcp socket.
refer this link:
click here to example
source from:1
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
Try using IP instead for local host that would be 127.0.0.1 or ::1 if your system does IPV6.
can't really tell you why that is but I guess the SQL won't answer to a domain name because it's configured that way.(had the same problem yesterday)