Migrating Hassbian to MySQL

Hi,

I’ve installed MySQL on Hassbian but I keep getting this error

2017-11-21 16:55:47 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: No module named 'MySQLdb' (retrying in 3 seconds)
2017-11-21 16:55:50 ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: No module named 'MySQLdb' (retrying in 3 seconds) 

Anyone else ran into this issue and can assist ?
Thanks in advance

1 Like

Hello, seems mysqlclient is not installed in the python environment used by Home Assistant.
Can you try to do the following in console:
$ sudo systemctl stop [email protected]
$ sudo su -s /bin/bash homeassistant
$ source /srv/homeassistant/bin/activate
$ pip3 install mysqlclient
$ exit
$ sudo systemctl start [email protected]
It should install mysqlclient properly

8 Likes

Thanks, this is what I was missing, now it works like a charm

Good day, can you share your installation procedure. Did you use the script?
sudo hassbian-config install Mssql?
Thank you

No, I haven’t… wasn’t aware of the fact a script exist, this is what I did :

sudo apt-get install libmysqlclient-dev libssl-dev
sudo pip3 install mysqlclient
CREATE DATABASE hass_db;
CREATE USER 'hassuser'@'localhost' IDENTIFIED BY '<YOURPASSWORD>';
GRANT ALL PRIVILEGES ON hass_db.* TO 'hassuser'@'localhost';
FLUSH PRIVILEGES;
quit

sudo su homeassistant -s /bin/bash  
source /srv/homeassistant/bin/activate
pip3 install mysqlclient

And my configuration.yaml something like that :

recorder:
  db_url: mysql://hassuser:<YOURPASSWORD>@localhost/hass_db

Thank you
Are you on hassbian stretch?

Yes, I am, moved to it as part of recent HASS upgrades

hey juan - i just installed mysql with the hassbian-config tools. At the end it says mysql and the mysqlclient was successful. I can’t for the live of me figure how to create the database and database user. can you let me know the steps you took. thanks

Hi steps in this link
https://github.com/home-assistant/hassbian-scripts/blob/dev/docs/mssql.md

I can’t figure out where to run sudo mysql -u root -p command from. cmd prompt returns β€” sudo:mysql: command not found.

Thank you for that answer, you just made my day.

Hi, I’ve done this, and got this message:

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting mysqlclient
  Downloading https://www.piwheels.org/simple/mysqlclient/mysqlclient-1.4.4-cp37-cp37m-linux_armv7l.whl (106kB)
    100% |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 112kB 1.6MB/s 
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.4.4

It seems to have installed OK, however when restarting HA I get this error:

ERROR (Recorder) [homeassistant.components.recorder] Error during connection setup: libmariadb.so.3: cannot open shared object file: No such file or directory (retrying in 3 seconds)

Do I need to install something else?

You might be missing one of these (sudo apt install these)

  • libmariadbclient-dev
  • default-libmysqlclient-dev
  • libssl-dev
  • mariadb-server
  • python-pymysql
  • python-dev