Factors to Consider When Choosing Accounts Payable Services Providers.pptx
ย
My sql102
1. MySQL 102
MySQL 102 is the second part of a
presentation to be preceded by MySQL 101
and covers material that will build on the
previous presentation.
1
Http://slideshare.net/davestokes/presentations
2. Agenda
โ Workbench
โ User Accounts & Privileges
โ Tables and Databases
โ Views
โ Stored Routines/Procedures
โ Questions and Answers
โ Replication (after a break)
David.Stokes@Oracle.com @stoker 2
3. Workbench
๎ FREE
๎ http://dev.mysql.com/downloads/
๎ Three tools in one
๎ Query Tool
๎ Admin Tool
๎ Entity Relationship Mapper
๎ Scripts available for setting up replication,
fail over and more
http://dev.mysql.com/doc/refman/5.5/en/getting-mysql.html 3
4. Did I mention free?
http://dev.mysql.com/downloads/workbench/ 4
8. Know whom
can do what
๎ We have four
accounts
๎ Anonymous (%)
๎ ODBC
๎ joe
๎ root
๎ ODBC and joe can
login from any host
while root and
anonymous are local
host only
8
9. Joe's Info
'joe' can connect to the mysqld server from any host.
Note he does not have a password which can be a
serious security concern.
9
htallation.html
13. Easier than ...
GRANT INSERT, UPDATE,
SELECT
ON world.*
To 'joe'@'%';
FLUSH PRIVILEGES;
13
14. Tables & Databases
Databases contain tables, which
are used for storing data.
Databases also contain objects
such as stored routines or
triggers. โ MySQl 5.0 Certification
Guide
httphtml 14
15. 1. CREATE DATABASE foo
2. (magic)
3. mkdir foo
๎ CREATE DATBASE
will create a directory
to house .frm files
๎ InnoDB tables will
have table spaces for
data & indexes
๎ MyISQM can also
have .MYD and .MYI
files for data and
indexes
15
16. Databases
๎ db.opt will hold info on
character sets,
collations.
๎ Databases can hold
zero or more tables
plus objects like view,
triggers
๎ Databases can not be
nested
16
22. Creating a Table
Create a table named stuff with a column named
member_id that is NOT NULL, AUTOINCREMENT,
UNSIGNED and a PRIMARY KEY
22
23. Review the SQL
We can see the
SQL that is about
to be executed to
create the table.
23
24. Double Check
๎ Any problems will be
show here as well as
success
24
25. SHOW CREATE TABLE
๎ Note that INT(10) means 10 characters will be
shown for output. INT(2) will show two places of
data by default but still holds upto 2147483647
signed or 4294967295 unsigned.
25
26. After adding
two more columns
For the sake of brevity,
two more columns have
been added for name and
email, both are stup to
hold CHAR data
26
28. Select data from stuff
Here we select data
from the table. Note
that member_id was
automatically filled in
for this record.
28
29. Add a few more
records
Here a few more records
have been added and the
member_id has again has
been incremented and
inserted.
29
30. Triggers
๎ Triggers are 'fired' in response to a an SQL
statement.
๎ They can happen before OR after an INSERT,
UPDATE, or DELETE event.
๎
๎ They can be used to check values, sum data, etc.
๎ You may not want 'logic' in your database and
prefer to have it in the application level.
30
31. Boss: We need to track
previous email addresses
๎ Lets track previous email address by placing them
in a new column creatively called oldemail.
31
33. Did you catch the mistake?
The previous trigger had a serious logical
flaw. Take a look at it and see if you can
spot it.
Hint: Is the email the only thing that will
ever get updated?
33
34. VIEWS
๎ Views are stored queries that when invoked
produce a result set. A view acts as a virtual table.
๎ Can be used to hide table and column names from
programmers.
๎ Can be used to gather information from many
tables into one view for simpler access (PHB
protector)
๎ Not materialized
34
35. Create a VIEW,
use as a table
๎ SELECT * from get_stuffg
๎ SELECT Customer from get_stuffg
35
36. Stored Routines
Stored Procedures
Stored procedures and Stored Routines take zero or more
arguments. A Stored Procedure can pass back values through
output variables or result sets. A function must output exactly
ONE scalar variable.
MySQL Follows the ISO:2003 SQL standard syntax for stored
routines.
And theses two subjects are not for newbies.
36