Database server Campus-Booster ID : ****** www.supinfo.com Copyright © SUPINFO. All rights reserved MySQL
Jan 19, 2016
Database serverCampus-Booster ID : ******
www.supinfo.com
Copyright © SUPINFO. All rights reserved
MySQL
Your trainer…
Title: **Enter title or job role.
Accomplishments: **What makes the presenter qualified to present this course.
Education: **List degrees if important.
Publications: **Writings by the presenter on the subject of the course or presentation.
Contact:**Campus-Booster ID: [email protected]’s Name
MySQL
Course objectives
Install Mysql. Server installation and configuration
Use Mysql
Replicate Mysql
By completing this course, you will:
MySQL
Course topics
Introduction. MySQL History and concepts
Configuration. client-server installation and configuration
MySQL Usage.
Course’s plan:
MySQL
Introduction
What’s MySQL ?
MySQL
Preview
History
What’s MySQL
Comparison
Introduction
History
First version : May,23 1995
Created by Michaël Widenius in Sweden
Under GPL License with the version 3
In June 2000
Redeem by Sun Microsystems
FOSS (Free and Open Source Software)
Commercial License
Current version 5.1
Introduction
What’s MySQLMySQL is a RDBMS
MySQL is a relational SQL database server OpenSource SoftwareMulti OS :
•Linux
•Mac OS X
•WindowsThe most used DBMS all over the worldLightweight resources neededCluster supported with the Version 4.1
Introduction
Comparaison
The different versions of MySQL
Features MySQL 3.x
No
No
No
No
No
MySQL 4.0
Partial
No
No
No
No
MySQL 5.x
Yes
Yes
Yes
Yes
Yes
Subquery
View
Foreign Keys
Triggers
Constraints
Introduction
Stop and thinkIntroduction
Do you have any questions?
Configuration
Configuration of MySQLv5
MySQL
Preview
Installation
Configuration
Configuration
Installation
Installation with binary
Recommended
Download it :
http://dev.mysql.com/downloads/
Installation with packages tools
Needs to update the sources list
Configuration
Installation
Launch the server
Use the automatic rc script
Manual Launch :
mysqld_safe usage comparative to mysqld:
In case of problems reboot the server
logging
Give parameters to mysqld
Configuration
# /etc/init.d/mysqld start# /etc/init.d/mysqld start
# /usr/bin/mysqld_safe start# /usr/bin/mysqld_safe start
Configuration
Only one configuration file
my.cnf
For the server like for the client
Based on a section structure
Example of a configuration file :
Configuration
Stop and thinkConfiguration
Do you have any questions?
Basic usage
Basic usage of MySQL 5
MySQL
Preview
Define an admin password
Manage users
Create/Delete a database
Administration tools
Basic usage
Define a root password
By default the root password is empty
Adding a password for the root account :
or with mysqladmin command:
An user exists once he has rights on a table
# mysql -u root
mysql> GRANT ALL PRIVILEGES ON *.* TO
'root'@'localhost' IDENTIFIED BY
'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
# mysql -u root
mysql> GRANT ALL PRIVILEGES ON *.* TO
'root'@'localhost' IDENTIFIED BY
'password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
Basic usage
# mysqladmin -u root password <root_password># mysqladmin -u root password <root_password>
Listing existing usersBasic usage
A simple SQL statement :
mysql> SELECT user,password,host FROM mysql.user;
+---------+------------+-------------------+
| user | password | host |
+---------+------------+-------------------+
| root | *A4E990E4… | localhost |
| root | | Arbalest |
| supinfo | *06CDF16C… | linux.supinfo.com |
+---------+------------+-------------------+
3 rows in set (0.01 sec)
mysql> SELECT user,password,host FROM mysql.user;
+---------+------------+-------------------+
| user | password | host |
+---------+------------+-------------------+
| root | *A4E990E4… | localhost |
| root | | Arbalest |
| supinfo | *06CDF16C… | linux.supinfo.com |
+---------+------------+-------------------+
3 rows in set (0.01 sec)
Create a database
With mysqladmin
Within MySQL client (SQL statement)
# mysqladmin -p create mandriva # mysqladmin -p create mandriva
mysql> CREATE DATABASE mandriva;mysql> CREATE DATABASE mandriva;
Basic usage
Delete a database
With mysqladmin
Within MySQL client (SQL statement)
Basic usage
# mysqladmin -p drop mandriva# mysqladmin -p drop mandriva
mysql> DROP DATABASE mandriva;mysql> DROP DATABASE mandriva;
Note
Every
command in
basic usage is
a SQL
statement
Basic usage
Administration tools
Many MySQL tools are available:
Installed with the server
mysql_install_db, mysql_find_rows, mysql_manager
Non-free Clients
MySQL explorer, MySQL tracer
Web Clients
PHPMyAdmin
Basic usage
Stop and thinkBasic usage
Do you have any questions?
Replication
Setting up replication with MySQL
MySQL
Preview
What’s a replication?
Setting up the master
Setting up the slave(s)
Replication
Overview
Setting up a replication
Characteristics:
Unidirectional: Master -> Slave(s)
Binary log file usage
Element of concern:
The database
What for?
Fault tolerance
Load balancing
Replication
Replication account
Replication user creation
Rights attribution replication slave
Command used GRANT statement
Replication
mysql> GRANT replication slave,replication client,
super,reload ON *.* TO 'user'@'%'
IDENTIFIED BY 'password'
mysql> GRANT replication slave,replication client,
super,reload ON *.* TO 'user'@'%'
IDENTIFIED BY 'password'
Setting up the master
Configuration of the master and database archiving
Configuration
Adding options
• log-bin: Active the creation of binary log
• server-id: master’s unique number
Command used for manual replication
Replication
# cd /var/lib/mysql# tar -cvjf mysql-database.tar.bz2 test# cd /var/lib/mysql# tar -cvjf mysql-database.tar.bz2 test
Setting up the slave(s)
Slave configuration
Configuration
Adding options
• master-host: master server name
• master-user: replication account username
• master-password: replication account password
• master-port: server port
• server-id: slave’s unique number (mandatory)
Replication
Setting up the slave(s)
Activate the replication (after creating the same database on both servers)
Command :
Replication
Mysql > LOAD DATA FROM MASTER;Mysql > LOAD DATA FROM MASTER;
Setting up the slave(s)
Uncompressing the database
Command for uncompressing
Replication
# cd /var/lib/mysql
# tar -xvjf mysql-database.tar.bz2
# cd /var/lib/mysql
# tar -xvjf mysql-database.tar.bz2
Note
The
replication is
done, you
just have to
restart the
master and
the slave(s)
Replication
Stop and thinkReplication
Do you have any questions?
MySQL setup
Basic usageMySQL
Replication
Course summary
Installation of MySQL
MySQL
For more
CoursesPublications
Web sites
Introduction to databases
If you want to go into these subjects more deeply…
www.labo-linux.com
www.dunod.fr
MySQL
Congratulations
You have successfully completed the SUPINFO course module
MySQL
The endMySQL