在 Linux 机器上安装 MySQL 时我遇到了一个奇怪的问题。
我尝试将 MySQL 配置为后端数据库以在 Airflow 上运行。以下是我的配置:
Operating System: Red Hat Enterprise Linux Server 7.7
python 3.7.2
anaconda 3
spark 2.45
我可以连接到 MySQL,但在运行 airflow initdb 命令时遇到错误。不确定为什么会发生此错误,但肯定是 MySQL 导致的。
错误:
[2020-04-09 05:19:00,990] {settings.py:253} INFO - settings.configure_orm(): Using pool settings. pool_size=5, max_overflow=10, pool_recycle=1800, pid=15499
Traceback (most recent call last):
File "/home/npa/anaconda3/envs/python3.7.6/bin/airflow", line 25, in <module>
from airflow.configuration import conf
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/airflow/__init__.py", line 47, in <module>
settings.initialize()
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/airflow/settings.py", line 377, in initialize
configure_orm()
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/airflow/settings.py", line 266, in configure_orm
engine = create_engine(SQL_ALCHEMY_CONN, **engine_args)
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/sqlalchemy/engine/__init__.py", line 479, in create_engine
return strategy.create(*args, **kwargs)
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 87, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 118, in dbapi
return __import__("MySQLdb")
File "/home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
import _mysql
ImportError: /home/npa/anaconda3/envs/python3.7.6/lib/python3.7/site-packages/_mysql.cpython-37m-x86_64-linux-gnu.so: symbol mysql_real_escape_string_quote, version libmysqlclient_18 not defined in file libmysqlclient.so.18 with link time reference
答案1
我通过创建指向该库的符号链接解决了该问题。即
实际的图书馆位于
/usr/local/mysql/lib
然后我创建了一个符号链接
/usr/lib
使用命令:
sudo ln -s /usr/local/mysql/lib/libmysqlclient_18 /usr/lib/libmysqlclient_18
因此我有以下映射:
ls -l libmysqlclient_18
lrwxr-xr-x 1 root wheel 44 16 Jul 14:01 libmysqlclient_18 -> /usr/local/mysql/lib/libmysqlclient_18
答案2
我尝试了所有方法,但最终我不得不从服务器中删除所有内容,然后再次安装 anaconda 和 MySQL 来解决问题。
我最终从 SO 中得到了下面的命令,这些命令有效。由于某些原因,MySQL 已损坏并且无法正确卸载。以下是一些最终有效并从我的系统中完全删除 MySQL 的命令。
yum remove mysql-server
pkill mysqld; pkill mysqld_safe
rpm -qa | grep mysql
yum remove <name displayed in above step-1>
sudo -H pip uninstall mysqlclient
sudo -H pip install --no-binary mysqlclient mysqlclient
rm -rf ~/anaconda3
conda install anaconda-clean
anaconda-clean
此后,我再次安装并配置了 anaconda 和 MySQL,问题得到解决。