0

-- EDIT -- Complete setup in the answer below. -- EDIT --

When I follow an article (link below) on how to setup a extra MariaDB or Mysql on Linux, and it works. However, I don't like the name "mysql1" & "mysql2" for instance names. But when I change just that aspect of the code, the server wont install when I run the start command.

I wrote both setups here below for easy comparison: The one that does work where 2 instances are being made, and the one that ultimately doesn't work. I would very much love to figure how to make the one that doesn't work, work. Your help is very much appreciated!

- 1) Datadir (setup that works):

sudo mkdir -p -v /var/lib/mysql{1..2}
sudo chown mysql:mysql -v /var/lib/mysql{1..2}

- 1) Datadir (setup that ultimately doesn't work):

sudo mkdir -p -v /var/lib/mysqlTest
sudo chown mysql:mysql -v /var/lib/mysqlTest

- 2) Socket directory (setup that works):

sudo mkdir -p -v /usr/local/mysql/mdb{1..2}
sudo chown -v -R mysql:mysql /usr/local/mysql/mdb{1..2}

- 2) Socket directory(setup that ultimately doesn't work):

sudo mkdir -p -v /usr/local/mysql/mdbTest
sudo chown -v -R mysql:mysql /usr/local/mysql/mdbTest

- 3) Log directory (setup that works):

sudo mkdir -p -v /var/log/mysql{1..2}
sudo chown -v -R mysql:mysql /var/log/mysql{1..2}

- 3) Log directory(setup that ultimately doesn't work):

sudo mkdir -p -v /var/log/mysqlTest
sudo chown -v -R mysql:mysql /var/log/mysqlTest

- 4) I create the following file

"mysqld_multi_cls.cnf"

Located at: /etc/mysql/

- 5) content (setup that works):

# Configuration Settings for mysqld_multi , as well as separate instances. 
#
[mysqld_multi]
mysqld       = /usr/bin/mysqld_safe
mysqladmin   = /usr/bin/mysqladmin

[mysqld1] socket = /tmp/mysql.sock1 port = 3307 pid-file = /usr/local/mysql/mdb1/ansible-host1.pid1 datadir = /var/lib/mysql1 log-error = /var/log/mysql1/error.log log_bin = /var/lib/mysql1/mdb1-mysql-bin.log server-id = 1 expire_logs_days = 72 sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT
binlog_format = mixed gtid_strict_mode = 1

[mysqld2] socket = /tmp/mysql.sock2 port = 3308 pid-file = /usr/local/mysql/mdb2/ansible-host1.pid2 datadir = /var/lib/mysql2 log-error = /var/log/mysql2/error.log log-bin = /var/lib/mysql2/mdb2-mysql-bin.log server-id = 2 expire_logs_days = 64 sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT
binlog_format = mixed gtid_strict_mode = 1

- 5) content(setup that ultimately doesn't work):

# Configuration Settings for mysqld_multi , as well as separate instances. 
#
[mysqld_multi]
mysqld       = /usr/bin/mysqld_safe
mysqladmin   = /usr/bin/mysqladmin

[mysqlTest] socket = /tmp/mysql.sock3 port = 3309 pid-file = /usr/local/mysql/mdbTest/ansible-host1.pid3 datadir = /var/lib/mysqlTest log-error = /var/log/mysqlTest/error.log log_bin = /var/lib/mysqlTest/mdbTest-mysql-bin.log server-id = 3 expire_logs_days = 72 sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT
binlog_format = mixed gtid_strict_mode = 1

-6) And now we start the server:

sudo mysqld_multi --defaults-file=/etc/mysql/mysqld_multi_cls.cnf --log=/etc/mysql/multi_ins.log start      
  • If done in the 1st manor, the database is now installing and everyone is happy.
  • But if done in the 2nd manor where I only changed the name and made a single (extra) instance, nothing happens.

What am I missing?

Cheers and thank you very much!

Here is the article on Linkedin by Michael Amadi: https://www.linkedin.com/pulse/running-multiple-instances-mariadb-single-server-different-amadi

1 Answers1

0

Alright, let's answer this bad-boy.

You can't change the name of the extra mysql or mariadb instances. Its either going to be mysql# or mariadb#. The reason is that mariadb and mysql cycles through it by it's GNR, the number ($i). But we can give the server instances a different name in phpMyAdmin with the "verbose" option.

In this example, we'll make 3 instances. We could give our 1st instance the #1. But that might create some difficulties later on with phpmyadmin. So, we ID our first instance #2 And here is how we do it. : First we need to create some folders for the new mariadb or mysql instances.

1: make directories:

sudo mkdir -p -v /var/lib/mysql{2..4} /usr/local/mysql/mdb{2..4} /var/log/mysql{2..4} /var/log/mysql 

2: set the permissions:

sudo chown mysql:mysql -v /var/lib/mysql{2..4} /usr/local/mysql/mdb{2..4} /var/log/mysql{2..4} /var/log/mysql

3: We are going to create a config file mysqld_multi_cls.cnf for mariadb/mysql. We can do this at the same time as opening the file.

sudo mousepad /etc/mysql/conf.d/mysqld_multi_cls.cnf

4: Add the following code:

# Configuration Settings for mysqld_multi , as well as separate instances. 
#
[mysqld_multi]
mysqld      = /usr/bin/mariadbd-safe
mysqladmin  = /usr/bin/mariadb-admin
User        = multi_admin
Password    = multi_admin-password

InstanceA

[mysqld2] socket = /tmp/mysql.sock2 port = 3307 pid-file = /usr/local/mysql/mdb2/ansible-host1.pid2 datadir = /var/lib/mysql2 general_log = 1 general_log_file = /var/log/mysql2/general_ID2.log log-error = /var/log/mysql2/error_ID2.log server-id = 2 expire-logs-days = 72 sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT
binlog_format = mixed gtid_strict_mode = 1

InstanceB

[mysqld3] socket = /tmp/mysql.sock3 port = 3308 pid-file = /usr/local/mysql/mdb3/ansible-host1.pid3 datadir = /var/lib/mysql3 general_log = 1 general_log_file = /var/log/mysql3/general_ID3.log log-error = /var/log/mysql3/error_ID3.log server-id = 3 expire-logs-days = 64 sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT
binlog_format = mixed gtid_strict_mode = 1

InstanceC

[mysqld4] socket = /tmp/mysql.sock4 port = 3309 pid-file = /usr/local/mysql/mdb4/ansible-host1.pid4 datadir = /var/lib/mysql4 general_log = 1 general_log_file = /var/log/mysql4/general_ID4.log log-error = /var/log/mysql4/error_ID4.log server-id = 4 expire-logs-days = 64 sync_binlog = 1 innodb_flush_log_at_trx_commit = 1 innodb_flush_method = O_DIRECT
binlog_format = mixed gtid_strict_mode = 1

5: In the terminal, start the new server-instances. The first time will take a while as mariadbd-multi will install them:

sudo mariadbd-multi --defaults-file=/etc/mysql/conf.d/mysqld_multi_cls.cnf start 

6: Than to check if they run:

sudo mariadbd-multi --defaults-file=/etc/mysql/conf.d/mysqld_multi_cls.cnf report

Or you can use:

sudo mariadbd-multi report

7: These instances won't start when your computer boots. I didn't manage to find a nice clean way to do this through mariadbd/mysql itself. But we can give Linux a script to run after booting to start the instances. And we can do this with the file /etc/rc.local. You might not see this file in your explorer, but we can open it through the terminal:

sudo nano /etc/rc.local

Before/Above "exit 0" add the following:

sudo mariadbd-multi --defaults-file=/etc/mysql/conf.d/mysqld_multi_cls.cnf --log=/var/log/mysql/multi_ins.log start

Hit "CTRL S" to save, and "CTRL X" to close.

Setup the new instance We want to make the server save. That's means we need to delete the root account, as this is was "hackers" will first try out. Renaming it to "admin" is also not what you call "high class safety". But you can skip this part if you like.

1: In the Terminal:

sudo mariadb -A -S /tmp/mysql.sock2

2: let's check the port number just to be sure we opend the correct instance:

select @@port;

3: Creating User will full blown authority is of course not a save thing. But let's make one anyway :D

CREATE USER 'NewUser'@'localhost' IDENTIFIED BY 'Super-Duper-Complicated-Password' ;

4: Grant "all Privileges" will give it the privilege to create, delete, write, read, and everything. The "With Grand Option" allows this new user to create/give other users certain privileges.

GRANT ALL PRIVILEGES ON *.* TO 'NewUser'@'localhost' WITH GRANT OPTION;

5: Flush the new settings trough the system, and close.

FLUSH PRIVILEGES;

\q

6: Now we enter the mariadb instance again but this time with our new super-user. And type in the Super-Duper-Complicated-Password when requested.

mariadb -A -u NewUser -p -S /tmp/mysql.sock2

7: Let's take this account for a spin and create a database:

CREATE DATABASE testDB_instance07;

show databases;

8: Did it work? if so, lets continue and delete the root user.

DROP USER 'root'@localhost;

9: A Good thing is to have a seperate account that can close down a server. Let's make that account.

CREATE USER 'multi_admin'@'localhost' IDENTIFIED BY 'multi_admin-password';

GRANT SHUTDOWN ON . TO 'multi_admin'@'localhost';

FLUSH PRIVILEGES;

Redo this a few more times for your other instances.

Setup the main server: 1: We could do the exact same for the main server. Create a new account and delete root. But let's do this one differently for the sake of it. Let's rename it and change the password.

sudo mariadb -A -S /run/mysqld/mysqld.sock

RENAME USER 'root'@'localhost' TO 'Batman'@'localhost';

SET PASSWORD FOR 'Batman'@'localhost' = PASSWORD('New-Main-Super-Duper_Safe-Password');

flush privileges;

/q

2: Now we login again under the new account name, and we make the multi_admin as before:

mariadb -A -u Nedry -p -S /run/mysqld/mysqld.sock

CREATE USER 'multi_admin'@'localhost' IDENTIFIED BY 'multi_admin-password';

GRANT SHUTDOWN ON . TO 'multi_admin'@'localhost';

FLUSH PRIVILEGES;

3: And we setup some logging for this main server:

SET GLOBAL general_log_file = '/var/log/mysql/general.log';

SET GLOBAL slow_query_log_file = '/var/log/mysql/slow_query.log';

SET GLOBAL general_log = 'ON';

SET GLOBAL slow_query_log = 'ON';

/q

restart Now might be a good time for a happy reboot of your system. And when you get back, see if the server is running.

sudo mariadbd-multi report

And remember the multi_admin. This is how you can close one of your instances.

sudo mysqladmin -u multi_admin -p -S /tmp/mysql.sock3 shutdown

With the report command from before you can check if it worked.

Now add the mariadb or mysql instances to phpMyAdmin:

Of course you now how to get into phpMyAdmin in your browser, but here is the address just to be safe:

localhost/phpMyAdmin

1: We need change the "config.inc.php" file. (I like the Geany editor for this)

sudo geany /var/www/html/phpMyAdmin/config.inc.php

Do you see the following?:

/**
 * End of servers configuration
*/

2: Past the following above that.

$i = 2;
$cfg['Servers'][$i]['verbose'] = 'Server-Name_A';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = 3307;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

$i = 3; $cfg['Servers'][$i]['verbose'] = 'Server-Name_B'; $cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['port'] = 3308; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['AllowNoPassword'] = false;

$i = 4; $cfg['Servers'][$i]['verbose'] = 'Server-Name_C'; $cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['port'] = 3309; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['AllowNoPassword'] = false;

Let's do a nice clean happy reboot.

Now you can login with your Mysql/MariaDB accounts into phpMyAdmin. Just remember to fill in the correct credentials to the selected server in the dropdown.

Have a great day!