Saturday, February 3, 2018

Install MariaDB with yum

This post is one of a series

Create an environment for Web development
  1. Vagrant/Virtualbox
  2. Install Apache or Nginx for PHP or Nginx for Python
  3. Install MariaDB - You are here
  4. Install PHP / Install Python

MariaDB

Make sure that you have updated yum:
$ sudo yum update
And install MariaDB:
$ sudo yum install mariadb-server mariadb-client
Start and enable MariaDB
$ sudo systemctl enable mariadb
$ sudo systemctl start mariadb
Or the following is OK too:
$ 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.
In the mysql_secure_installation process, you will be asked a new password. I always use "root" for the password of MariaDB because this DB will be used for a development environment. So if you are asked a new password, you can write "root" and press the enter to use it as the password. If this is for a real server, you need to set a secure password, not a too simple one.

Also, when you are asked if you will disallow remote access, answer no if you want to use the MariaDB from the host computer.
Run the following command to log into MariaDB:
$ mysql -u root -proot

Change the password

For your information, you can change the password like this:
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

Use MariaDB from the host computer

You need to add privileges to access from outside the server:
$ mysql -u root -proot
MariaDB[none]> use mysql;
MariaDB[mysql]> GRANT ALL ON *.* to root@'192.168.33.10' IDENTIFIED BY 'root';
MariaDB[mysql]> GRANT ALL ON *.* to root@'192.168.33.1' IDENTIFIED BY 'root';
MariaDB[mysql]> SET PASSWORD FOR 'root'@'192.168.33.10' = PASSWORD('root');
MariaDB[mysql]> flush privileges;
MariaDB[mysql]> exit;

The use the following information to access from outside the server:
Host name: 192.168.33.10 (or your virtual machine's IP address)
port: 3306
user: root
password: root