SlideShare une entreprise Scribd logo
1  sur  118
Télécharger pour lire hors ligne
Welcome to MySQL
Haim Tzadok
Safe Usage
The material provided here is not free of
errors and should be treated as such.
If you find any error, please email me -
haim.tzadok@grigale.com and I will try my
best to correct any error.
Before using this material, always test and
test again, before implementing !
The technical material may be subject to
changes and should be treated as a
recommendation only.
Table Of Content
1. MySQL Introduction
2. MySQL Clients
3. MySQL Architecture
4. MySQL Basic Security
5. MySQL Configuration
6. MySQL Administration
7. MySQL Monitoring
8. MySQL Replication
9. Backup & Recovery
10.MySQL Advanced Security
11.MySQL Performance Monitoring &
Tuning
WELCOME
Introduction to MySQL
o MySQL Editions
o MySQL Components
o MySQL Installation Brief
MySQL Basic Security
o User Privileges
o User account management
MySQL Clients
o MySQL CLI
o MySQL Workbench
o MySQL Connectors
o MySQL Router
MySQL Architecture
o Internal Architecture
o Information Schema
o Storage Engines
MySQL Configuration
o Server configuration
o Client configuration
MySQL Administration
o OS Service
o Data directory
o Server logs
o Utilities
WELCOME
MySQL Monitoring
o Monitoring using Workbench
o Enterprise Monitoring
MySQL Replication
o Replication formats
o Replication methods
o Binlog Replication
o GTID replication
o Replication topologies
Backup & Recovery
o Logical backup
o Physical backup
Advanced Security
o MySQL Firewall
o MySQL Auditing
o Encryption
MySQL Performance Monitoring
MySQL Introduction
MySQL Introduction
Objectives
● Overview of MySQL History
● MySQL License and Availability
● MySQL Distributions
● MySQL Israeli Community Activities
● MySQL Editions
● MySQL Components
● MySQL Installation Brief – Windows/Linux
“The wolrd’s most popular open source database”
MySQL History
MySQL - started as an OpenSource project for RDBMS. (Initially called
msql)
My - is the name of the daughter of the founder - Monty Widenius
MySQL - Swedish company (MySQL AB)
2008 - it was bought by Sun Microsystems
2010 - Oracle acquired Sun Microsystems
“The wolrd’s most popular open source database”
MySQL Usage and Spread
● MySQL is the second world’s widely used RDBMS.
(Which is the first ?) dbengines ranking –
https://db-engines.com/en/ranking
● Ranking method: #of mentions in websites, frequency searches in
google, # of mentions in technical sites (stackoverflow, DBA stack
exchange), # of job offers, # of profiles in linkedin, # of tweets
MySQL Usage and Spread
● MySQL is the second world’s widely used RDBMS.
(Which is the first ?) dbengines ranking –
https://db-engines.com/en/ranking
● MySQL is known as M in LAMP.
● It is widely used in many Web Application frameworks such
as: Joomla, Drupal, WordPress etc…
● It is widely used by many large companies like: Google,
Facebook, Twitter, Flickr, YouTube,Wikipedia, Booking.com
etc..
● In Israel it is widely used by many companies.
Introduction to MySQL
The world's most popular open source database
MySQL License and Availability
● MySQL is Open Source project licensed under
Dual license - GPL/Commercial
● It is maintained by Oracle/MySQL
● MySQL is multi platform - runs on Linux, Windows,
Solaris, HP-UX, AIX, MAC OS/X and many more.
MySQL Distributions
● MySQL has other forks like:
○ MariaDB
○ Percona
○ Google patches
○ Facebook patches
MySQL Israeli Community activities
● MySQL enjoys large community and wide usage.
● MySQL Israeli User group - is an active Meetup
group –
http://meetup.com/MySQL-User-Group-Israel
● MySQL Acitivities and Conferences in Israel -
hosted by Oracle/MySQL
● Tech tour – March 2018
● Oracle week – November 2018 (2 MySQL seminars)
● MySQL Meetups – every 3~ Months.
● MySQL Workshops – every ½ year.
MySQL Editions
MySQL Product line:
○ MySQL Community edition
• Server, WorkBench, Connectors, utilities
○ MySQL Standard Edition
○ Community + 24/7 Support + Consultative support
○ MySQL Enterprise Edition
○ Standard + Enterprise tools like: MEB, MEM, Firewall, Audit,
Thread Pooling etc…
○ MySQL Cluster Carrier Grade Edition
○ Enterprise + NDB + Cluster
Introduction to MySQL
MySQL Components
• MySQL Server
• Workbench (GUI)
• MySQL Connectors
• MySQL Router
• MySQL Utilities
• MySQL Enterprise
Monitor (MEM)
• MySQL Enterprise
Backup (MEB)
• MySQL Enterprise
Audit
• MySQL Enterprise
security (PAM
authentication plugin)
• MySQL Thread Pool
• MySQL Firewall
MySQL Installation Brief
Obtaining MySQL for Windows
● Available .msi or zip distributions
● Download the software from mysql.com
○ Requires Oracle SSO user in order to access
Oracle eDelivery site
○ Two kind of installers -
■ MySQL Web community - which
downloads mysql online
■ MySQL Community - Downloads the whole
installation for offline usage
Obtaining MySQL for Windows
● 4 Installation types:
○ Developer
■ installs Server, Client and excel plugin for MySQL.
○ Server Only
■ Only installs MySQL server
○ Client Only
■ Only installs Workbench MySQL Visual studio
plugin and MySQL Connectors
○ Full
■ installs everything
○ Custom
■ Allows to select what to install
Obtaining MySQL for Windows
● Pre-requisite -
○ In order to use workbench and other
MySQL tools it is better to download and
install - Microsoft Visual C++ 2013
redistributable/runtime package
Obtaining MySQL for Windows
Proceed to execute...
Obtaining MySQL for Linux
● Installation via packages
○ Download the packages as a single zip file from
Oracle eDelivery site
○ Open the zip file
○ Install the packages
○ Prerequisites should be met manually...
● Installation via Repositories -
○ Available CentOS based Linux repository
○ Available Debian flavors Linux repository
○ All prerequisites are handled automatically
Obtaining MySQL for Linux - DEMO
● Installation via packages
○ Download the packages as a single zip file from Oracle eDelivery
site, you may also download the commercial packages.
■ You should identify the right packeges for your Linux
distribution.
■ if you download commercial packages - remember that big
brother is watching...
○ Open the zip file - using the unzip command
○ Install the packages - using deb or rpm command
○ Prerequisites should be met manually…
■ Commonly missing packages are - proj, python etc...
■ To install all packages, you can also use:
yum localinstall *.rpm
Obtaining MySQL for Linux - DEMO
● Installation via Repositories -
○ Available CentOS based Linux repository -
Download the relevant package from the link:
○ http://dev.mysql.com/downloads/repo/yum/
○ Install the package Using:
yum localinstall mysql57-community-release-el6-n.noarch.rpm
○ Fetch MySQL from the repository using the
command:
yum install mysql-community-server
yum install mysql-workbench-community
○ Usually all prerequisites are handled
automatically, provided that you have the
necessary repositories
Obtaining MySQL for Linux - DEMO
Initalizing a DB on MySQL (5.6)
To initialize a database, just run the secure installation script
mysql_secure_installation
This script will ask about root password for the Database. It will remove
anonymous users and so on…
Initializing a DB on MySQL (5.7)
To initialize a fresh database of MySQL 5.7 - just start the
service.
The root password is generated automatically and can be
fetched using the command:
grep 'temporary password' /var/log/mysqld.log
To change the root password:
mysql -uroot -p
ALTER USER ’root’@’localhost’ identified by ’newpassword’
Obtaining MySQL for Linux - DEMO
Handling MySQL Service
● To start MySQL server:
○ service mysqld start (CentOS6)
○ systemctl start mysql (CentOS7)
● To stop MySQL server:
○ service mysqld stop (CentOS6)
○ systemctl stop mysql (CentOS7)
● To get status of MySQL server:
○ service mysqld status (CentOS6)
○ systemctl status mysql (CentOS7)
MySQL Basic Security
MySQL Basic Security
• MySQL Access Privileges
• MySQL User account Management
MySQL Access Privileges
• MySQL Access Privileges
• All the information is stored in MySQL DB.
• User is identified by a combination of - username and host
(userhost).
haim@mysql1 = haim@mysql2
• The wildcard ‘%’ for the host part – represents that a user
can connect from any host except from the localhost.
• A user is a global object, password is not associated with
db,table or routine
MySQL User account Management
Create Remove Status
USER create user haim@’%’ identified by
‘pass123’;
DROP USER haim@’%’ ; select user, host from mysql.user;
Privilege GRANT ALL ON *.* TO haim@’%’; REVOKE INSERT ON *.* FROM
haim@’%’;
show grants for user@’host’;
Resource
limits
CREATE USER haim@'localhost'
IDENTIFIED BY ‘pass123' WITH
> MAX_QUERIES_PER_HOUR 20
> MAX_UPDATES_PER_HOUR 10
> MAX_CONNECTIONS_PER_HOUR 5
> MAX_USER_CONNECTIONS 2;
ALTER USER haim@'localhost'
WITH
MAX_CONNECTIONS_PER_HOUR
0;
desc mysql.user;
select user, host,
MAX_QUERIES_PER_HOUR,
MAX_CONNECTIONS_PER_HOUR
FROM mysql.user;
PASSWORD CREATE USER haim@'localhost'
IDENTIFIED BY ‘pass123' ;
ALTER USER haim@'localhost'
IDENTIFIED BY ‘pass123' ;
MySQL Clients
MySQL Clients
• SQL Review
• MySQL Client/Server Architecture
• Client Types
– CLI clients
• mysql client
• Mysqladmin client
– Application specific clients
• Connectors
• Router
– GUI Clients
• Workbench
SQL Review
SQL
SQL is a database computer language designed for the retrieval and management of
data in relational database. SQL stands for Structured Query Language.
DDL
Data Definition Language
SHOW databases
SHOW tables
CREATE database <db_name>
DROP database <db_name>
CREATE table <table_name>
DROP table <table_name>
ALTER – change table columns
RENAME – rename table
SHOW CREATE – show information
on the DB or Table.
DML
Data manipulation language
SELECT– select rows for viewing
INSERT– insert data as rows
UPDATE– update rows
DELETE– delete rows
TRUNCATE– delete all rows in table
DCL
Data Control language
CREATE user
ALTER user
RENAME user
DROP user
GRANT privileges
REVOKE privileges
SET PASSWORD
create table tab1 (ID int, FIRST char(20), LAST char(20));
Insert into db1.tab1 (ID,FIRST,LAST) VALUES (1,’Haim’,’Tzadok’);
SHOW [GLOBAL] VARIABLES LIKE ‘%pass%’;
SQL review
MySQL InnoDB
InnoDB is by default set to ‘autocommit’.
DDL
BEGIN/START TRANSACTION
CREATE T1 (C1 int);
CREATE T2 (C1 int);
Rollback;
CREATE T3 (C1 int);
SHOW TABLES;
What is the output ?
DML
BEGIN/START TRANSACTION
INSERT INTO T1(‘C1’) VALUES (10);
INSERT INTO T1(‘C1’) VALUES (9);
Rollback;
SELECT * from T1;
INSERT INTO T1(‘C1’) VALUES (7);
Select * from T1;
What is the output ?
create table tab1 (ID int, FIRST char(20), LAST char(20));
Insert into db1.tab1 (ID,FIRST,LAST) VALUES (1,’Haim’,’Tzadok’);
SHOW [GLOBAL] VARIABLES LIKE ‘%pass%’;
MySQL Client/Server Architecture
• All clients must negotiate for credentials via a
tcp/connection or via socket.
• Based on credited privileges, connected clients are then
able to query the server.
• A MySQL distribution provides several types of clients.
• MySQL also releases GUI clients (see Workbench)
Client Types
CLI Clients
• MySQL Command line clients
▪ mysql – a command line client
▪ mysqladmin – a command line client for management
GUI Clients
• Workbench
Application Clients
• MySQL Connectors
• MySQL Router
MySQL Client/Server Architecture
● All clients connect to MySQL using the MySQL Client
API.
● Most do not implement this API, but rather use
connectors or libraries to wrap it up.
● Not all connectors themselves implement the API.
Some rely on the libmysqlclient, for example.
MySQL Command Line Clients
● MySQL ships with many command line clients:
● mysql: a general, interactive/non-interactive client
● mysqladmin: a utility to perform administration tasks
● mysqldump: a client to export database structure
and data
● mysqlshow: a client to query metadata
● mysqlimport: an importing utility
● more in mysql utilities…
Command Line client options
● To connect with a MySQL command line client, one
must supply with credentials:
[root@olp1 ~]# mysql -u root -p
mysql: [Warning] Using a password on the command line interface can be insecure.
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 70
Server version: 5.7.13-enterprise-commercial-advanced-log MySQL Enterprise Server -
Advanced Edition (Commercial)
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>
mysql client - variables and values
bash:~$ mysql --help
… (at the end of output)
Variables (--variable-name=value)
and Boolean options {FALSE|TRUE}
Value (after reading options)
--------------------------------- ----
------------------------------------
debug-info
FALSE
database (No
default value)
default-character-set auto
delimiter ;
enable-cleartext-plugin TRUE
vertical
FALSE
force
FALSE
named-commands
FALSE
ignore-spaces
FALSE
init-command (No
default value)
local-infile
FALSE
no-beep
FALSE
host (No
default value)
html
FALSE
xml
FALSE
line-numbers TRUE
unbuffered
FALSE
column-names TRUE
sigint-ignore
FALSE
port 0
prompt
mysql>
quick
FALSE
raw
FALSE
reconnect TRUE
socket
/var/lib/mysql/mysql.sock
value)
ssl-crlpath (No
default value)
ssl-verify-server-cert
FALSE
table
FALSE
user root
safe-updates
FALSE
i-am-a-dummy
FALSE
connect-timeout 0
max-allowed-packet
16777216
net-buffer-length
16384
select-limit 1000
max-join-size
1000000
secure-auth TRUE
show-warnings
FALSE
The mysql client
SYNOPSIS
mysql [options] [db_name]
Usually reads /etc/my.cnf and $HOME/.my.cnf
General purpose options include:
--help : shows help and the current Variables options and Boolean values
-h / --host : server host name (default: localhost)
-P / --port : server TCP/IP port (default: 3306)
-S / --socket : UNIX socket file
-u / --user : MySQL login
-U / --safe-updates, --i-am-a-dummy : safe mode
-p / --password : password
--defaults-file : name of configuration file where options are listed.
Output format (Using ; or G)
Execute queries - ending with ; or G
A statement ending with ; will produce an output in table format.
mysqlmysql> explain select * from mysql.user;
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| 1 | SIMPLE | user | NULL | ALL | NULL | NULL | NULL | NULL | 4 | 100.00 | NULL |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)
A statement ending with G will produce an output in list format.
mysql> explain select * from mysql.userG
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: user
partitions: NULL
type: ALL
….
filtered: 100.00
Extra: NULL
1 row in set, 1 warning (0.00 sec)
Different Output Format (XML)
Use --xml to get output in XML format
[root@olp1 ~]# mysql -uroot grigale --xml --execute="SELECT * FROM employees
LIMIT 2"
mysql: [Warning] Using a password on the command line interface can be
insecure.
<?xml version="1.0"?>
<resultset statement="SELECT * FROM employees LIMIT 2
" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="ID">1</field>
<field name="FIRST">Haim</field>
<field name="LAST">Tzadok</field>
</row>
</resultset>
Operations on Databases
show databases – shows available databases.
use <db_name> - select the database you want to use.
create database <db_name> - creates an empty database.
drop database <db_name> - drops a database.
The mysql client
mysql> use grigale;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+-------------------+
| Tables_in_grigale |
+-------------------+
| employees |
+-------------------+
1 row in set (0.00 sec)
mysql>
Using pager
mysql> pager less
PAGER set to 'less'
mysql> show tables;
+-----------------------------------+
| Tables_in_opencart |
+-----------------------------------+
| oc_address |
| oc_affiliate |
| oc_affiliate_activity |
| oc_category_to_layout |
| oc_category_to_store |
| oc_country |
…
…
…
(END)
mysql> pager grep country
PAGER set to 'grep country'
mysql> show tables;
| oc_country |
124 rows in set (0.01 sec)
mysql>
On UNIX/Linux Systems, use pager to manipulate the output of the
result set.
Pager command
Execute pager with no arguments to cancel current pager.
There are some nice tricks with pager.
mysql> pager md5sum;
PAGER set to 'md5sum'
mysql> select * from employees;
758839cc399f41c7f5ecf765f058acd9 -
1 row in set (0.00 sec)
mysql> pager
Default pager wasn't set, using stdout.
mysql>
Log session activities
Log all activity in external text file using tee, Disable with notee.
mysql> tee /tmp/output.txt
Logging to file '/tmp/output.txt'
mysql>
mysql> SELECT 123 FROM grigale.employees;
--------
| 123 |
--------
| 123 |
--------
1 row in set (0.00 sec)
mysql> notee;
Log session activities
To show the activities just use any printing command to view the file that was
saved.
root@mysql1:~# cat /tmp/output.txt
mysql>
mysql> SELECT 123 FROM grigale.employees;
-------
| 123 |
-------
| 123 |
--------
1 row in set (0.00 sec)
Execute SQL from external files
Use SOURCE to execute SQL statements from external files.
mysql> SOURCE /home/haim/test.sql;
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
...
Using non-interactive sql scripts
The mysql client accepts reads from standard input.
This allows pipelining or redirection:
[root@centv1]# cat /tmp/databases/world.sql | mysql -uroot
world
[root@centv1]# cat /tmp/databases/world.sql 
| sed -e s/ENGINE=MyISAM/ENGINE=InnoDB/g 
| mysql -uroot world
bash# mysql -uroot world < /tmp/databases/world.sql
Using non-interactive mysql
command
Execute a query without getting into interactive shell,
using –e “” /--execute=“”.
This can be further combined with pipelining
[root@olp1 ~]# mysql -u root -p grigale -e "
select count(*) from employees;"
mysql: [Warning] Using a password on the command line interface can
be insecure.
Enter password:
+----------+
| count(*) |
+----------+
| 1 |
+----------+
[root@olp1 ~]#
The mysqladmin client
• Allows for administrative tasks.
• Provide the processlist argument to show pending connections.
[root@olp1 ~]# mysqladmin -uroot -p processlist
Enter password:
+----+------+-----------+----+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+----------+------------------+
| 76 | root | localhost | | Query | 0 | starting | show processlist |
+----+------+-----------+----+---------+------+----------+------------------+
[root@olp1 ~]#
The mysqladmin client
• Add -c, -i to make for successive invocations.
• -c : count -i: interval
[root@olp1 ~]# mysqladmin -uroot -p processlist -c 2 -i 1
Enter password:
+----+------+-----------+----+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+----------+------------------+
| 79 | root | localhost | | Query | 0 | starting | show processlist |
+----+------+-----------+----+---------+------+----------+------------------+
+----+------+-----------+----+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+----------+------------------+
| 79 | root | localhost | | Query | 0 | starting | show processlist |
+----+------+-----------+----+---------+------+----------+------------------+
[root@olp1 ~]#
The mysqladmin client
• Use the status argument to print general purpose status:
• -c : count -i: interval
[root@olp1 ~]# mysqladmin -uroot -p status -c 2 -i 1
Enter password:
Uptime: 1215337 Threads: 1 Questions: 9390 Slow queries: 0 Opens: 589
Flush tables: 1 Open tables: 567 Queries per second avg: 0.007
Uptime: 1215338 Threads: 1 Questions: 9391 Slow queries: 0 Opens: 589
Flush tables: 1 Open tables: 567 Queries per second avg: 0.007
[root@olp1 ~]#
The mysqladmin client
• Use the kill argument forcibly kill a connection
[root@olp1 ~]# mysqladmin -uroot -p processlist
+----+------+-----------+----+---------+------+------------+-------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+------------+-------------------------------------------------+
| 82 | root | localhost | | Query | 34 | User sleep | select 1 from grigale.employees where
sleep(10000) |
| 84 | root | localhost | | Query | 0 | starting | show processlist |
+----+------+-----------+----+---------+------+------------+-------------------------------------------------+
[root@olp1 ~]# mysqladmin -uroot -p kill 82
[root@olp1 ~]# mysqladmin -uroot -p processlist
+----+------+-----------+----+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+----+---------+------+----------+------------------+
| 86 | root | localhost | | Query | 0 | starting | show processlist |
+----+------+-----------+----+---------+------+----------+------------------+
[root@olp1 ~]#
The mysqladmin client
Other commands:
• extended-status: dump the result of SHOW
GLOBAL STATUS
• shutdown: shut down the server
• password: change an account's password
• flush-logs: flush + rotate logs
• more...
Connectors
Oracle/MySQL supply with MySQL connectors
These are client libraries, implemented in popular
programming languages:
• Connector/J, JDBC driver for Java
• ADO.NET for the .NET framework
• Connector/ODBC
• Connector/C++
• More...
Work is evolving and new connectors are occasionaly added.
Connectors
3rd parties also provide MySQL connectors:
● libdbd-mysql-perl
● libdbd-mysql-ruby
● Python MySQLdb
● More...
The common connectors are open source, released
under varying licenses.
If using Enterprise Edition:
– It is strongly recommended to use the commercial connectors.
Connectors
The MySQL connectors usually implement the MySQL
Client API, and 3rd party solutions usually rely on
client libraries (e.g. libmysqlclient)
The average user will use the ordinary connector, and
will not dwell into the Client API.
Consult you favorite connector's API to learn how to
connect and query MySQL.
MySQL Router
• MySQL Router is a lightweight middleware that provides
transparent routing between your applications to your MySQL
servers.
• MySQL Router is normally installed in each application server.
• Two scheduling based on mode option are available
▪ Read-write: uses a list with First available routing method.
▪ Read-only: uses round-robin routing method.
▪ Default configuration file:
/etc/mysqlrouter/mysqlrouter.ini
MySQL Router
• Read-only configuration:
[routing: ro_prod]
bind_port=7001
Destinations = slave1, slave2, slave3
mode=read-only
• Read-Write configuration:
[routing: rw_prod]
bind_port=7002
Destinations = master1, master2, master3
mode=read-write
Workbench
Workbench is the default GUI client that comes with MySQL. Available
on Windows/Linux.
Main Features –
• Rich and Sophisticated connection mechanism use SSH to tunnel
and encrypt connection, or use direct connection to DB. (DB can be
local or remote machine)
• SSL Encryption available for direct connection
• Data design & Modeling
• Execute queries and analyze queries
• Status and online monitoring
• Extensive performance monitoring reports
• Full DB Administration
Workbench
Workbench Connection administration
• - Add a connection
- Edit one of the available Connections
Workbench
Workbench Connection details
– by tapping the right upper edge of an existing connection.
Workbench
Main Navigation
Navigator
Use navigator
to navigate
Between
Available
Administration
options
Workbench
Management -> Server status – Shows server Status and online monitoring
Workbench –
Database design and modeling
Workbench Data design and modeling
- Add a new data model file
- Open an existing data model file.
- Create EER diagram from an existing database or script
Workbench – Data Modeling
Database –> Reverse
Engineering
You can create a EER diagram
of your existing database.
Database –> Forward
engineering
You can implement a EER
diagram to a new database.
Workbench – Preferences
Edit – Preferences
You can change the
Behavior of workbench to
fit your needs.
For example –
Show Metadata and
Internal schemas - will Reveal
internal databases Such as mysql,
performance_schema, sys and more…
Combine Managenent Tools and
Schema Tree - will combine/Separate
the management tools From the
Schema tree management.
MySQL Architecture
MySQL Architecture
• MySQL Architecture
• MySQL Information Schema
• MySQL Storage Engines
MySQL Architecture
MySQL Architecture
MySQL Information Schema
• MySQL Information Schema
– Holds database metadata
• Schema design and architecture
• Running processes
• Internal counters
• Replication status
• Storage engine specific information
• Grants and privileges
– A collection of read only views/tables
– Aggregate data from various MySQL components and the
user’s data.
– Allows for SQL access to metadata
– Holds no data – all the information is gathered at runtime.
MySQL Storage Engines
Sotrage Engine History
● Originally MySQL provided ISAM, then MyISAM engines.
● Berkeley DB (BDB) was the first 3rd party storage engine to work
with MySQL.
● InnoDB was later introduced.
● The storage engine API has since evolved.
● MySQL continued developing in house storage engines.
● There is now a large number of MySQL storage engines.
MySQL Storage Engines
What is a storage Engine?
● Every table belongs to a specific storage engine.
● The storage engine is a module responsible for storing table's data and
keys.
● It is responsible for allocating disk storage, memory cache, storing and
fetching of data, providing with information.
● It is similar in concept to file systems: while they basically provide the
same functionality, implementation is different; plus different features can
be added.
MySQL Storage Engines
What is Storage Engine ?
● There is a fine line between MySQL's roles and the SE's roles.
For example:
● Parsing of the query is strictly MySQL's role.
● Building the B-Tree for the index is strictly the SE's role.
● Evaluation the execution plan is MySQL's role, but based on
recommendations from the SE.
MySQL Storage Engines
Storage engine responsibilities
● Data storage
● Index implementations
● Transactional support
● Caching
● Compression
● Constraints
● Additional features (e.g. accept special syntax)
MySQL Storage Engines
Major players
In-house (Oracle/MySQL) storage engines are:
● MyISAM (Non transactional SE, not ACID compliant)
● MERGE
● InnoDB
● MEMORY (Saves all the data in the RAM)
● Blackhole (don’t save data in db files, used for replication shipping)
● CSV (Save the data as .csv files, don’t allow indexes)
● ARCHIVE (Compress the data and archive it)
● Federated
● NDB (as part of MySQL Cluster)
Newer, emerging and gaining popularity:
● XtraDB (InnoDB plugin fork by Percona)
● MariaDB (by Monty Program AB)
Today MySQL recommend using InnoDB for all kind of uses !
MySQL Architecture
MySQL Storage Engines
Which engine do we use ?
Use SHOW commands.
mysql> show create table employees;
+-----------+----------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------+
| Table | Create Table
|
+-----------+----------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------+
| employees | CREATE TABLE `employees` (
`id` int(11) DEFAULT NULL,
`first` char(30) DEFAULT NULL,
`last` char(30) DEFAULT NULL,
KEY `i1` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-----------+----------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
MySQL Architecture
MySQL Storage Engines
InnoDB
Each database has a directory inside the data dir.
*.frm – contains table structure.
*.ibd – contains data and indexes.
show engine innodb status – Shows the status of innodb engine.
Lsn- current log sequence number of the redo logs.
Redo-logs – a mechanism of innodb.
Bin-log – a mechanism in mysql not related to innodb, used for
replication and point-in-time recovery.
MySQL Configuration
MySQL Configuration
AGENDA
• MySQL Server Configuration (/etc/my.cnf mysqld section,
dynamic/static variables – allow/don’t allow changes at runtime)
• MySQL Client Configuration (/etc/my.cnf client section)
• MySQL Variables (show variables like ‘%pass%’, global/session
specific variables, read-only/read-write parameters)
• MySQL Server Status (show status)
MySQL Server Configuration
• Essential parameters:
– port, socket, datadir,
• General parameters:
– init-connect – statement that will be executed upon start of connection
– sql_mode – a set of modes that mysql will comply to when running SQL statements.
– read_only (0=OFF, 1=ON)
– wait_timeout (in seconds)
– InnoDB parameters
– innodb_buffer_pool_size – the amount of memory innodb will use for data & index caches.
– Innodb_log_file_size – size of transaction log size.
– Innodb_file_per_table – required for replication.
– Innodb_lock_wait_timeoiut – seconds to wait before rolling back a locking transaction.
– Workbench -> MANAGEMENT -> Status and System Variables
– Status variables – read only variables
– System variables – configurable variables.
MySQL Variables
• MySQL Variables
– Global parameters
– Session specific parameters.
• MySQL Variables are parameters that comes from my.cnf or as dynamic
parameters.
• Some of them are read only some of them are writable.
• Full list of 5.7 parameters:
http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
show variables like ‘%string%’;
show global variables like ‘%string%’;
select @@global.read_only ;
set global max_connections = 1000; - set max connections variable globally
SET sql_log_bin=0; - disable bin logging in the current session
MySQL Server Status
• MySQL Server Status
Metadata
show databases | show tables | show plugins |
show triggers | show indexes| show grants
show create table/procedure/trigger |
MySQL Server Status
status
show status|show master status| show slave
status | show open tables |show engine innodb
status | show [full] processlist |show global
status
• show status like ‘%conn%’;
MySQL Administration
MySQL Administration
AGENDA
• MySQL Service
• MySQL Data Directory
• MySQL Server Logs
• MySQL Multiple Instances
• MySQL Utilities
MySQL Service
Handling MySQL Service
● To start MySQL server:
○ service mysqld start (CentOS 6)
○ systemctl start mysql (CentOS 7)
● To stop MySQL server:
○ service mysqld stop (CentOS 6)
○ systemctl stop mysql (CentOS 7)
● To get status of MySQL server:
○ service mysqld status (CentOS 6)
○ systemctl status mysql (CentOS 7)
MySQL Data Directory
• /etc/my.cnf – default configuration file.
• /var/lib/mysql – Default data dir.
• /var/log/mysqld.log – default log file
• /var/lib/mysql/mysql.sock – default socket
file
• /var/lib/mysql/mysqld.pid – pid file
• /usr/lib64/mysql/plugin – plugins directory
MySQL Server logs
• Bin log - saves events that changes the database
(DDL/DML) including their times, but does not save
show/select events.
– Normally needed for replication between the current master
and it’s slaves.
– When doing backup all changes are stored in the binlog till the
backup is finished and then re-run from the binlog to take
affect.
– Good for point in time recovery.
– Available formats: MIXED (recommended), ROW, STATEMENT
• General log – saves any event that occurred in the
database. (usually enabled when needed more debugging).
• Error log – stores error events, usually under
/var/log/mysqld.log
• Slow log – stores slow query logs (normally more than 10
seconds - in real time), normally does not log slow
administrative or replication statements.
MySQL Utilities
• MySQL Utilities is a package with set of administrative scripts
written in python mainly handling administration, replication,
general usage and more.
• Bin log operation –
• DB operations
• General operations
• HA operations
• Server operations
• Specialized operations
MySQL Monitoring
MySQL Monitoring
• MySQL Monitoring Tools
• Monitoring MySQL using WorkBench
• Monitoring MySQL Server using CLI
• MySQL Enterprise Monitor – DEMO
MySQL Replication
MySQL Replication
• MySQL Replication formats
• MySQL Replication methods
• MySQL Replication topologies
MySQL Replication
• MySQL Replication formats
– SBR – Statement Based Replication
– RBR – Raw Based Replication
– Mixed – Utilize both formats
• MySQL Replication methods
– Replication using Binlog
– Replication using GTID’s
• MySQL Replication topologies
– Master/Slave Topology
– Chained Topology
– Group Replication Topology
MySQL Replication
• MySQL Replication formats
– SBR – Statement based Replication, replication
ships the statements between replicated nodes.
– RBR – Raw based replication, replication ships the
outcome of the execution of statements between
replicated nodes.
– Mixed – Utilize both formats.
MySQL Replication
• MySQL Replication Methods
– Replication using Binlog – Slave fetches transactions
from the Master using binlog position mechanism.
(Each transaction is anonymous transaction)
– Replication using GTID’s – Slave fetches transactions
from the Master using Global Transaction ID’s
(Each transaction has an ID)
MySQL Replication
• MySQL Replication topologies
– Master/Slave(s)
– Chained (Master/Intermediate/Slave)
– Group Replication M M
M M
I
M S
S
M
S
MySQL Replication
MySQL Replication formats
CAP Theorem – Consistency, Availability, Partition Tolerance
We can only have two out of the three.
Consistency
AvailabilityPartition
Tolerance
CA – Network problem
Might stop system.
Ex: RDBMS Systems
(Oracle, MySQL, …)
CP – There is a risk of data
Becoming unavailable
Ex: MongoDB, Hbase, Memcache
PA – Clients may read
inconsistent Data
Ex: Cassandra, Riak, CouchDB
MySQL Backup & Recovery
MySQL Backup and Recovery
• MySQL Backup Methods
–MySQL logical Backup & Restore
–MySQL physical Backup & Restore
MySQL Backup and Restore
MySQL Backup Methods
• Logical Backup – using mysqldump
– Storage engine independent
– Architecture independent
– Textual backup, easy to manipulate
– Corruption is easily detected.
– Usually very slow…
MySQL Backup and Recovery
MySQL Backup Methods
• Physical(Raw) Backup – using MEB (MySQL
Enterprise Backup)
– Consist of raw copies of directories and files using
snapshot like technology.
– Suitable for large, important databases.
– Usually very fast…
MySQL
Advanced Security
MySQL Advanced Security
• MySQL Firewall
• MySQL Auditing
• MySQL encryption
MySQL Firewall
• MySQL Firewall consists of several plugins and tables in
information_schema and mysql db.
• MySQL Firewall is enabled globally but it will not work till it
is implemented on users.
• Firewall mode on users –
OFF – Firewall is not implemented on the user.
RECORDING – Generates white list for the specific user which is
being recorded.
DETECTING - detect and log any transaction which is not in the
white list.
PROTECTING - enables the firewall to work in enforcing mode.
(any statement that is not in the white list will be denied).
MySQL Auditing
MySQL Auditing
MySQL Enterprise Audit provides an easy to use, policy-based
auditing solution that helps organizations implement stronger
security controls and satisfy regulatory compliance.
As more sensitive data is collected, stored and used online,
database auditing becomes an essential component of any
security strategy. To guard against the misuse of information,
popular compliance regulations including HIPAA, Sarbanes-
Oxley, and the PCI Data Security Standard require
organizations to track access to information.
MySQL Encryption
Encryption vs TDE
Enabling MySQL Encryption
MySQL Encryption
Encryption vs TDE
Encryption – Data itself is encrypted
No indexes can be enabled on
encrypted column. Data is decrypted
using a private key.
TDE – Transparent Data encryption is
encryption in the file-system layer.
MySQL Performance
Monitoring
MySQL Performance Monitoring
• Buffer Pool, Redo logs and Binlog
• Performance Schema
• SYS Schema
• Monitoring Tools
Buffer Pool, Redo Logs and Binlog
• The Buffer pool is mainly a cache for incoming read/write operations. Every new transaction
is first written to the redo log
• After a while the redo logs are flushed to the data files.
• Binlog is a different mechanism to store logs mainly for replication and point-in-time
recovery.
• If the server is crashed the recovery is reading the redo logs and flush things to disk.
Bufferpool
REDO
LOGS
Datadir
datafiles
Tab3
Tab2
Tab1
Performance schema
• A storage engine for collecting performance.
• Collection of sensors that inform about the
time an access has occurred.
• Collection of tables that stores all the timers.
• Usually not easily readable.
SYS Schema
• A storage engine that helps to interpret the
performance schema.
• Collection of views that summarize
performance schema data
• Stored procedures that enables performance
schema operations such as configuration
changes and diagnostic reports.
MySQL Performance
Monitoring and Tuning
Monitoring tools
• Workbench
– Performance -> Performance Reports -> High Cost
SQL Statements
• Mysqlslap – load emulation client
• HeidiSQL – SQL GUI
• MonYog – 3rd party monitoring tool
Welcome to MySQL

Contenu connexe

Tendances

MySQL Connectors 8.0.19 & DNS SRV
MySQL Connectors 8.0.19 & DNS SRVMySQL Connectors 8.0.19 & DNS SRV
MySQL Connectors 8.0.19 & DNS SRVKenny Gryp
 
MySQL High Availability Solutions - Avoid loss of service by reducing the r...
MySQL High Availability Solutions  -  Avoid loss of service by reducing the r...MySQL High Availability Solutions  -  Avoid loss of service by reducing the r...
MySQL High Availability Solutions - Avoid loss of service by reducing the r...Olivier DASINI
 
MySQL Replication Performance Tuning for Fun and Profit!
MySQL Replication Performance Tuning for Fun and Profit!MySQL Replication Performance Tuning for Fun and Profit!
MySQL Replication Performance Tuning for Fun and Profit!Vitor Oliveira
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best PracticesOlivier DASINI
 
High-Availability using MySQL Fabric
High-Availability using MySQL FabricHigh-Availability using MySQL Fabric
High-Availability using MySQL FabricMats Kindahl
 
MySQL High Availability with Group Replication
MySQL High Availability with Group ReplicationMySQL High Availability with Group Replication
MySQL High Availability with Group ReplicationNuno Carvalho
 
MySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMatt Lord
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationManish Kumar
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017Ivan Ma
 
MySQL Group Replication - an Overview
MySQL Group Replication - an OverviewMySQL Group Replication - an Overview
MySQL Group Replication - an OverviewMatt Lord
 
Posscon my sql56
Posscon my sql56Posscon my sql56
Posscon my sql56Dave Stokes
 
MySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersMySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersRonald Bradford
 
Sharding and Scale-out using MySQL Fabric
Sharding and Scale-out using MySQL FabricSharding and Scale-out using MySQL Fabric
Sharding and Scale-out using MySQL FabricMats Kindahl
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQLTed Wennmark
 
MySQL Operator for Kubernetes
MySQL Operator for KubernetesMySQL Operator for Kubernetes
MySQL Operator for KubernetesKenny Gryp
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationPercona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationKenny Gryp
 
MySQL Cluster 8.0 tutorial
MySQL Cluster 8.0 tutorialMySQL Cluster 8.0 tutorial
MySQL Cluster 8.0 tutorialFrazer Clement
 
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
MySQL Group Replicatio  in a nutshell - MySQL InnoDB ClusterMySQL Group Replicatio  in a nutshell - MySQL InnoDB Cluster
MySQL Group Replicatio in a nutshell - MySQL InnoDB ClusterFrederic Descamps
 
MySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoMySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoKeith Hollman
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015Dave Stokes
 

Tendances (20)

MySQL Connectors 8.0.19 & DNS SRV
MySQL Connectors 8.0.19 & DNS SRVMySQL Connectors 8.0.19 & DNS SRV
MySQL Connectors 8.0.19 & DNS SRV
 
MySQL High Availability Solutions - Avoid loss of service by reducing the r...
MySQL High Availability Solutions  -  Avoid loss of service by reducing the r...MySQL High Availability Solutions  -  Avoid loss of service by reducing the r...
MySQL High Availability Solutions - Avoid loss of service by reducing the r...
 
MySQL Replication Performance Tuning for Fun and Profit!
MySQL Replication Performance Tuning for Fun and Profit!MySQL Replication Performance Tuning for Fun and Profit!
MySQL Replication Performance Tuning for Fun and Profit!
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best Practices
 
High-Availability using MySQL Fabric
High-Availability using MySQL FabricHigh-Availability using MySQL Fabric
High-Availability using MySQL Fabric
 
MySQL High Availability with Group Replication
MySQL High Availability with Group ReplicationMySQL High Availability with Group Replication
MySQL High Availability with Group Replication
 
MySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB ClustersMySQL High Availability -- InnoDB Clusters
MySQL High Availability -- InnoDB Clusters
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
MySQL InnoDB Cluster and MySQL Group Replication @HKOSC 2017
 
MySQL Group Replication - an Overview
MySQL Group Replication - an OverviewMySQL Group Replication - an Overview
MySQL Group Replication - an Overview
 
Posscon my sql56
Posscon my sql56Posscon my sql56
Posscon my sql56
 
MySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and DevelopersMySQL For Oracle DBA's and Developers
MySQL For Oracle DBA's and Developers
 
Sharding and Scale-out using MySQL Fabric
Sharding and Scale-out using MySQL FabricSharding and Scale-out using MySQL Fabric
Sharding and Scale-out using MySQL Fabric
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
MySQL Operator for Kubernetes
MySQL Operator for KubernetesMySQL Operator for Kubernetes
MySQL Operator for Kubernetes
 
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group ReplicationPercona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
 
MySQL Cluster 8.0 tutorial
MySQL Cluster 8.0 tutorialMySQL Cluster 8.0 tutorial
MySQL Cluster 8.0 tutorial
 
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
MySQL Group Replicatio  in a nutshell - MySQL InnoDB ClusterMySQL Group Replicatio  in a nutshell - MySQL InnoDB Cluster
MySQL Group Replicatio in a nutshell - MySQL InnoDB Cluster
 
MySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & DemoMySQL InnoDB Cluster HA Overview & Demo
MySQL InnoDB Cluster HA Overview & Demo
 
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015MySQL's new Secure by Default Install -- All Things Open October 20th 2015
MySQL's new Secure by Default Install -- All Things Open October 20th 2015
 

Similaire à Welcome to MySQL

BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS
 
MySQL 8.0.21 - New Features Summary
MySQL 8.0.21 - New Features SummaryMySQL 8.0.21 - New Features Summary
MySQL 8.0.21 - New Features SummaryOlivier DASINI
 
MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...
MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...
MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...Olivier DASINI
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAsBen Krug
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)Gustavo Rene Antunez
 
Securing your database servers from external attacks
Securing your database servers from external attacksSecuring your database servers from external attacks
Securing your database servers from external attacksAlkin Tezuysal
 
Setting up a MySQL Docker Container
Setting up a MySQL Docker ContainerSetting up a MySQL Docker Container
Setting up a MySQL Docker ContainerVictor S. Recio
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015Dave Stokes
 
My sql introduction for Bestcom
My sql introduction for BestcomMy sql introduction for Bestcom
My sql introduction for BestcomIvan Tu
 
My S Q L Introduction for 1 day training
My S Q L  Introduction for 1 day trainingMy S Q L  Introduction for 1 day training
My S Q L Introduction for 1 day trainingIvan Tu
 
Mysql 8 vs Mariadb 10.4 Highload++ 2019
Mysql 8 vs Mariadb 10.4 Highload++ 2019Mysql 8 vs Mariadb 10.4 Highload++ 2019
Mysql 8 vs Mariadb 10.4 Highload++ 2019Alkin Tezuysal
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN BASHA
 
MariaDB Security Best Practices
MariaDB Security Best PracticesMariaDB Security Best Practices
MariaDB Security Best PracticesFederico Razzoli
 

Similaire à Welcome to MySQL (20)

BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and Installation
 
MySQL 8.0.21 - New Features Summary
MySQL 8.0.21 - New Features SummaryMySQL 8.0.21 - New Features Summary
MySQL 8.0.21 - New Features Summary
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...
MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...
MySQL Day Paris 2018 - MySQL InnoDB Cluster; A complete High Availability sol...
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)My First 100 days with a MySQL DBMS (WP)
My First 100 days with a MySQL DBMS (WP)
 
Securing your database servers from external attacks
Securing your database servers from external attacksSecuring your database servers from external attacks
Securing your database servers from external attacks
 
Setting up a MySQL Docker Container
Setting up a MySQL Docker ContainerSetting up a MySQL Docker Container
Setting up a MySQL Docker Container
 
PostgreSQL and MySQL
PostgreSQL and MySQLPostgreSQL and MySQL
PostgreSQL and MySQL
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
 
My sql introduction for Bestcom
My sql introduction for BestcomMy sql introduction for Bestcom
My sql introduction for Bestcom
 
My S Q L Introduction for 1 day training
My S Q L  Introduction for 1 day trainingMy S Q L  Introduction for 1 day training
My S Q L Introduction for 1 day training
 
Mysql 8 vs Mariadb 10.4 Highload++ 2019
Mysql 8 vs Mariadb 10.4 Highload++ 2019Mysql 8 vs Mariadb 10.4 Highload++ 2019
Mysql 8 vs Mariadb 10.4 Highload++ 2019
 
My sql
My sqlMy sql
My sql
 
My SQL 101
My SQL 101My SQL 101
My SQL 101
 
Mysql
Mysql Mysql
Mysql
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
 
MariaDB Security Best Practices
MariaDB Security Best PracticesMariaDB Security Best Practices
MariaDB Security Best Practices
 
Web Server Hardening
Web Server HardeningWeb Server Hardening
Web Server Hardening
 
My sql
My sqlMy sql
My sql
 

Dernier

Stochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptxStochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptxjkmrshll88
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j
 
Air Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdfAir Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdfJasonBoboKyaw
 
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...Neo4j
 
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...ferisulianta.com
 
Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1bengalurutug
 
2024 Build Generative AI for Non-Profits
2024 Build Generative AI for Non-Profits2024 Build Generative AI for Non-Profits
2024 Build Generative AI for Non-ProfitsTimothy Spann
 
Paul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdfPaul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdfdcphostmaster
 
Empowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded AnalyticsEmpowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded AnalyticsGain Insights
 
How to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product DevelopmentHow to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product DevelopmentAggregage
 
Data Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potxData Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potxEmmanuel Dauda
 
Unleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IMUnleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IMMarco Wobben
 
Brain Tumor Detection with Machine Learning.pptx
Brain Tumor Detection with Machine Learning.pptxBrain Tumor Detection with Machine Learning.pptx
Brain Tumor Detection with Machine Learning.pptxShammiRai3
 
The market for cross-border mortgages in Europe
The market for cross-border mortgages in EuropeThe market for cross-border mortgages in Europe
The market for cross-border mortgages in Europe321k
 
Data Collection from Social Media Platforms
Data Collection from Social Media PlatformsData Collection from Social Media Platforms
Data Collection from Social Media PlatformsMahmoud Yasser
 
PPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfggggPPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfggggbhadratanusenapati1
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptxFurkanTasci3
 
Microeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdfMicroeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdfmxlos0
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptxFurkanTasci3
 
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdfNeo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdfNeo4j
 

Dernier (20)

Stochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptxStochastic Dynamic Programming and You.pptx
Stochastic Dynamic Programming and You.pptx
 
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdfNeo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
Neo4j Graph Summit 2024 Workshop - EMEA - Breda_and_Munchen.pdf
 
Air Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdfAir Con Energy Rating Info411 Presentation.pdf
Air Con Energy Rating Info411 Presentation.pdf
 
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
Deloitte+RedCross_Talk to your data with Knowledge-enriched Generative AI.ppt...
 
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
Prediction Of Cryptocurrency Prices Using Lstm, Svm And Polynomial Regression...
 
Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1Bengaluru Tableau UG event- 2nd March 2024 Q1
Bengaluru Tableau UG event- 2nd March 2024 Q1
 
2024 Build Generative AI for Non-Profits
2024 Build Generative AI for Non-Profits2024 Build Generative AI for Non-Profits
2024 Build Generative AI for Non-Profits
 
Paul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdfPaul Martin (Gartner) - Show Me the AI Money.pdf
Paul Martin (Gartner) - Show Me the AI Money.pdf
 
Empowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded AnalyticsEmpowering Decisions A Guide to Embedded Analytics
Empowering Decisions A Guide to Embedded Analytics
 
How to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product DevelopmentHow to Build an Experimentation Culture for Data-Driven Product Development
How to Build an Experimentation Culture for Data-Driven Product Development
 
Data Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potxData Analytics Fundamentals: data analytics types.potx
Data Analytics Fundamentals: data analytics types.potx
 
Unleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IMUnleashing Datas Potential - Mastering Precision with FCO-IM
Unleashing Datas Potential - Mastering Precision with FCO-IM
 
Brain Tumor Detection with Machine Learning.pptx
Brain Tumor Detection with Machine Learning.pptxBrain Tumor Detection with Machine Learning.pptx
Brain Tumor Detection with Machine Learning.pptx
 
The market for cross-border mortgages in Europe
The market for cross-border mortgages in EuropeThe market for cross-border mortgages in Europe
The market for cross-border mortgages in Europe
 
Data Collection from Social Media Platforms
Data Collection from Social Media PlatformsData Collection from Social Media Platforms
Data Collection from Social Media Platforms
 
PPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfggggPPT for Presiding Officer.pptxvvdffdfgggg
PPT for Presiding Officer.pptxvvdffdfgggg
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
 
Microeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdfMicroeconomic Group Presentation Apple.pdf
Microeconomic Group Presentation Apple.pdf
 
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptxSTOCK PRICE ANALYSIS  Furkan Ali TASCI --.pptx
STOCK PRICE ANALYSIS Furkan Ali TASCI --.pptx
 
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdfNeo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
Neo4j_Jesus Barrasa_The Art of the Possible with Graph.pptx.pdf
 

Welcome to MySQL

  • 2. Safe Usage The material provided here is not free of errors and should be treated as such. If you find any error, please email me - haim.tzadok@grigale.com and I will try my best to correct any error. Before using this material, always test and test again, before implementing ! The technical material may be subject to changes and should be treated as a recommendation only.
  • 3. Table Of Content 1. MySQL Introduction 2. MySQL Clients 3. MySQL Architecture 4. MySQL Basic Security 5. MySQL Configuration 6. MySQL Administration 7. MySQL Monitoring 8. MySQL Replication 9. Backup & Recovery 10.MySQL Advanced Security 11.MySQL Performance Monitoring & Tuning
  • 4. WELCOME Introduction to MySQL o MySQL Editions o MySQL Components o MySQL Installation Brief MySQL Basic Security o User Privileges o User account management MySQL Clients o MySQL CLI o MySQL Workbench o MySQL Connectors o MySQL Router MySQL Architecture o Internal Architecture o Information Schema o Storage Engines MySQL Configuration o Server configuration o Client configuration MySQL Administration o OS Service o Data directory o Server logs o Utilities
  • 5. WELCOME MySQL Monitoring o Monitoring using Workbench o Enterprise Monitoring MySQL Replication o Replication formats o Replication methods o Binlog Replication o GTID replication o Replication topologies Backup & Recovery o Logical backup o Physical backup Advanced Security o MySQL Firewall o MySQL Auditing o Encryption MySQL Performance Monitoring
  • 7. MySQL Introduction Objectives ● Overview of MySQL History ● MySQL License and Availability ● MySQL Distributions ● MySQL Israeli Community Activities ● MySQL Editions ● MySQL Components ● MySQL Installation Brief – Windows/Linux “The wolrd’s most popular open source database”
  • 8. MySQL History MySQL - started as an OpenSource project for RDBMS. (Initially called msql) My - is the name of the daughter of the founder - Monty Widenius MySQL - Swedish company (MySQL AB) 2008 - it was bought by Sun Microsystems 2010 - Oracle acquired Sun Microsystems “The wolrd’s most popular open source database”
  • 9. MySQL Usage and Spread ● MySQL is the second world’s widely used RDBMS. (Which is the first ?) dbengines ranking – https://db-engines.com/en/ranking ● Ranking method: #of mentions in websites, frequency searches in google, # of mentions in technical sites (stackoverflow, DBA stack exchange), # of job offers, # of profiles in linkedin, # of tweets
  • 10. MySQL Usage and Spread ● MySQL is the second world’s widely used RDBMS. (Which is the first ?) dbengines ranking – https://db-engines.com/en/ranking ● MySQL is known as M in LAMP. ● It is widely used in many Web Application frameworks such as: Joomla, Drupal, WordPress etc… ● It is widely used by many large companies like: Google, Facebook, Twitter, Flickr, YouTube,Wikipedia, Booking.com etc.. ● In Israel it is widely used by many companies.
  • 11. Introduction to MySQL The world's most popular open source database
  • 12. MySQL License and Availability ● MySQL is Open Source project licensed under Dual license - GPL/Commercial ● It is maintained by Oracle/MySQL ● MySQL is multi platform - runs on Linux, Windows, Solaris, HP-UX, AIX, MAC OS/X and many more.
  • 13. MySQL Distributions ● MySQL has other forks like: ○ MariaDB ○ Percona ○ Google patches ○ Facebook patches
  • 14. MySQL Israeli Community activities ● MySQL enjoys large community and wide usage. ● MySQL Israeli User group - is an active Meetup group – http://meetup.com/MySQL-User-Group-Israel ● MySQL Acitivities and Conferences in Israel - hosted by Oracle/MySQL ● Tech tour – March 2018 ● Oracle week – November 2018 (2 MySQL seminars) ● MySQL Meetups – every 3~ Months. ● MySQL Workshops – every ½ year.
  • 15. MySQL Editions MySQL Product line: ○ MySQL Community edition • Server, WorkBench, Connectors, utilities ○ MySQL Standard Edition ○ Community + 24/7 Support + Consultative support ○ MySQL Enterprise Edition ○ Standard + Enterprise tools like: MEB, MEM, Firewall, Audit, Thread Pooling etc… ○ MySQL Cluster Carrier Grade Edition ○ Enterprise + NDB + Cluster
  • 16. Introduction to MySQL MySQL Components • MySQL Server • Workbench (GUI) • MySQL Connectors • MySQL Router • MySQL Utilities • MySQL Enterprise Monitor (MEM) • MySQL Enterprise Backup (MEB) • MySQL Enterprise Audit • MySQL Enterprise security (PAM authentication plugin) • MySQL Thread Pool • MySQL Firewall
  • 17. MySQL Installation Brief Obtaining MySQL for Windows ● Available .msi or zip distributions ● Download the software from mysql.com ○ Requires Oracle SSO user in order to access Oracle eDelivery site ○ Two kind of installers - ■ MySQL Web community - which downloads mysql online ■ MySQL Community - Downloads the whole installation for offline usage
  • 18. Obtaining MySQL for Windows ● 4 Installation types: ○ Developer ■ installs Server, Client and excel plugin for MySQL. ○ Server Only ■ Only installs MySQL server ○ Client Only ■ Only installs Workbench MySQL Visual studio plugin and MySQL Connectors ○ Full ■ installs everything ○ Custom ■ Allows to select what to install
  • 19. Obtaining MySQL for Windows ● Pre-requisite - ○ In order to use workbench and other MySQL tools it is better to download and install - Microsoft Visual C++ 2013 redistributable/runtime package
  • 20. Obtaining MySQL for Windows Proceed to execute...
  • 21. Obtaining MySQL for Linux ● Installation via packages ○ Download the packages as a single zip file from Oracle eDelivery site ○ Open the zip file ○ Install the packages ○ Prerequisites should be met manually... ● Installation via Repositories - ○ Available CentOS based Linux repository ○ Available Debian flavors Linux repository ○ All prerequisites are handled automatically
  • 22. Obtaining MySQL for Linux - DEMO ● Installation via packages ○ Download the packages as a single zip file from Oracle eDelivery site, you may also download the commercial packages. ■ You should identify the right packeges for your Linux distribution. ■ if you download commercial packages - remember that big brother is watching... ○ Open the zip file - using the unzip command ○ Install the packages - using deb or rpm command ○ Prerequisites should be met manually… ■ Commonly missing packages are - proj, python etc... ■ To install all packages, you can also use: yum localinstall *.rpm
  • 23. Obtaining MySQL for Linux - DEMO ● Installation via Repositories - ○ Available CentOS based Linux repository - Download the relevant package from the link: ○ http://dev.mysql.com/downloads/repo/yum/ ○ Install the package Using: yum localinstall mysql57-community-release-el6-n.noarch.rpm ○ Fetch MySQL from the repository using the command: yum install mysql-community-server yum install mysql-workbench-community ○ Usually all prerequisites are handled automatically, provided that you have the necessary repositories
  • 24. Obtaining MySQL for Linux - DEMO Initalizing a DB on MySQL (5.6) To initialize a database, just run the secure installation script mysql_secure_installation This script will ask about root password for the Database. It will remove anonymous users and so on… Initializing a DB on MySQL (5.7) To initialize a fresh database of MySQL 5.7 - just start the service. The root password is generated automatically and can be fetched using the command: grep 'temporary password' /var/log/mysqld.log To change the root password: mysql -uroot -p ALTER USER ’root’@’localhost’ identified by ’newpassword’
  • 25. Obtaining MySQL for Linux - DEMO Handling MySQL Service ● To start MySQL server: ○ service mysqld start (CentOS6) ○ systemctl start mysql (CentOS7) ● To stop MySQL server: ○ service mysqld stop (CentOS6) ○ systemctl stop mysql (CentOS7) ● To get status of MySQL server: ○ service mysqld status (CentOS6) ○ systemctl status mysql (CentOS7)
  • 27. MySQL Basic Security • MySQL Access Privileges • MySQL User account Management
  • 28. MySQL Access Privileges • MySQL Access Privileges • All the information is stored in MySQL DB. • User is identified by a combination of - username and host (userhost). haim@mysql1 = haim@mysql2 • The wildcard ‘%’ for the host part – represents that a user can connect from any host except from the localhost. • A user is a global object, password is not associated with db,table or routine
  • 29. MySQL User account Management Create Remove Status USER create user haim@’%’ identified by ‘pass123’; DROP USER haim@’%’ ; select user, host from mysql.user; Privilege GRANT ALL ON *.* TO haim@’%’; REVOKE INSERT ON *.* FROM haim@’%’; show grants for user@’host’; Resource limits CREATE USER haim@'localhost' IDENTIFIED BY ‘pass123' WITH > MAX_QUERIES_PER_HOUR 20 > MAX_UPDATES_PER_HOUR 10 > MAX_CONNECTIONS_PER_HOUR 5 > MAX_USER_CONNECTIONS 2; ALTER USER haim@'localhost' WITH MAX_CONNECTIONS_PER_HOUR 0; desc mysql.user; select user, host, MAX_QUERIES_PER_HOUR, MAX_CONNECTIONS_PER_HOUR FROM mysql.user; PASSWORD CREATE USER haim@'localhost' IDENTIFIED BY ‘pass123' ; ALTER USER haim@'localhost' IDENTIFIED BY ‘pass123' ;
  • 31. MySQL Clients • SQL Review • MySQL Client/Server Architecture • Client Types – CLI clients • mysql client • Mysqladmin client – Application specific clients • Connectors • Router – GUI Clients • Workbench
  • 32. SQL Review SQL SQL is a database computer language designed for the retrieval and management of data in relational database. SQL stands for Structured Query Language. DDL Data Definition Language SHOW databases SHOW tables CREATE database <db_name> DROP database <db_name> CREATE table <table_name> DROP table <table_name> ALTER – change table columns RENAME – rename table SHOW CREATE – show information on the DB or Table. DML Data manipulation language SELECT– select rows for viewing INSERT– insert data as rows UPDATE– update rows DELETE– delete rows TRUNCATE– delete all rows in table DCL Data Control language CREATE user ALTER user RENAME user DROP user GRANT privileges REVOKE privileges SET PASSWORD create table tab1 (ID int, FIRST char(20), LAST char(20)); Insert into db1.tab1 (ID,FIRST,LAST) VALUES (1,’Haim’,’Tzadok’); SHOW [GLOBAL] VARIABLES LIKE ‘%pass%’;
  • 33. SQL review MySQL InnoDB InnoDB is by default set to ‘autocommit’. DDL BEGIN/START TRANSACTION CREATE T1 (C1 int); CREATE T2 (C1 int); Rollback; CREATE T3 (C1 int); SHOW TABLES; What is the output ? DML BEGIN/START TRANSACTION INSERT INTO T1(‘C1’) VALUES (10); INSERT INTO T1(‘C1’) VALUES (9); Rollback; SELECT * from T1; INSERT INTO T1(‘C1’) VALUES (7); Select * from T1; What is the output ? create table tab1 (ID int, FIRST char(20), LAST char(20)); Insert into db1.tab1 (ID,FIRST,LAST) VALUES (1,’Haim’,’Tzadok’); SHOW [GLOBAL] VARIABLES LIKE ‘%pass%’;
  • 34. MySQL Client/Server Architecture • All clients must negotiate for credentials via a tcp/connection or via socket. • Based on credited privileges, connected clients are then able to query the server. • A MySQL distribution provides several types of clients. • MySQL also releases GUI clients (see Workbench)
  • 35. Client Types CLI Clients • MySQL Command line clients ▪ mysql – a command line client ▪ mysqladmin – a command line client for management GUI Clients • Workbench Application Clients • MySQL Connectors • MySQL Router
  • 36. MySQL Client/Server Architecture ● All clients connect to MySQL using the MySQL Client API. ● Most do not implement this API, but rather use connectors or libraries to wrap it up. ● Not all connectors themselves implement the API. Some rely on the libmysqlclient, for example.
  • 37. MySQL Command Line Clients ● MySQL ships with many command line clients: ● mysql: a general, interactive/non-interactive client ● mysqladmin: a utility to perform administration tasks ● mysqldump: a client to export database structure and data ● mysqlshow: a client to query metadata ● mysqlimport: an importing utility ● more in mysql utilities…
  • 38. Command Line client options ● To connect with a MySQL command line client, one must supply with credentials: [root@olp1 ~]# mysql -u root -p mysql: [Warning] Using a password on the command line interface can be insecure. Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 70 Server version: 5.7.13-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial) 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>
  • 39. mysql client - variables and values bash:~$ mysql --help … (at the end of output) Variables (--variable-name=value) and Boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---- ------------------------------------ debug-info FALSE database (No default value) default-character-set auto delimiter ; enable-cleartext-plugin TRUE vertical FALSE force FALSE named-commands FALSE ignore-spaces FALSE init-command (No default value) local-infile FALSE no-beep FALSE host (No default value) html FALSE xml FALSE line-numbers TRUE unbuffered FALSE column-names TRUE sigint-ignore FALSE port 0 prompt mysql> quick FALSE raw FALSE reconnect TRUE socket /var/lib/mysql/mysql.sock value) ssl-crlpath (No default value) ssl-verify-server-cert FALSE table FALSE user root safe-updates FALSE i-am-a-dummy FALSE connect-timeout 0 max-allowed-packet 16777216 net-buffer-length 16384 select-limit 1000 max-join-size 1000000 secure-auth TRUE show-warnings FALSE
  • 40. The mysql client SYNOPSIS mysql [options] [db_name] Usually reads /etc/my.cnf and $HOME/.my.cnf General purpose options include: --help : shows help and the current Variables options and Boolean values -h / --host : server host name (default: localhost) -P / --port : server TCP/IP port (default: 3306) -S / --socket : UNIX socket file -u / --user : MySQL login -U / --safe-updates, --i-am-a-dummy : safe mode -p / --password : password --defaults-file : name of configuration file where options are listed.
  • 41. Output format (Using ; or G) Execute queries - ending with ; or G A statement ending with ; will produce an output in table format. mysqlmysql> explain select * from mysql.user; +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+ | 1 | SIMPLE | user | NULL | ALL | NULL | NULL | NULL | NULL | 4 | 100.00 | NULL | +----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+ 1 row in set, 1 warning (0.00 sec) A statement ending with G will produce an output in list format. mysql> explain select * from mysql.userG *************************** 1. row *************************** id: 1 select_type: SIMPLE table: user partitions: NULL type: ALL …. filtered: 100.00 Extra: NULL 1 row in set, 1 warning (0.00 sec)
  • 42. Different Output Format (XML) Use --xml to get output in XML format [root@olp1 ~]# mysql -uroot grigale --xml --execute="SELECT * FROM employees LIMIT 2" mysql: [Warning] Using a password on the command line interface can be insecure. <?xml version="1.0"?> <resultset statement="SELECT * FROM employees LIMIT 2 " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row> <field name="ID">1</field> <field name="FIRST">Haim</field> <field name="LAST">Tzadok</field> </row> </resultset>
  • 43. Operations on Databases show databases – shows available databases. use <db_name> - select the database you want to use. create database <db_name> - creates an empty database. drop database <db_name> - drops a database.
  • 44. The mysql client mysql> use grigale; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show tables; +-------------------+ | Tables_in_grigale | +-------------------+ | employees | +-------------------+ 1 row in set (0.00 sec) mysql>
  • 45. Using pager mysql> pager less PAGER set to 'less' mysql> show tables; +-----------------------------------+ | Tables_in_opencart | +-----------------------------------+ | oc_address | | oc_affiliate | | oc_affiliate_activity | | oc_category_to_layout | | oc_category_to_store | | oc_country | … … … (END) mysql> pager grep country PAGER set to 'grep country' mysql> show tables; | oc_country | 124 rows in set (0.01 sec) mysql> On UNIX/Linux Systems, use pager to manipulate the output of the result set.
  • 46. Pager command Execute pager with no arguments to cancel current pager. There are some nice tricks with pager. mysql> pager md5sum; PAGER set to 'md5sum' mysql> select * from employees; 758839cc399f41c7f5ecf765f058acd9 - 1 row in set (0.00 sec) mysql> pager Default pager wasn't set, using stdout. mysql>
  • 47. Log session activities Log all activity in external text file using tee, Disable with notee. mysql> tee /tmp/output.txt Logging to file '/tmp/output.txt' mysql> mysql> SELECT 123 FROM grigale.employees; -------- | 123 | -------- | 123 | -------- 1 row in set (0.00 sec) mysql> notee;
  • 48. Log session activities To show the activities just use any printing command to view the file that was saved. root@mysql1:~# cat /tmp/output.txt mysql> mysql> SELECT 123 FROM grigale.employees; ------- | 123 | ------- | 123 | -------- 1 row in set (0.00 sec)
  • 49. Execute SQL from external files Use SOURCE to execute SQL statements from external files. mysql> SOURCE /home/haim/test.sql; Query OK, 1 row affected (0.00 sec) Query OK, 1 row affected (0.00 sec) Query OK, 1 row affected (0.00 sec) ...
  • 50. Using non-interactive sql scripts The mysql client accepts reads from standard input. This allows pipelining or redirection: [root@centv1]# cat /tmp/databases/world.sql | mysql -uroot world [root@centv1]# cat /tmp/databases/world.sql | sed -e s/ENGINE=MyISAM/ENGINE=InnoDB/g | mysql -uroot world bash# mysql -uroot world < /tmp/databases/world.sql
  • 51. Using non-interactive mysql command Execute a query without getting into interactive shell, using –e “” /--execute=“”. This can be further combined with pipelining [root@olp1 ~]# mysql -u root -p grigale -e " select count(*) from employees;" mysql: [Warning] Using a password on the command line interface can be insecure. Enter password: +----------+ | count(*) | +----------+ | 1 | +----------+ [root@olp1 ~]#
  • 52. The mysqladmin client • Allows for administrative tasks. • Provide the processlist argument to show pending connections. [root@olp1 ~]# mysqladmin -uroot -p processlist Enter password: +----+------+-----------+----+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+----+---------+------+----------+------------------+ | 76 | root | localhost | | Query | 0 | starting | show processlist | +----+------+-----------+----+---------+------+----------+------------------+ [root@olp1 ~]#
  • 53. The mysqladmin client • Add -c, -i to make for successive invocations. • -c : count -i: interval [root@olp1 ~]# mysqladmin -uroot -p processlist -c 2 -i 1 Enter password: +----+------+-----------+----+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+----+---------+------+----------+------------------+ | 79 | root | localhost | | Query | 0 | starting | show processlist | +----+------+-----------+----+---------+------+----------+------------------+ +----+------+-----------+----+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+----+---------+------+----------+------------------+ | 79 | root | localhost | | Query | 0 | starting | show processlist | +----+------+-----------+----+---------+------+----------+------------------+ [root@olp1 ~]#
  • 54. The mysqladmin client • Use the status argument to print general purpose status: • -c : count -i: interval [root@olp1 ~]# mysqladmin -uroot -p status -c 2 -i 1 Enter password: Uptime: 1215337 Threads: 1 Questions: 9390 Slow queries: 0 Opens: 589 Flush tables: 1 Open tables: 567 Queries per second avg: 0.007 Uptime: 1215338 Threads: 1 Questions: 9391 Slow queries: 0 Opens: 589 Flush tables: 1 Open tables: 567 Queries per second avg: 0.007 [root@olp1 ~]#
  • 55. The mysqladmin client • Use the kill argument forcibly kill a connection [root@olp1 ~]# mysqladmin -uroot -p processlist +----+------+-----------+----+---------+------+------------+-------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+----+---------+------+------------+-------------------------------------------------+ | 82 | root | localhost | | Query | 34 | User sleep | select 1 from grigale.employees where sleep(10000) | | 84 | root | localhost | | Query | 0 | starting | show processlist | +----+------+-----------+----+---------+------+------------+-------------------------------------------------+ [root@olp1 ~]# mysqladmin -uroot -p kill 82 [root@olp1 ~]# mysqladmin -uroot -p processlist +----+------+-----------+----+---------+------+----------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +----+------+-----------+----+---------+------+----------+------------------+ | 86 | root | localhost | | Query | 0 | starting | show processlist | +----+------+-----------+----+---------+------+----------+------------------+ [root@olp1 ~]#
  • 56. The mysqladmin client Other commands: • extended-status: dump the result of SHOW GLOBAL STATUS • shutdown: shut down the server • password: change an account's password • flush-logs: flush + rotate logs • more...
  • 57. Connectors Oracle/MySQL supply with MySQL connectors These are client libraries, implemented in popular programming languages: • Connector/J, JDBC driver for Java • ADO.NET for the .NET framework • Connector/ODBC • Connector/C++ • More... Work is evolving and new connectors are occasionaly added.
  • 58. Connectors 3rd parties also provide MySQL connectors: ● libdbd-mysql-perl ● libdbd-mysql-ruby ● Python MySQLdb ● More... The common connectors are open source, released under varying licenses. If using Enterprise Edition: – It is strongly recommended to use the commercial connectors.
  • 59. Connectors The MySQL connectors usually implement the MySQL Client API, and 3rd party solutions usually rely on client libraries (e.g. libmysqlclient) The average user will use the ordinary connector, and will not dwell into the Client API. Consult you favorite connector's API to learn how to connect and query MySQL.
  • 60. MySQL Router • MySQL Router is a lightweight middleware that provides transparent routing between your applications to your MySQL servers. • MySQL Router is normally installed in each application server. • Two scheduling based on mode option are available ▪ Read-write: uses a list with First available routing method. ▪ Read-only: uses round-robin routing method. ▪ Default configuration file: /etc/mysqlrouter/mysqlrouter.ini
  • 61. MySQL Router • Read-only configuration: [routing: ro_prod] bind_port=7001 Destinations = slave1, slave2, slave3 mode=read-only • Read-Write configuration: [routing: rw_prod] bind_port=7002 Destinations = master1, master2, master3 mode=read-write
  • 62. Workbench Workbench is the default GUI client that comes with MySQL. Available on Windows/Linux. Main Features – • Rich and Sophisticated connection mechanism use SSH to tunnel and encrypt connection, or use direct connection to DB. (DB can be local or remote machine) • SSL Encryption available for direct connection • Data design & Modeling • Execute queries and analyze queries • Status and online monitoring • Extensive performance monitoring reports • Full DB Administration
  • 63. Workbench Workbench Connection administration • - Add a connection - Edit one of the available Connections
  • 64. Workbench Workbench Connection details – by tapping the right upper edge of an existing connection.
  • 65. Workbench Main Navigation Navigator Use navigator to navigate Between Available Administration options
  • 66. Workbench Management -> Server status – Shows server Status and online monitoring
  • 67. Workbench – Database design and modeling Workbench Data design and modeling - Add a new data model file - Open an existing data model file. - Create EER diagram from an existing database or script
  • 68. Workbench – Data Modeling Database –> Reverse Engineering You can create a EER diagram of your existing database. Database –> Forward engineering You can implement a EER diagram to a new database.
  • 69. Workbench – Preferences Edit – Preferences You can change the Behavior of workbench to fit your needs. For example – Show Metadata and Internal schemas - will Reveal internal databases Such as mysql, performance_schema, sys and more… Combine Managenent Tools and Schema Tree - will combine/Separate the management tools From the Schema tree management.
  • 71. MySQL Architecture • MySQL Architecture • MySQL Information Schema • MySQL Storage Engines
  • 73. MySQL Information Schema • MySQL Information Schema – Holds database metadata • Schema design and architecture • Running processes • Internal counters • Replication status • Storage engine specific information • Grants and privileges – A collection of read only views/tables – Aggregate data from various MySQL components and the user’s data. – Allows for SQL access to metadata – Holds no data – all the information is gathered at runtime.
  • 74. MySQL Storage Engines Sotrage Engine History ● Originally MySQL provided ISAM, then MyISAM engines. ● Berkeley DB (BDB) was the first 3rd party storage engine to work with MySQL. ● InnoDB was later introduced. ● The storage engine API has since evolved. ● MySQL continued developing in house storage engines. ● There is now a large number of MySQL storage engines.
  • 75. MySQL Storage Engines What is a storage Engine? ● Every table belongs to a specific storage engine. ● The storage engine is a module responsible for storing table's data and keys. ● It is responsible for allocating disk storage, memory cache, storing and fetching of data, providing with information. ● It is similar in concept to file systems: while they basically provide the same functionality, implementation is different; plus different features can be added.
  • 76. MySQL Storage Engines What is Storage Engine ? ● There is a fine line between MySQL's roles and the SE's roles. For example: ● Parsing of the query is strictly MySQL's role. ● Building the B-Tree for the index is strictly the SE's role. ● Evaluation the execution plan is MySQL's role, but based on recommendations from the SE.
  • 77. MySQL Storage Engines Storage engine responsibilities ● Data storage ● Index implementations ● Transactional support ● Caching ● Compression ● Constraints ● Additional features (e.g. accept special syntax)
  • 78. MySQL Storage Engines Major players In-house (Oracle/MySQL) storage engines are: ● MyISAM (Non transactional SE, not ACID compliant) ● MERGE ● InnoDB ● MEMORY (Saves all the data in the RAM) ● Blackhole (don’t save data in db files, used for replication shipping) ● CSV (Save the data as .csv files, don’t allow indexes) ● ARCHIVE (Compress the data and archive it) ● Federated ● NDB (as part of MySQL Cluster) Newer, emerging and gaining popularity: ● XtraDB (InnoDB plugin fork by Percona) ● MariaDB (by Monty Program AB) Today MySQL recommend using InnoDB for all kind of uses !
  • 79. MySQL Architecture MySQL Storage Engines Which engine do we use ? Use SHOW commands. mysql> show create table employees; +-----------+---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------+ | Table | Create Table | +-----------+---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------+ | employees | CREATE TABLE `employees` ( `id` int(11) DEFAULT NULL, `first` char(30) DEFAULT NULL, `last` char(30) DEFAULT NULL, KEY `i1` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +-----------+---------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
  • 80. MySQL Architecture MySQL Storage Engines InnoDB Each database has a directory inside the data dir. *.frm – contains table structure. *.ibd – contains data and indexes. show engine innodb status – Shows the status of innodb engine. Lsn- current log sequence number of the redo logs. Redo-logs – a mechanism of innodb. Bin-log – a mechanism in mysql not related to innodb, used for replication and point-in-time recovery.
  • 82. MySQL Configuration AGENDA • MySQL Server Configuration (/etc/my.cnf mysqld section, dynamic/static variables – allow/don’t allow changes at runtime) • MySQL Client Configuration (/etc/my.cnf client section) • MySQL Variables (show variables like ‘%pass%’, global/session specific variables, read-only/read-write parameters) • MySQL Server Status (show status)
  • 83. MySQL Server Configuration • Essential parameters: – port, socket, datadir, • General parameters: – init-connect – statement that will be executed upon start of connection – sql_mode – a set of modes that mysql will comply to when running SQL statements. – read_only (0=OFF, 1=ON) – wait_timeout (in seconds) – InnoDB parameters – innodb_buffer_pool_size – the amount of memory innodb will use for data & index caches. – Innodb_log_file_size – size of transaction log size. – Innodb_file_per_table – required for replication. – Innodb_lock_wait_timeoiut – seconds to wait before rolling back a locking transaction. – Workbench -> MANAGEMENT -> Status and System Variables – Status variables – read only variables – System variables – configurable variables.
  • 84. MySQL Variables • MySQL Variables – Global parameters – Session specific parameters. • MySQL Variables are parameters that comes from my.cnf or as dynamic parameters. • Some of them are read only some of them are writable. • Full list of 5.7 parameters: http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html show variables like ‘%string%’; show global variables like ‘%string%’; select @@global.read_only ; set global max_connections = 1000; - set max connections variable globally SET sql_log_bin=0; - disable bin logging in the current session
  • 85. MySQL Server Status • MySQL Server Status Metadata show databases | show tables | show plugins | show triggers | show indexes| show grants show create table/procedure/trigger |
  • 86. MySQL Server Status status show status|show master status| show slave status | show open tables |show engine innodb status | show [full] processlist |show global status • show status like ‘%conn%’;
  • 88. MySQL Administration AGENDA • MySQL Service • MySQL Data Directory • MySQL Server Logs • MySQL Multiple Instances • MySQL Utilities
  • 89. MySQL Service Handling MySQL Service ● To start MySQL server: ○ service mysqld start (CentOS 6) ○ systemctl start mysql (CentOS 7) ● To stop MySQL server: ○ service mysqld stop (CentOS 6) ○ systemctl stop mysql (CentOS 7) ● To get status of MySQL server: ○ service mysqld status (CentOS 6) ○ systemctl status mysql (CentOS 7)
  • 90. MySQL Data Directory • /etc/my.cnf – default configuration file. • /var/lib/mysql – Default data dir. • /var/log/mysqld.log – default log file • /var/lib/mysql/mysql.sock – default socket file • /var/lib/mysql/mysqld.pid – pid file • /usr/lib64/mysql/plugin – plugins directory
  • 91. MySQL Server logs • Bin log - saves events that changes the database (DDL/DML) including their times, but does not save show/select events. – Normally needed for replication between the current master and it’s slaves. – When doing backup all changes are stored in the binlog till the backup is finished and then re-run from the binlog to take affect. – Good for point in time recovery. – Available formats: MIXED (recommended), ROW, STATEMENT • General log – saves any event that occurred in the database. (usually enabled when needed more debugging). • Error log – stores error events, usually under /var/log/mysqld.log • Slow log – stores slow query logs (normally more than 10 seconds - in real time), normally does not log slow administrative or replication statements.
  • 92. MySQL Utilities • MySQL Utilities is a package with set of administrative scripts written in python mainly handling administration, replication, general usage and more. • Bin log operation – • DB operations • General operations • HA operations • Server operations • Specialized operations
  • 94. MySQL Monitoring • MySQL Monitoring Tools • Monitoring MySQL using WorkBench • Monitoring MySQL Server using CLI • MySQL Enterprise Monitor – DEMO
  • 96. MySQL Replication • MySQL Replication formats • MySQL Replication methods • MySQL Replication topologies
  • 97. MySQL Replication • MySQL Replication formats – SBR – Statement Based Replication – RBR – Raw Based Replication – Mixed – Utilize both formats • MySQL Replication methods – Replication using Binlog – Replication using GTID’s • MySQL Replication topologies – Master/Slave Topology – Chained Topology – Group Replication Topology
  • 98. MySQL Replication • MySQL Replication formats – SBR – Statement based Replication, replication ships the statements between replicated nodes. – RBR – Raw based replication, replication ships the outcome of the execution of statements between replicated nodes. – Mixed – Utilize both formats.
  • 99. MySQL Replication • MySQL Replication Methods – Replication using Binlog – Slave fetches transactions from the Master using binlog position mechanism. (Each transaction is anonymous transaction) – Replication using GTID’s – Slave fetches transactions from the Master using Global Transaction ID’s (Each transaction has an ID)
  • 100. MySQL Replication • MySQL Replication topologies – Master/Slave(s) – Chained (Master/Intermediate/Slave) – Group Replication M M M M I M S S M S
  • 101. MySQL Replication MySQL Replication formats CAP Theorem – Consistency, Availability, Partition Tolerance We can only have two out of the three. Consistency AvailabilityPartition Tolerance CA – Network problem Might stop system. Ex: RDBMS Systems (Oracle, MySQL, …) CP – There is a risk of data Becoming unavailable Ex: MongoDB, Hbase, Memcache PA – Clients may read inconsistent Data Ex: Cassandra, Riak, CouchDB
  • 102. MySQL Backup & Recovery
  • 103. MySQL Backup and Recovery • MySQL Backup Methods –MySQL logical Backup & Restore –MySQL physical Backup & Restore
  • 104. MySQL Backup and Restore MySQL Backup Methods • Logical Backup – using mysqldump – Storage engine independent – Architecture independent – Textual backup, easy to manipulate – Corruption is easily detected. – Usually very slow…
  • 105. MySQL Backup and Recovery MySQL Backup Methods • Physical(Raw) Backup – using MEB (MySQL Enterprise Backup) – Consist of raw copies of directories and files using snapshot like technology. – Suitable for large, important databases. – Usually very fast…
  • 107. MySQL Advanced Security • MySQL Firewall • MySQL Auditing • MySQL encryption
  • 108. MySQL Firewall • MySQL Firewall consists of several plugins and tables in information_schema and mysql db. • MySQL Firewall is enabled globally but it will not work till it is implemented on users. • Firewall mode on users – OFF – Firewall is not implemented on the user. RECORDING – Generates white list for the specific user which is being recorded. DETECTING - detect and log any transaction which is not in the white list. PROTECTING - enables the firewall to work in enforcing mode. (any statement that is not in the white list will be denied).
  • 109. MySQL Auditing MySQL Auditing MySQL Enterprise Audit provides an easy to use, policy-based auditing solution that helps organizations implement stronger security controls and satisfy regulatory compliance. As more sensitive data is collected, stored and used online, database auditing becomes an essential component of any security strategy. To guard against the misuse of information, popular compliance regulations including HIPAA, Sarbanes- Oxley, and the PCI Data Security Standard require organizations to track access to information.
  • 110. MySQL Encryption Encryption vs TDE Enabling MySQL Encryption
  • 111. MySQL Encryption Encryption vs TDE Encryption – Data itself is encrypted No indexes can be enabled on encrypted column. Data is decrypted using a private key. TDE – Transparent Data encryption is encryption in the file-system layer.
  • 113. MySQL Performance Monitoring • Buffer Pool, Redo logs and Binlog • Performance Schema • SYS Schema • Monitoring Tools
  • 114. Buffer Pool, Redo Logs and Binlog • The Buffer pool is mainly a cache for incoming read/write operations. Every new transaction is first written to the redo log • After a while the redo logs are flushed to the data files. • Binlog is a different mechanism to store logs mainly for replication and point-in-time recovery. • If the server is crashed the recovery is reading the redo logs and flush things to disk. Bufferpool REDO LOGS Datadir datafiles Tab3 Tab2 Tab1
  • 115. Performance schema • A storage engine for collecting performance. • Collection of sensors that inform about the time an access has occurred. • Collection of tables that stores all the timers. • Usually not easily readable.
  • 116. SYS Schema • A storage engine that helps to interpret the performance schema. • Collection of views that summarize performance schema data • Stored procedures that enables performance schema operations such as configuration changes and diagnostic reports.
  • 117. MySQL Performance Monitoring and Tuning Monitoring tools • Workbench – Performance -> Performance Reports -> High Cost SQL Statements • Mysqlslap – load emulation client • HeidiSQL – SQL GUI • MonYog – 3rd party monitoring tool