Skip to content

Instantly share code, notes, and snippets.

@conkonig
Last active July 1, 2020 17:10
Show Gist options
  • Save conkonig/422a77fd17791f09356716b8a1ed35ca to your computer and use it in GitHub Desktop.
Save conkonig/422a77fd17791f09356716b8a1ed35ca to your computer and use it in GitHub Desktop.
Enable remote connections to a mysql (mariadb) server running ubuntu 18.04
# edit the my.cnf file in /etc/mysql and add the line
bind-address=0.0.0.0
# and if you have the line:
skip-networking
# make sure to comment it:
#skip-networking
# restart mysql
sudo service mysql restart
# make sure to allow mysql connections through the firewall (below for ufw)
ufw allow mysql
# make sure to allow the remote ip addresses through the firewall (for google data studio example):
sudo ufw allow from 64.18.0.0/20
sudo ufw allow from 64.233.160.0/19
sudo ufw allow from 66.102.0.0/20
sudo ufw allow from 66.249.80.0/20
sudo ufw allow from 72.14.192.0/18
sudo ufw allow from 74.125.0.0/16
sudo ufw allow from 108.177.8.0/21
sudo ufw allow from 173.194.0.0/16
sudo ufw allow from 207.126.144.0/20
sudo ufw allow from 209.85.128.0/17
sudo ufw allow from 216.58.192.0/19
sudo ufw allow from 216.239.32.0/19
# create a user inside of mysql and give it privileges granted for the specific db (replace my_database)
CREATE USER my_user IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'%' WITH GRANT OPTION;
# for READ ONLY privileges for ALL databases
GRANT SELECT, SHOW VIEW, PROCESS, REPLICATION CLIENT ON *.* TO 'my_user'@'%';
# If you need to change a password
UPDATE mysql.user SET Password = PASSWORD('something_new') WHERE User = 'my_user';
# finally flush privileges
FLUSH PRIVILEGES;
# check the port mysql is running on with
netstat -tlnp
# your remote connect credentials should be as below
user=my_user
password=password
databases=my_database
host=192.168.0.1 (replace with your host IP)
port=3306 (or whatever you got)
# example
mysql -u my_user -h 192.168.0.1 -P 3306 -D my_database -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment