How to allow remote connection to mysql?

by Devansh


Posted on 03 Oct 2019 11:10:06 (1 month ago)




Mainly in MySQL remote login is enabled by default but not in the case for 'root'. If you want to enable you need to login to 'root' user in command line. Below is the command,

sudo mysql -u root -p

Then enter your password. After successfull login you need to type below command,

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;

After that go to 'my.cnf file',
For Linux's path: '/etc/mysql/my.cnf' or '/etc/mysql/mysql.conf.d/mysqld.cnf'
For Window's path: 'C:\Program Files\MySQL\MySQL Server*\'

After opening the 'my.cnf' file comment out the following line,
Change below line,

bind-address = 127.0.0.1

to

#bind-address = 127.0.0.1

After that restart the MySQL server.