Monday, October 31, 2016

Setting Up a New Replication Slave Using MySQL Enterprise Backup Utility (with GTID enabled)


1) Make sure whether the binary logging is enabled on the master database server and to make InnoDB aware of the current binary log position, you must run at least one transaction while binary logging is enabled. For example I'm executing following command,
mysql> insert into first values(1,'siva','dasari');
Query OK, 1 row affected (0.10 sec)

2) Verify the binlog position on master database server.
mysql> show master status \G
+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000012 |      432 | repl01       |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

3) Take full backup as image file.
mysqlbackup --backup-dir=/usr/siva/mysql_full_backup --backup-image=full.bki backup-to-image

4) Copy the backup folder to target server. (make sure the destination directory has right permissions)
scp -r /usr/siva/mysql_full_backup/ siva@192.168.159.143:/usr/siva/ 

5) Stop the mysql service on destination.
systemctl stop mysqld

6) Remove all the files in mysql data directory.
rm -rf /var/lib/mysql/

7) Grant owner permissions to the account used to access the backup image file location.
chown -R siva:siva /usr/siva/

8) Use following command to restore full backup by applying the logs.
mysqlbackup --datadir=/var/lib/mysql --backup-image=/usr/siva/mysql_full_backup/full.bki --backup-dir=/usr/siva/mysql_full_backup copy-back-and-apply-log

9) Edit the my.cnf file on the new slave and add skip-slave-start and event_scheduler=off under the [mysqld] section.
10) Bring the mysql service online. (Initially it failed to bring the service online, fixes are provided below)
systemctl start mysqld

Issues encountered while bringing the service online.
i)  Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
Fix: chown -R mysql:mysql /var/lib/mysqld  (add permissiona to mysql user)
ii) SELinux is preventing /usr/sbin/mysqld from getattr access on the file /var/lib/mysql/ibdata1.
Fix: restorecon -R -v /var/lib

11) Once the slave instance is up and running. Issue following command from mysql client on slave,
mysql> RESET MASTER;
# Stop the binary logging on slave mysql> SET sql_log_bin=0
12) From the restored directory find the file named "backup_gtid_executed.sql" which contains following commands. (update the file as required.)
# On a new slave, issue the following command if GTIDs are enabled:
SET @@GLOBAL.GTID_PURGED='e65fa8h2-0a1e-11f5-b980-100205633290:1-3';

# To use GTID handshake protocol uncomment below and modify it as required. CHANGE MASTER TO MASTER_HOST='192.168.159.141',MASTER_USER='slave_user', MASTER_PASSWORD='****', MASTER_AUTO_POSITION = 1;

13) After updating the file execute the script file as below,
mysql>source /usr/siva/mysql_full_backup/backup_gtid_executed.sql

14) Execute following commands once you connect on mysql instance,
mysql> UPDATE mysql.event SET status = 'SLAVESIDE_DISABLED';

15) Remove the edits from my.cnf which are added as part of step -9.
16) Reatart the slave mysql service.
 systemctl stop mysqld

systemctl start mysqld

17) Once the service is successfully started check the slave status as below,
mysql> SHOW SLAVE STATUS \G

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event                   Master_Host: 192.168.159.141                   Master_User: slave_user                   Master_Port: 3306                 Connect_Retry: 60               Master_Log_File: mysql-bin.000012           Read_Master_Log_Pos: 432                Relay_Log_File: mysqlslave-relay-bin.000003                 Relay_Log_Pos: 320         Relay_Master_Log_File: mysql-bin.000012              Slave_IO_Running: Yes             Slave_SQL_Running: Yes Slave is up & running succefully.
========================================================

Thursday, October 6, 2016

Setting Up a New Replication Slave Using MySQL Enterprise Backup Utility (without GTID enabled)


1) Make sure whether the binary logging is enabled on the master database server and to make InnoDB aware of the current binary log position, you must run at least one transaction while binary logging is enabled. For example I'm executing following command,
mysql> insert into first values(1,'siva','dasari');
Query OK, 1 row affected (0.10 sec)

2) Verify the binlog position on master database server.
mysql> show master status \G
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000012 |      432 | repl01       |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

3) Take full backup as image file.
mysqlbackup --backup-dir=/usr/siva/mysql_full_backup --backup-image=full.bki backup-to-image

4) Copy the backup folder to target server. (make sure the destination directory has right permissions)
scp -r /usr/siva/mysql_full_backup/ siva@192.168.159.143:/usr/siva/ 

5) Stop the mysql service on destination.
systemctl stop mysqld

6) Remove all the files in mysql data directory.
rm -rf /var/lib/mysql/

7) Grant owner permissions to the account used to access the backup image file location.
chown -R siva:siva /usr/siva/

8) Use following command to restore full backup by applying the logs.
mysqlbackup --datadir=/var/lib/mysql --backup-image=/usr/siva/mysql_full_backup/full.bki --backup-dir=/usr/siva/mysql_full_backup copy-back-and-apply-log

9) Edit the my.cnf file on the new slave and add skip-slave-start and event_scheduler=off under the [mysqld] section.
10) Bring the mysql service online. (Initially it failed to bring the service online, fixes are provided below)
systemctl start mysqld

Issues encountered while bringing the service online.
i)  Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
Fix: chown -R mysql:mysql /var/lib/mysqld  (add permissiona to mysql user)
ii) SELinux is preventing /usr/sbin/mysqld from getattr access on the file /var/lib/mysql/ibdata1.
Fix: restorecon -R -v /var/lib

11) Execute following commands once you connect on mysql instance,
mysql>CHANGE MASTER TO MASTER_HOST='192.168.159.141',MASTER_USER='slave_user', MASTER_PASSWORD='****', MASTER_LOG_FILE='mysql-bin.000012', MASTER_LOG_POS=432;

mysql> UPDATE mysql.event SET status = 'SLAVESIDE_DISABLED';

12) Remove the edits from my.cnf which are added as part of step -9.
13) Reatart the slave mysql service.
 systemctl stop mysqld
systemctl start mysqld

14) Once the service is successfully started check the slave status as below,
mysql> SHOW SLAVE STATUS \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event                   Master_Host: 192.168.159.141                   Master_User: slave_user                   Master_Port: 3306                 Connect_Retry: 60               Master_Log_File: mysql-bin.000012           Read_Master_Log_Pos: 432                Relay_Log_File: mysqlslave-relay-bin.000003                 Relay_Log_Pos: 320         Relay_Master_Log_File: mysql-bin.000012              Slave_IO_Running: Yes             Slave_SQL_Running: Yes Slave is up & running succefully.
========================================================

Sunday, September 18, 2016

MySQL Backup / Copy Backup / Restore Backup using mysqlbackup enterprise utility.

1) Add following startup parameters to my.cnf on source server under [mysqlbackup].
user = mysql_backup_user
password
socket=/var/lib/mysql/mysql.sock

2) Take full backup as image file.
#mysqlbackup --backup-dir=/usr/siva/mysql_full_backup --backup-image=full.bki backup-to-image

3) Copy the backup folder to target server. (make sure the destination directyory has right permissions)
#scp -r /usr/siva/mysql_full_backup/ siva@192.168.159.143:/usr/siva/ 

4) Stop the mysql service on destination.
systemctl stop mysqld 

5) Remove all the files in mysql data directory.
#rm -rf /var/lib/mysql/ 

6) Grant owner permissions to the account used to access the backup image file location.
#chown -R siva:siva /usr/siva/

7) Use following command to restore full by applying the logs.
#mysqlbackup --datadir=/var/lib/mysql --backup-image=/usr/siva/mysql_full_backup/full.bki --backup-dir=/usr/siva/mysql_full_backup copy-back-and-apply-log

8) Bring the service online. (Initially it failed to bring the service online, fixes are provided below)
#systemctl start mysqld 
  Issues encountered while bringing the service online.
              i)  Can't change dir to '/var/lib/mysql/' (Errcode: 13 - Permission denied)
             Fix:   #chown -R mysql:mysql /var/lib/mysql  (add permissiona to mysql user)
ii) SELinux is preventing /usr/sbin/mysqld from getattr access on the file /var/lib/mysql/ibdata1.
             Fix: #restorecon -R -v /var/lib

9) Now you should be able to successfully bring the services online.

Thursday, September 8, 2016

MySQL InnoDB File Architecture


Keep in mind that /var/lib/mysql/ibdata1 is the busiest file in the InnoDB infrastructure. It normally houses six types of information:

  • Table Data
  • Table Indexes
  • MVCC (Multiversioning Concurrency Control) Data
  • Rollback Segments
  • Undo Space
  • Table Metadata (Data Dictionary)
  • Double Write Buffer (background writing to prevent reliance on OS caching)
  • Insert Buffer (managing changes to non-unique secondary indexes)
  • Please find below architecture for complete details,

Wednesday, September 7, 2016

Access MySQL from remote machine / If remote login to MySQL fails.


By default the firewall is enabled on linux environment. We have two options to configure the firewall,

1) Turn off the firewall completely.
2) Allow remote access on the port where MySQL is listening on running.

a) Follow below steps to go with option (1).
#Disable the firewall service:
 $systemctl disable firewalld

#Stop the firewall service:
 $systemctl stop firewalld

#Verify the firewall status:
 $systemctl status firewalld


b) Follow below steps to go with option (2).
#Add the port to access list by executing following command
 $sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent

#Now reload the updated firewall configurations.
 $sudo firewall-cmd --reload

#Now if you run the check you will see the ports added to exception list.
$sudo firewall-cmd --list-all
  public (default, active)
  interfaces: eno16777736
  sources:
  services: dhcpv6-client ssh
  ports: 3306/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

Monday, September 5, 2016

How to reset / recover MySQL root password


There are many ways recovering or resetting MySQL root password but the one i like & follow is below procedure,

1) Update MySQL configuration file to add "skip-grant-tables"(without quotes) under [mysqld] section. When the server is restarted this option causes the MySQL service / process to start without using the privilege system at all, which gives anyone with access to the server unrestricted access to all databases.

2) Now restart MySQL process / service issuing following command.
$ sudo systemctl restart mysqld

3) Once the server is restarted you can change the password of the root user issuing following command in sequence,
[siva@mysql ~]$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 Server version: 5.7.14 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, 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> UPDATE mysql.user SET authentication_string=PASSWORD("xxxyyy") WHERE User='root';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
4) Now, you have successfully updated the root password. You have to secure the MySQL access by removing "skip-grant-tables" from my.cnf file & restart MySQL service.

5) Now you should be able to login to MySQL using updated root password.

6) But once you try to perform any operations it may throw below exception & solution follows, (here when you execute alter you may retain same passowrd or change the password based on your policy requirements)
mysql> select * from mysql.user where user="root";
ERROR 1820 (HY000):
You must reset your password using ALTER USER statement before executing this statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxyyyzzz';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

Saturday, September 3, 2016

Install / Configure MySQL Enterprise Backup Utility


1) Identify the right package for your operating system & download. I have choose "MySQL Enterprise Backup 4.0.3 RPM for Oracle Linux / RHEL 7 x86 (64bit)" based on my operating system.

2) Execute the following command to install,
$yum install meb-4.0.3-el7.x86_64.rpm

3) If you type the command 'mysqlbackup' now you will get command not found error this is expected because the system doesn't know where the executable is located. By default the executable's are installed at location "/opt/mysql/meb-4.0"
$cd /opt/mysql/meb-4.0

4) We have to execute following command to add the path to environment variable where the system looks for all executable's when you try to execute a command. (note this is valid until your session is live, to make it permanent you have to add this to user's .bash_profile file)
$PATH=$PATH:/opt/mysql/meb-4.0/bin

5) Now execute following command to run the backup of mysql server, (I have included complete shell output)
$mysqlbackup --user=root --password  --port=3306  --socket=/var/lib/mysql/mysql.sock --backup-dir=/usr/siva/mysql_backup_new/ backup-and-appl
MySQL Enterprise Backup version 4.0.3 Linux-3.8.13-118.4.2.el7uek.x86_64-x86_64 [2016/08/04]
Copyright (c) 2003, 2016, Oracle and/or its affiliates. All Rights Reserved.

 mysqlbackup: INFO: Starting with following command line ...
 mysqlbackup --user=root --password --port=3306
        --socket=/var/lib/mysql/mysql.sock
        --backup-dir=/usr/siva/mysql_backup_new/ backup-and-apply-log

 mysqlbackup: INFO:
Enter password:
 mysqlbackup: INFO: MySQL server version is '5.7.14-log'
 mysqlbackup: INFO: MySQL server compile os version is 'Linux'
 mysqlbackup: INFO: Got some server configuration information from running server.

IMPORTANT: Please check that mysqlbackup run completes successfully.
           At the end of a successful 'backup-and-apply-log' run mysqlbackup
           prints "mysqlbackup completed OK!".

160831 19:56:33 mysqlbackup: INFO: MEB logfile created at /usr/siva/mysql_backup_new/meta/MEB_2016-08-31.19-56-33_backup_apply_log.log

--------------------------------------------------------------------
                       Server Repository Options:
--------------------------------------------------------------------
  datadir = /var/lib/mysql/
  innodb_data_home_dir =
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /var/lib/mysql/
  innodb_log_files_in_group = 2
  innodb_log_file_size = 50331648
  innodb_page_size = 16384
  innodb_checksum_algorithm = crc32
  innodb_buffer_pool_filename = ib_buffer_pool
  innodb_undo_directory = /var/lib/mysql/
  innodb_undo_tablespaces = 0
  innodb_undo_logs = 128

--------------------------------------------------------------------
                       Backup Config Options:
--------------------------------------------------------------------
  datadir = /usr/siva/mysql_backup_new/datadir
  innodb_data_home_dir = /usr/siva/mysql_backup_new/datadir
  innodb_data_file_path = ibdata1:12M:autoextend
  innodb_log_group_home_dir = /usr/siva/mysql_backup_new/datadir
  innodb_log_files_in_group = 2
  innodb_log_file_size = 50331648
  innodb_page_size = 16384
  innodb_checksum_algorithm = crc32
  innodb_buffer_pool_filename = ib_buffer_pool
  innodb_undo_directory = /usr/siva/mysql_backup_new/datadir
  innodb_undo_tablespaces = 0
  innodb_undo_logs = 128

 mysqlbackup: INFO: Unique generated backup id for this is 14726985936584861

 mysqlbackup: INFO: Creating 14 buffers each of size 16777216.
160831 19:56:33 mysqlbackup: INFO: Full Backup operation starts with following threads
                1 read-threads    6 process-threads    1 write-threads
160831 19:56:33 mysqlbackup: INFO: System tablespace file format is Barracuda.
160831 19:56:33 mysqlbackup: INFO: Starting to copy all innodb files...
160831 19:56:33 mysqlbackup: INFO: Found checkpoint at lsn 2530912.
160831 19:56:33 mysqlbackup: INFO: Starting log scan from lsn 2530816.
160831 19:56:33 mysqlbackup: INFO: Copying log...
160831 19:56:33 mysqlbackup: INFO: Log copied, lsn 2530921.
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/ibdata1 (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/engine_cost.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/gtid_executed.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/help_category.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/help_keyword.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/help_relation.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/help_topic.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/innodb_index_stats.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/innodb_table_stats.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/plugin.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/server_cost.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/servers.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/slave_master_info.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/slave_relay_log_info.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/slave_worker_info.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/time_zone.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/time_zone_leap_second.ibd (Barracuda file format).
160831 19:56:33 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/time_zone_name.ibd (Barracuda file format).
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/time_zone_transition.ibd (Barracuda file format).
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/mysql/time_zone_transition_type.ibd (Barracuda file format).
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/repl01/first.ibd (Barracuda file format).
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/sys/sys_config.ibd (Barracuda file format).
160831 19:56:34 mysqlbackup: INFO: Completing the copy of innodb files.
160831 19:56:34 mysqlbackup: INFO: Starting to copy Binlog files...
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/mysql-bin.000001.
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/mysql-bin.000002.
160831 19:56:34 mysqlbackup: INFO: Preparing to lock tables: Connected to mysqld server.
160831 19:56:34 mysqlbackup: INFO: Starting to lock all the tables...
160831 19:56:34 mysqlbackup: INFO: All tables are locked and flushed to disk
160831 19:56:34 mysqlbackup: INFO: Copying /var/lib/mysql/mysql-bin.000003.
160831 19:56:34 mysqlbackup: INFO: Completed the copy of binlog files...
160831 19:56:34 mysqlbackup: INFO: Opening backup source directory '/var/lib/mysql'
160831 19:56:34 mysqlbackup: INFO: Starting to backup all non-innodb files in
        subdirectories of '/var/lib/mysql'
160831 19:56:34 mysqlbackup: INFO: Copying the database directory 'mysql'
160831 19:56:34 mysqlbackup: INFO: Copying the database directory 'performance_schema'
160831 19:56:34 mysqlbackup: INFO: Copying the database directory 'repl01'
160831 19:56:34 mysqlbackup: INFO: Copying the database directory 'sys'
160831 19:56:34 mysqlbackup: INFO: Completing the copy of all non-innodb files.
160831 19:56:34 mysqlbackup: INFO: A copied database page was modified at 2530912.
          (This is the highest lsn found on page)
          Scanned log up to lsn 2530921.
          Was able to parse the log up to lsn 2530921.
160831 19:56:34 mysqlbackup: INFO: All tables unlocked
160831 19:56:34 mysqlbackup: INFO: All MySQL tables were locked for 0.642 seconds.
160831 19:56:34 mysqlbackup: INFO: Reading all global variables from the server.
160831 19:56:34 mysqlbackup: INFO: Completed reading of all global variables from the server.
 mysqlbackup: INFO: Writing config file for server '5.7.14-log'.
160831 19:56:34 mysqlbackup: INFO: Creating server config files server-my.cnf and server-all.cnf in /usr/siva/mysql_backup_new/
160831 19:56:34 mysqlbackup: INFO: Full Backup operation completed successfully.
160831 19:56:34 mysqlbackup: INFO: Backup created in directory '/usr/siva/mysql_backup_new/'
160831 19:56:34 mysqlbackup: INFO: MySQL binlog position: filename mysql-bin.000003, position 154

-------------------------------------------------------------
   Parameters Summary
-------------------------------------------------------------
   Start LSN                  : 2530816
   End LSN                    : 2530921
-------------------------------------------------------------


 mysqlbackup: INFO: Creating 14 buffers each of size 65536.
160831 19:56:34 mysqlbackup: INFO: Apply-log operation starts with following threads
                1 read-threads    1 process-threads
 mysqlbackup: INFO: Using up to 100 MB of memory.
160831 19:56:34 mysqlbackup: INFO: ibbackup_logfile's creation parameters:
          start lsn 2530816, end lsn 2530921,
          start checkpoint 2530912.
 mysqlbackup: INFO: InnoDB: Doing recovery: scanned up to log sequence number 2530921.
 mysqlbackup: INFO: InnoDB: Starting an apply batch of log records to the database...
.
InnoDB: Progress in percent: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 
37 38 39 40 41 42 43 44 45 46 47 48 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 
89 90 91 92 93 94 95 96 97 98 99
 mysqlbackup: INFO: InnoDB: Setting log file size to 50331648.
 mysqlbackup: INFO: InnoDB: Setting log file size to 50331648.
160831 19:56:36 mysqlbackup: INFO: We were able to parse ibbackup_logfile up to
          lsn 2530921.
 mysqlbackup: INFO: Last MySQL binlog file position 0 154, file name mysql-bin.000003:154
160831 19:56:36 mysqlbackup: INFO: The first data file is '/usr/siva/mysql_backup_new/datadir/ibdata1'
          and the new created log files are at '/usr/siva/mysql_backup_new/datadir'
160831 19:56:36 mysqlbackup: INFO: Apply-log operation completed successfully.
160831 19:56:36 mysqlbackup: INFO: Full backup prepared for recovery successfully.

mysqlbackup completed OK!

Thursday, August 25, 2016

MySQL installation from scratch

1) Once login to unix system update the yum repositories by issuing following command.
$sudo yum update

2) Find if there are any traces of previously installed mysql on the system
$rpm -qa | grep mysql

3) You can either issue following command to directly install MySQL from exisitng repos.
$sudo yum localinstall mysql-community-common-5.7.24-1.el7.x86_64.rpm 
mysql-community-libs-5.7.24-1.el7.x86_64.rpm mysql-community-client-5.7.24-1.el7.x86_64.rpm 
mysql-community-devel-5.7.24-1.el7.x86_64.rpm mysql-community-server-5.7.24-1.el7.x86_64.rpm

(This will install mysql server along with all its dependencies)
(or)
Alternatively you can download the latest or your required community version of MySQL & update your repository first and then install it.

   $wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
   $sudo rpm -ivh mysql57-community-release-el7-8.noarch.rpm
   $yum update
   $sudo yum install mysql-server 

(This will install mysql server along with all its dependencies)
(Do not proceed with below step if you would like to have custom configurations for MySQL. Update /etc/my.cnf file first & then proceed with below step)
4) Start mysql service    
$sudo systemctl start mysqld

5) Verify if mysqld service is started successfully or not.
$sudo systemctl status mysqld

6) Get the default root password created with installation for mysql 'root' user account.
$sudo grep 'temporary password' /var/log/mysqld.log

7) Connect to mysql instance using temporary root password & update the root password.
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'XXyyZZ!';

8) Once mysql is installed you have to secure the mysql access. For more details you can refer to one of my blogs "MySQL Secure Installation" with multiple options.

Tuesday, August 16, 2016

MySQL Internal Architecture, Memory Architecture, Core modules & their flow.


MySQL Internal Architecture (Pluggable storage engines):



MySQL Memory Architecture:





MySQL Core Modules & Flow:


Monday, August 15, 2016

MySQL differences between MyISAM vs InnoDB vs Memory Storage Engines.


Feature
MyISAM
InnoDB
Memory
ACID Transaction
No
Yes
No
Configurable ACID Properties
No
Yes
No
Crash Safe
No
Yes
No (RAM)
Foreign Key Support
No
Yes
No
Multi Version Concurrency Control (MVCC)
No
Yes
No
Geospatial datatype
Yes
Yes
No
Geospatial indexing
Yes
No
No
Full-text Search Index
Yes
No
No
Data Cache
No
Yes
N/A
Compressed Data
Yes
Yes
No
Storage Limits
256TB
64TB
RAM
Storage Cost
Low
High
N/A
Memory Cost
Low
High
Medium
Locking Granularity
Table
Row
Table
Encrypted Data
Yes
Yes
Yes
Replication Support
Yes
Yes
Yes
Cluster Database Support
No
No
No
B-Tree Indexes
Yes
Yes
Yes
Clustered Indexes
No
Yes
No


Advantages of InnoDB
-InnoDB should be used where data integrity comes a priority because it inherently takes care of them by the help of relationship constraints and transactions.
-Faster in write-intensive (inserts, updates) tables because it utilizes row-level locking and only hold up changes to the same row that’s being inserted or updated.

Disadvantages of InnoDB
-Because InnoDB has to take care of the different relationships between tables, database administrator and scheme creators have to take more time in designing the data models which are more complex than those of MyISAM.
-Consumes more system resources such as RAM. As a matter of fact, it is recommended by many that InnoDB engine be turned off if there’s no substantial need for it after installation of MySQL.
-No full-text indexing.

Advantages of MyISAM
-Simpler to design and create, thus better for beginners. No worries about the foreign relationships between tables.
-Faster than InnoDB on the whole as a result of the simpler structure thus much less costs of server resources.
-Full-text indexing.
-Especially good for read-intensive (select) tables.

Disadvantages of MyISAM
-No data integrity (e.g. relationship constraints) check, which then comes a responsibility and overhead of the database administrators and application developers.
-Doesn’t support transactions which is essential in critical data applications such as that of banking.
-Slower than InnoDB for tables that are frequently being inserted to or updated, because the entire table is locked for any insert or update.

MySQL Secure Installation / MySQL Hardening Steps / Securing MySQL

You can straight forward use below secure installation for mysql after the core installation,
           --MySQL secure installation
             mysql-secure-installation

You can follow below instructions individually to secure / harden mysql access.

           --Set strong password for root user in mysql.
                   set password for ‘root’@’localhost’ = PASSWORD(‘password’);
                   flush privileges;
        (or)
                   update mysql.user set authentication_string=PASSWORD('password') where user ='root';
                   flush privileges;

           --Remove anonymous users
                      delete from mysql.user where user =’’;
                      flush privileges;

           --Start MySQL to disable the use of symbolic links.
           --Any user having write access to data directory can disable the symbolic links & can potentially drop the database.
                      Add symbolic-links=0 in /etc/my.cnf

           --Rename the root account in mysql
                      update mysql.user set user=’dbadmin’ where user=’root’;

           --Enable proper logging MySQL as required with following keys in my.cnf
                      #Recommend to log mysql logs in  syslogs
                      [mysqld_safe]
                      syslog

                      #Alternatively you can specify your own path
                      [mysqld_safe]
                      log_error=/var/log/mysql/mysql_error.log

                      [mysqld]
                      log_error=/var/log/mysql/mysql_error.log

           --Remove test database after mysql initial installation.
                      drop database test;

           --Disable TCP/IP connectivity
                      Add skip-networking in /etc/my.cnf