MySQL: How to allow remote connection to mysql

后端 未结 16 1133
北海茫月
北海茫月 2020-11-21 06:15

I have installed MySQL Community Edition 5.5 on my local machine and I want to allow remote connections so that I can connect from external source.

How can I do that

相关标签:
16条回答
  • 2020-11-21 06:46

    This blog How to setup a MySQL server on Local Area Network will be useful in setting up a MySQL from scratch

    0 讨论(0)
  • 2020-11-21 06:48

    If your MySQL server process is listening on 127.0.0.1 or ::1 only then you will not be able to connect remotely. If you have a bind-address setting in /etc/my.cnf this might be the source of the problem.

    You will also have to add privileges for a non-localhost user as well.

    0 讨论(0)
  • 2020-11-21 06:49

    If you installed MySQL from brew it really does only listen on the local interface by default. To fix that you need to edit /usr/local/etc/my.cnf and change the bind-address from 127.0.0.1 to *.

    Then run brew services restart mysql.

    0 讨论(0)
  • 2020-11-21 06:50

    In my case I was trying to connect to a remote mysql server on cent OS. After going through a lot of solutions (granting all privileges, removing ip bindings,enabling networking) problem was still not getting solved.

    As it turned out, while looking into various solutions,I came across iptables, which made me realize mysql port 3306 was not accepting connections.

    Here is a small note on how I checked and resolved this issue.

    • Checking if port is accepting connections:
    telnet (mysql server ip) [portNo]
    • Adding ip table rule to allow connections on the port:
    iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
    • Would not recommend this for production environment, but if your iptables are not configured properly, adding the rules might not still solve the issue. In that case following should be done:
    service iptables stop

    Hope this helps.

    0 讨论(0)
  • 2020-11-21 06:50

    Please follow the below mentioned steps inorder to set the wildcard remote access for MySQL User.

    (1) Open cmd.

    (2) navigate to path C:\Program Files\MySQL\MySQL Server 5.X\bin and run this command.

    mysql -u root -p

    (3) Enter the root password.

    (4) Execute the following command to provide the permission.

    GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'IP' IDENTIFIED BY 'PASSWORD';

    USERNAME: Username you wish to connect to MySQL server.

    IP: Public IP address from where you wish to allow access to MySQL server.

    PASSWORD: Password of the username used.

    IP can be replaced with % to allow user to connect from any IP address.

    (5) Flush the previleges by following command and exit.

    FLUSH PRIVILEGES;

    exit; or \q

    0 讨论(0)
  • 2020-11-21 06:52

    That is allowed by default on MySQL.

    What is disabled by default is remote root access. If you want to enable that, run this SQL command locally:

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

    And then find the following line and comment it out in your my.cnf file, which usually lives on /etc/mysql/my.cnf on Unix/OSX systems. In some cases the location for the file is /etc/mysql/mysql.conf.d/mysqld.cnf).

    If it's a Windows system, you can find it in the MySQL installation directory, usually something like C:\Program Files\MySQL\MySQL Server 5.5\ and the filename will be my.ini.

    Change line

     bind-address = 127.0.0.1
    

    to

     #bind-address = 127.0.0.1
    

    And restart the MySQL server (Unix/OSX, and Windows) for the changes to take effect.

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