You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The MySQL interface allows to using a MySQL (or MariaDB or Percona) server for :ref:`data_logging` and/or persistence.
6
+
7
+
Setup
8
+
-----
9
+
10
+
The MySQL interface does (currently) not include automated database setup or database schema migration, so the database needs to be set up manually.
11
+
Typically, this includes chosing a secure password for the database connection and running the following commands in a mysql console with root privileges:
12
+
13
+
.. code-block:: mysql
14
+
15
+
CREATE DATABASE 'shc';
16
+
CREATE USER 'shc'@'localhost' IDENTIFIED BY '<password>';
17
+
GRANT SELECT, INSERT, UPDATE ON shc.* TO 'shc'@'localhost';
18
+
FLUSH PRIVILEGES;
19
+
20
+
USE shc;
21
+
22
+
CREATE TABLE log (
23
+
name VARCHAR(256) NOT NULL,
24
+
ts DATETIME(6) NOT NULL,
25
+
value_int INTEGER,
26
+
value_float FLOAT,
27
+
value_str LONGTEXT,
28
+
KEY name_ts(name, ts)
29
+
);
30
+
31
+
CREATE TABLE `persistence` (
32
+
name VARCHAR(256) NOT NULL,
33
+
ts DATETIME(6) NOT NULL,
34
+
value LONGTEXT,
35
+
UNIQUE KEY name(name)
36
+
);
37
+
38
+
Usage
39
+
-----
40
+
41
+
With the database setup listed above, the database can be used in an SHC project with the following code (or similar)::
42
+
43
+
import shc
44
+
import shc.interfaces.mysql
45
+
46
+
# you may want to load the database password from some configfile to keep it out of your project code
0 commit comments