Skip to content

MariaDb linux Python ORM

Last updated on October 25, 2019

MariaDB is an open source, multi-threaded relational database management system, backward compatible replacement for MySQL. It is maintained and developed by the MariaDB Foundation including some of the original developers of the MySQL.

sudo apt update

sudo apt install mariadb-server

sudo mysql -V

sudo systemctl status mariadb

Run the mysql_secure_installation command to improve the security of the MariaDB installation:

sudo mysql_secure_installation

The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine and remove the test database. At the end the script will reload the privilege tables ensuring that all changes take effect immediately.

All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions, except no if you have a sudo password.

Connect to MariaDB from the command line

sudo mysql (cmd access) or mysql -u root -p


show databases;

To create a MySQL database which uses the utf8 character set:

create database tech character set UTF8 collate utf8_bin

MySQL supports two kinds of UTF8 character sets: utf8 and utf8mb4.

MySQL’s utf8 character table contains characters from the Basic Multililingial Plane, also known as BMP — it is a subset of UTF8 characters which lengths are from 1 to 3 bytes. 4-bytes characters are not included into this character table, and when one attempted to store such characters into a MySQL table, the Incorrect String Value error occurs.

Create a user:

create user ‘espen’ identified by ‘your-password’;

GRANT ALL privileges ON ‘tech‘.* TO ‘espen’@localhost;

flush privileges;

Use tech;

create table test (id int, name varchar(20));

Navigate to env (activate it) run:

pip3 install mysql-connector


Published inlinuxPythonSql