MySQL: access outside the local machine – ubuntu server

To allow access to a MySQL database from outside the machine on an Ubuntu server, follow these steps:

  1. Update the MySQL configuration file: sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf Find the line that reads bind-address = 127.0.0.1 and change it to the IP address of your server. You can put 0.0.0.0 if you want to be accessible anywhere.
  2. Create a new MySQL user:
mysql -u root -p
CREATE USER 'username'@'%' IDENTIFIED BY 'password';

Replace “username” and “password” with your desired username and password.

  1. Grant privileges to the new user:
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%';

This grants the user all privileges on all databases and tables.

  1. Restart MySQL: sudo service mysql restart

And that’s it! Your MySQL database should now be accessible from remote machines using the username and password you created. Just be sure to properly secure your server and database to avoid any security risks.

Leave a Comment

Your email address will not be published.

Free Web Hosting