Point In Time Recovery Using Binlog In MySQL-Part 1

Lets see how we can recover our database or tables using MySQL Binary logs. To avail this feature make sure that BINARY LOGS  are enabled in MySQL.Here We will see how to recover table data. We have full backup plus binary logs as incremental backup. Lets assume we have taken full backup at 9 PM and database gets crashed at 9:30 PM. how to recover we will see in this post.

Step 1: Lets perform full database Backup using mysqldump command.

1

Now Login to database and select values in table.

2

Now Add some rows into table so that there should be new entries in binlog file to recover the data.

3

Now we have inserted 2 more rows in table. now we can drop the table and then restore full backup and last 2 rows can be recovered using binlog file.

4

Since we have dropped table and there was only one table in database we can restore full database now.

5

6

Now lets recover last 2 rows using binlog file.Here we have recovered data using Timestamp to a point so that only till that time data can be recovered.

7

Since we have executed recovery statement lets check in table whether data is being recovered or not. We can see id 6 and 7 has been added in table.

8

This post is just for demo purpose. please do not apply these steps on production setup unless you are confident.

More Scenarios coming soon on this. Stay tuned

 

MySQL Master-Slave Replication Using GTID.

Today we will explore how to create Master-Slave Replication in MySQL 5.6 using GTID. GTID’s are unique transaction ID given to each transaction executed on master server.in  case of any failure on slave server we can recover using GTID.

Creation of GTID replication is almost same as Master Slave replication but there are few changes involved in my.cnf file of mysql server.

If replication is already created then you can make both the server READ ONLY and proceed with the given steps.

we can execute read only variable on global level.

Here we have make MASTER server read only.

1

Now make SLAVE Server read only.

2

Now Add below variables in my.cnf file of MASTER server and restart services.

3

Once service on MASTER server is restarted you can check if GTID_MODE is on.

4

Now to generate some GTID perform some transaction in MySQL on Master server.We can see a GTID is being created for performed transaction.

5

Now on SLAVE server open my.cnf file and make given changes in screenshot and restart MySQL service.

6

7

Once MySQL is restarted on SLAVE server. login to Database and check slave status.

8.1

8.2

Now we can match GTID on Master and Slave server. Since SLAVE IO RUNNING and SLAVE SQL RUNNING is in YES state. Replication is working properly.

Please do comment for any suggestion.

2015 in review

The WordPress.com stats helper monkeys prepared a 2015 annual report for this blog.

Here’s an excerpt:

The concert hall at the Sydney Opera House holds 2,700 people. This blog was viewed about 14,000 times in 2015. If it were a concert at Sydney Opera House, it would take about 5 sold-out performances for that many people to see it.

Click here to see the complete report.

MySQL MASTER-SLAVE Replication

Hello and welcome back to another topic on TechDBA. Today we will explore how to configure Replication in MySQL. there are different types of replication in MySQL such Master-Slave , Master-Master and Circular Replication. Our today’s topic will be Master-Slave Replication as other 2 types will be covered in separate session.

First we should know what is Replication in MySQL.

A simple answer If you want to distribute your data at different location you can use MySQL replication technique. Replication enable the data from one MySQL server called as Master to be replicated to other MySQL server called as Slave server.

MySQL Replication are mostly asynchronous in nature that slave need not to connect to all the time to master to receive the update from master.

MySQL Replication can be used for DR purpose or Data Security or Reporting purpose where you don’t have have to fetch the data from production server and automatically load on production server will be decreased.

Now let us see how to configure MySQL MASTER-SLAVE Replication.

To Configure Master-Slave Replication in MySQL minimum 2 servers are required. one will act as Master and other will act as Slave.

Now we have below servers.

MASTER         192.168.201.130
SLAVE            192.168.201.1

Basic Requirement of MySQL Replication is that BINLOG Should be enabled and Server should be identified with unique server id.

make those changes in my.cnf in linux and my.ini in windows.

First stop MySQL Services on Master Server.

1

Now add below lines in my.cnf and restart MySQL Services

2

Once you have restarted MySQL Services you can login to database and check the variables if they are properly set or not.

3

Now master changes have done. On slave server provide a unique server id.

4

Now login to database and check if the same has done properly or not

5

Once Configuration changes are done. Create a MySQL user and provide with replication slave privileges.This user will be connected to master database and copy the changes to slave server.

6

Once the user has been created check the required privileges for the user.

7

Now take the backup of master database you want to replicate. since i want to replicate only zahid database so i am taking backup of that only. if you want to replicate all the databases you can take backup of all.

9

Now create database on slave server.

10

Once the database is being created restore it on slave server using below command.

11

After restoring database check if everything is working properly on slave server.

12

Now on Slave server execute below command to configure the replication.

13

Now on slave server Check slave status whether it is in sync or not using below command.since we have configured just now we need to start slave in order to sync.

14

Execute below command to start slave.

20

now check if server is in sync or not. Slave_Io_running and Slave_Sql_Running should be in yes mode then only data will be in sync across the server. if any one of them is no mode means there is some issue.

15

Now on master i have created a database named rehan and it should be automatically created at slave server.

16

Now on slave server we can see database is being created. it means replication is working properly.

17

To stop the slave use below command.

18

When you stop the slave both Slave_Io_running and Slave_Sql_Running will be in no mode. means slave is stopped and no update from master will be copied to slave unless you start it.

19

To start Slave use below command.

20

Once started slave you can check both Slave_Io_running and Slave_Sql_Running should be in yes mode.

21

Now we are replicating all the databases its not a good idea we should not replicate all the database especially system databases such as mysql or information_schema. here i have created one user and it got replicated automatically on slave server.

22

23_slave

To avoid such problem on slave server add the name of databases you want to replicate using replicate-do-db variable name in my.cnf or my.ini. doing so will replication only those databases and will not replication any databases.

you can also use replicate-ignore-db=dbname. here it will not replication this database but whenever you will create new database it will start replicating that. good idea is to use replicate-do-db command.

after changes restart MySQL Services.

24

Now we have done the changes and restarted MySQL service you can check it will display names of databases will be replicated.

25

This was simple method to achieve replication in MySQL. you can always explore options available for replication. in next topic we will see how to configure Master-Master replication.

Comment and suggestions are always welcome

Capture MYSQL Database Size in Table using Cron / MySQL Events

Hello friends Welcome back to another topic related to MySQL. Today we will be exploring how to capture MySQL Database Growth report in Table. We can achieve this by using Linux CRONTAB or MYSQL EVENTS.

Some time we have requirement where we need to capture daily database growth size and maintain it in excel file for reporting purpose and capacity planning. Recently i had this requirement so i thought to share with you guys.

First we need to create a table in MySQL. Here i have created a separate database and in that i have created a table which will capture MySQL database growth on daily basis.

1

Since we have created database now we can create table using required field. Here in Time stamp will will be updating automatically whenever data will get inserted in the table.

2

After creating table we can describe it and check if everything has been created properly.

3

Now We will add one record manually in the table in order to check if all goes well. then we will implement the same query in a script or event and schedule as per our requirement.

Here i am capturing specific databases you can replace your database name with mysql and test. and if you want values in GB then add one more /1024 before from clause.

4

Now we can see in below screenshot entries are getting inserted in the table. Now we can proceed ahead and implement the same in script.

5

 ##CAPTURE DATABASE SIZE USING CRONTAB ON LINUX

If you are working with Linux System you can create a script using VI editor  as given in below screenshot. Replace username,password,host as per your requirement.

6

Once the script has been created. you can give execute permission on the script so that you can execute it manually or using crontab.

7

Now add file named db_size.sh to crontab and schedule as per your requirement. i have scheduled it on daily basis means this file will get executed every night at 12:00AM.

8

Now you can check if you have made proper entry for crontab.

9

Now i have executed the script manually just for testing if it works. since it is working now it will not give any problem in crontab.

10

##CAPTURE DATABASE SIZE USING MYSQL EVENTS IN LINUX OR WINDOWS

In above method we have captured database size in table using Crontab . But now if i am not working on linux or my linux user doesnt have permission for crontab then we can achieve the same using MYSQL EVENTS. this is one of most important feature of MySQL i will suggest every DBA to explore this. We will be having more topics on EVENTS in future.

Below event i have created it will get executed on daily basis and capture the database size in table.

11

Now you can check if you have created and scheduled event properly.

12

Now you can check if the database size in getting captured in created table properly or not.

13

COMMENTS AND SUGGESTION ARE WELCOME

PASSWORD VALIDATION PLUGIN IN MYSQL

Here we will explore how to implement Password Validation Plugin in MySQL 5.6.As a MySQL DBA We all know that by default if we assign any password to MySQL user it will accept but when it comes to security we should make sure database user is having secured password which should be hard to guess. By Implementing password validation plugin we can achieve this. 

Please note this feature is not available in MySQL Community Edition but if you are using MySQL Enterprise Edition this comes by default. you just have to install and use it. But still Community users can learn this for future use.

Now follow below given steps to implement the same.

First check the plugin directory of MySQL.

1

Go to given path and check it. We can see lots of plugins are present in Plugin Directory Of MySQL. We need PASSWORD_VALIDATE.SO file.

2

Now Stop MySQL Services

3

Now open my.cnf file of MySQL at /etc/ location and add below entries. on windows file is named as my.ini

4

Once entries are made you can start MySQL Services.

5

Now login to MySQL And execute below command. i am getting error because plugin is already installed.

6

Since Plugin is installed you can check the variable named VALIDATE_PASSWORD.

7

Now as you can see above. you can define policy as per your requirement like what should be password length and how many character and special character should be present in the password.

Now try to assign some simple password and check if it accepts. We can see its not accepting simple password.

8

Now try to assign some complicated password with mix case. We can see it has accepted the password.

9

Now you can create password dictionary. password present in file will not be accepted.

10

Give proper permission to dictionary file as it will be used by MySQL user.

11

Now open my.cnf file and add below entries in the file 

12

Now restart MySQL Services

13

Now check if the changes are reflecting or not. We can see all the necessary changes are getting reflected.

14

comments And Suggestion Are Welcome

Create Database Manually In Oracle 11G On Linux

Here we will explore how to create database manually in Oracle 11G. Although there is a utility available called as DBCA using which you can create database with ease but i will recommend you to create it manually doing so we will know where we have kept all the configuration files etc.

Below are some highlights of steps involved in creating database manually.

1. create pfile , password file for new database
2. Create necessary directories
3. create instance and start database in nomount mode
4. use create database to create new database
5. Run necessary scripts file to create data dictonary table
6. Testing newly created database and registering to listener

First Login as ORACLE OS USER.

1

Now goto $ORACLE_HOME/dbs location and copy the content of init.ora into file name you want to create

2

3

Now open initzahid.ora and make the necessary changes as per your need.

4

Now as per changes you have made. make sure you have created necessary folders given in the path. if  not then create.

5

Now goto path and check if the necessary folders has been created.

6

Now open /etc/oratab file and make entry of database name and $ORACLE_HOME location.

7

8

Now set the environment path for zahid database. you can simply do it by executing oraenv command.

9

Now create a password file for sys user.

10

Once password file is created you can login to database and check.

11

Now you can start listener services if you want else it can be configure later also.

12

Now login to database and start the database using pfile you have created.

13

Now you can create spfile from pfile if you want. Major different using spfile over pfile is that you can make online changes in configuration file how ever in pfile you have to restart database for any global changes.

14

Now check if the spfile has been created or not.

15

Now all the configuration part has been completed Now you can execute create database command.I have created a script to create database you can execute this command on sql prompt also.

Now login to oracle and execute zahid.sql file to create database.

16

18

Now database has been created

Now import various catalog file to database

19

20

21

22

Once these catalogs are imported you can check if the database is mounted properly and it is opened in read write mode or not

23

Now you can once restart database services and test

24

Now come out of database and check if all the processes are running properly or not.

25 

Since all the processes are running properly Database has been created successfully.

Comments and suggestion are welcome

INSTALLATION OF MYSQL ON WINDOWS

Lets explore how to install and configure MySQL on Windows server. Although installing MySQL on windows is quite simple but still it might be useful for some one who face some issue during installation.

To install MySQL First download it from MySQL website.

http://dev.mysql.com/downloads/installer/

Now i have download below binary for MySQL

1

Now click on Above binary to install it. Please note you must have admin privileges to do the install it.

2

Click on Next Button

3

Now Accept Team And Condition And Click on Next

4

Now select the type of installation you want to perform. if you are doing on server machine do the complete installation. for developer or local machine you can use typical installation.

5

Click on install Button

6

7

Once the progress bar is completed. you can click on next button

8

Now click on next

9

Now Click on Finish button it will configure MySQL server

10

Click on Next button

11

Now you can select the type of configuration and then click on next button

12

Select type of configuration i.e developer or server or dedicated machine.

13

Now Select the type of database. most cases multifunctional is preferable

14

Now select the innodb tablespace path. this is the location where ibdata will be located.

15

I have selected C Drive. now click on next

16

Select the type and number of concurrent connection and click on next button

17

If you want you can change port of MySQL and add firewall exception. and click next

18

Select character set and click next

19

Now provide service name for MySQL and if you want to include environment variable check the checkbox and click on next button.

20

Now Provide MySQL Password and click on next button

21

Now click on execute button

22

23

Now installation is completed. you can click on finish button

24

Now you can login from command prompt to mysql and check

25

From services tab you can start or stop mysql services.

26

Click on stop or start .

27

Now installation is completed.

Comment and Suggestion are welcome

Installation Of MySQL 5.6 Enterprise Edition On Linux

Here we will explore how to install and configure MYSQL 5.6 ENTERPRISE EDITION on Linux Systems.Both the installation of Community and Enterprise Edition are same. If you are upgrading MySQL from older version to MySQL 5.6 then make sure you have taken backup of all the database configuration file and physical backup of data directory.

Follow Below given steps to install MySQL 5.6 on Linux

1. First Download the require packages from oracle e-delivery it is available 30 days as trial you can always test it.

1

2. Now You can install all the packages by using RPM command

2

3.Once installation is done you can restart MySQL service.

3

I Am getting above ERROR because i have not deleted OLD MySQL Data directory that is why it is trying to start service using old PID. Now we can resolve by below methods.

Now goto /var/lib/mysql and delete all the contents.

4

Now Execute Below command to over come this issue.

5

6

7

4. By Default my.cnf file will be located at /usr location on database server. You can copy the same to /etc location and restart database services.

9

5. Now Restart Database Services

10

6.Now Run Secure Installation to secure Database Server.

11

12

Once Restart Database Service and Try To Login to database

14

Now Login to Database

13

Now setup is completed successfully.

Comments and suggestions are Welcome

Create your own website, free on WordPress.com.Create your own website.
Start free