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