Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

My sql crashcourse_intro_kdl

1.159 visualizaciones

Publicado el

MySQL Crashcourse @ RMOUG labs 2011

Publicado en: Tecnología
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

My sql crashcourse_intro_kdl

  1. 1. <Insert Picture Here>MySQL: Crash Course IntroductionKeith Larsonkeith.larson@oracle.comMySQL Community Manager
  2. 2. The following is intended to outline our general productdirection. It is intended for information purposes only, andmay not be incorporated into any contract. It is not acommitment to deliver any material, code, orfunctionality, and should not be relied upon in makingpurchasing decisions.The development, release, and timing of any features orfunctionality described for Oracle’s products remains atthe sole discretion of Oracle.Safe Harbor Statement
  3. 3. Who am I and who are you?Keith Larsonkeith.larson@oracle.comMySQL Community Managersqlhjalp.blogspot.comStarted with MySQL during the days.Primary real world work was with a MySQL InnoDB replicatedchain environment that easily held over 4 billion rows of userdata.Numerous other sites developed on LAMP stack over the last13 years.Who are you?–  DBAs?–  Developers?–  Already have replicated databases?–  Cluster Users or Cluster curious?
  4. 4. • Oracles Investment into MySQL• Provide high-level overview• Familiarize with the key concepts• Emphasize MySQL specificity• Community Edition, version 5.5 GAAgenda
  5. 5. The official way to pronounce “MySQL” is“My Ess Que Ell”but we do not mind if you pronounce it as“my sequel”Pronouciation
  6. 6. MySQL Crash CourseStarted in 80sAcquired by SUN Microsystems in 2008 for 1B USDAcquired by Oracle in 2009Dual licensing: GPL v.2 + commercial“M” in “LAMP” stackEasy of use: the 15 minute ruleBackground of MySQL
  7. 7. MySQL Makes The Cover!
  8. 8. Built togetherTested togetherManaged togetherServiced togetherBased on open standardsLower costLower riskMore reliableHardware and SoftwareEngineered to Work TogetherMySQL Completes The Stack
  9. 9. More Product Releases Than Ever BeforeContinuous InnovationQ2 CY2010 Q3 CY2010 Q4 CY2010 Q1 CY2011• MySQL Workbench 5.2GA!• MySQL Database 5.5• MySQL Enterprise Backup 3.5• MySQL Enterprise Monitor 2.3• MySQL Cluster Manager 1.1All GA!A Better MySQLQ2 CY2011• MySQL Enterprise Monitor 2.2• MySQL Cluster 7.1• MySQL Cluster Manager 1.0All GA!• MySQL Database5.6• MySQL Cluster 7.2DMR*and MySQL Labs!(“early and often”)*Development Milestone Release
  10. 10. Enterprise 2.0SaaS, CloudWeb OEM / ISV’sTelecommunicationsIndustry Leading CustomersRely on MySQL
  11. 11. >70% of Oracle shops run Still Free, Open to the CommunityAvailable to download and use under the GPL:• MySQL Database (Community Server)• MySQL Cluster• MySQL Workbench Community Edition• MySQL Connectors• MySQL Proxy• Documentation (free to use, not covered under GPL)• Forums
  12. 12. “I’m really blown away by MySQL 5.5’s improvements. “- Don MacAskill, SmugMug“My expectations for 5.5 were not high. I am pleasantlysurprised!”- Mark Callaghan, Facebook, MySQL UC Keynote"Oracle really did a great job with MySQL 5.5 -- in recordtime! It has lots of new features and performanceimprovements that our customers need andwant. Were very excited about this release."- Sheeri K. Cabral, Oracle Ace Director andDatabase Operations Manager, PalominoDBMySQL 5.5 Early Adopters Speak! GA
  13. 13. MySQL ComponentsMySQLServerMySQL Workbenchmysql (cmd-line client)System ToolsMySQL Enterprise MonitorDirect I/O“Not Only SQL”NoSQLMySQLProxyCnCnCnYour ApplicationCnSQL
  14. 14. MySQL ServerStandalone (mysqld)UNIX daemonWindows serviceRegular process on UNIX or WindowsEmbedded (libmysqld)Shared / Dynamic library
  15. 15. MySQL Server ComponentsInnoDBDB1InnoDBDB2MyISAMDB3InnoDB MyISAMCoreSQL-query processing, …Plugin 1 Plugin 2 Plugin 3 The CorePluginsStorage EnginesFull-text searchpluginsAudit pluginsAuthenticationplugins…
  16. 16. MySQL Server ComponentsSE defines data storage and retrievalEvery regular table belongs to some SEMost known Storage Engines:InnoDB (default since 5.5) – fully transactional SEMyISAM (default prior to 5.5) – NON-transactional SEDefault Storage EngineStorage Engine
  17. 17. •  Default Storage Engine for MySQL 5.5 and above•  ACID-compliant transactions, MVCC•  Row-level locking•  Two phase commit•  Efficient indexing•  Fast DDL operations•  Table compression•  Automatic crash recovery•  Referential integrity•  Online backup•  MoreMySQL DatabaseInnoDB - Transactional by Default
  18. 18. Storage Engines:Select a specialized storage engine for a particular applicationneed.InnoDB: a high-reliability and high-performance storage enginefor MySQL designed for transaction processing. It follows theACID model. Row-level locking and Oracle-style consistentreads increase multi-user concurrency and performanceMyISAM: -oldest storage engine has many featuresthat have been developed over years.Memory: creates tables with contents that are stored in memory.MySQL Cluster offers the same features as the MEMORYengine with higher performance levels, and providesadditional features
  19. 19. Storage Engines:CSV: data file is a plain text fileARCHIVE: is used for storing large amounts of data withoutindexes in a very small footprint.BLACKHOLE:accepts data but throws it away and does notstore it but the binary log is enabled.
  20. 20. MySQL Server ComponentsOpen SourceA Storage EngineHorizontal partitioning (distribute rows, notcolumns)Partitioning functions:The modulusRangeInternal hashing functionLinear hashing functionPartitioning
  21. 21. MySQL Server ComponentsOpen SourceOne-way, master and slavesAsynchronous or Semi-synchronous replicationReplication formats:Statement-based replication (SBR): propagate SQLstatementsRow-based replication (RBR): propagate row changesMixed-based replication: SBR or RBR depending onthe queryReplication
  22. 22. MySQL Replication OverviewNative in MySQLUsed for Scalability andHAAsynchronous asstandardSemi-Synchronoussupport added inMySQL 5.5Each slave addsminimal load on master
  23. 23. Writes & Reads Reads Reads• Write to one master• Read from many slaves, easily add more as needed• Perfect for read/write intensive appsApplicationMySQL ReplicationLoad BalancerMySQL DatabaseReplication Enables Scalability
  24. 24. Replication Topologies
  25. 25. MySQL Server ComponentsOpen SourceDifferent source tree, different versioning (7.x)In-memory, shared-nothing architecture“Synchronous, multi-master replication”Cluster
  26. 26. Copyright 2011 Oracle Corporation 26MySQL DatabaseHigh Availability with MySQL Replication
  27. 27. MySQL ArchitectureParallel Database with no SPOF: High Read & WritePerformance & 99.999% uptimeMySQL Cluster Data NodesMySQL ClusterApplication NodesClientsMySQLClusterMgmtLDAPRESTNoSQLSQL,JDBC,ODBC,ADO
  28. 28. Node Failure Detection & Self-Healing Recovery
  29. 29. Cluster – Typical PerformanceAvailability99.999% (<5 min downtime / year)PerformanceResponse Time 2-5 millisecond (with synchronous replicationand access via NDB APIThroughput of 10,000+ replicated transactions/sec on a 2Node Cluster, with 1 CPU Per Node (minimal configuration)Throughput of 100,000 replicated transactions/sec on 4 NodeCluster, with 2 CPU Per Node (low-end configuration)FailoverSub-second failover enables you to deliver servicewithout interruptionGA
  30. 30. BackupThe way depends on the applicationPossible solutions:MySQL Enterprise BackupReplicationmysqldump…Overview
  31. 31. MySQL Enterprise Backup• Online Backup for InnoDB• Full, Incremental, Partial Backups (scriptable interface)• Compression• Point in Time, Full, Partial Recovery options• Metadata on status, progress, history• Unlimited Database Size• Cross-Platform•  Windows, Linux, Unix• Certified with Oracle Secure BackupMEB BackupFilesMySQLDatabase FilesmysqlbackupEnsures quick, online backup and recovery of your MySQL apps.
  32. 32. Is it standard SQL?Yesaim is to support the full ANSI/ISO SQL standard, butwithout makingconcessions to speed andquality of the codeNoDepends on engine
  33. 33. MySQL ConceptsMySQL aims to follow The SQL StandardNot PL/SQLPrepared StatementsViewsStored ProgramsSHOW statements and especially SHOWCREATE …Administrative statementsSQL
  34. 34. MySQL ConceptsDatabase or SchemaCurrent database (per connection)Database – a set of files in “the data directory”System database (mysql)Virtual databases:INFORMATION_SCHEMAPERFORMANCE_SCHEMADatabase
  35. 35. MySQL ConceptsFull Unicode 5.0 for dataEncodings: UTF-8, UTF-16, UTF-32, UCS-2Two encodings for UTF-8:utf8 – 1..3 bytes, BMP onlyutf8mb4 – 1..4 bytes, BMP and supplementalAlias utf8mb3 == utf8Metadata are in utf8(no supplementary characters in identifiers)Unicode
  36. 36. MySQL ConceptsKnow your options9 numeric data typesCHAR, VARCHARBLOBsDate/time types…Weak typingSELECT 1 + ‘ 2nd place’ => 3Types
  37. 37. MySQL ConceptsError: code, level, SQL-state, messageError messages are localizedError level: errors, warnings, notesThe actual error level depends on configurationSerious errors might be thrown as warnings:SELECT 1 + ‘ 2nd place’Truncated incorrect DOUBLE value: 2nd placeSHOW WARNINGSSQL Conditions
  38. 38. MySQL VariablesOverview
  39. 39. MySQL VariablesUser Variables:– Weakly typed– SESSION variables– Arbitrary names– Available for any user– No declaration needed– Syntax:– SELECT @a– SET @a = 1User Variables
  40. 40. MySQL VariablesSP Variables:– Strongly typed– Only inside SP– Arbitrary names– Must be declared– Syntax:– DECLARE x INT– SELECT x– SET x = 1Stored Program Variables
  41. 41. MySQL VariablesSystem Variables:– Configuration options– Fixed names– Fixed types– GLOBAL requires SUPER– Syntax:–  SET / SELECT @@v1–  SET / SELECT @@session.v1–  SET / SELECT @@global.v2–  SHOW VARIABLES LIKE …System Variables
  42. 42. MySQL VariablesStatus Variables:– Read-only– Provide stat / information– NotPERFOMANCE_SCHEMA– SHOW GLOBAL STATUS…– SHOW SESSION STATUS…System Variables
  43. 43. MySQL ConfigurationHighly configurableCommand line optionsConfiguration files (plain-text, INI-like files withgroups)Several configuration files (/etc, $HOME, …)The last value takes precedence<exe> --help – order of loading filesSQL interface to get or change configurationparametersOverview
  44. 44. MySQL ConfigurationVery important variableAffects data consistency!It might be remembered…… or it might be notThus: set it once for all• Recommended value:STRICT_ALL_TABLES |NO_ZERO_DATE |NO_ZERO_IN_DATE |NO_ENGINE_SUBSTITUTION |NO_AUTO_CREATE_USER |IGNORE_SPACE |ERROR_FOR_DIVISION_BY_ZEROSQL MODE
  45. 45. MySQL Configuration• SET AUTOCOMMIT = ON | OFF (default: ON)• Auto-commit means COMMIT after each statement• Use START TRANSACTION if you plan to useROLLBACK• START TRANSACTION == BEGIN [WORK]AUTOCOMMIT
  46. 46. MySQL ConfigurationDatabase name – directory nameTable name – file name(s)Case-sensitive or case-insensitive ?lower_case_table_names = 0, 1, 2Defines how to name files on diskDefines how to compareSo: use lowercase everywhereIdentifier Case Sensitivity
  47. 47. Connecting to The ServerNamed Pipe and Shared Memory are disabled by defaultIPv4 and IPv6 connectivity supportedOverviewProtocolConnectionTypeOperatingSystemsTCP/IPLocal andRemoteAnyUNIX Socket File Local only UNIXNamed Pipe Local only WindowsShared Memory Local only WindowsOverview
  48. 48. Connecting to The Server--bind-address can be of use (all:‘mysql -pfoo’ != ‘mysql -p foo’-pfoo means password is ‘foo’-p foo means “ask password”, and the default database is ‘foo’mysql does SHOW DATABASES and SHOW TABLES onconnectHints
  49. 49. Understanding PrivilegesUser or User AccountPrivilege – what is allowed for the userSHOW GRANTS – get privileges for the currentuserSHOW GRANTS FOR …SHOW PRIVILEGES – list of all availableprivilegesBasics
  50. 50. Understanding PrivilegesGlobal: GRANT SELECT ON *.* TO …Database: GRANT SELECT ON db1.* TO …Table: GRANT SELECT ON db1.t1 TO …Column: GRANT SELECT(a) ON db1.t1 TO …Server administration privileges – global onlySUPERUSAGEOther privilegesHierarchy
  51. 51. Understanding PrivilegesSUPERA “different” privilegeIgnores init_connectBypasses read_only…GRANT ALL ON *.* … grants SUPER!USAGEAllows the user to just connect to the serverMind the default database in client connectionsBeware of …
  52. 52. Understanding PrivilegesWITH GRANT OPTIONenables the user to give to / to remove from otherusers those privileges that the user hasGRANT SELECT ON db1.* TO foo@bar WITHGRANT OPTIONGRANT DELETE ON db1.* TO foo@barSHOW GRANTS FOR foo@bar-> GRANT SELECT, DELETE ON db1.*TO foo@bar WITH GRANT OPTIONBeware of …
  53. 53. Understanding PrivilegesUser: username@hostnamePrecisely: ‘user-name-mask’@’host-name-mask’Host name – client host name (“from” host name)User name mask:can be empty (anonymous user) – all usersHost name mask:can be empty – all host namescan have ‘%’ (e.g.: the User
  54. 54. Understanding PrivilegesConnecting as foo from localhost…Should be foo@%, right ?The most specific values are usedBUT: host name matching is done before usernamehost userlocalhost barlocalhost% foo‘’@localhost will be chosen !Anonymous users…
  55. 55. Understanding PrivilegesSELECT CURRENT_USER()The authenticated user name and host nameSELECT USER()The user name and host name provided by the clientFor our example:CURRENT_USER(): ‘’@locahostUSER(): foo@localhostUseful Functions
  56. 56. Working With TablesRegular tablesTemporary tables (per session)ViewsINFORMATION_SCHEMA tablesPERFORMANCE_SCHEMA tablesOverview
  57. 57. Working With TablesMind the storage engine!Temporary tables are in the same namespace !Temporary tables shadow regular ones !5.5: CREATE TEMPORARY TABLES is notenough5.6: CREATE TEMPORARY TABLES is enoughHints
  58. 58. The First StepsServer – Community or Enterprise (for 30 days)Cluster –real-time open source transactional database designed forfast, always-on access to data under high throughput conditions.Workbench – visual database design application that can be used toefficiently design, manage and document database schemataProxy – a simple program that sits between your client and MySQLserver(s) that can monitor, analyze or transform their communication.Connectors – ODBC, Java, .Net, MXJ, C/C++, DBI, Ruby, Python,etc. Options
  59. 59. How to get MySQLCommunity:Freely downloadable version of the worlds most popular opensource database. It is available under the GPL license and issupported by a huge and active community of open sourcedevelopers.Enterprise:Paid subscription includes support and the following•  MySQL Enterprise Backup•  MySQL Enterprise Security–  External Authentication•  MySQL Enterprise Scalability–  Thread Pool•  MySQL Enterprise High Availability–  Oracle VM Template–  Windows Clustering•  MySQL Enterprise MonitorFree for 30 day evaluation
  60. 60. The First StepsChoosing the version5.1 – previous GA version5.5 – the latest GA version5.6 – development releaseChoosing the editionCommunity Edition (Community Server)Enterprise Editions (even MySQL Classic and MySQLStandard)Source or BinaryDownload
  61. 61. The First Steps• Where are the configuration filesDefault configuration might be not so goodPerformance, …SQL_MODEAUTOCOMMIT…Post-installation steps: Configuration
  62. 62. The First StepsSecure the installationDon’t run under ‘root’Have separate directories (configuration, data, binarylogs, …)Change ‘root’ passwordRemove default accountsPost-installation steps: Security
  63. 63. • Reach out to the community–  Irc on freenode–• Oracle Support• CertificationsMySQL SupportHow can I get help ?
  64. 64. • 24 X 7 Problem ResolutionServices• Unlimited Support Incidents• Knowledge Base• Maintenance Releases, Bugfixes, Patches, Updates• MySQL Consultative Support• Staffed by experienced,seasoned MySQL EngineersOracle Premier Support for MySQL
  65. 65. •  MySQL Database, Visual Development/Admin, Monitoring,Backup tools, and Oracle Lifetime Support servicesMySQL EnterpriseMonitorPerformanceMonitoring/ AlertsHot fixesService packsMySQL WorkbenchOracle Lifetime SupportMySQL Enterprise BackupMySQL Enterprise EditionQuery AnalyzerDev/Admin, Monitoring/Backup ToolsOracle LifetimeSupport Services
  66. 66. •  Oracle High Availability•  Oracle Linux•  Oracle VM + MySQL Template•  Oracle Fusion MiddleWare•  WebLogic Server 10.3.1 +•  Database Adapter for Oracle SOA Suite +•  Oracle BPM +•  Oracle Virtual Directory•  Oracle Data Integrator +•  Oracle Enterprise Performance Management 11.1.2•  Oracle Identity Analytics•  Open SSO STS, Open SSO Fedlet Enterprise CertificationsOracle Products
  67. 67. •  Oracle Golden Gate•  Bi-directional replication between MySQL and Oracle•  Exadata Data Stores – Enterprise DW, legacy apps,etc.•  Hybrid Applications (MySQL frontend + Oracle datastore)•  Oracle Secure Backup•  MySQL Enterprise Backup 3.6 - supports backupstreaming to OSB via SBT APIMySQL Enterprise CertificationsOracle ProductsEnables you to manage your Oracle and MySQL databaseswith Oracle tools/solutions you are already using.
  68. 68. Additional•  TCO calculator•  White Papers•  Customer use cases and success•  Downloads•  Documentation•  Forums••  Download and evaluate all MySQL products
  69. 69. Additional•  Download MySQL 5.5, MySQL Cluster 7.1 GA, GPL Products•  MySQL Products, Editions, Licensing Options•  TCO calculator•  Upcoming Events•  Customer use cases and success•  Download MySQL 5.6 DMR and Labs “early access” features•  Developer Zone Articles, How to’•  Download and evaluate all MySQL products
  70. 70. Additional•  Blog feeds from the experts and the communityBooks:•  MySQL by Paul DuBois•  MySQL Administrators Bible•  High Performance MySQL: Optimization, Backups, Replication,and•  Community interaction
  71. 71. things to know before migrating Oracle to MySQLIt is a little old but worth the readAdditional Resources
  72. 72. <Insert Picture Here>Thanks for attending!
  73. 73. Extra Slides