'mysql connection refused and mysql no such file or directory
Simply connecting to mysql server, username password and host all are correct.
Still mysql_error() throws the following error:
Warning: mysql_connect(): No such file or directory in
save.php on line 6
No such file or directory
When I change it from 'localhost' to '127.0.0.1', it gives error:
Warning: mysql_connect(): Connection refused in
save.php on line 6
Connection refused
The same connection is working without any issue for a wordpress website on the same host.
When I enter wrong password, mysql throws error of password not exist
What does it mean ?
[Update]
I checked my phpinfo() and
mysql.default_socket no value no value
same for default_host, user, password etc.
I tried
ini_set("mysql.default_socket","/var/run/mysqld/mysqld.sock");
as mention in php.ini but no luck.
Again its working for a wordpress previous install and its wp_config has the same mysql access. For wrong password sometime it throws "password not exist"
Solution 1:[1]
Even i had faced similar problem. Please try this, hope it may works for you. Use mysqli instead of mysql
// Create connection
$domain = "localhost"; // or yourdomainname.com
$username = "root"; // db username
$password = "pass123"; // db password
$dbName = "gymchalo"; // db name
$con = mysqli_connect($domain,$username,$password,$dbName);
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die('Mysql connection error');
}else{
echo "Connection Established";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vinit Kadkol |
