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
1 • Founda1on
2 • Installa1on
4 • Architecture
5 • Log
Files
8 • Monitoring
9 • Basic
Troubleshoo1ng
1 • Basics
2 • Commercial
• 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
1 • Basics
2 • Commercial
1 • Files
2 • Installa1on
• Windows
- INSTALLDIR\my.ini
- INSTALLDIR\my.cnf
• Linux
&
Mac
- /etc/my.cnf
- /etc/mysql/my.cnf
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
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
1 • Files
2 • Installa1on
• 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)
• GUI
-‐ SQL
Development
-‐ Data
Modeling
-‐ Server
Administra1on
-‐ Data
Migra1on
-‐ Performance
Tools
and
Reports
-‐ Integrated
with
MEB
and
Audit
-‐ MySQL
U1li1es
1 • High
Level
2 • Storage
Engines
1 • High
Level
2 • Storage
Engines
• Features
Con1nued:
-‐ Tablespaces
• file
per
table
-‐ transportable
-‐ encrypted
• undo
logs
• general
• MyISAM
• Memory
• CSV
• Archive
• Blackhole
• 3rd
Party
• --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
• 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
• 2
parts
-‐ username
-‐ hostname
-‐ Ex:
• ‘root’@‘localhost’
• ‘’@‘127.0.0.1’
• ‘root’@‘192.168.1.%’
• ‘lig’@’%’
• Ini1al
accounts
-‐ Superuser
(root)
-‐ Anonymous
(“”)
• test
database
• Ini1al
accounts
-‐ Superuser
(root)
-‐ Anonymous
(“”)
• test
database
• Securing
the
easy
way
- mysql_secure_installation
• Ini1al
accounts
-‐ Superuser
(root)
-‐ Anonymous
(“”)
• test
database
• Securing
the
easy
way
- mysql_secure_installation
• Hard way
• mysqld --initialize-insecure
-‐ Empty
password
for
`root`@`localhost`
account
-‐ Does
*NOT*
mark
password
as
expired
• 2 stages
• 2
stages
-‐ Stage
1:
Connec1ng
• Who
are
you?
-‐ host
-‐ username
• CREATE USER
• 2
stages
-‐ Stage
1:
Connec1ng
• Who
are
you?
-‐ host
-‐ username
• Prove it!
• 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
• 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?
1 • Logical
2 • Physical
• Saved
-‐ Logical
structure
-‐ Content
• Machine
Independent
• Slower
• Server
Up/Warm
• Full
Granularity
• Logical
• Commonly
used
• Editable
text
files
• Very
flexible
• Ques1onable
scalability
• 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
1 • Logical
2 • Physical
• Raw
copies
• Faster
then
logical
(orders
of
magnitude)
• Compact
• File
based
granularity
• Usually
server
is
down
or
locked
• Physical
• OS
Dependent
• Basic
Steps
- FLUSH TABLES WITH READ LOCK
-‐ Take
the
snapshot
- UNLOCK TABLES
-‐ Copy
files
from
snapshot
• Features:
-‐ Par1al
and
incremental
backups
-‐ Streaming,
direct
to
tape
and
single
file
backup
-‐ Throqling
and
Parallel
backup
opera1ons
-‐ Compression
-‐ Encryp1on
-‐ Valida1on
-‐ Supports
TDE
Status
• 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
• 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
-‐
• 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
• 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
• Error
log
• Slow
Query
Log
• EXPLAIN
• SHOW CREATE TABLE
• SHOW TABLE STATUS
• SHOW INDEXES
• Profile
the
query
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.
|