[Solved] Recorder MySQL module import errors

I’ve spent a good half a day picking away at this one. Maybe y’all can shed some light.

Fedora 31 (Server Edition)
Home Assistant 0.103.6 (though I tried with a pervious version as well)

I’ve tried both of these db_url lines:

recorder:
  db_url: mysql+mysqlconnector://hass:[email protected]:3306/hass?charset=utf8
  db_url: mysql+mysqldb://hass:[email protected]:3306/hass?charset=utf8

Errors have been various version of

ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: No module named 'mysql' (retrying in 3 seconds)

Recorder works fine, if I leave it to write to the default.

(homeassistant) [homeassistant@iris ~]$ pip list
Package                Version
---------------------- ----------
aiohttp                3.6.1
argcomplete            1.10.0
astral                 1.10.1
async-timeout          3.0.1
attrs                  19.3.0
bcrypt                 3.1.7
certifi                2019.11.28
cffi                   1.14.0
chardet                3.0.4
configobj              5.0.6
cryptography           2.8
dbus-python            1.2.8
decorator              4.4.0
distro                 1.4.0
dnspython              1.16.0
Glances                3.1.0
gpg                    1.13.1
homeassistant          0.105.5
idna                   2.8
importlib-metadata     1.4.0
Jinja2                 2.11.1
libcomps               0.1.14
MarkupSafe             1.1.1
multidict              4.7.4
mysql-connector        2.2.9
mysql-connector-python 8.0.19
mysqlclient            1.4.6
perf                   0.1
pip                    19.1.1
protobuf               3.6.1
psutil                 5.6.3
pycparser              2.19
PyGObject              3.34.0
PyJWT                  1.7.1
PyMySQL                0.9.3
python-augeas          0.5.0
python-dateutil        2.8.0
python-dmidecode       3.12.2
python-linux-procfs    0.6.1
python-slugify         4.0.0
pytz                   2019.3
pyudev                 0.21.0
PyYAML                 5.3
requests               2.22.0
rpm                    4.15.1
ruamel.yaml            0.15.100
schedutils             0.6
selinux                2.9
sepolicy               1.1
setools                4.2.2
setroubleshoot         1.1
setuptools             41.2.0
six                    1.12.0
slip                   0.6.4
slip.dbus              0.6.4
sos                    3.8
SQLAlchemy             1.3.13
systemd-python         234
text-unidecode         1.3
urllib3                1.25.8
virtualenv             16.6.1
voluptuous             0.11.7
voluptuous-serialize   2.3.0
yarl                   1.4.2
zipp                   3.0.0

Installed packages:

python3-libreport-2.12.0-1.fc31.x86_64
python3-abrt-2.14.0-1.fc31.x86_64
python3-schedutils-0.6-8.fc31.x86_64
python-wheel-wheel-0.33.1-3.fc31.noarch
python3-3.7.6-2.fc31.x86_64
python3-slip-0.6.4-16.fc31.noarch
python-pip-wheel-19.1.1-7.fc31.noarch
python3-setuptools-41.2.0-1.fc31.noarch
python3-firewall-0.7.3-1.fc31.noarch
python3-distro-1.4.0-2.fc31.noarch
python3-libselinux-2.9-5.fc31.x86_64
python3-argcomplete-1.10.0-1.fc31.noarch
python3-libsemanage-2.9-3.fc31.x86_64
python3-libdnf-0.43.1-2.fc31.x86_64
python3-psutil-5.6.3-2.fc31.x86_64
python3-abrt-addon-2.14.0-1.fc31.noarch
python3-hawkey-0.43.1-2.fc31.x86_64
python3-dnf-4.2.18-1.fc31.noarch
python3-linux-procfs-0.6.1-3.fc31.noarch
python3-perf-5.4.7-200.fc31.x86_64
python-setuptools-wheel-41.2.0-1.fc31.noarch
policycoreutils-python-utils-2.9-5.fc31.noarch
python3-systemd-234-9.fc31.x86_64
python3-libcomps-0.1.14-1.fc31.x86_64
python-unversioned-command-3.7.6-2.fc31.noarch
python3-augeas-0.5.0-15.fc31.noarch
python3-gpg-1.13.1-3.fc31.x86_64
python3-rpm-4.15.1-1.fc31.x86_64
python3-setools-4.2.2-1.fc31.x86_64
python3-pip-19.1.1-7.fc31.noarch
python3-dmidecode-3.12.2-16.fc31.x86_64
python3-devel-3.7.6-2.fc31.x86_64
python-systemd-doc-234-9.fc31.x86_64
python3-dnf-plugins-core-4.0.13-1.fc31.noarch
python3-configobj-5.0.6-16.fc31.noarch
python3-policycoreutils-2.9-5.fc31.noarch
python3-dbus-1.2.8-6.fc31.x86_64
python3-six-1.12.0-2.fc31.noarch
python3-gobject-base-3.34.0-3.fc31.x86_64
python3-decorator-4.4.0-2.fc31.noarch
python3-dateutil-2.8.0-3.fc31.noarch
python3-libxml2-2.9.10-3.fc31.x86_64
python3-pyudev-0.21.0-11.fc31.noarch
python3-virtualenv-16.6.1-2.fc31.noarch
python3-libs-3.7.6-2.fc31.x86_64
python3-audit-3.0-0.15.20191104git1c2f876.fc31.x86_64
python3-unbound-1.9.6-1.fc31.x86_64
python3-slip-dbus-0.6.4-16.fc31.noarch
mariadb-server-10.3.21-3.fc31.x86_64
mariadb-errmsg-10.3.21-3.fc31.x86_64
mariadb-cracklib-password-check-10.3.21-3.fc31.x86_64
mariadb-devel-10.3.21-3.fc31.x86_64
mariadb-connector-c-config-3.1.7-1.fc31.noarch
mariadb-gssapi-server-10.3.21-3.fc31.x86_64
mariadb-common-10.3.21-3.fc31.x86_64
mariadb-server-utils-10.3.21-3.fc31.x86_64
mariadb-connector-c-3.1.7-1.fc31.x86_64
mariadb-backup-10.3.21-3.fc31.x86_64
mariadb-connector-c-devel-3.1.7-1.fc31.x86_64
mariadb-10.3.21-3.fc31.x86_64

For anyone who runs into this issue in the future, check that you’re in the correct venv. I’ve been using this command set from the docs for weeks, but something must have gone weird. After double checking my pip list this morning, I noticed that I wasn’t in the right env.

I rebooted, logged in again, ran these commands from the docs:

sudo -u homeassistant -H -s
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant

Ran pip install mysqlclient and now this url works:

db_url: mysql+mysqldb://hass:[email protected]:3306/hass?charset=utf8