Data Science/DB+SQL

[MYSQL] root 원격 접속 허용

DS-9VM 2021. 6. 17. 11:56
728x90

 

1) local 에서 mysql 실행. 
etc/mysql/mysql -u root 

2) Grant privileges. As root user execute with this substituting 'password' with your current root password :

RENAME USER 'root'@'localhost' TO 'root'@'%';
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';

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

FLUSH PRIVILEGES;

SELECT User, Host, plugin, authentication_string FROM mysql.user;



3) bind to all addresses:
The easiest way is to comment out the line in your my.cnf file:

#bind-address = 127.0.0.1 


4) restart mysql

service mysql restart

# or 

/etc/init.d/mysql stop
/etc/init.d/mysql start



By default it binds only to localhost, but if you comment the line it binds to all interfaces it finds. Commenting out the line is equivalent to bind-address=*.
To check where mysql service has binded execute as root:

netstat -tupan | grep mysql

 

728x90