Download MySQL-server

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

IMDb wikipedia , lookup

Microsoft Access wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Oracle Database wikipedia , lookup

Concurrency control wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Database wikipedia , lookup

Ingres (database) wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

SQL wikipedia , lookup

ContactPoint wikipedia , lookup

Clusterpoint wikipedia , lookup

PL/SQL wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
Installation of MySQL
• Objectives
– Install MySQL
• Contents
–
–
–
–
–
–
Getting the enviroment for building MySQL server
Rebuilding SRPMS
Removing existing
Installing new MySQL
Verify installation
Creating MySQL admin
• Practical
– Install MySQL
• Summary
Developers enviroment needed
• Developers enviroment needed
– If you want to install applications from SRPMS or TAR packages
– There are many dependencies so for most comfort use: # yast
– Get development tools and enviroment is needed:
ncurces
ncurces-devel
binutils
gcc
glibc-devel
gcc-c++
gcc-objc
gcc-locale
Then click on Update and follow instruction’s
Install original MySQL, Apache & PHP
• It is a good idea to have RedHat original servers
– You will have all files, and only need to update
– There are many dependencies so for most comfort use:
– Get the webserver and the nessesary addons:
Web Server (add PHP, SQL, PERL)
SQL Database (check MySQL)
– Then click on Update and follow instruction’s
# yast
Rebuild MySQL from SRPMS
• Adding user mysqldev
• Get MySQL
# useradd –m –d mysqldev
http://dev.mysql.com/downloads/
– Since we use SuSE or RedHat which is RPM based we get the SRPMS
• Download MySQL SRPM to /usr/local/src
# cd /usr/local/src
# wget http://ftp.sunet.se/pub/unix/databases/relational/mysql/Downloads/MySQL-5.0/MySQL5.0.18-0.src.rpm
• Rebuild Source RPM
– This operation needs lot of diskspace > 660 MByte and time
# rpmbuild --rebuild MySQL-5.0.18-0.src.rpm
– Process take between 1 to 4 hour to complete!
Check rebuilded packages
• Rebuilded SRPMS en up in: /usr/src/packages/RPMS/i386
• Check that the rebuild created this files:
# cd /usr/src/packages/RPMS/i586
# ls –1
MySQL-bench-5.0.18-0.i586.rpm
MySQL-client-5.0.18-0.i586.rpm
MySQL-debuginfo-5.0.18-0.i586.rpm
MySQL-devel-5.0.18-0.i586.rpm
MySQL-embedded-5.0.18-0.i586.rpm
MySQL-Max-5.0.18-0.i586.rpm
MySQL-server-5.0.18-0.i586.rpm
MySQL-shared-5.0.18-0.i586.rpm
• SRPMS can also be generated for specific CPU
– Then you have to check proper sub-catalogs i486/, i686/. . .
Removing old MySQL and installing new
• Removing old MySQL libraries, ignoring dependecies
rpm –qa | grep –i mysql
. . .
mysql-3.23.54a-11
. . .
rpm -e --nodeps mysql-3.23.54a-11
• Installing new MySQL and subcomponents
cd /usr/src/packages/RPMS/i586
rpm -ivh MySQL-shared-5.0.18-0.i586.rpm
rpm -ivh MySQL-server-5.0.18-0.i586.rpm
rpm -ivh MySQL-devel-5.0.18-0.i586.rpm
rpm -ivh MySQL-client-5.0.18-0.i586.rpm
rpm -ivh MySQL-debuginfo-5.0.18-0.i586.rpm
Checking installation
• Check that all files are there
rpm -qa | grep -i mysql
MySQL-shared-5.0.18-0
MySQL-debuginfo-5.0.18-0
MySQL-server-5.0.18-0
MySQL-client-5.0.18-0
MySQL-devel-5.0.18-0
mysql-administrator-1.0.19-3
perl-DBD-MySQL-2.9004-3
• The rpm –qa takes some time, have pation
• We also installed mysql-admin, as you can see.
• The module perl-DBD is needed for API
– Use yast to install perl-DBD and mysql-admin
Start service & Create MySQL admin
• Starting MySQLd service
# /etc/init.d/mysql start
Before you can do anything with MySQL it must be running and you must have a
client installed.
Check logfiles tail /var/log/messages to se any startup error
• Creating MySQL admin user
# /usr/bin/mysqladmin -u root password 'qwerty'
# /usr/bin/mysqladmin -u root -h server.my-site.com password 'qwerty'
# /usr/bin/mysql_fix_privilege_tables
• Test MySQL
# mysql –u root –p
Enter password:
mysql> create database test;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
mysql> drop database test;
mysql> exit;
Learn SQL basics, create new database
• Login as administrator in MySQL
• Create a new database
mysql> create database gronsaker;
Query OK, 1 row affected (0.01 sec)
• Check that the database exist
mysql> show databases;
+-------------+
| Database |
+-------------+
| gronsaker |
| mysql
|
| test
|
+-------------+
3 rows in set (0.00 sec)
# mysql -u root -p
password:*******
mysql>_
Learn SQL basics, connect & create
• Connect to the database with connect or use
mysql> connect gronsaker;
Database changed
mysql> use gronsaker;
Database changed
• Check if database haves tables for data
mysql> show tables;
• Create listuser for anonymous secure read only access
mysql> grant select on gronsaker.* to listuser@localhost
identified by '123456';
• Create the first table vara with product namn and pris
mysql> create table gronsaker.vara(namn char(15), pris float);
- namn and pris is known as columns in table vara
• Check that the table vara was created with describe or
show mysql> describe vara;
mysql> show columns from vara;
Learn SQL basics, adding & viewing data
• Add a banan worth 5 kr to vara
mysql> insert into vara (namn,pris) values ('banan','5.0');
• Add äpplen, tomater, potatis, isbergssallad and jordgubbe
mysql>
mysql>
mysql>
mysql>
insert
insert
insert
insert
into
into
into
into
vara
vara
vara
vara
(namn,pris)
(namn,pris)
(namn,pris)
(namn,pris)
values
values
values
values
('apple','2.0');
('tomat','1.0');
('potatis','1.0');
('isbergssallad','12.0');
mysql> insert into vara (namn,pris) values ('jordgubbe','0.5');
• Check that we got our apples etc. Into database
mysql> select * from vara;
+---------------+-------+
| namn
| pris |
+---------------+-------+
| banan
| 5
|
| apple
| 2
|
| tomat
| 1
|
| potatis
| 1
|
| isbergssallad | 12
|
| jordgubbe
| 0.5
|
+---------------+-------+
6 rows in set (0.07 sec)
Learn SQL basics, adding new column
• Add one column lager to table vara
mysql> alter table vara add column lager integer;
• Check that the new column was created
mysql> select lager from vara;
+-------+
| lager |
+-------+
|
|
|
|
|
|
|
|
|
|
|
|
+-------+
6 rows in set (0.00 sec)
• Set 1000 products in each cathegory
mysql> update vara set lager='1000';
Learn SQL basics, changing data on one post
• Check that we now have 1000 products in each cathegory
mysql> select * from vara;
+-----------------+-----+-------+
| namn
| pris| lager |
mysql>
select lager from vara;
+-----------------+-----+-------+
+-------+
| banan
| 5
| 1000 |
| lager |
|
apple
| 2
| 1000 |
+-------+
|
|
| tomat
| 1
| 1000 |
|
|
| potatis
| 1
| 1000 |
|
|
|
| 12 | 1000 |
| isbergssallad
|
|
|
| jordgubbe
| 0.5 | 1000 |
|
|
+-----------------+-----+-------+
+-------+
6
rowsin in
sec)
6 rows
set set
(0.00(0.00
sec)
• We have only 500 bananer so update only banan
mysql> update vara set lager='500' where namn='banan';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
Learn SQL basics, modifying tables
• Add a limited administrator gadmin for database gronsaker
mysql> grant delete,insert,select,update on gronsaker.* to
gadmin@localhost identified by '123456';
• Test the limited administrator
• Add 123 gurkor of value 1.1 Kr
# mysql -u gadmin -p
password:******
mysql> use gronsaker
mysql> insert into vara (namn,pris,lager) values
('gurka','1.1','123'); Query OK, 1 row affected (0.00 sec);
• We check that we got gurkor
mysql> select * from vara;
+-------------+------+-------+
| namn
| pris | lager |
+-------------+------+-------+
| banan
| 5
| 500
|
| apple
| 2
| 1000 |
| tomat
| 1
| 1000 |
| potatis
| 1
| 1000 |
| isbergssallad | 12 | 1000 |
| jordgubbe
| 0.5 | 1000 |
| gurka
| 1.1 | 123
|
+---------------+------+-----+
7 rows in set (0.00 sec)
Learn SQL basics, working with tables
• 5 bananas is sold, update database
mysql> update vara set lager='495' where namn='banan';
• Check the new banana status, b% show all that begin with
b, like b* mysql> select lager from vara where namn like 'b%';
+-------+
| lager |
+-------+
| 495
|
+-------+
1 row in set (0.00 sec)
• Some more matching expressions
like)
% all characters, more than one
_ all characters, but only one
rlike) regular expressions
. All characthers, but only one
* all characters, more than one
[a-z] any character in the interval
Learn SQL basics, working with tables
• Limit your search result to the 3 first found
mysql> select * from vara limit 3;
• Which wares costs more than 2 Kr ?
mysql> select namn from vara where pris > 2;
• Remove all wares that costs more than 2 Kr
mysql> delete from vara where pris > 2;
• There are offcourse much more to learn about databases.
Recomended books:
PHP 5 PROGRAMMERING
ISBN:9163608006
DEN SNABBA VÄGEN TILL GRUNDERNA I MYSQL
ISBN:9163608308
• Next we will setup Apache2 webserver