Skip to main content

Install MySQL community edition | multiple instances same machine | configure systemctld

Install MySQL 5.7.22 Community edition:

#yum install mysql-community-server
#yum install perl-DBD-MySQL-4.023-6.el7.x86_64.rpm
#yum install percona-release-0.1-4.noarch.rpm

Configure multiple instances instance1 and instance2 on the same machine:

01.    Backup existing my.cnf file to my.cnf.bkup
02.    Edit my.cnf with following

[root@server_name]# cat /etc/my.cnf
[mysqld@instance1]
datadir = /mysql/instance1/data
socket = /mysql/instance1/data/instance1.sock
port = 3777
server-id = 3777
log-error = /mysql/instance1/data/instance1.err
 

[mysqld@instance2]
datadir = /mysql/instance2/data
socket = /mysql/instance2/data/instance2.sock
port = 3999
server-id = 3999
log-error = /mysql/instance2/data/instance2.err


Start mysql instance using system:#systemctl start mysqld@instance1
#systemctl start mysqld@instance2

It will create database files at /mysql/instance1/data/ and /mysql/instance2/data/

Check status:
[root@mysqlhost system]# systemctl status mysqld@instance1
● mysqld@instance1.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld@.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-06-05 14:40:33 PDT; 1h 51min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 90452 (mysqld)
   CGroup: /system.slice/system-mysqld.slice/mysqld@instance1.service
           └─90452 /usr/sbin/mysqld --defaults-group-suffix=@instance1 --daemonize --pid-file=/var/run/mysqld/mysqld-instance1.pid
Jun 05 14:40:30 mysqlhost systemd[1]: Starting MySQL Server...
Jun 05 14:40:33 mysqlhost systemd[1]: Started MySQL Server.

[root@mysqlhost system]# systemctl status mysqld@instance2
● mysqld@instance2.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld@.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-06-05 14:40:57 PDT; 1h 53min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 90563 (mysqld)
   CGroup: /system.slice/system-mysqld.slice/mysqld@instance2.service
           └─90563 /usr/sbin/mysqld --defaults-group-suffix=@instance2 --daemonize --pid-file=/var/run/mysqld/mysqld-instance2.pid
Jun 05 14:40:54 mysqlhost systemd[1]: Starting MySQL Server...
Jun 05 14:40:57 mysqlhost systemd[1]: Started MySQL Server.

Enable systemd so that it start when server re-boot:

[root@mysqlhost lib]# systemctl enable mysqld@instance1
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld@instance1.service to /usr/lib/systemd/system/mysqld@.service.

[root@mysqlhost lib]#  systemctl enable mysqld@instance2
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld@instance2.service to /usr/lib/systemd/system/mysqld@.service.

Check mysqld:
[root@mysqlhost system]# ps -ef | grep mysqld
mysql     90452      1  0 14:40 ?        00:00:02 /usr/sbin/mysqld --defaults-group-suffix=@instance1 --daemonize --pid-file=/var/run/mysqld/mysqld-instance1.pid
mysql     90563      1  0 14:40 ?        00:00:02 /usr/sbin/mysqld --defaults-group-suffix=@instance2 --daemonize --pid-file=/var/run/mysqld/mysqld-instance2.pid
root      91927  68721  0 16:38 pts/0    00:00:00 grep --color=auto mysqld

Use temporary password from the /var/log/mysqld.log file to login first time.
#grep 'temporary password' /var/log/mysqld.log

Connect to mysqld:
[mysql@mysqlhost data]$ mysql -uroot -p --socket=/mysql/instance1/data/instance1.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Set password for mysql root user:

[mysql@mysqlhost data]$ mysql -uroot -p --socket=/mysql/instance2/data/instance2.sock
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' identified by '<code>';
Update root user setting to connect remotely:
mysql> UPDATE mysql.user SET Host='%' WHERE Host='localhost' AND User='root';
mysql> UPDATE mysql.db SET Host='%' WHERE Host='localhost' AND User='root';
mysql> FLUSH PRIVILEGES;

[root@mysqlhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2018-06-05 17:19:02 PDT; 54min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3082 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1508 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3085 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─3085 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Create Backup user:
CREATE USER 'bkusr'@'localhost' IDENTIFIED BY '<code>';
GRANT CREATE, INSERT, UPDATE, SELECT, DROP, RELOAD, ALTER, SUPER, PROCESS, LOCK TABLES,REFERENCES,CREATE ROUTINE,TRIGGER ON *.* TO 'bkusr'@'localhost';
GRANT CREATE, INSERT, DROP, UPDATE ON mysql.backup_progress TO 'bkusr'@'localhost';
GRANT CREATE, INSERT, SELECT, DROP, UPDATE ON mysql.backup_history TO 'bkusr'@'localhost';
GRANT REPLICATION CLIENT ON *.* TO 'bkusr'@'localhost';
Ref.: https://dev.mysql.com/doc/refman/5.7/en/using-systemd.html

Comments

Popular posts from this blog

MySQL InnoDB cluster troubleshooting | commands

Cluster Validation: select * from performance_schema.replication_group_members; All members should be online. select instance_name, mysql_server_uuid, addresses from  mysql_innodb_cluster_metadata.instances; All instances should return same value for mysql_server_uuid SELECT @@GTID_EXECUTED; All nodes should return same value Frequently use commands: mysql> SET SQL_LOG_BIN = 0;  mysql> stop group_replication; mysql> set global super_read_only=0; mysql> drop database mysql_innodb_cluster_metadata; mysql> RESET MASTER; mysql> RESET SLAVE ALL; JS > var cluster = dba.getCluster() JS > var cluster = dba.getCluster("<Cluster_name>") JS > var cluster = dba.createCluster('name') JS > cluster.removeInstance('root@<IP_Address>:<Port_No>',{force: true}) JS > cluster.addInstance('root@<IP add>,:<port>') JS > cluster.addInstance('root@ <IP add>,:<port> ') JS > dba.getC

MySQL slave Error_code: 1032 | MySQL slave drift | HA_ERR_KEY_NOT_FOUND

MySQL slave Error_code: 1032 | MySQL slave drift: With several MySQL, instance with master slave replication, I have one analytics MySQL, environment which is larger in terabytes, compared to other MySQL instances in the environment. Other MySQL instances with terabytes of data are running fine master, slave replication. But this analytics environment get started generating slave Error_code :1032. mysql> show slave status; Near relay log: Error_code: 1032; Can't find record in '<table_name>', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log <name>-bin.000047, end_log_pos 5255306 Near master section: Could not execute Update_rows event on table <db_name>.<table_name>; Can't find record in '<table_name>', Error_code: 1032; Can't find record in '<table_name>', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log <name>-bin.000047, end_l

InnoDB cluster Remove Instance Force | Add InnoDB instance

InnoDB cluster environment UUID is different on node: To fix it stop group replication, remove instance (use force if require), add instance back Identify the node which is not in sync: Execute following SQL statement on each node and identify the node has different UUID on all nodes. mysql> select * from mysql_innodb_cluster_metadata.instances; Stop group replication: Stop group replication on the node which does not have same UUID on all nodes. mysql > stop GROUP_REPLICATION; Remove instances from cluster: Remove all secondary node from the cluster and add them back if require. $mysqlsh JS >\c root@<IP_Address>:<Port_No> JS > dba.getCluster().status() JS > dba.getCluster () <Cluster:cluster_name> JS > var cluster = dba.getCluster("cluster_name"); JS >  cluster.removeInstance('root@<IP_Address>:<Port_No>'); If you get "Cluster.removeInstance: Timeout reached waiting......" JS > cluster.removeInstance(&#