Вы находитесь на странице: 1из 18

MySQL

MySQL (
).
, IBM DB2, Firebird.
(
DNS). ..
,
, . .
.

12

13

. ,
SQL (.. SQL).
MySQL . ,
, .

SQL
SQL structured query language.
, .
, . ,
,
, . :

..

1975

..

1986

45/3


. , ,
. .
MySQL PRIMARY KEY.
SQL () (
=) ).
, , . MySQL

TINYINT , -128 127 0


255
SMALLINT , -32768 32767 0
65535
MEDIUMINT , -8388608
8388607 0 16777215
INT , -2147483648
2147483647 0 4294967295
BIGINT , -9223372036854775808
9223372036854775807 0 18446744073709551615
FLOAT .
-3.402823466E+38 -1.175494351E-38, 0, 1.175494351E-38
3.402823466E+38.
DOUBLE -
. -1,7976931348623157E+308 -2,2250738585072014E308, 0, 2,2250738585072014E-308 1,7976931348623157E+308
()
CHAR 255 ,
VARCHAR , VARCHAR

BLOB ,
. BLOB 65535 .
MEDIUMBLOB BLOB,
DATE '1000-01-01' '9999-12-31'
, + 1
16,777,215 (16 )
LONGBLOB , 4 .

DATE '1000-01-01' '9999-12-31'
DATETIME . '1000-01-

TIMESTAMP 1970-01-01.
'1970-01-01 00:00:01' UTC '2038-01-09 03:14:07' UTC
TIME . '-838:59:59' '838:59:59'
YEAR[(2|4)] .
1901 2155, 0000.
70 69, 1970 2069.
, .

TINYINT - 1
SMALLINT - 2
MEDIUMINT - 3
INT, INTEGER - 4
BIGINT - 8
FLOAT(p) - 4 0 <= p <= 24, 8 25 <= p <= 53
FLOAT - 4
DOUBLE [PRECISION], REAL - 8

DATE - 3
TIME - 3
DATETIME - 8
TIMESTAMP - 4
YEAR - 1

CHAR - M+w , 0 <= M <= 255, w
VARCHAR - L + 1 255 , L + 2
255
BLOB L + 2 , L < 216
MEDIUMBLOB L + 3 , L < 224
LONGBLOB L + 4 , L < 232
M , L
MySQL, .
#yum install mysql-server
:
#chkconfig mysqld on

:
#service mysqld start
root . Root
root linux, .
root:

, . .
(
exit). root :

-, . :

. .
:
mysql>status
:
mysql>\s

mysql \h help:
mysql>\h
,
( , =) ):
mysql>show databases;
;

.. WTF? 3 ? 3
, MySQL.
test . .
:

, SQL .
:
1. ;
2. ;
3. , ;
4. .

library CREATE DATABASE:


mysql>CREATE DATABASE library;
:
mysql>\s

Current database ,
. :

.
:

. .

CRATE TABLE ,
, , id
, INT 5 (..
0, 99999
=)). ,
. PRIMARY KEY
, .
name VARCHAR 64 ,
( , 64 ).
.

, .
. UTF8 ( ) .
,
,
( , .. ),
,
. .
:

. 6
, id :

, . :

INSERT INTO ,
VALUES , ,
, .
, id
AUTO_INCREMENT
,
.
10 .
, ,

/root/users.sql, INSERT.
, SOURCE:
mysql>SOURCE /root/users.sql;

, ,
, ,
.
.
SELECT, , ,
:

* SELECT
. id

.
, :

, .
SELECT . 2
:

, , ,
, :

WHERE ,
, .
, ,
++:

= ,
,
30 :

, age
30. .
, (dismissed) ,
,
, .
UPDATE:

SELECT
, SET
,
WHERE
surename
Muhin.

UPDATE DELETE
, :

DELETE , .
:

()
COUNT:

root ,
, ,
. , ..
root , .
admin library:

GRANT ,
SELECT, INSERT, DELETE, UPDATE,
GRANT, library,
library.*,
, IDENTIFIED BY
.
=). ,
,
library.users users library.

.
=).
.
, .
REVOKE:

admin ,
root:

.
.
, ,
( mysql user) MySQL :

.
.

, library. ,
, . , ..
SQL, , , .
. :
1. root;
2. ;
3. ;
4. ;
5. .
,
, .
, ,
. MeSQL:

,
:

&, ,
, .
( MySQL):

root- :

- paasw0rd.

.
. ,
.

root library.sql.
,
. , -p
root , - - opt,
, : - - add-drop-table, - - addlocks, - - create-options, - - disable-keys, - - set-charset. -u
. p
-u.
, , - - all-databases. ,
. library , library.sql
, .
, .
, -,
.
library, , :

. -,
:

!
. ,

, , .
? =). 99%
myisamchk. ,
, .. .
( , /var/lib/mysql, MYI)
:

, 2 : - -recover - -safe-recover.
, man myisamchk ( 98% =))
, . ,
,
1% ( 99% =)), .

, .

.
. , ,
. ,
. , . ,
MySQL . , ,
etc , -
. :
,
, ,
. , ,
(
, .. ,
, apache, postfix ,
), . skipnetworking.

MySQL TCP/IP,
UNIX . Windows UNIX
, named-pipes ,
=).
/usr/share/mysql *.cnf.

, , :
1. RAM 1-2Gb,
MySQL;
2. innoDB,
4Gb ;
3. RAM - 512Mb,
MySQL;
4. 32-64Mb RAM, MySQL ;
5. RAM 64 Mb, MySQL
, .

.
. :
1. http://www.mysql.ru =);
2. http://www.mysql.com =);
3. http://www.tc.state.mn.us/classes/sql_paids/index.htm
.

Оценить