How to connect to MySQL server on another host?

前端 未结 1 1736
暗喜
暗喜 2020-12-18 03:18

Django can simply connect to its own MySQL server by setting HOST and PORT in settings.py as \'\' (empty string):

DATA         


        
相关标签:
1条回答
  • 2020-12-18 03:40

    By default, Debian-based distros configure MySQL to bind to localhost only, which means that other hosts cannot connect to it. Fix your MySQL configuration and it will work.

    Edit /etc/mysql/my.cnf and change this line:

    bind-address = 127.0.0.1
    

    To this:

    bind-address = 0.0.0.0
    

    This will expose MySQL to all network interfaces, so make sure that you have security measures in place if this server is exposed to untrusted hosts.

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