SlideShare a Scribd company logo
1 of 75
Download to read offline
Title




       MySQL Best Practices
                for DBAs and Developers
                                          Volume 1
                                               OTN LAD Tour
                                               South America
                                                  2010.10


Ronald Bradford
http://ronaldbradford.com
      MySQL Best Practices for DBAs and Developers - 2010.10
Objectives




     Identify poor development practices
     Recommended best practices
     MySQL development tips and tricks
     Standard & expected RDBMS practices




MySQL Best Practices for DBAs and Developers - 2010.10
Agenda




     Essential MySQL configuration
     Improving your SQL
     MySQL user security
     Schema optimizations
     Instrumentation
     Monitoring


MySQL Best Practices for DBAs and Developers - 2010.10
MySQL Configuration



MySQL Best Practices for DBAs and Developers - 2010.10
Configuration Best Practices




     Server SQL Mode
     "Modes define what SQL syntax MySQL should
     support and what kind of data validation checks
     it should perform."




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



MySQL Best Practices for DBAs and Developers - 2010.10
Configuration Best Practices




sql_mode = "STRICT_ALL_TABLES,
      NO_ZERO_DATE,                                                    Recommended
                                                                       Configuration
      NO_ZERO_IN_DATE,
      NO_ENGINE_SUBSTITUTION";
mysql> SET GLOBAL
sql_mode="STRICT_ALL_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION";



# my.cnf
sql_mode="STRICT_ALL_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION"




MySQL Best Practices for DBAs and Developers - 2010.10
SQL Mode Examples




mysql> INSERT INTO sample_data (i) VALUES (-1), (9000);
ERROR 1264 (22003): Out of range value for column 'i' at row 1
                                                                 ✔

mysql> INSERT INTO sample_data (i) VALUES (-1), (9000);
mysql> SELECT * FROM sample_data;
+-----+
                                                                 ✘
| i   |
+-----+
|   0 |
| 255 |
+-----+




MySQL Best Practices for DBAs and Developers - 2010.10
SQL Mode Examples




mysql> INSERT INTO sample_date (d) VALUES ('2010-02-31');
ERROR 1292 (22007): Incorrect date value: '2010-02-31' for
column 'd' at row 1
                                                             ✔

mysql> INSERT INTO sample_date (d) VALUES ('2010-02-31');
mysql> SELECT * FROM sample_date;
+------------+
                                                             ✘
| d          |
+------------+
| 0000-00-00 |
+------------+




MySQL Best Practices for DBAs and Developers - 2010.10
Configuration Best Practices




storage_engine="InnoDB"

                                                         Recommended
                                                         Configuration




mysql> SET GLOBAL storage_engine="innodb";



# my.cnf
default-storage-engine=innodb




MySQL Best Practices for DBAs and Developers - 2010.10
Configuration Best Practices




mysql> INSERT INTO sample_int VALUES (1),(2);
mysql> INSERT INTO sample_int VALUES (3),(2);
ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'
                                                            ✔
mysql> SELECT * FROM sample_int;
+---+
| i |
+---+
| 1 |
| 2 |
+---+


mysql> INSERT INTO sample_int VALUES (1),(2);
mysql> INSERT INTO sample_int VALUES (3),(2);
ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY'
mysql> SELECT * FROM sample_int;
                                                            ✘
+---+
| i |
+---+
| 1 |
| 2 |
| 3 |
+---+



MySQL Best Practices for DBAs and Developers - 2010.10
Configuration Best Practices




     Use a transactional storage engine
          e.g. InnoDB
          Other options exist                            Changing to InnoDB
                                                            in MySQL 5.5
     MySQL default is MyISAM
          non-transactional
          table level locking
          No auto recovery

MySQL Best Practices for DBAs and Developers - 2010.10
Configuration Best Practices




     MySQL Idiosyncrasies that BITE presentation
          Data Integrity
          Storage Engine defaults
          Referential Integrity



                                                         http://rb42.com/idiosyncrasies



MySQL Best Practices for DBAs and Developers - 2010.10
Security



MySQL Best Practices for DBAs and Developers - 2010.10
MySQL Physical Security




     Default is woeful
     Minimum
          $ mysql_secure_installation
     Recommended
          Operating System
          Permissions & Privileges


MySQL Best Practices for DBAs and Developers - 2010.10
Operating System Security




     Defaults are not secure
     Never run as 'root' user
     Separate Data/Binary Logs/Logs/
     Configuration/Backups
          Individual directory permissions

                                                         • Minimize security risk
                                                         • Better auditability

MySQL Best Practices for DBAs and Developers - 2010.10
MySQL Installation Best Practice




     Best Practice


/mysql                                                   /etc/my.cnf
   /etc                                                  /etc/profile.d/mysql.sh
   /data                                                 /etc/init.d/mysqld
   /binlog
   /log
   /mysql-version


MySQL Best Practices for DBAs and Developers - 2010.10
MySQL Installation Security




     Software installed by root
$   chown      -R root:root /mysql
$   chown      -R mysql:mysql /mysql/{data,log,binlog,etc}
$   chmod      700 /mysql/{data,binlog}
$   chmod      750 /mysql/{etc,log}




MySQL Best Practices for DBAs and Developers - 2010.10
Application User Security




Best Practice
CREATE USER appuser@localhost IDENTIFIED BY 'sakila';
GRANT SELECT,INSERT,UPDATE,DELETE ON schema.* TO
                                                         ✔
appuser@localhost;



Normal Practice
CREATE USER superman@'%';
GRANT ALL ON *.* TO superman@'%';
                                                         ✘

MySQL Best Practices for DBAs and Developers - 2010.10
Why not use GRANT ALL




     GRANT ALL ON *.* TO user@’%’
          *.* gives you access to all tables in all schemas
          @’%’ give you access from any external location
          ALL gives you
          ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY
          TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, FILE,
          INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION
          CLIENT, REPLICATION SLAVE, SELECT, SHOW DATABASES, SHOW VIEW,
          SHUTDOWN, SUPER, TRIGGER, UPDATE, USAGE
       See MySQL Idiosyncrasies that BITE presentation -- http://rb42.com/idiosyncrasies

MySQL Best Practices for DBAs and Developers - 2010.10
Why SUPER is bad?




     SUPER
          Bypasses read_only
          Bypasses init_connect
          Can Disable binary logging
          Change configuration dynamically
          No reserved connection


MySQL Best Practices for DBAs and Developers - 2010.10
Application User Security Best Practices




     Application Viewer (Read Only Access)
       SELECT
     Application User (Read/Write Access)
       INSERT, UPDATE, DELETE, SELECT
     Application DBA (Schema Access Only)
       CREATE, DROP, CREATE ROUTINE,
       SELECT, INSERT, UPDATE, DELETE
                                                         • Track Data Security
                                                         • Separation of responsibilities
MySQL Best Practices for DBAs and Developers - 2010.10
SQL



MySQL Best Practices for DBAs and Developers - 2010.10
Development Best Practices




     Comment your SQL
     Format your SQL
     Future proof your SQL
     Log your SQL
     Analyze your SQL
     Always use transactions



MySQL Best Practices for DBAs and Developers - 2010.10
SQL Commenting




     Identify queries by code function
     Identify OLTP / Batch / Cache queries


     SELECT /* XXX123 */ ...
     UPDATE /* YYY999 */ ...
     SELECT /* Batch */... can identify code function
                        • DBA/SA
                                                         and purpose quickly


MySQL Best Practices for DBAs and Developers - 2010.10
SQL Commenting (2)




   26 Query SELECT /* 5m cache */ .....
    26 Query SELECT /* ViewPost */ t.*, tt.*, tr.object_id FROM
wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id =
t.term_id INNER JOIN wp_term_relationships AS tr ON
tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN
('category', 'post_tag') AND tr.object_id IN (2849, 2842, 2836,
2824, 2812, 2680, 2813, 2800, 2770, 2784) ORDER BY t.name ASC
   26 Query SELECT /* batch */ key, value FROM usermeta WHERE user_id
= 2




MySQL Best Practices for DBAs and Developers - 2010.10
SQL Formatting




     Create single line queries
          Don't embed newlines
     Enables per line analysis by CLI tools




                                                         • DBA/SA can use simple CLI tools
                                                         including grep,awk,cut etc for SQL analysis



MySQL Best Practices for DBAs and Developers - 2010.10
SQL Formatting (2)




   26 Query SELECT FOUND_ROWS()
   26 Query SELECT post_id,start,end,allday,rpt,IF(end>='2010-06-04
 00:00:00',1,0) AS active
      FROM wp_ec3_schedule
      WHERE post_id IN (2849,2842,2836,2824,2812,2680,2770,2784)
      ORDER BY start
   26 Query SELECT * FROM wp_users WHERE user_login = 'ronald'
   26 Query SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER
JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN
wp_term_relationships AS tr ON tr.term_taxonomy_id =
tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag')
AND tr.object_id IN (2849, 2842, 2836, 2824, 2812, 2680, 2813, 2800,
2770, 2784) ORDER BY t.name ASC
   26 Query SELECT meta_key, meta_value FROM wp_usermeta WHERE
user_id = 2




MySQL Best Practices for DBAs and Developers - 2010.10
Future proofing your SQL




     Specify INSERT columns
          INSERT INTO table(a,b,c) VALUES(...)
mysql> INSERT INTO example VALUES (10,10,'A');

mysql> ALTER TABLE example ADD d DATE;

mysql> INSERT INTO example VALUES (10,10,'A');
ERROR 1136 (21S01): Column count doesn't match value
count at row 1



                                                         • Reduce likelihood of runtime errors
                                                         when structural changes to objects


MySQL Best Practices for DBAs and Developers - 2010.10
Future proofing your SQL




          Always use column aliases in joins
            SELECT a.col1, b.col2 ...
mysql> SELECT id, name, val FROM parent p, child c WHERE p.id =
c.parent_id;

mysql> alter table child add name varchar(10);

mysql> SELECT id, name, val FROM parent p, child c WHERE p.id =
c.parent_id;
ERROR 1052 (23000): Column 'name' in field list is ambiguous




MySQL Best Practices for DBAs and Developers - 2010.10
Future proofing your SQL




     SELECT * is generally bad
          What columns are actually used in code
          TEXT/BLOB can cause extra disk I/O
          New columns can change performance




MySQL Best Practices for DBAs and Developers - 2010.10
Avoid Fancy Constructs




     DELAYED
     IGNORE
     LOW PRIORITY
     REPLACE


                                                         • Changes ACID and statement precedence
                                                         • May have additional performance overhead


MySQL Best Practices for DBAs and Developers - 2010.10
Use Deterministic Functions




     Use '2010-06-21' instead of CURDATE()
          Same for NOW()
     Don't Use ORDER BY RAND()


     Leverage Query Cache (if enabled)
                                                         •Leverages database caching when enabled
                                                         • Allows testing via parameterization


MySQL Best Practices for DBAs and Developers - 2010.10
SQL Analysis



MySQL Best Practices for DBAs and Developers - 2010.10
General Query Log




     Logs all SQL Statements
     Turn on for all development environments
     Aggregate and Email results to developer
     Works best in single user environment


                                                         • Developers are seeing SQL in operation
                                                         • Enables access to SQL to analyze

MySQL Best Practices for DBAs and Developers - 2010.10
General Query Log


                                                                               Never enable in
                                                                                Production

# my.cnf
general_log = ON
general_log_file = /mysql/log/general.log
log_output = FILE,TABLE




mysql> SET GLOBAL general_log=OFF;
mysql> SET GLOBAL general_log=ON;
mysql> SELECT event_time,argument FROM mysql.general_log;
+---------------------+---------------------------------------------------+
| event_time          | argument                                          |
+---------------------+---------------------------------------------------+
| 2010-10-11 21:48:05 | select * from test1                               |
| 2010-10-11 21:48:30 | SELECT event_time,argument FROM mysql.general_log |
+---------------------+---------------------------------------------------+




                                        http://dev.mysql.com/doc/refman/5.1/en/query_log.html



MySQL Best Practices for DBAs and Developers - 2010.10
Leveraging General Query Log




     For single user development environment
          In SQL Session
     mysql> SELECT 'Function X Start';

          In Application
               Run Function/Process
          In SQL Session
     mysql> SELECT 'Function X End';


MySQL Best Practices for DBAs and Developers - 2010.10
General Query Log Output




$ tail /mysql/log/general.log

101011    21:58:00          2   Query   SELECT   'Function X Start'
101011    21:58:09          2   Query   SELECT   * from sample_int
101011    21:58:41          2   Query   SELECT   * from example
101011    21:58:47          2   Query   SELECT   'Function X End'




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



MySQL Best Practices for DBAs and Developers - 2010.10
SQL Analysis




     Bulk trending analysis
          Volume of SQL statements
     Query Execution Plan (QEP)
          Online v Batch/Cache SQL via commenting


                                                         • Identify bottlenecks ASAP without load
                                                         • Iterative Design feedback

MySQL Best Practices for DBAs and Developers - 2010.10
Know your SQL



MySQL Best Practices for DBAs and Developers - 2010.10
Common Coding Errors




     Remove duplicate code




                                                         • Less code to maintain
                                                         • Remove chance of human errors


MySQL Best Practices for DBAs and Developers - 2010.10
Defining your database connection


                                                               The WRONG way

$ cd public_html
$ grep "mysql*_connect" * */* */*/*
db-disp.php:$cid = mysql_connect("localhost", "museum", "******") or die ('I
cannot connect to the database because: ' . mysql_error());
test.php:$cid = mysql_connect("localhost", "museum", "******");
PMCollection/connection.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser",
"$sqlpass");
PMCollection/connection_live.php: $dbcnx = mysql_connect("$sqlhost",
"$sqluser", "$sqlpass");
PMCollection/connection_local.php: $dbcnx = mysql_connect("$sqlhost",
"$sqluser", "$sqlpass");
PMEcards/connection.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser",
"$sqlpass");
core/connection.php:      $dbcnx = mysql_connect("$sqlhost", "$sqluser",
"$sqlpass");
discussion_admin/db_fns.php:    $cid = mysql_connect("localhost", "museum",
"******");
discussion_admin/header.php:// $cid = mysql_connect("localhost", "museum",
"******");
discussion_admin/inc_title.php:     //$cid = mysql_connect("localhost",
"museum", "******");
discussion_admin/stats.php: //$cid = mysql_connect("localhost", "museum",




MySQL Best Practices for DBAs and Developers - 2010.10
Database connection example


                                                                  The RIGHT way

class database {

   function getConnection($type, $message) {

       try {
         $con = mysqli_connect($cp->host,$cp->user,$cp->passwd,$cp->database);
         if (!$con) {
          $message = new message ("fatal", "Unable to obtain a '$type' ...
          return;
         }
         mysqli_query($con, "SET NAMES 'utf8'");
       } catch (Exception $e) {
          $message = new message ("fatal", "Unable to obtain a '$type' ...
          debug($e->getMessage());
       }

       return $con;
   }




MySQL Best Practices for DBAs and Developers - 2010.10
Database Connections




     Open and close database connections only
     when necessary




                                                         • Reduce unnecessary database load
                                                         • Increases page serve volume
                                                         • Increases true DB throughput


MySQL Best Practices for DBAs and Developers - 2010.10
Database Connections Initialization


                                                         The WRONG way

  $ cat header.php
  ...
  $con = getConnection();
  ...

  if($this_user->user_row["status"]!='ws' &&
      in_array($this_page->getValue(),$page)){
      header("Location: /permission.php");
      exit();
  }
  ...
  if () {
      header("Location: abc.php");
      exit();
  }
  ...
  if () {
      header("Location: xyz.php");
      exit();
  }
  ...




MySQL Best Practices for DBAs and Developers - 2010.10
Common SQL Errors




     Remove redundant SQL
          Use general query log
          You may be surprised!




MySQL Best Practices for DBAs and Developers - 2010.10
Common Coding Errors - Repeating Queries


                                                                  The WRONG way



     SQL for one page load
          8 unwanted full table scans *BUG*
          Removed gave 20x faster page load
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist` WHERE (ArtistID = 196 )
5   Query        SELECT      * FROM `artist` WHERE (ArtistID = 2188 )
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist`
5   Query        SELECT      * FROM `artist`             Not cached (too big)
MySQL Best Practices for DBAs and Developers - 2010.10   If cached, two queries
Common Coding Errors - Row at a time (RAT) Processing


                                                                          The WRONG way


SELECT   option_name,   option_value FROM wp_options WHERE autoload = 'yes'
SELECT   option_value   FROM wp_options WHERE option_name = 'aiosp_title_format' LIMIT   1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_show_only_even' LIMIT   1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_num_months' LIMIT 1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_day_length' LIMIT 1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_hide_event_box' LIMIT   1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_advanced' LIMIT 1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_navigation' LIMIT 1
SELECT   option_value   FROM wp_options WHERE option_name = 'ec3_disable_popups' LIMIT   1
SELECT   option_value   FROM wp_options WHERE option_name = 'sidebars_widgets' LIMIT 1




MySQL Best Practices for DBAs and Developers - 2010.10
RAT v CAT Processing




Row (RAT) Processing
SELECT       *   FROM    activities_theme                WHERE   theme_parent_id=0
                                                                                      ✘
SELECT       *   FROM    activities_theme                WHERE   theme_parent_id=1
SELECT       *   FROM    activities_theme                WHERE   theme_parent_id=2
SELECT       *   FROM    activities_theme                WHERE   theme_parent_id=11
SELECT       *   FROM    activities_theme                WHERE   theme_parent_id=16



Chunk (CAT) Processing
SELECT *
FROM   activities_theme
                                                                                      ✔
WHERE theme_parent_id in                         (0,1,2,11,16)




MySQL Best Practices for DBAs and Developers - 2010.10
Common Coding Errors - Boundary Conditions




     The following SQL executed 6,000 times in
     5 minute analysis period            The WRONG way


SELECT pages_id, pages_livestats_code, pages_title,
       pages_parent, pages_exhibid, pages_theme,
       pages_accession_num
FROM pages WHERE pages_id = 0



     0 is an invalid pages_id


MySQL Best Practices for DBAs and Developers - 2010.10
In a highly tuned system
  the greatest time in a
    query is network
        overhead

MySQL Best Practices for DBAs and Developers - 2010.10
Schema Design



MySQL Best Practices for DBAs and Developers - 2010.10
Design Best Practices




     Optimal Data Types
          Saving Disk Space
     Naming Standards




MySQL Best Practices for DBAs and Developers - 2010.10
About MySQL Data Types




     Numeric Data Types
          Oracle has 1
          MySQL has 9


          TINYINT,SMALLINT,MEDIUMINT,INT,
          BIGINT,FLOAT,DOUBLE,DECIMAL,BIT



MySQL Best Practices for DBAs and Developers - 2010.10
Optimal Auto Increment Primary Key




     Don't use BIGINT AUTO_INCREMENT
     Use INT UNSIGNED AUTO_INCREMENT
     BIGINT is 8 bytes
     INT is 4 Bytes
     INT UNSIGNED stores 4.3 billion values

                                                         • Can reduce index space by 50+%
                                                         • Better memory usage, less I/O

MySQL Best Practices for DBAs and Developers - 2010.10
Horror Stories


                                                         INT(1) is not what it
                                                              looks like


     INT(1)
          This is not 1 byte, it's 4 bytes
          (1) is only for client display only


          Client with 10+ flags using INT(1)
          40 bytes reduced to 10 bytes
               or 2 bytes using bit operators
MySQL Best Practices for DBAs and Developers - 2010.10
Dates




     MySQL supports
          DATE, DATETIME, TIMESTAMP, YEAR
     TIMESTAMP for Epoch values
          TIMESTAMP is 4 bytes
          DATETIME is 8 bytes
          Supports DEFAULT CURRENT_TIMESTAMP
     Neither store milliseconds
MySQL Best Practices for DBAs and Developers - 2010.10
The beauty of ENUM




     Values Check Constraint
     Ideal for static codes
     Compact - i.e. 1 byte for 'True', 'False'
     Human readable values
     5.1 Non blocking ALTER



MySQL Best Practices for DBAs and Developers - 2010.10
TRUE/FALSE Datatype Examples




CREATE TABLE enums (
   flag1 CHAR(1) NOT NULL COMMENT 'T or F, Y or N',
   flag2 TINYINT NOT NULL COMMENT '0 or 1',
   flag3 BIT NOT NULL COMMENT 'True or False',
   flag4 ENUM ('True','False') NOT NULL,
   flag5 VARCHAR(5) NOT NULL
);

INSERT INTO enums(flag4) VALUES ('True', 'False');
SELECT flag4 FROM enums;




MySQL Best Practices for DBAs and Developers - 2010.10
Schema Management




     Always have current schema.sql
     Use Patch/Revert SQL for upgrades
     See http://schemasync.org




                                                         • Reproducibility
                                                         • Upgrade/Downgrade path

MySQL Best Practices for DBAs and Developers - 2010.10
Testing



MySQL Best Practices for DBAs and Developers - 2010.10
Testing is not about
     what works; testing is
     about breaking your
            software

MySQL Best Practices for DBAs and Developers - 2010.10
Resilience




     What is your backup strategy?
     What is your recovery strategy?
     How long does it take?
     Have you actually tested it end to end?

                     Take the survey
http://ronaldbradford.com/blog/checked-your-mysql-recovery-process-recently-2010-02-15/



MySQL Best Practices for DBAs and Developers - 2010.10
Instrumentation



MySQL Best Practices for DBAs and Developers - 2010.10
Application Instrumentation




     Creating one primary abstract DB call
     Enable logging of ALL SQL statements
     Enable embedded HTML output
          Total Execution Time/Count
          Individual SQL Execution Time/SQL

                                                         • Enable runtime analysis via browser
                                                         • No additional tools needed to gather

MySQL Best Practices for DBAs and Developers - 2010.10
Sharding 101




                                                         •SQL Statements Example

                                                          Joomla
                                                65
MySQL Best Practices for DBAs and Developers - 2010.10
Sharding 101




                                                         •SQL Statements Example




                                                         Cold Fusion
                                                66
MySQL Best Practices for DBAs and Developers - 2010.10
Application Instrumentation Benefits




     End to End Timing
     Component Timing
          (i.e. a series of SQL)
     Observe as desired
     Intelligent Activation
          e.g. Page Load exceeds x ms


MySQL Best Practices for DBAs and Developers - 2010.10
Monitoring



MySQL Best Practices for DBAs and Developers - 2010.10
If you don't have
        monitoring in
        place, make it
      your top priority
MySQL Best Practices for DBAs and Developers - 2010.10
Monitoring




     Monitoring
     Alerting
     Dashboard
     Public Status

           Successful Scalability
        http://ronaldbradford.com/blog/successful-mysql-scalability-presentation-2010-09-17/



MySQL Best Practices for DBAs and Developers - 2010.10
Number 1 problem!




  Don't change a
 setting without
evidence to prove/
   disprove the
MySQL Best Practices for DBAs and Developers - 2010.10
Bad MySQL Configuration




     [sort|join|read|read_rnd] _buffer_size
          Defaults are 128K - 256K
          Settings of 1M, 2M,16M, 128M
     Pre allocated per thread buffer
          Larger buffer is slower to create > 256K
          Wastes valuable process memory


MySQL Best Practices for DBAs and Developers - 2010.10
Where is the bottleneck?




     Is the database the problem?
     Front End Performance
          The website will always be too slow
          Identify the true components
          End to End time
               Database may be only a small portion


MySQL Best Practices for DBAs and Developers - 2010.10
Questions?



MySQL Best Practices for DBAs and Developers - 2010.10
RonaldBradford.com


MySQL Best Practices for DBAs and Developers - 2010.10

More Related Content

What's hot

10x Performance Improvements
10x Performance Improvements10x Performance Improvements
10x Performance ImprovementsRonald Bradford
 
MySQL Backup and Recovery Essentials
MySQL Backup and Recovery EssentialsMySQL Backup and Recovery Essentials
MySQL Backup and Recovery EssentialsRonald Bradford
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best PracticesOlivier DASINI
 
My two cents about Mysql backup
My two cents about Mysql backupMy two cents about Mysql backup
My two cents about Mysql backupAndrejs Vorobjovs
 
10x Performance Improvements - A Case Study
10x Performance Improvements - A Case Study10x Performance Improvements - A Case Study
10x Performance Improvements - A Case StudyRonald Bradford
 
What's New MySQL 8.0?
What's New MySQL 8.0?What's New MySQL 8.0?
What's New MySQL 8.0?OracleMySQL
 
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
 
Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Ronald Bradford
 
MySQL For Oracle Developers
MySQL For Oracle DevelopersMySQL For Oracle Developers
MySQL For Oracle DevelopersRonald Bradford
 
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 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 
My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2Morgan Tocker
 
Lessons Learned Managing Large AWS Environments
Lessons Learned Managing Large AWS EnvironmentsLessons Learned Managing Large AWS Environments
Lessons Learned Managing Large AWS EnvironmentsRonald Bradford
 
Tx lf propercareandfeedmysql
Tx lf propercareandfeedmysqlTx lf propercareandfeedmysql
Tx lf propercareandfeedmysqlDave Stokes
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAsMark Leith
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep diveMark Leith
 
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 8.0.22 - New Features Summary
MySQL 8.0.22 - New Features SummaryMySQL 8.0.22 - New Features Summary
MySQL 8.0.22 - New Features SummaryOlivier DASINI
 
MySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeMySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeAbel Flórez
 
[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama
[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama
[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke KajiyamaInsight Technology, Inc.
 

What's hot (20)

10x Performance Improvements
10x Performance Improvements10x Performance Improvements
10x Performance Improvements
 
MySQL Backup and Recovery Essentials
MySQL Backup and Recovery EssentialsMySQL Backup and Recovery Essentials
MySQL Backup and Recovery Essentials
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best Practices
 
My two cents about Mysql backup
My two cents about Mysql backupMy two cents about Mysql backup
My two cents about Mysql backup
 
10x Performance Improvements - A Case Study
10x Performance Improvements - A Case Study10x Performance Improvements - A Case Study
10x Performance Improvements - A Case Study
 
What's New MySQL 8.0?
What's New MySQL 8.0?What's New MySQL 8.0?
What's New MySQL 8.0?
 
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
 
Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1
 
MySQL For Oracle Developers
MySQL For Oracle DevelopersMySQL For Oracle Developers
MySQL For Oracle Developers
 
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 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2
 
Lessons Learned Managing Large AWS Environments
Lessons Learned Managing Large AWS EnvironmentsLessons Learned Managing Large AWS Environments
Lessons Learned Managing Large AWS Environments
 
Tx lf propercareandfeedmysql
Tx lf propercareandfeedmysqlTx lf propercareandfeedmysql
Tx lf propercareandfeedmysql
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
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 8.0.22 - New Features Summary
MySQL 8.0.22 - New Features SummaryMySQL 8.0.22 - New Features Summary
MySQL 8.0.22 - New Features Summary
 
MySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeMySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgrade
 
[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama
[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama
[B34] MySQL最新ロードマップ – MySQL 5.7とその先へ by Ryusuke Kajiyama
 

Viewers also liked

Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应zhaolinjnu
 
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 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMario Beck
 
Multi Source Replication With MySQL 5.7 @ Verisure
Multi Source Replication With MySQL 5.7 @ VerisureMulti Source Replication With MySQL 5.7 @ Verisure
Multi Source Replication With MySQL 5.7 @ VerisureKenny Gryp
 
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 Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server DefaultsMorgan Tocker
 
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 High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Divehastexo
 
A New Architecture for Group Replication in Data Grid
A New Architecture for Group Replication in Data GridA New Architecture for Group Replication in Data Grid
A New Architecture for Group Replication in Data GridEditor IJCATR
 
Lessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting ReplicationLessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting ReplicationSveta Smirnova
 
MySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group ReplicationMySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group ReplicationFrederic Descamps
 
Why MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackWhy MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackSveta Smirnova
 
Эффективная отладка репликации MySQL
Эффективная отладка репликации MySQLЭффективная отладка репликации MySQL
Эффективная отладка репликации MySQLSveta Smirnova
 
MySQL - checklist для новичка в Highload
MySQL - checklist для новичка в HighloadMySQL - checklist для новичка в Highload
MySQL - checklist для новичка в HighloadSveta Smirnova
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!Boris Hristov
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group ReplicationManish Kumar
 
Mysql参数-GDB
Mysql参数-GDBMysql参数-GDB
Mysql参数-GDBzhaolinjnu
 

Viewers also liked (20)

Mysql展示功能与源码对应
Mysql展示功能与源码对应Mysql展示功能与源码对应
Mysql展示功能与源码对应
 
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 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDB
 
Multi Source Replication With MySQL 5.7 @ Verisure
Multi Source Replication With MySQL 5.7 @ VerisureMulti Source Replication With MySQL 5.7 @ Verisure
Multi Source Replication With MySQL 5.7 @ Verisure
 
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 Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server Defaults
 
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 High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Dive
 
A New Architecture for Group Replication in Data Grid
A New Architecture for Group Replication in Data GridA New Architecture for Group Replication in Data Grid
A New Architecture for Group Replication in Data Grid
 
Lessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting ReplicationLessons Learned: Troubleshooting Replication
Lessons Learned: Troubleshooting Replication
 
Requirements the Last Bottleneck
Requirements the Last BottleneckRequirements the Last Bottleneck
Requirements the Last Bottleneck
 
MySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group ReplicationMySQL InnoDB Cluster - Group Replication
MySQL InnoDB Cluster - Group Replication
 
Redis介绍
Redis介绍Redis介绍
Redis介绍
 
Why MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it BackWhy MySQL Replication Fails, and How to Get it Back
Why MySQL Replication Fails, and How to Get it Back
 
MySQL aio
MySQL aioMySQL aio
MySQL aio
 
Эффективная отладка репликации MySQL
Эффективная отладка репликации MySQLЭффективная отладка репликации MySQL
Эффективная отладка репликации MySQL
 
MySQL - checklist для новичка в Highload
MySQL - checklist для новичка в HighloadMySQL - checklist для новичка в Highload
MySQL - checklist для новичка в Highload
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
 
MySQL Group Replication
MySQL Group ReplicationMySQL Group Replication
MySQL Group Replication
 
Mysql参数-GDB
Mysql参数-GDBMysql参数-GDB
Mysql参数-GDB
 

Similar to MySQL Best Practices for DBAs and Developers - 2010.10

Upgrade from MySQL 5.7 to MySQL 8.0
Upgrade from MySQL 5.7 to MySQL 8.0Upgrade from MySQL 5.7 to MySQL 8.0
Upgrade from MySQL 5.7 to MySQL 8.0Olivier DASINI
 
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenOSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenNETWAYS
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksJaime Crespo
 
NoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONNoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONMario Beck
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise MonitorTed Wennmark
 
My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012sqlhjalp
 
Tutorial MySQL com Java
Tutorial MySQL com JavaTutorial MySQL com Java
Tutorial MySQL com JavaMySQL Brasil
 
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...SpanishPASSVC
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...GeneXus
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMoshe Kaplan
 
20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharingIvan Ma
 
My sql performance tuning course
My sql performance tuning courseMy sql performance tuning course
My sql performance tuning courseAlberto Centanni
 
My sql 56_roadmap_april2012
My sql 56_roadmap_april2012My sql 56_roadmap_april2012
My sql 56_roadmap_april2012sqlhjalp
 

Similar to MySQL Best Practices for DBAs and Developers - 2010.10 (20)

Upgrade from MySQL 5.7 to MySQL 8.0
Upgrade from MySQL 5.7 to MySQL 8.0Upgrade from MySQL 5.7 to MySQL 8.0
Upgrade from MySQL 5.7 to MySQL 8.0
 
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert VanderkelenOSMC 2008 | Monitoring MySQL by Geert Vanderkelen
OSMC 2008 | Monitoring MySQL by Geert Vanderkelen
 
My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
NoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSONNoSQL and MySQL: News about JSON
NoSQL and MySQL: News about JSON
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
MySQL Enterprise Monitor
MySQL Enterprise MonitorMySQL Enterprise Monitor
MySQL Enterprise Monitor
 
My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012
 
Tutorial MySQL com Java
Tutorial MySQL com JavaTutorial MySQL com Java
Tutorial MySQL com Java
 
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
24 HOP edición Español -Diferentes técnicas de administración de logins y usu...
 
MySQL Tech Tour Nov, 2013
MySQL Tech Tour Nov, 2013MySQL Tech Tour Nov, 2013
MySQL Tech Tour Nov, 2013
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
MySQL Quick Dive
MySQL Quick DiveMySQL Quick Dive
MySQL Quick Dive
 
MySQL crash course by moshe kaplan
MySQL crash course by moshe kaplanMySQL crash course by moshe kaplan
MySQL crash course by moshe kaplan
 
MariaDB training
MariaDB trainingMariaDB training
MariaDB training
 
20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing20190817 coscup-oracle my sql innodb cluster sharing
20190817 coscup-oracle my sql innodb cluster sharing
 
Curso de MySQL 5.7
Curso de MySQL 5.7Curso de MySQL 5.7
Curso de MySQL 5.7
 
My sql performance tuning course
My sql performance tuning courseMy sql performance tuning course
My sql performance tuning course
 
My sql 56_roadmap_april2012
My sql 56_roadmap_april2012My sql 56_roadmap_april2012
My sql 56_roadmap_april2012
 

More from Ronald Bradford

My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNRonald Bradford
 
Successful MySQL Scalability
Successful MySQL ScalabilitySuccessful MySQL Scalability
Successful MySQL ScalabilityRonald Bradford
 
MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07Ronald Bradford
 
Capturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLCapturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLRonald Bradford
 
MySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That BiteMySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That BiteRonald Bradford
 
LIFTOFF - MySQLCamp for the Oracle DBA
LIFTOFF - MySQLCamp for the Oracle DBALIFTOFF - MySQLCamp for the Oracle DBA
LIFTOFF - MySQLCamp for the Oracle DBARonald Bradford
 
IGNITION - MySQLCamp for the Oracle DBA
IGNITION - MySQLCamp for the Oracle DBAIGNITION - MySQLCamp for the Oracle DBA
IGNITION - MySQLCamp for the Oracle DBARonald Bradford
 
Dolphins Now And Beyond - FOSDEM 2010
Dolphins Now And Beyond - FOSDEM 2010Dolphins Now And Beyond - FOSDEM 2010
Dolphins Now And Beyond - FOSDEM 2010Ronald Bradford
 
Drizzle - Status, Principles and Ecosystem
Drizzle - Status, Principles and EcosystemDrizzle - Status, Principles and Ecosystem
Drizzle - Status, Principles and EcosystemRonald Bradford
 
MySQL for the Oracle DBA - Object Management
MySQL for the Oracle DBA - Object ManagementMySQL for the Oracle DBA - Object Management
MySQL for the Oracle DBA - Object ManagementRonald Bradford
 
Know Your Competitor - Oracle 10g Express Edition
Know Your Competitor - Oracle 10g Express EditionKnow Your Competitor - Oracle 10g Express Edition
Know Your Competitor - Oracle 10g Express EditionRonald Bradford
 
The Ideal Performance Architecture
The Ideal Performance ArchitectureThe Ideal Performance Architecture
The Ideal Performance ArchitectureRonald Bradford
 
Getting started with MySQL on Amazon Web Services
Getting started with MySQL on Amazon Web ServicesGetting started with MySQL on Amazon Web Services
Getting started with MySQL on Amazon Web ServicesRonald Bradford
 
Best Practices in Migrating to MySQL - Part 1
Best Practices in Migrating to MySQL - Part 1Best Practices in Migrating to MySQL - Part 1
Best Practices in Migrating to MySQL - Part 1Ronald Bradford
 
Extending The My Sql Data Landscape
Extending The My Sql Data LandscapeExtending The My Sql Data Landscape
Extending The My Sql Data LandscapeRonald Bradford
 

More from Ronald Bradford (17)

My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
 
Successful MySQL Scalability
Successful MySQL ScalabilitySuccessful MySQL Scalability
Successful MySQL Scalability
 
MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07MySQL Idiosyncrasies That Bite 2010.07
MySQL Idiosyncrasies That Bite 2010.07
 
Capturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQLCapturing, Analyzing and Optimizing MySQL
Capturing, Analyzing and Optimizing MySQL
 
MySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That BiteMySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That Bite
 
LIFTOFF - MySQLCamp for the Oracle DBA
LIFTOFF - MySQLCamp for the Oracle DBALIFTOFF - MySQLCamp for the Oracle DBA
LIFTOFF - MySQLCamp for the Oracle DBA
 
IGNITION - MySQLCamp for the Oracle DBA
IGNITION - MySQLCamp for the Oracle DBAIGNITION - MySQLCamp for the Oracle DBA
IGNITION - MySQLCamp for the Oracle DBA
 
Dolphins Now And Beyond - FOSDEM 2010
Dolphins Now And Beyond - FOSDEM 2010Dolphins Now And Beyond - FOSDEM 2010
Dolphins Now And Beyond - FOSDEM 2010
 
Drizzle - Status, Principles and Ecosystem
Drizzle - Status, Principles and EcosystemDrizzle - Status, Principles and Ecosystem
Drizzle - Status, Principles and Ecosystem
 
SQL v No SQL
SQL v No SQLSQL v No SQL
SQL v No SQL
 
MySQL for the Oracle DBA - Object Management
MySQL for the Oracle DBA - Object ManagementMySQL for the Oracle DBA - Object Management
MySQL for the Oracle DBA - Object Management
 
Know Your Competitor - Oracle 10g Express Edition
Know Your Competitor - Oracle 10g Express EditionKnow Your Competitor - Oracle 10g Express Edition
Know Your Competitor - Oracle 10g Express Edition
 
The Ideal Performance Architecture
The Ideal Performance ArchitectureThe Ideal Performance Architecture
The Ideal Performance Architecture
 
Getting started with MySQL on Amazon Web Services
Getting started with MySQL on Amazon Web ServicesGetting started with MySQL on Amazon Web Services
Getting started with MySQL on Amazon Web Services
 
Best Practices in Migrating to MySQL - Part 1
Best Practices in Migrating to MySQL - Part 1Best Practices in Migrating to MySQL - Part 1
Best Practices in Migrating to MySQL - Part 1
 
Extending The My Sql Data Landscape
Extending The My Sql Data LandscapeExtending The My Sql Data Landscape
Extending The My Sql Data Landscape
 
Best Design Practices A
Best Design Practices ABest Design Practices A
Best Design Practices A
 

MySQL Best Practices for DBAs and Developers - 2010.10

  • 1. Title MySQL Best Practices for DBAs and Developers Volume 1 OTN LAD Tour South America 2010.10 Ronald Bradford http://ronaldbradford.com MySQL Best Practices for DBAs and Developers - 2010.10
  • 2. Objectives Identify poor development practices Recommended best practices MySQL development tips and tricks Standard & expected RDBMS practices MySQL Best Practices for DBAs and Developers - 2010.10
  • 3. Agenda Essential MySQL configuration Improving your SQL MySQL user security Schema optimizations Instrumentation Monitoring MySQL Best Practices for DBAs and Developers - 2010.10
  • 4. MySQL Configuration MySQL Best Practices for DBAs and Developers - 2010.10
  • 5. Configuration Best Practices Server SQL Mode "Modes define what SQL syntax MySQL should support and what kind of data validation checks it should perform." http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html MySQL Best Practices for DBAs and Developers - 2010.10
  • 6. Configuration Best Practices sql_mode = "STRICT_ALL_TABLES, NO_ZERO_DATE, Recommended Configuration NO_ZERO_IN_DATE, NO_ENGINE_SUBSTITUTION"; mysql> SET GLOBAL sql_mode="STRICT_ALL_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION"; # my.cnf sql_mode="STRICT_ALL_TABLES,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION" MySQL Best Practices for DBAs and Developers - 2010.10
  • 7. SQL Mode Examples mysql> INSERT INTO sample_data (i) VALUES (-1), (9000); ERROR 1264 (22003): Out of range value for column 'i' at row 1 ✔ mysql> INSERT INTO sample_data (i) VALUES (-1), (9000); mysql> SELECT * FROM sample_data; +-----+ ✘ | i | +-----+ | 0 | | 255 | +-----+ MySQL Best Practices for DBAs and Developers - 2010.10
  • 8. SQL Mode Examples mysql> INSERT INTO sample_date (d) VALUES ('2010-02-31'); ERROR 1292 (22007): Incorrect date value: '2010-02-31' for column 'd' at row 1 ✔ mysql> INSERT INTO sample_date (d) VALUES ('2010-02-31'); mysql> SELECT * FROM sample_date; +------------+ ✘ | d | +------------+ | 0000-00-00 | +------------+ MySQL Best Practices for DBAs and Developers - 2010.10
  • 9. Configuration Best Practices storage_engine="InnoDB" Recommended Configuration mysql> SET GLOBAL storage_engine="innodb"; # my.cnf default-storage-engine=innodb MySQL Best Practices for DBAs and Developers - 2010.10
  • 10. Configuration Best Practices mysql> INSERT INTO sample_int VALUES (1),(2); mysql> INSERT INTO sample_int VALUES (3),(2); ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY' ✔ mysql> SELECT * FROM sample_int; +---+ | i | +---+ | 1 | | 2 | +---+ mysql> INSERT INTO sample_int VALUES (1),(2); mysql> INSERT INTO sample_int VALUES (3),(2); ERROR 1062 (23000): Duplicate entry '2' for key 'PRIMARY' mysql> SELECT * FROM sample_int; ✘ +---+ | i | +---+ | 1 | | 2 | | 3 | +---+ MySQL Best Practices for DBAs and Developers - 2010.10
  • 11. Configuration Best Practices Use a transactional storage engine e.g. InnoDB Other options exist Changing to InnoDB in MySQL 5.5 MySQL default is MyISAM non-transactional table level locking No auto recovery MySQL Best Practices for DBAs and Developers - 2010.10
  • 12. Configuration Best Practices MySQL Idiosyncrasies that BITE presentation Data Integrity Storage Engine defaults Referential Integrity http://rb42.com/idiosyncrasies MySQL Best Practices for DBAs and Developers - 2010.10
  • 13. Security MySQL Best Practices for DBAs and Developers - 2010.10
  • 14. MySQL Physical Security Default is woeful Minimum $ mysql_secure_installation Recommended Operating System Permissions & Privileges MySQL Best Practices for DBAs and Developers - 2010.10
  • 15. Operating System Security Defaults are not secure Never run as 'root' user Separate Data/Binary Logs/Logs/ Configuration/Backups Individual directory permissions • Minimize security risk • Better auditability MySQL Best Practices for DBAs and Developers - 2010.10
  • 16. MySQL Installation Best Practice Best Practice /mysql /etc/my.cnf /etc /etc/profile.d/mysql.sh /data /etc/init.d/mysqld /binlog /log /mysql-version MySQL Best Practices for DBAs and Developers - 2010.10
  • 17. MySQL Installation Security Software installed by root $ chown -R root:root /mysql $ chown -R mysql:mysql /mysql/{data,log,binlog,etc} $ chmod 700 /mysql/{data,binlog} $ chmod 750 /mysql/{etc,log} MySQL Best Practices for DBAs and Developers - 2010.10
  • 18. Application User Security Best Practice CREATE USER appuser@localhost IDENTIFIED BY 'sakila'; GRANT SELECT,INSERT,UPDATE,DELETE ON schema.* TO ✔ appuser@localhost; Normal Practice CREATE USER superman@'%'; GRANT ALL ON *.* TO superman@'%'; ✘ MySQL Best Practices for DBAs and Developers - 2010.10
  • 19. Why not use GRANT ALL GRANT ALL ON *.* TO user@’%’ *.* gives you access to all tables in all schemas @’%’ give you access from any external location ALL gives you ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE USER, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, FILE, INDEX, INSERT, LOCK TABLES, PROCESS, REFERENCES, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SELECT, SHOW DATABASES, SHOW VIEW, SHUTDOWN, SUPER, TRIGGER, UPDATE, USAGE See MySQL Idiosyncrasies that BITE presentation -- http://rb42.com/idiosyncrasies MySQL Best Practices for DBAs and Developers - 2010.10
  • 20. Why SUPER is bad? SUPER Bypasses read_only Bypasses init_connect Can Disable binary logging Change configuration dynamically No reserved connection MySQL Best Practices for DBAs and Developers - 2010.10
  • 21. Application User Security Best Practices Application Viewer (Read Only Access) SELECT Application User (Read/Write Access) INSERT, UPDATE, DELETE, SELECT Application DBA (Schema Access Only) CREATE, DROP, CREATE ROUTINE, SELECT, INSERT, UPDATE, DELETE • Track Data Security • Separation of responsibilities MySQL Best Practices for DBAs and Developers - 2010.10
  • 22. SQL MySQL Best Practices for DBAs and Developers - 2010.10
  • 23. Development Best Practices Comment your SQL Format your SQL Future proof your SQL Log your SQL Analyze your SQL Always use transactions MySQL Best Practices for DBAs and Developers - 2010.10
  • 24. SQL Commenting Identify queries by code function Identify OLTP / Batch / Cache queries SELECT /* XXX123 */ ... UPDATE /* YYY999 */ ... SELECT /* Batch */... can identify code function • DBA/SA and purpose quickly MySQL Best Practices for DBAs and Developers - 2010.10
  • 25. SQL Commenting (2) 26 Query SELECT /* 5m cache */ ..... 26 Query SELECT /* ViewPost */ t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (2849, 2842, 2836, 2824, 2812, 2680, 2813, 2800, 2770, 2784) ORDER BY t.name ASC 26 Query SELECT /* batch */ key, value FROM usermeta WHERE user_id = 2 MySQL Best Practices for DBAs and Developers - 2010.10
  • 26. SQL Formatting Create single line queries Don't embed newlines Enables per line analysis by CLI tools • DBA/SA can use simple CLI tools including grep,awk,cut etc for SQL analysis MySQL Best Practices for DBAs and Developers - 2010.10
  • 27. SQL Formatting (2) 26 Query SELECT FOUND_ROWS() 26 Query SELECT post_id,start,end,allday,rpt,IF(end>='2010-06-04 00:00:00',1,0) AS active FROM wp_ec3_schedule WHERE post_id IN (2849,2842,2836,2824,2812,2680,2770,2784) ORDER BY start 26 Query SELECT * FROM wp_users WHERE user_login = 'ronald' 26 Query SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category', 'post_tag') AND tr.object_id IN (2849, 2842, 2836, 2824, 2812, 2680, 2813, 2800, 2770, 2784) ORDER BY t.name ASC 26 Query SELECT meta_key, meta_value FROM wp_usermeta WHERE user_id = 2 MySQL Best Practices for DBAs and Developers - 2010.10
  • 28. Future proofing your SQL Specify INSERT columns INSERT INTO table(a,b,c) VALUES(...) mysql> INSERT INTO example VALUES (10,10,'A'); mysql> ALTER TABLE example ADD d DATE; mysql> INSERT INTO example VALUES (10,10,'A'); ERROR 1136 (21S01): Column count doesn't match value count at row 1 • Reduce likelihood of runtime errors when structural changes to objects MySQL Best Practices for DBAs and Developers - 2010.10
  • 29. Future proofing your SQL Always use column aliases in joins SELECT a.col1, b.col2 ... mysql> SELECT id, name, val FROM parent p, child c WHERE p.id = c.parent_id; mysql> alter table child add name varchar(10); mysql> SELECT id, name, val FROM parent p, child c WHERE p.id = c.parent_id; ERROR 1052 (23000): Column 'name' in field list is ambiguous MySQL Best Practices for DBAs and Developers - 2010.10
  • 30. Future proofing your SQL SELECT * is generally bad What columns are actually used in code TEXT/BLOB can cause extra disk I/O New columns can change performance MySQL Best Practices for DBAs and Developers - 2010.10
  • 31. Avoid Fancy Constructs DELAYED IGNORE LOW PRIORITY REPLACE • Changes ACID and statement precedence • May have additional performance overhead MySQL Best Practices for DBAs and Developers - 2010.10
  • 32. Use Deterministic Functions Use '2010-06-21' instead of CURDATE() Same for NOW() Don't Use ORDER BY RAND() Leverage Query Cache (if enabled) •Leverages database caching when enabled • Allows testing via parameterization MySQL Best Practices for DBAs and Developers - 2010.10
  • 33. SQL Analysis MySQL Best Practices for DBAs and Developers - 2010.10
  • 34. General Query Log Logs all SQL Statements Turn on for all development environments Aggregate and Email results to developer Works best in single user environment • Developers are seeing SQL in operation • Enables access to SQL to analyze MySQL Best Practices for DBAs and Developers - 2010.10
  • 35. General Query Log Never enable in Production # my.cnf general_log = ON general_log_file = /mysql/log/general.log log_output = FILE,TABLE mysql> SET GLOBAL general_log=OFF; mysql> SET GLOBAL general_log=ON; mysql> SELECT event_time,argument FROM mysql.general_log; +---------------------+---------------------------------------------------+ | event_time | argument | +---------------------+---------------------------------------------------+ | 2010-10-11 21:48:05 | select * from test1 | | 2010-10-11 21:48:30 | SELECT event_time,argument FROM mysql.general_log | +---------------------+---------------------------------------------------+ http://dev.mysql.com/doc/refman/5.1/en/query_log.html MySQL Best Practices for DBAs and Developers - 2010.10
  • 36. Leveraging General Query Log For single user development environment In SQL Session mysql> SELECT 'Function X Start'; In Application Run Function/Process In SQL Session mysql> SELECT 'Function X End'; MySQL Best Practices for DBAs and Developers - 2010.10
  • 37. General Query Log Output $ tail /mysql/log/general.log 101011 21:58:00 2 Query SELECT 'Function X Start' 101011 21:58:09 2 Query SELECT * from sample_int 101011 21:58:41 2 Query SELECT * from example 101011 21:58:47 2 Query SELECT 'Function X End' http://dev.mysql.com/doc/refman/5.1/en/server-sql-mode.html MySQL Best Practices for DBAs and Developers - 2010.10
  • 38. SQL Analysis Bulk trending analysis Volume of SQL statements Query Execution Plan (QEP) Online v Batch/Cache SQL via commenting • Identify bottlenecks ASAP without load • Iterative Design feedback MySQL Best Practices for DBAs and Developers - 2010.10
  • 39. Know your SQL MySQL Best Practices for DBAs and Developers - 2010.10
  • 40. Common Coding Errors Remove duplicate code • Less code to maintain • Remove chance of human errors MySQL Best Practices for DBAs and Developers - 2010.10
  • 41. Defining your database connection The WRONG way $ cd public_html $ grep "mysql*_connect" * */* */*/* db-disp.php:$cid = mysql_connect("localhost", "museum", "******") or die ('I cannot connect to the database because: ' . mysql_error()); test.php:$cid = mysql_connect("localhost", "museum", "******"); PMCollection/connection.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser", "$sqlpass"); PMCollection/connection_live.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser", "$sqlpass"); PMCollection/connection_local.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser", "$sqlpass"); PMEcards/connection.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser", "$sqlpass"); core/connection.php: $dbcnx = mysql_connect("$sqlhost", "$sqluser", "$sqlpass"); discussion_admin/db_fns.php: $cid = mysql_connect("localhost", "museum", "******"); discussion_admin/header.php:// $cid = mysql_connect("localhost", "museum", "******"); discussion_admin/inc_title.php: //$cid = mysql_connect("localhost", "museum", "******"); discussion_admin/stats.php: //$cid = mysql_connect("localhost", "museum", MySQL Best Practices for DBAs and Developers - 2010.10
  • 42. Database connection example The RIGHT way class database { function getConnection($type, $message) { try { $con = mysqli_connect($cp->host,$cp->user,$cp->passwd,$cp->database); if (!$con) { $message = new message ("fatal", "Unable to obtain a '$type' ... return; } mysqli_query($con, "SET NAMES 'utf8'"); } catch (Exception $e) { $message = new message ("fatal", "Unable to obtain a '$type' ... debug($e->getMessage()); } return $con; } MySQL Best Practices for DBAs and Developers - 2010.10
  • 43. Database Connections Open and close database connections only when necessary • Reduce unnecessary database load • Increases page serve volume • Increases true DB throughput MySQL Best Practices for DBAs and Developers - 2010.10
  • 44. Database Connections Initialization The WRONG way $ cat header.php ... $con = getConnection(); ... if($this_user->user_row["status"]!='ws' && in_array($this_page->getValue(),$page)){ header("Location: /permission.php"); exit(); } ... if () { header("Location: abc.php"); exit(); } ... if () { header("Location: xyz.php"); exit(); } ... MySQL Best Practices for DBAs and Developers - 2010.10
  • 45. Common SQL Errors Remove redundant SQL Use general query log You may be surprised! MySQL Best Practices for DBAs and Developers - 2010.10
  • 46. Common Coding Errors - Repeating Queries The WRONG way SQL for one page load 8 unwanted full table scans *BUG* Removed gave 20x faster page load 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` WHERE (ArtistID = 196 ) 5 Query SELECT * FROM `artist` WHERE (ArtistID = 2188 ) 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` 5 Query SELECT * FROM `artist` Not cached (too big) MySQL Best Practices for DBAs and Developers - 2010.10 If cached, two queries
  • 47. Common Coding Errors - Row at a time (RAT) Processing The WRONG way SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes' SELECT option_value FROM wp_options WHERE option_name = 'aiosp_title_format' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_show_only_even' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_num_months' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_day_length' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_hide_event_box' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_advanced' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_navigation' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'ec3_disable_popups' LIMIT 1 SELECT option_value FROM wp_options WHERE option_name = 'sidebars_widgets' LIMIT 1 MySQL Best Practices for DBAs and Developers - 2010.10
  • 48. RAT v CAT Processing Row (RAT) Processing SELECT * FROM activities_theme WHERE theme_parent_id=0 ✘ SELECT * FROM activities_theme WHERE theme_parent_id=1 SELECT * FROM activities_theme WHERE theme_parent_id=2 SELECT * FROM activities_theme WHERE theme_parent_id=11 SELECT * FROM activities_theme WHERE theme_parent_id=16 Chunk (CAT) Processing SELECT * FROM activities_theme ✔ WHERE theme_parent_id in (0,1,2,11,16) MySQL Best Practices for DBAs and Developers - 2010.10
  • 49. Common Coding Errors - Boundary Conditions The following SQL executed 6,000 times in 5 minute analysis period The WRONG way SELECT pages_id, pages_livestats_code, pages_title, pages_parent, pages_exhibid, pages_theme, pages_accession_num FROM pages WHERE pages_id = 0 0 is an invalid pages_id MySQL Best Practices for DBAs and Developers - 2010.10
  • 50. In a highly tuned system the greatest time in a query is network overhead MySQL Best Practices for DBAs and Developers - 2010.10
  • 51. Schema Design MySQL Best Practices for DBAs and Developers - 2010.10
  • 52. Design Best Practices Optimal Data Types Saving Disk Space Naming Standards MySQL Best Practices for DBAs and Developers - 2010.10
  • 53. About MySQL Data Types Numeric Data Types Oracle has 1 MySQL has 9 TINYINT,SMALLINT,MEDIUMINT,INT, BIGINT,FLOAT,DOUBLE,DECIMAL,BIT MySQL Best Practices for DBAs and Developers - 2010.10
  • 54. Optimal Auto Increment Primary Key Don't use BIGINT AUTO_INCREMENT Use INT UNSIGNED AUTO_INCREMENT BIGINT is 8 bytes INT is 4 Bytes INT UNSIGNED stores 4.3 billion values • Can reduce index space by 50+% • Better memory usage, less I/O MySQL Best Practices for DBAs and Developers - 2010.10
  • 55. Horror Stories INT(1) is not what it looks like INT(1) This is not 1 byte, it's 4 bytes (1) is only for client display only Client with 10+ flags using INT(1) 40 bytes reduced to 10 bytes or 2 bytes using bit operators MySQL Best Practices for DBAs and Developers - 2010.10
  • 56. Dates MySQL supports DATE, DATETIME, TIMESTAMP, YEAR TIMESTAMP for Epoch values TIMESTAMP is 4 bytes DATETIME is 8 bytes Supports DEFAULT CURRENT_TIMESTAMP Neither store milliseconds MySQL Best Practices for DBAs and Developers - 2010.10
  • 57. The beauty of ENUM Values Check Constraint Ideal for static codes Compact - i.e. 1 byte for 'True', 'False' Human readable values 5.1 Non blocking ALTER MySQL Best Practices for DBAs and Developers - 2010.10
  • 58. TRUE/FALSE Datatype Examples CREATE TABLE enums ( flag1 CHAR(1) NOT NULL COMMENT 'T or F, Y or N', flag2 TINYINT NOT NULL COMMENT '0 or 1', flag3 BIT NOT NULL COMMENT 'True or False', flag4 ENUM ('True','False') NOT NULL, flag5 VARCHAR(5) NOT NULL ); INSERT INTO enums(flag4) VALUES ('True', 'False'); SELECT flag4 FROM enums; MySQL Best Practices for DBAs and Developers - 2010.10
  • 59. Schema Management Always have current schema.sql Use Patch/Revert SQL for upgrades See http://schemasync.org • Reproducibility • Upgrade/Downgrade path MySQL Best Practices for DBAs and Developers - 2010.10
  • 60. Testing MySQL Best Practices for DBAs and Developers - 2010.10
  • 61. Testing is not about what works; testing is about breaking your software MySQL Best Practices for DBAs and Developers - 2010.10
  • 62. Resilience What is your backup strategy? What is your recovery strategy? How long does it take? Have you actually tested it end to end? Take the survey http://ronaldbradford.com/blog/checked-your-mysql-recovery-process-recently-2010-02-15/ MySQL Best Practices for DBAs and Developers - 2010.10
  • 63. Instrumentation MySQL Best Practices for DBAs and Developers - 2010.10
  • 64. Application Instrumentation Creating one primary abstract DB call Enable logging of ALL SQL statements Enable embedded HTML output Total Execution Time/Count Individual SQL Execution Time/SQL • Enable runtime analysis via browser • No additional tools needed to gather MySQL Best Practices for DBAs and Developers - 2010.10
  • 65. Sharding 101 •SQL Statements Example Joomla 65 MySQL Best Practices for DBAs and Developers - 2010.10
  • 66. Sharding 101 •SQL Statements Example Cold Fusion 66 MySQL Best Practices for DBAs and Developers - 2010.10
  • 67. Application Instrumentation Benefits End to End Timing Component Timing (i.e. a series of SQL) Observe as desired Intelligent Activation e.g. Page Load exceeds x ms MySQL Best Practices for DBAs and Developers - 2010.10
  • 68. Monitoring MySQL Best Practices for DBAs and Developers - 2010.10
  • 69. If you don't have monitoring in place, make it your top priority MySQL Best Practices for DBAs and Developers - 2010.10
  • 70. Monitoring Monitoring Alerting Dashboard Public Status Successful Scalability http://ronaldbradford.com/blog/successful-mysql-scalability-presentation-2010-09-17/ MySQL Best Practices for DBAs and Developers - 2010.10
  • 71. Number 1 problem! Don't change a setting without evidence to prove/ disprove the MySQL Best Practices for DBAs and Developers - 2010.10
  • 72. Bad MySQL Configuration [sort|join|read|read_rnd] _buffer_size Defaults are 128K - 256K Settings of 1M, 2M,16M, 128M Pre allocated per thread buffer Larger buffer is slower to create > 256K Wastes valuable process memory MySQL Best Practices for DBAs and Developers - 2010.10
  • 73. Where is the bottleneck? Is the database the problem? Front End Performance The website will always be too slow Identify the true components End to End time Database may be only a small portion MySQL Best Practices for DBAs and Developers - 2010.10
  • 74. Questions? MySQL Best Practices for DBAs and Developers - 2010.10
  • 75. RonaldBradford.com MySQL Best Practices for DBAs and Developers - 2010.10