quick setup mariadb


MariaDB is open-source DB which was developed by the same developers who were part of MySQL. it’s forked from MySQL. It’s highly compatible with MySQL you don’t need any special drivers etc to make it work if you migrate from MySQL to MariaDB.

install MariaDB using yum.

# yum install mariadb-server.x86_64


enable using systemctl

# systemctl enable mariadb

 


start MariaDB

# systemctl start mariadb


check the MariaDB process

# ps -ef|grep maria
root      8759  2217  0 11:07 pts/0    00:00:00 grep --color=auto maria
mysql    32567 32405  0 11:05 ?        00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

Note: It still runs with id MySQL.

You can see the default settings:

data directory=/var/lib/mysql

log dir=/var/log/mariadb/

you can change them as per your needs in /etc/my.cnf.

 


how to login to MariaDB after installation?

bitarray# mysql -u root -p -h localhost
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (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)]> 

do not put any password when prompted for a password (after initial installation).

 


How to change the default root password?

As stated above the default root password is blank which is not secure. To change the root password run:

bitarray# mysqladmin --version
mysqladmin  Ver 9.0 Distrib 5.5.60-MariaDB, for Linux on x86_64
bitarray# mysqladmin -u root password "<new password>";

Note: You can only run it once. To change it again

bitarray# mysqladmin --user=root --password=<old password> password <new password>

What if you forget root password? It’s not good: 🙂 but yes it can be reset easily. We will discuss this in another post.


How to see the list of available commands?

MariaDB [(none)]> ?

General information about MariaDB can be found at
http://mariadb.org

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

 


How to find MariaDB version, Start Time, Connections, Threads,  query per second?

MariaDB [(none)]> status
--------------
mysql  Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1

Connection id:		4
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server:			MariaDB
Server version:		5.5.60-MariaDB MariaDB Server
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	utf8
Conn.  characterset:	utf8
UNIX socket:		/var/lib/mysql/mysql.sock
Uptime:			3 days 8 hours 35 min 30 sec

Threads: 1  Questions: 43  Slow queries: 0  Opens: 15  Flush tables: 2  Open tables: 41  Queries per second avg: 0.000


mariadb command history

By default all commands run in mariadb shell are stored in $HOME/.mysql_history file. You can change location of this file by changing MYSQL_HISTFILE  environment variable.

 


Get a list of all users in mariadb

MariaDB [(none)]> SELECT User,Password,Host FROM mysql.user;
+----------+-------------------------------------------+-------------+
| User     | Password                                  | Host        |
+----------+-------------------------------------------+-------------+
| root     | *F1C9A84879A214CC79F5143AA9D60B67C9789F3F | localhost   |
| root     |                                           | hostmaster  |
| root     |                                           | 127.0.0.1   |
| root     |                                           | ::1         |
|          |                                           | localhost   |
|          |                                           | hostmaster  |
| bitarray | *F1C9A84879A214CC79F5143AA9D60B67C9789F3F | bitarray.io |
+----------+-------------------------------------------+-------------+
7 rows in set (0.00 sec)
​_

 


Creating users to get started.

MariaDB [(none)]> create user 'bitarray'@'bitarray.io' identified by 'password';

see we added user ‘bitarray’ who can login from host bitarray.io only. You can restrict users based on hosts/ip.