grant remote access of MySQL database from any IP address

后端 未结 21 1741
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 09:18

I am aware of this command:

GRANT ALL PRIVILEGES
ON database.*
TO \'user\'@\'yourremotehost\'
IDENTIFIED BY \'newpassword\';

But then it on

21条回答
  •  广开言路
    2020-11-22 09:24

    Config file changes are required to enable connections via localhost.

    To connect through remote IPs, Login as a "root" user and run the below queries in mysql.

    CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
    
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
    
    CREATE USER 'username'@'%' IDENTIFIED BY 'password';
    
    GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
    
    FLUSH PRIVILEGES;
    

    This will create a new user that is accessible on localhost as well as from remote IPs.

    Also comment the below line from your my.cnf file located in /etc/mysql/my.cnf

    bind-address = 127.0.0.1
    

    Restart your mysql using

    sudo service mysql restart
    

    Now you should be able to connect remotely to your mysql.

提交回复
热议问题