Skip to content

Instantly share code, notes, and snippets.

@sanikkenway
Last active November 19, 2021 03:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanikkenway/f86a8b64ec4017f34b37e398e89b3dc9 to your computer and use it in GitHub Desktop.
Save sanikkenway/f86a8b64ec4017f34b37e398e89b3dc9 to your computer and use it in GitHub Desktop.
Allow Remote Access to MySQL

Update Mysql Config

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Change from 127.0.0.1 to 0.0.0.0

. . .
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 127.0.0.1
. . .

Restart Mysql

sudo systemctl restart mysql Login into Mysql

sudo mysql

mysql -u root -p

You might rename, create or alter users

** use % instead of IP to open to all IPs

RENAME USER 'user'@'localhost' TO 'user'@'remote_server_ip';

CREATE USER 'user'@'remote_server_ip' IDENTIFIED BY 'password';

ALTER USER 'user'@'remote_server_ip' IDENTIFIED WITH mysql_native_password BY 'password';

GRANT CREATE, ALTER, DROP, INSERT, UPDATE, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'user'@'remote_server_ip' WITH GRANT OPTION;

FLUSH PRIVILEGES;

Open port 3306

Whitelist ip sudo ufw allow from remote_IP_address to any port 3306

or all ip

sudo ufw allow 3306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment