grant remote access of MySQL database from any IP address

后端 未结 21 1569
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 09:47

    Assuming that the above step is completed and MySql port 3306 is free to be accessed remotely; Don't forget to bind the public ip address in the mysql config file.

    For example on my ubuntu server:

    #nano /etc/mysql/my.cnf
    

    In the file, search for the [mysqld] section block and add the new bind address, in this example it is 192.168.0.116. It would look something like this

    ......    
    .....    
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    
    bind-address        = 127.0.0.1    
    bind-address        = 192.168.0.116
    
    .....    
    ......
    

    you can remove th localhost(127.0.0.1) binding if you choose, but then you have to specifically give an IP address to access the server on the local machine.

    Then the last step is to restart the MySql server (on ubuntu)

    stop mysql
    
    start mysql
    

    or #/etc/init.d/mysql restart for other systems

    Now the MySQL database can be accessed remotely by:

    mysql -u username -h 192.168.0.116 -p
    

提交回复
热议问题