Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to remote MySQL Server in Digital Ocean

Tags:

mysql

I am trying to connect to a remote MySQL server 5.7 installed on Ubuntu 16.04 from my workstation.

Here is the error i am getting (Using Navicat to connect).

enter image description here

To make it work I followed the following steps.

1) GRANT ALL ON database_name.* TO [email protected] IDENTIFIED BY 'your_password';

2) flush privileges;

3) sudo /etc/init.d/mysql restart

Some forums recommends commenting line starts with "bind-address" on my.cnf which resides in /etc/mysql/my.cnf. The problem is there is no such line on my installation.

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

I also tried to open ports on firewall using the following commands.

sudo ufw allow 3306/tcp
sudo service ufw restart

But still stuck with the same problem.

Update: To make MySQL to listen to all interfaces i added bind-address=0.0.0.0 to my.cnf file. Now MySQL is not even restarting and throws the following error.

demo@ubuntu:~$ sudo /etc/init.d/mysql restart
[....] Restarting mysql (via systemctl): mysql.serviceJob for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
 failed!
demo@ubuntu:~$
like image 535
Cody Avatar asked Nov 08 '22 01:11

Cody


1 Answers

Use the following ways to debugging this-

First you need to understands what the logs says- the default logs in ubuntu is stores in /var/log/mysql folder or go to mentioned location in /etc/mysql/my.cnf.

Second if you want to access your mysql server from any where location then just comment the line by putting # at starting. So please conmment the bind-address line. It will now access from any where.

[mysqld]
# bind-address=0.0.0.0

Start the mysql server and use telnet from client system with the ip & port. Check are you able to connect or not. for ex-

telnet xx.xx.xx.xx 3306

If you are able to connect then create user in mysql server, where I used % in hostname which means it can be connect from any client For ex-

GRANT ALL ON database_name.* TO 'user'@'%' IDENTIFIED BY 'your_password';

If still its showing errors then you need to post the logs.

like image 65
Hitesh Mundra Avatar answered Nov 14 '22 23:11

Hitesh Mundra