Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在我自己的笔记本电脑上连接到运行在raspberry pi上的MySQL_Python_Mysql_Raspbian - Fatal编程技术网

Python 在我自己的笔记本电脑上连接到运行在raspberry pi上的MySQL

Python 在我自己的笔记本电脑上连接到运行在raspberry pi上的MySQL,python,mysql,raspbian,Python,Mysql,Raspbian,我在连接数据库时遇到问题。我已经测试了用户名和密码。它工作正常,可以登录到数据库。数据库一直在运行 这是我自己的笔记本电脑中python的代码,而不是虚拟机 import mysql.connector try: connection = mysql.connector.connect( user='myname', password='mypw', host='169.254.X.X', database='GarageParking') print('succes

我在连接数据库时遇到问题。我已经测试了用户名和密码。它工作正常,可以登录到数据库。数据库一直在运行

这是我自己的笔记本电脑中python的代码,而不是虚拟机

import mysql.connector

try:
    connection = mysql.connector.connect(
    user='myname', password='mypw', host='169.254.X.X', database='GarageParking') 
    print('success')
except mysql.connector.Error as e:
    print("Database not successful")
主机是raspberrypi的ip地址。我已经将mysql配置文件编辑为0.0.0.0。我只是在连接数据库而不是登录时遇到问题

错误是 2003:无法连接到“169.254.X.X:3306”上的MySQL服务器(10061无法连接,因为目标计算机主动拒绝)

phpMyadmin
我感谢你的帮助

我已经解决了alr。对于那些想要访问运行在raspberry pi上的mysql的用户

import mysql.connector

try:
    connection = mysql.connector.connect(
    user='x', password='x', host='169.254.X.X', database='xx', 
    port=3306) // The host is the ip addr of the raspberry pi which also runs mysql.
    print('success')
except mysql.connector.Error as e:
    print(e)
记住在my.cnf中注释掉绑定地址

命令是

 sudo nano /etc/mysql/my.cnf
请检查my.cnf文件中是否意外添加了任何内容,并将其适当删除

修改后,重新启动服务器

 sudo service mysql restart

请创建一个可以来自任何主机的用户。在这种情况下,它是一个#。请指定在phpmyadmin web中选择任何主机。

会发生什么?@DanielRoseman,它会不断遇到数据库不成功的异常。我不知道,是不是主机的输入有问题?不知道。如果您没有捕获错误并打印模糊的消息,而是显示了实际的异常,我们也许可以解决它。@DanielRoseman,打印出错误。2003:无法连接到“169.254.X.X:3306”上的MySQL服务器(10061无法连接,因为目标计算机主动拒绝了它)。我已经把绑定地址注释掉了。但仍然不是working@DanielRoseman哦,它在工作。我可能不小心在配置文件中添加了smth。谢谢