Installing MySQL and MariaDB in One Machine

Installing Mysql And Mariadb In One Machine

MySQL is the original source of MariaDB. The both come with same sintax and similar configuration. However, nowdays many developers move to MariaDB. It is because the statement is clear that MariaDB will be opensource forever. Moving to MariaDB from MySQL also has another reasons for example faster engine. When we are installing MariaDB on a running MySQL server, sometimes it will cause error can not installing it. This is normal.

The main reason is port. Port is number where a service is running on a machine. When we can not run MariaDB, it is becase MySQL and MariaDB use the same default port 3306. Changing this port will solve the problem.

However, we can not installing MariaDB on a running MySQL server because this will override automatically the existing MySQL and we can not running two servers on one machine. Here, we would like to guide you step by step of how to install MariaDB on running MySQL server.

  1. On command prompt terminal, move to /opt directory by typing this command: cd /opt
  2. Download MariaDB in compressed tar.gz file from its source MariaDB website: https://archive.mariadb.org/mariadb-5.5.24/kvm-bintar-hardy-amd64/mariadb-5.5.24-linux-x86_64.tar.gz. For the command, we can type in command prompt: sudo wget https://archive.mariadb.org/mariadb-5.5.24/kvm-bintar-hardy-amd64/mariadb-5.5.24-linux-x86_64.tar.gz
  3. Extract the downloaded file by typing: sudo tar -xvzf mariadb-5.5.24-linux-x86_64.tar.gz
  4. Create directory mariadb-data: sudo mkdir mariadb-data
  5. Create symbolic link by typing: sudo ln -s mariadb-5.5.24-linux-x86_64 mariadb
  6. Create group mariadb: sudo groupadd --system mariadb
  7. Add user MariaDB Server: sudo useradd -c "MariaDB Server" -d /opt/mariadb -g mariadb --system mariadb
  8. Change owner of original directory: sudo chown -R mariadb:mariadb mariadb-5.5.24-linux-x86_64
  9. Change owner of maridb-data directory: sudo chown -R mariadb:mariadb mariadb-data/
  10. Create configuration file from existing provided example: sudo cp mariadb/support-files/my-medium.cnf mariadb-data/my.cnf
  11. Change owner of the configuration file: sudo chown mariadb:mariadb mariadb-data/my.cnf
  12. Edit the configuration file my.cnf: sudo nano /opt/mariadb-data/my.cnf

In the [client] section, change into the following:

[client]

password = your_password
port = 3307
socket = /opt/mariadb-data/mariadb.sock

In the [mysqld] section, add the following lines:

[mysqld]

datadir = /opt/mariadb-data
basedir = /opt/mariadb
port = 3307
socket = /opt/mariadb-data/mariadb.sock
user = mariadb

Please note that the port must be different from the defaut 3306. In the example, we change the port to 3307

  1. Create an automating starting script: sudo cp mariadb/support-files/mysql.server /etc/init.d/mariadb
  2. Make the starting script executable: sudo chmod +x /etc/init.d/mariadb
  3. Edit the starting script: sudo nano /etc/init.d/mariadb

Change the following lines into:

basedir=/opt/mariadb
datadir=/opt/mariadb-data
lock_file_path="$lockdir/mariadb"

Add the following line –defaults-file=/opt/mariadb-data/my.cnf to:

# Give extra arguments to mysqld with the my.cnf file. This script may be overwritten at next upgrade.

$bindir/mysqld_safe --defaults-file=/opt/mariadb-data/my.cnf --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 & wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?

Save the file by pressing Ctrl+o Enter, and quit the file by pressing Ctrl+x Enter.

  1. Install the configuration file by this commands:
cd mariadb
scripts/mysql_install_db --defaults-file=/opt/mariadb-data/my.cnf
  1. Finally, start the service by executing the following command: sudo /etc/init.d/mariadb

I used to be a pilot, but ended up being just a mediocre writer.

×