Sunteți pe pagina 1din 4

- Mysql 5.0/5.

1 Table of Contents:
Lesson 1 : Showing the basics
Lesson 2 : Creating Tables & DBs
Lesson 3 : Adding / Updating / Displaying data
Lesson 4 : Backing up a DB
Lesson 5 : Restoring a DB
Lesson 6 : Destruction of tables and DBs
Lesson 7 : Config's
Lesson 8 : Self Exploration
Lesson 9 : Challenge
Lesson 1 : Showing the basics
Showing databases.
mysql> show databases;
Utilizing a Database using the "mysql" database as an example.
mysql> use mysql;
Showing tables in our example database "mysql".
mysql> show tables;
We will now describe the table "user" in the "mysql" database.
mysql> desc user;
Showing users in the "mysql" in the "user" table.
mysql> select * from user;
To Select the Host,User,and Password
mysql> select host, user, password from user;
If you describe "user" you will see these are 3 feilds listed in here.
This is how you can tell what your able to select.
mysql> desc user;
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field
| Type
| Null | Key | Default | Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host
| char(60)
| NO
| PRI |
|
|
| User
| char(16)
| NO
| PRI |
|
|
| Password
| char(41)
| NO
|
|
|
|

Lesson 2 : Creating Tables & DBs


Creating a database called "example".
mysql> create database exampledb;
Creating tables using DataTypes such as varchar, int, Date Time:
mysql> use exampledb;
mysql> create table exampletable(
user varchar(255),

descr char(255),
Login int(10),
SignupDate DATETIME NOT NULL,
SignupUnix TIMESTAMP NOT NULL
);
For other DataTypes view my supplemental documentation:
MySQL_DataType_supplemental.pdf
View your new table!
mysql> desc exampletable;
mysql> select * from exampletable;
Empty set (0.00 sec)
Yep Empty set = No data in table. We will come back to this later,
and add data!
We will now Creating a user for our DB.
mysql> grant all on exampledb.* to 'exampleuser'@'localhost' identified
by 'test' with grant option;
Above allows you too effectively have root over the exampledb, but what
if you need a user to have limited access? We are going to grant basic
priviledges.
mysql> grant Select,Insert,Update on exampledb.*
to 'exampleuser1'@'localhost' identified by 'test1' with grant option;
Above creates a user with read, write, and update priviledges only.
To Revoke priviledges, take a look at this page and try to figure it out :)
http://dev.mysql.com/doc/refman/5.0/en/drop-user.html
Lesson 3 : Adding / Updating / Displaying data
Now we are going Inserting values or add information to our database.
mysql> insert into exampletable (user,descr,login) values ('TheDude','The
Dude is a user',1);
mysql> select * from exampletable;
+---------+--------------------+-------+---------------------+---------------------+
| user
| descr
| Login | SignupDate
| SignupUnix
|
+---------+--------------------+-------+---------------------+---------------------+
| TheDude | The Dude is a user |
1 | 0000-00-00 00:00:00 | 2011-03-13 05:17:46 |
+---------+--------------------+-------+---------------------+---------------------+

1 row in set (0.00 sec)


So Lets update "TheDudes" info with the Updating values.

mysql> update exampletable set descr='Updated


TheDude',Login='0',SignupDate=NOW() Where user='TheDude';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from exampletable;
+---------+-----------------+-------+---------------------+---------------------+
| user
| descr
| Login | SignupDate
| SignupUnix
|
+---------+-----------------+-------+---------------------+---------------------+
| TheDude | Updated TheDude |
0 | 2011-03-13 05:21:58 | 2011-03-13 05:21:58 |
+---------+-----------------+-------+---------------------+---------------------+

1 row in set (0.00 sec)


Lesson 4 : Backing up a DB
Using mysqldump to produce a SQL dump/backup
#> sudo mysqldump -u root -p exampledb > exampledump.sql
Lesson 5 : Restoring a DB
Restoring a SQL dump
#> sudo mysqldump -u root -p exampledb < exampledump.sql
Lesson 6 : Destruction of tables and DBs
Dropping tables
mysql> drop table exampletable;
Dropping databases
mysql> drop database exampledb;
Lesson 7 : Config's
I just want you too go through a few things so you know where they are and
what they are, but first we need to find the config file.
#> locate my.cnf
/etc/mysql/my.cnf
We want to verify this file has a logging entry. You'll see a line like:
log_error

= /var/log/mysql/error.log

We also want to verify that we can access this mysql server from the
outside. We will have to verify the bind-address is not set to local host or
127.0.0.1 :
#bind-address

= 127.0.0.1

<-- This is what you should see/

Lesson 8 : Self Exploration


Check out these commands, they are some of the tools provided by mysql.
#> sudo mysql_upgrade -u root mysql

#>
#>
#>
#>
#>

sudo
sudo
sudo
sudo
sudo

mysqlcheck -A
mysqloptimize -A
mysqlcanalyze -A
mysqlreport
mysqlshow

Lesson 9 : Challenge
Installing wordpress :D
HINT:
http://codex.wordpress.org/Installing_WordPress#Famous_5-Minute_Install

S-ar putea să vă placă și