How to configure MySQL on Ubuntu to accept connections from the local network (LAN).
Replace user with the username you want to enable local network access for.
mysql -u root -p
# CREATE USER 'user'@'%' IDENTIFIED BY 'some_pass'; # Execute if creating a new user
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/mysql.conf.d/mysqld.cnf.bak
sudo sed -Ei 's/^(bind-address)/# \1/g' /etc/mysql/mysql.conf.d/mysqld.cnf
sudo /etc/init.d/mysql restart
mysql -h 192.168.99.101 -u user -p
What weโre doing
- Log in to mysql with root privileges and grant the user
userpermission to access from any IP address. - Edit mysqld.cnf. Remove bind-address as it's in the way.
- Restart mysql
- Try connecting by specifying the local IP address confirmed with ifconfig or ip. (If this succeeds, it means you can also access from clients like mysql workbench)