connect_mariadb¶
-
getml.database.
connect_mariadb
(dbname, user, password, host, port=3306, unix_socket='/var/run/mysqld/mysqld.sock', time_formats=['%Y-%m-%dT%H:%M:%s%z', '%Y-%m-%d %H:%M:%S', '%Y-%m-%d'])¶ Creates a new MariaDB database connection.
But first, make sure your database is running and you can reach it from via your command line.
- Parameters
dbname (str) – The name of the database to which you want to connect.
user (str) – User name with which to log into the MariaDB database.
password (str) – Password with which to log into the MariaDB database.
host (str) – Host of the MariaDB database.
port (int, optional) –
Port of the MariaDB database.
The default port for MariaDB is 3306.
If you do not know which port to use, type
SELECT @@port;
into your MariaDB client.
unix_socket (str, optional) –
The UNIX socket used to connect to the MariaDB database.
If you do not know which UNIX socket to use, type
SELECT @@socket;
into your MariaDB client.
time_formats (List[str], optional) –
The list of formats tried when parsing time stamps.
The formats are allowed to contain the following special characters:
%w - abbreviated weekday (Mon, Tue, …)
%W - full weekday (Monday, Tuesday, …)
%b - abbreviated month (Jan, Feb, …)
%B - full month (January, February, …)
%d - zero-padded day of month (01 .. 31)
%e - day of month (1 .. 31)
%f - space-padded day of month ( 1 .. 31)
%m - zero-padded month (01 .. 12)
%n - month (1 .. 12)
%o - space-padded month ( 1 .. 12)
%y - year without century (70)
%Y - year with century (1970)
%H - hour (00 .. 23)
%h - hour (00 .. 12)
%a - am/pm
%A - AM/PM
%M - minute (00 .. 59)
%S - second (00 .. 59)
%s - seconds and microseconds (equivalent to %S.%F)
%i - millisecond (000 .. 999)
%c - centisecond (0 .. 9)
%F - fractional seconds/microseconds (000000 - 999999)
%z - time zone differential in ISO 8601 format (Z or +NN.NN)
%Z - time zone differential in RFC format (GMT or +NNNN)
%% - percent sign
Note
By selecting an existing table of your database in
from_db()
function, you can create a newDataFrame
containing all its data. Alternatively you can use theread_db()
andread_query()
methods to replace the content of the currentDataFrame
instance or append further rows based on either a table or a specific query.You can also write your results back into the MariaDB database. By providing the name for the destination table in
getml.models.MultirelModel.transform()
, the features generated from your raw data will be written back. Passing them intogetml.models.MultirelModel.predict()
, instead, makes predictions of the target variables to new, unseen data and stores the result into the corresponding table.