You are on page 1of 24

An Introduction to MySQL

for

Oracl e & MS D BA

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 1
Objectives
• Introduction MySQL the Company
• Architecture of MYSQL
• The Basic
• Configuration of MySQL
• Security
• User Management
• Backup and Restore
• Troubleshooting Step

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 2
The World’s Most Popular
Open Source Database

• Founded in Sweden in 1995; Privately Owned


• Employs over 300 people worldwide
• Over 10,000,000 installations
• 50,000 web downloads/day
• Part of a rapidly growing open source LAMP stack

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 3
MySQL Database Server – the 10 million!

Free

Community Edition
 Available under GPL
 Software tested by
Community + basic
MySQL AB testing
 Release early & often
cycle (3 to 4 weeks)
 Bleeding edge
 No maintenance SLA
 Not supported
 No ISV certification

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 4
MySQL Network

Free Supported

Community Edition MySQL Network


 Available under GPL  Software fully tested, certified and
1. Platform for Innovation
 Software tested by
Community + basic MySQL 
1. Platform for Stability
optimized by MySQL AB
Enterprise release cycles
AB testing (6 to 9 months)
 Release early & often cycle  Annual Subscription
2. Change
 is revolutionary
(3 to 4 weeks)
Bleeding edge  2. Change is evolutionary
Update Advisor
 No maintenance SLA  Technical Alert Advisor
 Not supported  Knowledge Base
3. Informal Communication
 No ISV certification 
3. Formal Support
Production Support
 Indemnification
Great for open source
developers & Great for enterprise
technology enthusisats customers and supported by
MySQL

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 5
Yahoo!

Application
MySQL powers over 200 Yahoo!
properties around the world including
Yahoo! Finance with 260 million rows.

Key Business Benefit


Low down time for high-volume, business-
critical applications. Using MySQL has
reduced cost by more than $2 million.

Why MySQL? Mission-Critical Reliability


“We have used MySQL far more than
anyone expected. We went from
experimental to mission-critical in a
couple of months.”
Jeremy Zawodny
MySQL Database Expert
Yahoo! Finance

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 6
MYSQL Architecture

indows™ : my.ini
C:\Program Files\MySQL\MySQL Server x.y\my.ini
Linux : my.cnf
/etc/my.cnf or /etc/mysql/my.cnf
/whereYouInstalledMySQL/data/my.cnf (server-specific options)
(@localstatedir@ for this installation)

~/.my.cnf (user-specific options)

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 7
Let’s st art working

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 8
The Basic
Connecting to and disconnecting from Server
shell > mysql –h localhost –u user –p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.67-community-nt MySQL Community
Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 9
The Basic
•Creating and Using Database
mysql> create database tutorial;
Query OK, 1 row affected (0.00 sec)
mysql> use tutorial;
Database changed

•Create a table
Shell>mysql -h localhost -u root -p tutorial
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> create table cheese ( Name varchar(15) not null, weight int not null,
-> primary key(name));
Query OK, 0 rows affected (0.13 sec)
Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 10
System File & Table
Configuration files
Windows™ : my.ini
C:\Program Files\MySQL\MySQL Server x.y\my.ini
Linux : my.cnf
/etc/my.cnf or /etc/mysql/my.cnf ( Global options)

/whereYouInstalledMySQL/data/my.cnf (server-specific options)


(@localstatedir@ for this installation)

~/.my.cnf (user-specific options)

Repository of tables & stuctures


Linux : /var/lib/mysql  or  /whereYouInstalledMySQL/data/
Windows™ : C:\Program Files\MySQL\MySQL Server x.y\data

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 11
Command -Start & Stop Server
In Window
Start MySql server:
c:\mysql\bin\mysqld-nt --standalone - You can leave the DOS window open or
close it.
Stop MySql server:
c:\mysql\bin\mysqladmin shutdown - This will shutdown the server.

If Mysql is install as services


c:\> net start mysql  - starts mysql database server.
c:\> net stop mysql - stops mysql database server.

In Linux
To start MySQL server
/etc/init.d/mysqld start
To stop MySQL server
/etc/init.d/mysqld stop
To check the status
/etc/init.d/mysqld status
Or
Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 12
Running external script

Manually:
mysql -u root -p -P 3306
create myDatabase
By a SQL script:

SQL commands, or:


source fichier.sql

mysql -u root -p < C:\fichier.sql

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 13
Security setting
• Set the root password
– The default installation of MySQL leave the root
password blank. So the first step to do when we login
is
Shell>mysql –uroot mysql
mysql> update user set password = PASSWORD('abc123') where
user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

mysql> flush privileges;


Query OK, 0 rows affected (0.00 sec)

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 14
Security setting
• List anonymous users:
• SELECT Host, User FROM mysql.user WHERE
User='';

• Delete anonymous users:


• DELETE FROM mysql.user WHERE Host='localhost'
AND User='';
• FLUSH PRIVILEGES; -- { Update and reflect change
on existing session}
• Careful: by default, root has no password !
 
• To set a password for root:
– mysqladmin -u root password unPassword

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 15
Security setting
• MySQL uses Access Control Lists (ACLs) for all
connections, queries, and other operations that a user may
attempt to perform. The ACLs are composed of tables which
are used to determine privilege.

MySQL access control involves two stages:

Stage 1 Connection Verification: The server checks whether


you are even allowed to connect.

Stage 2 Request Verification: Assuming you can connect, the


server checks each request you issue to see whether you
have sufficient privileges to perform it.

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 16
Security setting
• The server uses the user, db, and host tables in the mysql
database at both stages of access control.

• For the second stage of access control, the server may, if the
request involves tables, additionally consult the tables_priv and
columns_priv tables.

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 17
User Management
• The server uses the user, db, and host tables in the mysql
database at both stages of access control.
• For the second stage of access control, the server may, if the
request involves tables, additionally consult the tables_priv and
columns_priv tables.

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 18
Security setting
• Adding Users. MySQL users and their privileges are normally
created with GRANT statements. You may however edit the user
table manually with INSERT statements. Below are examples of
each.
Using GRANT statements.
shell> mysql --user=root mysql mysql> GRANT ALL PRIVILEGES ON *.* TO
cheese@localhost -> IDENTIFIED BY 'some_pass' WITH GRANT OPTION; mysql> GRANT
RELOAD,PROCESS ON *.* TO admin@localhost; mysql> GRANT USAGE ON *.* TO
dummy@localhost;
Using INSERT statements.
shell> mysql --user=root mysql mysql> INSERT INTO user
VALUES('localhost','cheese',PASSWORD('some_pass'), ->
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y'); mysql> INSERT INTO user SET
Host='localhost',User='admin', -> Reload_priv='Y', Process_priv='Y'; mysql> INSERT INTO
user (Host,User,Password) -> VALUES('localhost','dummy',''); mysql> FLUSH PRIVILEGES;

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 19
Mysqldump-backup

A simple example of creating a backup of one database is the following:

mysqldump --opt database > backup-file.sql


You can then restore it like so:
mysql database < backup-file.sql

It is possible to dump several databases with one command:


mysqldump --databases database1 [database2 ...] > my_databases.sql

If all the databases are wanted, one can use:


mysqldump --all-databases > all_databases.sql

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 20
Basic MySQL syntax (i)
Use the "mysql" Database
use mysql;
Show a list of Tables in the Database
show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| proc |
| procs_priv |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 21
Basic MySQL syntax

•SHOW DATABASES;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
USE database_name;

List data from "user" table


select Host, User, Password from user;
select * from user;
select * from user\G; { in row order}

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 22
Summary useful command
•mysql -u root -p -P 3306
mysql> status
mysql> show status ;    (<=> mysqladmin -u root -p extended-status)

mysql> show warnings ;


mysql> show variables ;
mysql> show processlist ;
mysql> show full processlist ;
mysql> show databases ;
mysql> connect mysql;    ("system" tables of MySQL)
 mysql> show table status\G
mysql> show table status like "a_table"\G
mysql> connect myDatabase ;    ( or: mysql> use myDatabase)
mysql> show tables ;
mysql> describe a_table ;
EXPLAIN - useful for optimize & debug SQL requests
example: mysql> explain SELECT ...
InnoDB
Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 23
Connection test
•Linux : check if mysqld is configurated to start in current init level:
[root]# chkconfig mysql
[root]# echo $?
 
Check if mysqld is started
 
telnet localhost 3306
 
mysqladmin -u root -p ping
mysqladmin -u root -p status
mysqladmin -u root -p extended-status
mysqladmin -u root -p processlist

Copyright 2006 MySQL AB The World’s Most Popular Open Source Database 24

You might also like