Академический Документы
Профессиональный Документы
Культура Документы
MYSQL is free to use and it needs a server to run. Because of the restrictions imposed
to the school’s computers we can’t run MYSQL Server directly on the computer labs. To
go around this we have to install everything you need to learn these concepts on a
portable flash memory.
You will also install Apache Server, PHP, Perl, etc. that could be used later. All these
could be installed separately, but it could create a lot of problems. We are going to
install an application that contains all of the above in one standalone portable file. It is
called XAMPP (one of many…).
Navigate to the folder on the flash drive. Go at the bottom of the folder and click and
open the “xampp-control.exe” file that will show the GUI control centre.
1
Now, that the server started we can actually use MYSQL. To do so we have to navigate
to the MYSQL folder and from there to a special folder called BIN. This is where most
of the “binary” files of the programs are stored.
When you reached the folder you should be like in the picture:
2
To start the program you have to type “MYSQL” in the command prompt. This program
will allow you to interact with the MYSQL Server. We do not worry about user
privileges or admin account for the moment (more about this at the end of tutorial).
If the server was started before and you navigated properly you should see this:
All the databases you create with all the tables are stored in a file called DATA. We are
going to use, at the beginning, a database that exists by default and is empty. It is
called TEST. This is for trying the MYSQL for the first time. Later we are going to
create users and grant them privileges to create databases.
The “mysql>_” is called the prompt and it is the place where the commands are shown
when you type. The underscore sign will always flash.
All commands will finish in semicolon. You have to press enter to execute them. If you
type something wrong and you want to cancel that command type “\c”.
3
Try firstly to find the version of the MYSQL used:
Let’s create our first table. Copy and paste the entire code shown below (this could be
entered on one line or on multiple lines as long you do not enter the semicolon):
create table if not exists players
( name VARCHAR(100) PRIMARY KEY,
password VARCHAR(100),
amount_money INT(10),
account_name VARCHAR(50)
);
4
Lets see what happened:
We can look at the design structure of the table (like a design view):
Good we have a table but it is empty. We should put something in it. We have two
options to add records in the table. Line by line or to read from a file.
Now we
should check
if the table
has the
values we just inserted. To do so we have to write our first QUERY. The quesry in
English is: “show everything from table players”:
5
Multiple entries using “load data” from a file.
Create a text file like this (add what ever you want as long you maintain the structure):
To copy the data from the file and insert them to the table do this:
load data local infile '../data/test/players.txt' into table players lines terminated by ‘\r\n’;
We can write another query, “show the names of all people with a credit account”:
6
The rules for queries is :
select WHAT
from TABLE
where CONDITION
Lets try another one, “show name and amount of money of people with less than 1000
money into their account”:
Good, one more, “show the names of all people with 10000 in their account and the
type of account is check” :
You can also sort, “show the names of all clients sorted alphabetically”:
All the statistical queries you learned in Access could be aplied here: count, group, etc.
7
Now we should delete some entries from the table:
Also you can do query in a query, “show everything for the client that has the biggest
amount in to account”:
So this is in brief MYSQL. You can also use multiple tables and query both of them
separatelly or you can join them. All about this later.
Do not forget to stop the MYSQL server from XAMPP command GUI.
8
If you want to create users (as admin) in order to create databases do the following:
(the pictures are from my local computer but it works for XAMPP anyway)
Now you have to give full privileges (in real life you don’t do such a thing, but for this project you are admin
and user)”
You have to start MYSQL with this (it will prompt for password):
mysql -u wwwuser1 -p
9
In the end you will have to create a database for the user you just created. Or you access the
MYSQL as admin or as user and then you use the following command to create the database:
CREATING THE USER AND A DATABASES FOR THE USER HAVE TO BE DONE BEFORE YOU START
THE PROJECT. YOU DO THIS USING THE ABOVE COMMANDS OR A GUI OPTION CALLED
“MYPHPADMIN”:
10