以下是從Ubuntu系統上的Ubuntu存儲庫安裝MariaDB 10.1的命令:
sudo apt update sudo apt install mariadb-server
以下是從Ubuntu系統上的MariaDB存儲庫運行以安裝MariaDB 10.3的命令:
sudo apt-get install software-properties-common sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 sudo add-apt-repository'deb [arch = amd64,arm64,ppc64el] http://mirrors.neusoft.edu.cn/mariadb/repo/10.3/ubuntu bionic main'
您還可以創建自定義MariaDB sources.list文件。為此,在導入如上所述的簽名密鑰后,將以下內容復制並粘貼到/etc/apt/sources.list.d / 下的文件中(我們建議命名文件MariaDB.list或類似的東西),或者添加它在/etc/apt/sources.list文件的底部。
# MariaDB 10.3 repository list - created 2018-10-23 06:44 UTC # http://downloads.mariadb.org/mariadb/repositories/ deb [arch=amd64,arm64,ppc64el] http://mirrors.neusoft.edu.cn/mariadb/repo/10.3/ubuntu bionic main deb-src http://mirrors.neusoft.edu.cn/mariadb/repo/10.3/ubuntu bionic main
以下安裝信息來自HA
https://www.home-assistant.io/components/recorder
如果使用虛擬環境,需要安裝相關依賴,而且要在虛擬環境下安裝mySQL客戶端
sudo apt-get install libmariadbclient-dev libssl-dev pip3 install mysqlclient
如果是10.1版本(當前ubuntu倉庫版本)
sudo apt-get install libmariadb-dev libssl-dev pip3 install mysqlclient
如果使用時10.2以后版本
sudo apt-get install libmariadb-dev libssl-dev sudo -u homeassistant -H -s homeassistant@homeassistant:~$ source /srv/homeassistant/bin/activate (homeassistant) homeassistant@homeassistant:~$ pip3 install mysqlclient
如果您在與Home Assistant相同的服務器上運行數據庫服務器實例,則必須確保在Home Assistant之前啟動此服務。對於運行Systemd(Raspberry Pi,Debian,Ubuntu等)的Linux實例,您應該編輯服務文件。
sudo nano /etc/systemd/system/homeassistant@homeassistant.service
https://mariadb.com/kb/en/library/systemd/
systemd服務文件包含在MariaDB服務器包中。服務定義安裝在/usr/lib/systemd/system/mariadb.service
。服務名稱是mariadb.service
; 但為方便起見mysql.service
,mysqld.service
包含了別名並包含在內。
[Unit] Description=Home Assistant After=network.target mariadb.service
保存文件然后重新加載systemctl
:
sudo systemctl daemon-reload
https://github.com/home-assistant/hassbian-scripts/blob/dev/docs/mariadb.md
sudo mysql -u root -p CREATE DATABASE homeassistant; CREATE USER 'homeassistantuser' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON homeassistant.* TO 'homeassistantuser'; FLUSH PRIVILEGES; exit
將域和實體定義為exclude
(又名黑名單)。當您對記錄的信息基本滿意時,這很方便,但只想刪除一些實體或域。通常,這些是不改變(例如weblink
)或很少改變(updater
或automation
)的實體/域。
# Example configuration.yaml entry with exclude recorder: purge_keep_days: 5 db_url: mysql://user:password@SERVER_IP:3307/DB_NAME?charset=utf8 exclude: domains: - automation - weblink - updater entities: - sun.sun # Don't record sun data - sensor.last_boot # Comes from 'systemmonitor' sensor platform - sensor.date