Download mysql

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

Concurrency control wikipedia , lookup

Microsoft Access wikipedia , lookup

Oracle Database wikipedia , lookup

Database wikipedia , lookup

Functional Database Model wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

SQL wikipedia , lookup

PL/SQL wikipedia , lookup

Ingres (database) wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Clusterpoint wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Relational model wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

Database model wikipedia , lookup

Transcript
Software-Projekt 2008
Seminarvortrag“Short tutorial of MySql“
Wei Chen
Verena Honsel
What is MySQL ?
MySQL = my Structured Query Language
A relational database management system
Open source software
Basis for many dynamic websites
Storage engines
How to install MySQL?
Download:
The MySQL official website
http://dev.mysql.com/get/Downloads/MySQL-5.0/mysqlessential-5.0.67-win32.msi
And the MYSQL GUI-TOOLS will be also needed
http://dev.mysql.com/get/Downloads/MySQLGUITools/mysqlgui-tools-5.0-r13-win32.msi
Install MySQL Server
Double click The installation
file as a .msi file.Then on the
window click “Next>”.
Install MySQL Server
The next window:
click the radio button
"Custom", and then click
"Next>" you can change the
destinition folder or do
nothing just “Next>”.
Install MySQL Server
then click the "change" button
and choose another folder.
Install MySQL Server
Now MySQL Server is ready to
install,click “install”.
Install MySQL Server
Leave the check box "Configure
the MySQL Server Now"
checked , and click “Finish”.
On the next window, click the
radio button "Standard
Configuration", and then click
"Next>".
Install MySQL Server
On the next window make sure
"Install As Windows Service"
and "Launch the MySQL Server
Automatically" check boxes are
checked. Click "Next>".
Install MySQL Server
On the next window need to
create a root password. Type in
what you want your root
password be and make sure
"Enable root access from
remote machines" is checked.
Install MySQL Server
On the next window, after you
have clicked "Execute". This
will start the MySQL server.
After MySQL has done its
thing, click "Finish".
MySQL was in fact installed
sucessfully ?
click "Start">"All
Programs">"MySQL">"MySQL
Server 5.0">"MySQL
Command line client".
Enter your root password and
you ´ve connected Server.
a command-line client tool
that is installed as standard
with the MySQL package.
MySQL Commands
From the mysql commandprompt it is possible to issue
a wide range of commands
to the database server such
as creating and deleting
databases and tables,
searching for data, adding
new rows and much more.
MySQL Commands
MySQL Commands
For a list of these commands, type
help or \h at the mysql> prompt.
clear (\c) Clear command.
Clears the current input. Use this if
you change your mind about
executing the statement that you
are entering.
connect [db_name host_name]], \r
[db_name host_name]]
Reconnects to the server. The
optional database name and
hostname arguments may be given
to specify the default database or
the host where the server is
running.
use db_name, \u db_name
Uses db_name as the default
database.
show databases
This command id used to list all
databases on the sql server.
Syntax: show databases;
show tables
This command is see all the
tables in the database.
exit, \q
Exits mysql.
go, \g
Sends the current statement to
the server to be executed.
MySQL Commands
MySQL Commands
How to create database,
and new users:
mysql> create database
database01;
-> created a new blank
database and folder in the
mysql \ data
mysql> use database01;
->open the database
mysql> show tables;
-> lists the tables on this
database
Install MySQL Server
mysql> create table table01 (field01
integer, field02 char(10));
-> Sets empty table with Columns
field01 in which numbers are
available and may field02 in strings of
up to 10 characters are allowed.
mysql> show columns from table01;
-> delivers the columns from table01
mysql> insert into table01 (field01,
field02) values (1, 'first');
-> Inserts into the table table01 the
values 1 (in column field01) and 'first'
(in column field02)
mysql> select * from table01;
Install MySQL Server
Create Columns:
mysql> alter table table01 add
column field03 date, add column
field04 time;
-> Adds to the table table01
columns field04 (only records the
data type date allowed) and field05
(only records the data type of time
allowed)
mysql> insert into table01
(field01,field02,field03,field04)
values (2, 'second', '1999-10-23',
'10:30:00');
Install MySQL Server
Create new user:
mysql> create user user01 [identified by password];
-> create new user user01 (with optional password)
First, no privileges
mysql> drop user user01;
-> delete user01
Rights award (Rechtevergabe)
mysql> GRANT select, insert ON table01 TO user01 WITH GRANT OPTION;
allows user01 to retrieve data from table table01 and add items.
Install MySQL Server
-> Using the additional 'WITH
GRANT OPTION‘ user01 will be
allowed himself to forgive
Rights / withdraw.
mysql> REVOKE ALL PRIVILEGES,
GRANT OPTION FROM user01;
-> Cut user01 any rights
Install MySQL GUI TOOLS
The Same to Install for MySQL Server
It was finished too.
How to use MySQL
MySQL Administrator:
keep the MySQL Server running
,then start MySQL Administrator,
it displays a connection dialog
box.
To connect to a newly installed
server, you need the host
‘localhost’, the user ‘root’ and the
password that you sent during
installation.
How to use MySQL
After you have successfully
connected to your MySQL
server, the main window
of MySQL Administrator
appears.
The sidebar consists of the
following options…
How to use MySQL
For us 3 options are more
important:
1.Server Information:
It is about the MySQL
server you are connected
to, about MySQL
Administrator and the
machine that it runs on,
and about your
connection.
How to use MySQL
2. User Administration :
the next importants point
is User Administration,
how to administer existing
users:
Right clicking on a
username, or on one of
the subcategories a user
might have.
- add new users
- delete existing users.
How to use MySQL
2. User Administration :
You will have to fill a
username
password
in the User Information
tab, which, after applying
this change.
You can also give some
information in the
Additional Information tab.
How to use MySQL
3. Catalogs :
We selected catalogs
Existing catalogs and
schemata are listed in the
lower left area of the
sidebar.
You can also create a new
database.
right-click the "mysql",
select "Create New Schema”
How to use MySQL
3. Catalogs :
enter the name of the
database, here Vorlesung
ws08.a new datebase has
been created.
How to use MySQL
3. Catalogs :
"Create Table" button, then
the following dialog box will
appear. and give a name for
the table"Pflichtsfach",
then we can add
attributs,id field for the
primary key is necessary,
for another as you will.
Click "Apply Changes"
button will appear below
the window,it is a table to
create the SQL
statement.Click "Execute"
How to use MySQL
MySQL Query Browser:
Now we can add data to our database Vorlesung ws08,open the
MySQL Query Browser, then log on the server.
MySQL Query Browser displays a window that you can use for issuing
queries.
How to use MySQL
MySQL Query Browser
You can see 3 parts:
-The top part of the window
contains an area for
entering queries.
-At the lower left, a result
area displays results from
queries.
-At the right, there are two
browser areas.
How to use MySQL
MySQL Query Browser
Double-clicking Vorlesung
ws08 selects it as the default
database.
Double-clicking a
table name enters a SELECT
* FROM Pflichtsfach
statement in the query area.
you can also use sql
commands to change the
table or add new tables in
the query area.
SQL Commands
Introduce to the SQL Commands with MySQL Query Browser.
Practicaly using: Explains and example
1. The SQL syntax for CREATE TABLE is
CREATE TABLE "table_name“ ("column 1" "data_type_for_column_1", "column 2"
"data_type_for_column_2",... )
2. Data tables have no sense. That is why we want with the command INSERT INTO A few paste
data.
The syntax is: INSERT INTO table_name [ (feld_name,...) ] VALUES (werte,...)
3. The SQL SELECT clause selects data from one or more database tables and/or views.
SELECT * FROM table,(example to MySQL QB..SELECT name FROM pflichtsfach p;)
SQL Commands
SELECT zeit FROM pflichtsfach p where p.ort = "F-128"
order by p.zeit
-where : we might want to conditionally select the data from a table
-order by: defines in what order to return a data set retrieved with a SQL SELECT
statement.
4. DELETE FROM: is used to delete data from a database table.
Syntax: DELETE FROM table_name [WHERE where_definition]
example: delete from pflichtsfach where zeit >"2008-10-16"
5. UPDATE: serves to update data in database table.
Syntax: UPDATE "table_name“ SET "column_1" = [new value] WHERE {condition}
example: update pflichtsfach set zeit = "2008-10-12" where name = "Numerik"
SQL Commands
6. DROP TABLE: to drop the table called Nebenfach
7. ALTER TABLE
here are many occasions where one may wish to change the structure of the table. Typical cases include the
following:
- Add a column
- Drop a column
- Change a column name
- Change the data type for a column
example : ALTER table Pflichtsfach add klausur char(40)
or we want to rename "name" to "vname": ALTER table Pflichtsfach change name vname char(40)