You are on page 1of 107

Oracle

 
Support  Stars  
Bar
• Ask  the  Experts  your  
toughest  product  
quesCons.
• View  My  Oracle  
Support  and  Product  
DemonstraCons.
• Learn  what’s  new  and  
more!

9/6/16 Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.  
Oracle  Confiden1al  –   9
Monday, September 19, 16 Internal/Restricted/Highly  
A  MySQL  DBA  Primer
Ligaya  Turmelle
Principal  Technical  Support  Engineer  -­‐  MySQL
ligaya.turmelle@oracle.com
@lig

Copyright  ©  2016,  ,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 2


Monday, September 19, 16
Safe  Harbor  Statement
The  following  is  intended  to  outline  our  general  product  direc1on.  It  is  intended  for  
informa1on  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  
commitment  to  deliver  any  material,  code,  or  func1onality,  and  should  not  be  relied  upon  
in  making  purchasing  decisions.  The  development,  release,  and  1ming  of  any  features  or  
func1onality  described  for  Oracle’s  products  remains  at  the  sole  discre1on  of  Oracle.

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


3
Monday, September 19, 16
Agenda  -­‐  First  Half

1 • Founda1on
2 • Installa1on

3 • Talking  to  MySQL

4 • Architecture
5 • Log  Files

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


4
Monday, September 19, 16
Agenda  -­‐  Second  Half

5 • Log  Files  (con’t)


6 • Security
7 • Backup

8 • Monitoring
9 • Basic  Troubleshoo1ng

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


5
Monday, September 19, 16
FoundaCon

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


6
Monday, September 19, 16
FoundaCon

1 • Basics
2 • Commercial

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


7
Monday, September 19, 16
MySQL  in  a  Nutshell

• Worlds  most  popular  open  source  database


• “M”  of  LAMP
• Main  site:  mysql.com

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


8
Monday, September 19, 16
MySQL.com

• mysql.com
- Commercial site
• dev.mysql.com (AKA mysql.org)
- Developer Zone
• downloads.mysql.com
• dev.mysql.com/doc/
- Documentation
• bugs.mysql.com
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
9
Monday, September 19, 16
GeXng  Help

• Manual
• MySQL  Support
• MySQL  Forums  (forums.mysql.com)
• Mailing  Lists  (lists.mysql.com)
• Search  the  Web
• IRC  on  freenode  -­‐  #mysql

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


10
Monday, September 19, 16
Main  Features

• Works  on  mul1ple  plaborms


• Mul1-­‐layered  server  design
• Pluggable  architecture
-­‐ Storage  engine
-­‐ Misc  plugins  (Ex:  validate_password,  SHA256_password)
• Mul1-­‐threaded
• “Plays  well”  with  most  programming  languages

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


11
Monday, September 19, 16
FoundaCon

1 • Basics
2 • Commercial

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


12
Monday, September 19, 16
Enterprise  EdiCon  Add-­‐Ons

• MySQL  Enterprise  Backup  (MEB)


• MySQL  Enterprise  Monitor  (MEM)
• Workbench
• Plugins
• Threadpool,  Audit,  Firewall,  TDE,  Encryp1on,  PAM,  etc
• Oracle  Enterprise  Manager  for  MySQL

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


13
Monday, September 19, 16
InstallaCon

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


14
Monday, September 19, 16
InstallaCon

1 • Files
2 • Installa1on

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


15
Monday, September 19, 16
OpCon  Files # The following options will be passed to all
MySQL clients

• AKA  configura1on  files [client]


#password! = your_password
port! ! = 3626
• Lists  specific  startup  op1ons socket!! = /tmp/mysql.5.6.26.sock

# Here follows entries for some specific


programs

# The MySQL server


[mysqld]
port! = 3626
socket!= /tmp/mysql.5.6.26.sock
log-error = /Users/ligaya/mysql_installs/
mysql-5.6.26-osx10.9-x86_64/data/error.log
server-id! = 1
table_open_cache = 4000

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 16


Monday, September 19, 16
Common  LocaCons  of  OpCon  File

• Windows
- INSTALLDIR\my.ini
- INSTALLDIR\my.cnf
• Linux  &  Mac
- /etc/my.cnf
- /etc/mysql/my.cnf

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


17
Monday, September 19, 16
Generic  Unix/Linux  Binary  File  Layout

Directory Contents
bin, scripts Client  programs,  mysqld  server  and  u1lity  programs
data Log  files  and  databases
docs Manual  in  Info  format
man Unix  manual  pages
include Include  (header)  files
lib Libraries
Misc  support  files  including  error  messages,  sample  op1on  files  and  SQL  for  database  
share
installa1on

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


18
Monday, September 19, 16
Linux  RPM  File  Layout

Directory Contents
/usr/bin Client  programs  and  scripts
/usr/sbin mysqld  server
/var/lib/mysql log  files  and  databases
/usr/share/info Manual  in  Info  format
/usr/share/man Unix  manual  pages
/usr/include/mysql Include  (header)  files
/usr/lib/mysql Libraries
Misc  support  files  including  error  messages,  character  set  files,  sample  op1on  files  and  
/usr/share/mysql
SQL  for  database  installa1on

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


19
Monday, September 19, 16
Windows  File  Layout
Directory Contents Notes
bin, scripts Client  programs,  mysqld  server  and  u1li1es  scripts
The Windows system variable
%ALLUSERSPROFILE% Log  files  and  databases  (Windows  XP,  Windows  Server   %ALLUSERSPROFILE% defaults to
\MySQL\MySQL
Server 5.7\ 2003) C:\Documents and Settings
\All Users\Application Data
%PROGRAMDATA% The Windows system variable
\MySQL\MySQL
Log  files  and  databases  (Vista,  Windows  7,  Windows   %PROGRAMDATA% defaults to C:
Server  2008  and  newer) \ProgramData
Server 5.7\
examples Example  programs  and  scripts
include include  (header)  files
lib Libraries
Misc  support  files  including  error  messages,  character  set  
share
files,  sample  op1on  files  and  SQL  for  database  installa1on

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


20
Monday, September 19, 16
InstallaCon

1 • Files
2 • Installa1on

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


21
Monday, September 19, 16
InstallaCon

• Well  documented  in  the  Manual


• Each  OS  is  documented  -­‐  some  with  mul1ple  ways  to  do  it
-­‐ Unix/Linux  Generic  Binaries
-­‐ Windows
-­‐ Mac
-­‐ Various  Linux  (MySQL  Repositories,  RPM,  Na1ve  Repositories)
-­‐ Solaris
-­‐ Source

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


22
Monday, September 19, 16
Generic  Binary  InstallaCon
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chmod 770 mysql-files
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db --user=mysql # Before 5.7.6
shell> bin/mysqld --initialize --user=mysql # 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup # 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data mysql-files
shell> bin/mysqld_safe --user=mysql & # optionally start the server
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


23
Monday, September 19, 16
StarCng  it  up

• Various  methods
- mysqld_safe
- mysqld
- mysql.server
- service mysqld start
-­‐ Windows  Service
• Unix/Linux  -­‐  run  as  a  non-­‐root  account
• Windows  -­‐  admin  rights
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
24
Monday, September 19, 16
ShuXng  it  down

• Manually
- mysqladmin shutdown
- /etc/init.d/mysql stop
- service mysqld stop
- NET STOP MySQL
- Services  Manager
- SHUTDOWN  (5.7)

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


25
Monday, September 19, 16
Talking  to  MySQL

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


26
Monday, September 19, 16
CLI  -­‐  mysql  client
mysql> select count(*) from inventory;
+----------+
• Easy  to  use | count(*) |
+----------+

• Simple  SQL  shell


| 4581 |
+----------+
1 row in set (0.08 sec)
• Server  side  help mysql> ALTER TABLE rental DROP FOREIGN KEY
`fk_rental_inventory`;
• Many  op1ons Query OK, 0 rows affected (0.25 sec)
Records: 0 Duplicates: 0 Warnings: 0
-­‐ Example:  --i-am-a-
mysql> SELECT rental_id from rental order by RAND() LIMIT
dummy 10;
+-----------+
• Has  its  own  commands | rental_id |
+-----------+
| 12539 |
| 8592 |
| 15699 |

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 27


Monday, September 19, 16
Workbench

• GUI
-­‐ SQL  Development
-­‐ Data  Modeling
-­‐ Server  Administra1on
-­‐ Data  Migra1on
-­‐ Performance  Tools  and  Reports
-­‐ Integrated  with  MEB  and  Audit
-­‐ MySQL  U1li1es  

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


28
Monday, September 19, 16
SQL  Editor  
in  Windows

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


29
Monday, September 19, 16
Data  
Modeling  
in  Mac

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


30
Monday, September 19, 16
Performance  Dashboard  in  Linux

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


31
Monday, September 19, 16
Architecture

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


32
Monday, September 19, 16
Architecture

1 • High  Level
2 • Storage  Engines

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


33
Monday, September 19, 16
High  Level  

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


34
Monday, September 19, 16
Architecture

1 • High  Level
2 • Storage  Engines

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


35
Monday, September 19, 16
InnoDB  

• General-­‐purpose  storage  engine


• As  of  5.5,  is  the  default  engine
• Features:
-­‐ ACID  compliant
-­‐ Row  level  locking  with  consistent  reads
-­‐ Foreign  keys  
-­‐ Clustered  primary  key  index
-­‐ FullText  Indexes  (5.6)  &  Geospa1al  data  and  indexes  (5.7)
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
36
Monday, September 19, 16
InnoDB  
(con’t)

• Features  Con1nued:
-­‐ Tablespaces
• file  per  table
-­‐ transportable
-­‐ encrypted
• undo  logs
• general

-­‐ Compressed  Data

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


37
Monday, September 19, 16
Others

• MyISAM
• Memory
• CSV
• Archive
• Blackhole
• 3rd  Party

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


38
Monday, September 19, 16
Log  Files

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


39
Monday, September 19, 16
Error  Log

• --log-error[=file_name]
• Default  loca1on:  host_name.err  in  datadir
• Examples  of  stuff  logged
-­‐ Start  and  stops  &  Cri1cal  errors
-­‐ MyISAM  tables  that  need  to  be  checked  or  repaired
-­‐ some  OS’s  -­‐  stack  trace  if  mysqld  crashes
• (5.7)  log_syslog  to  send  MySQL  error  log  to  syslog
• (5.7)  log_error_verbosity
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
40
Monday, September 19, 16
Slow  Query  Log

• First  line  of  offense  for  tuning  queries


• Why?
-­‐ Performance  usually
• Enable  dynamically  or  with  --slow-query-log
-­‐ Default  file  loca1on:  host_name-slow.log  in  the  datadir
-­‐ Can  also  go  to  a  table
• Mul1ple  op1ons  for  controlling  it
• Aggregate  its  data  with  mysqldumpslow  u1lity
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
41
Monday, September 19, 16
EXPLAIN

• Displays  query  execu1on  plan


• Syntax:
-­‐ Prior  to  5.6:
• EXPLAIN [explain_type] SELECT select_options
-­‐ 5.6:
• EXPLAIN [explain_type] explainable_stmt

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


42
Monday, September 19, 16
EXPLAIN
(con’t)

• Talk  all  by  itself


• 1  row  ==  1  table
• Order  maqers
• EXTENDED  +  SHOW WARNINGS  =  rewriqen  query
• Columns:
-­‐ id,  select_type,  table,  par11ons,  type,  possible_keys,  key,  key_length,  ref,  rows,  
filtered,  Extra

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


43
Monday, September 19, 16
Example  CLI  EXPLAIN

mysql> EXPLAIN EXTENDED SELECT ci.Name,


-> co.Name,
-> cl.IsOfficial
-> FROM City ci
-> INNER JOIN Country co
-> ON ci.CountryCode = co.Code
-> INNER JOIN CountryLanguage cl
-> ON co.Code = cl.CountryCode
-> WHERE cl.Language = 'ENGLISH'
-> LIMIT 100;
+----+-------------+-------+------------+--------+---------------------+-------------+---------+----------------------+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+--------+---------------------+-------------+---------+----------------------+------+----------+-------------+
| 1 | SIMPLE | cl | NULL | ALL | PRIMARY,CountryCode | NULL | NULL | NULL | 984 | 10.00 | Using where |
| 1 | SIMPLE | co | NULL | eq_ref | PRIMARY | PRIMARY | 3 | world.cl.CountryCode | 1 | 100.00 | NULL |
| 1 | SIMPLE | ci | NULL | ref | CountryCode | CountryCode | 3 | world.cl.CountryCode | 1 | 100.00 | NULL |
+----+-------------+-------+------------+--------+---------------------+-------------+---------+----------------------+------+----------+-------------+
3 rows in set, 2 warnings (0.00 sec)

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


44
Monday, September 19, 16
Workbench  Visual  EXPLAIN  -­‐  Mac

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


45
Monday, September 19, 16
mysqldumpslow

• Parses  slow  query  log  and  aggregates  the  data


• Default  -­‐  groups  queries  that  are  similar
-­‐ “abstracts”  out  specific  string  and  number  data  values
• Op1ons  for  sor1ng:
-­‐ t, at  -­‐  sort  by  query  1me  or  average  query  1me
-­‐ l, al  -­‐  sort  by  lock  1me  or  average  lock  1me
-­‐ r, ar  -­‐  sort  by  rows  or  average  rows  sent
-­‐ c  -­‐  sort  by  count
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
46
Monday, September 19, 16
Example  mysqldumpslow  output
Count: 6 Time=0.36s (2s) Lock=0.00s (0s) Rows=1.0 (6), agent[agent]@localhost
SELECT @@version NOT LIKE "S" AND (SELECT COUNT(*) < N FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_SCHEMA != 'S') AND (SELECT COUNT(*) = N FROM INFORMATION_SCHEMA.TABLES WHERE CREATE_OPTIONS LIKE
'S')

Count: 2 Time=0.24s (0s) Lock=0.10s (0s) Rows=1.0 (2), agent[agent]@localhost


SELECT ROUND(SUM(sum_timer_wait)/N) total_wait_time_ms, SUM(count_star) total_statements,
ROUND(MAX(max_timer_wait)/N) max_wait_time_ms, SUM(sum_errors) total_errors, SUM(sum_warnings)
total_warnings, SUM(sum_rows_sent) total_rows_returned, ROUND(SUM(sum_lock_time)/N) total_lock_time_ms
FROM performance_schema.events_statements_summary_by_digest

Count: 100 Time=0.22s (22s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost


CREATE TABLE `t1` (id serial,id0 varchar(N) unique key,intcol1 INT(N) ,intcol2 INT(N) ,intcol3
INT(N) ,intcol4 INT(N) ,intcol5 INT(N) ,charcol1 VARCHAR(N),charcol2 VARCHAR(N),charcol3
VARCHAR(N),charcol4 VARCHAR(N),charcol5 VARCHAR(N),charcol6 VARCHAR(N),charcol7 VARCHAR(N),charcol8
VARCHAR(N),charcol9 VARCHAR(N),charcol10 VARCHAR(N))

Count: 300 Time=0.20s (60s) Lock=0.00s (0s) Rows=0.0 (0), root[root]@localhost


CREATE TABLE `t1` (id serial,id0 varchar(N) unique key,intcol1 INT(N) ,intcol2 INT(N) ,intcol3
INT(N) ,intcol4 INT(N) ,intcol5 INT(N) ,intcol6 INT(N) ,intcol7 INT(N) ,intcol8 INT(N) ,intcol9
INT(N) ,intcol10 INT(N) ,charcol1 VARCHAR(N),charcol2 VARCHAR(N),charcol3 VARCHAR(N),charcol4
VARCHAR(N),charcol5 VARCHAR(N),charcol6 VARCHAR(N),charcol7 VARCHAR(N),charcol8 VARCHAR(N),charcol9
VARCHAR(N),charcol10 VARCHAR(N))

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


47
Monday, September 19, 16
General  Query  Log

• General  Record
• Why:
-­‐ Order  is  important
-­‐ Exact  query  that  came  in
-­‐ minimal  audit  of  what  a  connec1on  did
• Enable  Dynamically  or  with  --general-log
-­‐ Default  loca1on:  host-name.log  in  datadir
• Mul1ple  op1ons  for  controlling  it
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
48
Monday, September 19, 16
Binary  Log

• Logs  database  *change*  events


• Why?
-­‐ Replica1on  or  Data  Recovery
• Enable  with  --log-bin
• A  LOT  of  op1ons
• “Read”  with  mysqlbinlog
• To  disable  binary  logging  for  the  current  session,  use  sql_log_bin

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


49
Monday, September 19, 16
mysqlbinlog

• Display  binary/relay  logs  in  text  format


• Syntax:  mysqlbinlog [options] logfile
• Can  work  with  any  replica1on  format
-­‐ Reading  Row  Based  Replica1on
• --verbose --base64-output=DECODE-ROWS

• Can  backup  binary  logs  to  remote  server


-­‐ Sta1c  or  streaming
• --read-from-remote-server

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


50
Monday, September 19, 16
Example  mysqlbinlog  output
# at 316
#130512 20:22:57 server id 1 end_log_pos 364 CRC32 0xa7a9fe8c !GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '6e521de8-bb62-11e2-836e-821afda5425c:2'/*!*/;
# at 364
#130512 20:22:57 server id 1 end_log_pos 443 CRC32 0xf9bf1aaa !Query! thread_id=3
! exec_time=0!error_code=0
SET TIMESTAMP=1368404577/*!*/;
BEGIN
/*!*/;
# at 443
#130512 20:22:57 server id 1 end_log_pos 542 CRC32 0x1b82a82c !Query! thread_id=3
! exec_time=0!error_code=0
SET TIMESTAMP=1368404577/*!*/;
insert into t1 values (1)
/*!*/;
# at 542
#130512 20:22:57 server id 1 end_log_pos 573 CRC32 0x22965d3b !Xid = 29
COMMIT/*!*/;
# at 573
#130512 20:23:01 server id 1 end_log_pos 621 CRC32 0x89e5d253 !GTID [commit=yes]
SET @@SESSION.GTID_NEXT= '6e521de8-bb62-11e2-836e-821afda5425c:3'/*!*/;

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


51
Monday, September 19, 16
Security

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


52
Monday, September 19, 16
Securing  a  New  InstallaCon  Prior  to  5.7

• Ini1al  user  accounts


-­‐ Superuser  (root)
-­‐ Anonymous  (“”)

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


53
Monday, September 19, 16
User  Account  

• 2  parts
-­‐ username
-­‐ hostname
-­‐ Ex:
• ‘root’@‘localhost’
• ‘’@‘127.0.0.1’
• ‘root’@‘192.168.1.%’
• ‘lig’@’%’

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


54
Monday, September 19, 16
Securing  a  New  InstallaCon  Prior  to  5.7
(con’t)

• Ini1al  accounts
-­‐ Superuser  (root)
-­‐ Anonymous  (“”)
• test  database

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


55
Monday, September 19, 16
Securing  a  New  InstallaCon  Prior  to  5.7
(con’t)

• Ini1al  accounts
-­‐ Superuser  (root)
-­‐ Anonymous  (“”)
• test  database
• Securing  the  easy  way
- mysql_secure_installation

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


56
Monday, September 19, 16
Securing  a  New  InstallaCon  Prior  to  5.7
(con’t)

• Ini1al  accounts
-­‐ Superuser  (root)
-­‐ Anonymous  (“”)
• test  database
• Securing  the  easy  way
- mysql_secure_installation
• Hard way

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


57
Monday, September 19, 16
Securing  a  New  InstallaCon  in  5.7

• Done  during  data  directory  installa1on


• mysqld --initialize  
-­‐ Secure  by  default
• Generate  random  password  for  `root`@`localhost`  account  and  writes  message  with  it
• Password  marked  as  expired

• mysqld --initialize-insecure
-­‐ Empty  password  for  `root`@`localhost`  account
-­‐ Does  *NOT*  mark  password  as  expired

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


58
Monday, September 19, 16
Securing  a  New  InstallaCon  in  5.7  
(con’t)

• Assigning  a  new  `root`@localhost`  password

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘new-password’;

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


59
Monday, September 19, 16
Access  Control

• 2  stages

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


60
Monday, September 19, 16
Access  Control

• 2  stages
-­‐ Stage  1:  Connec1ng
• Who  are  you?
-­‐ host
-­‐ username

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


61
Monday, September 19, 16
User  Accounts

• CREATE  USER

mysql> CREATE USER ‘lig’@‘localhost’ IDENTIFIED BY ‘S3cr3t’;

• ALTER  USER  (5.6)

mysql> ALTER USER ‘lig’@‘localhost’ IDENTIFIED BY ‘new-password’;

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


62
Monday, September 19, 16
Access  Control

• 2  stages
-­‐ Stage  1:  Connec1ng
• Who  are  you?
-­‐ host
-­‐ username

• Prove  it!

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


63
Monday, September 19, 16
Passwords

• Expira1on
-­‐ Manually  (5.6)  or  with  a  Policy  (5.7)
• Hashing
-­‐ Mul1ple  authen1ca1on  plugins  available
• Policy
-­‐ Use  Password  Valida1on  plugin  (validate_password)
• cleartext  supplied  password  checked  against  password  policy
• 3  levels  of  password  checking  which  can  be  modified

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


64
Monday, September 19, 16
Access  Control

• 2  stages
-­‐ Stage  1:  Connec1ng
• Who  are  you?
-­‐ host
-­‐ username

• Prove  it!
-­‐ Stage  2:  Request
• For  each  request
-­‐ What  are  you  doing  and  are  you  allowed  to  do  that?

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


65
Monday, September 19, 16
GRANT

• Defines  privileges  and  account  characteris1cs


• Mul1ple  privileges
-­‐ Ex:  SUPER, CREATE, ALTER, SELECT, INSERT
• Mul1ple  levels
-­‐ Ex:  Global,  Database,  Table,  Column
• Account  characteris1cs
-­‐ Ex:  REQUIRE SSL or  MAX_QUERIES_PER_HOUR

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


66
Monday, September 19, 16
Sample  GRANTS
mysql> SHOW GRANTS;
+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT ALL PRIVILEGES ON `mysql`.* TO 'root'@'localhost' |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
3 rows in set (0.00 sec)

mysql> SHOW GRANTS FOR 'test'@'localhost';


+--------------------------------------------------------+
| Grants for test@localhost |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' |
| GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'localhost' |
+--------------------------------------------------------+
2 rows in set (0.00 sec)

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


67
Monday, September 19, 16
REVOKE

• Removes  the  privileges  GRANTed


-­‐ Does  not  extrapolate
• Does  not  remove  the  user
• If  no  host  is  given
-­‐ %  is  used
-­‐ Again  -­‐  Does  not  extrapolate

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


68
Monday, September 19, 16
REVOKE
mysql> SHOW GRANTS FOR 'test'@'localhost';
+--------------------------------------------------------+
| Grants for test@localhost |
+--------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'localhost' |
| GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'localhost' |
+--------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> REVOKE DELETE ON test.t1 FROM 'test'@'localhost';


ERROR 1147 (42000): There is no such grant defined for user 'test' on host
'localhost' on table 't1'

mysql> REVOKE USAGE ON *.* FROM 'test'@'localhost';


Query OK, 0 rows affected (0.02 sec)

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


69
Monday, September 19, 16
Backups

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


70
Monday, September 19, 16
Backups  Types

1 • Logical
2 • Physical

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


71
Monday, September 19, 16
Logical  Backups

• Saved
-­‐ Logical  structure
-­‐ Content
• Machine  Independent
• Slower
• Server  Up/Warm
• Full  Granularity

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


72
Monday, September 19, 16
mysqldump

• Logical
• Commonly  used
• Editable  text  files
• Very  flexible
• Ques1onable  scalability

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


73
Monday, September 19, 16
mysqlpump

• Logical
• Similar  to  mysqldump
• Parallel  processing  to  speed  up  dump  process
• Dump  user  accounts  with  CREATE USER/GRANT
• Default:  I_S, P_S, ndbinfo  and  SYS  not  included
• Reloading:  faster  secondary  index  crea1on  for  InnoDB

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


74
Monday, September 19, 16
Backup  Types

1 • Logical
2 • Physical

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


75
Monday, September 19, 16
Physical  Backup

• Raw  copies
• Faster  then  logical  (orders  of  magnitude)
• Compact
• File  based  granularity
• Usually  server  is  down  or  locked

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


76
Monday, September 19, 16
Filesystem  Snapshot

• Physical
• OS  Dependent
• Basic  Steps
- FLUSH TABLES WITH READ LOCK
-­‐ Take  the  snapshot
- UNLOCK TABLES
-­‐ Copy  files  from  snapshot

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


77
Monday, September 19, 16
MySQL  Enterprise  Backup

• Official  physical  backup  solu1on


• Mul1-­‐plaborm
• “Hot”  InnoDB  backup
• “Warm”  backup  for  other  storage  engines
• Binlog  and  Relay  log  backup
• Fast  Recovery

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


78
Monday, September 19, 16
MySQL  Enterprise  Backup

• Features:
-­‐ Par1al  and  incremental  backups
-­‐ Streaming,  direct  to  tape  and  single  file  backup
-­‐ Throqling  and  Parallel  backup  opera1ons
-­‐ Compression
-­‐ Encryp1on
-­‐ Valida1on
-­‐ Supports  TDE

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


79
Monday, September 19, 16
Monitoring

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


80
Monday, September 19, 16
SHOW

• MySQL  specific  command


• Commands  for  
-­‐ Metadata
-­‐ Status  informa1on
• Metric  crap-­‐ton

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


81
Monday, September 19, 16
Examples
Metadata

SHOW DATABASES SHOW TRIGGERS SHOW PLUGINS

SHOW CREATE PROCEDURE SHOW ENGINES SHOW VARIABLES

SHOW INDEXES SHOW GRANTS SHOW BINARY LOGS

Status

SHOW SLAVE STATUS SHOW OPEN TABLES SHOW RELAYLOG EVENTS

SHOW ENGINE INNODB SHOW FULL PROCESSLIST SHOW GLOBAL STATUS


STATUS

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


82
Monday, September 19, 16
INFORMATION_SCHEMA

• Mostly  metadata
- PROCESSLIST
- GLOBAL_VARIABLES / GLOBAL_STATUS
- FILES / INNODB_SYS_TABLESPACES / INNODB_SYS_DATAFILES
• But
- INNODB_TRX / INNODB_LOCKS / INNODB_LOCK_WAITS
- INNODB_TEMP_TABLE_INFO

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


83
Monday, September 19, 16
SYS  SCHEMA

• Included  in  5.7.7


-­‐ Installed  by  default  with  --initialize
• Originally  known  as  ps_helper
-­‐ Originally  created  by  Mark  Leith
-­‐ hqp://www.markleith.co.uk/ps_helper
-­‐ Can  work  with  5.6  -­‐  download  from  Github
• hqps://github.com/mysql/mysql-­‐sys

• Easy,  human  readable  access  to  P_S  and  I_S  info  for  typical  use  cases
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
84
Monday, September 19, 16
SYS  SCHEMA

• Pair  views  
-­‐ Ex:  host_summary_by_file_io  and  x$host_summary_by_file_io
• Example  views
-­‐  statements_with_full_table_scans
-­‐  statements_with_runtimes_in_95th_percentile
-­‐  io_by_thread_by_latency
-­‐  memory_by_user_by_current_bytes
-­‐  schema_redundent_indexes
-­‐

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


85
Monday, September 19, 16
PERFORMANCE_SCHEMA

• Monitors  at  a  low  level


• Uses  PERFORMANCE_SCHEMA  storage  engine
• Available
-­‐ Current  events
-­‐ Event  histories  /  Event  summa1ons
• Configura1on  is  dynamic
• Query  using  SQL

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


86
Monday, September 19, 16
PERFORMANCE_SCHEMA
(con’t)

• Using  the  PERFORMANCE_SCHEMA


-­‐ Manual
• Diagnose  Problems  -­‐  hqps://dev.mysql.com/doc/en/performance-­‐schema-­‐examples.html
• Query  Profiling  -­‐  hqps://dev.mysql.com/doc/en/performance-­‐schema-­‐query-­‐profiling.html
-­‐ Blog  posts
• Marc  Alff’s  blog  -­‐  hqp://marcalff.blogspot.com
• Mark  Leith’s  blog  -­‐  hqp://www.markleith.co.uk/
-­‐ Many  Presenta1ons/Webinars

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


87
Monday, September 19, 16
MySQL  Enterprise  Monitor  -­‐  MEM

• Real  1me  monitoring


-­‐ Performance
-­‐ Replica1on
-­‐ Query  analysis
-­‐ InnoDB
-­‐ Backup
-­‐ Disk  and  OS

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


88
Monday, September 19, 16
MEM  -­‐  Dashboard

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


89
Monday, September 19, 16
MEM  -­‐  Query  Analysis

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


90
Monday, September 19, 16
MEM  -­‐  ReplicaCon

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


91
Monday, September 19, 16
Oracle  Enterprise  Manager  for  MySQL

• Monitoring  of  MySQL  servers  in  familiar  OEM  interface


• Real  1me  monitoring
-­‐ Performance
-­‐ Replica1on
-­‐ InnoDB
-­‐ Metric  Collec1on
• Won’t  lie  -­‐  doesn’t  do  everything  MEM  does

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


92
Monday, September 19, 16
OEM  MySQL  -­‐  Performance  Monitoring

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


93
Monday, September 19, 16
OEM  MySQL  -­‐  Performance  Reports

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


94
Monday, September 19, 16
Basic  TroubleshooCng

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


95
Monday, September 19, 16
Step  1

• Define  the  problem


• Must  know  what  is  “normal”,  so  you  know  when  it  is  not  -­‐  and  how  much  
• Be  exact!
• Read  and  understand  the  manual  for  the  area  that  is  problema1c

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


96
Monday, September 19, 16
Step  2

• Collect  the  diagnos1c  data


-­‐ OS  data
-­‐ MySQL  data
• May  need  to  collect  the  diagnos1c  data  during  the  problem
-­‐ Monitoring  
-­‐ Maybe  pt-stalk

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


97
Monday, September 19, 16
Error  Log

• First  place  to  look


• Can  give  history  and  context  to  any  problem.
• Error  message(s)

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


98
Monday, September 19, 16
Server  Crash

• Error  log
-­‐ Stack  trace  and  error  message(s)
• OS  error  log  around  the  crash  1me
• Any  and  all  diagnos1c  data  available
-­‐ MySQL  and  OS  monitoring  data  (graphs  or  raw  data)
-­‐ core  file?
• Any  informa1on  about  what  was  happening  before  and  during  the  crash
-­‐ External  Scripts  running  /  Applica1ons  /  Cronjobs  /  Backups  /  Etc.
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |
99
Monday, September 19, 16
ReplicaCon  Issues

• Error  log
• SHOW MASTER STATUS
• my.cnf  /  my.ini
• SHOW GLOBAL VARIABLES
• SHOW SLAVE STATUS

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


100
Monday, September 19, 16
Performance  Issues

• Error  log  
• OS  data  (Ex:  IO,  CPU,  Memory,  NUMA,  etc.)
• SHOW GLOBAL VARIABLES
• SHOW GLOBAL STATUS
• SHOW FULL PROCESSLIST
• SHOW ENGINE INNODB STATUS
• Informa1on  from  PERFORMANCE_SCHEMA

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


101
Monday, September 19, 16
Query  Performance  Issues

• Error  log
• Slow  Query  Log
• EXPLAIN
• SHOW CREATE TABLE
• SHOW TABLE STATUS
• SHOW INDEXES
• Profile  the  query

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


102
Monday, September 19, 16
QuesCons?

Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |


103
Monday, September 19, 16
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 104
Monday, September 19, 16
Copyright  ©  2016,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 105
Monday, September 19, 16
A  MySQL  DBA  Primer

Ligaya  Turmelle
Principal  Technical  Support  Engineer  -­‐  MySQL
ligaya.turmelle@oracle.com
@lig

Copyright  ©  2016,  ,  Oracle  and/or  its  affiliates.  All  rights  reserved.    | 106
Monday, September 19, 16
Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |

Monday, September 19, 16

You might also like