Connect on remote MySQL database through Python

后端 未结 4 1543
栀梦
栀梦 2020-12-09 09:33

I have tried the following script but unfortunately doesn\'t work. I am using a free MySQL database provider. Any ideas?

import MySQLdb

myDB = MySQLdb.conne         


        
相关标签:
4条回答
  • 2020-12-09 09:50
     GRANT ALL
     ON  *.*
     TO user@192.168.39.17  -- client ip address
     IDENTIFIED BY 'pwd';
    

    Edit

    This is SQL that you'd run on the database in order to ensure that the user has access to everything. pwd is the user's password.

    Basically, this answer assumes that the connection issue is a credentials issue.

    0 讨论(0)
  • 2020-12-09 10:02

    open your database in mysql and type the following :

    mysql> GRANT ALL ON *.* TO root@'x' IDENTIFIED BY 'Your-password'
    

    where x is the ip address of the user that wants to access your db.

    use this link for more information: How to Allow MySQL Client to Connect to Remote MySQL server

    0 讨论(0)
  • 2020-12-09 10:05

    This is what I would do

    1. See if the port is actually open on that machine.
    2. On the machine you are connecting from, open console/cmd/terminal and see if you can connect using mysql -u XXXX -h 208.11.220.249 -p. If your mysql client can not connect, then there is no way you can connect using python
    0 讨论(0)
  • 2020-12-09 10:09

    You don't have permission for connecting to database with this user. Follow these steps:

    1.try connecting to mysql DB: mysql -h208.11.220.249 -uXXXXX -pXXXXX XXXXX

    2.If you don't have permission for connecting to DB ,try creating user that has remote permission

    GRANT ALL ON DB.* -- Database name TO user@ip -- client ip address IDENTIFIED BY 'pwd';

    3.on the last check my.cnf . "bind-address" must be 0.0.0.0 If you want to connect all remote addresses.

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