Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Explore additional ways to connect to MariaDB, including less common client libraries, ODBC, and methods for various programming languages and tools beyond the main connectors.
{deps, [
{mysql, ".*", {git, "https://github.com/mysql-otp/mysql-otp.git", {tag, "2.0.0"}}} % Use the latest stable tag or master
]}.% Basic connection
{ok, Pid} = mysql:start_link([{host, "localhost"}, {user, "myuser"}, {password, "mypass"}, {database, "mydb"}]).
% Connection with SSL (example with CA certificate)
% {ok, Pid} = mysql:start_link([{host, "localhost"},
% {user, "myuser"},
% {password, "mypass"},
% {database, "mydb"},
% {ssl, [{server_name_indication, disable}, {cacertfile, "/path/to/ca.pem"}]}
% ]).% Prepared statement with parameters
{ok, ColumnNames, Rows} = mysql:query(Pid, <<"SELECT id, name FROM mytable WHERE status = ?">>, [<<"active">>]),
io:format("Columns: ~p~n", [ColumnNames]),
io:format("Rows: ~p~n", [Rows]).% Insert data
ok = mysql:query(Pid, "INSERT INTO mytable (col1, col2) VALUES (?, ?)", [<<"value1">>, 123]),
io:format("Insert successful!~n").
% Get info about the last query
LastInsertId = mysql:insert_id(Pid),
AffectedRows = mysql:affected_rows(Pid),
WarningCount = mysql:warning_count(Pid),
io:format("Last Insert ID: ~p, Affected Rows: ~p, Warnings: ~p~n", [LastInsertId, AffectedRows, WarningCount]).% Example of a nested transaction
mysql:transaction(Pid, fun() ->
ok = mysql:query(Pid, "UPDATE accounts SET balance = balance - 100 WHERE user_id = 1"),
mysql:transaction(Pid, fun() ->
ok = mysql:query(Pid, "UPDATE accounts SET balance = balance + 100 WHERE user_id = 2")
end),
{atomic, ok} % or {atomic, YourResult}
end).
io:format("Transaction completed.~n").% Example with multiple queries and multiple result sets
{ok, Results} = mysql:query(Pid, "SELECT 1 AS a; SELECT 'hello' AS b;"),
io:format("Multiple Query Results: ~p~n", [Results]).
% Results format: [{[ColumnNames], [Rows]}, {[ColumnNames], [Rows]}]% Query with a 1000ms (1 second) timeout
{ok, ColumnNames, Rows} = mysql:query(Pid, <<"SELECT SLEEP(5)">>, 1000),
io:format("Query interrupted, result: ~p~n", [Rows]). % SLEEP() typically returns 1 when interruptedmysql:stop(Pid).
io:format("Connection closed.~n").General usage information, available features, available magic commands
The MariaDB Jupyter Kernel lets you run MariaDB directly in Jupyter notebooks. Execute SQL, visualize results with magic commands, and integrate with Python for data analysis.

install.packages("RMariaDB")library(RMariaDB)library(RMariaDB)
library(DBI)
# Connect to my-db as defined in ~/.my.cnf
con <- dbConnect(RMariaDB::MariaDB(), group = "my-db")
dbListTables(con)
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)
dbListFields(con, "mtcars")
dbReadTable(con, "mtcars")
# You can fetch all results:
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)
# Or a chunk at a time
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
while(!dbHasCompleted(res)){
chunk <- dbFetch(res, n = 5)
print(nrow(chunk))
}
# Clear the result
dbClearResult(res)
# Disconnect from the database
dbDisconnect(con)python3 -m pip install mariadb_kernelpython3 -m mariadb_kernel.install# After you downloaded the script run:
sh ./Miniconda3-latest-Linux-x86_64.shconda create -n maria_env python=3.7# You should see the terminal prompt prefixed with (maria_env)
conda activate maria_envconda install -c conda-forge jupyterlabpython3 -m pip install mariadb_kernelpython3 -m mariadb_kernel.installTABcat ~/.jupyter/mariadb_config.json
{
"user": "root",
"host": "localhost",
"port": "3306",
"password": "securepassword",
"start_server": "True",
"client_bin": "/usr/bin/mariadb",
"server_bin": "/usr/bin/mariadbd"
}
















------cell
%%magic_python
from matplotlib import pyplot
x = [1,2,3]
print(x)
pyplot.plot(x)
------end of cell--------cell
%%delimiter //
CREATE PROCEDURE proc ()
BEGIN
select 1;
END;
//
--------end-of-cell