Remotely connect to MySQL with Python mysql.connector

偶尔善良 提交于 2019-12-05 18:37:11
gbe

If you're running PHPMyAdmin on the same server that your mysql daemon is running on, here's what's happening: you have your webserver configured to accept connections from all interfaces, but mysql configured to only accept local connections. Since PHPMyAdmin is colocated wit mysql, it will only be making local connections which is why it works but your code doesn't.

So, double check that your mysql daemon is configured to listen interfaces. You should have a line something like bind-address=0.0.0.0 in your mysql.cnf file. See this answer for more details.

Try to edit you non working example to this (no http in the host)

import mysql.connector
cnx = mysql.connector.connect(host='imaginarywebsite.ddns.net', database='import_test',user='user_builder', password='password***', port=3309)

Actually the answer was to use the global IP address of my server instead of the domain name, probably an issue of name management.

Replacing host='http://imaginarywebsite.ddns.net' by 'host=85.23.56.****" made it work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!