我在cPanel中有一个Python脚本,需要将我的脚本连接到MYSQL,为了将Python连接到MYSQL,我需要有libmysqlclient

运行代码时,系统显示以下错误

File "/usr/lib64/python3.6/site-packages/MySQLdb/init.py", line 19, in <module>
import _mysql
ImportError: /usr/lib64/libmysqlclient.so.18: version `libmysqlclient_16' not found (required by /usr/lib64/python3.6/site-packages/_mysql.cpython-36m-x86_64-linux-gnu.so)



服务器操作系统:Centos 6.9
cpanel版本:68.0.13


libmysqlclient中的/usr/lib64列表

/usr/lib64/libmysqlclient_r.so.15
/usr/lib64/libmysqlclient.so
/usr/lib64/libmysqlclient.so.16.0.0
/usr/lib64/libmysqlclient_r.so.16.0.0
/usr/lib64/libmysqlclient.so.15.0.0
/usr/lib64/libmysqlclient_r.so.18
/usr/lib64/libmysqlclient_r.so.18.1.0
/usr/lib64/libmysqlclient.so.15
/usr/lib64/libmysqlclient_r.so.15.0.0
/usr/lib64/mysql/libmysqlclient.a
/usr/lib64/mysql/libmysqlclient_r.a
/usr/lib64/libmysqlclient.so.16
/usr/lib64/libmysqlclient_r.so
/usr/lib64/libmysqlclient_r.so.16
/usr/lib64/libmysqlclient.so.18
/usr/lib64/libmysqlclient.so.18.1.0

最佳答案

您可以使用mysql.connector

在ubuntu上:python 3的sudo apt-get install python-mysql.connectorpython3-mysql.connector

然后:

import mysql.connector
mysql.connector.connect(host='localhost',database='mysql',user='root',password='')

09-25 20:33