Setting Up MySQL/MariaDB
MariaDB is basically an open source fork of MySQL.
Installation
MariaDB can simply be installed via pacman with the following command.
$ pacman -S mariadbresolving dependencies...looking for conflicting packages...Packages (5) jemalloc-1:5.3.0-3 liburing-2.4-1 mariadb-clients-11.1.2-1 mariadb-libs-11.1.2-1mariadb-11.1.2-1Total Download Size: 41.21 MiBTotal Installed Size: 300.52 MiB:: Proceed with installation? [Y/n]Setup
First, run the following setup command.
$ mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysqlInstalling MariaDB/MySQL system tables in '/var/lib/mysql' ...OKTo start mariadbd at boot time you have to copysupport-files/mariadb.service to the right place for your systemTwo all-privilege accounts were created.One is root@localhost, it has no password, but you need tobe system 'root' user to connect. Use, for example, sudo mysqlThe second is mysql@localhost, it has no password either, butyou need to be the system 'mysql' user to connect.After connecting you can set the password, if you would need to beable to connect as any of these users with a password and without sudoSee the MariaDB Knowledgebase at https://mariadb.com/kbYou can start the MariaDB daemon with:cd '/usr' ; /usr/bin/mariadb-safe --datadir='/var/lib/mysql'You can test the MariaDB daemon with mariadb-test-run.plcd '/usr/mariadb-test' ; perl mariadb-test-run.plPlease report any problems at https://mariadb.org/jiraThe latest information about MariaDB is available at https://mariadb.org/.Consider joining MariaDB's strong and vibrant community:https://mariadb.org/get-involved/Then, MariaDB must be started with systemctl. One can start the service every time it is needed (it will not restart upon boot), or one can enable it so that it always starts upon boot. Both are shown below.
$ systemctl start mariadb$ systemctl enable mariadbThen you can enter the MariaDB interface. The default password should be blank.
$ sudo mysql -u root -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 3Server version: 11.1.2-MariaDB Arch LinuxCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.A new user can be added.
MariaDB [(none)]> CREATE USER 'USER_NAME'@'localhost' IDENTIFIED BY 'PASSWORD';Query OK, 0 rows affected (0.014 sec)MariaDB [(none)]> MariaDB> GRANT ALL PRIVILEGES ON *.* TO 'USER_NAME'@'localhost';Query OK, 0 rows affected (0.005 sec)MariaDB [(none)]> MariaDB> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.004 sec)MariaDB [(none)]> MariaDB> quitByeThat user can then be used to login. If a blank password was set, then an empty password can be used to login.
$ mariadb -u USER_NAME -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 4Server version: 11.1.2-MariaDB Arch LinuxCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>Use
Once logged in, a new database can be created as follows.
MariaDB [(none)]> CREATE DATABASE myDataBase;Query OK, 1 row affected (0.001 sec)That database can be entered as follows.
MariaDB [(none)]> USE myDataBase;Database changedA table can be created as follows.
MariaDB [myDataBase]> CREATE TABLE exampleTable ( CREATE TABLE exampleTable ( -> ID char(5) not null, -> name varchar(15) not null, -> number int not noll, -> primary key (ID));Query OK, 0 rows affected (0.204 sec)Data can be loaded from an external SQL file as follows.
MariaDB [myDataBase]> SOURCE database.sqlQuery OK, 0 rows affected (0.116 sec)Query OK, 0 rows affected (0.106 sec)Query OK, 0 rows affected (0.092 sec)Query OK, 0 rows affected (0.108 sec)Query OK, 0 rows affected (0.100 sec)Query OK, 0 rows affected (0.125 sec)Query OK, 0 rows affected (0.108 sec)Query OK, 0 rows affected (0.090 sec)Query OK, 0 rows affected (0.117 sec)Query OK, 0 rows affected (0.108 sec)Query OK, 0 rows affected (0.092 sec)All available tables can be shown as follows.
MariaDB [myDataBase]> SHOW TABLES;+----------------------+| Tables_in_university |+----------------------+| balloons || designs || clowns || circus || clubs || jugglers || elephants || rings || dancers || cannons || venues |+----------------------+11 rows in set (0.001 sec)| Previous | Published October 11, 2023 |
|---|