【发布时间】:2022-10-02 17:31:02
【问题描述】:
我想使用 python SQLalchemy 连接到 Synology NAS 中的 MariaDB10 数据库。我安装了 PhpMyAdmin,并创建了一个名为 \"test\" 的数据库和一个名为 \"company\" 的随机表。我已经通过界面在表中插入了几行虚拟数据。这是它的快照。
我的代码是这样的:
# Module Imports
import sqlalchemy
import pymysql
from sqlalchemy.ext.declarative import declarative_base
import config_maria_us
# Define the MariaDB engine using MariaDB Connector/Python
user = \"username\"
passwd = \"password\"
host = \"192.168.1.111\"
db = \"test\"
port= \"3307\"
engine = sqlalchemy.create_engine(f\'mysql+pymysql://{user}:{passwd}@{host}:{port}/{db}\')
sql_df = engine.execute(\"SELECT * FROM company\" ).fetchall()
但这会返回一个错误:
OperationalError: (2003, \"Can\'t connect to MySQL server on \'192.168.1.111\' ([Errno 61] Connection refused)\")
因为这个page,所以我一直使用create_engine(\"mysql+pymysql:。它说要连接到 MariaDB 数据库,不需要更改数据库 URL。
我关注了这个page,并尝试通过brew install mariadb SQLAlchemy 安装mariadb SQLAlchemy。但它显示警告Warning: No available formula with the name \"sqlalchemy\". Did you mean sqlancer?
然后我当然用brew install mariadb-connector-c安装了MariaDB Connector/C(通过page)并用pip install PyMySQL安装了PyMySQL。其实一开始我尝试用brew install mariadb安装mariadb,但是加载一堆东西后,显示失败,
Error: Cannot install mariadb because conflicting formulae are installed.
mysql: because mariadb, mysql, and percona install the same binaries
Please `brew unlink mysql` before continuing.
Unlinking removes a formula\'s symlinks from /opt/homebrew. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side effects in the
resulting software.
我没有继续安装它,因为我不知道如何在取消链接后“重新链接”MySQL。
差不多就这些了,谁能告诉我怎么办?通过运行 \"engine = ...\" 语法,看起来我至少到达了我的服务器,但它仍然无法连接为\'(pymysql.err.OperationalError) (2003, \"Can\'t connect to MySQL server\'
标签: python sqlalchemy mariadb apple-m1 nas