更换MariaDB数据库

https://downloads.mariadb.org/mariadb/repositories/#mirror=neusoft&distro=Ubuntu&distro_release=bionic--ubuntu_bionic&version=10.3

以下是从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.servicemysqld.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)或很少改变(updaterautomation)的实体/域

# 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

 

posted @ 2018-10-23 15:13  新贵  阅读(1285)  评论(0编辑  收藏  举报