iloug2015.Mysql.for.oracle.dba.V2

39

Transcript of iloug2015.Mysql.for.oracle.dba.V2

Exploring MySQL Best Practices for DBA`s

About ME Baruch osoveskiy

• Senior Consultant @ brillix

• Linux/UNIX SYSADMIN (from 1999)

• DBA on oracle and MySQL.

• Working with MySQL from 2000.

• blogger in ildba.co.il

History of MySQL• 1979 Founded and developed by David Axmark, Allan Larsson,

and Michael “Monty” Widenius

• Named after Monty's daughter, My

• Sun acquired MySQL AB in Jan 2008 for $1 billion dollars

• Oracle acquired Sun in 2010 for $5.6 billion dollars

• 4 December 2012 David Axmark, Allan Larsson, and Michael “Monty” Widenius announced MariaDB

MySQL Version History

• 3.11.1 First public release

• 3.23 Integrated Berkeley DB supports transactions, abstract Storage Engine

• 4.0 Integration InnoDB

• 4.1 significant improvements, subquery, Unicode, c / s communication protocol

MySQL Version History

• 5.0 stored procedure, view, triggers, query optimizer

• 5.1 NDB, record replication InnoDB plugin default install

• 5.5 Oracle First Version Multi process support,

~300% performance improvement

• 5.6 and 7.4 cluster Current GA Version

• 5.7 Current DEV Version

** Production recommendation is 5.5 and 5.6.

Who uses MySQL?

US Navy carrier flight operations

MySQL Server

Community:

Freely downloadable version open source database. It is available under the GPL license and is supported by a huge and active community of open source developers.

Enterprise: Free for 30 day evaluation

Paid subscription includes support and the following:• MySQL Enterprise Backup (LIVE BACKUP tool)• MySQL Enterprise Monitor (“GRID CONTROL” like tool)• MySQL Query Analyzer • MySQL Workbench (Free)

MySQL Architecture vs ORACLE Architecture is it user or schema ?

Data Base Instance (pmon,smon…) Server Instance (mysqld)

User User

TableSpace TableSpace

DataFile OS File - .ibd MYI. MYD. Frm

Data BaseSchemaUser

Storage Engines why so many ?

Storage Engines why so many ?

• handles, and retrieves information from a table

• Each Storage Engine have its Advantage and disadvantage

• There is no perfect Storage Engine

• The recommended/default Storage Engine is InnoDB

Storage Engines why so many ?

Attribute MyISAM HEAP (Memory)

InnoDB/*XtraDB ARCHIVE (Compressed storage)

Transaction NO NO YES No

Lock Granularity Table Table Row row

Storage File pre table

In memory TableSpace / file per table

Files

Isolation level None None All None

Referential Integrity (FK)

NO NO Yes No

Cached Data NO YES YES No

Advantage and disadvantage

* mariadb do not have INNODB

Storage Engines why so many ?

Attribute MyISAM HEAP (Memory)

InnoDB/*XtraDB ARCHIVE (Compressed storage)

Transaction NO NO YES No

Lock Granularity Table Table Row row

Storage File pre table

In memory TableSpace / file per table

Files

Isolation level None None All None

Referential Integrity (FK)

NO NO Yes No

Cached Data NO YES YES No

Advantage and disadvantage

* mariadb do not have INNODB

Storage Engines why so many ?

Attribute MyISAM HEAP (Memory)

InnoDB/*XtraDB ARCHIVE (Compressed storage)

Transaction NO NO YES No

Lock Granularity Table Table Row row

Storage File pre table

In memory TableSpace / file per table

Files

Isolation level None None All None

Referential Integrity (FK)

NO NO Yes No

Cached Data NO YES YES No

Advantage and disadvantage

* mariadb do not have INNODB

Storage Engines why so many ?

Attribute MyISAM HEAP (Memory)

InnoDB/*XtraDB ARCHIVE (Compressed storage)

Transaction NO NO YES No

Lock Granularity Table Table Row row

Storage File pre table

In memory TableSpace / file per table

Files

Isolation level None None All None

Referential Integrity (FK)

NO NO Yes No

Cached Data NO YES YES No

Advantage and disadvantage

* mariadb do not have INNODB

Storage Engines why so many ?

And more

• Percona XtraDB enhanced version of the InnoDB storage engine.

• RocksDB (LevelDB) is an persistent key-value store for fast storage.

• OQGRAPH (for MariaDB) Open Query GRAPH engine

MySQL configuration - my.cnf,my.ini where is my spfile?

MySQL configuration - my.cnf,my.ini where is my spfile?

• Configuration file name my.cnf

• Configuration file Location:

“/etc/my.cnf”, “/etc/mysql/my.cnf “ in linux,

“C:\ProgramData\MySQL\MySQL Server 5.6\my.ini” in windows

• mysqld_safe --defaults-file=/etc/my.cnf &

• Can run Multiple MySQL Instances on one machine

need different port

Storage and log types what is this file? can I delete it ?

• Error Log: log-error (Oracle alert log)

• Binary Log: log-bin (Oracle Archive logs)• Slow Query Log: log-slow-queries,slow-query-time,log-queries-

not-using-indexes• General Log : MySQL session debug log

• .frm : MySQL represents each table by an .frm table format file, stores table definition in the database directory.

• .MYD : This is the extension of the Data files for MyISAMtables.

• .MYI :This is the extension of the Index files for MyISAMtables.

Storage and log types what is this file? can I delete it ?

• TABLE_NAME.ibd :If you specify innodb_file_per_table option to my.cnf, InnoDB stores each table in its own .ibd

• ibdata1 : Shared tablespace / data file for InnoDB tables when innodb_file_per_table option is not specified in my.cnf.

• ib_logfile0 , ib_logfile1 : InnoDB log files. important for performance and recovery.

Storage and log types what is this file? can I delete it ?

The Data Dictionarywhere is v$ and DBA_ ?

The Data Dictionarywhere is v$ and DBA_

• INFORMATION_SCHEMA – INFORMATION about the instance ,table, columns,views,privileges

• PERFORMANCE_SCHEMA – INFORMATION about instance performance ,top sql,top table IO

• Show command – get system variables information, oracle :show parameters

show process list select * from v$sessions ;

show tables select table_name from user_tables;

show variables like ‘%size%’ show parameters size

SELECT TABLE_SCHEMA, SUM((DATA_LENGTH + INDEX_LENGTH) / (1024 * 1024)) AS SIZE_MB FROM INFORMATION_SCHEMA.TABLESGROUP BY TABLE_SCHEMA ORDER BY SIZE_MB DESC

SELECT ROUTINE_TYPE, ROUTINE_NAME FROM

INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA='dbname';

SELECT EVENT_ID, EVENT_NAME, TIMER_WAIT

FROM PERFORMANCE_SCHEMA.events_waits_history

WHERE THREAD_ID = 13

ORDER BY EVENT_ID;

The Data Dictionarywhere is v$ and DBA_

MySQL User account

• MySQL user account is based on user name and hostname For example :select user,host from mysql.user;

+--------+---------------------+| user | host |+--------+---------------------+| baruch| % || root | 127.0.0.1 || root | 192.168.10.40 || root | ::1 || root | localhost |+--------+--------------------+

The User [email protected] can not connect from 192.168.10.40 And the user baruch@% as connect from all clients

Tips for Developer

Tips for Developer what the F***, no Sequences ?

• No Sequences - use AUTO_INCREMENT

id INT NOT NULL AUTO_INCREMENT

- Must be tied to a [table].[column]

- Only one per table

- No system wide capability

- LAST_INSERT_ID()

- No get next capability

Tips for Developer Character Set/Collation

• Every character column has a column character set and a column collation

CREATE TABLE t1(col1 CHAR(10) CHARACTER SET utf8, COLLATE utf8_unicode_ci,col2 TEXT) CHARACTER SET latin1 COLLATE

latin1_bin;

Tips for Developer

• Escaped Reserved Words are allowed

CREATE TABLE `workers` (...);

CREATE TABLE “workers” (...); (depend on sql_mode)

• Space and other special characters allowed

CREATE TABLE `My Table Name` (...);

(depend on OS for file creation )

Tips for Developer can I use PL/SQL ?

• No PL/SQL - Stored Procedures with limited Functionality NO - Types, Overloading, named parameters, pinning, packages Built-in Packages

• MySQL Provide procedures and functions

Tips for Developerinserts and dual

• no need of dual

• Multi value insert INSERT INTO example

VALUES (100, 'Name 1', 'Value 1', 'Other 1'),

(101, 'Name 2', 'Value 2', 'Other 2');

• INSERT ON DUPLICATE KEY

INSERT INTO table (a,b,c) VALUES (1,2,3)

ON DUPLICATE KEY UPDATE c=c+1;

• Store IP Address as UNSIGNED INT

SELECT INET_ATON('10.0.5.9');

167773449

select 1 select 1 from dual

Tips for Developer SQL_MODE

• Emulate Oracle Behavior

SET SQL_MODE=TRADITIONAL,ORACLE

Example : Use concat in mysql :

SELECT CONCAT('A','B');

SET sql_mode='PIPES_AS_CONCAT';

SELECT 'A'||'B';

http://dev.mysql.com/doc/refman/5.6/en/server-sql-mode.html

MySQL Cluster

MySQL Replication – Master Slave(n)

MySQL and NoSQL

NoSQL API

Q & A

Thanks for attending!

Baruch osoveskiy [email protected]