grant remote access of MySQL database from any IP address

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

    Open your mysql console and execute the following command (enter your database name,username and password):

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

    Then Execute:

    FLUSH PRIVILEGES;

    Open command line and open the file /etc/mysql/mysql.conf.d/mysqld.cnf using any editor with root privileges.

    For example:

    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
    

    Then comment out the below line:

    bind-address = 127.0.0.1

    Restart mysql to reflect the changes using command:

    sudo service mysql restart
    

    Enjoy ;)

    0 讨论(0)
  • 2020-11-22 09:24
    TO 'user'@'%'
    

    % is a wildcard - you can also do '%.domain.com' or '%.123.123.123' and things like that if you need.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-11-22 09:29
    • START MYSQL using admin user
      • mysql -u admin-user -p (ENTER PASSWORD ON PROMPT)
    • Create a new user:
      • CREATE USER 'newuser'@'%' IDENTIFIED BY 'password'; (% -> anyhost)
    • Grant Privileges:
      • GRANT SELECT,DELETE,INSERT,UPDATE ON db_name.* TO 'newuser'@'%';
      • FLUSH PRIVILEGES;

    If you are running EC2 instance don't forget to add the inbound rules in security group with MYSQL/Aurura.

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

    You need to change the mysql config file:

    Start with editing mysql config file

    vim /etc/mysql/my.cnf
    

    add:

    bind-address = 0.0.0.0
    
    0 讨论(0)
  • 2020-11-22 09:30

    In website panels like cPanel you may add a single % (percentage sign) in allowed hostnames to access your MySQL database.

    By adding a single % you can access your database from any IP or website even from desktop applications.

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