Saturday, December 15, 2018

Install mariadb-server with apt-get

Make sure that you have updated apt-get:
sudo apt-get update

And install MariaDB:
sudo apt-get install mariadb-server

Start and enable MariaDB
sudo systemctl enable mariadb
$ sudo systemctl start mariadb

Or
sudo service mariadb enable
$ sudo service mariadb start

Now we will set up our MariaDB, which is needed when we start MariaDB for the first time. Do the following command:

$ sudo mysql_secure_installation

You will be asked password, but just hit enter because there is no password when it is started for the first time.

Maybe you will be asked a new password, however, we will not use password for MariaDB here because we will set a new password later. So if you are asked a new password, just hit the enter to set empty password. If this is for a real server, you need to set a secure password.

Run the following command to log into MariaDB:

$ mysql -u root



The password is often long like 8 letters. But I think 8 letters that contain a big letter, a small letter and a special letter is not useful for development if we often login and logout. So we will change the password of root to "root". Run these commands:

MariaDB[none]> use mysql;
MariaDB[mysql]> update user set password=PASSWORD("root") where User='root';
MariaDB[mysql]> flush privileges;
MariaDB[mysql]> exit;

Now your password for the root of MariaDB is changed to "root". You can log-in to MariaDB this way:

$ mysql -u root -proot