SlideShare a Scribd company logo
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
MYSQL TRAINING
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Mysql =>
• Installation
• Install Multiple Mysql Instances on same host
• Change default location of data files
• Basic Mysql Commands
• Mysqldump
• Restore
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Mysql Installation=>
Mysql installation is based on RPMs that needs to be
installed on the server. Mysql software RPM’s is
available from dev.mysql.com as community version
which can be downloaded as per the OS on which the
installation needs to be done.
http://dev.mysql.com/downloads/mysql
Minimum of 2 RPMs are needed on the server, a server
and client RPM. Without client rpm installation, mysql
server cannot be accessible and hence its mandatory to
get both the rpms installed correctly.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Install Multiple Instances of Mysql on same
host =>
Mysql services work as a daemon process on a machine. Although it’s
possible to run multiple daemon processes on a machine but it’s not a
official supported way and hence it’s not a recommended configuration
to be done on Production servers.
By giving different my.cnf configuration files with different data
directories, different socket & different port, different pid files we can
configure multiple instance of Mysql.
Regeneron Slave server “renritdb01b.regeneron.regn.com” is an
example of multiple Instances running on a host.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Here is an example of how multiple Mysql
instances can run on a node.
-bash-3.2$ ps -ef |grep -i mysql
root 6592 1 0 2015? 00:00:00 /bin/sh /usr/bin/mysqld_safe --
datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log-
error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid
mysql 11746 1 0 2011 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --
defaults-file=/opt/mysql5_data/my.cnf --datadir=/opt/mysql5_data/ --
user=mysql --pid-file=/opt/mysql5_data/node1.pid --skip-external-locking --
port=3341 --socket=/tmp/mysql41.sock
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Change default location of Myisam and
Innodb data files
When we do a new installation of mysql server then default data directory is /var/lib/mysql
on Linux OS.
If we need to change default directory to user defined then the steps needs to be
performed.
• Stop mysql services using command like /etc/init.d/mysql stop
• Change following parameters in /etc/init.d/mysql file
Edit the file and check for first occurrence of datadir variable and make changes to it
as below.
datadir=/data01/mysql-data/db
• change below parameters in /etc/my.cnf
datadir=/data01/mysql-data/db
innodb_data_home_dir = /data01/mysql-data/db
• Move all the datafiles from source to target folders
• Start mysql services with /etc/init.d/mysql start
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Basic Commands for checking Mysql is
running fine & for creating db or users=>
• It will tell us if db is working fine or any locks are there
on db & long running queries and the time for which the
process is either active or idle. It also shows the total no
of sessions being connected to the mysql server.
mysql> show processlist;
• Check Mysql is running on Server.
$ ps –ef |grep –i mysql
• Creating a new database
mysql> create database abc;
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
• How many db’s are in Mysql Instance
mysql> show databases;
• Create users in Mysql
mysql> create user abc@’localhost’ identified by
'abc'; -- This creates user and allow only local access to the user
mysql> create user abc@’%’ identified by 'abc';
-- This creates user and allow access over the network to the users
mysql> GRANT ALL PRIVILEGES ON DB1.* TO
'abc'@'localhost'; -- Grant all privileges on all the tables on
DB1 database to user which can connect locally.
mysql> GRANT ALL PRIVILEGES ON DB1.* TO
'abc'@'%'; -- Grant all privileges on all the tables on DB1
database to user which can connect locally.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
mysql> GRANT ALL PRIVILEGES ON *.* TO
'abc'@'%'; -- Grant all privileges on all the tables on DB1
database to user which can connect on network.
We need to give below command after creating user so that it can
flush from memory and comes in affect.
mysql> flush privileges;
• Check the slave process status =>
mysql> show slave statusG
There are 3 values to look for in the status:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
• How to check locks and release all or specific
locks
mysql> show processlist;
+-----------+------------+------------------------------------------+---------
| Id | User | Host | db |
Command | Time | State
| Info |
+-----------+------------+------------------------------------------+---------
| 98485035 | jirauser | 10.31.82.49:35725 |
jiradb | Sleep | 1049 |
| NULL |
We will get all the info like from which db user, app
server (host) on which db lock is coming
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
If we need to release that lock we need to kill that ID, check ID for specific lock & kill
that id with kill “id” command.
Mysql> kill “id”;
• Mysql Service Start/Stop
#sudo to mysql
$/etc/init.d/mysql start => for starting
$/etc/init.d/mysql stop => for stopping
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
• Delete bin logs from Master when space is full on disk.
Check first how far is slave replication behind its master before purging the binary logs on
master instance:
Run show master status get bin log id
Mysql> show master status;
--Moving to next binary log
Mysql> flush logs;
mysql> Purge binary logs to <binlog from above-1>;
OR
Delete binary logs that are n days old
mysql> PURGE BINARY LOGS BEFORE DATE_SUB(
NOW( ), INTERVAL 2 DAY); -- Deleting all binary logs that are 2 days
old
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
• Skipping statements on slave when it’s stopped due to
errors:
mysql> SET GLOBAL sql_slave_statement_skip_counter=1; --
This will skip only the last problematic statement
Storage engines in Mysql:
Mysql daemon process acts as a framework which
can be plugged with one or many storage engines
to create table and store data in it. All storage
engines comes with different characteristics and
before creating a new database or a table it should
be decided in advance that the application is
compatible to which storage engine in mysql.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Commonly used storage engines in Mysql are as follow:
1. MYISAM =>
MyISAM is the default storage engine. Each MyISAM table is stored on disk in
three files. The files have names that begin with the table name and have an
extension to indicate the file type. An .frm file stores the table format. The data
file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex)
extension.
Properties:
• MyISAM implements table-level lock for inserting and updating.
• MyISAM does not support transactions & foreign keys.
• Also a long running SELECT will also lock the table for other sessions
to access it.
• MyISAM tables are auto commit and hence it cannot be committed or
rolled back.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
2. INNODB:
InnoDB is a transaction-safe storage engine for MySQL that has commit,
rollback, and crash-recovery capabilities to protect user data.
Properties:
• InnoDB row-level locking and Oracle-style consistent no locking
reads increase multi-user concurrency and performance.
• To maintain data integrity, InnoDB also supports FOREIGN KEY
referential-integrity constraints.
• The InnoDB storage engine maintains its own buffer pool for caching
data and indexes in main memory.
• InnoDB stores its tables and indexes in a tablespace, which may
consist of several files (or raw disk partitions). This is different from,
for example, MyISAM tables where each table is stored using separate
files.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
We can create db with storage engine, we can create
table with non default storage engine
mysql> CREATE TABLE t (i INT) ENGINE = INNODB;
&
we can change storage engine of an existing table like
below command,
mysql> Alter table t (i INT) ENGINE =MYISAM;
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
How to find current storage engine for a table =>
mysql> show table status like 'onlineregsession'G
*************************** 1. row ***************************
Name: onlineregsession
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 1725842
Avg_row_length: 384
Data_length: 663991508
Max_data_length: 281474976710655
Index_length: 117795840
Data_free: 0
Auto_increment: 1726849
Create_time: 2011-06-11 19:35:03
Update_time: 2012-04-30 02:12:39
Check_time: 2011-06-11 19:36:40
Collation: latin1_swedish_ci
Checksum: NULL
Create_options:
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
MYSQL BACKUP & RESTORE
MYSQLDUMP
Mysqldump is a logical backup tool equivalent to exp/imp tool of oracle.
It is used to dump a database or a collection of databases for backup. It
creates a *.sql file with DROP table, CREATE table and INSERT into
sql-statements of the source database. To restore the database, execute
the *.sql file on destination database.
1) Backup a single database
$mysqldump -u root -p[root_password] -–databases [database_name] >
dumpfilename.sql
2) Backup Multiple databases
$mysqldump -u root -p[root_password] --databases db_name1
db_name2 > dumpfilename.sql
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
3) Backup all databases containing MyISAM and/or Innodb tables –
CONSISTENT DUMP.
mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)
From second session, use below command for backup
$mysqldump --all-databases –single-transaction --master-data=2
>dbdump.db
When backup will be finished then from first session where we acquire
read lock give below command to release locks
mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0.00 sec)
4) Backup all databases containing MyISAM and Innodb tables
– INCONSISTENT DUMP
$mysqldump --all-databases >dbdump.db
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
--single-transaction : This option sends a START TRANSACTION SQL
statement to the server before dumping data. It is useful only with
transactional tables such as InnoDB, because then it dumps the
consistent state of the database at the time when BEGIN was issued
without blocking any applications. This is a method for taking a consistent
backup of innodb tables. This option will not take consistent backup of
Myiasm tables. This is not lock any Innodb tables and a consistent backup
can be taken without impacting any production processes.
For taking consistent backup of Myisam tables there are 2 options
available.
• Take a mysql session connecting to the server and run FLUSH
table with read locks. This will lock all the tables on the database with read
lock with no DML operation permitted. From another session take
mysqldump with consistent image. Release the locks from the first
session.
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
• If there is a slave configured for primary database, then on
slave perform the following:
Stop the slave process on slave server. Initiate mysqldump, this will be a
consistent backup since no transactions are getting written onto slave.
Once the dump is completed, the again start the slave process.
Restore backup which are taken by mysqldump utility
1. If we took backup of a single database & didn’t use --database
switch while backup then we need to create database before restore
mysql> create database database_name;
$mysql -u root -p[root_password] [database_name] < dumpfilename.sql
2. When took backup with --database switch then no need to create
database manually
$mysql -u root -p[root_password] < dumpfilename.sql
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
3. If we have multiple database backup & we need to restore only
one, put db name which we want to restore in restore command
$mysql -u root -p[root_password] dbname < dumpfilename.sql
Click to edit Master title style
Click to edit Master text styles
Second level
Third level
Fourth level
Fifth level
Thank You

More Related Content

Similar to Mysql-Basics.pptx

Performence tuning
Performence tuningPerformence tuning
Performence tuning
Vasudeva Rao
 
Multiple instances on linux
Multiple instances on linuxMultiple instances on linux
Multiple instances on linux
Vasudeva Rao
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
Dave Stokes
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
Dave Stokes
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
Tahsin Hasan
 
MySQL database
MySQL databaseMySQL database
MySQL database
lalit choudhary
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
Dave Stokes
 
Getting started with my sql
Getting started with my sqlGetting started with my sql
Getting started with my sql
Web Sky
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 Enliufabin 66688
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
Dave Stokes
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manualMir Majid
 
Get mysql clusterrunning-windows
Get mysql clusterrunning-windowsGet mysql clusterrunning-windows
Get mysql clusterrunning-windows
JoeSg
 
Collaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsCollaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAs
Nelson Calero
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysqlVasudeva Rao
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
SULTHAN BASHA
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
Dave Stokes
 

Similar to Mysql-Basics.pptx (20)

Mysql all
Mysql allMysql all
Mysql all
 
Performence tuning
Performence tuningPerformence tuning
Performence tuning
 
Multiple instances on linux
Multiple instances on linuxMultiple instances on linux
Multiple instances on linux
 
MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016MySQL Replication Basics -Ohio Linux Fest 2016
MySQL Replication Basics -Ohio Linux Fest 2016
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
 
Architecting cloud
Architecting cloudArchitecting cloud
Architecting cloud
 
MySQL database
MySQL databaseMySQL database
MySQL database
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
 
Mysql tutorial 5257
Mysql tutorial 5257Mysql tutorial 5257
Mysql tutorial 5257
 
Getting started with my sql
Getting started with my sqlGetting started with my sql
Getting started with my sql
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
Mysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 EnMysql Replication Excerpt 5.1 En
Mysql Replication Excerpt 5.1 En
 
ConFoo MySQL Replication Evolution : From Simple to Group Replication
ConFoo  MySQL Replication Evolution : From Simple to Group ReplicationConFoo  MySQL Replication Evolution : From Simple to Group Replication
ConFoo MySQL Replication Evolution : From Simple to Group Replication
 
My sql technical reference manual
My sql technical reference manualMy sql technical reference manual
My sql technical reference manual
 
Get mysql clusterrunning-windows
Get mysql clusterrunning-windowsGet mysql clusterrunning-windows
Get mysql clusterrunning-windows
 
Collaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAsCollaborate 2012 - Administering MySQL for Oracle DBAs
Collaborate 2012 - Administering MySQL for Oracle DBAs
 
Mater,slave on mysql
Mater,slave on mysqlMater,slave on mysql
Mater,slave on mysql
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
 
Sql installation
Sql installationSql installation
Sql installation
 
MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016MySQL Replication Update -- Zendcon 2016
MySQL Replication Update -- Zendcon 2016
 

Recently uploaded

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 

Recently uploaded (20)

Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 

Mysql-Basics.pptx

  • 1. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level MYSQL TRAINING
  • 2. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Mysql => • Installation • Install Multiple Mysql Instances on same host • Change default location of data files • Basic Mysql Commands • Mysqldump • Restore
  • 3. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Mysql Installation=> Mysql installation is based on RPMs that needs to be installed on the server. Mysql software RPM’s is available from dev.mysql.com as community version which can be downloaded as per the OS on which the installation needs to be done. http://dev.mysql.com/downloads/mysql Minimum of 2 RPMs are needed on the server, a server and client RPM. Without client rpm installation, mysql server cannot be accessible and hence its mandatory to get both the rpms installed correctly.
  • 4. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Install Multiple Instances of Mysql on same host => Mysql services work as a daemon process on a machine. Although it’s possible to run multiple daemon processes on a machine but it’s not a official supported way and hence it’s not a recommended configuration to be done on Production servers. By giving different my.cnf configuration files with different data directories, different socket & different port, different pid files we can configure multiple instance of Mysql. Regeneron Slave server “renritdb01b.regeneron.regn.com” is an example of multiple Instances running on a host.
  • 5. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Here is an example of how multiple Mysql instances can run on a node. -bash-3.2$ ps -ef |grep -i mysql root 6592 1 0 2015? 00:00:00 /bin/sh /usr/bin/mysqld_safe -- datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --log- error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid mysql 11746 1 0 2011 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe -- defaults-file=/opt/mysql5_data/my.cnf --datadir=/opt/mysql5_data/ -- user=mysql --pid-file=/opt/mysql5_data/node1.pid --skip-external-locking -- port=3341 --socket=/tmp/mysql41.sock
  • 6. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Change default location of Myisam and Innodb data files When we do a new installation of mysql server then default data directory is /var/lib/mysql on Linux OS. If we need to change default directory to user defined then the steps needs to be performed. • Stop mysql services using command like /etc/init.d/mysql stop • Change following parameters in /etc/init.d/mysql file Edit the file and check for first occurrence of datadir variable and make changes to it as below. datadir=/data01/mysql-data/db • change below parameters in /etc/my.cnf datadir=/data01/mysql-data/db innodb_data_home_dir = /data01/mysql-data/db • Move all the datafiles from source to target folders • Start mysql services with /etc/init.d/mysql start
  • 7. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Basic Commands for checking Mysql is running fine & for creating db or users=> • It will tell us if db is working fine or any locks are there on db & long running queries and the time for which the process is either active or idle. It also shows the total no of sessions being connected to the mysql server. mysql> show processlist; • Check Mysql is running on Server. $ ps –ef |grep –i mysql • Creating a new database mysql> create database abc;
  • 8. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level • How many db’s are in Mysql Instance mysql> show databases; • Create users in Mysql mysql> create user abc@’localhost’ identified by 'abc'; -- This creates user and allow only local access to the user mysql> create user abc@’%’ identified by 'abc'; -- This creates user and allow access over the network to the users mysql> GRANT ALL PRIVILEGES ON DB1.* TO 'abc'@'localhost'; -- Grant all privileges on all the tables on DB1 database to user which can connect locally. mysql> GRANT ALL PRIVILEGES ON DB1.* TO 'abc'@'%'; -- Grant all privileges on all the tables on DB1 database to user which can connect locally.
  • 9. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level mysql> GRANT ALL PRIVILEGES ON *.* TO 'abc'@'%'; -- Grant all privileges on all the tables on DB1 database to user which can connect on network. We need to give below command after creating user so that it can flush from memory and comes in affect. mysql> flush privileges; • Check the slave process status => mysql> show slave statusG There are 3 values to look for in the status: Slave_IO_Running: Yes Slave_SQL_Running: Yes Seconds_Behind_Master: 0
  • 10. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level • How to check locks and release all or specific locks mysql> show processlist; +-----------+------------+------------------------------------------+--------- | Id | User | Host | db | Command | Time | State | Info | +-----------+------------+------------------------------------------+--------- | 98485035 | jirauser | 10.31.82.49:35725 | jiradb | Sleep | 1049 | | NULL | We will get all the info like from which db user, app server (host) on which db lock is coming
  • 11. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level If we need to release that lock we need to kill that ID, check ID for specific lock & kill that id with kill “id” command. Mysql> kill “id”; • Mysql Service Start/Stop #sudo to mysql $/etc/init.d/mysql start => for starting $/etc/init.d/mysql stop => for stopping
  • 12. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level • Delete bin logs from Master when space is full on disk. Check first how far is slave replication behind its master before purging the binary logs on master instance: Run show master status get bin log id Mysql> show master status; --Moving to next binary log Mysql> flush logs; mysql> Purge binary logs to <binlog from above-1>; OR Delete binary logs that are n days old mysql> PURGE BINARY LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 2 DAY); -- Deleting all binary logs that are 2 days old
  • 13. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level • Skipping statements on slave when it’s stopped due to errors: mysql> SET GLOBAL sql_slave_statement_skip_counter=1; -- This will skip only the last problematic statement Storage engines in Mysql: Mysql daemon process acts as a framework which can be plugged with one or many storage engines to create table and store data in it. All storage engines comes with different characteristics and before creating a new database or a table it should be decided in advance that the application is compatible to which storage engine in mysql.
  • 14. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Commonly used storage engines in Mysql are as follow: 1. MYISAM => MyISAM is the default storage engine. Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type. An .frm file stores the table format. The data file has an .MYD (MYData) extension. The index file has an .MYI (MYIndex) extension. Properties: • MyISAM implements table-level lock for inserting and updating. • MyISAM does not support transactions & foreign keys. • Also a long running SELECT will also lock the table for other sessions to access it. • MyISAM tables are auto commit and hence it cannot be committed or rolled back.
  • 15. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 2. INNODB: InnoDB is a transaction-safe storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data. Properties: • InnoDB row-level locking and Oracle-style consistent no locking reads increase multi-user concurrency and performance. • To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints. • The InnoDB storage engine maintains its own buffer pool for caching data and indexes in main memory. • InnoDB stores its tables and indexes in a tablespace, which may consist of several files (or raw disk partitions). This is different from, for example, MyISAM tables where each table is stored using separate files.
  • 16. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level We can create db with storage engine, we can create table with non default storage engine mysql> CREATE TABLE t (i INT) ENGINE = INNODB; & we can change storage engine of an existing table like below command, mysql> Alter table t (i INT) ENGINE =MYISAM;
  • 17. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level How to find current storage engine for a table => mysql> show table status like 'onlineregsession'G *************************** 1. row *************************** Name: onlineregsession Engine: MyISAM Version: 10 Row_format: Dynamic Rows: 1725842 Avg_row_length: 384 Data_length: 663991508 Max_data_length: 281474976710655 Index_length: 117795840 Data_free: 0 Auto_increment: 1726849 Create_time: 2011-06-11 19:35:03 Update_time: 2012-04-30 02:12:39 Check_time: 2011-06-11 19:36:40 Collation: latin1_swedish_ci Checksum: NULL Create_options:
  • 18. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level MYSQL BACKUP & RESTORE MYSQLDUMP Mysqldump is a logical backup tool equivalent to exp/imp tool of oracle. It is used to dump a database or a collection of databases for backup. It creates a *.sql file with DROP table, CREATE table and INSERT into sql-statements of the source database. To restore the database, execute the *.sql file on destination database. 1) Backup a single database $mysqldump -u root -p[root_password] -–databases [database_name] > dumpfilename.sql 2) Backup Multiple databases $mysqldump -u root -p[root_password] --databases db_name1 db_name2 > dumpfilename.sql
  • 19. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 3) Backup all databases containing MyISAM and/or Innodb tables – CONSISTENT DUMP. mysql> FLUSH TABLES WITH READ LOCK; Query OK, 0 rows affected (0.00 sec) From second session, use below command for backup $mysqldump --all-databases –single-transaction --master-data=2 >dbdump.db When backup will be finished then from first session where we acquire read lock give below command to release locks mysql> UNLOCK TABLES; Query OK, 0 rows affected (0.00 sec) 4) Backup all databases containing MyISAM and Innodb tables – INCONSISTENT DUMP $mysqldump --all-databases >dbdump.db
  • 20. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level --single-transaction : This option sends a START TRANSACTION SQL statement to the server before dumping data. It is useful only with transactional tables such as InnoDB, because then it dumps the consistent state of the database at the time when BEGIN was issued without blocking any applications. This is a method for taking a consistent backup of innodb tables. This option will not take consistent backup of Myiasm tables. This is not lock any Innodb tables and a consistent backup can be taken without impacting any production processes. For taking consistent backup of Myisam tables there are 2 options available. • Take a mysql session connecting to the server and run FLUSH table with read locks. This will lock all the tables on the database with read lock with no DML operation permitted. From another session take mysqldump with consistent image. Release the locks from the first session.
  • 21. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level • If there is a slave configured for primary database, then on slave perform the following: Stop the slave process on slave server. Initiate mysqldump, this will be a consistent backup since no transactions are getting written onto slave. Once the dump is completed, the again start the slave process. Restore backup which are taken by mysqldump utility 1. If we took backup of a single database & didn’t use --database switch while backup then we need to create database before restore mysql> create database database_name; $mysql -u root -p[root_password] [database_name] < dumpfilename.sql 2. When took backup with --database switch then no need to create database manually $mysql -u root -p[root_password] < dumpfilename.sql
  • 22. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level 3. If we have multiple database backup & we need to restore only one, put db name which we want to restore in restore command $mysql -u root -p[root_password] dbname < dumpfilename.sql
  • 23. Click to edit Master title style Click to edit Master text styles Second level Third level Fourth level Fifth level Thank You