When I try to connect the MySQL database that is on my Mac to a website, I get the following error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
That is when I put localhost as the servername.
When I put 127.0.0.1 as the servername, I receive the following error:
Can't connect to MySQL server on '127.0.0.1' (13)
The following Stack questions did not work for me:
Cannot connect to mysql with 127.0.0.1
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
First, you should check the status of mysql server:
is that runs?
the difference between tow error is based on allowed mysql connection port over network.
Related
I have a laravel 5.2 project on homestead 7 which works with mysql and mongodb, I have configured it to connect to host (my mac AMPPS) mysql and mongodb servers.
mysql is connected successfully but I can't connect to host mongodb from homestead.
when I try to connect to host mongodb server from homestead using mongo command I get below error :
vagrant#homestead:~$ mongo 192.168.10.1:27017/admin
MongoDB shell version: 3.2.18
connecting to: 192.168.10.1:27017/admin
2018-01-29T13:18:36.967+0000 W NETWORK [thread1] Failed to connect to 192.168.10.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2018-01-29T13:18:36.968+0000 E QUERY [thread1] Error: couldn't connect to server 192.168.10.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
exception: connect failed
as you can see my host ip address is 192.168.10.1 and homestead ip address is 192.168.10.10.
And whenever I try to connect to mongodb from laravel mongodb driver I get below error message :
ConnectionTimeoutException in Collection.php line 174:
No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '192.168.10.1:27017']
FYI : I used This shell script to install mongodb and it's driver on homestead 7 with php 7.1
Any suggestion how to fix this ?
The solution to this problem was to edit host /etc/mongodb.conf and set bind-ip to 0.0.0.0
bind_ip = 0.0.0.0
remember to restart mongodb server, then I connected to the host mongodb server.
I need to connect to a postgres database on a remote server using PHP. I've opened an SSH tunnel on the local machine, local port 8000. The tunnel seems to work fine.
The problem arises when I attempt to connect to the db with PHP. The following code:
$ConnectionString = "host=127.0.0.1:8000 user=username password=passphrase dbname=databasename sslmode=require port=5432";
pg_connect($ConnectionString);
produces the following error:
Warning: pg_connect(): Unable to connect to PostgreSQL server: could not translate host name "127.0.0.1:8000" to address: Unknown host in [path]\mappage.php on line 22
Not connected
How, then, can I open a database connection via SSH?
For what it's worth, I can connect to the remote PostgreSQL database with PGAdmin using SSH.
As written in the manual it should be:
$ConnectionString = "host=127.0.0.1 port=8000 user=username password=passphrase dbname=databasename sslmode=require";
You had port twice and once incorrectly.
Once you've set up the tunnel, you connect to your database via 127.0.0.1. e.g. (MySQL Example):
ssh -L 127.0.0.1:8000:127.0.0.1:5432 sshuser#example.com
After that the connection parameters for my database are:
Host: 127.0.0.1 (localhost would try to connect to socket)
Port: 8000
User: username
Pass: passphrase
I am trying to connect to mysql remotely. Because this is such a common question I read several tutorials/questions but I keep getting this error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'the-ip-address' (60)
I edited the /etc/mysql/my.cnf and commented the line of bind_address like this:
#bind-address = 127.0.0.1
After that I ran:
$ sudo service mysql restart
with the output of:
mysql stop/waiting
mysql start/running, process 9853
mysql is running on default port: 3306
Using the user with which I am trying to connect remotely is working locally on the server (I can connect to the mysql from the server).
In phpmyadmin I configure these users:
user#localhost
user#127.0.0.1
user#87.45.34.23
Then I am trying to connect with the following:
mysql -u user -p -h 87.45.34.23
Maybe I am missing something... Thank you in advanced
UPDATE
As #Geoffrey suggested in the comments the problem was with a firewall. For this reason I will accept his answer although the answer itself is not for that but in the comments he was right.
Connection refused means the MySQL server is not listening or is firewalled.
By commenting out the bind line, MySQL doesn't bind to anything and only allows local socket access, you need to bind it to either the local IP, or all IPs by specifying 0.0.0.0
Also ensure that skip-networking is not set anywhere.
I'm trying to recover the root password for phpmyadmin. I followed some tricks found on the net, and now I have a deeper problem.
I can't login to phpmyadmin. I'm getting the following error:
\#2002 - Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
The server is not responding (or the local server's socket is not correctly configured).
Connection for controluser as defined in your configuration failed.
I ran the following command to verify if my MySQL is running,
mysqladmin: connect to server at 'localhost'
And I'm getting the following message:
failed error: 'Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (2)' Check that mysqld is running and
that the socket: '/var/run/mysqld/mysqld.sock' exists!
I'm not sure what to do next.
I've installed Laravel 4 on a windows machine with XAMPP and PostgreSQL on a virtual machine (Ubuntu).
I also edited below files on PostgreSQL machine (ubuntu) to work correctly:
/etc/postgresql/9.1/main/pg_hba.conf
/etc/postgresql/9.1/main/postgresql.conf
In a raw php: on my Windows machine I can connect to PostgreSQL database on the remote machine by the below code and everything is okay:
$dbconn = pg_connect("host=192.168.56.101 port=5432 dbname=gis user=gisuser password=mypass");
$sql="CREATE TABLE users (id varchar(5),name varchar(20),PRIMARY KEY(id))";
pg_exec($dbconn, $sql) or die(pg_errormessage());
now users table was created in my PostgreSQL database.
But in Laravel: I can't connect with the same config. I setup everything in database.php and when I run the following artisan command:
php artisan migrate:install
the following error occured in command line:
[PDOException]
SQLSTATE[08006] [7] could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
migrate:install [--database[="..."]]
Can anyone please help me to connect to my remote PostgreSQL server via Laravel 4 on my Windows machine?