SlideShare a Scribd company logo
1 of 37
Download to read offline
<Insert Picture Here>
MySQL: Regis Hands On Lab
Keith Larson
keith.larson@oracle.com
MySQL Community Manager
The following is intended to outline our general product
direction. It is intended for information purposes only, and
may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or
functionality, and should not be relied upon in making
purchasing decisions.
The development, release, and timing of any features or
functionality described for Oracle’s products remains at
the sole discretion of Oracle.
Safe Harbor Statement
tar -xvf MySQL-5.5.16-1.rhel5.x86_64.tar
rpm -i MySQL-server-5.5.16-1.rhel5.x86_64.rpm
It will prompt you with setting passwords but I will show that
soon.
MySQL
Installation
http://dev.mysql.com/doc/index-other.html
wget http://downloads.mysql.com/docs/world_innodb.sql.gz
wget launchpad.net/test-db/employees-db-1/1.0.6/+download/
employees_db-dump-files-1.0.5.tar.bz2
MySQL
Test Data
-bash-3.2$ mysql
mysql> create database world;
ERROR 1044 (42000): Access denied for user ''@'localhost' to
database 'world'
mysql> exit
mysql -u root
mysql> CREATE DATABASE world;
mysql>exit;
mysql -u root world < world_innodb.sql
MySQL
Denied
-bash-3.2$ mysqladmin -u root password brad
-bash-3.2$ mysql -u root world
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)
-bash-3.2$ mysql -u root world -p
Enter password:
MySQL
Set Root Password
http://dev.mysql.com/doc/refman/5.5/en/grant.html
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT
OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE ON
*.* TO 'monty'@'localhost'
WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT
OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE ON
*.* TO 'monty'@'%'
WITH GRANT OPTION;
mysql> flush privileges ;
MySQL
New Users
http://dev.mysql.com/doc/refman/5.5/en/grant.html
mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin_pass';
GRANT ALL ON *.* TO 'admin'@'localhost';
mysql> flush privileges ;
mysql -u monty -p
Enter password:
mysql -u admin -p
Enter password:
MySQL
New Super Users
mysql -u admin -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bobmason |
| mysql |
| performance_schema |
| test |
| world |
+--------------------+
mysql> create database <yourname>_example;
Query OK, 1 row affected (0.00 sec)
MySQL
Create Database/Schema
mysql> use world;
mysql> show tables;
+-----------------+
| Tables_in_world |
+-----------------+
| City |
| Country |
| CountryLanguage |
+-----------------+
3 rows in set (0.00 sec)
mysql> show create table City;
MySQL
Table
CREATE TABLE `City` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES
`Country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1
MySQL
Table City
mysql> use <yourname>_example;
mysql> CREATE TABLE `City` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES
`Country` (`Code`)
) ENGINE=InnoDB
ERROR 1005 (HY000): Can't create table '<yourname>_example.City' (errno: 150)
http://forums.mysql.com/read.php?22,19755,19755
MySQL
Create Table in Your Database
mysql> show create table world.Country;
mysql> CREATE TABLE `Country` (
-> `Code` char(3) NOT NULL DEFAULT '',
-> `Name` char(52) NOT NULL DEFAULT '',
-> `Continent` enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL
DEFAULT 'Asia',
-> `Region` char(26) NOT NULL DEFAULT '',
-> `SurfaceArea` float(10,2) NOT NULL DEFAULT '0.00',
-> `IndepYear` smallint(6) DEFAULT NULL,
-> `Population` int(11) NOT NULL DEFAULT '0',
-> `LifeExpectancy` float(3,1) DEFAULT NULL,
-> `GNP` float(10,2) DEFAULT NULL,
-> `GNPOld` float(10,2) DEFAULT NULL,
-> `LocalName` char(45) NOT NULL DEFAULT '',
-> `GovernmentForm` char(45) NOT NULL DEFAULT '',
-> `HeadOfState` char(60) DEFAULT NULL,
-> `Capital` int(11) DEFAULT NULL,
-> `Code2` char(2) NOT NULL DEFAULT '',
-> PRIMARY KEY (`Code`)
-> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec)
MySQL
Try again ….
Mysql> CREATE TABLE `City` (
-> `ID` int(11) NOT NULL AUTO_INCREMENT,
-> `Name` char(35) NOT NULL DEFAULT '',
-> `CountryCode` char(3) NOT NULL DEFAULT '',
-> `District` char(20) NOT NULL DEFAULT '',
-> `Population` int(11) NOT NULL DEFAULT '0',
-> PRIMARY KEY (`ID`),
-> KEY `CountryCode` (`CountryCode`),
-> CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`)
REFERENCES `Country` (`Code`)
-> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.04 sec)
MySQL
City works now...
Mysql> CREATE TABLE `CountryLanguage` (
`CountryCode` char(3) NOT NULL DEFAULT '',
`Language` char(30) NOT NULL DEFAULT '',
`IsOfficial` enum('T','F') NOT NULL DEFAULT 'F',
`Percentage` float(4,1) NOT NULL DEFAULT '0.0',
PRIMARY KEY (`CountryCode`,`Language`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `countryLanguage_ibfk_1` FOREIGN KEY (`CountryCode`)
REFERENCES `Country` (`Code`)
) ENGINE=InnoDB
MySQL
CountryLanguage as well..
mysql> use <yourname>_example;
mysql> insert into Country select * from world.Country;
Query OK, 239 rows affected (0.03 sec)
Records: 239 Duplicates: 0 Warnings: 0
mysql> insert into CountryLanguage select * from world.CountryLanguage;
Query OK, 984 rows affected (0.03 sec)
Records: 984 Duplicates: 0 Warnings: 0
mysql> insert into City select * from world.City;
Query OK, 4079 rows affected (0.29 sec)
Records: 4079 Duplicates: 0 Warnings: 0
Faster -- mysql -u admin -p <yourname>_example < world_innodb.sql
MySQL
Add Data
SELECT ID , Name , CountryCode , Population
FROM City
WHERE CountryCode = 'USA'
ORDER BY Population DESC limit 20;
SELECT C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA'
ORDER BY C.Population DESC limit 20;
MySQL
Look at some data
mysql> SELECT C.ID , C.Name , C.CountryCode , C.Population
-> FROM City C
-> INNER JOIN Country Y ON Y.Code = C.CountryCode
-> INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
-> WHERE Y.Code = 'USA'
-> ORDER BY Population DESC
-> GROUP BY C.Name limit 20;
MySQL
Group by…
mysql> SELECT C.ID , C.Name , C.CountryCode , C.Population
-> FROM City C
-> INNER JOIN Country Y ON Y.Code = C.CountryCode
-> INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
-> WHERE Y.Code = 'USA'
-> ORDER BY Population DESC
-> GROUP BY C.Name limit 20;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near 'GROUP BY C.Name limit 20' at line 7
mysql>
MySQL
Group by…Error
SELECT C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA'
GROUP BY C.Name
ORDER BY Population DESC
limit 20;
MySQL
Error fixed
SET @RANK=0; # Variable
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode ,
C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA'
GROUP BY C.Name
ORDER BY Population DESC
limit 20;
MySQL
Rank Results
SET @RANK=0;
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA'
UNION
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA' AND C.name = 'Denver'
GROUP BY C.Name
ORDER BY Population DESC
limit 25;
MySQL
Union Example
SET @RANK=0;
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA'
UNION
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA' AND C.name = 'Denver'
GROUP BY C.Name
ORDER BY Population DESC
limit 25;
## Not what you wanted is it....
MySQL
Union Example
SET @RANK=0;
SELECT @RANK:=@RANK+1 AS RANK, C.ID , DISTINCT(C.Name) as Name , C.CountryCode ,
C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA' AND C.Population >= 3694820
UNION
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA' AND C.name = 'Denver'
GROUP BY C.Name
ORDER BY Population DESC
limit 25;
MySQL
Union Example
SET @RANK=0;
SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population
FROM City C
INNER JOIN Country Y ON Y.Code = C.CountryCode
INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode
WHERE Y.Code = 'USA'
GROUP BY C.Name
ORDER BY Population DESC
limit 100 INTO OUTFILE '/tmp/mysql_export.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY 'n'
MySQL
Export Example
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
CREATE TABLE test1(a1 INT);
CREATE TABLE test2(a2 INT);
CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
CREATE TABLE test4(
a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
b4 INT DEFAULT 0
);
delimiter |
CREATE TRIGGER testref BEFORE INSERT ON test1
FOR EACH ROW BEGIN
INSERT INTO test2 SET a2 = NEW.a1;
DELETE FROM test3 WHERE a3 = NEW.a1;
UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1;
END; |
delimiter ;
MySQL
Trigger Example
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
INSERT INTO test3 (a3) VALUES
(NULL), (NULL), (NULL), (NULL), (NULL),
(NULL), (NULL), (NULL), (NULL), (NULL);
INSERT INTO test4 (a4) VALUES
(0), (0), (0), (0), (0), (0), (0), (0), (0), (0);
SELECT * FROM test1; 8 rows in set (0.00 sec)
SELECT * FROM test2; 8 rows in set (0.00 sec)
SELECT * FROM test3; 8 rows in set (0.00 sec)
SELECT * FROM test4; 8 rows in set (0.00 sec)
MySQL
Trigger Example
http://dev.mysql.com/doc/refman/5.5/en/stored-routines.html
The CREATE ROUTINE , ALTER ROUTINE , EXECUTE privilege is needed for stored
routines.
mysql> delimiter //
mysql> CREATE PROCEDURE simpleproc (OUT param1 INT)
-> BEGIN
-> SELECT COUNT(*) INTO param1 FROM t;
-> END//
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
mysql> CALL simpleproc(@a);
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @a;
+------+
| @a |
+------+
| 3 |
+------+
1 row in set (0.00 sec)
MySQL
Stored Routines (Procedures and Functions)
http://dev.mysql.com/doc/refman/5.5/en/commit.html
To disable autocommit mode, use the following statement: SET autocommit=0;
To disable autocommit mode for a single series of statements, use the START
TRANSACTION statement:
START TRANSACTION;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;
MySQL
Transactions
MySQL Workbench SE
Database Design
•  Visual Design, modeling
•  Forward/Reverse Engineer
•  Schema validation, Schema doc
SQL Development
• SQL Editor - Color Syntax
Highlighting
• Objects - Import/Export, Browse/Edit
• Connections - Wizard, SSH Tunnel
Database Administration
• Status, Configuration, Start/Stop
• Users, Security, Sessions
• Import/Export Dump Files
Scripting & Plug-in Support
UI Designed to match VS 2010
Saves you time developing and
managing your MySQL apps.
GA
MySQL Workbench - Plugins
•  Community driven Plugins & Add-ons site
–  Code in Python, share with the community
MySQL Workbench – Hands On Lab
•  http://sqlhjalp.com/iso/OTN_Developer_Day_MySQL.iso
Additional Resources
mysql.com
•  TCO calculator
•  White Papers
•  Customer use cases and success stories
dev.mysql.com
•  Downloads
•  Documentation
•  Forums
•  PlanetMySQL
eDelivery.com
•  Download and evaluate all MySQL products
Additional Resources
mysql.com
•  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 stories
dev.mysql.com
•  Download MySQL 5.6 DMR and Labs “early access” features
•  Developer Zone Articles, How to’s
eDelivery.com
•  Download and evaluate all MySQL products
Additional Resources
Planet.mysql.com
•  Blog feeds from the experts and the community
Books:
•  MySQL by Paul DuBois
•  MySQL Administrator's Bible
•  High Performance MySQL: Optimization, Backups, Replication,
and More
forums.mysql.com
•  Community interaction
<Insert Picture Here>
Thanks for attending!
keith.larson@oracle.com
Extra Slides

More Related Content

What's hot

Second Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON FunctionsSecond Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON FunctionsSveta Smirnova
 
Rapid prototyping search applications with solr
Rapid prototyping search applications with solrRapid prototyping search applications with solr
Rapid prototyping search applications with solrLucidworks (Archived)
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Dave Stokes
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesDave Stokes
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLPadraig O'Sullivan
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationDave Stokes
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developersColin Charles
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best PracticesOlivier DASINI
 
MySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesMySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesDave Stokes
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourRonald Bradford
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they doDave Stokes
 
Open Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseDave Stokes
 
Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!Guatemala User Group
 

What's hot (19)

MySQL Monitoring 101
MySQL Monitoring 101MySQL Monitoring 101
MySQL Monitoring 101
 
Second Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON FunctionsSecond Step to the NoSQL Side: MySQL JSON Functions
Second Step to the NoSQL Side: MySQL JSON Functions
 
Rapid prototyping search applications with solr
Rapid prototyping search applications with solrRapid prototyping search applications with solr
Rapid prototyping search applications with solr
 
MySQL JSON Functions
MySQL JSON FunctionsMySQL JSON Functions
MySQL JSON Functions
 
Curso de MySQL 5.7
Curso de MySQL 5.7Curso de MySQL 5.7
Curso de MySQL 5.7
 
Percona toolkit
Percona toolkitPercona toolkit
Percona toolkit
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my!
 
All Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for NewbiesAll Things Open 2016 -- Database Programming for Newbies
All Things Open 2016 -- Database Programming for Newbies
 
Capturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQLCapturing, Analyzing, and Optimizing your SQL
Capturing, Analyzing, and Optimizing your SQL
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentation
 
Terraform Cosmos DB
Terraform Cosmos DBTerraform Cosmos DB
Terraform Cosmos DB
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developers
 
MySQL Performance Best Practices
MySQL Performance Best PracticesMySQL Performance Best Practices
MySQL Performance Best Practices
 
MySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesMySQL 8.0 Operational Changes
MySQL 8.0 Operational Changes
 
MySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD TourMySQL Best Practices - OTN LAD Tour
MySQL Best Practices - OTN LAD Tour
 
Best Features of Multitenant 12c
Best Features of Multitenant 12cBest Features of Multitenant 12c
Best Features of Multitenant 12c
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
 
Open Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational Database
 
Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!Pluggable Databases: What they will break and why you should use them anyway!
Pluggable Databases: What they will break and why you should use them anyway!
 

Viewers also liked

My sql crashcourse_intro_kdl
My sql crashcourse_intro_kdlMy sql crashcourse_intro_kdl
My sql crashcourse_intro_kdlsqlhjalp
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replicationsqlhjalp
 
My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012sqlhjalp
 
2012 ohiolinuxfest replication
2012 ohiolinuxfest replication2012 ohiolinuxfest replication
2012 ohiolinuxfest replicationsqlhjalp
 
2012 replication
2012 replication2012 replication
2012 replicationsqlhjalp
 
Mysql nowwhat
Mysql nowwhatMysql nowwhat
Mysql nowwhatsqlhjalp
 
My sql crashcourse_2012
My sql crashcourse_2012My sql crashcourse_2012
My sql crashcourse_2012sqlhjalp
 
My sql 56_roadmap_april2012
My sql 56_roadmap_april2012My sql 56_roadmap_april2012
My sql 56_roadmap_april2012sqlhjalp
 

Viewers also liked (8)

My sql crashcourse_intro_kdl
My sql crashcourse_intro_kdlMy sql crashcourse_intro_kdl
My sql crashcourse_intro_kdl
 
2012 scale replication
2012 scale replication2012 scale replication
2012 scale replication
 
My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012My sql susecon_crashcourse_2012
My sql susecon_crashcourse_2012
 
2012 ohiolinuxfest replication
2012 ohiolinuxfest replication2012 ohiolinuxfest replication
2012 ohiolinuxfest replication
 
2012 replication
2012 replication2012 replication
2012 replication
 
Mysql nowwhat
Mysql nowwhatMysql nowwhat
Mysql nowwhat
 
My sql crashcourse_2012
My sql crashcourse_2012My sql crashcourse_2012
My sql crashcourse_2012
 
My sql 56_roadmap_april2012
My sql 56_roadmap_april2012My sql 56_roadmap_april2012
My sql 56_roadmap_april2012
 

Similar to My sql regis_handsonlab

Postgres Conference (PgCon) New York 2019
Postgres Conference (PgCon) New York 2019Postgres Conference (PgCon) New York 2019
Postgres Conference (PgCon) New York 2019Ibrar Ahmed
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17alikonweb
 
- Php myadmin sql dump-- version 4.0.10.7-- httpwww.php
 - Php myadmin sql dump-- version 4.0.10.7-- httpwww.php - Php myadmin sql dump-- version 4.0.10.7-- httpwww.php
- Php myadmin sql dump-- version 4.0.10.7-- httpwww.phpssuserfa5723
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHPVineet Kumar Saini
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNRonald Bradford
 
MySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That BiteMySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That BiteRonald Bradford
 
Cassandra, web scale no sql data platform
Cassandra, web scale no sql data platformCassandra, web scale no sql data platform
Cassandra, web scale no sql data platformMarko Švaljek
 
CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013
CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013
CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013MariaDB Corporation
 
MySQL and GIS Programming
MySQL and GIS ProgrammingMySQL and GIS Programming
MySQL and GIS ProgrammingMike Benshoof
 
Database Implementation Final Document
Database Implementation Final DocumentDatabase Implementation Final Document
Database Implementation Final DocumentConor O'Callaghan
 
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10Altinity Ltd
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverDave Stokes
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPDave Stokes
 
Practical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and BeyondPractical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and BeyondIke Walker
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Philip Zhong
 

Similar to My sql regis_handsonlab (20)

Postgres Conference (PgCon) New York 2019
Postgres Conference (PgCon) New York 2019Postgres Conference (PgCon) New York 2019
Postgres Conference (PgCon) New York 2019
 
MySQL SQL Tutorial
MySQL SQL TutorialMySQL SQL Tutorial
MySQL SQL Tutorial
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17
 
- Php myadmin sql dump-- version 4.0.10.7-- httpwww.php
 - Php myadmin sql dump-- version 4.0.10.7-- httpwww.php - Php myadmin sql dump-- version 4.0.10.7-- httpwww.php
- Php myadmin sql dump-- version 4.0.10.7-- httpwww.php
 
Country State City Dropdown in PHP
Country State City Dropdown in PHPCountry State City Dropdown in PHP
Country State City Dropdown in PHP
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
 
Mysql python
Mysql pythonMysql python
Mysql python
 
Mysql python
Mysql pythonMysql python
Mysql python
 
MySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That BiteMySQL Idiosyncrasies That Bite
MySQL Idiosyncrasies That Bite
 
Cassandra, web scale no sql data platform
Cassandra, web scale no sql data platformCassandra, web scale no sql data platform
Cassandra, web scale no sql data platform
 
CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013
CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013
CCM Escape Case Study - SkySQL Paris Meetup 17.12.2013
 
MySQL and GIS Programming
MySQL and GIS ProgrammingMySQL and GIS Programming
MySQL and GIS Programming
 
Database Implementation Final Document
Database Implementation Final DocumentDatabase Implementation Final Document
Database Implementation Final Document
 
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 
PDBC
PDBCPDBC
PDBC
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo Vancouver
 
PHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHPPHP Database Programming Basics -- Northeast PHP
PHP Database Programming Basics -- Northeast PHP
 
Practical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and BeyondPractical JSON in MySQL 5.7 and Beyond
Practical JSON in MySQL 5.7 and Beyond
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 

Recently uploaded

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Recently uploaded (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

My sql regis_handsonlab

  • 1. <Insert Picture Here> MySQL: Regis Hands On Lab Keith Larson keith.larson@oracle.com MySQL Community Manager
  • 2. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. Safe Harbor Statement
  • 3. tar -xvf MySQL-5.5.16-1.rhel5.x86_64.tar rpm -i MySQL-server-5.5.16-1.rhel5.x86_64.rpm It will prompt you with setting passwords but I will show that soon. MySQL Installation
  • 5. -bash-3.2$ mysql mysql> create database world; ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'world' mysql> exit mysql -u root mysql> CREATE DATABASE world; mysql>exit; mysql -u root world < world_innodb.sql MySQL Denied
  • 6. -bash-3.2$ mysqladmin -u root password brad -bash-3.2$ mysql -u root world ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) -bash-3.2$ mysql -u root world -p Enter password: MySQL Set Root Password
  • 7. http://dev.mysql.com/doc/refman/5.5/en/grant.html mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass'; mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE ON *.* TO 'monty'@'localhost' WITH GRANT OPTION; mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass'; mysql> GRANT ALTER, CREATE VIEW, CREATE, DELETE, DROP, GRANT OPTION, INDEX, INSERT, SELECT, SHOW VIEW, TRIGGER, UPDATE ON *.* TO 'monty'@'%' WITH GRANT OPTION; mysql> flush privileges ; MySQL New Users
  • 8. http://dev.mysql.com/doc/refman/5.5/en/grant.html mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin_pass'; GRANT ALL ON *.* TO 'admin'@'localhost'; mysql> flush privileges ; mysql -u monty -p Enter password: mysql -u admin -p Enter password: MySQL New Super Users
  • 9. mysql -u admin -p mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | bobmason | | mysql | | performance_schema | | test | | world | +--------------------+ mysql> create database <yourname>_example; Query OK, 1 row affected (0.00 sec) MySQL Create Database/Schema
  • 10. mysql> use world; mysql> show tables; +-----------------+ | Tables_in_world | +-----------------+ | City | | Country | | CountryLanguage | +-----------------+ 3 rows in set (0.00 sec) mysql> show create table City; MySQL Table
  • 11. CREATE TABLE `City` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`), CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1 MySQL Table City
  • 12. mysql> use <yourname>_example; mysql> CREATE TABLE `City` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Name` char(35) NOT NULL DEFAULT '', `CountryCode` char(3) NOT NULL DEFAULT '', `District` char(20) NOT NULL DEFAULT '', `Population` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), KEY `CountryCode` (`CountryCode`), CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ) ENGINE=InnoDB ERROR 1005 (HY000): Can't create table '<yourname>_example.City' (errno: 150) http://forums.mysql.com/read.php?22,19755,19755 MySQL Create Table in Your Database
  • 13. mysql> show create table world.Country; mysql> CREATE TABLE `Country` ( -> `Code` char(3) NOT NULL DEFAULT '', -> `Name` char(52) NOT NULL DEFAULT '', -> `Continent` enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia', -> `Region` char(26) NOT NULL DEFAULT '', -> `SurfaceArea` float(10,2) NOT NULL DEFAULT '0.00', -> `IndepYear` smallint(6) DEFAULT NULL, -> `Population` int(11) NOT NULL DEFAULT '0', -> `LifeExpectancy` float(3,1) DEFAULT NULL, -> `GNP` float(10,2) DEFAULT NULL, -> `GNPOld` float(10,2) DEFAULT NULL, -> `LocalName` char(45) NOT NULL DEFAULT '', -> `GovernmentForm` char(45) NOT NULL DEFAULT '', -> `HeadOfState` char(60) DEFAULT NULL, -> `Capital` int(11) DEFAULT NULL, -> `Code2` char(2) NOT NULL DEFAULT '', -> PRIMARY KEY (`Code`) -> ) ENGINE=InnoDB; Query OK, 0 rows affected (0.02 sec) MySQL Try again ….
  • 14. Mysql> CREATE TABLE `City` ( -> `ID` int(11) NOT NULL AUTO_INCREMENT, -> `Name` char(35) NOT NULL DEFAULT '', -> `CountryCode` char(3) NOT NULL DEFAULT '', -> `District` char(20) NOT NULL DEFAULT '', -> `Population` int(11) NOT NULL DEFAULT '0', -> PRIMARY KEY (`ID`), -> KEY `CountryCode` (`CountryCode`), -> CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) -> ) ENGINE=InnoDB; Query OK, 0 rows affected (0.04 sec) MySQL City works now...
  • 15. Mysql> CREATE TABLE `CountryLanguage` ( `CountryCode` char(3) NOT NULL DEFAULT '', `Language` char(30) NOT NULL DEFAULT '', `IsOfficial` enum('T','F') NOT NULL DEFAULT 'F', `Percentage` float(4,1) NOT NULL DEFAULT '0.0', PRIMARY KEY (`CountryCode`,`Language`), KEY `CountryCode` (`CountryCode`), CONSTRAINT `countryLanguage_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `Country` (`Code`) ) ENGINE=InnoDB MySQL CountryLanguage as well..
  • 16. mysql> use <yourname>_example; mysql> insert into Country select * from world.Country; Query OK, 239 rows affected (0.03 sec) Records: 239 Duplicates: 0 Warnings: 0 mysql> insert into CountryLanguage select * from world.CountryLanguage; Query OK, 984 rows affected (0.03 sec) Records: 984 Duplicates: 0 Warnings: 0 mysql> insert into City select * from world.City; Query OK, 4079 rows affected (0.29 sec) Records: 4079 Duplicates: 0 Warnings: 0 Faster -- mysql -u admin -p <yourname>_example < world_innodb.sql MySQL Add Data
  • 17. SELECT ID , Name , CountryCode , Population FROM City WHERE CountryCode = 'USA' ORDER BY Population DESC limit 20; SELECT C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' ORDER BY C.Population DESC limit 20; MySQL Look at some data
  • 18. mysql> SELECT C.ID , C.Name , C.CountryCode , C.Population -> FROM City C -> INNER JOIN Country Y ON Y.Code = C.CountryCode -> INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode -> WHERE Y.Code = 'USA' -> ORDER BY Population DESC -> GROUP BY C.Name limit 20; MySQL Group by…
  • 19. mysql> SELECT C.ID , C.Name , C.CountryCode , C.Population -> FROM City C -> INNER JOIN Country Y ON Y.Code = C.CountryCode -> INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode -> WHERE Y.Code = 'USA' -> ORDER BY Population DESC -> GROUP BY C.Name limit 20; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY C.Name limit 20' at line 7 mysql> MySQL Group by…Error
  • 20. SELECT C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' GROUP BY C.Name ORDER BY Population DESC limit 20; MySQL Error fixed
  • 21. SET @RANK=0; # Variable SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' GROUP BY C.Name ORDER BY Population DESC limit 20; MySQL Rank Results
  • 22. SET @RANK=0; SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' UNION SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' AND C.name = 'Denver' GROUP BY C.Name ORDER BY Population DESC limit 25; MySQL Union Example
  • 23. SET @RANK=0; SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' UNION SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' AND C.name = 'Denver' GROUP BY C.Name ORDER BY Population DESC limit 25; ## Not what you wanted is it.... MySQL Union Example
  • 24. SET @RANK=0; SELECT @RANK:=@RANK+1 AS RANK, C.ID , DISTINCT(C.Name) as Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' AND C.Population >= 3694820 UNION SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' AND C.name = 'Denver' GROUP BY C.Name ORDER BY Population DESC limit 25; MySQL Union Example
  • 25. SET @RANK=0; SELECT @RANK:=@RANK+1 AS RANK, C.ID , C.Name , C.CountryCode , C.Population FROM City C INNER JOIN Country Y ON Y.Code = C.CountryCode INNER JOIN CountryLanguage L ON L.CountryCode = C.CountryCode WHERE Y.Code = 'USA' GROUP BY C.Name ORDER BY Population DESC limit 100 INTO OUTFILE '/tmp/mysql_export.csv' FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' MySQL Export Example
  • 26. http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html CREATE TABLE test1(a1 INT); CREATE TABLE test2(a2 INT); CREATE TABLE test3(a3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY); CREATE TABLE test4( a4 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b4 INT DEFAULT 0 ); delimiter | CREATE TRIGGER testref BEFORE INSERT ON test1 FOR EACH ROW BEGIN INSERT INTO test2 SET a2 = NEW.a1; DELETE FROM test3 WHERE a3 = NEW.a1; UPDATE test4 SET b4 = b4 + 1 WHERE a4 = NEW.a1; END; | delimiter ; MySQL Trigger Example
  • 27. http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html INSERT INTO test3 (a3) VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL), (NULL); INSERT INTO test4 (a4) VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0); SELECT * FROM test1; 8 rows in set (0.00 sec) SELECT * FROM test2; 8 rows in set (0.00 sec) SELECT * FROM test3; 8 rows in set (0.00 sec) SELECT * FROM test4; 8 rows in set (0.00 sec) MySQL Trigger Example
  • 28. http://dev.mysql.com/doc/refman/5.5/en/stored-routines.html The CREATE ROUTINE , ALTER ROUTINE , EXECUTE privilege is needed for stored routines. mysql> delimiter // mysql> CREATE PROCEDURE simpleproc (OUT param1 INT) -> BEGIN -> SELECT COUNT(*) INTO param1 FROM t; -> END// Query OK, 0 rows affected (0.00 sec) mysql> delimiter ; mysql> CALL simpleproc(@a); Query OK, 0 rows affected (0.00 sec) mysql> SELECT @a; +------+ | @a | +------+ | 3 | +------+ 1 row in set (0.00 sec) MySQL Stored Routines (Procedures and Functions)
  • 29. http://dev.mysql.com/doc/refman/5.5/en/commit.html To disable autocommit mode, use the following statement: SET autocommit=0; To disable autocommit mode for a single series of statements, use the START TRANSACTION statement: START TRANSACTION; SELECT @A:=SUM(salary) FROM table1 WHERE type=1; UPDATE table2 SET summary=@A WHERE type=1; COMMIT; MySQL Transactions
  • 30. MySQL Workbench SE Database Design •  Visual Design, modeling •  Forward/Reverse Engineer •  Schema validation, Schema doc SQL Development • SQL Editor - Color Syntax Highlighting • Objects - Import/Export, Browse/Edit • Connections - Wizard, SSH Tunnel Database Administration • Status, Configuration, Start/Stop • Users, Security, Sessions • Import/Export Dump Files Scripting & Plug-in Support UI Designed to match VS 2010 Saves you time developing and managing your MySQL apps. GA
  • 31. MySQL Workbench - Plugins •  Community driven Plugins & Add-ons site –  Code in Python, share with the community
  • 32. MySQL Workbench – Hands On Lab •  http://sqlhjalp.com/iso/OTN_Developer_Day_MySQL.iso
  • 33. Additional Resources mysql.com •  TCO calculator •  White Papers •  Customer use cases and success stories dev.mysql.com •  Downloads •  Documentation •  Forums •  PlanetMySQL eDelivery.com •  Download and evaluate all MySQL products
  • 34. Additional Resources mysql.com •  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 stories dev.mysql.com •  Download MySQL 5.6 DMR and Labs “early access” features •  Developer Zone Articles, How to’s eDelivery.com •  Download and evaluate all MySQL products
  • 35. Additional Resources Planet.mysql.com •  Blog feeds from the experts and the community Books: •  MySQL by Paul DuBois •  MySQL Administrator's Bible •  High Performance MySQL: Optimization, Backups, Replication, and More forums.mysql.com •  Community interaction
  • 36. <Insert Picture Here> Thanks for attending! keith.larson@oracle.com