grant remote access of MySQL database from any IP address

后端 未结 21 1274
伪装坚强ぢ
伪装坚强ぢ 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:32

    Enable Remote Access (Grant) Home / Tutorials / Mysql / Enable Remote Access (Grant) If you try to connect to your mysql server from remote machine, and run into error like below, this article is for you.

    ERROR 1130 (HY000): Host ‘1.2.3.4’ is not allowed to connect to this MySQL server

    Change mysql config

    Start with editing mysql config file

    vim /etc/mysql/my.cnf
    

    Comment out following lines.

    #bind-address           = 127.0.0.1
    #skip-networking
    

    If you do not find skip-networking line, add it and comment out it.

    Restart mysql server.

    ~ /etc/init.d/mysql restart
    

    Change GRANT privilege

    You may be surprised to see even after above change you are not getting remote access or getting access but not able to all databases.

    By default, mysql username and password you are using is allowed to access mysql-server locally. So need to update privilege.

    Run a command like below to access from all machines. (Replace USERNAME and PASSWORD by your credentials.)

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
    

    Run a command like below to give access from specific IP. (Replace USERNAME and PASSWORD by your credentials.)

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
    

    You can replace 1.2.3.4 with your IP. You can run above command many times to GRANT access from multiple IPs.

    You can also specify a separate USERNAME & PASSWORD for remote access.

    You can check final outcome by:

    SELECT * from information_schema.user_privileges where grantee like "'USERNAME'%";
    

    Finally, you may also need to run:

    mysql> FLUSH PRIVILEGES;
    

    Test Connection

    From terminal/command-line:

    mysql -h HOST -u USERNAME -pPASSWORD
    

    If you get a mysql shell, don’t forget to run show databases; to check if you have right privileges from remote machines.

    Bonus-Tip: Revoke Access

    If you accidentally grant access to a user, then better have revoking option handy.

    Following will revoke all options for USERNAME from all machines:

    mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'USERNAME'@'%';
    Following will revoke all options for USERNAME from particular IP:
    
    mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'USERNAME'@'1.2.3.4';
    Its better to check information_schema.user_privileges table after running REVOKE command.
    

    If you see USAGE privilege after running REVOKE command, its fine. It is as good as no privilege at all. I am not sure if it can be revoked.

    0 讨论(0)
  • 2020-11-22 09:33

    Use this command:

    GRANT ALL ON yourdatabasename.* TO root@'%' IDENTIFIED BY 'yourRootPassword';
    

    Then:

    FLUSH PRIVILEGES; 
    

    Then comment out the below line in file "/etc/mysql/mysql.conf.d/mysqld.cnf" (is required!):

    bind-address = 127.0.0.1 
    

    Works for me!

    0 讨论(0)
  • 2020-11-22 09:36
    GRANT ALL PRIVILEGES ON *.* TO 'user'@'ipadress'
    
    0 讨论(0)
  • 2020-11-22 09:36

    what worked for on Ubuntu is granting all privileges to the user:

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

    and setting the bind address in /etc/mysql/mysql.conf.d/mysqld.cnf:

    bind-address            = 0.0.0.0
    

    then restarting the mysql daemon:

    service mysql restart
    
    0 讨论(0)
  • 2020-11-22 09:36

    For example in my CentOS

    sudo gedit /etc/mysql/my.cnf

    comment out the following lines

    #bind-address = 127.0.0.1

    then

    sudo service mysqld restart

    0 讨论(0)
  • 2020-11-22 09:38

    Edit File:

    /etc/mysql/percona-server.cnf

    Append below code in file.

    [mysqld] bind-address = 0.0.0.0

    Create user for remote access.

    $ mysql -u root -p      
    mysql> GRANT ALL ON *.* to snippetbucketdotcom@'%' IDENTIFIED BY 'tejastank';   
    mysql> FLUSH PRIVILEGES;    
    mysql> exit
    

    All linux server works,

    For MSWin c:\ Find insatallation location \ file path

    0 讨论(0)
提交回复
热议问题