napalias
napalias

Reputation: 1205

Connect to Mysql database from remote

Problem: I have server where is install Laravel app and database. But i want share same database with another server. And i want enable remote access.

What i tried: I changed config file /etc/mysql/mysql.conf commented out bind-address = 127.0.0.1

Also changed to bind-address = 0.0.0.0 or bind-address = *, not helps (this is what everywhere i found to do)

ufw is disabled

netstat -ltn returns

Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     

isn't 127.0.0.1:3306 suppose to be 0.0.0.1:3306?

I try connect from another server

mysql -h xxx.xxx.xxx.xxx -u pf_remote -p

i got error

Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)

I think that port is not open, but where else i can open. Do i miss something?

Upvotes: 0

Views: 212

Answers (2)

Umair Ayub
Umair Ayub

Reputation: 21201

Find mysql.conf and set

bind-address=0.0.0.0

Then login to MySQL and run below 2 commands

GRANT ALL PRIVILEGES ON *.* TO 'pf_remote'@'%' IDENTIFIED BY 'your_password' with grant option;
flush privileges;

then

sudo service mysql restart

Then also make sure you do not have any firewall blocking connections, check by

sudo ufw status

If its enabled, then allow remote connections to MySQL port

sudo ufw allow 3306 && sudo ufw reload

If you are using Amazon Web Services server then allowing connections from within shell won't work, you will have to allow connections from AWS Dashboard

Upvotes: 1

deevee
deevee

Reputation: 1845

Try to grant priviliges to user for remote access:

 mysql> GRANT ALL ON yourDatabase.* TO user@'1.2.3.4' IDENTIFIED BY 'yourPassword';

Also please remember to restart your mysql service after config changes:

sudo /etc/init.d/mysql restart

Upvotes: 0

Related Questions