Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.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 使用sqlalchemy读取sql数据库:操作错误[Errno 111]连接被拒绝_Python_Pandas_Sqlalchemy_Operationalerror - Fatal编程技术网

Python 使用sqlalchemy读取sql数据库:操作错误[Errno 111]连接被拒绝

Python 使用sqlalchemy读取sql数据库:操作错误[Errno 111]连接被拒绝,python,pandas,sqlalchemy,operationalerror,Python,Pandas,Sqlalchemy,Operationalerror,这很好用 from sqlalchemy import create_engine import pandas as pd db_connection_str = 'mysql+pymysql://User:PW@localhost/DBName' db_connection = create_engine(db_connection_str) df = pd.read_sql('SELECT * FROM tablename', con=db_connection) 如果我用IP替换lo

这很好用

from sqlalchemy import create_engine
import pandas as pd

db_connection_str = 'mysql+pymysql://User:PW@localhost/DBName'
db_connection = create_engine(db_connection_str)

df = pd.read_sql('SELECT * FROM tablename', con=db_connection)
如果我用IP替换
localhost
,则不会

from sqlalchemy import create_engine
import pandas as pd

db_connection_str = 'mysql+pymysql://User:PW@192.168.0.7/DBName'
db_connection = create_engine(db_connection_str)

df = pd.read_sql('SELECT * FROM tablename', con=db_connection)
OperationalError:(pymysql.err.OperationalError)(2003,“无法连接到'192.168.0.7'上的MySQL服务器([Errno 111]连接被拒绝)”) (此错误的背景信息位于:)

但是有必要用IP替换localhost,因为我想从客户端执行脚本

编辑:在我的
/etc/mysql/my.cnf
中没有
绑定地址:
-因此我添加了最后一行:

# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

bind-address = 0.0.0.0
并执行
sudo systemctl restart mariadb

现在我有一条新的错误消息:

InternalError:(pymysql.err.InternalError)数据包序列号 错误-获取1应为0(此错误的背景信息位于: )


内部错误的解决方案:数据包序列号错误-获取1预期的0
错误可在此处找到:

检查MySQL服务器配置,查看是否设置了
绑定地址(或默认值)到
localhost
。尝试直接从PyMySQL运行以检查连接。如果使用
localhost
,则测试脚本正常工作,但它与IP不兼容:
InternalError:Packet sequence number error-得到1预期为0