You are on page 1of 42

MySQL Server

CJ
Introduction MySQL
• MySQL server is one of the most widely used relational database management systems.
( Structured collection of Data as its stored in separate tables )

• Name : My - Michael Monty Widenius (Monty) first daughter’s name.

• SQL – Structured Query Language

• MySQL version 1.0 Released May 1996

• Supports all major OS – Linux flavors (Mac), Windows ( from 1998 ) etc

• Open_Source – Till Oracle acquired Sun - Apr 2009


MySQL Enterprise Software
• MySQL Database
• MySQL Enterprise Backup
• MySQL Enterprise Monitor
• MySQL Enterprise HA
• MySQL Enterprise Scalability
• MySQL Enterprise Security
• MySQL Enterprise Audit
• MySQL Workbench Standard Edition

Find them for downloads :

My Oracle Support (MOS): This is the preferred location to download commercial builds as it includes all releases
since 2011 and some earlier releases.
Oracle Software Delivery Cloud (eDelivery): This only includes the latest patch release of the latest GA version
(currently the 8.0 series). As the repository is only updated once a month, it can lag compared to the release available
in My Oracle Support.
MySQL Downloads: This is for the Community releases only. (https://dev.mysql.com/downloads/)
Compatibility Between MySQL Servers and MySQL Clients/Tools
Client/Tool Client/Tool Version MySQL 5.6 MySQL 5.7 MySQL 8.0

8.0 ✗ ✓ ✓
MySQL Shell
8.0 ✗ ✓ ✓
MySQL Router
1.2 ✓ ✓ ✓
2.0 ✓ ✓ ✗
MySQL for Visual Studio

1.3 ✓ ✓ ✓
MySQL for Excel
13.2.4.0.0 ✓ ✓ ✓

Oracle Enterprise Manager for MySQL Database

3.12 ✓ ✗ ✗
MySQL Enterprise Backup 4.1 ✗ ✓ ✗
8.0 ✗ ✗ ✓
4.0 ✓ ✓ ✗
8.0 ✓ ✓ ✓
MySQL Enterprise Monitor

1.1 ✓ ✓ ✓
MySQL Notifier
8.0 ✓ ✓ ✓
MySQL Workbench
MySQL Server Versions
Change History :

• MySQL version 1.0 Released May 1996


• MySQL version 3.22 Release Oct 1996 ( ISAM (non-transactional) => MyISAM ( transactional) )
• MySQL version 4.0 Released Oct 2001 (MySQL/ InnoDB)
• MySQL version 5.0 Oct 2005
• MySQL acquired by Sun Microsystems in 2008
MySQL 5.1.38 – Oct 2009 => Maria DB – fork of mysql (Michael Monty Widenius’ second daughter)
• Oracle acquired Sun Microsystems in 2010 with MySQL included.
MySQL Server 5.5 ( Default – InnoDB )

• MySQL Server 8.0 ( Default – InnoDB )


MySQL 8.0.11 (2018-04-19)
MySQL 8.0.21 (2020-07-13)
MySQL Storage Engine or Table Types
• Component or Module that handles sql operations like (dml) operations on data from a database.
• How data is stored in database while creating a table.
• MySQL DB performance is dependent on the type of storage-engine used.
• MySQL can support close to 10 storage engine types
mysql> show engines\G;

MySQL supported storage engines:

 InnoDB
 MyISAM
 Memory
 CSV
 Merge
 Archive
 Federated
 Blackhole
 Example

• Pre MySQL 5.5 – default storage engine - MyISAM


• From MySQL 5.5 – Default Storage Engine - InnoDB
MySQL Patches
• No PSU – only Cumulative Patches
• Cumulative means : Current Release : MySQL 5.7.31 - includes all patches applied to 5.7.0, 5.7.1, 5.7.2, ... up to 5.7.31
• Apply the latest patches - download and install the latest patch release.

Change History :
•MySQL Server 5.5
•MySQL Server 5.6 (MySQL 5.6.10 (2013-02-05))
•MySQL Server 5.7

MySQL Server 5.7 Versions :


Changes in MySQL 5.7.9 (2015-10-21, General Availability)..
..
Changes in MySQL 5.7.31 (2020-07-13, General Availability)
Changes in MySQL 5.7.32 (Not yet released, General Availability)
Changes in MySQL 5.7.33 (Not yet released, General Availability)

•.MySQL Server 8.0


Changes in MySQL 8.0.11 (2018-04-19, General Availability)
..
Changes in MySQL 8.0.21 (2020-07-13, General Availability)
Changes in MySQL 8.0.22 (Not yet released, General Availability)
MySQL Server Installation Type
2.5.1 Installing MySQL on Linux Using the MySQL Yum Repository
2.5.2 Replacing a Third-Party Distribution of MySQL Using the MySQL Yum Repository
2.5.3 Installing MySQL on Linux Using the MySQL APT Repository
2.5.4 Installing MySQL on Linux Using the MySQL SLES Repository
2.5.5 Installing MySQL on Linux Using RPM Packages from Oracle
2.5.6 Installing MySQL on Linux Using Debian Packages from Oracle
2.5.7 Deploying MySQL on Linux with Docker
2.5.8 Installing MySQL on Linux from the Native Software Repositories
2.5.9 Installing MySQL on Linux with Juju
2.5.10 Managing MySQL Server with system

Type Setup Method Additional


Information
Apt Enable the MySQL Apt repository Documentation
Yum Enable the MySQL Yum repository Documentation
Zypper Enable the MySQL SLES repository Documentation
RPM Download a specific package Documentation
DEB Download a specific package Documentation
Generic Download a generic package Documentation
Source Compile from source Documentation
Docker Use Docker Hub for MySQL Community Edition; download Docker image for MySQL Documentation
Enterprise Edition from My Oracle Support
Oracle Unbreakable Linux Network Use ULN channels Documentation
MySQL Server 5.7 RPM Installation
As root user :
 
yum localinstall mysql-commercial-server-5.7.28-1.1.el7.x86_64.rpm mysql-commercial-client-5.7.28-1.1.el7.x86_64.rpm
mysql-commercial-common-5.7.28-1.1.el7.x86_64.rpm mysql-commercial-libs-5.7.28-1.1.el7.x86_64.rpm mysql-
commercial-libs-compat-5.7.28-1.1.el7.x86_64.rpm

Basic changes to find first time root password : vi /etc/my.cnf


[mysqld]
datadir=/apps/mysql/data
port=1216
socket=/apps/mysql/mysql.sock
log-bin=/apps/mysql/data/mysql-bin.log
bind-address=0.0.0.0

Start mysql server :


sudo service mysql start

Get the root password in /apps/mysql/data/mysql-bin.log

Login to Mysql Prompt :


mysql –uroot -p
Set SELinux contexts for MySQL Server
• Security-Enhanced Linux (SELinux) is a security architecture for Linux® systems that allows administrators to have more
control over who can access the system. 
• SELinux uses SELinx security policy to manage access permissions for all users, programs, processes, files,
and devices they act upon. 
• SELinux context – contains security-relevant information - SELinux user, role, type, level.
• All files, directories, devices, and processes have a security context (or label) associated with them.

To make SELinux context changes that survive a file system relabel:


 
1.Run the semanage fcontext -a options file-name|directory-name command, remembering to use the full
path to the file or directory.

2.Run the restorecon -v file-name|directory-name command to apply the context changes.

Guide:
How to set SELinux contexts for MySQL Server (Doc ID 2296123.1)
MySQL Physical Architecture
MySQL Logical Architecture
MySQL Logical Architecture
My.cnf
You can find the my.cnf file in one of the following locations:

/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
[datadir]/my.cnf

Default contents of my.cnf file :

basedir = dir_name ( Directory location to the MySQL binaries installation. ) - $MYSQL_HOME

datadir = dir_name ( Directory location to the MySQL database data, status and log files. )

pid-file = file_name ( Filename in which the mysqld server should write its process ID information. )

socket = file_name, -S file_name ( On Unix, the name of the Unix socket file to use, for connections made using a named pipe to a local server. )

port = 3306 ( default port ) FHLB Port 1216


MySQL Basics
mysql — The MySQL Command-Line Client

mysqladmin — A MySQL Server Administration Program

mysqlcheck — A Table Maintenance Program

mysqldump — A Database Backup Program

mysqlimport — A Data Import Program

mysqlpump — A Database Backup Program

mysqlshow — Display Database, Table, and Column Information

mysqlslap — A Load Emulation Client


Simple Commands for DB and User related
Check if MySQL is installed

rpm -qa | grep mysql


which mysqld
yum list installed | grep mysql
apt-cache show mysql

Check if MySQL is running currently :


ps - aux | grep mysqld or ps -ef | grep mysqld
sudo service mysql status

Check Version of MySQL:

mysql --version
mysql -V
mysql

show variables like '%version%';


select version();
status;
Start MySQL Server ( root ) :

service mysql start


service mysql restart

Stop MySQL Server ( root ) :


service mysql stop
Default databases
Default Databases
mysql contains tables that store information required by the MySQL server
information_schema  provides access to database metadata
performance_schema  feature for monitoring MySQL Server execution at a low level
sys a set of objects that helps DBAs and developers interpret data collected by the Performance Schema

In MySQL, physically, a schema is synonymous with a database. You can substitute the keyword SCHEMA instead
of DATABASE in MySQL SQL syntax, for example using CREATE SCHEMA instead of CREATE DATABASE.
Both MySQL DATABASE and SCHEMA are a collection of tables.
MySQL objects such as tables, table columns, views, users, indexes, functions, procedures, etc.
MySQL Objects Database Objects
CREATE DATABASE STORED PROCEDURE
CREATE EVENT STORED FUNCTION
CREATE FUNCTION TRIGGER
CREATE FUNCTION UDF EVENT
CREATE INDEX VIEW
CREATE LOGFILE GROUP TABLE
CREATE PROCEDURE INDEX
CREATE SCHEMA STORED ROUTINES
CREATE SERVER ..
CREATE TABLE etc
CREATE TABLESPACE
CREATE TRIGGER
CREATE USER
CREATE VIEW
Simple User related
Create/Connect /Drop Database :
CREATE DATABASE <db_name>;
CREATE Schema <db_name>;
Use <db_name>;

Create / Drop / Grant User:


CREATE USER 'hostuser'@'localhost’ IDENTIFIEDBY 'user_password’;
DROP USER 'hostuser'@'localhost’;

Global Priv : ( upcoming slide )

Check DB, User and Privs :

SELECT USER(),CURRENT_USER(),session_user(),system_user();
SELECT db, host, user FROM mysql.db ;
select DISTINCT User,host,account_locked,password_expired FROM mysql.user;
User Management
CREATE USER:
CREATEUSER'hostuser'@'localhost'IDENTIFIEDBY'user_password’;
CREATEUSER'hostuser'@’%'IDENTIFIEDBY'user_password’;

DROP USER:
DROP USER 'hostuser'@'localhost’;

RESET PASSWORD :
SET PASSWORD FOR 'hostuser'@'localhost’= 'auth_string’;
or 
ALTER USER 'hostuser'@'localhost’ IDENTIFIED BY 'auth_string';

GET DDL of the User :


SHOW CREATE USER 'hostuser'@'localhost’;

Frequently used Types of Permissions :


ALL PRIVILEGES: As the name suggest, this command gives users unlimited access to a specific database. This means the new user has all the privileges
to perform and execute all functions within the designated database.
CREATE: The user has permission to create tables and databases.
DELETE: The user can expunge rows from the designated table.
DROP: The user can drop tables and databases
INSERT: The user can add rows to a specific table
SELECT: User has the permission to read the specified database
UPDATE: User can update the rows in a table.
GRANT OPTION: User can give or remove the privileges of other users
Privileges
GRANT PRIV
GRANT type_of_permission ON database_name.table_name TO'hostuser'@'localhost’;
GRANT permission1, permission2 ON database_name.table_name TO'hostuser'@'localhost’;

Global Priv : GRANT type_of_permission ON *.* TO 'hostuser'@'localhost’;


DB Priv : GRANT type_of_permission ON <db_name>.* TO 'hostuser'@'localhost’;
Table Priv : GRANT type_of_permission ON <db_name>.<table_name> TO 'hostuser'@'localhost’;
FLUSH PRIVILEGES;  Apply privileges immediately

REVOKE PRIV :
REVOKE type_of_permission ON database_name.table_name TO'hostuser'@'localhost’;
REVOKE permission1, permission2 ON database_name.table_name TO'hostuser'@'localhost’;

CHECK :
SHOW GRANTS FOR 'hostuser'@'localhost’;
SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user;
SELECT * FROM information_schema.user_privileges;
SELECT * FROM information_schema.user_privileges WHERE GRANTEE="'hostuser'@'localhost’";
Security
SSL AUDITING
Enable SSL: Enable Auditing:
my.cnf variables : my.cnf variables :
[mysqld] / [mysqlclient] plugin-load=audit_log.so
ssl-cert=/apps/mysql/ssl/scpl-dbmysq-001.fhlbsf-i.com.cer audit-log-file=/apps/mysql/mysql_5.7.29/audit/audit.log
ssl-key=/apps/mysql/ssl/scpl-dbmysq-001.fhlbsf-i.com.key audit-log=FORCE_PLUS_PERMANENT
ssl-ca=/apps/mysql/ssl/scpl-dbmysq-001_2020-interim-ca.pem audit_log_format=JSON
Force SSL : audit_log_policy=LOGINS
require_secure_transport=ON audit_log_rotate_on_size=8M
audit_log_connection_policy=ALL
Enable SSL to user: audit_log_statement_policy=ALL
GRANT ALL PRIVILEGES ON database.* to 'hostuser'@'localhost’; REQUIRE SSL; audit_log_exclude_accounts=root
or
ALTER USER 'hostuser'@'localhost’ REQUIRE SSL; Extra Steps :
Disable or Remove SSL Type for user: By default, rule-based audit log filtering logs no auditable events for any
ALTER USER 'hostuser'@'localhost’ REQUIRE NONE; users.
User connect:
mysql –u<username> -h ‘hostname’ -P –p 1216 –sql-mode=REQUIRED SELECT audit_log_filter_set_filter('log_all', '{ "filter": { "log": true } }');
SELECT audit_log_filter_set_user('%', 'log_all');

Check DB is SSL enabled : Check audit enabled :


status show global variables like 'have_%audit’;
show global variables like 'have_%ssl’; Tail -1000f the audit log file
select user, host,ssl_type from mysql.user;
MySQL Enterprise Monitor vs Workbench
MySQL Enterprise Monitor MySQL Workbench

Tool continuously monitor your databases and alerts you to Graphical user interface tool used for the MySQL database
potential problems before they impact your system management.

MySQL Enterprise Monitor is a web-based application MySQL Workbench is a binary/executable based


application.

Enables you to monitor MySQL instances on your network It facilitates creation of new physical data models and
or on a cloud service. modification of existing MySQL databases with
reverse/forward engineering and change management
functions. 

SQL Development, Data Modeling (Design), Server


Administration, Data Migration.
Backup and Restore MySQL DB
MEB ( Separate downloadable Software) Mysqldump (Utility)
Physical backups of entire instances or selected databases, Performs logical backups, producing a set of SQL statements
tables, or both. Physical backups consist of raw copies of that can be executed to reproduce the original database
the directories and files that store database contents. object definitions and table data. (Text Backup)

hot backup with MySQL Enterprise Backup  Logical backups are performed with the MySQL server
running. The server is not taken offline.
Physical backups is suitable for large, important databases logical backup with mysqldump for smaller data volumes or
that need to be recovered quickly when problems occur. to record the structure of schema objects.

mysqldump does not dump


the INFORMATION_SCHEMA, performance_schema,
or sys schema by default.
mysqlbackup --socket=/var/lib/mysql/mysql.sock mysqldump --port 1216 --single-transaction --set-gtid-
--datadir=/var/lib/mysql --backup_dir=/backup-mysql/09- purged=ON --all-databases --triggers --routines --events >
05-2019 backup-and-apply-log --port=1216 --protocol=tcp /backup-mysql/<db-name>.sql
--trace=2

 cold backup by copying files while the MySQL server is shut down;
Hot and cold backups are physical backups that copy actual data files, which can be used directly by the mysqld server for
faster restore.
MySQL DB Refresh Steps
1) Export from DB from PROD using mysqldump ( Verify DB Size and Table count ) :
mysqldump --port 1216 --add-drop-database --flush-privileges --flush-logs --single-transaction --set-gtid-purged=OFF --triggers --routines --events
--databases db_name > db_name_"$(date +%d-%m-%Y-%H_%M)".sql
2) scp the file to target server

3) Import dump into the server ( Verify DB Size and Table count ) ;
mysql>
source /apps/mysql/mysqldump/db_name_30-09-2020-18_59_20.sql;
Or
mysql < /apps/mysql/mysqldump/db_name_30-09-2020-18_59_20.sql;

4) Verify Query :
SELECT table_schema AS "Database", ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)",
count(*) as "Total Table Counts",MAX(create_time) create_time,MAX(update_time) update_time
FROM information_schema.TABLES WHERE table_schema = "db_name" GROUP BY table_schema Order by 2 desc;

5) Process Automated in Source and Target :


PROD : /apps/mysql/scripts/export_dbref.sh
DEV/TEST: /apps/mysql/scripts/import_dbref.sh
Replication
• Continuously creating a copy of source data from Master MySQL on a node to one or more SLAVE MySQL nodes over network.
• Level of Replication ( All Databases , Selected Databases , Specific Tables within a database ).
• Two replication schemes supported by MySQL Replication:
• Asynchronous replication ( by default )
• Semi-synchronous replication ( need to enable a plugin )
• Replication methods :
• The traditional method is based on replicating events from the source's binary log, and requires the log files and
positions in them to be synchronized between source and replica.
- Types of events: Row based (default) or statement based or mixed type.

• The newer method based on global transaction identifiers (GTIDs) is transactional and therefore does not require working with log files
or positions within these files.

Replication Types :   MySQL Replication Topology (Doc ID 1489113.1)

• Master-Slave
• Master_Master (Active-Active)
• Master_Master (Active-Passive)
• Group Replication ( Clustered - InnoDB Cluster )
Replication in-Short
1) All database operations are copied to the master’s binary log.

2) Slaves connect to the master and asks for the data.

3) The slave servers get the data in masters binary log.

4) Slaves then apply the binary log to its relay log.


The relay-log is used by the slave server to synchronize with the master. If you don’t set it,
mysql uses the hostname.

5) The relay log is read by the SQL thread process and it applies all the operations/data to
the slave’s database and its binary log.
Asynchronous replication
•  The primary executes transactions, commits them and then
they are later (thus asynchronously) sent to the secondaries to
be either re-executed (in statement-based replication) or
applied (in row-based replication).
• Master keeps writing data
Semi-synchronous replication
• The master does not confirm/commit transactions to the client
until at least one slave has copied the change to its relay log,
and flushed it to disk.
• Master waits for the data – received in any one slave but does
care/bother/wait for commit to happen on Slave.
Replication basics…
Client Master Slave

DATA DATA
INSERT
INTO …

• Clients perform data modification on master server


• INSERT, SELECT, DELETE, LOAD DATA
• EXECUTE in MySQL 5.0 and above
Replication basics…
Client Master Slave

DATA
DATA

Binary INSERT
Log INTO …

• Immediately following execution of command on master, the command is written to


the local binary log
• Additionally, the master records its unique ID (to prevent endless loops in circular
replication scenarios) and the timestamp for use with statements which use NOW(),
etc.
Replication basics…
Client Master Slave

DATA
DATA

INSERT Replication INSERT Relay


INTO … Thread INTO … Log

• If the slave is online, the command is transmitted to the slave in parallel (well, immediately following)
to being written in the local binary log
• Otherwise, when the slave next connects it will receive a list of all pending statements from the
master server’s binary log
• The slave’s replication IO thread stores the command in the local relay log
Replication basics… Slave

DATA
Master
Client
DATA

Thread
SQL
DATA INSERT
INTO …
Replication INSERT I/O
Binary Logs Relay Log
Thread INTO … Thread

• Once the data is received in the slave’s relay log, the slave SQL thread executes the
command locally, bringing the slave up-to-date with the master
• In MySQL 3.23, the IO and SQL threads were just one thread. In later versions this
was changed to 2 threads.
Replication Setup Steps
Common Steps for Master and Slave :
• Add replication variables to my.cnf in both the Master and Slave/Master nodes
• Restart mysql server/service

On Primary / Master:
• Create a replication user and grant REPLICATION SLAVE privilege
• Create a snap-shot / dump of Master Server
• Copy dump file or snap-shop to Slave Server

On Standby / Slave :
• Start P2 mysql_server in read-only
• Update Slave : CHANGE MASTER ( inserting the Master’s replication user credentials ) – channel is created for replication
• On Standby / Slave :
• Start slave mysql in read-only
• Update Slave : CHANGE MASTER ( inserting the Master’s replication user credentials ) – channel is created for replication
• CHANGE MASTER TO MASTER_HOST='<NODE_1>', MASTER_PORT=<port>, MASTER_USER='<user>', MASTER_PASSWORD='<password>',
MASTER_AUTO_POSITION=1 FOR CHANNEL 'Node1';
• Restore dump file or snap-shop into Slave Server ( now both Master and Slave in same sync )
• Start Slave process.
• Restore dump file or snap-shop into Slave Server ( now both Master and Slave in same sync )
• Start Slave process.
Replication Threads
Slave Threads
IO thread continuously receives updates from master and writes to local relay log
When a START SLAVE statement is issued on a replica server, the replica creates an I/O thread, which connects to the source
and asks it to send the updates recorded in its binary logs.
The replication I/O thread reads the updates that the source's Binlog Dump thread sends (see previous item) and copies
them to local files that comprise the replica's relay log.
The state of this thread is shown as Slave_IO_running in the output of SHOW SLAVE STATUS.
SQL thread continuously executes statements in relay log.
The replica creates an SQL thread to read the relay log that is written in relay log by the replication I/O thread and execute
the transactions contained in it.
Master Threads / Binary log dump thread.:
• Dedicated to scanning the binary logs on the master and sending updates to the connected slave – whenever binary
requests for it.
• The source creates a thread to send the binary log contents to a replica when the replica connects. This thread can be
identified in the output of SHOW PROCESSLIST on the source as the Binlog Dump thread.
• The binary log dump thread acquires a lock on the source's binary log for reading each event that is to be sent to the
replica. As soon as the event has been read, the lock is released, even before the event is sent to the replica.
Replicaiton my.cnf variables Master-Slave
Master Slave

 ##replication ##replication
server-id=1 server-id=2
gtid_mode=ON gtid_mode=ON
enforce-gtid-consistency=ON enforce-gtid-consistency=ON
binlog_format = ROW binlog_format = ROW
master_info_repository='TABLE' master_info_repository='TABLE'
relay_log_info_repository='TABLE’ relay_log_info_repository='TABLE’
read_only=ON
super_read_only=ON
 
log-bin=/backup/mysql-binlogs/mysql-bin log-bin=/backup/mysql-binlogs/mysql-bin
log-bin-index=/backup/mysql-binlogs/mysql-bin.index log-bin-index=/backup/mysql-binlogs/mysql-bin.index
master-info-file=/backup/mysql-binlogs/master.info master-info-file=/backup/mysql-binlogs/master.info
relay-log=/backup/mysql-relaylogs/relay-bin
relay_log_index=/backup/mysql-relaylogs/lvpl-dbmysq-001-relay-bin.index
 
max_binlog_size=1G max_binlog_size=1G
expire_logs_days=10 expire_logs_days=10
relay_log_space_limit=2G relay_log_space_limit=2G
Replicaiton my.cnf variables - (Master(active)-Master(passive))
Master-Active Master - Passive

 ##replication ##replication
server-id=1 server-id=2
gtid_mode=ON gtid_mode=ON
enforce-gtid-consistency=ON enforce-gtid-consistency=ON
binlog_format = ROW binlog_format = ROW
master_info_repository='TABLE' master_info_repository='TABLE'
relay_log_info_repository='TABLE' relay_log_info_repository='TABLE’
auto_increment_offset = 1 auto_increment_offset = 2
auto_increment_increment = 2 auto_increment_increment = 2
  read_only=ON
super_read_only=ON

log-bin=/backup/mysql-binlogs/mysql-bin log-bin=/backup/mysql-binlogs/mysql-bin
log-bin-index=/backup/mysql-binlogs/mysql-bin.index log-bin-index=/backup/mysql-binlogs/mysql-bin.index
master-info-file=/backup/mysql-binlogs/master.info master-info-file=/backup/mysql-binlogs/master.info
relay-log=/backup/mysql-relaylogs/relay-bin relay-log=/backup/mysql-relaylogs/relay-bin
relay_log_index=/backup/mysql-relaylogs/scpl-dbmysq-001-relay-bin.index relay_log_index=/backup/mysql-relaylogs/lvpl-dbmysq-001-relay-bin.index
   
max_binlog_size=1G max_binlog_size=1G
expire_logs_days=10 expire_logs_days=10
relay_log_space_limit=2G relay_log_space_limit=2G
Replication Types :   MySQL Replication Topology (Doc ID 1489113.1)

Replication Topology Master (P1) Slave (P2)


Master-Slave Read-Write Read_only

No Slave Running Slave is started

P1 is P2’s Master P2 is P1’s Slave


Master-Master(Active-Active) Read-Write Read-Write

Slave is running P1 Slave is running P2

P1 is P2’s Master P2 is P1’s Slave

P1 is P2’s Slave P2 is P1’s Master


Master_Master (Active-Passive) Read-Write Read-Only

Slave is running P1 Slave is running P2

P1 is P2’s Master P2 is P1’s Slave

P1 is P2’s Slave P2 is P1’s Master


Check Replication
P1 (MASTER) – True Copy or Source Copy P2 (SLAVE) – Secondary Copy
mysql> show slave status\G;
mysql> show master status\G; *************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
*************************** 1. row *************************** Master_Host: 10.101.117.60
Master_User: rep_lv
File: mysql-bin.001123 Master_Port: 1216
Connect_Retry: 60
Position: 636095634 Master_Log_File: mysql-bin.001123
Read_Master_Log_Pos: 636095634
Relay_Log_File: relay-bin-10@002e101@002e117@002e60.024274
Binlog_Do_DB: Relay_Log_Pos: 35097
Relay_Master_Log_File: mysql-bin.001123
Binlog_Ignore_DB: Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Executed_Gtid_Set: 709ce169-dc4d-11ea-9dae-005056931831:1-6135176, Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
aeadbeda-a629-11ea-b000-005056bff976:1-1922 Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 636095634
Relay_Log_Space: 52526064
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 709ce169-dc4d-11ea-9dae-005056931831
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 709ce169-dc4d-11ea-9dae-005056931831:41839-6135176
Executed_Gtid_Set: 709ce169-dc4d-11ea-9dae-005056931831:1-6135176,
aeadbeda-a629-11ea-b000-005056bff976:1-1922
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name: 10.101.117.60
Master_TLS_Version:
1 row in set (0.01 sec)
Check Replication
P1 (MASTER) – True Copy or Source Copy P2 (SLAVE) – Secondary Copy
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
mysql> show master status\G;
Master_Host: 10.201.117.60
Master_User: rep_prd
*************************** 1. row ***************************
Master_Port: 1216
Connect_Retry: 60 File: mysql-bin.001130
Master_Log_File: mysql-bin.001130
Read_Master_Log_Pos: 564345544
Relay_Log_File: relay-bin-10@002e201@002e117@002e60.000473
Position: 584508375
Relay_Log_Pos: 461
Relay_Master_Log_File: mysql-bin.001130
Binlog_Do_DB:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Binlog_Ignore_DB:
Replicate_Do_DB:
Replicate_Ignore_DB: Executed_Gtid_Set: 709ce169-dc4d-11ea-9dae-005056931831:1-6223523,
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
aeadbeda-a629-11ea-b000-005056bff976:1-1922
Replicate_Wild_Ignore_Table:
Last_Errno: 0
1 row in set (0.00 sec)
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 564345544
Relay_Log_Space: 901
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2
Master_UUID: aeadbeda-a629-11ea-b000-005056bff976
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set: 709ce169-dc4d-11ea-9dae-005056931831:1-6223426,
aeadbeda-a629-11ea-b000-005056bff976:1-1922
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name: 10.201.117.60
Master_TLS_Version:
1 row in set (0.00 sec)
FHLB Setup
ENV3 SERVER NAME

PROD (P1) scpl-dbmysq-001 - 10.101.117.60

PROD-DR (P2) lvpl-dbmysq-001 - 10.201.117.60

MySQL MEM vmpl-dbmyem-001 - 10.101.117.61

DEV scdl-dbmysq-001 : 10.103.117.60

TEST lvtl-dbmysq-001: 10.202.117.60

RESERVED FOR DBA TESTING scdl-dbtoys-001 10.103.117.250           #rhel7


scdl-dbtoys-002 10.103.117.251           #reel7 
FHLB Mysql Scripts
Purpose of crontab and frequency Script Location

Monitor mysql service ( every 5 mins ) /apps/mysql/scripts/mysql_up_check.sh

mysql binary purge script ( Hourly ) /apps/mysql/scripts/mysqlpurgebin_log.sh

mysql daily backup ( 4 time a day ) /apps/mysql/scripts/mysqlback.sh

Monitor mysql replication status /apps/mysql/scripts/mysql_rep_mon.sh

OS Alerts Check (every 5 min) /apps/mysql/scripts/os_space_chk.sh


Cluster Types
• MySQL Group Replication /MGR Cluster alternative to InnoDB Cluster
• NDB Cluster

You might also like