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

M

A d m i n i s t r a t o r ' s

G u i d e

MySQLAB

M y S Q L
Press
800 East 96th Street, Indianapolis, Indiana 46240 USA

MySQL AB

""
-
2005

32.973.26-018.2.75

681.3.07

""
. ..
.. , .. , .

..
""
: info@williamspublishing.com, http://www.williamspublishing.com
115419, , / 783, 03150, , / 152.

MySQL AB.

MySQL. . : . . . :
"", 2005. 624 . . . .
ISBN 5-8459-0805-1 (.)
, MySQL AB,
,
MySQL. .
, MySQL, , .
, MySQL
. , API-, , MySQL Web, .
Web- , .
32.973.26-018.2.75

.

, ,
, MySQL Press.
Authorized translation from the English language edition published by MySQL Press, Copyright 2004
All rights reserved. No part of this book may be reproduced or transmitted in any form or by any means, electronic
or mechanical, including photocopying, recording or by any information storage retrieval system, without permission
from the Publisher.
Russian language edition published by Williams Publishing House according to the Agreement with R&I
Enterprises International, Copyright 2005

ISBN 5-8459-0805-1 (.)


ISBN 0-672-32634-5 (.)

"", 2005
MySQL AB, 2004

14

14

1.

15

2. MySQL

76

3. MySQL

202

4.

212

5. MySQL

365

6. MySQL

402

7. MySQL

460

8. MySQL

498

9. InnoDB

523

10. MaxDB

582

. MySQL

588

612

614

14

14

1.
1.1.
1.1.1. ,
1.2. MySQL
1.2.1. MySQL
1.2.2. MySQL
1.2.3. MySQL
1.2.4. MySQL
1.2.5. " 2000 "
1.3. MySQL AB
1.3.1. - , MySQL AB
1.3.2.
1.4. MySQL
1.4.1. , MySQL AB
1.4.2. MySQL
1.4.3. MySQL
1.4.4. MySQL AB
1.5. MySQL
1.5.1. MySQL 4.0
1.5.2. MySQL 4.1
1.5.3. MySQL 5.0:
1.6. MySQL ( TODO)
1.6.1. , 4.1
1.6.2. , 5.0
1.6.3. , 5.1
1.6.4. ,
1.6.5. ,
1.6.6. ,
1.7. MySQL
1.7.1. MySQL
1.7.2. MySQL IRC
1.8. MySQL
1.8.1. , MySQL
1.8.2. SQL
1.8.3. MySQL ANSI
1.8.4. SQL MySQL
1.8.5. MySQL SQL
1.8.6. MySQL
1.8.7. MySQL

15
15
16
18
19
20
22
23
25
26
27
30
31
31
32
32
35
37
37
39
41
41
41
42
43
43
46
47
48
48
56
56
57
57
57
58
61
68
70


2. MySQL
2.1.
2.1.1. , MySQL
2.1.2. MySQL
2.1.3. MySQL
2.1.4.
MD5 GnuPG
2.1.5.
2.2. MySQL
2.2.1. MySQL Windows
2.2.2. MySQL Linux
2.2.3. MySQL Mac OS X
2.2.4. MySQL NetWare
2.2.5. MySQL Unix-
2.3. MySQL
2.3.1.
2.3.2. configure
2.3.3.
2.3.4. MySQL
2.3.5. MIT-pthreads
2.3.6. MySQL Windows
2.3.7. MySQL Windows
2.4.
2.4.1. Windows
2.4.2. Unix
2.4.3. MySQL
2.4.4. MySQL
2.4.5. MySQL
2.5. MySQL
2.5.1. 4.1 5.0
2.5.2. 4.0 4.1
2.5.3. 3.23 4.0
2.5.4. 3.22 3.23
2.5.5. 3.21 3.22
2.5.6. 3.20 3.21
2.5.7. MySQL Windows
2.5.8.
2.5.9. MySQL
2.6.
2.6.1. Linux
2.6.2. Max OS X
2.6.3. Solaris
2.6.4. BSD
2.6.5. Unix
2.6.6. OS/2
2.6.7. BeOS
2.7. Perl
2.7.1. Perl Unix

7
76
77
77
79
90
90
93
95
95
107
109
112
114
117
118
121
124
127
131
133
136
136
137
138
144
146
149
153
154
154
159
163
165
166
167
167
168
170
170
178
179
183
187
196
197
197
197

2.7.2. ActiveState Perl Windows


2.7.3. Perl DBI/DBD

198
199

3. MySQL
3.1. MySQL
3.2. MySQL-
3.3.
3.3.1.
3.3.2.
3.3.3.
3.3.4.

202
202
203
204
204
206
210
210

4.
4.1. MySQL
4.1.1.
4.1.2. MySQL- mysqld-max
4.1.3. mysqld_safe
4.1.4. mysql.server
4.1.5. mysqldmulti
MySQL-
4.2. MySQL
4.2.1. mysqld
4.2.2. SQL
4.2.3.
4.2.4.
4.3.
4.3.1. ,
4.3.2. MySQL
4.3.3. mysqld,
4.3.4. LOAD DATA LOCAL
4.4. MySQL
4.4.1.
4.4.2.
4.4.3. , MySQL
4.4.4. MySQL
4.4.5. , :
4.4.6. , :
4.4.7.
4.4.8. (Access denied)
4.4.9 MySQL 4.1
4.5. MySQL
4.5.1. MySQL
4.5.2. MySQL
4.5.3. MySQL
4.5.4.
4.5.5.
4.5.6.
4.5.7.
4.6.

212
212
212
213
215
218
219
223
223
232
234
260
265
265
268
270
271
272
272
273
277
281
282
286
289
289
295
301
301
303
306
307
309
310
311
318


4.6.1.
4.6.2.
4.6.3.
4.6.4.
4.7. MySQL
4.7.1.
4.7.2.
4.7.3.
4.7.4.
4.7.5.
4.7.6.
4.7.7.
4.8. MySQL
4.8.1.
4.8.2.
4.8.3.
4.8.4.
4.8.5.
4.8.6.
4.9. MySQL
4.9.1. Windows
4.9.2. Unix
4.9.3.

4.10. MySQL
4.10.1.
4.10.2. SELECT
4.10.3.
4.10.4.
5. MySQL
5.1.
5.2.
5.3.
5.3.1.
5.3.2. /
5.3.3. SQL
5.3.4.
5.4.
5.5. MySQL
5.6.
5.6.1. 4.0 4.1
5.6.2. 5.0
5.7.
5.8.
5.9.
5.10.
5.11.

9
318
320
333
334
340
340
341
342
343
344
344
344
345
346
346
347
348
351
351
352
354
358
359
360
361
362
362
363
365
365
366
367
369
369
371
371
373
378
378
379
379
380
384
393
399
400

10

6. MySQL
6.1.
6.1.1. MySQL
6.1.2.
6.1.3. MySQL
6.1.4. MySQL
6.1.5.
6.2. SELECT
6.2.1. EXPLAIN ( SELECT)
6.2.2.
6.2.3. SELECT
6.2.4. MySQL WHERE
6.2.5. MySQL OR
6.2.6. MySQL IS NULL
6.2.7. MySQL DISTINCT
6.2.8. MySQL LEFT JOIN RIGHT JOIN
6.2.9. MySQL ORDER BY
6.2.10. MySQL LIMIT
6.2.11.
6.2.12. INSERT
6.2.13. UPDATE
6.2.14. DELETE
6.2.15.
6.3.
6.3.1.
6.3.2.
6.4.
6.4.1.
6.4.2.
6.4.3.
6.4.4.
6.4.5. MySQL
6.4.6. MylSAM
6.4.7. MySQL
6.4.8. MySQL
6.4.9.
6.5. MySQL
6.5.1.
6.5.2.
6.5.3. MySQL
6.5.4. MySQL
6.5.5. MySQL DNS
6.6.
6.6.1.

402
402
403
403
405
405
406
407
408
415
416
416
418
419
419
420
421
423
424
424
426
427
427
430
430
433
435
435
435
436
437
438
441
446
446
447
448
448
449
451
453
454
455
456

7. MySQL
7.1.

460
460


7.2. myisampack - MySQL,

7.3. mysql
7.3.1. mysql
7.3.2. SQL-
7.3.3. mysql
7.4. MySQL- mysqladmin
7.5. mysqlbinlog
7.6. MySQL - mysqlcc
7.7. mysqlcheck
7.8. mysqldump
7.9. mysqhotcopy
7.10. mysqlimport
7.11. , mysqlshow
7.12.
7.13. replace

11

461
467
471
475
476
477
480
483
485
487
492
493
495
497
497

8. MySQL
8.1. My IS AM
8.1.1. MylSAM
8.1.2. ,
8.1.3. MylSAM
8.1.4. , MylSAM
8.2. MERGE
8.2.1. , MERGE
8.3. MEMORY (HEAP)
8.4. BDB (BerkleyDB)
8.4.1. , BDB
8.4.2. BDB
8.4.3. BDB
8.4.4. BDB
8.4.5. BDB
8.4.6. BDB
8.4.7. , BDB
8.5. ISAM

498
500
502
504
504
507
509
511
513
515
516
516
517
517
520
520
520
521

9. InnoDB
9.1. InnoDB
9.2. , InnoDB
9.3. InnoDB MySQL 3.23
9.4. InnoDB
9.5. InnoDB
9.6. InnoDB
9.6.1. , InnoDB
9.7. InnoDB
9.7.1. InnoDB API-
9.7.2. MylSAM InnoDB
9.7.3. AUTOJNCREMENT InnoDB
9.7.4. (FOREIGN KEY)

523
523
524
524
525
530
534
535
535
536
537
538
539

12

9.7.5. InnoDB MySQL


9.7.6.
9.8. InnoDB
9.9. InnoDB
9.9.1.
9.9.2.
9.10. InnoDB
9.11. InnoDB
9.11.1. InnoDB AUTOCOMMIT
9.11.2. InnoDB
(TRANSACTION ISOLATION LEVEL)
9.11.3.
9.11.4. : SELECT... FOR UPDATE
SELECT... LOCK IN SHARE MODE
9.11.5. : " "
9.11.6. InnoDB
9.11.7. ,
SQL- InnoDB
9.11.8. MySQL

9.11.9.
9.11.10.
9.12. InnoDB
9.12.1. SHOW INNODB STATUS InnoDB
9.13.
9.14.
9.14.1.
9.14.2.
9.14.3.
9.14.4.
9.15. -
9.15.1. -
9.15.2.

9.15.3.
9.15.4.
9.16.
9.16.1. InnoDB
9.16.2.
9.17. InnoDB
9.18. InnoDB
9.18.1. InnoDB

10. MaxDB
10.1. MaxDB
10.2.
10.3. , MaxDB
10.4. MaxDB
10.5. MaxDB MySQL

543
544
546
547
548
550
550
551
551
551
553
554
555
556
557
558
559
559
561
563
568
568
569
569
570
570
571
571
572
572
573
574
574
575
577
579
580
582
582
582
583
583
583


10.6. MaxDB MySQL
10.7. MaxDB

13
584
584

. MySQL
.
.2. MySQL
.2.1.
.2.2. [] MySQL
.2.3.
.2.4.
.2.5. ''
.2.6.
.2.7.
.2.8. MySQL
.2.9.
.2.10.
.2.11.
.2.12. /
.2.13.
.2.14.
.2.15. ''
.2.16.
.2.17.
.. ,
.3.1. MySQL
..2. MySQL
.3.3.
.4. ,
.4.1. root
.4.2. , MySQL
.4.3. MySQL
.4.4. MySQL
.4.5. MySQL /tmp/mysql.sock
.4.6.

588
588
590
590
590
592
593
593
594
594
594
595
597
598
598
599
599
599
600
600
601
601
603
603
604
604
606
609
609
610
611

612

614


MySQL (http://www.mysql.com), , MySQL. , ,
InnoDB.

(Michael "Monty" Widenius) (David Axmark), MySQL.
(Paul DuBois),
(Stefan Hinz) (Arjen Lentz) .


, , .
, , .
, .
. , Web- . , , , ,
.
, ,
. .
:
E-mail:
WWW:

info@williamspublishing.com
http: //www.williamspublishing.com

:
:

115419, , / 783

03150, , / 152

MySQL , , SQL (Structured


Query Language - ). MySQL
, ,
. MySQL - , MySQL AB.
MySQL (Dual License). (Open Source/Free Software) GNU General Public License,
MySQL AB. 1.4.
MySQL Web-
MySQL (http: //www. mysql. com/).

1.1.
MySQL (MySQL Referense Guide), . , , , . , "MySQL. " ("MySQL Language
Reference"), SQL, MySQL. , , SQL.
MySQL 5.0.1, MySQL ( 3.23 4.0), .
,
SQL .
.
MySQL , , . Internet http://dev.mysql.com/doc/
, HTML, PDF Windows CHM.

16

1.

, , , , , docs@mysql. com.
(David Axmark)
(Michael "Monty" Widenius). MySQL (MySQL Documentation Team),
(Arjen Lentz), (Paul DuBois)
(Stefan Hinz).
(2004 )
MySQL AB (. 1.4.2).

1.1.1. ,
:

, SQL, , , Perl,
, URL-. : " , mysqladmin, help".


.


,
.
'1
, : " %'".

, , .

,
.
, - , . , shell>
, , a mysql> , mysql.
shell>
mysql> mysql
"shell" . UNIX
, sh csh. Windows
command.exe cmd.exe, .

1.1.

17

, ,
.
. ,
, . ,
.
: _ _, _. ,
- :
mysql> SELECT _ FROM _._;
, , , , :
mysql> SELECT author_name FROM biblio_db.author_list;
SQL , , . .
(' [' ' ] ' ) . IF EXISTS :
DROP TABLE [IF EXISTS] _;
,
(').
,
:
TRIM [[BOTH | LEADING | TRAILING] [_] FROM ];
,
:
{DESCRIBE | DESC} _ [_ \

_];

( . . . ) ; . , INSERT... SELECT INSERT SELECT.


, . _,
, , :
RESET _

[,

_]

...


Bourne. , , , :
s h e l l > _=
csh tcsh, -.
:
s h e l l > setenv _
s h e l l >

18

1.

1.2.
MySQL
, MySQL, () , MySQL AB.
MySQL AB - , MySQL,
, MySQL.
MySQL AB 1.3.
, MySQL (http://www.mysql.com/) MySQL MySQL AB.
MySQL - .
.
-
, .
MySQL - .
, , . "SQL" "MySQL" "Structured Query
Language" (" "). SQL - ;
ANSI/ISO SQL. SQL 1986
. "SQL-92" , 1992 , "SQL: 1999" - ,
1999 , "SQL:2003" - .
" SQL" .
MySQL - .
,
. MySQL
Internet, . , , . MySQL GPL
(GNU General Public License), , ,
. GPL MySQL
, MySQL AB (. 1.4.3).
MySQL - ,
.
, , . MySQL , .
MySQL http://dev.mysql.com/techresources/crash-me.php. MySQL
,

1.2. MySQL

19

, , . MySQL
,
. MySQL ,
Internet.
MySQL - .
MySQL - ,
SQL-, , , (API-).
MySQL , ,
, .
MySQL, .
, MySQL.
"MySQL" "---" ( "-"),
, "MySQL" .

1.2.1. MySQL
mSQL ,
(ISAM) . , mSQL , . SQL- , API, mSQL. API- ,
, mSQL, , MySQL.
"MySQL" . " "
10 . , ,
(Monty Widenius), (My). MySQL -
, .
MySQL, - (Sakila) - MySQL AB , " ". ,
(Ambrose Twebaze),
(). , - (SiSwati) - ,
. - (),
, .

20

1.

1.2.2. MySQL
MySQL. 1.5.
.
C++.
.
.
GNU - Automake,
Autoconf Libtool.
API- , C++, Eiffel, Java, Perl, PHP, Python, Ruby Tel.
.
.
.
(MylSAM)
(-).
. , SQL- .
, .
, .
-, .
SQL . , - .
MySQL ,
, .
. , , .
,
.

: /
1, 2, 3, 4 8 ; FLOAT, DOUBLE, CHAR, VARCHAR, TEXT, BLOB, DATE,
TIME, DATETIME, TIMESTAMP, YEAR, SET, ENUM OpenGIS.

.
.
SELECT WHERE , :

1.2. MySQL

21

raysql> SELECT CONCAT(first_name, ' ' , lastjiame)


-> FROM c i t i z e n
-> WHERE income/dependents > 10000 AND age > 30;

GROUP BY ORDER BY.


(COUNT (), COUNT (DISTINCT . . . ) , AVG(), STD(), SUM(), MAX(), MIN()
GROUP_CONCAT()).

LEFT OUTER JOIN RIGHT OUTER JOIN SQL,


ODBC.
,
SQL.

DELETE, INSERT, REPLACE UPDATE ,


. ,
,
.
MySQL SHOW
, .
EXPLAIN , .

. ,
ABS - . ,
, - , ' (' .

(
MySQL 3.22).
.
, , .
, .
.
. ,
MySQL AB MySQL , 50 . ,
MySQL 60 000 , 5 .
64 ( ,
MySQL 4.1.2, 32 ).
1 16 . 1000 (500 , MySQL 4.1.2).
CHAR, VARCHAR, BLOB TEXT.

MySQL, TCP/IP
. Windows- NT (NT, 2000 ) .
UNIX UNIX-.

22

1.

Connector/ODBC MySQL , ODBC-. ,


MySQL MS Access.
Windows UNIX. Connector/ODBC .
ODBC 2.5, .
Connector/JDBC MySQL Java, JDBC-.

Windows UNIX. Connector/JDBC .


.
, l a t i n l (ISO8859-1), german, big5, ujis . ,
'', '' ''. MySQL 4.1, Unicode.
.
.
( ). MySQL
. .
MySQL ,
, .
.
MySQL SQL- ,
.
, mysqlcheck.
MySQL myisamchk - MylSAM.
MySQL help
-? .

1.2.3. MySQL
" MySQL?" "
MySQL ?". , , . , , ,
,
.

. ISAM, ,
. , - MySQL AB, MySQL , 1996 . MySQL

1.2. MySQL

23

, ,
.
, ,
.
MySQL . , " ". , , ,
, .
MySQL 3.23 MySQL 4.O.
, ,
, (. 1.8.7).
MySQL .
, .
(-).
, , . MySQL 5.x .
innoDB ( ).
MySQL 3.23, 3.23.49. InnoDB ,
.
BDB (-).
Berkley DB , BDB MySQL ,
, BDB
, .
(-).
, .
MySQL 4.0 .
Connector/ODBC 3.51 ( ).
Connector /ODBC 3.51 ODBC SDK 3.51
.
ODBC- .
My ISAM (-).
"" My ISAM, , ,
, .

1.2.4. MySQL
MySQL 3.22 4 . MylSAM MySQL 3.23 8

24

1.

(2 6 3 ). , ,
, MySQL.
InnoDB InnoDB , .
.
( ),
.
64 .
. 1.1 , .
1.1.

Linux-Intel, 32-

2 , LFS

8 (?)
2 (4 )
4 ( )
4
512
8

Linux-Alpha
Solaris 2.5.1
Solaris 2.6
Solaris 2.7 Intel
Solaris 2.7 UltraSPARC
NetWare NSS

Linux 2.2 My ISAM 2 , LFS (Large Files Support - ) ext2. Linux 2.4 ReiserFS. Linux
2.4 LFS. - ,
- , MySQL.
LFS Linux
(Andreas Jaeger) "Large File Support in Linux" (" Linux") no
http://www.suse.de/~aj/linux_lfs.html.
MySQL My ISAM , 4 .
SHOW TABLE STATUS myisamchk -dv _.
My ISAM 4 ( ), CREATE TABLE AVG_ROW__LENGTH MAX_R0WS.
ALTER TABLE ,
.

My ISAM, .
,
myisampack . ,

1.2. MySQL

25

50% .
. myisampack
.


My ISAM RAID.

MySQL MERGE,
My ISAM , .

1.2.5. " 2000 91


MySQL " 2000 " (Y2K) .

MySQL Unix,
2037 TIME STAMP. DATE
DATETIME 9999 .

MySQL - sql/time.cc;
,
" 2000 ".

MySQL 3.22 YEAR 0


1901 2155
. 1970 2069; , YEAR 01, MySQL 2001 .

, MySQL
DATE DATETIME 9999 , TIMESTAMP - 2030 .
mysql> DROP TABLE IF EXISTS y2k;
Query OK, 0 rows a f f e c t e d ( 0 . 0 1 s e c )
( , 0 (0.01 ))
mysql> CREATE TABLE y2k (date DATE,
->
date_time DATETIME,
->
time_stamp TIMESTAMP) ;
Query OK, 0 rows a f f e c t e d ( 0 . 0 1 s e c )
mysql>
->
->
->
->
->
->
->
->
->
->
->
->
->
->

INSERT INTO y2k VALUES


('1998-12-31','1998-12-31
('1999-01-01','1999-01-01
('1999-09-09','1999-09-09
('2000-01-01','2000-01-01
('2000-02-28','2000-02-28
('2000-02-29','2000-02-29
('2000-03-01','2000-03-01
('2000-12-31','2000-12-31
('2001-01-01','2001-01-01
('2004-12-31','2004-12-31
('2005-01-01','2005-01-01
('2030-01-01','2030-01-01
('2040-01-01','2040-01-01
('9999-12-31','9999-12-31

23:59:59',19981231235959),
00:00:00',19990101000000),
23:59:59',19990909235959),
00:00:00',20000101000000),
00:00:00',20000228000000),
00:00:00',20000229000000),
00:00:00',20000301000000),
23:59:59',20001231235959),
00:00:00',20010101000000),
23:59:59',20041231235959),
00:00:00',20050101000000),
00:00:00',20300101000000),
00:00:00',20400101000000),
23:59:59',99991231235959);

26

1.
Query OK, 14 rows a f f e c t e d (0.01 sec)
Records: 14 D u p l i c a t e s : 0 Warnings: 2
(: 14 : 0 : 2)
mysql> SELECT * FROM y2k;
I date
1998- 12-31
1999-01-01
1999-09-09
2000- 01-01
2000- 02-28
2000- 02-29
2000- 03-01
2000- 12-31
2001-01-01
2004-12-31
2005-01-01
2030-01-01
2040-01-01
9999-12-31

time_stamp

d a t e time
1998- 12-31
1999- 01-01
1999- 09-09
2000- 01-01
2000- 02-28
2000- 02-29
2000- 03-01
2000- 12-31
2001- 01-01
2004- 12-31
2005- 01-01
2030- 01-01
2040- 01-01
9999-12-31

14 rows in set (0.00 sec)


(14 (0.00

23:59: 59
00:00: 00
23:59: 59
00:00: 00
00:00: 00
00:00: 00
00:00: 00
23:59: 59
00:00: 00
23:59: 59
00:00: 00
00:00: 00
00:00; 00
23:59: 59

19981231235959
19990101000000
19990909235959
20000101000000
20000228000000
20000229000000
20000301000000
20001231235959
20010101000000
20041231235959
20050101000000
20300101000000
00000000000000
00000000000000

))

TIME_STAMP ,
(2040 9999) ,
TIMESTAMP. , , ( ) 19700101000000 20300101000000 32 . 64- TIMESTAMP (
) 2106 .
MySQL "
2000 ", ,
. , , .
, 00 99 "" . , ,
, .
, MySQL " 2000 ", .

1.3. MySQL AB
MySQL AB - MySQL. (David Axmark), (Allan
Larsson) (Michael "Monty" Widenius).
MySQL . MySQL AB -
, .

1.3. MySQL AB

27

Internet , , .
MySQL . MySQL AB MySQL, MySQL,
(. 1.2).
MySQL
. MySQL AB , MySQL
:
.
.
.
.
.
.
, MySQL AB
.
,
(Open
Source).
.
,
.
.
- , Internet.
- .
Web- MySQL (http://www.mysql.com)
MySQL MySQL AB.
, "" "aktiebolag" - "
". MySQL AB MySQL, Inc.
, MySQL, Inc. MySQL GmbH MySQL AB,
, , .

1.3.1. - , MySQL AB
: "
, ?". :
MySQL AB , ,
.
, MySQL.

28

1.

, . 2001
. -
.

1.3.1.1.
MySQL AB
MySQL. ,
. . -
MySQL.

MySQL AB. ,
.
1.4.
1.3.1.2.
MySQL AB MySQL
. ,
, . MySQL
- .
,
, . , MySQL.
, .
, MySQL-. , :
.
.
.
.
MySQL.

,
http://www.mysql.com/training/ :
training@mysql.com.
, ,
http://www.mysql.com/certification/.
1.3.1.3.
MySQL AB
MySQL , MySQL , .

1.3. MySQL AB

29

, , , , , .
,
. , . ,
MySQL, , Perl, PHP .
,
,
http://www.mysql.com/consulting/ :
consulting@mysql.com.
1.3.1.4.
MySQL GNU (General
Public License - GPL). , GPL
MySQL . GPL (, , , GPL),
MySQL AB (https://order.mysql.com/).
MySQL MySQL AB,
,
GPL, . ,
MySQL AB .
, ,
1.4.3.
MySQL AB Open
Source GPL , MySQL.
innoDB, ACID,
, , ,
.
1.3.1.5.
MySQL AB , , , ,
MySQL . MySQL AB
Web- http://www.mysql.com/.
MySQL .
, MySQL AB,
partner@mysql. com.
"MySQL" MySQL MySQL AB (. 1.4.4).
MySQL
.

30

1.

Web- MySQL (http://www.mysql.com)


. 2003 16
. , , , .
, . 65%
70% .

1.3.2.
Web- MySQL (http://www.mysql.com) MySQL MySQL AB.
- ,
(http://www.mysql.com/news-and-events/),
press@mysql. com.
MySQL AB, MySQL. 1.4.1,
http://www.mysql.com/support
sales@mysql. com.
, MySQL,
http://www.mysql.com/training/ ,
training@mysql.com. 1.3.1.2.
MySQL
http://www.mysql.com/certification/. 1.3.1.2.
, http://www.mysql.com/consulting/
: consulting@mysql.com. 1.3.1.3.
Internet
https: //order .mysql. com/. ,
MySQL AB. http://www.mysql.com/products/pricing.html.
, Web-
http://www.mysql.com licensing@mysql.com
( ) sales@mysql.com ( ). 1.4.3.
,
MySQL AB, partner@mysql.com.
1.3.1.5.
MySQL
http://www.mysql.com/company/trademark.html : trademark@mysql.com. 1.4.4.
MySQL AB, (http://www.mysql.com/company/jobs/)
jobs@mysql.com. ,
.

1.4. MySQL

31


. 1.7.1.
, ,
MySQL (. 1.7.1).
MySQL,
security@mysql.com (. 1.7.1.3).
, , benchmark@mysql. com.
, (docs@mysql. com).
Web- MySQL (http://www.mysql.com)
webmaster@mysql. com.
MySQL AB ,
http://www.mysql.com/company/privacy.html.
: privacy@mysql. com.
inf o@mysql. com.

1.4. MySQL
MySQL.

1.4.1. , MySQL AB
MySQL AB
, MySQL.
MySQL AB
. , MySQL,
, . ,
, , , MySQL,
, API- . MySQL ,
, MySQL,
.

http://www.mysql.com/support/.
. , ,
sales@mysql.com.
. . , , .
MySQL
,
. , MySQL AB.

32

1.

1.4.2. MySQL
MySQL AB MySQL, , (. 1.3).
MySQL:
1. MySQL, mysqlclient, ,
GNU- readline, GNU General
Public License (http://fsf.org/licenses/). COPYING MySQL
.
2. GNU getopt
GNU Lesser General Public License (http://www.fsf.org/licenses/).
3. ( , regexp)
Berkley.
4. MySQL, MySQL 3.22, (http://www.mysql.com/products/mypl.html). .
5. MySQL
GPL. :
, - .
.
, , MySQL AB.


docs@mysql.com.
MySQL 1.4.3
1.4.4 .

1.4.3. MySQL
MySQL GNU General
Public License (GPL), , ,
. GPL
http://www.fsf.org/licenses/.
http://www.fsf.org/licenses/gplfaq.html http://www.gnu.org/philosophy/enforcinggpl.html.
GPL , , Free/Libre and Open Source
("FLOSS"), MySQL, ,
FLOSS GPL.
:
http://www.mysql.com/products/licensing/foss-exception.html

1.4. MySQL

33

MySQL GPL,
, MySQL AB.
https://order.mysql.com/.
http://www.mysql.com/products/licensing.html.
MySQL, MySQL 3.22, (http://www.mysql.com/products/mypl.html). MySQL .
, MySQL
, GPL MySQL MySQL AB (. 1.4.4).

1.4.3.1. MySQL

GPL "" , GPL-,
GPL. ,
, GPL- . ,
.
.

MySQL, GPL, , GPL. ,
- ,
. , MySQL, GPL.
, GPL,
MySQL,
MySQL. ,
.
MySQL
, GPL.
MySQL,
. MySQL AB - MySQL,
(. 1.4.1).
GPL , , Free/Libre and Open Source
("FLOSS"), MySQL, ,
FLOSS GPL.
:
http://www.mysql.com/products/licensing/foss-exception.html

34

1.

, MySQL.
, , .
Web-
http://www.mysql.com/products/licensing.html. ,
http://www.mysql.com/support/. - , , ,
: sales@mysql. com.

1.4.3.1. MySQL
GPL
MySQL GPL GPL.
GPL, , FAQ
(Free Software Foundation)
http://www.fsf.org/licenses/gpl-faq.html.
GPL , , Free/Libre and Open
Source ("FLOSS"), MySQL,
, FLOSS GPL. .
http://www.mysql.com/products/licensing/foss-exception.html.
GPL.


MySQL GPL.
MySQL , MySQL,
. GPL
" " ("mere aggregation").

MySQL, .
Internet-,
Web- MySQL. , MySQL,
, MySQL. Internet- MySQL, , ,
MySQL,
, .

MySQL
Web-, ( ,
). ,
Web- ,
MySQL, MySQL .
MySQL, MySQL .

1.4. MySQL

35

MySQL
,
MySQL AB. MySQL (. 1.4.1).
MySQL , MySQL AB MySQL . , MySQL ,
MySQL AB. ( , , , , , .)

1.4.4. MySQL AB
MySQL
MySQL AB Web-, . , ,
"MySQL" MySQL AB
,
(. http://www.mysql.com/company/trademark.html).

1.4.4.1. MySQL
MySQL
Priority 2001 .
MySQL - , , .
MySQL
MySQL AB , .

1.4.4.2. MySQL,

, Web- (http://www.mysql.com/press/logos.html) Web- MySQL AB.


, , . , . .
,
http://www.mysql.com. , , , .
, , MySQL AB
, MySQL.

36

1.
, MySQL AB . MySQL AB.
Web-,
, h t t p : //www.mysql. com.
MySQL GPL ,
MySQL.

- ,
, : trademark@mysql. com.
1.4.4.3.
MySQL
MySQL AB MySQL :
MySQL AB ,
Web-.
MySQL AB, ( ) Web-
- .

MySQL , .
MySQL , , MySQL.

1.4.4.4. MySQL AB
MySQL AB , MySQL AB. -
MySQL. 1.3.1.5.
1.4.4.5. "MySQL"
MySQL AB MySQL,
, "MySQL" MySQL AB.
"MySQL" (), , , , MySQL MySQL AB.

http://www.mysql.com/corapany/trademark.html.
1.4.4.6. "MySQL"
"MySQL" ,
Internet MySQL AB .

1.5. MySQL

37

1.5. MySQL
MySQL, , MySQL 4.0, 4.1, 5.0 5.1.
.
- MySQL
4.0, 4.0.12, ( 2003 ). ,
4.0 . MySQL 3.23 .
MySQL MySQL 4.1 MySQL
5.0. , MySQL 4.1
MySQL 5.0. MySQL 4.1 -,
MySQL 5.0 - -.
.

MySQL

4.0
4.1

R-

4.1 ( My ISAM)

5.0
5.0
5.0
5.1 ( 3.23 InnoDB)

5.1
5.1
5.1

1.5.1. MySQL 4.0


MySQL 4.0 .
h t t p : //dev.mysql. com, .
MySQL 4.0 Web-.
, MySQL 4.0,

. MySQL
, . .

1.5.1.1. , MySQL 4.0


.
MySQL 4.0 , , .

38

1.
MySQL 4.0
, INSERT, , ( FULLTEXT),
COUNT(DISTINCT).
MySQL.
. -
MySQL - .
InnoDB .
InnoDB MySQL.
ACID-, INSERT
DELETE, .
.
FULLTEXT MySQL 4.0 ,
, . ,
, MySQL-.
,
MySQL UNION - SQL.
MySQL Novell Netware, NetWare 6.O.
,
MySQL, TRUNCATE TABLE ( Oracle).

, ,
MySQL 4.0 - l a t i n l d e , , , .


.
mysqld ( ) . .
DELETE UPDATE.
Windows . UNIX My ISAM
(
, ).

1.5. MySQL

39

SQL_CALC_FOUND_ROWS FOUND_ROWS() -

, SELECT LIMIT,
.

(. http://dev.mysql.com/doc/mysql/en/News.html).

1.5.1.2. MySQL
libmysqld MySQL. , MySQL
, . MySQL
Internet-, , , Internet-,
, -, .
libmysqld MySQL. ,
GPL, .
MySQL , , .

1.5.2. MySQL 4.1


MySQL 4.0 ,
Unicode, 4.1,
, 5.0.
.
MySQL , MySQL.
, ,
MySQL ,
.
1.5.2.1. , MySQL 4.1
MySQL 4.1, , . MySQL 4.1 (. 1.6.1).
, 4.1, . , , MySQL 5.0 (. 1.6.2).
MySQL 4.1 -,
:
http://dev.mysql.com/downloads/mysql/4.1.html
-
, .
, , , BitKeeper
MySQL 4.1.

40

1.

MySQL 4.1 - ( ), - ( ) (,
). MySQL 4.1 .
.
"" - SELECT, .
" " ( ) -
FROM .
.
- .
BTREE HEAP, .
.

CREATE TABLE _2 LIKE _1 ,


, .
My ISAM
OpenGIS .
SSL-.

,
- , . , , .

SHOW WARNINGS , .


, , MySQL
Unicode utf8nucs2.

, . , , Web-.


HELP
, SQL. , ,
. SQL, , . -

1.6. MySQL ( TODO)

41

, help mysql
.
-
.
-
. , ,
.
INSERT.. .ON DUPLICATE KEY UPDATE...,
UPDATE , INSERT , .
GROUP_CONCAT (), .

(. http://dev.mysql.com/doc/mysql/en/News.html).

1.5.3. MySQL 5.0:


MySQL 5.0, (.
1.6.2).
, MySQL, BitKeeper MySQL 5.O. 2003 , 5.0.

1.6. MySQL ( TODO)


, MySQL. . , , , .
!
, -
,
(sales@mysql.com), .
-
. , , .

1.6.1. , 4.1
MySQL 4.1 ,
, MySQL 4.1 -. , MySQL 4.1, 1.5.2.1.
OpenSSL. ( SSL MySQL 4.0 100% .)
.

42

1.

.

1.6.2. , 5.0
MySQL 5.O. , , , MySQL
5.0 alpha, . , , . , .
, , ,
. ,
MySQL 4.1. , MySQL 4.1, 1.5.2.1.
, MySQL, BitKeeper MySQL 5.0. 2003 , 5.0.
.

SQL:2003.
.
.
My ISAM, RTREE ( MySQL 4.1 RTREE
GIS, ).
MEMORY.
,
VARCHAR ( 255
). My ISAM,
.
.
SHOW COLUMNS FROM _ ( mysql
, )
, .
.
DELETE MylSAM . ,
.MYD.
MEMORY:
.
( ).

, RENAME TABLE , MERGE ( ).

1.6. MySQL ( TODO)

43


(. http: //dev.mysql. com/doc/mysql/en/News. html).

1.6.3. , 5.1
.

(FOREIGN KEY) ,
InnoDB.

.
. .
.
(. f rm) .
.
BIT ( BIT
TINYINT).
.
-
, .
RENAME DATABASE.
, :
1. .
2. ,
RENAME.

3. .
.
, RAID.

1.6.4. ,

.
, , .
Oracle CONNECT BY PRIOR SELECT .
SQL ODBC 3.0.
SUM (DISTINCT).

INSERT SQL_CONCURRENT mysqld --concurrent-insert


, .

44

1.

UPDATE, , UPDATE
foo

SET @a:=a+b, a=@a, b=@a+c.

,
GROUP BY, : SELECT i d ,
@a:=COUNT(*), SUM(sura_col)/@a FROM _ GROUP BY id.

IMAGE LOAD DATA INFILE,


TIMESTAMP AUTO_INCREMENT.

LOAD DATA INFILE.. .UPDATE,


:

,
, , . ,
, .

, , - , LOAD DATA INFILE...REPLACE INTO.

LOAD DATA INFILE, :


LOAD DATA INFILE '_a.txt f INTO TABLE _
TEXT_FIELDS (_1, _2, _)
SET _!=CONCAT[_1, _2),
_=23
IGNORE _
, , .

SET:

ADD_TO_SET{, )
REMOVE_FROM_SET{, )

, mysql ,
. , .


, .
, ,
. SHOW INFO
FROM __ .

SELECT a FROM _1 LEFT JOIN _2 USING (a) ;


, __1.

DELETE REPLACE UPDATE ( , ,


).

DATETIME, .

1.6. MySQL ( TODO)

45

GNU regexp
( ).
, .
(DEFAULT).
INSERT,
, DEFAULT.
ANY (), EVERY () SOME ().
SQL ,
,
FALSE TRUE.

(),
, :
raysql> CREATE TABLE t l (a DATE);
mysql> INSERT INTO t l VALUES (NOW());
mysql> CREATE TABLE t 2 SELECT MAX (a) FROM t l ;
mysql> SHOW COLUMNS FROM t 2 ;

.
He , ,
My ISAM .
INSERT INTO.. .SELECT , .

, .
( ).
, , , .
,
.
.
SELECT MIN(column)
. . . GROUP BY.

long_query_time .
myisampack ,
PACK COMPRESS.

INSERT, DELETE
UPDATE ,
.
ALTER TABLE , ,
.

46

1.

DATE DATETIME ,
, .

configure, ( My ISAM)
.


LIMIT, : LIMIT @, @b.

mysql Web-.

LOCK DATABASES ( ).

SHOW STATUS. .
.
. ORDER BY GROUP BY.

mysqladmin copy _
COPY mysqld.

/.

SHOW HOSTS .

NULL .

Item_copy_string ,
-- :

__;.

SELECT COUNT(*)*(id+0) FROM _ GROUP BY i d

ALTER TABLE , , INSERT DELAYED.

, UPDATE
, .

MySQL LynxOS.

1.6.5. ,

get_changed_tables {-, !, 2, . . . ) .

, mmap (), .
mmap () .

. SET TI ME STAMP=;

- .

, ,
23 ( ).

.
_=, - , __ . .

1.6. MySQL ( TODO)

47

, .

= .
= - .
.
sql_yacc.yy ,
.
,
.
( Access 97).
MINUS, INTERSECT FULL OUTER JOIN ( UNION
LEFT | RIGHT OUTER JOIN).
SQLJDPTION MAX_SELECT_TIME=
.
.
LIMIT, .

//.

mysqld_safe: FSSTND
( Debian), PID-
///<_>.11, - /var/log. , "DATADIR" "pidfile"
"log",
.
.
LOAD DATA INFILE , zip.
BLOB ( ).
.
MIT-pthreads.
JOIN .
" "
.
GETLOCK () .
,
.

1.6.6. ,

ANSI/ISO SQL. , .

48

1.

1.7. MySQL
1.7.1. MySQL
MySQL . , ,
. , , .

1.7.1.1. MySQL
, , http://lists.mysql.com. ,
.

MySQL. , , , lists.mysql.com, , .
,
MySQL.
,
, .
List-ID:
Delivered-TO:.
MySQL.
anounce
MySQL .
; MySQL.
mysql
MySQL. , .
, , , .
mysql-digest
mysql . ,
.
bugs
,
MySQL .
bugs-digest
bugs .
internals
, MySQL.
MySQL .
internals-digest
internals .

1.7. MySQL

49

mysqldoc
, MySQL:
MySQL AB, .
mysqldoc-digest
mysqldoc .
benchmarks
, .
( MySQL), , ,
, .
benchmarks-digest
benchmarks .
packagers
MySQL.
,
, MySQL ,
MySQL
.
packagers-digest
packagers
Java
, MySQL Java. JDBC-, MySQL Connector/J.
java-digest
j ava .
Win32
,
MySQL Microsoft,
Windows 9x, Me, NT, 2000 .
win32-digest
Win32 .
myodbc
, MySQL
ODBC.
myodbc-digest
myodbc .
gui-tools
MySQL , MySQL Administrator MySQL Control Center.
gui-tools-digest
gui-tools .
plusplus
C++ MySQL.

50

1.
plusplus-digest
plusplus .
msql-mysql-modules
, MySQL Perl,
, DBD:mysql.
msql-mysql-modules-digest
msql-mysql-modules .

MySQL,
MySQL AB.
MySQL (. 1.4.1).
MySQL ( ). MySQL AB .
mysql-france-subscribe@yahoogroups.com
.
list@tinc.net
.
subscribe mysql @, .
mysql-de-request@lists.4t2.com
.
subscribe mysql-de @. . h t t p : //www. 4t2.com/mysql.
mysql-br-request@listas.linkway.com.br
.
subscribe mysql-br @..
mysql-alta@elistas.net
.
subscribe mysql @..

1.7.1.2.
, :
MySQL http: / /dev. mysql. com/doc/.
, .
(http: //dev. mysql. com/doc/mysql/en/News .html), , .
,
http://bugs.mysql.com/. , , , .
http://lists.mysql.com/.
http://www.mysql.com/search/
Web- MySQL AB, .

1.7. MySQL

51

,
MySQL. , , MySQL.

1.7.1.3.
, ,
http://bugs.mysql.com/ - . ,
.
, .
, , , , .
, (
); ,
. , , ,
, ,
, .
( ) mysqlbug.
scripts ( ) bin ( MySQL).
mysqlbug (, Windows),
,
( - MySQL).
mysqlbug ,
, - .
,
.
, MySQL , .
, mysql t e s t < ^
Perl-, .
, http: //bugs .mysql. com/,
MySQL.
, , .
MySQL, security@mysql. com.
,
http://bugs.mysql.com/. , mysqlbug . ,
, , MySQL.
MySQL.
, , , , . , ,
, , . ,
, :

52

1.

, -, .
, , , , .
: ()
MySQL () ,
MySQL ( ).
, 99 100 .
: " - - ?" , MySQL , MySQL.
-, .
MySQL ,
, .
, , MySQL.
. , , ,
. , .
, .
, ,
. , , , .
- ,
. - , , , , ,
( ).
, .
Connector/ODBC (MyODBC), , MyODBC .
, , ,
80 .
mysqlbug --vertical (
\G) , (, EXPLAIN SELECT, ).
:
MySQL, , MySQL 4.0.12.
, mysqladmin version.
mysqladmin bin MySQL.
, .
. Windows, ,
My Computer ( ) Help ()
About ( ). Unix- uname -a.

1.7. MySQL

53

( ). , .
MySQL ,
. ,
.

, , , .

mysqld , ,
. , mysqld

mysqld.

,
mysqldump nodata __ _.
. .

, SELECT,
EXPLAIN SELECT . . . , ,
, , SELECT.
SHOW CREATE TABLE ^ ,
. ,
, - .
. mysqlbug.
mysql.
\G , 80 :
mysql> SHOW VARIABLES;
mysql> SHOW COLUMNS FROM . . . \ G
< SHOW COLUMNS>
mysql> EXPLAIN SELECT . . . \ G

< EXPLAIN>
mysql> FLUSH STATUS;
mysql> SELECT . . . ;

SELECT,
>
mysql> SHOW STATUS;
< SHOW STATUS>

mysqld,
, .
.
, . ,
http://bugs.mysql.com/ .
, ,
mysqladmin variables extended-status processlist,
, .

54

1.

, ( 10 ),
mysqldump README .
tar, gzip zip FTP-
ftp://ftp.mysql.cora/pub/mysql/upload/. h t t p : //bugs .mysql. com/.
, MySQL ,
, ,
, .
, , ,
. . ,
. , ,
. ,
, FTP-
ftp://ftp.mysql.com/pub/mysql/upload. , , , .
,
, . , , , mysqld,
MySQL. mysqld, mysql, configure . .
, Perl , ,
.
,
mysqlaccess, mysqladmin reload ,
. , mysqlaccess.
mysqladmin reload version , .
, .
, - ,
,
, , . ,
, . , . ,
, .
. , , . -
( ), ,
.

1.7. MySQL

55

,
, , . MySQL
- , .
, , , .
"parse error" ("
"), .
, , MySQL . h t t p : //dev.mysql.com/doc/ , , MySQL
. -

licensing@mysql. com . , , MySQL,
MySQL, , .
MySQL .
, , , CHECK TABLE REPAIR
TABLE, myisamchk. Windows,
, SHOW VARIABLES LIKE 'lower_case_table_names' 1 2.
, , . MySQL
, . (
.err ). . mysqld ,
. mysqld, .
,
MySQL , .
MySQL
. , , .
- , ,
mysql-support@mysql.com , , , - , , - .
, ,
, ,
.

56

1.

1.7.1.4.

, , ,
, ,
. ,
, , . , , . ,
.

HTML. , .

1.7.2. MySQL IRC


MySQL
IRC (Internet Relay Chat - Internet). /,
.
freenode (http://www.freenode.net/)

#mysql. , MySQL, SQL.


#mysqlphp. ,
- MySQL + PHP.

#mysqlperl. ,
- MySQL + Perl.

EFnet (http://www.efnet.org/)

#mysql. MySQL.

IRC- IRC, X-Chat (http://www.xchat.org/). X-Chat ( GPL) Unix-, Windows-.

1.8. MySQL
, , MySQL
ANSI/ISO SQL. MySQL
SQL, ,
. , , MySQL, ,
.
SQL 1986
. "SQL-92" , 1992
, "SQL: 1999" - , 1999 , "SQL:2003" - . " SQL" .
, MySQL
. , , ,
MySQL .

1.8. MySQL

57

, SQL, ,
. SQL -SQL ,
MySQL . HANDLER MySQL 4.O.
- ,
, "24 , 7 ", , Web .
MySQL (10-100
, 100 ) .
MySQL , -
,
. MySQL , -
.
, , , MySQL .
NDB- ,
2004 .
XML .

1.8.1. , MySQL
ANSI/ISO, .
ODBC 0-3.51.

1.8.2. SQL
MySQL SQL - . .
, SQL MySQL
.
MySQL , .
SQL mysqld
--sql-mode="modes". MySQL 4.1, sqljnode SET
[SESSION|GLOBAL] sql_mode='modes'.

1.8.3. MySQL ANSI


mysqld ANSI-, ansi.

58

1.

ANSI ( sql-mode ):
--transaction-isolation=SERIALIZABLE
sql-mode=REAL_AS_FLOAT,PIPES_AS_CONCAT/ANSI_QUOTESf
IGNORE_SPACE,ONLY_FULL_GROUP_BY
MySQL 4.1 :
SET GLOBAL TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SET GLOBAL sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,
IGNORE_SPACE,ONLY_FULL_GROUP_BY';
. 1.8.2.
MySQL 4.1.1 sqljnode , :
SET GLOBAL sql_mode='ansi';
sqljnode , ANSI. :
mysql> SET GLOBAL sql_mode='ansi';
mysql> SELECT @@global.sqljnode;
-> 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,
IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI';

1.8.4. SQL MySQL


MySQL , , ,
SQL. , ,
SQL. ,
MySQL, ,
/*! . . . */. MySQL
, SQL-, SQL
. :
SELECT /*! STRAIGHT_JOIN */ _ FROM 1,2 WHERE . . .
'!' ,
MySQL :
CREATE /*132302 TEMPORARY */ TABLE t (a INT);
, MySQL 3.23.02 , TEMPORARY .
MySQL .
.
MySQL
MySQL, - . :

MySQL ,
( Unix-).
, , , , -

1.8. MySQL

59

My ISAM ISAM. , MylSAM, .MYD, .MYI .frm, .


, , ,
( ).

'V .
SQL- __. __.
SQL ,
(User space). MySQL , : CREATE TABLE r a l p h . m y _ t a b l e . . .IN
my_tablespace.

SQL-.

ANALYZE TABLE, CHECK TABLE, OPTIMIZE TABLE REPAIR TABLE.

CREATE DATABASE DROP DATABASE.

DO.

EXPLAIN SELECT - .

FLUSH RESET.

SET.

SHOW.

LOAD DATA INFILE. Oracle.

RENAME TABLE.

REPLACE DELETE + INSERT.

CHANGE ^, DROP _, DROP INDEX, IGNORE


RENAME ALTER TABLE.
ADD, ALTER, DROP CHANGE ALTER TABLE.

, , INDEX KEY CREATE TABLE.

IF EXISTS DROP TABLE.

DROP TABLE.

ORDER BY LIMIT UPDATE DELETE.

INSERT INTO...SET _ =

DELAYED INSERT REPLACE.

LOW_PRIORITY INSERT, REPLACE, DELETE UPDATE.

INTO OUTFILE STRAIGHT_JOIN SELECT.

SQL_SMALL_RESULT SELECT.

60

1.

GROUP
BY. , .

ASC DESC GROUP BY.


: = :
mysql> SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg
-> FROM t e s t _ t a b l e ;
mysql> SELECT @tl:=(@t2:=l)+@t3:=4,@tl,@t2,@t3;

.
MEDIUMINT, SET, ENUM BLOB TEXT.
AUTO_INCREMENT, BINARY, NULL, UNSIGNED ZEROFILL.
.
, SQL-,
MySQL . ,
SQL, ODBC.

MySQL && | | " " (AND)


"" (OR), . MySQL | | OR , & &
AND. MySQL SQL-
| | .
CONCAT (). CONCAT () , | | .

COUNT (DISTINCT ),
.
, (
ISO-8859-1 Latin 1). , BINARY BINARY, , .

% MOD (). , N % MOD(N, M). '%'


PostgresSQL.

=, , <=, <, >=, >, , , <=>, AND, OR LIKE


FROM SELECT, :
mysql> SELECT coll=l AND col2=2 FROM ^;

LASTINSERTIDO
AUTO_INCREMENT.

LIKE .

REGEXP NOT
REGEXP.

1.8. MySQL

61

CONCAT () CHAR () .

B I T _ C 0 U N T ( ) , CASE, E L T ( ) , F R O M _ D A Y S ( ) , FORMAT ( ) , I F ( ) , PASSWORD ( ) ,


ENCRYPT ( ) , MD5 ( ) , ENCODE ( ) , DECODE ( ) , PERIOD_ADD ( ) , P E R I O D _ D I F F ( ) , TO_DAYS ( )
WEEKDAY().

TRIM() . SQL .
GROUP BY STD(),
BIT_OR(), BIT_AND(), BIT_XOR() GROUP_CONCAT().

,
MySQL, , "TODO"
http://dev.mysql.com/doc/mysql/en/TODO.html. "TODO". . 1.6.

1.8.5. MySQL SQL


, MySQL ANSI
SQL ODBC SQL, MySQL :
VARCHAR (. 1.8.7).
CHAR VARCHAR,
.
.
REVOKE.
1.8.5.1.
MySQL 4.1 . - SELECT, . ( ) - FROM .
MySQL
.
1.8.5.2. SELECT INTO TABLE
MySQL SQL
Sybase: SELECT... INTO TABLE... MySQL SQL INSERT INTO... SELECT..., .
INSERT INTO tbl_temp2 (fld_id)
SELECT tbl_templ.fld_order_id
FROM tbl_templ WHERE tbl_templ.fld_order_id > 100;
SELECT INTO OUTFILE...
CREATE TABLE SELECT...
5.0, MySQL SELECT.. .INTO .

62

1.

1.8.5.3.
MySQL ( 3.23 , 4.0) innoDB BDB. innoDB ACID.
MySQL (, My ISAM) ,
" ". My ISAM AUTOCOMMIT=1. .
MySQL , ,
. .
, .
, . , , InnoDB, .
MySQL
.
MySQL
My ISAM,
?
1. ,
ROLLBACK COMMIT ,
. , . .
, MySQL
, , ,

, - . ,
MySQL , .
2. . , ,
,
LOCK TABLE , ,
, .
3. , .
, , . ,
100%, " ". Oracle, -

1.8. MySQL

63

,
.
MySQL,
, .
, , . ,
.
. ,
, ,
. , ,
, , 3-5 ,
, .
, , MySQL . LOCK TABLE, , .
READ LOCAL ( ) , , ,
. , , , . INSERT
DELAYED, ,
, .
"" , ,
. , ,
, , (
, ).
MySQL ,
(dirty read).
.
, ,
LOCK TABLES;
.
ROLLBACK, :
1. LOCK TABLES , .
2. , .
3. .
4. UNLOCK TABLES .
,
, . , -

64

1.
, - .
, .
.
, :
.
, .
, , , , ,
, .
WHERE UPDATE. , : " ". , ,
.
, , , ,
, . ,
UPDATE , :
UPDATE tablename SET pay_back=pay_back+125;
UPDATE customer
SET
customer_date='current_date',
address='new address',
phone='new phone',
money_owed_to_us=money_owed_to_us-125
WHERE
customer_id=id AND address='old address' AND phone='old phone';
,
pay_back money_owed_to_us.
LOCK TABLES / ROLLBACK
. ,
AUTO_INCREMENT SQL- LAST_INSERT_ID(), API
mysql_insert_id ().
, , . ,
innoDB . My ISAM - :
UPDATE _ SET row_flag = 1 WHERE id = ID;
MySQL 1 , rowf lag 1 .
, MySQL
:
UPDATE _ SET row_flag = 1 WHERE id = ID AND row_flag <> 1;

1.8. MySQL

65

1.8.5.4.
MySQL 5.O.
5.1. - , - . ,
, ,
, , .

1.8.5.5.
MySQL 3.23.44 InnoDB , CASCADING, ON DELETE ON
UPDATE.
MySQL FOREIGN KEY CREATE TABLE, . ,
mysqldump ODBC.
My ISAM.
:

, , - .


. , , - .

,
, . , , . (

.)
MySQL .
, ,
, , My ISAM. , My ISAM
, INSERT SELECT,
.
,
:


. ,
,

66

1.
. , .
ON DELETE, , MySQL 4.0
DELETE .
, ON DELETE,
, DELETE
, . , ,
.
, :
, , , .
,
, . (MySQL ,
, . MySQL 4.1.1
mysqldump , .)

, SQL , .
SELECT, :
SELECT * FROM tl, t2 WHERE tl.id = t2.id;
FOREIGN KEY ON DELETE... ODBC-
WHERE.

1.8.5.6.
5.0
MySQL. { , FROM SELECT) 4.1.
, MySQL Web-,
. , ,
.
,
, . (, , ). , MySQL
.

1.8. MySQL

67

. . MySQL , , ,
SQL,
. , ,
.

1.8.5.7.'--'
' ' .
MySQL '#'. : /* */.
MySQL 3.23.3 , '', , (
). , , SQL-, , !payment! :
UPDATE account SET credit=credit-'payment!
, , , , -1:
UPDATE.account SET credit=credit1
credit1 - SQL, , .
, , :
UPDATE account SET credit=credit
! , '--' .
, MySQL
3.23.3 , credit1.
,
mysql , ' - - ' .
, MySQL
, 3.23.3.
SQL- , ,
*', replace '#':
shell> replace " " " #" < text-file-with-funny-comments.sql \
| mysql __

:
shell> mysql __ < text-file-with-funny-comments.sql
, ' ' '#':
shell> replace " " " #" text-file-with-funny-comments.sql
:
shell> replace " #" " " text-file-with-funny-comments.sql

68

1.

1.8.6. MySQL
MySQL , , , ,
(constraints) MySQL , .
,
, .
, , ,
, .
, (. 1.6.4).
, MySQL ,

, , .
, .

1.8.6.1. PRIMARY KEY/UNIQUE


, ,
,
. ,
innoDB, MySQL . , MySQL .
, MySQL IGNORE , (, INSERT IGNORE
UPDATE IGNORE). MySQL . ,
MySQL, mysql_info() API- .
MySQL 4.1 SHOW
WARNINGS.

, InnoDB. My ISAM
MySQL 5.1.

1.8.6.2. NOT NULL DEFAULT


,
MySQL .
"" , NULL ,
NOT NULL, ,
MySQL " " ,
:

, , MySQL , .

1.8. MySQL

69

MySQL ,
, .
, ,
, MySQL 0.
NULL ,
NULL, MySQL 0 -
. (
, MySQL
-DONT_USE_DEFAULT_FIELDS.) INSERT , ,
NOT NULL.
MySQL
DATE DATETIME ( '2000-02-31' '2000-02-00').
, SQL.
MySQL , , . (
), '0000-00-00'.
,
, .
, ,
, . -
, , . " "
, .
, MySQL
. , MySQL .
MySQL 5.0 , ,
, , ,
, .

1.8.6.3. ENUM SET


MySQL 4.x ENUM , ,
.
ENUM,
0,
.
SET . , ' ' , ' ' ' ' ,
' , , , ' ' a, b ' .

70

1.

1.8.7. MySQL
1.8.7.1. 3.23,
MySQL
3.23, , , , , . " " "".
, LOCK TABLE
DROP TABLE , . ( KILL .)
MySQL 4.0.12.

SELECT {__) FROM t l , t 2 , t 3 . . . , ,


NULL, .
MySQL 4.0.11.

DELETE FROM _ WHERE


-.

1.8.7.2. 4.0,
4.0,
, , , , . , " " "".
UNION SELECT - , (max_length), NULL.
MySQL 4.1.1 -
UNION.
DELETE
. MySQL 4.1.

1.8.7.3. MySQL
:
FOREIGN KEY , , .

REPLACE ( LOAD DATA REPLACE) ON DELETE CASCADE ( ).

UNION ALL UNION DISTINCT .


ALL UNION, .
, , ,
, DROP TABLE,
.

1.8. MySQL

71

5.0, DROP TABLE , .


( 2 6 3 2 6 4 - 1)
, ,
.
MySQL 4.1.

FLUSH TABLES WITH READ LOCK CREATE TABLE COMMIT,



.

ANALYZE TABLE BDB ,


, mysqld.
, MySQL :
001207 22:07:56 bdb: log_flush: LSN past current end-of-log
MySQL FROM SELECT, . , , ,

FROM, .
RIGHT JOIN LEFT JOIN RIGHT JOIN , MySQL
NULL , LEFT JOIN RIGHT
JOIN. 5.0,
FROM.
ALTER TABLE BDB,
, , . (
.)
ANALYZE TABLE, OPTIMIZE TABLE REPAIR TABLE , INSERT DELAYED.
LOCK TABLE... FLUSH TABLES... ,
.
BDB .
BDB, , mysql
- rehash. ,
.
.
. ,
,
. , , ,
, , . .
( , , !).
:
CREATE... SELECT INSERT... SELECT, NULL- AUTO INCREMENT.

72

1.

DELETE, , ON DELETE CASCADE.

REPLACE. . .SELECT, INSERT IGNORE. . .SELECT,


.

ORDER BY, .
, INSERT... SELECT ORDER BY, SELECT ( ,
, , AUTO_INCREMENT), , . ,
:

, , . , OPTIMIZE TABLE
( , MySQL 4.1.1, OPTIMIZE TABLE, ANALYZE TABLE REPAIR
TABLE ).


( ; , InnoDB My ISAM - , ).

(key__buf f e r _ s i z e ).

MySQL,
.


mysqlbinlog|mysql.
- ORDER BY , ,
.
MySQL ORDER BY , .
:

(
). , , log-bin=__-.
,
.

mysqlbinlog ,
LOAD DATA INFILE.

RENAME ,
MERGE.

RPAD () ,
,
. .

1.8. MySQL

73

SELECT RPAD(tl.columnl, 50, ' ') AS f2, RPAD(t2.column2, 50, ' ') AS fl
FROM tablel as t l LEFT JOIN table2 AS t2 ON tl.record=t2.joinID
ORDER BY t2.record;
.
, .
, -, , VARCHAR.
MySQL
4.1.
-
255 (CHAR (255)) , . 5.1, .
SET CHARACTER SET
, .
'_', '%' ESCAPE LIKE...
ESCAPE.

DECIMAL, (, +01.00, 1.00, 01.00), GROUP BY


.
MITpthreads. MIT-pthreads, , .
BLOB "" GROUP BY, ORDER BY
DISTINCT. BLOB max_sort_length . max_sort_length 1024
. . , , :
SELECT DISTINCT LEFT {_, 2048) FROM _
BIGINT DOUBLE (
64 ). , . :
BIGINT, IF ELT () - BIGINT DOUBLE, -
DOUBLE. ,
63 (9223372036854775807) ,
. MySQL 4.0 BIGINT,
MySQL 3.23.
, BLOB TEXT, . CHAR .
, VARCHAR .
255 ENUM SET.

74

1.
MIN (), ()
ENUM SET ,
.
mysqld_saf e mysqld mysqld. , mysqladmin refresh
, stdout
stderr . log , mysqld_safe,
_. _.log. , ,
mysqladmin refresh.
UPDATE . , . , KEY 2, 1:
mysql> UPDATE _

SET KEY=KEY+1,KEY=KEY+1;

,
. ,
:
mysql> SELECT * FROM temp_table, temp_table AS t 2 ;
ERROR 1137: Can't reopen table: 'temp_table f
(ERROR 1137: : 'temp
table')
DISTINCT -,
"" . ( ),

DISTINCT. , ,
DISTINCT.
:
SELECT DISTINCT mp3id FROM band_downloads
WHERE u s e r i d = 9 ORDER BY id DESC;
SELECT DISTINCT band_downloads.mp3id
FROM band_downloads,band_mp3
WHERE band_downloads.userid = 9
AND band_mp3.id = band_downloads.mp3id
ORDER BY band_downloads.id DESC;
MySQL 3.23.x
( id ). , ,
, ORDER BY.
MySQL , , ,
, SQL. , , MySQL

1.8. MySQL

75

SQL-. ,
,
, MySQL , .
, MySQL
" " .
, , 1.8.6.
PROCEDURE ,
, PROCEDURE .
MERGE
.
ALTER TABLE
, MERGE,
MERGE-, , ,
. , ALTER
TABLE ,
.
MySQL.
.
.
LOCK TABLE WRITE.

FLUSH TABLE.

MySQL 3.23.2 UPDATE, , WHERE, ,


, :
UPDATE _ SET KEY=KEY+1 WHERE KEY > 100;
:
UPDATE _ SET KEY=KEY+1 WHERE KEY+0 > 100;
, MySQL
WHERE.

MySQL 3.23
. , ,
. .

2
MySQL

, MySQL.
1. , . ,
MySQL.
MySQL ,
(. 2.1.1).
2. , .
MySQL . , ( ) , . - .
,
. , , , 2.1.2.
3. , . ,
MySQL, 2.1.3.
, 2.1.4.
4. . MySQL
, 2.2. MySQL
2.3. MySQL , ,
2.5, , . , 2.6
.
5. . MySQL
2.4, , , MySQL . ,
MySQL,
, .
, .
6. , MySQL,
Perl (. 2.7).

2.1.

77

2.1.
MySQL :
1. , MySQL .
2. .
3. .
, . , ,
,
.

2.1.1. , MySQL
, MySQL.
GNU Autoconf, MySQL
, C++ POSIX. ( .
C++.)

Linux (SuSE Red Hat), FreeBSD Sun Solaris ( 8 9).
MySQL
. , .
AIX 4.x, 5.x . . 2.6.5.3.
Amiga.
BSDI 2.x MIT-threads. . 2.6.4.5.
BSDI 3.0, 3.1 4.x . . 2.6.4.5.

DEC UNIX 4.x . . 2.6.5.5.


FreeBSD 2.x MIT-threads. . 2.6.4.1.
FreeBSD 3.x 4.x . . 2.6.4.1.
FreeBSD 4.x LinuxThreads. . 2.6.4.1.
HP-UX 10.20 DCE- MIT-threads. . 2.6.5.1.
HP-UX 11.x . . 2.6.5.2.

Linux 2.0+ Linux Threads 0.7.1+ glibc 2.0.7+. . 2.6.1.


Mac OS X. . 2.6.2.
NetBSD 1.3/1.4 Intel NetBSD 1.3 Alpha ( GNU make). .
2.6.4.2.
Novell NetWare 6.0. . 2.2.4.
OpenBSD > 2.5 , OpenBSD < 2.5
MIT-threads. . 2.6.4.3.
OS/2 Warp 3, FixPack 29 OS/2 Warp 4, FixPack 4. . 2.6.6.
SCO OpenServer FSU Pthreads. . 2.6.5.8.

78

2. MySQL
SCO UnixWare 7.1.x. . 2.6.5.9.
SGI Irix 6.x . . 2.6.5.7.
Solaris 2.5 SPARC Intel. . 2.6.3.
SunOS 4.x MIT-threads. . 2.6.3.
64 Unix.

Windows 9x, Me, NT, 2000 . . 2.2.1.


MySQL . ,
, MySQL, :
.
, MySQL
, , .
(SMP). , , ,
, .
, (mutex)
. pthread_mutex_lock() , MySQL. , MySQL.
.
,
,
, .
MySQL AB.
, . MySQL.
, .
, MySQL
. , .
MySQL
86,
SuSE Linux 2.4 ReiserFS ( Linux), SPARC Solaris (2.7-9). FreeBDS , , , . , -
, MySQL -

2.1.

79

, .
,
MySQL.
, , , , ,
MySQL ,
MySQL i t e r n a l s (. 1.7.1.1).
, , , () .
- MySQL.
, , .
, ,
,
. , , MySQL.

2.1.2. MySQL
MySQL ,
. MySQL , , .
, ,
. .

2.1.2.1. MySQL
, , , :
() .
MySQL ,
:

MySQL 5.0 - ,
. ( ) BitKeeper. .

MySQL 4.1 - , , . . .

MySQL 4.0 - . . , , .

MySQL 3.23 - .
, .

, , " ". "-

80

2. MySQL

" , - , " , ". ,



.
, MySQL
, , . MySQL
4.0. MySQL, , , ,
.
, , ,
, ( ).
,
.
, , , .
, , .
, ,
BitKeeper. , , .
, MySQL, , , mysql-4.1.2-alpha.
:
(4)
. 4 .
(1) - .
.
(2) - .
. .
.

, . ,
.
, . , . .

alpha () , ,
100% . (
) (News) http://dev.mysql.com/doc/mysql/en/News.html.
- . , , -

2.1.

81

-,
. MySQL.
beta () , .
, , . . - - , -
, , , , .
gamma () - -,
. . , .
, ,
, , .
. , () .
MySQL ,
. ,
.
MySQL ,
. , ,
.
, , :
. mysql-test
.
.
. . , (. 6.1.4).
crash-me. , (. 6.1.4).
, , -
MySQL , , . 100 , .

2.1.2.2.
MySQL ,
: .
, . , , RPM- Linux DMG Mac OS X.
Zip- tar.
:

82

2. MySQL

, , .

, :
( ), ,
. . MySQL .
MySQL - , mysqld-max. . 4.1.2.
RPM- MySQL-Max, RPM- MySQL-server.

, , , MySQL :

MySQL . , MySQL , .

mysqld ,
. , , ,
:
--with-innodb ( MySQL 4.0 )
--with-berkleydb ( )
with-raid
with-libwrap
with-names-z-libs ( )
with-debug[=full]

mysqld ,
. , . MySQL,
.

(, , ),
, .
,
.

BitKeeper, .
,
MySQL, ,
.
.

2.1.

83

( ) MySQL C++.
, -
.
, .
2.1.2.3.
MySQL MySQL AB, MySQL. , - , .
, , . , , , , . .
. (News) , ,
. . http://dev.mysql.com/doc/mysql/en/News.html.
MySQL :
. -
- , .
() 1-2 .
, .
/ 4-8
.
. ,
, .
, , .
BitKeeper .
, , . ( ,
!)

2.1.2.4. !
,
. MySQL - "" ( "" , MySQL , , , .)
,
(. 1.8.7).
- ,
MySQL. , -

84

2. MySQL

, , () . , ,
.
.
,
http://bugs.mysql.com/ , MySQL.
.
, , , ,
, . (
90% .)
, MySQL.
MySQL, , MySQL (3.23.x, 4.0.x ) . - ( - MySQL), . . 1.8.7.
,
( 15 )
.
,
. ,
, .
2-3 .
, .
http://dev.mysql.com mysql announce (.
1.7.1.1). .

MySQL, 4-8 . :
http://downloads.mysql.com/snapshots.php
, , , , , - ;
' ' . , .
.
150 , 10.
glibc - , .

2.1.

85

2.1.2.5. MySQL, MySQL


MySQL
,
, , .
, ,
, t a r ( . t a r . g z ) . 2.2.
Build-tools/Do-compile, tar.gz,
scripts/make_binary_distribution.
. ,
COMP_ENV_INFO CONFIGURE_LINE bin/mysqlbug, tar- .
MySQL :
Linux 2.4. 86 2.95.3:
CFLAGS="-O2 -mcpu=pentiumpro" CXX=gcc CXXFLAGS="-O2 -mcpu=pentiumpro
-felideconstructors" ./configure prefix=/usr/local/mysql
with-extra-charsets=complex enable-thread-safe-client
enable-local-infile enable-assembler disable-shared
with-client-ldflags=-all-static with-mysqld-ldflags=-allstatic
Linux 2.4.xx Intel Itanium 2 (Intel C++ Itanium Compiler 7.0):
CC=ecc CFLAGS="-02 -tpp2 -ip -nolib_inline" CXX=ecc CXXFLAGS=
"-02 -tpp2 -ip -nolib_inline" ./configure prefix=/usr/local/mysql
with-extra-charsets=complex enable-thread-safe-client
enable-local-infile
Linux 2.4.xx Intel Itanium (Intel C++ Itanium Compiler 7.0):
CC=ecc CFLAGS=-tppl CXX=ecc CXXFLAGS=-tppl ./configure -prefix*
/usr/local/mysql with-extra-charsets=complex enable-thread-safeclient
enable-local-infile

Linux 2.4.xx alpha (Compaq V6.2-505 / Compaq C + + V6.3-006):


CC=ccc CFLAGS="-fast -arch generic" CXX=cxx CXXFLAGS="-fast -arch
generic -noexceptions -nortti" ./configure prefix=/usr/local/mysql
with-extracharsets=complex enable-thread-safe-client
enable-local-infile withmysqld-ldflags=-non_shared
with-client-ldflags=-non_shared disable-shared

Linux 2.x.xx ppc 2.95.4:


CC=gcc CFLAGS="-03 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS=
"-03 -fno-omitframe-pointer -felide-constructors -fno-exceptions
-fno-rtti" ./configure prefix=/usr/local/mysql localstatedir=
/usr/local/mysql/data libexecdir=/usr/local/mysql/bin
with-extra-charsets=complex enable-threadsafe-client
enable-local-infile disable-shared with-embedded-server
with-innodb

86

2. MySQL
Linux 2.4. s390 gcc 2.95.3:
CFLAGS=n-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors" ./configure
prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safe-client enable-local-infile disable-shared
with-client-ldflags=-all-static
with-mysqld-ldflags=-all-static
Linux 2.4.xx x86_64 (AMD64) gcc 3.2.1:
CXX=gcc ./configure prefix=/usr/local/mysql with-extra-charsets=
complex enable-thread-safe-client enable-local-infile disable-shared
Sun Solaris 8 x86 gcc 3.2.3:
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-fno-oraitframe-pointer -felide-constructors -fno-exceptions -fno-rtti"
./configure prefix=/usr/local/mysql localstatedir=
/usr/local/mysql/data libexecdir=/usr/local/mysql/bin
with-extra-charsets=complex enablethread-safe-client
enable-local-infile disable-shared with-innodb
Sun Solaris 8 SPARC gcc 3.2:
COgcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-fno-omitframe-pointer -felide-constructors -fno-exceptions - f n o - r t t i "
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile enable-assembler
with-named-z-libs=no withnamed-curses-libs=-lcurses disable-shared
Sun Solaris 8 SPARC 64-bit gcc 3.2:
CC=gcc CFLAGS="-O3 -m64 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-m64 -fno-omit-frame-pointer -felide-constructors -fno-exceptions
- f n o - r t t i " ./configure prefix=/usr/local/mysql with-extra-charsets=
complex enable-threadsafe-client enable-local-infile
with-named-z-libs=no with-named-curseslibs=-lcurses disable-shared
Sun Solaris 9 SPARC gcc 2.95.3:
COgcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-fno-omitframe-pointer -felide-constructors -fno-exceptions - f n o - r t t i "
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile enable-assembler
with-named-curses-libs=-lcurses disable-shared
Sun Solaris 9 SPARC -5.0 (Sun Forte 5.0):
CC=cc-5.0 CXX=CC ASFLAGS="-xarch=v9" CFLAGS="-Xa -xstrconst -mt
-D_FORTEC_ -xarch=v9" CXXFLAGS="-noex -mt -D_FORTEC_ -xarch=v9"
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile enable-assembler
with-named-z-libs=noenable-thread-safe-client disable-shared
IBM AIX 4.3.2 ppc gcc 3.2.3:
CFLAGS="-O2 -mcpu=powerpc -Wa,-many " CXX=gcc CXXFLAGS="-O2 -mcpu=
powerpc -Wa,-many -felide-constructors -fno-exceptions - f n o - r t t i "
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile with-named-z-libs=
no disable-shared

2.1.

87

IBM AIX 4.3.3 xlC_r (IBM Visual Age C/C++ 6.0):


CC=xlc_r CFLAGS="-ma -02 -qstrict -qoptimize=2 -qmaxmem=8192" CXX=xlC_r
CXXFLAGS ="-ma -02 -qstrict -qoptimize=2 -maxmem=8192" ./configure
prefix=/usr/local/mysql localstatedir=/usr/local/mysql/data
libexecdir=/usr/local/mysql/bin with-extra-charsets=complex
enablethread-safe-client enable-local-infile with-named-z-libs=
no -disableshared with-innodb
I B M A I X 5.1.0 gcc 3.3:
CFLAGS="-02 -mcpu=powerpc -Wa,-many" CXX=gcc CXXFLAGS="-02 -mcpu=
powerpc -Wa, -many -felide-constructors -fno-exceptions -fno-rtti"
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeelient enable-local-infile with-named-z-libs=
no disable-shared
I B M A I X 5.2.0 x l C r (IBM Visual Age C/C++ 6.0):
CC=xlc_r CFLAGS="-ma -02 -qstrict -qoptimize=2 -qmaxmem=8192" CXX=xlC_r
CXXFLAGS="-ma -02 -qstrict -qoptimize=2 -qmaxmem=8192" ./configure
prefix=/usr/local/mysql localstatedir=/usr/local/mysql/data
libexecdir=/usr/local/mysql/bin with-extra-charsets=complex
enablethread-safe-client enable-local-infile with-named-z-libs=
no -disableshared with-embedded-server with-innodb
H P - U X 10.20 pa-riscl.l gcc 3.1:
CFLAGS="-DHPUX -I/opt/dce/include -03 -fPIC" CXX=gcc CXXFLAGS=
"-DHPUX -I/opt/dce /include -felide-constructors -fno-exceptions
-fno-rtti -03 -fPIC" ./configure prefix=/usr/local/mysql
with-extra-charsets=complex enablethread-safe-client
enable-local-infile with-pthread with-named-threadlibs=
-Idee with-lib-ccflags=-fPIC disable-shared
H P - U X 11.00 pa-risc aCC (HP ANSI C + + B3910B A.03.50):
CC=cc CXX=aCC CFLAGS=+DAportable CXXFLAGS=+DAportable ./configure
prefix=/usr/local/mysql localstatedir=/usr/local/mysql/data
libexecdir=/usr/local/mysql/bin with-extra-charsets=complex
enablethread-safe-client enable-local-infile disable-shared
with-embeddedserver with-innodb
H P - U X 11.11 pa-risc2.0 64bit aCC (HP A N S I C + + B3910B A.03.33):
CC=cc CXX=aCC CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure
prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safe-client enable-local-infile disable-shared
H P - U X 11.11 pa-risc2.0 32bit aCC (HP ANSI C + + B3910B A.03.33):
CC=cc CXX=aCC CFLAGS="+DAportable" CXXFLAGS=ll+DAportable" ./configure
prefix=/usr/local/mysql localstatedir=/usr/local/mysql/data
libexecdir=/usr/local/mysql/bin with-extra-charsets=complex
enable-threadsafe- client enable-local-infile disable-shared
with-innodb
H P - U X 11.22 ia64 64bit aCC (HP aC++/ANSI 3910 A.05.50):

88

2. MySQL
= = CFLAGS="+DD64 +DSitanium2" CXXFLAGS="+DD64 +DSitanium2"
./configure prefix=/usr/local/mysql localstatedir=/usr/local/mysql/data
libexecdir=/usr/local/mysql/bin with-extra-charsets=complex
--enablethread-safe-client enable-local-infile disable-shared
with-embeddedserver with-innodb
Apple Mac OS X 10.2 powerpc gcc 3.1:
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-fno-omitframe-pointer -felide-constructors -fno-exceptions - f n o - r t t i "
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile disable-shared
FreeBSD 4.7 i386 gcc 2.95.4:
CFLAGS=-DHAVE_BROKEN_REALPATH ./configure prefix=/usr/local/mysql
withextra-charsets=complex enable-thread-safe-client
enable-local-infile enable-assembler with-named-z-libs=not-used
disable-shared
FreeBSD 4.7 i386 using LinuxThreads gcc 2.95.4:
CFLAGS="-DHAVE_BROKEN_REALPATH -D_USE_UNIX98 -D_REENTRANT -D_THREAD_SAFE
- I / u s r / l o c a l / i n c l u d e / p t h r e a d / l i n u x t h r e a d s " CXXFLAGS=
M

-DHAVE_BROKEN_REALPATH -D

USEJJNIX98 -D_REENTRANT -D_THREAD_SAFE

-I/usr/local/include/pthread/linuxthreads" ./configure prefix=


/usr/local/mysql localstatedir=/usr/local/mysql/data libexecdir=
/usr/local/mysql/bin enablethread-safe-client enable-local-infile
enable-assembler with-namedthread-libs=
M

-DHAVE_GLIBC2_STYLE_GETHOSTBYNAME_R

-D_THREAD_SAFE - I

/usr/local/include/pthread/linuxthreads -L/usr/local/lib -11thread


-llgcc_r" disable-shared with-embedded-server with-innodb
QNX Neutrino 6.2.1 i386 gcc 2.95.3qnx-nto 20010315:
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-fno-omitframe-pointer -felide-constructors -fno-exceptions - f n o - r t t i "
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile disable-shared
, . MySQL AB , , .

SCO Unix 3.2v5.0.6 i386 gcc 2.95.3:


CFLAGS="-O3 -mpentium" LDFLAGS=-static CXX=gcc CXXFLAGS="-O3 -mpentium
-felideconstructors" ./configure prefix=/usr/local/mysql
with-extra-charsets=complex enable-thread-safe-client
enable-local-infile with-named-z-libs=no enable-thread-safe-client
disable-shared

SCO OpenUnix 8.0.0 i386 3.2:


CC=cc CFLAGS="-O" CXX=CC ./configure prefix=/usr/local/mysql
with-extracharsets=complex enable-thread-safe-client
enable-local-infile withnamed-z-libs=no enable-thread-safe-client
disable-shared

2.1.

89

Compaq Tru64 OSF/1 V5.1 732 alpha / (Compaq V6.3-029i /


DIGITAL C++V6.1-027):
CC="cc -pthread" CFLAGS="-04 -ansi_alias -ansi_args -fast -inline speed
-speculate a l l " CXX="cxx -pthread" CXXFLAGS="-O4 -ansi_alias -fast
-inline speed -speculate a l l -noexceptions -nortti" ./configure
prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safe-client enable-local-infile with-prefix=
/usr/local/mysql with-named-thread-libs="-lpthread -lmach -lexc - l c "
disable-shared with-mysqld-ldflags=-all-static
SGI Irix 6.5 IP32 gcc 3.0.1:
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXXFLAGS="-O3
-fno-omit-framepointer -felide-constructors -fno-exceptions -fno-rtti"
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile disable-shared
FreeBSD/sparc64 5.0 gcc 3.2.1:
CFLAGS=-DHAVEJ3ROKEN_REALPATH ./configure prefix=/usr/local/mysql
localstatedir=/usr/local/mysql/data libexecdir=/usr/local/mysql/bin
with-extracharsets=complex enable-thread-safe-client
enable-local-infile -disableshared with-innodb
MySQL AB
. ,
, .
Linux 2.2. SPARC egcs 1.1.2:
CC=gcc CFLAGS="-03 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3
-fno-omitframe-pointer -felide-constructors -fno-exceptions -fno-rtti"
./configure prefix=/usr/local/mysql with-extra-charsets=complex
enable-thread-safeclient enable-local-infile enable-assembler
disable-shared
Linux 2.2.x with x686 gcc 2.95.2:
CFLAGS="-03 -mpentiumpro" CXX=gcc CXXFLAGS="-03 -mpentiumpro
-felideconstructors -fno-exceptions -fno-rtti" ./configure
prefix=/usr/local/mysql enable-assembler with-mysqld-ldflags=
- a l l - s t a t i c disable-shared withextra-charsets=complex
SunOS 4.1.4 2 sun4c gcc 2.7.2.1 :
CC=gcc CXX=gcc CXXFLAGS="-03 -felide-constructors" ./configure prefix=
/usr/local/mysql disable-shared with-extra-charsets=complex
enable-assembler
SunOS 5.5.1 ( ) sun4u egcs 1.0.3
2.90.27, gcc 2.95.2 :
CC=gcc CFLAGS="-03" CXX=gcc CXXFLAGS="-O3 -felide-constructors
-fno-exceptions -fno-rtti" ./configure prefix=/usr/local/mysql
with-low-memory withextra-charsets=complex enable-assembler
SunOS 5.6 i86pc gcc 2.8.1:

90

2. MySQL
CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure prefix=/usr/local/mysql
with-lowmemory with-extra-charsets=complex
BSDI BSD/OS 3.1 i386 gcc 2.7.2.1:
CC=gcc CXX=gcc CXXFLAGS=-0 ./configure ~prefix=/usr/local/mysql
with-extracharsets=complex
BSDI BSD/OS 2.1 i386 gcc 2.7.2:
CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure prefix=/usr/local/mysql
with-extracharsets=complex
AIX 2 4 c gcc 2.7.2.2:
CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure prefix=/usr/local/mysql
with-extracharsets=complex

, , MySQL
internals (. 1.7.1.1).
RPM MySQL 3.22 . MySQL 3.22, RPM
MySQL AB.
MySQL, --with-debug
with-debug=full

-fomit-frame-pointer.

2.1.3. MySQL
,
MySQL http://www.mysql.com/.
h t t p : //mirrors. sunsite.dk/mysql/.
, MySQL,
http://dev.mysql.com/downloads/mirrors.html. , MySQL .

2.1.4.
MD5 GnuPG
MySQL , .
MySQL AB :
MD5.
GnuPG (GNU Privacy Guard).
RPM-.
.
, MD5 GPG- , , , . -

2.1.

91

,
webmaster@mysql.com build@mysql.com,
, . .

2.1.4.1. MD5
, MySQL , , MD5 , .
, ( _ - ):
shell> md5sum _
:
shell> md5sum mysql-standard-4.0.17-pc-linux-i686.tar.gz
60f5fe969d61c8f82e4f7f62657elf06
mysql-standard-4.0.17-pc-linux-i686.tar.gz
, ( ) .
, md5sum. md5, . Linux GNU Text Utilities, . http://www.gnu.org/software/textutils. OpenSSL, openssl md5
_. md5 DOS/Windows
http://www.fourmilab.ch/md5.

2.1.4.2. GnuPG
. , MD5, , , .
MySQL 4.0.10 ( 2003 ) MySQL AB GnuPG (GNU Privacy Guard). GnuPG - , Pretty
Good Privacy (PGP) (Phil Zimmermann). GnuPG, , ,
http://www.gnupg.org. Linux GnuPG,
. OpenPGP
http://www.openpgp.org.
GPG MySQL AB. http: //www. keyserver.net.
, , build@mysql.com. :
Key ID:
pub
1024D/5072E1F5 2003-02-03
MySQL Package signing key (www.mysql.com) <build@mysql.com>
Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
Public Key (ASCII-armored):

92

2. MySQL
BEGIN PGP PUBLIC KEY BLOCK
Version: GnuPG vl.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
mQGiBD4+owwRBAC14GIfUfCyEDSIePvEW3SAFUdJBtoQHH/nJKZyQT7h9bPlUWC3RODjQReyCITR
rdwyrKUGku2FmeVGwn2u2WmDMNABLnpprWPkBdCk96+OmSLN9brZfw2vOUgCmYv2hW0hyDHuvYlQ
A/BThQoADgj8AW6/0Lo7VlW9/8VuHP0gQwCgvzV3BqOxRznNCRCRxAuAuVztHRcEAJooQKl+iSiu
nZMYDlWufeXfshc57S/+yeJkegNWhxwR9pRWVArNYJdDRT+rf2RUe3vpquKNQU/hnEIUHJRQqYHo
8gTxvxXNQc7fJYLVK2HtkrPbP72vwsEKMYhhr0eKCbtLGfls9krjJ6sBgACyP/Vb7hiPwxh6rDZ7
ITnEkYpXBACmWpP8NJTkamEnPCia2ZoOHODANwpUkP43I7jsDmgtobZX9qnrAXw+uNDIQJEXM6FS
bi0LLtZciNlYsafwAPEOMDKpMqAK6lyisNtPvaLd81H0bPAnWqcyefeprv0sxxqUEMcM3o7wwgfN
83POkDasDbs3pjwPhxvhz6//62zQJ7Q7TXlTUUwgUGFja2FnZSBzaWduaW5nIGtleSAod3d3Lml5
c3FsLmNvbSkgPGJlaWxkQG15c3FsLmNvbT6lXQQTEQIAHQUCPj6jDAUJCWYBgAULBwoDBAMVAwID
FgIBAheAAAoJEIxxjTtQcuHlcY4AnilUwTXn8MatQOiG0a/bPxrvK/gCAJ4oinSNZRYTnblChwFa
azt7PF3qzIhMBBMRAgAMBQI+PqPRBYMJZgC7AAoJEElQ4SqycpHyJOEAnlmxHijft00bKXvucSo/
pECUmppiAJ41M9MRVj5VcdH/KN/KjRtW6tHFPYhMBBMRAgAMBQI+QoIDBYMJYiKJAAoJELblzU3G
uiQ/lpEAoIhpp6BozKI8p6eaabzF5MUH58pAKCu/ROofK8JEg2aLos+5zEYrB/LsrkCDQQ+PqMd
EAgA7+GJfxbMdY4wslPnjH9rF4N2qfWsEN/lxaZoJYc3a6M02WCnH16ahT2/tBK2wlQI4YFteR47
gCvtgb6OUHffOo2HfLmRDRiRjdlDTCHqeyX7CHhcghj/dNRlW2Z015QFEcmV9U0Vhp3aFfWC4Uj
fs3LU+hkAWzE7zaD5cH9J7yv/6xuZVw411x0h4UqsTcWMu0iMlBzELqXlDY7LwoPEb/O9Rkbf4fm
LellEzIaCa4PqARXQZc4dhSinMt6K3X4BrRsKTfozBu74F47D8Ilbf5vSYHbuE5p/loIDznkg/p8
kW+3FxuWrycciqFTcNz215yyX39LXFnlLzKUb/F5GwADBQf+Lwqqa8CGrRfsOAJxim63CHfty5mU
c5rUSnTslGYEIOCRlBeQauyPZbPDsDD9MZlZaSafanFvwFG6Llx9xkU7tzq+VKLoWkm4u5xf3vn5
5VjnSdlaQ9eQnUcXiL4cnBGoTbOWI39EcyzgslzBdC++MPjcQTcA7p6JUVsP6oAB3FQWg54tuUo0
Ec8bsM8b3Ev42LmuQT5NdKHGwHsXTPtl0klk4bQk4OajHsiylBMahpT27jWjJlMiJc+IWJ0mghkK
Ht926s/ymfdf5HkdQlcyvsz5tryVI3Fx78XeSYfQvuuwqp2H139pXGEkg0n6KdUOetdZWhe70YGN
PwlyjWJTlIhMBBgRAgAMBQI+PqMdBQkJZgGAAAoJEIxxjTtQcuH17p4An3rlQpVC9yhnW2cSAjq+
kr72GX0eAJ4295kl6NxYEuFApmrl+0uUq/SlsQ===YJkx
END PGP PUBLIC KEY BLOCK

GPG
gpg --import.
, mysqljpubkey.asc, :
shell> gpg import mysqljpubkey.asc
GPG , .

MySQL , .
, , .asc.
:
Distribution file
mysql-standard-4.0.17-pc-linux-i686. t a r . gz
Signature
file
mysql-standard-4.0.17-pc-linux-i686.tar.gz.asc
, , :
shell> gpg verify _.as
:
shell> gpg verify mysql-standard-4.0.17-pc-linux-i686.tar.gz.asc
gpg: Warning: using insecure memory!

2.1.

93

gpg: S i g n a t u r e made Mon 03 Feb 2003 08:50:39 PM MET


u s i n g DSA key ID 5072E1F5
gpg: Good s i g n a t u r e from
"MySQL Package s i g n i n g key (www.mysql.com) <build@mysql.com>"
"Good signature..." , .
" u s i n g i n s e c u r e memory" (" ") .

2.1.4.3. RPM
RPM .
GPG MD5. :
s h e l l > rpm checksig ^.rpm
:
s h e l l > rpm checksig MySQL-server-4.0.10-0.i386.rpm
MySQL-server-4.0.10-0.i386.rpm: md5 gpg OK
!
RPM 4.1, : "(GPG) NOT OK (MISSING KEYS:
GPG#5072e1f5)"f MySQL GPG, RPM. , RPM 4.1 GPG ( GPG).
, ,
GPG - , .
MySQL RPM, ,
. rpm import . , mysql_pubkey. as , :
s h e l l > rpm import mysql_pubkey.asc

2.1.5.
,
,
MySQL AB. , ,
.
Windows C:\raysql,
:

bin

mysqld.

data

Docs

examples

include

lib

scripts

share

94

2. MySQL

, RPM- Linux,
:

/usr/bin

/usr/sbin

mysqld.

/var/lib/mysql

/usr/ share/doc/packages

include/usr/include/mysql

lib/usr/lib/mysql

/usr/share/mysql

sql-bench/usr/share/sql-bench

Unix t a r ( /usr/ l o c a l /mysql).


:

bin

mysqld.

data

docs

include

lib

scripts

mysql_install_db.

share/mysql

sql-bench


.
/usr/local:

bin

include /mysql

info
lib/mysql
libexec
share /mysql
sql-bench
var

Info-.
.
mysqld.
.
.
.

mysqld l i b e x e c bin.

- v a r data.

m y s q l _ i n s t a l l _ d b b i n s c r i p t s .

- , i n c l u d e /mysql
lib/mysql include lib.

2.2. MySQL

95

scripts/make_binary_distribution,
.

2.2. MySQL

MySQL ,
(,
" "). . 2.2.5 , .
2.1 ,
.

2.2.1. MySQL Windows


MySQL Windows :
1. .
2. , .
3. , .
4. .
5. MySQL.
MySQL Windows :
, ,
, .
, , VC++ 6.0.
, . ,
,
MySQL.
, MySQL Windows . 2.3.6.
2.2.1.1. Windows
MySQL Windows :
32- Windows, 9, Me, NT, 2000 .
NT (Windows NT, 2000 ) MySQL
(. 2.2.1.7).
TCP/IP.
Windows,
http://dev.mysql.com/downloads (. 2.1.3).
1

Jf FTP FTP-,
'v. , .

96

2. MySQL
WinZip Windows-, .zip, .
, , .
MySQL ODBC, MyODBC.
4 , MySQL NTFS .
MAXROWS AVGROWLENGTH.

2.2.1.2. Windows
MySQL Windows :
1. Windows NT, 2000 ,
, .
2. MySQL,
MySQL. Windows NT, 2000
, Windows, :
:\> NET STOP MySQL
(, mysqld-max
mysqld), :
:\> C:\mysql\bin\mysqld remove
, . MySQL ,
:
:\> C:\raysql\bin\mysqladmin -u root shutdown
3. WinMySQLAdmin, .
4. .
5. setup.exe, .
MySQL , (C:\mysql),
Browse () . MySQL , . - , 2.2.1.3.
6. .

!
- MySQL 4.1 Windows . 4.1 - Zip-, ,
MySQL. , m y s q l - 4 . 1 . 1 alpha-win.zip C:\mysql, :, mysql-4.1.1-alpha mysql.

2.2. MySQL

97

MySQL 4.1,
data,
. 4.1
, , data - .
: \raysql . MySQL 4.1, , data
data. . (. 2.5.8).

2.2.1.3. MySQL- Windows


- ,
. , , ,
MySQL. , :

(: \mysql : \mysql\data).
. , innoDB MySQL 3.23, , 9.4. ( MySQL 4.0,
InnoDB data.
, InnoDB .
, - ,
.)
Windows MySQL , MySQL. , . , MySQL C:\mysql,
- : \mysql\data. , ,
: \raydata, :
: \mysql\data : \mydata.
datadir
.
Windows MySQL :
my. ini Windows : \my. cnf. Windows : \WINDOWS
: \WinNT. WINDIR; :
:\> echo %WINDIR%
MySQL my.ini, my.cnf.
. (boot loader), : , - my. ini.
, .
Notepad (). , MySQL

98

2. MySQL

E:\mysql, E:\mydata\data,
[mysqld] basedir datadir:
[mysqld]
# set basedir to your i n s t a l l a t i o n path
# basedir
basedir=E:/mysql
# set datadir to the location of your data directory
# datadir
datadir=E:/raydata/data
, Windows ( ) ( ).
, .

WinMySQLAdmin. bin MySQL,
.
WinMySQLAdmin ,
:
WinMySQLAdmin my. ini.
WinMySQLAdmin C:\my.cnf,
:\my_cnf .bak, .
.

2.2.1.4. Windows
MySQL 3.23.38, Windows
, MySQL-Max.
MySQL, , .

mysqld

,
, InnoDB BDB.

mysqld-opt

. 4.0,
InnoDB. 4.0
.
Windows NT, 2000 .
InnoDB BDB.

mysqld-nt
mysqld-max
mysqld-max-nt

To , mysqld-max, .

Intel,
Intel i386 .
MySQL TCP/IP Windows-, mysqld-nt
mysqld-max-nt Windows NT,
Windows 2000 Windows . , , -

2.2. MySQL

99

TCP/IP. ( Windows , TCP/IP.) :


MySQL 3.23.50, ,
enabled-named-pipe. , , .
mysqld-nt
mysqld-max-nt, Windows, (NT, 2000, ).
Windows 98 Windows Me, TCP/IP. .
Windows 95 .
% !
?
|?
&
il
t;
1\


mysqld. , mysqld-opt, , . pa , , mysqld
, , ,
, Windows.

2.2.1.5.
Windows 95, 98 Me MySQL
TCP/IP. ( MySQL .) MySQL , TCP/IP. TCP/IP
- Windows.
, Windows 95 (,
OSR2), , Winsock. MySQL
Winsock 2. Winsock
http://www.microsoft.com. Windows 98 Winsock 2, .
NT- , Windows NT, 2000 , TCP/IP (,
).
2.2.1.4.
MySQL.
Windows.
, MySQL
, C:\mysql. MySQL , , .
( " DOS").
. - , .

102

2. MySQL

MySQL TCP/IP Windows NT,


Service Pack 3 ( ).
MySQL Windows , . :
:\> C:\mysql\bin\mysqladmin -u root shutdown
mysqladmin, . root -
MySQL. , MySQL
, Windows.
:
:\> mysqld --install
mysqld
, :
:\> C:\mysq\bin\mysqld install
MySQL 4.0.2 i n s t a l l .
MySQL 4.0.3 defaults-file,
, . , , .
, , MySQL,
[mysqld] .
i n s t a l l , [mysqld] ,
.
defaults-file , [mysqld]
.

? !
%
'^
||
&

MySQL 4.0.17 , Windows,


, . MySQL : \Program F i l e s ,
.

, i n s t a l l ,
, MySQL.
:
:\> :\mysql\bin\mysqld install mysqldefaults-file=C:\my-opts.cnf
- - i n s t a l l .
defaults-file, [mysql] ( ,
). , defaults-file ,
, [mysqld].
Start parameters ( ) Windows Services.

2.2. MySQL

103

, MySQL ,
Windows.
Services NET START MySQL. NET .
MySQL ,
, . mysqld ,
. : \mysql\data .err.
mysqld ,
Services, NET STOP MySQL mysqladmin shutdown. Windows , .
MySQL 3.23.44, Manual,
, MySQL . - - i n s t a l l install-manual:
:\> :\mysql\bin\mysqld install-manual
, , .
--remove :
:\> :\mysql\bin\mysqld remove
MySQL 3.23.49 , : Windows ,
, , . (,
InnoDB ). MySQL 3.23.49, Windows MySQL . , ,
MySQL .
mysqladmin shutdown.

Windows 2000 . Windows NT,
20 , . ,
\winnt\system32\regedt32.exe
WaitToKillServiceTimeout HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
. (, 120000 120- ).
mysqld ,
. 2.2.1.6.
2.2.1.8. MySQL Windows
, MySQL :
:\> :\mysql\bin\mysqlshow
:\> C:\mysql\bin\mysqlshow -u root mysql
:\> C:\mysql\bin\mysqladmin version status proc
C:\> C:\mysql\bin\mysql test

2. MySQL

104

mysqld TCP/IP-
Windows 9x/Me, , (DNS).
mysqld skip-name-resolve
localhost IP- Host MySQL.
MySQL TCP/IP, pipe (.) .
socket . MySQL 4.1 ptorocol=PIPE.
MySQL:

mysql

Windows,
.
gnus GNU , readline.

mysql

mysql ,
cygwinbl9.dll, , mysqlc . MySQL , mysqlc
( bin MySQL). cygwinbl9.dll bin, l i b
Windows (\Windows\System ).

2.2.1.9. MySQL Windows MySQL Unix


MySQL Windows .
MySQL Windows ,
Unix, :
Windows 95 . Windows 95 200
. MySQL ,
mysqld
Windows 95, !
Windows .
. Windows 4000 ,
, , ,
, . ,
, , -
. MySQL , , . , , ; , MySQL, .
. MySQL pread() pwriteO,
INSERT SELECT. (mutexes) pread()/pwrite (). - , readfile()/writefile
Windows NT, 2000 . -

2.2. MySQL

105

MySQL 1024, ,
NT, 2000 ,
Unix.

. MySQL , ,
:

, Unix- MySQL.

"", MySQL.

mysqladmin k i l l .

mysqladmin
.

shutdown , -

, Windows- " ".

ALTER TABLE. ALTER TABLE,


. , Windows
, . ,
, .

DROP TABLE. DROP TABLE , MERGE,


Windows, MERGE
MySQL. Windows ,
MERGE ( FLUSH TABLE),
MERGE DROP TABLE.
.

DATA DIRECTORY INDEX DIRECTORY. DATA DIRECTORY INDEX DIRECTORY


CREATE TABLE Windows- MySQL ,
Windows . , r e a l p a t h ().

DROP DATABASE. , -
.

MySQL (Task Manager).


MySQL shutdown Windows 95.
mysqladmin shutdown.

, . Windows
, MySQL
Windows . ,
SQL-.

'V . Windows 95
' \ \ MySQL .
LOAD DATA INFILE SELECT.. .INTO OUTFILE,
V Unix, :
mysql> LOAD DATA INFILE 'Ci/tmp/skr.txt' INTO TABLE skr;
mysql> SELECT * INTO OUTFILE 'Cr/tmp/skr.txt f FROM skr;

106

2. MySQL

'V:
mysql> LOAD DATA INFILE ':\\tmp\\skr.txt' INTO TABLE skr;
mysql> SELECT * INTO OUTFILE 'C:\\tmp\\skr.txt' FROM skr;
.
Windows. AZ/CHAR(24), Windows
. ,
:
:\> mysqlbinlog __ | mysql user=root
, ,
AZ/CHAR(24), :
:\> mysqlbinlog __ result-file=/tmp/bin.sql
:\> mysql user=root execute "source /tmp/bin.sql"

SQL-, .
'Can't open named pipe9 (' 9).
MySQL 3.23 Windows NT MySQL, :
error 2017: can't open named pipe to host: . pipe...
2017: : . ...
, MySQL Windows
NT . , host=localhost MySQL-, : \my. cnf, :
[client]
host = localhost
MySQL 3.23.50,
, mysqld-nt mysql-max-nt enabled-named-pipe.
'Access denied for user 9 (' 9).
MySQL, , , ,
: 'Access denied for user 'some-user@unknown' to database 'mysql'',
, MySQL .
, \windows\hosts,
:
127.0.0.1

localhost

,
MySQL Windows:
- MySQL.
mysqld
Windows 95. mysqladmin shutdown.

2.2. MySQL

107

readline Windows,
mysql.
MySQL (mysql,
mysqldhow, mysqladmin mysqldump).
, net. . Windows
mysqladmin k i l l .

/, Windows.

2.2.2. MySQL Linux


MySQL Linux RPM. MySQL RPM- Linux SuSE 7.3, Linux, rpm glibc. , RPM-, 2.1.3.
!
if*

|f

%
fj|

MySQL RPM- .
, , MySQL AB,
.
.

RPM- (, "Sorry, the host 'xxxx' could not be looked up" (", '' ")), 2.6.1.2.
MySQL
- MySQL-server MySQL-client. . MySQL-Max,
, RPM MySQL-Max (. 4.1.2).
MySQL 4.0 , (, "error: removing these packages would break
dependencies: libmysqlclient.so.10 is needed by . . . " (": : libmysqlclient.so.10 ...")), MySQL-shared-compat,

(libmysqlclient. so. 12 MySQL 4.0 libmysqlclient. so. 10 MySQL 3.23).
Linux MySQL 3.23,
, .
(, MySQLshared), MySQL ( ).
, MySQL (, Red Hat Linux),
3.23 MySQL-shared,
MySQL-shared-compat.

108

2. MySQL

RPM-:
MySQL-server-.386.rpm
MySQL. , MySQL, . , RPM- 4.0.10 MySQL. i386. rpm, -server.
MySQL-Max-. 386. rpm
MySQL-Max. , RPM- MySQL-server. RPM MySQL-serve , RPM- MySQL-serve r .
MySQL-client-.386.rpm
MySQL. , .
MySQL-bench-.386.rpm
. Perl
DBD::mysql.
MySQL-devel-.386.rpm
,
MySQL-, Perl.
MySQL-shared-.386.rpm
(libmysqlclient.so*),

MySQL.
MySQL-shared-compat-.386.rpm
( )
MySQL 3.23, MySQL 4.O. MySQL-shared.
MySQL-embedded-.386. rpm
MySQL ( MySQL 4.0).
MySQL-.src.rpm
.
RPM-,
(, Alpha SPARC).
RPM- (, MySQL-server)
:
shell> rpm -qpl MySQL-server-BPCM.i386.rpm
:
shell> rpm - i MySQL-server-.i386.rpm
shell> rpm - i MySQL-client-BPOlff.i386.rpm
, :
shell> rpm - i MySQL-client-BPO^.i386.rpm

2.2. MySQL

109

RPM
.
2.1.4.
RPM /var/lib/mysql. , mysql (
), MySQL,
/ e t c / i n i t . d
. ( ,
- , , RPM). 2.4.3 , MySQL
.
RPM- MySQL Linux, / e t c / i n i t . d
( ), , . , /etc/rc.d/init.d,
RPM
/ e t c / i n i t . d , :
shell> cd /etc
shell> In -s r c . d / i n i t . d .
Linux , /etc/init.d, LSB (Linux Standard Base).
RPM-, , MySQL-server, mysqld . MySQL.
- ,
, (. 2.2.5).
;

1;' , MySQL,
h . ,
\/ 2.4.

2.2.3. MySQL Mac OS X


MySQL 4.0.11, MySQL Mac OS
X ("Jaguar"), Mac OS X PKG
tar. , Max OS (,
10.1.x) .
(.dmg),
Finder. .
MySQL 2.1.3.

2. MySQL

110
!

, , MySQL . MySQL Manager Application ( Mac OS X


Server), mysqladmin shutdown .

MySQL PKG,
. Mac OS X Package Installer,
MySQL.
- Mac OS X :
You cannot install this software on this disk, (null)
, (null)
, Go Back ()
, . Continue (), .
. Apple,
.
Mac OS X PKG MySQL /usr/local/mysql /usr/local/mysql, . /usr/local/mysql ,
/usr/local/mysql.bak.
mysql,
mysql_install_db.
,
tar, - MySQL
/usr/local/mysql/bin. MySQL
/tmp/mysql. sock. . 2.1.5.
MySQL Mac OS X
mysql. Mac OS X 10.2 .
Mac OS X Server, , , MySQL
. MySQL, Mac OS X
Server, :
Mac OS X Server

MySQL

10.2-10.2.2
10.2.3-10.2.6
10.3
10.3.2

3.23.51
3.23.53
4.0.14
4.0.16


MySQL Mac OS X PKG. Apple
MySQL: "Help View", "Mac OS X Server", "MySQL" , "Installing MySQL".
MySQL Mac OS X Server , mysqld safejnysqld,
mysqldsaf , MySQL 4.0.

2.2. MySQL

111

MySQL Mac OS X (Marc


Liyanage) (http://www.entropy.ch),
, h t t p : //www. entropy. ch.
3.23.x MySQL Mac OS X
MySQL, Mac OS X Server, MySQL PKG,
MySQL , (. 2.5.8).
, MySQL , MySQL Startup Item. MySQL
4.0.15, . MySQLStartupItem.pkg,
.
, Startup Item ! MySQL.
Startup Item /Library/StartupItems/MySQLCOM.
( MySQL 4.1.2 /Library/StartupItems/MySQL,
MySQL Startup Item, Mac OS X Server.)
Startup Item MYSQLCOM=-YES-
/etc/hostconfig.
MySQL, MYSQLCOM=-NO-.
Mac OS X Server MySQL
MYSQL /etc/hostconfig. Startup Item MySQL AB , MYSQL=-NO-.
MYSQLCOM, Startup Item MySQL AB.
MySQL, .
.
MySQL MySQL, . .
Startup Item:
shell> sudo /Library/StartupItems/MySQL/MySQL s t a r t
(Enter your password, if necessary)
(Press Control-D or enter "exit" to exit the shell)
( )
( Control-D "exit" )
Startup Item , :
shell> cd /usr/local/mysql
shell> sudo ./bin/mysqld_safe
(Enter your password, if necessary)
(Press Control-Z)
( )
( Control-Z)
shell> bg
(Press Control-D or enter "exit" to exit the shell)
( Control-D "exit" )

/usr/local/mysql/bin/mysqld.

, ,

112

2. MySQL

|1 !
, MySQL,
f . ,
2.4.

, ,
mysql mysqladmin. tcsh:
alias mysql /usr/local/mysql/bin/mysql
alias mysqladmin /usr/local/mysql/bin/mysqladmin
bash:
alias
alias

mysql=/usr/local/mysql/bin/mysql
mysqladmirWusr/local/mysql/bin/mysqladmin

, /usr/local/mysql/bin PATH. , $HOME/.tcshrc, tcsh:


setenv PATH ${PATH}:/usr/local/mysql/bin
.tcshrc , .
, ,
MySQL PKG . , MacOS X , .
MySQL ,
. , , , . , . Package Receipt, /Library/Receipts/mysql-..

2.2.4. MySQL NetWare


MySQL NetWare Novell. Novell NetWare 6.5 MySQL
,
NetWare.
4.0.11, MySQL Novell Netware
. MySQL NetWare Metrowerks
CodeWarrior for NetWare - GNU autotools.
NetWare http://dev.mysql.com/downloads/
(. 2.1.3).
MySQL NetWare :
NetWare 6.5 NetWare 6.0
(Support Pack) 3. :
http://support.novell.com/filefinder/13659/index.html

2.2. MySQL

113

Novell NetWare.
MySQL, ,
NSS; .
MySQL NetWare :
1. , MySQL. :
SERVER: mysqladmin -u root shutdown
2. ,
MySQL.
3. Zip- .
Zip-. SYS: \.
(, SYS:MYSQL\DATA), my.cnf, . MySQL.
4. , ,
. SYS:MYSQL. .
5. ,
NLM- MySQL, :
SERVER: SEARCH ADD SYS:MYSQL\BIN
6. , , mysqld_install_db .
7. MySQL m y s q l s a f e .
8.
autoexec.ncf. , MySQL
SYS:MYSQL ,
, :
# S t a r t s t h e MySQL 4 . 0 . x database server
#3 MySQL 4 . 0 . x
SEARCH ADD SYS:MYSQL\BIN
MYSQLD_SAFE
MySQL NetWare 6.0, s k i p - e x t e r n a l - l o c k i n g :
# S t a r t s t h e MySQL 4 . 0 . x database server
#3 MySQL 4 . 0 . x
SEARCH ADD SYS:MYSQL\BIN
MYSQLD_SAFE - - s k i p - e x t e r n a l - l o c k i n g
, CHECK TABLE REPAIR TABLE myisamchk, myisamchk . ,
NetWare 6.0 , NetWare 6.5.

114

2. MySQL
mysqldsaf e NetWare . () NLM- mysqld_safe, .
:
*<NLM has terminated; Press any key to close the screen>*
*<NLM ;

>*

, NetWare , autoclose, :
# S t a r t s t h e MySQL 4 . 0 . x d a t a b a s e s e r v e r
#3 MySQL 4 . 0 . x
SEARCH ADD SYS:MYSQL\BIN
MYSQLD_SAFE a u t o c l o s e

mysqld_safe NetWare 4.1.3.


MySQL,
MySQL autoexec.ncf .
|

;>

, MySQL,
. ,
2.4.

2.2.5. MySQL Unix-

MySQL,
, t a r ( .tar.gz).
2.1.2.5.
MySQL 2.1.3.
MySQL t a r mysql-.tar.gz, - (, 4.0.17),
, (, pc-linuxgnu-i586).
,
, . 2.2 , .
t a r :
GNU gun zip .
t a r . , , GNU tar. tar, , . , t a r Mac OS X Sun . Mac OS X
gnutar.
t a r GNU t a r .
, mysqlbug
MySQL. ,

2.2. MySQL

115

mysqlbug , .
mysqlbug, . mysqlbug
bin . . 1.7.1.3.
, MySQL, , :
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < ///mysql--.tar.gz | tar xvf shell> In -s ---1--0 mysql
shell> cd mysql
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
shell> bin/mysqld_safe user=mysql &
MySQL, 4.0,
bin/mysqld_saf bin/safe_mysqld.
!
MySQL.
, 2.4.

.
1. mysqld:
shell> groupadd mysql
shell> useradd -g mysql mysql
mysql mysql.
groupadd useradd Unix.
adduser addgroup.
- mysql. ,
.
2. , . /usr/local. (,
/usr/local.
, root.)
shell> cd /usr/local
3. , 2.1.3.
MySQL.
4. , . :
shell> gunzip < ///mysql--.tar.gz | tar xvf shell> In -s noMHbiu-nyTb-K-mysql-BEPCM-OC mysql

116

2. MySQL
t a r mysql--. In . - /usr/local/mysql.
GNU tar
gun zip. :
shell> tar zxvf ///mysql--.tar.gz

5. :
s h e l l > cd mysql

.
bin scripts:
bin. .
PATH,
MySQL (. ).
scripts. mysql_install_db,
, .
6. MySQL ,
:
shell> scripts/mysql_install_db --user=mysql
root,
--user, . , .
, user .
, MySQL,
3.22.10, mysql_install_db . . .
7. root, , mysqld. , (/usr/local/mysql),
:
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
root.
mysql.
mysql.
8. , MySQL , support-files/mysql. server , .
support-files/mysql. server, 2.4.3.

2.3. MySQL

117

9. Perl- DBI DBD: :mysql, bin/mysql_setpermission. 2.7.


10. mysqlaccess, MySQL , ,
mysqlaccess mysql. bin/mysqlaccess
18- . , :
$MYSQL = Vusr/local/bin/mysql 1 ;

# path to mysql executable


# mysql

, mysql .
, mysqlaccess
Broken pipe ( ).
, , .
MySQL :
shell> bin/mysqld_safe user=mysql &
MySQL, 4.0, bin/mysqld_safe
bin/safe_mysqld.
mysqld_safe 4.1.3.

|! !
^ , MySQL,
. ,
|< 2.4.

2.3. MySQL

, , .
, ,
.
, 2.1.3.
MySQL tar-
mysql-, t a r . gz, - , , 5.0.0-alpha.
MySQL :
GNU gun zip .
t a r . , , GNU tar. tar, , . , t a r Mac OS X Sun . Mac OS X
gnutar. t a r GNU tar.

118

2. MySQL

ANSI C++. , ,
, : 2.95.2 , egcs
1.0.2 , egcs 2.91.66, SGI C++ SunPro C++. libg++
. 2.11.x ,
C++, ,
sql/sql_base.cc. 2.77.x, , MySQL, gcc
2.8.1 ,
, ^ - .
2.95.2 MySQL
3.23.x.
make. GNU make , . GNU make
3.75 .
, fno-exceptions, , .
, .
felide-constructors f n o - r t t i
fno-exceptions. , :
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
fno-exceptions -fno-rtti" ./configure \
prefix=/usr/local/mysql enable-assembler \
with-mysqld-ldflags=-all-static

.
, mysqlbug
MySQL. ,
mysqlbug , .
mysqlbug, . mysqlbug
bin . . 1.7.1.3.

2.3.1.
, :
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> gunzip < mysql-.tar.gz | tar -xvf shell> cd mysql-
shell> ./configure prefix=/usr/local/mysql
shell> make
shell> make install
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> cd /usr/local/mysql
shell> bin/mysql_install_db user=mysql

2.3. MySQL
shell>
shell>
shell>
shell>

119

chown -R root .
chown -R mysql var
chgrp -R mysql .
bin/mysqld_safe user=mysql &

MySQL, 4.0,
bin/mysqld_safe bin/safe_mysqld.
RPM, :
s h e l l > rpm --rebuild c l e a n MySQL-.src.rpm

RPM-,
.
% !
; MySQL.

, 2.4.

:
1. mysqld:
shell> groupadd mysql
shell> useradd -g mysql mysql
mysql mysql.
groupadd useradd Unix.
adduser addgroup.
- mysql. ,
.
2. , , .
3. , 2.1.3.
4. :
shell> gunzip < //'/mysql-.tar.gz | tar xvf mysql-.
GNU t a r gunzip .
:
shell> tar zxvf ///mysql-.tar.gz
5. :
shell> cd mysql-
, MySQL
.
6. :

shell> ./configure prefix=/usr/local/mysql


shell> make
configure .
./configure --help. 2.3.2

120

2. MySQL
.
configure ,
MySQL ,
configure.log, , , .
, configure.
mysqlbug. . 1.7.1.3.

7. :
shell> make install
,
, support-files, :
shell> cp support-files/my-medium.cnf /etc/my.cnf
, root.
innoDB,
/etc/my.cnf, # ,
c
innodb_...', . .
3.3.2 9.4.
8. :
shell> cd /usr/local/mysql
9. MySQL ,
:
shell> bin/mysql_install_db user=mysql
root,
user, . , .
, user .
, MySQL,
3.22.10, mysql_install_db . . .
10. root, , mysqld. , (/usr/local/mysql),
:
shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
root.
mysql.
mysql.
11. , MySQL , support-files/mysql. server , -

2.3. MySQL

121

.
support-files/mysql. server, 2.4.3.
12. Perl- DBI DBD::mysql, bin/mysql_setpermission. 2.7.
, , .
MySQL :
shell> bin/mysqld_safe user=mysql &
MySQL, 4.0, bin/mysqld_safe
bin/safe_mysqld.

raysqld ended (mysqld ), , ,
host_name. err, .
mysqld_safe 4.1.3.

f| !
|| , MySQL,
f* . ,
2.4.

2.3.2. configure
configure MySQL.
.
(. ). ,
configure, :

shell> ./configure help


configure.
,
, --without-server.
C++, mysql (
, C++). configure , C++,
without-server.
mysql, , mysql.. ( make , -, , ,
.)
MySQL (libmysqld.a), with-embedded-server.
,
/usr/local/var, configure :

shell> ./configure prefix=/usr/local/mysql

122

2. MySQL
shell> ./configure --prefix=/usr/local \
--localstatedir=/usr/local/mysql/data
, ,
/usr/local, /usr/local/mysql.
,
, / u s r / l o c a l / v a r ,
/usr/local/mysql/data. , MySQL,
(. 3.3.2).

Unix , MySQL
, (/tmp /var/run), configure , :
shell> ./configure \
with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
. mysql. sock (. .4.5).
, (,
, Red Hat Linux), configure :
shell> ./configure with-client-ldflags=-all-static \
with-mysqld-ldflags=-all-static
gcc libg++
libstdc++, configure, C++
gcc:
shell> CC=gcc CXX=gcc ./configure
gcc C++, libg++ libstdc++. , ,

MySQL.
:
gcc 2.7.2:
CC=gcc CXX=gcc CXXFLAGS="-O3 -felide-constructors"

egcs 1.0.3a:
CC=gcc CXX=gcc CXXFLAGS="-03 -felide-constructors \
-fno-exceptions -fno-rtti"

gcc 2.95.2:
CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-03 -mpentiumpro \
-felide-constructors -fno-exceptions -fno-rtti"
pgcc 2.90.29 :
CFLAGS="-03 -mpentiumpro -mstack-align-double" CXX=gcc \

2.3. MySQL

123

CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \


-felide-constructors -fno-exceptions -fno-rtti"
MySQL, configure
:
prefix=/usr/local/mysql enable-assembler \
with-mysqld-ldflags=-all-static
, configure , , :
CFLAGS="-O3 -mpentiumpro" CXX=gcc CXXFLAGS="-O3 -mpentiumpro \
-felide-constructors -fno-exceptions - f n o - r t t i " ./configure \
prefix=/usr/local/mysql enable-assembler \
with-mysqld-ldflags=-all-static
, http://www.mysql.com,
(. 2.1.2.5). , ,
(. 6.5.3).
, ,

l i b m y s q l c l i e n t . s o . # ( ' # ' - ), , configure disable-shared. configure l i b m y s q l c l i e n t . s o . #.

MySQL , (DEFAULT) ,
NULL (. 1.8.6.2):
s h e l l > CXXFIAGS=-DDONTJJSEJ)EFAULT_FIELDS ./configure
, INSERT , NOT NULL.

MySQL l a t i n l (ISO-8859-1). - - w i t h - c h a r s e t :
shell> ./configure with-charset=Ha6op
: big5, cpl251,
1257, czech, danish, dec8, dos, eucjtr, gb2312, gbk, germanl, hebrew, hp8,
hungarian, koi8_ru, koi8_ukr, l a t i n l , Iatin2, s j i s , swe7, tis620, ujis, usa7
winl251ukr. 4.7.1.
.
MySQL l a t i n l _ s w e d i s h _ c i .
with-collation:
shell> ./configure with-collation=collation
, with-charset with-collation.

124

2. MySQL
. ( SHOW
COLLATION ,
.)
, SET CHARACTER SET. "MySQL. ".

|
||
||

, myisamchk - r -q set-character-set=Ha6op. . ( , MySQL, - , MySQL


.)

configure with-extra-charsets=Cn#COiC, , . - , , complex, ,


, a l l - .
MySQL ,
with-debug:
shell> ./configure with-debug

, , .
, , ,
MySQL, enable-thread-safe-client.
libmysqlclientr,
.
, ,
, (. 2.6).

2.3.3.
|

, || . MySQL ,
|; ( ).

:
1. BitKeeper http://www.bitmover.com/cgi-bin/download.cgi. BitKeeper 3.0 .
2. .

2.3. MySQL

125

3. BitKeeper , ,
MySQL.
3.23:
shell> bk clone bk://mysql.bkbits.net/mysql-3.23 mysql-3.23
4.0:
shell> bk clone bk://mysql.bkbits.net/mysql-4.0 mysql-4.0
5.0, :
shell> bk clone bk://mysql.bkbits.net/mysql-5.0 mysql-5.0

mysql-3.23/, mysql-4.0/, mysql-4.1/ mysql-5.0/ .

HTTP-, BitKeeper HTTP.
-, http_proxy, :
shell> export httpjproxy="http://your.proxy,server:8080/"
bk: // http: //, :
shell> bk clone http://mysql.bkbits.net/mysql-4.! mysql-4.1

, . , .
4. GNU make, autoconf 2.53 ( ), automake 1.5,
libtool 1.4 m4 . ,
make, ,
.
GNU make ( gmake).
, GNU,
. , :
http://www.gnu.org/software/autoconf/
http://www.gnu.org/software/automake/
http://www.gnu.org/software/libtool/
http://www.gnu.org/software/m4/
http://www.gnu.org/software/make/
MySQL 4.1 ,
GNU bison 1.75 . bison :
sql_yacc.yy:#####: fatal error: maximum table size (32767) exceeded
sql_yacc.yy:#####;
(32767)

126

2. MySQL

^ !
/ ,
/ bison.

MySQL, 4.1,
(, BSD yacc 91.7.30). GNU bison.
, . cd
.
mysql-4.0 .
shell>
shell>
shell>
shell>
shell>
shell>
shell>

cd mysql-4.0
bk -r edit
aclocal; autoheader; autoconf; automake
(cd innobase; aclocal; autoheader; autoconf; automake)
(cd bdb/dist; sh s_all)
./configure #
make

, innobase bdb/dist,
innoDB Berkley DB (BDB).
InnoDB BDB, .
- ,
, libtool.
BUILD/. ,
BUILD/compile-pentium-debug
. ,
, Pentium.
5. , make i n s t a l l .
.
. MySQL, ./configure prefix,
--with-tcp-port --unix-socket-path, ,
.
6. ,
. make test.
7. make , h t t p : //bugs .mysql. com. GNU , . aclocal not found (
) - , .
, , PATH ,
.

2.3. MySQL

127

8. bk clone, , bk pull, .
9. bk revtool. - , , MySQL
internals (. 1.7.1.1). , , -, , , bk dif fs ,
.
, .
10. BitKeeper ,
bk helptool.
., ( bk ci bk
citool) MySQL internals, , openloging.org, .
, ( bk push). bk dif f s, .
, . ,
MySQL 4.1, http://mysql.bkbits.net: 8080/mysql-4.1.
, :
shell> bk clone bk://mysql.bkbits.net/mysqldoc mysqldoc
BitKeeper MySQL
Control Center ( MySQL) Connector/ODBC.
.
MySQL Control Center, :
shell> bk clone http://mysql.bkbits.net/mysqlcc mysqlcc
Connector/ODBC :
shell> bk clone http://mysql.bkbits.net/myodbc3 myodbc3

2.3.4. MySQL
MySQL Linux Solaris
- .
-
. 2.3.5 , MIT-pthreads. .
.
, :
configure , , , .

128

2. MySQL
config. cache. configure , . , configure ,
, .
, .

configure make . ,
, ,
.

, configure:
shell> rm config.cache
shell> make clean
make distclean.
,
MySQL.
s q l y a c c . c c
, , , , ,
:

Internal compiler error: program cclplus got fatal signal 11


: cclplus
11
Out of v i r t u a l memory

Virtual memory exhausted

, sql_yacc.cc . configure
with-low-memory:
shell> ./configure with-low-memory
f no-inline,
, -00 - .
with-low-memory, ,
, . ,
with-low-memory .
configure ++,
-lg++. ,
:

configure: error: installation or configuration problem:


C++ compiler cannot create executables.

configure: : :
C++ .

2.3. MySQL

129

, g++, libg++ libstdc++.


, ++, ++, libg++ libstdc++. conf ig. log. ,
C++ . C++. -03:
shell> CXX="gcc -03"

./configure

, C++ ,
++, libg++
libstdc++.
g++, libg++
libstdc++. , libg++
libstdc++ M y S Q L , mysqld,
- .
M y S Q L .
C + + ,
M y S Q L R A I D
3 . width-raid
, ,
C++, :
-03 -DDBUG_OFF -rdynamic - isamchk isamchk.o sort. libnisam.a
../mysys/libmysys.a ../dbug/libdbug.a ../strings/libmystrings.a
-Ipthread -lz -lcrypt -lnsl -lm -lpthread
../mysys/libmysys.a(raid.o)(.text+0x79): In function
"my_raid_createf:: undefined reference to "operator new(unsigned)'
../mysys/libmysys.a(raid.o)(.text+Oxdd): In function
4
my_raid_create':: undefined reference to "operator delete(void*)'
../mysys/libmysys.a(raid.o)(.text+0xl29): In function
"my_raid_openf:: undefined reference to "operator new(unsigned)'
../mysys/libmysys.a(raid.o)(.text+0xl89): In function
"my raid open1:: undefined reference to "operator delete(void*)'
../mysys/libmysys.a(raid.o)(,text+0x64b): In function
"my_raid_close':: undefined reference to "operator delete(void*)'
collect2: Id returned 1 exit status
, , make G N U make.
making all in mit-pthreads
make: Fatal error in reader: Makefile, line 18:
Badly formed macro assignment

make: file "Makefile' line 18: Must be a separator (:

pthread.h: No such file or directory

130

2. MySQL

, Solaris FreeBSD
, make.
, GNU make 3.75 .
C++,
CFLAGS CXXFLAGS.
- . :
shell>
shell>
shell>
shell>
shell>

CC=gcc
CFLAGS=-O3
CXX=gcc
CXXFLAGS=-O3
export CC CFLAGS CXX CXXFLAGS

2.1.2.5 , .
, , :
client/libmysql.c:273: parse error before N attribute '
client/libmysql.:273: '
, 2.8.1 ,
2.95.2 egsc 1.0.3.

mysqld , , configure
accept(), getsockname() getpeername():
: Error: mysqld.cc, line 645: In this statement, the referenced
type of the pointer value ''length1' is ''unsigned long 1 1 ,
which is not compatible with ''int1'.
new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
, config.h (
configure). :
/* Define as the base type of the last arg to accept */
/* */
#define SOCKET__SIZE_TYPE XXX
XXX s i z e t int, .
(, configure, config.h.)

sql_yacc.cc sql_yacc.yy. sqlyacc.ee, MySQL


. ,
:
"sql_yacc.yy", line xxx f a t a l : default action causes p o t e n t i a l . . .
, . ,
bison ( GNU) .

2.3. MySQL

131

Debian Linux 3.0 gawk


mawk, MySQL 4.1
Berkley DB.

mysqld MySQL, configure


with-debug,
.

Linux (, SuSE Linux 8.1 Red Hat


Linux 7.3) , :
libmysql.c:1329: warning: passing arg 5 of 4 gethostbyname_r' from
incompatible pointer type
libmysql.c:1329: too few arguments to function 4 gethostbyname_r'
libmysql.c:1329: warning: assignment makes pointer from integer
without a cast
make[2]: *** [libmysql.lo] Error 1
, configure
, C++ GNU g++.
, ++.
:

, ++ GNU C++ . Linux , - -++.

C++,
:
export CXX="gcc"

configure.

2.3.5. MIT-pthreads
, MITpthreads.
Linux MIT-p threads.
LinuxThreads. .
2.6.1.
, MySQL MIT-p threads. FreeBSD, SunOS 4.x, Solaris 2.4 , (. 2.1.1).
MySQL 4.0.2, MIT-pthreads
. , http://www.mysql.com/Downloads/Contrib/pthreads-l_60_beta6-mysql.tar.gz.

MySQL. m i t - p t h r e a d s .

MIT-pthreads, configure with-mit-pthreads:


shell> ./configure with-mit-threads

132

2. MySQL
, , MIT-pthreads,
, .

, MIT-pthreads,
, .
without-server,
, - , MITpthreads Unix-.
Unix- MIT-pthreads ,
, -h
h o s t .

MySQL MIT-pthreads, , .

external-locking. , MySQL , .

bind () pthread-
( , Solaris). :
s h e l l > mysqladmin version
mysqladmin: connect to server at ? l failed;
e r r o r : 'Can't connect to mysql server on localhost

(146)'

mysqld. , .

MIT-pthreads s l e e p () SIGINT (). ,


mysqladmin s l e e p .
s l e e p (), .

, ( , Solaris), :
Id: warning: symbol v _iob' has differing sizes:
(file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
f i l e /usr/lib/libc.so value=0xl40);
/my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
Id: warning: symbol iob 1 has differing s i z e s :
(file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
f i l e /usr/lib/libc.so value=0xl40);
/my/local/pthreads/lib/libpthread.a(findfp.o) definition taken

:
i m p l i c i t d e c l a r a t i o n of function
i m p l i c i t d e c l a r a t i o n of function

4
4

int s t r t o l l ( . . . ) '
int strtoul(...)'

r e a d l i n e MIT-pthreads ( , , , , - .)

2.3. MySQL

133

2.3.6. MySQL
Windows
MySQL 4.1
Windows. BitKeeper,
.
;

, , ,
MySQL Windows,
BitKeeper. MySQL AB
MySQL, .
MySQL,
7, MySQL AB Windows. ;, 2.2.1.

MySQL Windows , Windows:


VC++ 6.0 ( Service Pack 4 Service Pack 5, ).
. :
http://msdn.microsoft.com/vstudio/downloads/updates/sp/vs6/sp5/faq.aspx.
45 .
64 .
MySQL Windows.
MySQL 4.1 :
1. , MySQL AB MySQL, . MySQL
http://dev.mysql.com/downloads.
2. , BitKeeper.
, Unix,
Windows. ( ,
, Unix.)
BitKeeper :
Unix Linux;
BitKeeper 3.0.
http://www.bitkeeper.com.
Windows, 2.3.6.1. BitKeeper
2.3.6.2.
, - , , Windows,
Win32 (. 1.7.1.1).

2. MySQL

134
2.3.6.1. MySQL VC++
!

VC++ MySQL 4.1 , MySQL AB


, Microsoft Visual Studio 6.0 (7.0/.NET).
MySQL :
1. (, : \workdir).
2. WinZip
Windows, zip-.
3. VC++ 6.0.
4. File () VC++ Open Workspace ( ).
5. mysql.dsw, .
6. Build () Set Active Configuration ( ).
7. mysqld - Win32 .
8. <F7> , .
9. .
10. client_debug
lib_debug. , , c l i e n t _ r e l e a s e
l i b r e l e a s e . , Build Build All ( ).
11. . , ,
, MySQL , , C:\mysql C:\mysql\data.
, ,
.
basedir datadir, ( my.ini Windows :\my.cnf).
, - ,
.
12. client_release client_debug,
, . 2.2.1. , .
13. ,
mysql,
client_release client__debug.
, , . MySQL, .

2.3. MySQL

135

1. , MySQL . ,
: \mysql :
:\>
:\>
:\>
:\>
:\>

mkdir
mkdir
mkdir
mkdir
mkdir

C:\mysql
C:\mysql\bin
C:\mysql\data
:\mysql\share
C:\mysql\scripts


MySQL, :
:\> mkdir C:\mysql\include
:\> mkdir C:\mysql\lib
:\> mkdir C:\mysql\lib\debug
:\> mkdir C:\mysql\lib\opt
MySQL,
:
:\> mkdir C:\mysql\sql-bench
Perl.
2. workdir : \mysql :
:\> cd \workdir
C:\workdir> copy client_release\*.exe C:\mysql\bin
:\workdir> copy client_debug\mysqld.exe :\mysql\bin\mysqld-debug.exe
C:\workdir> xcopy scripts\*.* C:\mysql\scripts /E
C:\workdir> xcopy share\*.* C:\mysql\share /E

MySQL, :
C:\workdir> copy lib_debug\mysqlclient.lib C:\mysql\lib\debug
C:\workdir> copy lib_debug\libmysql.* C:\mysql\lib\debug
C:\workdir> copy lib_debug\zlib.* C:\mysql\lib\debug
C:\workdir> copy lib_release\mysqlclient.lib C:\mysql\lib\opt
C:\workdir> copy lib_release\libmysql.* C:\mysql\lib\opt
C:\workdir> copy lib_release\zlib.* C:\mysql\lib\opt
C:\workdir> copy include\*.h C:\mysql\include
C:\workdir> copy libmysql\libmysql.def C:\mysql\include
MySQL, :
C:\workdir> xcopy sql-bench\*.* C:\mysql\bench /
, (. 2.2.1).

2.3.6.2. Windows ,

Windows ,
BitKeeper, . , Unix Unix-
. , , , Linux.

136

2. MySQL

1. MySQL ( 4.1 )
BitKeeper. , ,
2.3.3.
2. . :
shell> ./BUILD/coinpile-pentium-max
3. , , ,
:
shell> ./scripts/make_win_src_distribution
Windows.
, :

help. .

debug. , .

dirname. ().

silent. He .

--suffix. .

tar. . t a r . gz .zip.

trap. .
make_win_src_distribution Zip
mysql-BEPCH#-win-src.zip,
MySQL .
4. Windows-.
, 2.3.6.1.

2.3.7. MySQL Windows


my_global.h mysql .h:
#include <my_global.h>
#include <mysql.h>
myglobal.h , Windows ( windows.h),
Windows.
libmysql.lib, libmysql .dll ,
mysqlclient. lib.
MySQL ,
, .

2.4.
MySQL , . , Unix
. ,
, , MySQL

2.4.

137

. ,
MySQL.
,
Windows Unix. 2.4.4 .
, , . 2.4.5 . , MySQL .
,
MySQL (.
4.4 4.5).

2.4.1. Windows
Windows . MySQL Windows mysql, . . , , 2.4.5.
, , . , (. 2.2.1.5), , , . , :
:\> C:\mysql\bin\mysqlshow
I Databases |
+
+
I mysql
|
I test
I
+
+

:\> C:\mysql\bin\mysqlshow mysql


Database: mysql
I Tables
+

|
+

I columns_priv
I db
I func
host
tables_priv
user
|
+
+
C:\> C:\mysql\bin\mysql -e "SELECT Host,Db,User FROM db" mysql
| host | db
I %

| user |

| test% |

138

2. MySQL

Windows, , ,
MySQL Windows,
2.2.1.7 .

2.4.2. Unix
MySQL Unix , . ,
, . , .
Unix mysql_install_db.
:
MySQL Linux, RPM, RPM mysql_install_db.

MySQL Mac OS X, PKG, mysql_install_db.

m y s q l i n s t a l l d b .
(
) . , ,
.
2.4.3.
, ,
, mysql_install_db. ,
, 2.4.5.
mysql. , . , , ,
.
1. MySQL, 30_0:
shell> cd 30_0
, 30_0 - /usr/local/mysql
/usr/local. , .
2. , mysql_install_db, , ,
. , , .
mysql_install_db - MySQL, , . mysql_install_db
, .
, ,

2.4.

139

, , mysqlinstalldb -
bin scripts:
shell> bin/mysql_install_db user=mysql
shell > scripts /my sql_install_db user=mysql
mysql_install_db , mysql,
, test, MySQL.
root .
. 2.4.5. MySQL
root , - t e s t t e s t .
, mysql,
, . , mysql_install_db
user, root. mysql;
user .
mysql__install_db mysql : user, db, host,
tables_priv, columns_priv, func , , , MySQL.
test,
mysqladmin -u root drop t e s t .
m y s q l i n s t a l l d b 2.4.2.1
.
m y s q l i n s t a l l d b ,
MySQL:
,
, mysql_install_db . GRANT
REVOKE , . ,
m y s q l i n s t a l l d b , mysql -u root
mysql MySQL root .
MySQL
, GRANT REVOKE , mysql
mysql_install_db. :
shell> bin/mysql_install_db user=mysql
shell> bin/mysql -u root < __
, .

2. MySQL

140

,
. , GRANT REVOKE mysql_install_db, .
, . frm, .MYI .MYD
, mysql ( mysql, ,
datadir mysqld --help). mysql_install_db .

Jf? MySQL, 3.22.10, . f r m . ff , mysql MySQL


|| m y s q l _ i n s t a l l _ d b .

mysqld skip-grant-tables
mysql:
shell> bin/mysqld_safe user=mysql skip-grant-tables &
shell> bin/mysql mysql
mysql SQL,
mysql_install_db. He mysqladmin flush-privileges
mysqladmin reload, .
, mysql_install_db, , .
3. MySQL:
shell> bin/mysqldjsafe user=mysql &
MySQL, 4.0, bin/mysqld_safe
bin/safe_mysqld.
, MySQL ( root). mysql_safe
root user.
mysql, user . MySQL .3.2.
, :
mysqld: Can't find f i l e : 'host.frm 1
mysqld:

'host.frm1

- ,
2.4.4.
4. mysqladmin . ,
:

2.4.

141

shell> bin/mysqladmin version


shell> bin/mysqladmin variables
mysqladmin version MySQL, :
shell> bin/mysqladmin version
mysqladmin Ver 8.40 Distrib 4.0.18, for linux on i586
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Server version
4.0.18-log
Protocol
version 10
Connection
Localhost via Unix socket
TCP port
3306
UNIX socket
/tmp/mysql.sock
Uptime:
16 sec
Threads: 1 Questions: 9 Slow q u e r i e s : 0
Opens: 7 Flush t a b l e s : 2 Open t a b l e s : 0
Queries per second avg: 0.000
Memory in u s e : 132K Max memory used: 16773K
, mysqladmin,
--help.
5. , :
shell> bin/mysqladmin -u root shutdown
6. , .
mysqld_saf e mysqld , :
shell> bin/mysqld_safe user=mysql log &
mysqld_saf e , 2.4.4.
7. ,
. :
: \> : \mysql\bin\mysqlshow
+
+
| Databases |
+
+
I mysql
|
I test
!
+
+
:\> C:\mysql\bin\mysqlshow mysql
Database: mysql
I Tables
|
+
+
| columns_priv |
I db
|
I func
I
I host
|
I tablesjpriv |
I user
|

142

2. MySQL
:\> C:\mysql\bin\mysql - "SELECT Host,Db,User FROM db" mysql
+
+
+
+
I host | db
| user |
+
+
+
+
I %
I test
|
|

I %

| testJ|

|
+

8. sql-bench , , MySQL . Perl DBI, .


Perl. :
DBI

DBD::mysql
Data::Dumper
Data::ShowTable
CPAN (http://www.cpan.org). . 2.7.1.
sql -bench/Results . , :
shell> cd sql-bench
shell> perl run-all-tests
sql-bench, , , MySQL RPM, ,
( RPM sql-bench). . MySQL 3.22,
RPM- mysqlbench-i386. rpm, .
t e s t , . , autoincrement.tst, :

shell> mysql -wf test < ./tests/auto_increment.tst



./tests/auto_increment.res.
9. . MySQL , , 2.4.5.

2.4.2.1. mysqMnstalldb
mysql_install_db ,
MySQL. .

2.4.

143

,
mysqld. mysql , , mysql_install_db:
shell> mv --mysql/mysql --mysql/mysql-old
shell> mysql_install_db user=mysql
,
mysql_install_db.
mysql_install_db .
, :
Starting mysqld daemon with databases from XXXXXX
mysqld ended
mysqld XXXXXX
mysqld
.
XXXXXX, ,
, , mysqld .
, ,
MySQL AB (. 1.7.1.3).
mysqld .
, , . ,
mysql_install_db, (
MySQL).
mysqld , .
, MySQL,
. ,
. , , ,
, ,
. :
Can't s t a r t server: Bind on TCP/IP port:
Address already in use
Can't s t a r t server: Bind on unix s o c k e t . . . .
: TCP/IP:

: unix....
4.9.
/tmp.
,
Unix (/tmp),
mysql_install_db mysqld.

144

2. MySQL
,
mysql_install_db mysqld:
shell> TMPDIR=/_/
she 11 > MYSQLJJNIX_PORT=/some_tmpjiir/mysql. sock
shell> export TMPDIR MYSQLJJNIX_PORT
_ , .
mysql_install_db :
shell> bin/mysql_install_db user=mysql
shell> bin/mysqld_safe user=mysql &
mysql_install_db scripts, bin scripts.
.4.5 .

2.4.3. MySQL
mysql :
mysqld. .
MySQL Windows.
Windows-, (NT, 2000 ).
Windows .
2.2.1.7.
mysqld_saf ,
mysqld .
, BSD Unix. . 4.1.3.
mysql. server. ,
System-V, mysql.
mysql.server , , , mysqld_safe. .
4.1.4.
Mac OS X MySQL
Startup Item, MySQL . Startup Item , mysql. server. . 2.2.3.
mysqld.server mysqld_safe, Mac OS X Startup Item,
. , mysqld. server Startup Item .
mysql.server,
, , s t a r t stop:
shell> mysql.server start
shell> mysql.server stop

2.4.

145

, mysql. server MySQL, mysqld_saf .


- ,
user [mysqld] /etc/my, cnf, . (, mysql.server,
MySQL . , mysqldsafe cd . ,
mysql.server ,
.)
mysql.server , .
b , mysqladmin shutdown.
MySQL ,
/etc/rc*.
RPM- Linux (MySQL-server-.), mysql.server /etc/init.d
mysql. .
RPM Linux 2.2.2.
RPM-,
, , mysqld.
MySQL ,
mysql.server, .
support-files MySQL .
mysql.server , / e t c / i n i t . d
mysql :
shell> cp mysql.server /etc/init.d/mysql
shell> chmod +x /etc/init.d/mysql
Red Hat /etc/rc.d/init.d
/etc/init.d. . , /etc/init.d , /etc/rc.d/init.d:
shell> cd /etc
shell> In -s re.d/init.d .
. Linux chkconf ig:
shell> chkconfig add mysql
Linux-
:
shell> chkconfig level 345 mysql on
FreeBSD
/usr/local/etc/rc.d/. man- (8) ,
, *.sh.

146

2. MySQL

, , . , FreeBDS mysql. server


/usr/local/etc/rc.d/mysql. server. sh, .
, , /etc/rc.local /etc/init.d/boot.local . MySQL ,
, :
/bin/sh - 'cd /usr/local/mysql; ./bin/mysqld_safe user=mysql &'

.
mysql.server /etc/my.cnf. /etc/my. cnf:
[mysqld]
datadir=/usr/local/mysql/var
socket=/var/tmp/mysql.sock
port=3306
user=mysql
[mysql.server]
basedir=/usr/local/mysql
mysql. server : basedir, datadir pid-f i l e .
, , . mysql.server start stop.
,
.

mysqld

[mysqld], [server], [mysqld--]

mysql.server

[mysqld], [mysql.server]

mysqld_safe

[mysqld], [server], [mysqld_safe]

[mysqld--) , [mysqld-4.0],
[mysqld-4.1] [mysqld-5.0] MySQL 4.0.x, 4.1.x, 5.0.x
. MySQL 4.0.14. , .
mysql.server
[mysql_server], a mysqld_safe - [safejnysqld]. , [mysql.server]
[mysqld_safe], MySQL 4.0 .
. 3.3.2.

2.44. MySQL

- , :

2.4.

147

, .
, .
, . , ,
, .
, , .
, .
, .
my.cnf .
,
(innoDB, BDB), , :
InnoDB, InnoDB . MySQL 3.23 InnoDB ,
. MySQL 4.0, InnoDB
, .
. 9.4.
BDB (Berkley DB), BDB . . 8.4.3.
mysqld . ,
. Unix
mysqld pid ( ).

. - ,
. , mysqld verbose help ( 4.1 MySQL
verbose).
MySQL
, mysqld
mysqld_saf . .
datadir. mysqld , MySQL, .
basedir.
, mysqld
verbose help. , , mysqld, , , /usr/local:
shell> ./mysqld basedir=/usr/local verbose help
, --datadir, ,
verbose help . ( MySQL,
4.1, verbose .)
, , verbose help.

148

2. MySQL

mysqld , :
shell> mysqladmin variables

shell> mysqladmin -h _ variables


_ - , MySQL.
mysqld Err code 13 ("Permission denied" - " "), ,
. , . root,
, .
Unix , , . ,
/usr/local/mysql/var, :

shell> Is -la /usr/local/mysql/var


, , , :
shell> chown -R mysql /usr/local/mysql/var
shell> chgrp -R mysql /usr/local/mysql/var
,
.
( C:\mysql\data Windows, /usr/local/mysql/data -
Unix /usr/local/var - Unix).
_. e r r ^. log, _ -
. ( Windows
mysql.err.)
. Unix t a i l :
shell> t a i l _.
shell> t a i l _.log
, .
, :
000729 14:50:10 bdb: Recovery function for LSN 1 27595 failed
000729 14:50:10 bdb: warning: . / t e s t / t l . d b : No such f i l e or directory
000729 14:50:10 Can't i n i t databases
, mysqld bdb-no-recover,
Berkley DB , -
, . ,
Berkley DB , . BDB
, log.0000000001, .

2.4.

149

mysqld BDB, , BDB.


bdb-no-recover. , BDB mysqld
bdb-no-recover.
, , - (, mysqld) TCP/IP Unix-,
mysqld:
Can't s t a r t server: Bind on TCP/IP port: Address already in use
Can't s t a r t server: Bind on unix socket...
ps , mysqld.
, . ( , ,
, ,
4.9.)
, telnet
-- --tcp-ip ( MySQL 3306),
<Enter> .
t e l n e t : Unable to connect to remote host: Connection refused
("telnet: : "),
, - TCP/IP,
mysqld. , , ,
port mysqld, .

TCP/IP.
, ,
, . , , .
, ,
/etc/hosts :
127.0.0.1 localhost
, MySQL MIT-pthreads.
mysqld , , , mysqld debug.

2.4.5. MySQL
MySQL mysql, :
MySQL Windows , .
Unix mysql_install_db. , , .
2.4.2.

150

2. MySQL


MySQL . :
root. , . ,
MySQL root .
Windows root
, - .
Unix root . localhost
IP- - .
, .
MySQL.
Windows
. , root.
,
test , test__.
Unix .
localhost IP - .
t e s t , t e s t .
, .
, MySQL , :
, , .
root.
MySQL - , root. "_" , .
, ,
.
, .
.
SET PASSWORD, UPDATE. PASSWORD ().
Windows, :
shell> mysql -u root
mysql> SET PASSWORD FOR " @'localhost 1 = PASSWORD (' _ ' ) ;
mysql> SET PASSWORD FOR "@'%' = PASSWORD(' ');

2.4.

151

Unix :
s h e l l > mysql -u r o o t
1
mysql> SET PASSWORD FOR ' ' l o c a l h o s t = PASSWORD (' _ ' ) ;
mysql> SET PASSWORD FOR ''_* = PASSWORD('_');
SET PASSWORD _ . , Host , l o c a l h o s t , r o o t u s e r . , SET
PASSWORD:
mysql> SELECT Host, User FROM m y s q l . u s e r ;
, User r o o t , Host l o c a l h o s t . Host SET
PASSWORD.
UPDATE user.
r o o t UPDATE
Password user.
Windows Unix. UPDATE
:
s h e l l > mysql -u r o o t
mysql> UPDATE m y s q l . u s e r SET Password = PASSWORD('newpwd')
->
WHERE User = ' ' ;
mysql> FLUSH PRIVILEGES;
, , UPDATE,
FLUSH
PRIVILEGES. , .
,
:
s h e l l > mysql -u r o o t
mysql> DELETE FROM m y s q l . u s e r WHERE User =
mysql> FLUSH PRIVILEGES;

";

DELETE Windows, Unix. Windows,


, , r o o t , :
s h e l l > mysql -u r o o t
1
mysql> DELETE FROM m y s q l . u s e r WHERE H o s t = ' l o c a l h o s t AND User = ' ' ;
mysql> FLUSH PRIVILEGES;
,
.
r o o t .
:

SET PASSWORD.

mysql admin.

UPDATE.

152

2. MySQL

SET PASSWORD,
root SET PASSWORD. He PASSWORD ().
Windows :
shell> mysql -u root
mysql> SET PASSWORD FOR 'root1@'localhost1 = PASSWORD('_');
mysql> SET PASSWORD FOR 'root' @' %' = PASSWORD('_');
Unix :
s h e l l > mysql -u root
m y s q l > SET PASSWORD FOR ' r o o t 1 @ ' l o c a l h o s t 1 = P A S S W O R D ( ' _ ' ) ;
mysql> SET PASSWORD FOR 'root'@'_' = PASSWORD('_');
SET PASSWORD _
. , ,
.
root mysqladmin, :
shell> mysqladmin -u root password "_"
shell> mysqladmin -u root -h __ password "_"
Windows, Unix.
_ . ,
, , ,
, .
MySQL, mysqladmin parse error near 'SET password' (
'SET password').
MySQL.
UPDATE USER.
root :
s h e l l > mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('_')
->
WHERE User = ' r o o t ' ;
mysql> FLUSH PRIVILEGES;
UPDATE Windows, Unix.
.
, mysqladmin ,
, :
shell> mysqladmin -u root -p shutdown
Enter password: (enter root password here)
: ( root)
; !
v root ,
' .4.1.
GRANT.
4.5.2.

2.5. MySQL

153

2.5. MySQL

, MySQL
, ,
. , MySQL 3.23 , MySQL 4.0, 4.1 5.0.
, MySQL:
, , , . , MySQL 4.1 MySQL 5.0
. . http://dev.mysql.com/doc/mysql/en/News.html.
, .
MySQL Windows, 2.5.7.
, mysql. , , , - . , , . 2.5.8.
, 5.6.
MySQL-Max, mysql-max, ,
MySQL-Max, , mysqld_safe - mysql-max.
mysql-max, , mysqld_saf e mysqld.
MySQL , MySQL.
MySQL 4.O. MySQL, myisamchk -r -q set-character- set=^ My ISAM.
,
.
( , ),
. mysqldump . mysql .
,
mysqld . ,
MySQL 4.0.18 MySQL 4.1.1, mysqld mysqld-4.0.18. ,
mysqld - , .
, "Commands out of sync" ( )
, , ,

154

2. MySQL

.
mysql.h libmysqlclient.a, ,
MySQL. ,
.
, mysqld
, , my.cnf
. print-defaults (, mysqld print-defaults). - , , my. cnf,
.
Perl DBD: :mysql MySQL. To MySQL,
, Python MySQLdb.

2.5.1. 4.1 5.0


MySQL 4.1 5.0 :
MySQL 5.0
(http://dev.mysql.com/doc/mysql/en/News.html).
MySQL Windows, 2.5.7.
MySQL 5.0 .
mysql. ,
mysqlf ix_privilege_tables, 2.5.8.
, 5.6.

2.5.2. 4.0 4.1


MySQL 4.0 4.1 :
, .
4.1
(http://dev.mysql.com/doc/mysql/en/News.html).
MySQL Windows, 2.5.7.
:

" "' !
- MySQL 4.1 Windows . 2.2.1.2.

,
Password, . mysql_f ix_privilege_tables,
2.5.8. .
, 5.6.

2.5. MySQL

155

Berkley DB DB 4.1 ( 3.2) . 4.0,


mysqdump BDB log.XXXXXXXXXX,
MySQL 4.0 .
.
, 4.1 , .
DBD-mysql (Msql-MySQL-modules), . DBD-mysql 2. . , ( DBl->do ()) .
MySQL 4.1 MySQL 4.0 ,
SQL. .
MySQL 4.1 MySQL 4.0 . ( 4.0.12) mysqld new (. 4.2.1).
4.1.

SET @@new=l - SET @@new=0.
, 4.1 , 4.1 MySQL 4.0
new, :
[mysqld-4.0]
new
,
4.0 , . ,
MySQL 4.1.
--new [mysqld-4.0] , MySQL 4.1 new.
, ,
4.1.
:
. SHOW CREATE TABLE
mysqldump. ( MySQL 4.0.6 , - .)
, .
, l a t i n l .
,
, MySQL 4.1 , .

2. MySQL

156

l a t i n l "" . . , , .
- . , , MySQL 4.0 latinl, I a t i n 2 n u t f 8 :
CREATE TABLE t
(
latinl_col CHAR(50),
Iatin2_col CHAR(IOO),
utf8_col CHAR(150)
);
4.1
, latinl_col , Iatin2_col
utf 8_col, Iatin2 utf 8 . , :
ALTER
ALTER
ALTER
ALTER

TABLE
TABLE
TABLE
TABLE

t
t
t
t

MODIFY
MODIFY
MODIFY
MODIFY

I a t i n 2 _ c o l BINARY(100);
u t f 8 _ c o l BINARY(150);
I a t i n 2 _ c o l CHAR(100) CHARACTER SET I a t i n 2 ;
u t f 8 _ c o l CHAR(150) CHARACTER SET u t f 8 ;

""
Iatin2_col utf 8_col. .
, :
ALTER TABLE t
MODIFY I a t i n 2 _ c o l BINARY(100),
MODIFY u t f 8 _ c o l BINARY(150);
ALTER TABLE t
MODIFY I a t i n 2 _ c o l CHAR(100) CHARACTER SET I a t i n 2 ,
MODIFY u t f 8 _ c o l CHAR(150) CHARACTER SET u t f 8 ;

, . frm,
MySQL 4.1. MySQL 4.0, 4.0.11,
. frm , - . 4.1 , 4.0.11, mysqldump. . 7.8.
/

U MySQL 4.1.1 ,
;;: 4.0 4.1.0. , InnoDB
|/ .

Windows-,
shared-memory-base-name
.
UDF- . xxx_clear () XXX ().

2.5. MySQL

157

:
mysqldump --opt quote-names, . skip-opt --skip-quote-names.
SQL:
SQL:
, . ,
' ' > f a \ t ' , . CHAR
VARCHAR, , ASCII (32),
REPAIR TABLE myisamchk,
.
DELETE ,
, . , DELETE t e s t
FROM t e s t AS t l , test2 WHERE . . . :
DELETE t l FROM test AS t l , test2 WHERE . . .

TIMESTAMP Y
' YYY-MM-DD HH:MM:SS\
( 4.0.12, new,
4.0 4.1.)
( 4.0), +0:
mysql> SELECT ts_col + FROM tbl_name;

TIMESTAMP . , TIMESTAMP (10), (10) .



SQL. ( ), TIMESTAMP
.
, OxFFDF, ,
. ,
.
CAST (), :
mysql> SELECT CAST(0xFEFF AS UNSIGNED INTEGER)
->
< CAST(0xFF AS UNSIGNED INTEGER);
-> 0
CAST (), :
mysql> SELECT OxFEFF < OxFF;
-> 1
= . ( 4.0.13,
--new, 4.0
4.1.)
, DATE, DATETIME TIME, . , MySQL 4.1
:

158

2. MySQL
mysql> SELECT CAST('2001-1-1' AS DATETIME);
-> '2001-01-01 00:00:00'
MySQL 4.0 :
mysql> SELECT CAST('2001-1-1' AS DATETIME);
-> '2001-01-01'

DEFAULT AUTO_INCREMENT (
4.0 DEFAULT , 4.1 ).
LIMIT . -
( 18446744073709551615) - 1 .

SERIALIZE
sql_mode. SET TRANSACTION ISOLATION
LEVEL SERIALIZABLE. SERIALIZE
--sql-mode mysqld. --transaction-isolation=
SERIALIZABLE.

API- :
API- , mysql_real_query(),
1, - 1 .
, :
if (mysql_real_query(mysql_object, query, query_length) == -1)
{

printf("");
}
, :
if

(mysql_real_query(mysql_object, query, query_length)

!= 0)

printf("");
}

MySQL 4.1 ,
, ,
, 4.0
. ( , 4.0, , 4.1). .

.
,
4.1. (
API), , - . ( MySQL 4.1 , ,
SQL- .)
4.1 mysql_f ix_privilege_tables,
Password user -

2.5. MySQL

159

. old-passwords
,
- . , 4.1, old-passwords. MySQL .
4.1 mysqlf ixprivilegetables,
Password user . ,
4.1, old-passwords. , . 4.1 .

4.4.9 .2.3.

2.5.3. 3.23 4.0


MySQL 3.23 4.0
:
, .
4.0
(http://dev.mysql.com/doc/mysql/en/News.html).
MySQL Windows, 2.5.7.

,
. mysql_f ix_privilege_tables
2.5.8.

, 5.6.
MySQL ,
, .
ISAM My ISAM. mysql_convert_table_format. (
Perl; , DBI).
:
shell> mysql_convert_table_format database __
, ,
ISAM My ISAM. , ISAM
.
My ISAM
ALTER TABLE, :
mysql> ALTER TABLE ^ TYPE=MyISAM;
, :

mysql> SHOW TABLE STATUS LIKE ' _*

',

160

2. MySQL

, - MySQL, ( Perl DBD: :mysql). , , ,


libraysqlclient.so, .
MySQL, , Python MySQLdb.
MySQL 4.0 , , MySQL 4.0
, MySQL 4.1 .
ISAM - MySQL 4.0, , . My ISAM.
4.0 .
,
MySQL 3.23.52 ,
MySQL 4.O. mysqldump , ,
MySQL 3.23. , 4.0
.
, , 4.0.
:
MySQL 4.0 mysql.user (.
4.4.3).
, . 2.5.8. ,
, SHOW
DATABASES, CREATE TEMPORARY

TABLES LOCK TABLES. SUPER EXECUTE

PROCESS. REPLICATION

SLAVE REPLICATION CLIENT

FILE.
, MySQL, ,
. GRANT , ,
.
4.0.2, --safe-show-database
( ). . 4.3.3.
"Access denied" (" ")
4.0.2 , , - , . , REPLICATION SLAVE ( FILE)
.

safe_mysqld mysqld_saf.
safejnysqld, mysqld_saf.

2.5. MySQL

161

InnoDB .
MySQL , InnoDB
. InnoDB , InnoDB, skip-innodb. MySQL InnoDB, configure without-innodb.

myisam_max_extra_sort_file_size myisam_raax_extra sort f i l e


( 4.0.3 ).

mysqldb temp-pool, ,
(
, Linux).

mysqldb skip-locking enable-locking , , skip-external-locking external-locking.

MylSAM/lSAM . external-locking. (
.)

myisam_bulk_insert_tree_size

bulk_insert__buffer_size

query_cache_startup_type

query_cache_type

record_buffer

read_buffer_size

record_rnd_buffer

read_rnd_buffer_size

sort_buffer

sort_buffer_size

warnings

log-warnings

err-log

log-error( mysqld_safe)

size

record_buffer, sort_buffer warnings


MySQL 4.0, .
SQL:

SQL :

SQL_BIG_TABLES

BIG_TABLES

SQL_LOW_PRIORITY_UPDATES

LOW_PRIORITY_UPDATES

SQL_MAX_JOIN_SIZE

MAX_JOIN_SIZE

SQL_QUERY_CACHE_TYPE

QUERY_CACHE_TYPE

- MySQL 4.0,
.

SET GLOBAL SQL_SLAVE_SKIP_COUNTER= _


SET SQL_SLAVE_SKIP_COUNTER=_.

SHOW MASTER STATUS , .

162

2. MySQL

SHOW SLAVE STATUS , .

SHOW INDEX , 3.23


(Null Index_type).

SHOW OPEN TABLES.


ORDER BY _ DESC NULL ,
MySQL 4.0.11. 3.23 4.0 .
CHECK, LOCALTIME LOCALTIMESTAMP .

DOUBLE FLOAT UNSIGNED (


).

(|, &, , ~) .
, ,
.
!
;

fy , UNSIGNED, \yl . , MySQL 4.0, || ,


, ':;- . sql-mode=
' NO_UNSIGNED_SUBSTRACTION mysqld. . 4.2.2.

BIGINT (
, MySQL 3.23). - ,
.
MySQL 3.23 INSERT INTO.. .SELECT IGNORE . 4.0.1, MySQL (, , ) ,
IGNORE .

TRUNCATE TABLE, . (DELETE FROM _ 4.0 , a TRUNCATE TABLE .)

TRUNCATE TABLE DROP DATABASE,


, .

MATCH.. .AGAINST (...IN BOOLEAN


MODE) , REPAIR
TABLE _ USE_FRM. , .
LOCATE () INSTR () , .
.
STRCMP () . ,
.

2.5. MySQL

163

HEX {) ,
. ,
, HEX () .

RAND {_) 4.0 , 3.23. RAND {_) RAND (_+1).


IFNULL (, ) ""
. ( - , REAL, INTEGER.)
API- :
mysql_drop_db (), mysql_create_db() mysql_connect () API ,
MySQL CFLAGS=-DUSE_OLD_FUNCTIONS. - API-.
MYSQL_FIELD length max_length unsigned
int unsigned long. , , printf ().
mysql_thread_init ()
mysql_thread_end().
:
Perl DBD: :mysql,
. 2.9003. ,
1.2218, ,
mysql_drop_db().

2.5.4. 3.22 3.23


MySQL 3.22 MySQL 3.21 MySQL 3.23 - . MySQL 3.23
.
:
MySQL 3.23 My ISAM
ISAM. My ISAM,
mysqld default-table-isam.
ISAM MySQL 3.23. ALTER TABLE _
TYPE=MyISAM Perl- mysql_convert_table_f ormat.
, tis620,
myisamchk -r REPAIR TABLE.
ISAM german, isamchk -r,
.

164

2. MySQL

:
MySQL- mysqld
no-named-commands (-g). , enable-named-commands (-G).
, ,
SQL-, .
- .
, mysqldump
MySQL 3.22 MySQL 3.23, mysqldump
opt a l l .
SQL:
DROP DATABASE ,
, , .
MySQL 3.22, configure
readlink().

OPTIMIZE TABLE My ISAM. ALTER TABLE.


OPTIMIZE TABLE ,
.
, ( MONTH()), 0 0000-00-00. MySQL 3.22 NULL.

IF () ,
.

AUTO_INCREMENT
. , , -1 0. 0
AUTO_INCREMENT. CHECK TABLE 0, ,
. AUTO_INCREMENT MylSAM , . , My ISAM , .

CASE, DELAYED, ELSE, END, FULLTEXT, INNER, RIGHT, THEN WHEN .

FLOAT (p) ,
, .

DECIMAL [, _) .
TIME :
[[[] []:]:][._] [[[[[]]]]][._].

LIKE , , =. , MySQL
CXXFLAGS=-DLIKE CMP TOUPPER.

2.5. MySQL

165

REGEXP , -
.
My ISAM (.MYI), CHECK TABLE myisamchk. ISAM
(.ISM) isamchk.
DATEFORMAT () '%' . (MySQL 3.22 ,
.)
MySQL 3.22 SELECT DISTINCT... .
MySQL 3.23
GROUP BY ORDER BY.

SUM() NULL 0, . SQL.

AND OR NULL NULL 0.


, NOT AND/OR NOT
NULL = NULL.

LPAD () RPAD () ,
, , .
API- :
m y s q l f e t c h f ields_direct () , . MYSQL_FIELD MYSQL_FIELD.
mysql_num_fields () MYSQL* (
, MYSQL__RES*).
MYSQL* mysql_field_count ().

2.5.5. 3.21 3.22


MySQL 3.21 MySQL 3.22 , . , DATE .
DATE mysqld.
MySQL 3.22 :
MySQL 3.22
mysqlf i x p r i v i l e g e t a b l e s . ,
GRANT.
, Access denied ALTER
TABLE, CREATE INDEX DROP INDEX.
2.5.8.
API- - mysq_real_connect () .
, ,
0 db ( ,
db ).
mysql_init() mysq_real__connect ().

166

2. MySQL
, mysql_options ()
MYSQL.

mysqld key__buffer key_buffer_size, .

2.5.6. 3.20 3.21


, , 3.20.28,
3.21, .
mysqld 3.21 old-protocol, 3.20. password () . ,
mysql_errno() , CR_UNKNOWN_ERROR.
.
old-protocol,
:
.
ODBC, MyODBC 2.x.
scripts/add_long_password
Password mysql.user CHAR(16).
mysql.user ,
62, 31 .
, .
MySQL 3.20.28
user, . MySQL, 3.20.28, user . , , ,
, MySQL 3.20.28, MySQL 3.21.
mysqld 3.20.x, 3.21.x, 3.20.x
.
old-protocol mysqld, :
ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
: .

= 1 0

=9

Perl DBI mysqlperl. , mysqlperl, connect (). : host, database, user password (, user password).
:

HAVING ORDER BY.

LOCATE () .
. : DATE,
DATETIME TIMESTAMP.

2.5. MySQL

167

2.5.7. MySQL Windows


MySQL Windows, :
1. MySQL Windows.
2. ,
.
3. , .
4. MySQL (, NET STOP MySQL,
Services mysqladmin shutdown).
5. WinMySQLAdmin, .
6. , Install () WinZip, .
\ !
\( - MySQL 4.1 Windows '';, . 2.2.1.2.

7. MySQL (
C:\mysql), , , C:\raysql4. .
8. , , NET START MySQL,
, mysqld.
9. . 2.5.8.
:
A system error has occurred.
System error 1067 has occurred.
The process terminated unexpectedly.
.
1067.
.

, ( C:\my.cnf)
, MySQL. ,
,
(, C:\my.cnf C:\my.cnf.old). , ,
, . my.cnf
, , , - .

2.5.8.
(
mysql), . ,
MySQL, .

168

2. MySQL

Unix Unix-
mysql_fix_privilege_tables:
shell> mysql_fix_privilege_tables
. , ,
root. root , . MySQL 4.1 :
shell> mysql__fix_privilege_tables '\=__
MySQL :
shell> mysql_fixjprivilege_tables __
mysql_fixjprivilege_tables ,
.
Duplicate column names (
). .
.
Windows-
MySQL 4.0.15. , MySQL SQL mysql_fix_privilege_tables.sql, mysql.
MySQL : \mysql, :
:\> C:\mysql\bin\mysql -u root -p mysql
mysql> SOURCE :\mysql\scripts\mysql_fix_privilege_tables.sql
mysql root; . , . Unix, mysql_fix_privilege_tables.sql
Duplicate column names. .
.

2.5.9. MySQL
MySQL 3.23 , .frm, .MYI .MYD MylSAM , (MySQL ). . 8.1.
ISAM (.ISD .ISM ) -, , .
, . mysqldump.
mysqldump , SQL-. mysql.
mysqldump help, . MySQL, mysqldump
opt, ,
, .

2.5. MySQL

169

( )
, :
shell> mysqladmin -h ' * create __
shell> mysqldump opt db_name | mysql -h ' ' __

, :
shell> mysqladmin create __
shell> mysqldump -h ' 1 opt compress __ |
mysql __
, . ,
:
shell> mysqldump quick __ | gzip > _ _ , con ten ts.gz
, , . , , :
shell> mysqladmin create __
shell> gunzip < __.contents.gz | mysql __
mysqldump mysql import.
,
mysqldump. _ , mysqldump.
:
s h e l l > mkdir _
s h e l l > mysqldump =_

__

_ - MySQL :
shell> mysqladmin create __
#
s h e l l > cat _/*. sql

| mysql ___ #

#
shell> mysqlimport __ _/*. txt #
#
mysql, user, db host. ,
root,
mysql
mysqladmin f lushprivileges, .

170

2. MySQL

2.6.

2.6.1. Linux
, Linux. ,
,
, . , Linux .
, Linux. , ,
.
2.6.1.1. Linux
MySQL , , Linux 2.0.

Linux 2.2.14 MySQL SMP-


( ). MySQL, MySQL
2.2.14. , 2.2.19 ( ) 2.4.
, 2.4, . ,
.

LinuxThreads , , mysqld. , , . LinuxThreads, , - .


2.6.1.2. Linux
Linux-Intel RPM- MySQL , . .
- s t a t i c , , , , .
LinuxThreads. ,
- s t a t i c , ,
( 3-5%). , (User-defined functions - UDF). UDF ( , C++),
MySQL
.
,
Linux-, libc ( Red Hat 4.x Slackware)
,
. libc glibc2, , , getpwnam(). , , , glibc ,

2.6.

171

, - s t a t i c . :
, mysql_install_db :
Sorry, the host 'xxxx' could not be looked up
, ''

, mysql_install_db --force,
resolveip mysql_install_db.
,
. ( localhost) IP.
mysqld user
:
getpwnam: No such f i l e or directory
getpwnam:

, mysqld, su user.
mysqld
.
- . MySQL ( RPM .tar.gz)
.
Linux 2.2
"Resource temporarily unavailable" (" "),
mysqld TCP/IP.
, Linux TCP/IP-
, . TCP/IP-c, ,
TCP/IP- . , test-connect TCP/IP.
, Linux, . - , ,
,
Unix TCP/IP-.

2.6.1.3. Linux
glib , MySQL . Linux 86, . glibc, ,
,
. , ,
,

172

2. MySQL

2 , .
, , , , ,
. , , . , .
MySQL Linux LinuxThreads.
Linux, glibc2, LinuxThreads, MySQL. http://dev.mysql.com/downloads/os-linux.htral.
, glibc 2.1.1
pthread_mutex_timedwait (),
INSERT DELAYED. INSERT DELAYED ,
glibc.
, Linux LinuxThreads
1024 . 1000 , LinuxThreads:
PTHREAD_THREADS_MAX sysdeps/unix/sysv/linux/bits/local_lim.h
4096 STACK_SIZE linuxthreads/internals .h 256 .
glibc. (, MySQL
600-1000 , STACKSIZE 2 ).
LinuxThreads,
libpthread. MySQL .
http://www.volano.com/linuxnotes.html , LinuxThreads.
,
MySQL, SMP-. LinuxThreads glibc 2.1
,
. :
MySQL LinuxThreads , SMP- MySQL.
glibc 2.1.3,
http://www.mysql.com/Downloads/Linux/linuxthreads-2.1-patch.
MySQL 3.23.36 glibc 2.2.2 , , glibc 2.I.3. ,
glibc 2.2.2 MySQL. , , ,
nice mysqld.
,
http://www.mysql.com/Downloads/Linux/linuxthreads-2.2.2.patch.

,
. linuxthreads patch -pO </tmp/linuxthreads-2.2.2.patch. , - glibc 2.2. , glibc 2.2.2 STACKSIZE
PTHREAD_THREADS_MAX. , -

2.6.

173

,
MySQL, ,
, ./configure; make; make i n s t a l l .
libpthread.a, MySQL.
, MySQL
, .
, LinuxThreads ,
, , .

MySQL, , ,
. ,
.
MySQL :
l d . s o . l : f a t a l : libmysqlclient,so.#:
open failed: No such f i l e or directory
:
-
-W1,///libmysqlclient.so.
libmysqclient.so /usr/lib.
, libmysqlclient. so,
LDRUNPATH .
Fujitsu (f cc/FCC), MySQL, Linux . configure fcc/FCC:
CC=fcc CFLAGS="-0 - fast - l i b - omitfp -Kpreex -D_GNU_SOURCE \
-DCONST=const -DNO_STRTOLL_PROTO" \
CXX=FCC CXXFLAGS="-0 -K fast -K l i b \
-K omitfp -K preex no_exceptions n o _ r t t i -D_GNU_SOURCE \
-DCONST=const -Dalloca= b u i l t i n _ a l l o c a -DNO_STRTOLL_PROTO \
f
-D_EXTERN_INLINE=static _ i n l i n e I M \
./configure \
prefix=/usr/local/mysql enable-assembler \
with-mysqld-ldflags=-all-static disable-shared \
with-low-memory
2.6.1.4. Linux
mysql. server support-files MySQL MySQL.
/etc/init.d/mysql ,
MySQL. . 2.4.3.
MySQL , , Linux .

174

2. MySQL

Linux 2.2
:
shell> cat /proc/sys/fs/file-max
shell> cat /proc/sys/fs/dquot-max
shell> cat /proc/sys/fs/super-max
16 ,
(, /etc/init.d/boot.local
SuSE Linux):
echo 65536 > /proc/sys/fs/file-max
echo 8192 > /proc/sys/fs/dquot-max
echo 1024 > /proc/sys/fs/super-max
root,
.
sysctl,
Linux ( SuSE , SuSE Linux 8.0).
/etc/sysctl. conf :
# Increase some values for MySQL
# MySQL
fs.file-max = 65536
fs.dquot-max = 8192
fs.super-max = 1024
/etc/my. cnf:
[mysqld_safe]
open-files-limit=8192
8192 .
LinuxThreads STACK_SIZE
. , , , ,
mysqld.
, , mmp () Linux , , , , . mysqld "" , .
, ,
, . mysqld,
max_connections.
MySQL ,
LinuxThreads (. 2.6.1.3). , max_connections
500. , , - , mysqld
, 2.2 .

2.6.

175

RPM- 3.23.25
, max_connections 1500, , . STACKSIZE LinuxThreads,
. 128 256 .
,
2.2, "fork bomb",
, . MySQL
. ,
,
( ), .
. , .
http://www.mysql.com/Downloads/Patches/linuxfork.patch.

, , .
MySQL,
, ,
2.2.
2.4, , , 2.2
2.4. SMP-

.
MySQL 2.4,
, , MySQL .
1000, MySQL ( ) 180%.
: 1000 300%.
, SMP-,
2.2, 2.4.
, mysqld 2.4 .
renice -20 $$ mysqld_safe. ,
60% 400 .
, MySQL - .
, ,
benchmarks@mysql.com.

2. MySQL

176

mysqld ps, , MySQL, . .


.4.2.
Linux mysqld
SIGSEGV, mysqld c o r e - f i l e . , ,
, ,
ulimit - 1000000 mysqld_safe mysqld_safe
--core-f ilesize=1000000. . 4.1.3.
2.6.1.5. Linux x86
MySQL l i b c 5.4.12 . , l i b c 5.4.46. g l i b c 2.0.6 . RPM- g l i b c Red Hat, ,
, , - , g l i b c 2.0.7-19
RPM- 2.0.7-29 .
Red Hat 8.0 g l i b c 2.2.x, , mysqld gethostbyaddr ().
, g l i b c 128 .
, mysqld thread-stack=192K. ( MySQL
4 -0 thread_stack=192K). MySQL
4.0.10 , ,
.
3.0 MySQL,
Iibstdc++v3 MySQL. ,
cxa_pure_virtual.
Linux configure
:
Syntax error in sched.h. Change _P to
P in the
/usr/include/sched.h file.
See the Installation chapter in the Reference Manual.
sched.h. _
P
/usr/include/sched.h.
. Installation
() .
, . _, ,
configure .
. :
mysqld. - objs-thread/mysqld.o
mysqld.ee: In function 4 void init_signals()':
mysqld.cc:315: warning: assignment of negative value 4 - l ' to
4
long unsigned int'
mysqld.ee: In function 4 void * signal_hand(void * ) ' :
mysqld.cc:346: warning: assignment of negative value 4 - l ' to
N
long unsigned int'

2.6.

177

mysqld ,
/ l i b / l i v e . . ,
sql/mysqld, make i n s t a l l mysqld .
Slackware.
mysqld,
, libg++. a:

/usr/lib/libc.a(putc.o): In function 4 _I0_putc':


putc.o (.text+OxO): multiple definition of v_IO_putc'

/usr/lib/libc.a (putc.o) : y_IO_putc ':


putc.o(.text+OxO):
y_IO_putc'
libg++.a, configure :
shell> CXX=gcc ./configure
mysqld , Red Hat 5.0 glibc, 2.0.7-5, , glibc. MySQL,

http://lists.mysql.com/.

2.6.1.6. Linux SPARC


readdir_r() .
, SHOW DATABASES . HAVE_READDIR_R config.h .

2.6.1.7. Linux Alpha


MySQL 3.23.12 - MySQL, Linux-Alpha.
MySQL Linux-Alpha, ,
.
MySQL Alpha .
MySQL SuSE Linux 7.0 for
, 2.4.4-SMP, Compaq (V6.2-505) Compaq
C++ (V6.3-006) Compaq DS20 Alpha EV6.
http://www.support.compaq.com/
alpha-tools/. 9-14%
MySQL.
, MySQL 3.23.52 4.0.2 ( -fast).
, Alpha, Alpha EV6.
-arch generic
, , Alpha. , , . configure :
= CFLAGS="-fast -arch generic" CXX=cxx \
CXXFLAGS="-fast -arch generic -noexceptions - n o r t t i " \
./configure prefix=/usr/local/mysql disable-shared \

178

2. MySQL
with-extra-charsets=complex enable-thread-safe-client \
with-mysqld-ldflags=-non_shared with-client-ldflags=-non_shared

egcs, configure:
CFLAGS="-O3 -fomit-frame-pointer" CXX=gcc \
CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
-fno-exceptions - f n o - r t t i " \
./configure prefix=/usr/local/mysql disable-shared
MySQL LinuxAlpha:
, MySQL, gdb 4.18 .
gdb 5.1.
mysqld , .
, with-mysqld-ldf lags=-all-static .

2.6.1.8. Linux PowerPC


MySQL MkLinux glibc (
glibc 2.0.7).

2.6.1.9. Linux MIPS


MySQL Qube2 (Linux MIPS),
glibc. , glibc 2.0.7-29C2. egcs C++ (egcs-1.0.2-9, gcc 2.95.2 ).

2.6.1.10. Linux IA-64


MySQL Linux IA-64,
configure:
CC=gcc \
CFLAGS="-O3 -fno-omit-frame-pointer" \
CXX=gcc \
CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions - f n o - r t t i " \
./configure prefix=/usr/local/mysql \
"--with-comment=Official MySQL binary" \
with-extra-charsets=complex
Ha IA-64 . , ,
/usr/local/mysql, , libmysqlclient.so,
/etc/Id.so.conf, LD_LIBRARY_PATH. .
.3.1.

2.6.2. Max OS X
Max OS X t a r .
. t a r .gz, gnutar.

2.6.

179

2.6.2.1. Mac OS X 10.x (Darwin)


MySQL Mac OS X 10.x (Darwin).
Mac OS X Darwin 6.3 -

configure:
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc \
CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti" \
./configure prefix=/usr/local/mysql \
with-extra-charsets=complex enable-thread-safe-client \
enable-local-infile disable-shared
. 2.2..

2.6.2.2. Mac OS X Server 1.2 (Rhapsody)


Mac OS X Server MySQL
.
, Mac OS X. ( ,
MySQL Mac OS X,
.)
(Mac OS X Server 1.2, Rhapsody),
MySQL, pthread.
. 2.2.3.

2.6.3. Solaris
Solaris , MySQL! t a r , Solaris,
. Solaris

http://dev.mysql.com/downloads/os-solaris.html.
Sun Solaris 2.5
. 2.4 MySQL MIT-pthreads
(. 2.3.5).
configure, ,
- :

checking for restartable system c a l l s . . . configure: error can not


run t e s t programs while cross compiling
...
configure:

-

.
,

config.cache:
ac_cv_sys_restartable_syscalls=${ac_cv_sys_restartable_syscalls='nol}
Solaris SPARC,
2.95.2 3.2. h t t p : / / g c c . g n u . o r g / . ,
eges 1.1.1 2.8.1 SPARC !
2.95.2 configure :

180

2. MySQL

COgcc CFLAGS="-03" \
CXX=gcc CXXFLAGS="-03 - f e l i d e - c o n s t r u c t o r s -fno-exceptions - f n o - r t t i " \
./configure prefix=/usr/local/mysql with-low-memory \
enable-assembler
UltraSPARC,
4% , -mcpu=v8 -Wa,-xarch=v8plusa CFLAGS
CXXFLAGS.
Sun Forte 5.0 ( )
configure :
= CFLAGS="-Xa -fast -native -xstrconst -mt" \
CXX=CC CXXFLAGS="-noex -mt11 \
./configure prefix=/usr/local/mysql enable-assembler
64- Sun Forte :
= CFLAGS="-Xa -fast -native -xstrconst -mt -xarch=v9" \
CXX=CC CXXFLAGS="-noex -mt -xarch=v9" ASFLAGS=fl-xarch=v9lf \
./configure prefix=/usr/local/mysql enable-assembler
64- Solaris ,
-4 CFLAGS CXXFLAGS enable-assembler configure.
MySQL 4.0 . MySQL 3.23 .
MySQL
4% UltraSPARC Forte 5.0 32-
3.2 -mcpu.
64- mysqld, , 4%
, 32- , .
fdatasync sched_yield, , LIBS=-lrt configure.
, Workshop 5.3, , configure. :
#if ! defined (_STDC__) | | _STDC_ != 1

#if

!defined(__STDC_J


STDC -, Sun pthread.h. Sun ( ).
mysqld , , MySQL Sun -mt:

libc internal error: _rmutex_unlock: rmutex not held


-mt CFLAGS CXXFLAGS .
SFW- ( Solaris 8),
/opt/swf/lib LD_LIBRARY_PATH

configure.

2.6.

181

, sunfreeware.com,
. , GNU
b i n u t i l s , .
MySQL ,
, Solaris:
s h e l l > gcc -03 -g -02 -DDBUGJDFF - thr__alarm . . .
x
./thr_alarm.c: In function signal_hand':
./thr_alarm.c:556: too many arguments to function

sigwait'

, , - . ,
Solaris 2.5, , , , ,
!
Solaris ( l i b p t h r e a d s
l i b d l ) , MySQL s t a t i c .
, :
Id: f a t a l : library - l d l : not found
undefined reference to 'dlopen'
cannot find - l r t
,
:
ld.so.l: fatal: libmysqlclient.so.#:
open f a i l e d : No such f i l e or d i r e c t o r y
:


-.

l i b m y s q c l i e n t . s o / u s r / l i b .

, l i b m y s q c l i e n t . s o , LD_RUN_PATH, .

-Wl,r////libmysqlclient.so

configure - l z , z l i b , :

,
z l i b f t p . gnu. org .

configure with-named-z-libs=no MySQL.

MySQL (UDF), - l g c c UDF.


, MySQL ,
support-files/mysql. server / e t c / i n i t . d
/etc/.d/S99mysql.server.
,
mysqld, MySQL :
Error in accept: Protocol error

2. MySQL

182

,
back_log=50. ( MySQL 4.0 -0 back_log=50.)
Solaris
setuid (), raysqld,
user.

2.6.3.1. Solaris 2.7/2.8


Solaris 2.6 Solaris 2.7
2.8. Solars 2.6 Solaris 2.7 2.8.
MySQL 3.23.4
Solaris .
Solaris 2.7 2.8 . :
/usr/include/widec.h:42: warning: Ngetwc' redefined
/usr/include/wchar.h:326: warning: this is the location of the previous
definition
/usr/include/widee.h:42:
: *getwc'
/usr/include/wchar.h:326:
:

, , /usr/include/widec.h
.. /lib/gcclib/os/gcc-version/include 41
#if

!defined(lint) && !defined(

lint)

#if Idefined(lint) && !defined(

lint) && !defined(getwc)

, /usr/include/widec.h . , config. cache


configure .
make ,
configure curses.h (, - /usr/include/widec.h):
In file included from mysql.ee:50:
/usr/include/term.h:1060: syntax error before 4,'
/usr/include/term.h:1081: syntax error before ;'
:

. / c o n f i g u r e CFLAGS=-DHAVE_CURSES_H CXXFLAGS=-DHAVE_CURSES_H.

/usr/include/widec.h, ,
configure.
Idefine HAVEJTERM config.h, make
.
-lz
, , , libz.so /usr/local/lib. :

/usr/local/lib LD_LIBRARY_PATH.

l i b z . so /lib.

2.6.

183

Solaris 8, zlib
Solaris 8 -.
configure with-named-z-libs=no MySQL.

2.6.3.2. Solaris 8
Solaris 8 86 mysqld , s t r i p .
egcs Solaris x86 , configure:
CC=gcc CFLAGS="-O3 -fomit-frame-pointer -DHAVE_CURSES_H" \
CXX=gcc \
CXXFLAGS="-O3 -fomit-frame-pointer -felide-constructors \
-fno-exceptions -fno-rtti -DHAVE_CURSES_H" \
./configure prefix=/usr/local/mysql
, libstdc++ C++.
,
gdb.

2.6.4. BSD
MySQL
BSD Unix.
2.6.4.1. FreeBSD
MySQL FreeBSD 4.0 , .
, FreeBSD,
-RELEASE.
( ) MySQL mysql-server mysql-clients,
http://www.freebsd.org/.
:
MySQL , , FreeBSD.
.
, /usr/local/etc/rc. d.
pkg_inf -L.
MySQL
pkg_delete.
MIT-pthreads FreeBSD 2.x
FreeBSD 3 . ,
2.2.x, mysqld.

184

2. MySQL

, FreeBSD
. gethostbynameO,
MySQL IP-. mysqld 100% . , mysqld skip-name-resolve.
, MySQL FreeBSD
LinuxThreads, ,
FreeBSD. LinuxThreads
(Jeremy Zawodny) "FreeBSD or Linux for your
MySQL Server?" ("FreeBSD Linux MySQL?"),
h t t p : //Jeremy, zawodny.com/blog/archives/000697 .html.
LinuxThreads FreeBSD ,
waittimeout (, -
FreeBSD/LinuxThreads). ,
FreeBSD 5.0. , , .
MySQL GNU make (gmake). GNU make
, MySQL.
MySQL
FreeBSD ( 2.95.2 ):
= CFLAGS="-02 -fno-strength-reduce" \
= CXXFLAGS="-02 -fno-rtti -fno-exceptions \
-felide-constructors -fno-strength-reduce" \
./configure prefix=/usr/local/mysql enable-assembler
gmake
gmake install
cd /usr/local/mysql
bin/mysql_install_db user=mysql
bin/mysqld_safe &
, configure MIT-pthreads,
2.3.5.
make i n s t a l l ,
/usr/include/pthreads, , configure MIT-pthreads. config. cache, configure
with-mit-pthreads.
, .
mysqld.
, localhost /etc/hosts.
, :
127.0.0.1
localhost localhost..
, FreeBSD .
. .2.17. --open-files-limit mysqld_safe,
mysqld /etc/login.conf
capjnkdb /etc/login.conf. ,

2.6.

185

, ( chpass --mysqld). . 4.1.3.


, , ,
, MySQL 512 . MAXDSIZ LINT.
MySQL
TZ. . .

2.6.4.2. NetBSD
NetBSD GNU make. , make l i n t
C++.
2.6.4.3. OpenBSD 2.5
OpenBSD 2.5 MySQL , :
CFLAGS=-pthread CXXFLAGS=-pthread ./configure with-mit-threads=no

2.6.4.4. OpenBSD 2.8


, OpenBSD 2.8 , , MySQL. OpenBSD ,
25 2001
"-current". ,
.
"Error in accept:: Bad f i l e
descriptor" (" :: ") 9
, , , MySQL
.
mysql_safe root :
roysqld_safe user=mysql open-files-limit=2048 &
2.6.4.5. BSD/OS 2.x
MySQL
j , ulimit :
item_func.h: In method
v
Item_func_ge: :Item_func_ge (const Item_func__ge &) ' :
item_func.h:28: virtual memory exhausted
make[2]: *** [item_func.o] Error 1
ulimit -v 80000 make . bash ,
csh sh. BSDI bash ulimit.
, , with-low-memory
configure, sql_yacc.cc.
MySQL, , TZ. . .

186

2. MySQL

2.6.4.6. BSD/OS 3.x


BSD/OS 3.1. ,
BSDIpatch M300-038.
MySQL :
env CXX=shlicc++ CC=shlicc2 \
./configure \
prefix=/usr/local/mysql \
localstatedir=/var/mysql \
without-perl \
with-unix-socket-path=/var/mysql/mysql.sock
:
env COgcc CXX=gcc CXXFLAGS=-O3 \
./configure \
prefix=/usr/local/mysql \
with-unix-socket-path=/var/mysql/mysql.sock
, , , , .
, skip-thread-priority mysqld.
. BSDI 3.1 , , , BSDI .
"virtual
memory exhausted" (" "),
ulimit -v 80000 make .
bash , csh sh.
BSDI bash ulimit.

2.6.4.7. BSD/OS 4.x


BSDI 4.x , .
MySQL , , .
, 400-023.
BSDI 4.x ,
.
, mysqladmin. , configure disable-shared.
BSDI 4.0.1, , mysqld .
, / mysqld , .
, MySQL , 3.23.34, configure #define HAVE_REALPATH
config.h make.
, , BSDI ,
( ).

2.6.

187

2.6.5. Unix
2.6.5.1. HP-UX 10.20
MySQL HPUX. HP-UX,
. HP-UX 2.95.
( -),
HP-UX.
configure 2.95:
CFLAGS="-I/opt/dce/include -fpic" \
CXXFLAGS="-I/opt/dce/include -felide-constructors -fno-exceptions \
-fno-rtti" \
CXX=gcc \
./configure with-pthread \
with-named-thread-libs='-Idee' \
prefix=/usr/local/mysql disable-shared
configure 3.1:
CFLAGS="-DHPUX -I/opt/dce/include -03 -fPIC" CXX=gcc \
CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors \
-fno-exceptions -fno-rtti -03 -fPIC" \
./configure prefix=/usr/local/mysql \
with-extra-charsets=complex enable-thread-safe-client \
enable-local-infile with-pthread \
with-named-thread-libs=-ldce with-lib-ccflags=-fPIC
disable-shared

2.6.5.2. HP-UX 11.x


HP-UX 11.x MySQL 3.23.15
.
- HP-UX
,
MySQL HP-UX 11.x:
PHKL_22840 Streams cumulative
PHNE_22397 ARPA cumulative
EWOULDBLOCK recv() EBADF accept () .
2.95.1 HP-UX 11.x, , :
In f i l e included from /usr/include/unistd.h:11,
from ../include/global.h:125,
from mysql joriv.h:15,
from item.ee:19:
/usr/include/sys/unistd.h:184: declaration of function . . .
/usr/include/sys/pthread.h:440: previous declaration . . .
In file included from item.h:306,
from mysql_jpriv.h: 158,
from item.ee:19:

2. MySQL

188

, HP-UX pthreads_atfork().
/usr/include/sys/unistd.h:184
/usr/include/sys/pthread.h:440.
/ u s r / i n c l u d e / s y s / u n i s t d . h
mysql/include unistd.h
pthreads. h. :
extern

i n t pthread_atfork(void

(*prepare) ( ) , void ( * p a r e n t ) ( ) ,

:
extern int pthread_atfork(void (^prepare)(void), void
void (*child)(void));

void

(*child)());

(*parent)(void),

configure :
CFLAGS="-fomit-frame-pointer -03 -fpic" CXX=gcc \
CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -03" \
./configure prefix=/usr/local/mysql
disable-shared
MySQL 4.0.5 HP-UX,
:
= = CFLAGS=+DD64 CXXFLAGS=+DD64 ./configure \
with-extra-character-set=complex
:
: warning 901: unknown o p t i o n :
documentation

- 3 ' : use +help for o n l i n e

configure , , K&R HP-UX C++:


checking for cc option to accept ANSI . . .
configure: e r r o r : MySQL requires an ANSI compiler (and a C++ compiler).
Try gcc. See the I n s t a l l a t i o n chapter in the Reference Manual.
, +DD64, .
MySQL HP-UX 10.20 HPUX 11. , HP-UX 11. -
(patch level) HP-UX.
2.6.5.3. IBM-AIX
1 Autoconf, configure .
IBM:
export CC="xlc_r -ma -03 - q s t r i c t -qoptimize=3 -qmaxmem=8192 "
export CXX="xlC_r -ma -03 - q s t r i c t -qoptimize=3 -qmaxmem=8192"
export CFLAGS="-I /usr/local/include"
export LDFLAGS="-L /usr/local/lib"
export CPPFLAGS=$CFLAGS
export CXXFLAGS=$CFLAGS

2.6.

189

./configure prefix=/usr/local \
localstatedir=/var/mysql \
sysconfdir=/etc/mysql \
sbindir='/usr/local/bin' \
libexecdir='/usr/local/bin 1 \
enable-thread-safe-client \
enable-large-files
MySQL,

http://www-frec.bull.com/.
configure -03 -02, - q s t r i c t . IBM.
egcs MySQL,
-fno-exceptions, gcc/egcs . ( egcs 1.1.)
IBM, - .
configure egcs 2.95 AIX:
=" -pipe -mcpu=power -Wa,-many" \
=" -pipe -mcpu=power -Wa,-many" \
CXXFLAGS="-felide-constructors -fno-exceptions - f n o - r t t i " \
. / c o n f i g u r e p r e f i x = / u s r / l o c a l / m y s q l with-low-memory
-Wa -many . IBM
, , . , -fno-exceptions 2.95,
MySQL , , gcc/egcs.
, -=, . ,
power2, power powerpc. ,
604 604. , , power
, power2.
, , uname -m.
, 000514676700, xxyyyyyymmss,
ss - 00, - mm -
. :

http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/uname.htm
,
.
(MySQL
), , , . MySQL , :

CFLAGS=-DDONT_USE_THR_ALARM CXX=gcc \
CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti \
-DDONT_USE_THR_ALARM" \
./configure prefix=/usr/local/mysql with-debug \
with-low-memory

190

2. MySQL

MySQL, , , mysqladmin k i l l mysqladmin shutdown. .


AIX libbind.a
getservbyname (). AIX
IBM.
AIX 4.2.1 .
config.h include/my_config.h,
:
#define HAVE_SNPRINTF I
:
#undef HAVE_SNPRINTF
mysqld. initgroups ():
#ifdef _AIX41
extern "C" int initgroups(const char *,int);
tendif
mysqld , ulimit -d unlimited. mysqld_safe,
:
export LDR_CNTRL='MAXDATA=0x80000000'

http://publibl6.boulder.ibm.com/pseries/en_US/aixprggd/genprogc/
lrg_prg_support.htm.

2.6.5.4. SunOS 4
SunOS 4 MySQL MITpthreads. , GNU make.
SunOS 4
libtool.
configure:
./configure disable-shared

with-mysqld-ldflags=-all-static

readline . .
mysqld "implicit
declaration of function" (" "). .

2.6.5.5. Alpha-DEC-Unix (Tru64)


eges 1.1.2 Digital Unix,
2.95.2, eges DEC .
Digital Unix -pthread , -lmach
-lexc ( -lpthread). configure :

2.6.

191

=" -pthread" CXX="cxx -pthread -0" \


./configure with-named-thread-libs="-lpthread -lmach -lexc - l c "
mysqld, , ,
:

mysqld.cc: In function void handle_connections()':


mysqld.ee:626: passing long unsigned int *' as argument 3 of
accept(int,sockadddr *, int * ) '
. ,
configure , .
, . (
SIGHUP.) ,
:

nohup mysqld [] &


nohup SIGHUP, .
mysqld_safe, mysqld, nohup. . 4.1.3.
mysys/get_opt.c,
#def ine _NO_PROTO .
Compaq CC configure:

=" -pthread 11
CFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed all -arch host"
CXX="cxx -pthread"
CXXFLAGS="-O4 -ansi_alias -ansi_args -fast -inline speed a l l \
-arch host -noexceptions - n o r t t i "
export CC CFLAGS CXX CXXFLAGS
./configure \
prefix=/usr/local/mysql \
with-low-memory \
enable-large-files \
enable-shared=yes \
with-named-thread-libs="-lpthread -lmach -lexc - l c "
gnumake
mysql
, , , :
cd mysql

/bin/sh ../libtool mode=link exx -pthread -03 -DDBUG_OFF \


-04 -ansi_alias -ansi_args -fast -inline speed \
-speculate all \ -arch host -DUNDEF_HAVE_GETHOSTBYNAME_R \
-o mysql mysql. readline.o sql_string.o completion_hash.o \
../readline/libreadline.a -leurses \
../libmysql/.libs/libmysqlclient.so -lm
cd ..
gnumake
gnumake install
scripts/mysql_install__db

2. MySQL

192

2.6.5.6. Alpha-DEC-OSF/1
DEC
, configure :
= CFLAGS=-0 = CXXFLAGS=-O3 \
./configure prefix=/usr/local/mysql
casm.h, - c_asm.h:
touch include/c_asm.h
CC=gcc CFLAGS=-I./include \
CXX=gcc CXXFLAGS=-O3

./configure prefix=/usr/local/mysql
, Id ,
DEC (Compaq) http://ftp.support.compaq.com/
public/unix/.
OSF/1 V4.0D , " DEC
V5.6-071 on Digital Unix V4.0 (Rev. 878)", ( asm), /bin/Id (
exit undefined mysqld). MySQL configure, /bin/Id OSF 4.0C:
CC=gcc CXX=gcc CXXFLAGS=-03 ./configure --prefix=/usr/local/mysql
Digital "C++ V6.1-029" :
= -pthread
CFLAGS=-04 -ansi_alias -ansi_args -fast -inline speed \
-speculate a l l -arch host
CXX=cxx -pthread
CXXFLAGS=-04 -ansi_alias -ansi_args -fast -inline speed \
-speculate a l l -arch host -noexceptions - n o r t t i
export CC CFLAGS CXX CXXFLAGS
./configure prefix=/usr/mysql/mysql \
with-mysqld-ldflags=-all-static disable-shared \
with-named-thread-libs="-lmach -lexc - l c "
OSF/1 alloca(). ,
config.h , HAVE_ALLOCA.
allocaO /usr/include/
alloca.h. , , .
configure :
with-named-threadlibs="-lpthread -lmach -lexc - l c " .
configure , :
CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-03 . / c o n f i g u r e

...

(MySQL
), ,
. MySQL :

2.6.

193

CFLAGS=-DDONT_USE_THR_ALARM \
CXXFLAGS=-DDONT_USE_THR_ALARM \
./configure ...
MySQL, - ,
, mysqladmin k i l l mysqladmin shutdown. .
2.95.2, , :

sql_acl.cc:1456: Internal compiler error in 4scan_region',


at except.c:2566
Please submit a full bug report.
, sql ,
, -03 -00 ( -00 ,
-0 ). , , make .

2.6.5.7. SGI Irix


Irix 6.5.3 , mysqld , , CAP_SCHED_MGT (, root), mysqld :
cheap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld

configure .
Irix a l l o c a ( ) . mysqld
SELECT, config.h , HAVE_ALLOC HAVE_ALLOC_H. mysqladmin c r e a t e ,
config.h , HAVE_READDIR_R.
HAVE_TERM_H.
SGI , :

http://support.sgi.com/surfzone/patches/patchset/.2_indigo.rps.html
mysqld. - :
" / u s r / i n c l u d e / c u r s e s . h " , l i n e 82: e r r o r ( 1 0 8 4 ) :
i n v a l i d combination of type
,
MySQL:

extra/replace bool cursesjDool < /usr/include/curses.h > include/curses.h


make
, .
, . ,
. 2 10 .
Irix ;
, .

2. MySQL

194

, configure :
COgcc CXX=gcc CXXFLAGS=-O3 \
./configure --prefix=/usr/local/mysql --enable-thread-safe-client \
with-named-thread-libs=-lpthread
Irix 6.5 Irix C++ 1.3.2
:
= = CFLAGS='-O3 -n32 -TARG:platform=IP22 -I/usr/local/include \
-L/usr/local/lib 1 CXXFLAGS='-03 -n32 -TARG:platform=IP22 \
-I/usr/local/include -L/usr/local/lib 1 \
./configure prefix=/usr/local/mysql with-innodb with-berkeley-db \
with-libwrap=/usr/local \
with-named-curses-libs=/usr/local/lib/libncurses.a
2.6.5.8. SCO
MySQL "sco3.2v5.0.5", "sco3.2v5.0.6"
"sco3.2v5.0.7". , "sco 3.2v4.2".
OpenServer
2.95.2. MySQL,
:
CC=gcc CXX=gcc ./configure ... [)
1. OpenServer 5.0.x gcc 2.95.2pl ,
Skunware. http://www.sco.com/skunkware/
OpenServer, FTP ftp2.caldera.com pub/skunkware/osr5/devtools/gcc.
2. GCC 2.5.x
(Development system). SCO Unix. GCC Dev system.
3. FSU Pthreads .
http://moss.esc.ncsu.edu/~mueller/ftp/pub/PART/pthreads.tar.gz.
4. FSU Pthreads SCO UNIX 4.2 tcpip,
OpenServer 3.0, Open Desktop 3.0 (OS 3.0 ODT 3.0) SCO Development System, GCC 2.5.x. ODT
OS 3.0 GCC 2.5.x. . SCO Unix Development
System. .
5. FSU Pthreads , :
1. ./configure, threads/src,
SCO OpenServer. Makefile.SC05 Makefile.
2. make.
3. /usr/include,
root, threads/src make i n s t a l l .
6. , MySQL GNU make.

2.6.

195

7. mysqld_safe root, ,
110 , mysqld .
8. SCO 3.2V5.0.5 FSU Pthreads 3.5
. 2.95.2 .
configure :
./configure prefix=/usr/local/raysql

disable-shared

9. SCO 3.2V4.2 FSU Pthreads 3.5


. configure:
CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
./configure \
prefix=/usr/local/mysql \
with-named-thread-libs="-lgthreads -lsocket -lgen - I g t h r e a d s " \
with-named-curses-libs="-lcurses"
, .
SCO
http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz.
include MySQL.
SCO.

MySQL FSU Pthreads mysqld


-Igthreads -lsocket -Igthreads.

SCO FSU Pthreads. SCO


,
FSU Pthreads. FSU Pthreads OpenServer SCO .

FSU Pthreads ( , http://www.mysql.com/) GNU ma 11 .


, , gmalloc.o l i b g t h r e a d s . a
libgthreads.so.

FSU Pthreads pthread:


r e a d ( ) , w r i t e ( ) , getmsg(), connect(), a c c e p t ( ) , s e l e c t ( ) w a i t ( ) .

CSSA-2001-SCO.35.2 ( "erg711905dscrremap security patch (version 2.0.0)") FSU


mysqld . mysqld OpenServer 5.0.6, .

SCO OpenServer 5.0.x


ftp://ftp.sco.com/pub/openserver5.

SCO OpenServer 5.0.x ,


libsocket.so.2, ftp://ftp.sco.com/pub/security/OpenServer
ftp://ftp.sco.com/pub/security/sse.

OSR506. telnetd ftp://stage.caldera.com/pub/security/openserver/


ftp://stage.caldera.com/pub/security/openserver/CSSA-2001-SCO.10/;

2. MySQL

196

- l i b s o c k e t . so. 2 l i b r e s o l v . so. 1 -
OSR506. ,

MySQL.
2.6.5.9. SCO UnixWare 7.1.x
UnixWare 7.1.0 MySQL, 3.22.13,
.
MySQL UnixWare 7.1.x,
configure:
= = ./configure

prefix=/usr/local/mysql

,
2.95.2 .
= =++ ./configure

prefix=/usr/local/raysql

S C O U n i x W a r e 7.1.1 7.1.3
ftp://ftp.sco.com/pub/unixware7, OpenUNIX 8.0.0 - ftp://ftp.sco.com/pub/
openunix8.
SCO ftp://ftp.sco.com/pub/security/OpenUNIX OpenUnix
ftp://ftp.sco.com/pub/security/UnixWare UnixWare.

2.6.6. OS/2
MySQL .
CONFIG.SYS , :
SET EMXOPT=-c - - 0 2 4

, , :
File 'xxxx' not found (Errcode: 24)
MySQL OS/2 Warp 3 ,
FixPack 2.9 . OS/2 Warp 4 FixPack 4 . Pthreads. MySQL
, , HPFS, FAT32 .
INSTALL.CMD OS/2 CMD.EXE,
4OS2.EXE.
s c r i p t s / m y s q l - i n s t a l l - d b .
i n s t a l l . c m d REXX-, MySQL Workplace Shell MySQL.
, .
Pthreads.
gcc - Z d l l -Zmt - Z c r t d l l = p t h r d r t l - I . . / i n c l u d e - I . . / r e g e x - I . . \
-o example udf_example.cc - L . . / l i b - l m y s q l c l i e n t udf_example.def
mv e x a m p l e . d l l example.udf

2.7. Perl
-

197

, OS/2, UDF 8 ( ). /mysql2/udf.


- safe-mysqld.cmd BEGINLIBPATH. '
UDF- . ,
'-' .udf. , Unix example.so
:
mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME ' e x a m p l e . s o ' ;
OS/2 example.udf,
:
1

mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME ' e x a m p l e ;

2.6.7. BeOS
BeOS , MySQL BeOS 80%, .

2.7. Perl
Perl MySQL DBI/DBD. Perl 5.6.0
. Perl.
Perl DBI,
DBI: :mysql 1.2216 . 2.9003 .
MySQL 4.1,
DBI: :mysql 2.9003 .
MySQL 3.22.8, Perl MySQL. Unix
http://search.cpan.org, ActiveState ppm
Windows. , .
Perl MySQL , . . 6.1.4.

2.7.1. Perl Unix


Perl MySQL ,
MySQL ( ). . MySQL Linux RPM-, , RPM . RPM-, - RPM- .
, Perl, CPAN
(Copmrehensive Perl Archive Network) h t t p : //search. cpan. org.
Perl Unix CPAN. :
shell> perl -MCPAN -e shell
cpan> i n s t a l l DBI
cpan> i n s t a l l DBD::mysql

198

2. MySQL

DBD: :mysql . MySQL . , . force i n s t a l l DBD: rraysql , .


DBI Data::Dumper. , . ,
DBI.
t a r . , DBI
:
1. :
shell> gunzip < DBI-.tar.gz

| tar xvf -

DBI-.
2. :
shell> cd -
3. :
shell> perl Makefile.PL
shell> make
shell> make test
shell> make install
make t e s t , .
, DBD: :mysql,
MySQL , .
DBD::mysql ,
MySQL, , , DBI-
MySQL.
Perl , , :
http://servers.digitaldaze.com/extensions/perl/modules.htrallmodules.
"Installing New Modules that Require Locally
Installed Modules" (" , ").

2.7.2. ActiveState Perl Windows


DBD MySQL ActiveState Perl Windows, :
ActiveState Perl
ActivePerl/ .

http://www.activestate.com/Products/

(" DOS").
, , , :
set HTTP_proxy=my.proxy,com:3128
PPM:
:\> C:\perl\bin\ppm.pl

2.7. Perl

199

DBI, :
ppm> install DBI
, :
install \
ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-raysql-l.2212.x86.ppd
, , ActiveState Perl 5.6.
,
MyODBC MySQL ODBC:
use DBI;
$dbh= DBI->connect("DBI:ODBC:$dsn",$user,$password) ||
die " $DBI::errstr $dsn\n";

2.7.3. Perl DBI/DBD


Perl , .. /mysql/mysql. so, ,
libmysql client .so.
:
DBD: :mysql perl Makefile.PL
- s t a t i c -config perl Makefile.PL.
libmysqlclient. so ,
(, /usr/lib /lib).
-L, DBD: :mysql,
libmysqlclient .so.
Linux , libmysqlclient.so,
/etc/Id.so.conf.
, libmysqlclient.so, LDRUNPATH.
LD_LIBRARY_PATH.
, , -L, , . ,
libc, /lib, -L/usr/lib, -L/lib
.
DBD::mysql , ,
( , ):
/usr/bin/perl: can't resolve symbol ' moddi3'
/usr/bin/perl: can't resolve symbol ' divdi3'
-L/usr/lib/gcc-lib/... -lgcc
mysql.so ( make mysql.so, Perl-). -L , libgcc. a.
, Perl
MySQL , .
.

200

2. MySQL


DBD::mysql:

t/OObase
install_driver(mysql) failed:
Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.
, -lz .
, lib/DBD/mysql/Install .pm
$sysliblist .= " -lm";

$sysliblist .= " -lm -lz";


make realclean .
DBI SCO,
Makefile DBl-xxx . , 2.95.2 :
:

CCCDLFLAGS = -KPIC -Wl,-Bexport

CCCDLFLAGS = -fpic

CCDLFLAGS = -wl,-Bexport

CCDLFLAGS =

LD = Id

LD = gee -G -fpic

LDDLFLAGS = -G -L/usr/local/lib
LDFLAGS = -belf -L/usr/local/lib

LDDLFLAGS = -L/usr/local/lib
LDFLAGS = -L/usr/local/lib

LD = Id

LD = gec -G -fpic

OPTIMISE = -Od

OPTIMISE = -01

:
CCCFLAGS = -belf -dy -wO -U M_XENIX -DPERL_SC05 -I/usr/local/include
:
CCFLAGS = -U M_XENIX -DPERL_SC05

-I/usr/local/include

, DBI, ice .
Perl , ( SCO), Perl,
DBD::mysql. ,
Perl
DBI Perl.
DBD .
SCO :
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib

2.7. Perl

201

:
LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
/usr/progressive/lib:/usr/skunk/lib
LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
/usr/progressive/lib:/usr/skunk/lib
MANPATH=scohelp:/usr/man:/usr/locall/man:/usr/local/man:\
/usr/skunk/man:
Perl,
DBI, , DBI, :
shell>
shell>
shell>
shell>

perl Makefile.PL -static -config


make
make install
make perl

Perl. make perl make, .


SCO make -f Makefile.aperl inst_perl MAP_TARGET=perl.
, Perl,
Perl, DBD: :mysql, , DBD: :mysql:
shell>
shell>
shell>
shell>

perl Makefile.PL -static -config


make
make install
make perl

, , Perl. -, make perl make, .

MySQL

,
MySQL AB, , .
, , , .
, ,
.

3.1. MySQL
MySQL AB :
MySQL :
mysqld - MySQL.
mysqld_saf e, mysql. server mysqldjnulti - .
mysql_install_db .
4.
, :
mysql - , SQL .
mysql (MySQL Control Center - MySQL) SQL-
.
mysqladmin - .
mysql check .
mysqldump mysqlhotcopy - .
mysqlimport .
mysql show .
7.

3.2. MySQL-

203

, :
myisamchk .
myisampack , .
mysqlbinlog - .
perror .
myisamchk
7.

4,

MySQL
, . (,
Windows .) RPM-, :
RPM- , RPM- .
2, MySQL .
, - .

3.2. MySQL-
MySQL ( ), ,
, , , . ,
. "shell>"
. , , . : $
sh bash, % csh tcsh :\> command.com cmd.exe Windows.
shell>
shell>
shell>
shell>

mysql test
mysqladmin extended-status variables
mysqlshow help
mysqldump user=root personnel

, '-', .
, , , . 3.3.
, ( ' - ' ) , . , mysql ( ) ;
, mysql t e s t ,
t e s t .
, , , .
. host, user password, . (),
MySQL,
MySQL. MySQL -

204

3. MySQL

, ,
.
MySQL bin, . ,
"program not found" (" ")
MySQL , bin.
bin PATH. , , , .
PATH , , , .

3.3.
MySQL:
, . , .
,
. , , .
.
, , , . (
4.9.2 , : , TCP/IP-
Unix- .)
MySQL , .
, ,
. ,
, - .

MySQL :
, , ,
.

3.3.1.
:
.
('-' ' ' ) ,
, . . , -? help
, MySQL .

3.3.

205

. -v -V
, ( --verbose
version ).
, . , -h localhost --host=localhost
MySQL. , MySQL.

, ,
'='.
, , , (-hlocalhost -h localhost ).
MySQL.
password=3Ha<jeHne_napcui# --password.
( ), .
-_ -.
,
.
, ,
- . :
shell> mysql -ptest
shell> mysql -p test
mysql t e s t ,
. mysql
, a t e s t .

MySQL 4.0 . MySQL 4.O.2. ,


"enabled" ("") "disabled" (""),
, MySQL
. . .
3.3.4.
, . , mysql column-names,
, .
.
, , mysql , , .
column-names :
disable-column-names
skip-column-names
column-names=0

206

3. MySQL

-disable -skip, =0
- .
:
column-names
enable-column-names
column-names=l
, ,
MySQL 4.0, ,
loose. , ,
, ,
:

shell> mysql loose-no-such-option


mysql: WARNING: unknown option 'no-such-option'
mysql: : ' no-such-option'
loose ,
MySQL , ,
, 4.0.2. ,
. ,
, --loose ( loose ).
, , . , MySQL 4.0.2 ,
--loose.

3.3.2.
MySQL (
" ").
,
. , MySQL 3.22.
, , : myisamchk,
myisampack, mysql, mysql.server, mysqladmin, mysqlbinlog, mysqlcc, mysqlcheck, mysqld,
mysqld_safe, mysqldump, mysqlhotcopy, mysqlimport mysqlshow.
Windows MySQL :

KATAJIOr_WINDOWS\my. i n i
: \my. cnf

.
.

KATAJlor_WlNDOWS Windows.
C:\Windows C:\WinNT. , :
:\> echo %WINDIR%
Unix MySQL :

3.3.

207

/etc/ray.cnf

_/. c n f

defaults-extra-file

, defaults-extra-f=,
.
.

~ /. my. enf

_ MySQL.
/usr/local/mysql/data /usr/local/var - .
, , , , datadir mysqld.
datadir , ,
, .
MySQL , , . , , , ,
, , .
, MySQL, .
, help.
, , ,
, ,
.
, quick host=localhost, quick host=localhost. loose-_ 1 se-^.
,
:

;
'#' ' ; ' . MySQL 4.0.14
'#' .

[)

- , .
_ set-variable .
_
_ .

_ =
_= .
'=' ,
. MySQL 4.0.16, , . , '#' .

208

3. MySQL

set-variable = _=
_.
1=_= . '=',
. MySQL 4.0,
. 3.3.4.
. , , , ,

: *\b\ ' \ t ' , '\n\ '\', '\\' '\s\
Windows
7 \ '\\ *\\ , '\\\
' \' MySQL .
, ,
, .
[client] ( mysqld).
, .
, [client] , ,
. ( ,
,
.) [client], , . ,
, , .
MySQL 4.0.14, ,
mysqld,
[mysqld-4.0], [mysqld-4.1 ] . , new MySQL 4.0.x:
[mysqld-4.]
new
:
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M
[mysqldump]
quick
_= ,
key_buffer_size max_allowed_packet.

3.3.

209

, MySQL 4.0.2,
set-variable ( ).
:
[client]
# MySQL
password="my_password"
[mysql]
no-auto-rehash
set-variable = connect_timeout=2
[mysqlhotcopy]
interactive-timeout
connect_timeout
set-variable. MySQL 4.0.2,
connect_timeout=2.
,
my-xxxx.cnf support-files. , support-files MySQL (
C:\mysql Windows, /usr/local/mysql Unix).
, , . , C:\my.cnf (Windows)
. my. cnf (Unix).
$ !
. Windows .cnf .
MySQL, , :
no-defaults. He .
print-defaults. , .
defaults-file=HM#_nyTH. . _ . ^
--defaults-extra-file=HM#_nyTn.
, . _ -
.
,
, print-defaults, defaults-file defaults-extra-file.
m y p r i n t d e f a u l t s .
, [client] [mysql]:
shell> myj?rint_defaults client mysql
~port=3306
socket=/tmp/mysql.sock
no-auto-rehash

3. MySQL

210
.

IE
|
||
%'t

jf

. ( , COOT ) , .
, , . C++, , , , . MySQL, ,
.

MySQL ,
.
Perl Python.
.

3.3.3.

, , , . , Windows NetWare MySQL USER. :
SET USER=_
Unix . , TCP/IP MYSQL__TCP_PORT.
Bourne (sh, bash, zsh ) :
MYSQLJTCP_PORT=3306
c s h n t c s h :
setenv MYSQL_TCP_PORT 3306

, .
. ,
, . : AUTOEXEC.BAT ( Windows),
.bash_profile ( bash) .tcshrc ( tcsh).
.
, MySQL.

3.3.4.

MySQL ,
. MySQL 4.0.2, , ,
. , mysql max_allowed_packet,

3.3.

211

.
mysql 16 , :
shell> mysql --max_allowed_packet=16777216
shell> mysql max_allowed_packet=16M
, - .
, G ( , ), - , .
:
[mysql]
max_allowed_packet=16777216
:
[mysql]
max_allowed_packet=l6M
('_')
('-').
, MySQL 4.0.2, .
set-variable:
shell> mysql
shell> mysql

~set-variable=max__allowed_packet=16777216
set-variable=max_allowedjpacket=16M

('--') :
[mysql]
set-variable = max_allowed_packet=16777216
:
[mysql]
set-variable = max_allowed_packet=16M
MySQL, 4.0.2, --set-variable
.
set-variable - MySQL 4.0.2 ,
.
.
4.23.2.


fcrf , ^ MySQL, - , .

41. MySQL
MySQL - mysqld - , MySQL.
, MySQL ,
.
,
.
4.2.

4.1.1.
MySQL . help,
. ,
mysqld help.
,
(. 3.3).
MySQL- :
mysqld. SQL ( MySQL).
, mysqld ,
. . 4.2.
mysqld-max. ,
. . 4.1.2.

4.1. MySQL

213

mysqld_safe. . mysqld_safe
mysqld-max, , mysqld. .
4.1.3.
mysql. server. . ,
, , . mysqld_safe
MySQL-. . 4.1.4.
mysqldmulti. , , . . 4.1.5.
mysql_install_db. MySQL . - MySQL .
mysql_fix_privilege_tables. ,
MySQL.
, :
myisamchk. , , , My ISAM. 4.6.2.
make_binary_distribution. MySQL. MySQL
FTP /pub/mysql/upload
ftp.mysql.com.
mysqlbug. , MySQL.
. (
h t t p : //bugs .mysql.com/.)

4.1.2. MySQL- mysqld-max


MySQL- - MySQL- mysqld, .
:
Windows. MySQL
(mysqld.exe), MySQL-Max (mysqld-max.exe),
. Windows, http://dev.mysql.com/
downloads/mysql-4.0.html. . 2.2.1.
Linux. MySQL RPM RPM- MySQL-server
mysqld. , RPM- MySQL-Max,
mysqld-max. RPM- MySQL-Max , RPM-
. ,
Linux RPM, 2.2.2.

214

4.

MySQL-Max , mysqld, .
MySQL-Max Web- MySQL AB
http://dev.mysql.com/downloads/mysql-max-4..html.
MySQL AB MySQL-Max
:

with-server-suf f ix=-max. -max mysqld.

with-innodb.
innoDB. MySQL-Max innoDB,
MySQL 3.23. MySQL 4, InnoDB ,
InnoDB MySQL-Max .

with-bdb. Berkley
DB (BDB).

CFLAGS=-DUSE_SYMDIR.
Windows.
MySQL-Max , . -, , MySQL-Max.
MySQL-Max BDB (Berkeley DB) ,
, BDB. , MySQL-Max, .

BDB

AIX 4.3
HP-UX 11.0
Linux-Alpha
Linux-IA-64
Linux-Intel
Mac OS X
NetWare
SCO OSR5
Solaris-Intel
Solaris-SPARC
UnixWare
Windows/NT

, ,
:
mysql> SHOW ENGINES;

4.1. MySQL

215

, MySQL 4.1.2 SHOW ENGINES . , :


mysql> SHOW VARIABLES LIKE havejk 1 ;
I
+
I
I
I
I
I
I
I
I

Variable_name

| Value
|
+
+
have_bdb
| NO
I
have_crypt
| YES
|
have_innodb
| YES
|
have_isam
| NO
|
have_raid
| NO
|
have_symlink
| DISABLED |
have_openssl
| NO
|
have_query_cache | YES
|

YES

N0

DISABLED

, .

N0 , ,
.
DISABLED , , , , ,
. _.
, .
, DISABLED, InnoDB M y S Q L 3.23. M y S Q L 3.23
InnoDB , ,
innodb_data_f i l e _ p a t h . InnoDB . . 9.3. BDB , , BDB . . 8.4.3.
, DISABLED InnoDB, BDB ISAM ,
, s k i p - i n n o d b , s k i p - b d b s k i p i s a m .
3.23, M y S Q L My ISAM, My ISAM .

4.1.3. mysqldsafe
mysqld_safe mysqld
Unix NetWare. mysqld_safe
, -

4.

216

.
NetWare , .
: !
, MySQL 4.0, mysqld_saf e safe_mysqld.
/', MySQL
s a f e j n y s q l d mysqld_saf.

mysqld_safe
mysqld-max, ; mysqld. :
Linux mysqld_safe MySQL-Max
RPM. RPM mysqld-max,
mysqldsafe .
MySQL-Max, mysqld-max,
MySQL , Max, mysqld_safe
- mysqld-max.

mysqld-max; , mysqld_safe
mysqld.
, , mysqldsafe mysqld mysqld-version.
mysqld_safe mysqld (.
4.2.1).
, mysqldsafe , mysqld. ,
mysqldsafe, mysqld,
. [mysqld_safe] . .
3.3.2.
mysqld_safe [mysqld], [server] [mysqld_safe]
. [safejnysqld],
MySQL 4.0
[mysqld_safe].
mysqldsaf e :

basedi=. MySQL.

core-f ile-size=pa3Mep. , mysqld . ulimit -.

datadi r=. .

defaults-extra-file=. , , .

defaults-file=nyTb. ,
.

-1=. log-error, ,
MySQL 4.O.

4.1. MySQL

217

111=. , mysqld. .

1-=. . . 4.8.1.
mysqld=nNM_nporpaMMbi. ( ledir),
.
--mysqld-versio=cyc. mysqld,
. ,
mysqld. , --mysqld-version=max
mysqld_safe mysqld-max l e d i r .
mysqld-version , mysqld_safe mysqld
ledir.

nice=. nice .

no-defaults. He .
open-files-limit=KcwjwecTBo. , mysqld. ulimit -n. ,
mysqld_safe (root) .
pid-f =. .
--port=HOMep_nopTa. , TCP/IP-.
socket=nyTb. Unix-, .
--timezone=3OHa. TZ. .

user={_ \ _}.
mysqld _ _. ("" , MySQL,
.)

mysqld_saf e , , MySQL, , ,
. (. 2.1.5.) mysqld_safe
:
, mysqldsafe.
mysqld_safe bin data. mysqldsafe libexec var. , mysqld_saf e MySQL (,

/usr /local /mysql).

218

4.

, mysqldsafe ,
/usr/local/libexec /usr/local/var.
,
. , MySQL ,
.
mysqld_safe
, MySQL
, mysqld_safe
MySQL:
shell> cd __1
shell> bin/mysqld_safe &
mysqld_safe MySQL,
ledir -datadir, , .
mysqld_safe . mysqldsafe
[mysqld_safe] my.cnf. mysqld_saf e . ,
MySQL, mysqld_safe . , , .
NetWare mysqld_safe - NLM,
Unix; :
1. .
2. My ISAM ISAM.
3. MySQL.
4. mysqld, , .
5. mysqld _.,
.
6. mysqld_safe ^. err,
.

4.1.4. mysql.server
MySQL Unix mysql.server.
, Linux Solaris, System V . , Mac OS Startup Item
MySQL.
mysql.server support-files MySQL
MySQL.
RPM- Linux (MySQL-server-.),
mysql. server /etc/init .d mysql. -

4.1. MySQL

219

. RPM-
Linux 2.2.2.
RPM- ,
, mysqld.
MySQL , mysql. server ,
mysql. server .
2.4.3.
mysql.server [mysql.server] [mysqld]
. [mysql_server],
MySQL 4.0
[mysql.server].

4.1.5. mysqld_multi
MySQL-
mysqldjnulti
mysqld, Unix- TCP/IP-.

.
[mysqld#] my.cnf ( , conf ig-f ile). # - . , GNR.

mysqldmulti, , , , . , , -
, [mysqld] mysqld. (. 2.4.3.) ,
, Unix -.
,
, 4.9.
mysqldjnulti :
shell> mysqldjnulti [] {start|stop|report}
[GNR[fGNR]...]
s t a r t , stop report , . ,
GNR, .
GNR .
.
, GNR [mysqldl7] 17.
,
. GNR 10-13 OT[mysqldlO] [mysqldl3]. , . GNR ( ); .
,
[mysqldl7]:
shell> mysqld__multi start 17

220

4.

,
[mysql8] [mysqldlO] [mysqldl3]:

shell> mysqldjnulti start 8,10-13


, :
shell> mysqldjnulti example
, mysqldjnulti.

--config-file=HM#. .
, mysqldjnulti [mysqld#].
, my.cnf.
, mysqldjnulti ,
[mysqldjnulti] my. cnf.

example. .

help. .

1=. . ,
.
mysqladmin=HM#_nporpaMMb/. mysqladmin, .

{=_. mysqld, . ,
mysqld_saf . , PATH , mysqld,
mysqld_saf .

--no-log. stdout, . .
password=napcwb. MySQL, mysqladmin. ,
, MySQL-, .

tcp-ip. MySQL TCP/IP-, Unix. ( - , TCP/IP.)


Unix. stop report.

=_. MySQL, mysqladmin.

version. .

mysqldjnulti.
, MySQL,
mysqld ( mysqladmin)
. SHUTDOWN.

, ,

4.1. MySQL

221

. , multi_adrain,
:
shell> mysql -u root -S /tmp/mysql.sock --_
mysql> GRANT SHUTDOWN ON *.*
-> TO 'multi^admin'e'localhost1 IDENTIFIED BY 'multipass1;
. 4.4.2. mysqld.
. , - multiadmin , mysqldjnulti.
pid-file mysqld_safe mysqld (, mysqld=mysqld_safe). mysqld
.
mysqld_safe mysqld , mysqld_safe ""
mysqld , , k i l l -9, , .
, mysqld_safe
. , mysqldjnulti . mysqld_safe. ,
:
MY_PWD=4pwd4
# Check if we are starting this relative (for the binary release)
# , ( )
if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
-x ./bin/mysqld
. 4.1.. , ,
, , .
Unix TCP/IP-
mysqld.
user mysqld,
mysqldjnulti (root) Unix. ;
, mysqld
Unix.

1 !
! , Unix, ^ mysqld. , r o o t Unix.
m y s q l d j n u l t i ,
, mysqld, ,
mysqld. He mysqld
. ,
- . . . 4.9.

222

4.

, mysqld_multi.
[mysqld#] , "" . . ,
.
#
# (~/.my.cnf) /etc/my.cnf
# 2.1 (Jani Tolonen)
[mysqld_multi]
mysqld
= /usr/local/bin/mysqld_safe
mysqladmin = /usr/local/bin/mysqladmin
user
= multi_admin
password = multipass
[mysqld2]
socket
port
pid-file
datadir
language
user
[mysqld3]
socket
port
pid-file
datadir
language
user

=
=
=
=
=

/tmp/mysql.sock2
3307
/usr/local/mysql/var2/hostname.pid2
/usr/local/mysql/var2
/usr/local/share/mysql/english

= John
=
=
=
=
=
=

/tmp/mysql.sock3
3308
/usr/local/mysql/var3/hostname.pid3
/usr/local/mysql/var3
/usr/local/share/mysql/swedish
monty

[mysqld4]
socket
port
pid-file
datadir
language
user

= /tmp/mysql.sock4
=
=
=
=
=

3309
/usr/local/mysql/var4/hostname.pid4
/usr/local/mysql/var4
/usr/local/share/mysql/estonia
tonu

[mysqld6]
socket
= /tmp/mysql.sock6
port
= 3311
pid-file
datadir
language
user

=
=
=
=

/usr/local/mysql/var6/hostname.pid6
/usr/local/mysql/var6
/usr/local/share/mysql/japanese
jani

. ..2.

4.2. MySQL

223

4.2. MySQL
, MySQL:

.
SQL .
.
.

4.2.1. mysqld
mysqld ,
, 3.3.
. , . - (. 3.3.2).
mysqld [mysqld] [server], a mysqld_safe -
[mysqld], [server], [mysqld_safe] [safejnysqld]. mysql.server
[mysqld] [mysql.server. MySQL [server], [embedded] [xxxxx_SERVER], - , .
mysqld . , mysqld help. , MySQL 4.1.1, --help
. MySQL 4.1.1, ; :
mysqld verbose help
. .
, - . 4.3.3.
, SSL - . 4.5.7.5.
- . 4.8.4.
, - . 5.8.
, My ISAM, BDB InnoDB - .
8.1.1, 8.4.3 9.5.
, .
help, -?. . , MySQL 4.1.1, help , 4.1.1. - .
, verbose help.

ansi. SQL MySQL.


. 1.8.3. SQL
--ansi sql-mode.

224

4.

basedi =, - . MySQL.
.

big-tables. ,
. "table full" (" "), , (in-memory) . MySQL 3.23.2
, ,
, .

bind-address=IP. IP- .

--console. s t d e r r / s t d o u t ,
log-error. Windows mysqld .

character-sets-dir=nyTb. , . .
4.7.1.

~chroot=nyTb. mysqld ,
chroot ().
, MySQL 4.O. ( MySQL 3.23
chroot ().) , LOAD DATA INFILE
SELECT...INTO OUTFILE.

c o r e - f i l e . mysqld.
raysqld_safe c o r e - f i l e - s i z e . .
4.1.3. , , Solaris,
, user-option.

datadir=nyrb, -h . .

debug [=__], -# [_]. MySQL


--with-debug,
mysqld . _
: ' d: t : , _'.

default-character-set=Ha6op_CHMBCxtfOB. _ . . 4.7.1.

default-collation=coocaee. . , MySQL 4.1.1. .


4.7.1.

default-storage-engine=Tnn. defaulttable-type. , MySQL 4.I.2.

--def ault-table-type=THn. . . 8.

delay-key-write [= OFF | ON | ALL]. , DELAYED KEYS.


My ISAM. OFF . ON ,
DELAYED KEYS. ALL -

4.2. MySQL

225

My ISAM. ,
MySQL 4.0.3. . 6.5.2, 8.1.1.
\ !
V"
%, ALL, My ISAM % (, MySQL myisamchik), f , , .

delay-key-write-for-all-tables.
delay-key-write=ALL, , MySQL 4.O.3. MySQL
4.0.3, delay-key-write.
--des-key-file=HM#_$awia. ,
DES_ENCRYPT () DES_DESCRYPT ().

enable-named-pipe. .
Windows NT/200/XP
mysqld-nt mysqld-max-nt,
.

external-locking. . , , lockd (, Linux), mysqld. enable-locking.

|! !
\"
ft
\,
1
2

My ISAM
MySQL, , :
, , , .
delay-key-write=ALL
DELAY_KEY_WRITE=1.

I'

- e x t e r n a l - l o c k i n g

delay-key-write=OFF query-cache-size=O.

f ( ,
J;: .)

exit-info[=], - []. , mysqld. He ,


, , !

flush. SQL- . MySQL SQL .


. .4.2.

init-file=. SQL- .
.

1=_, -L _.
. _
, . .
4.7.2.

226

4.

log[=], -1 []. . . 4.8.2. , MySQL


_.1.

log-bin= [ ]. . ,
, . . . 4.8.4. , MySQL
_-.

log-bin-index [=]. . .
4.8.4. , MySQL
_-. index.

log-error [=]. .
. 4.8.1. , MySQL _. err.

log-isam[=]. ISAM/MylSAM ( ISAM/My ISAM).

log-long-format. ( , , , , ). , .
log-slow-queries log-long-format, , , . , --log-long-format ; MySQL 4.1
log-short-format ( 4.1 ). , , MySQL
4.1, log-queries-not-using-indexes, ,
, .

log-queries-not-using-indexes.
log-slow-queries, , ,
. , MySQL 4.1. . 4.8.5.

log-short-format.
( , ,
, , ). ,
. MySQL 4.1.

log-slow-queries [=]. ,
, , , long_query_time. .
4.8.5. ,
MySQL 4.1 . log-long-format log-short-format.

--log-update[=]. ., # - , . . 4.8.3. , MySQL 5.0.0 ,


(log-bin). . 4.8.4.

4.2. MySQL

227

5.0.0, log-update .

log-warnings, -W. , Aborted connect i o n . . . (" ") .


, , ( , , ,
). MySQL 4.1.2 ;
, --skip-log-warnings. . .2.10. MySQL 4.0 warnings.

l o w - p r i o r i t y - u p d a t e s .
(INSERT/DELETE/UPDATE) ,
SELECT. {INSERT | REPLACE | DELETE | UPDATE}
LOW_PRIORITY . . . , ,
SET LOW_PRIORITY_UPDATES=1, . .
6.3.2.

memlock. mysqld . , Solaris, mlockall ().


, mysqld . ,
(root) , .

myisam-recover
[-[, ...]]].

My ISAM. DEFAULT,
BACKUP, FORCE QUICK. ,
. ,
"". myisam-recover , mysqld , , ( ,
--skip-external-locking). mysqld . , mysqld .
:

DEFAULT

To , ,
myisam-recover.

BACKUP

_ . MYD ,
__-- ..

FORCE

,
. MYD.

QUICK

M y S Q L
.
, -

228

4.
BACKUP FORCE.
, ,
, , .
, MySQL 3.23.25.

new. 4.0.12, --new , 4.1,


4.0 4.1:
TIMESTAMP ' YYYY-MM-DD HH :MM: SS'.
MySQL 4.1
4.1.

pid-file=nyTb. ,
mysqld_safe.

t=HOMep__nopTa, -P _. , -.

--old-protocol, -. 3.20
. . 2.5.6.

one-thread. ( Linux). , .

--open-files-limit=KOffH4ecTBO. , mysqld.
0, mysqld , setrlimit (). 0, mysqld max_connections*5
max_connections + table_cache*2 ( ). , mysqld "Too many open files"
(" ").

safe-mode. .

safe-show-database. SHOW DATABASES


,
. MySQL 4.0.2 - ( ),
SHOW DATABASES, ,
. . 4.4.3.

safe-user-create. ,
GRANT,
INSERT mysql. user .

secure-auth. ,
( 4.1) . , MySQL
4.1.1.

skip-bdb. BDB.
.
, BDB.

4.2. MySQL

229

skip-concurrent-insert.
My ISAM. ( ,
, .)

skip-delay-key-write. DELAY_KEY_WRITE. MySQL 4.0.3, delay-key-write=


OFF. . 6.5.2.

skip-external-locking. He . isamchik myisamchk . .


1.2.3. MySQL 3.23 CHECK TABLE REPAIR TABLE
My ISAM.
skip-locking.

skip-grant-tables. .
! ( ,
, mysldadmin flush-privileges
mysqladmin reload, FLUSH PRIVILEGES.)

skip-host-cache. He IP-. DNS-


, . . 6.5.5.

skip-innodb. innoDB.
. , InnoDB.

skip-is am. ISAM. MySQL 4.1 ISAM , , ISAM. MySQL 4.1.1.

skip-name-resolve. . IP-.
Host
IP- localhost. . 6.5.5.

--skip-networking. He TCP/IP- .
mysqld (Windows)
Unix (Unix). ,
. . 6.5.5.

skip-new. He , , .

--skip-symlink. skip-symbolic-links, , MySQL 4.0.13.

--symbolic-links, --skip-symbolic-links.
. - Windows
Unix:
Windows
directory.sym, . . 6.6.1.3.

230

4.

Unix My ISAM
INDEX DIRECTORY DATA DIRECTORY CREATE TABLE. , , . MySQL 4.0.13.

skip-safemalloc. MySQL with-debug=full,


MySQL-
.
, , , , skip-safemalloc.

skip-show-database. SHOW DATABASES


, SHOW DATABASES,
. SHOW DATABASES ,
, SHOW DATABASES - .

--skip-stack-trace. .
mysqld . .

skip-thread-priority.
.

socket=nyTb. Unix Unix,


.
/tmp/mysql.sock. Windows , . MySQL.

1 - ( 1 = [, [, ...]].
S Q L -
MySQL. . 4.2.2. MySQL 3.23.41.

temp-pool. ,
. Linux,

. Linux ,
, .

transaction-isolation=ypoBeHb. : READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ


SERIALIZABLE.

--tmpdir=nyib, -t . , . , /tmp , , . MySQL 4.1,


, . ( V ) Unix (';') Windows, NetWare
OS/2. MySQL ,
tmpdir ,

4.2. MySQL

231

, , , . , ,
LOAD DATA INFILE.
, .
user= {_ | _}, - {_
I _). mysqld
_ _. ("" , MySQL,
.)
mysqld
(root) .
, ,
root. . 4.3.1.
MySQL 3.23.56 4.0.12,
, user=root my.cnf ( root), mysqld user ,
. /etc/my, cnf _ / my.cnf
,
user /etc/my.cnf , root.
/etc/my, cnf --user, ,
(root), , user.

version, -V. .

_= . , key_buffer_size=32M key_buf f er_size 32 .


, MySQL , ,
,
.
set-variable=
_= -0 _=. MySQL
4.0 .
4.2.3. 6.5.2, , .

SET.
, SET,
maximum-_, . ,
query_cache_size 32 ,

232

4.

maximum-query_cache_size=32. , MySQL 4.O.2.

42.2. SQL
MySQL SQL ( MySQL 4.1)
.
.
, SQL- MySQL ,
.
MySQL .
SQL , mysqld sql-mode=
"". MySQL 4.1, ,
1
sqljnode SET [SESSION|GLOBAL] sql_mode=' .
GLOBAL
. SESSION , modes , (',').
SELECT @@sqljnode. - (
).
(sql-mode=""), .
:

ANSI_QUOTES. ' " ' (.. ' s ' ) , . - ' '


ANSI. ANSI_QUOTES, , . ( MySQL 4.O.O.)

IGNORE_SPACE. '('
,
. , , ,
. , USERO,
user mysql User * :
SELECT "User" FROM mysql."user";
( MySQL 4.0.0.)

NO_AUTO_VALUE_ON_ZERO. NO_AUTO_VALUE_ON_ZERO
AUTO_INCREMENT.
NULL 0. NO_AUTO_VALUE_ON_ZERO 0, NULL . , 0 AUTO_INCREMENT . ( .) , mysqldump
MySQL , 0, , . NOAUTOVALUEONZERO
. MySQL 4.1.1,

4.2. MySQL

233

mysqldump
NO_AUTO_VALUE_ON_ZERO. ( MySQL 4.O.O.)

NO_DIR_IN_CREATE. INDEX
DIRECTORY DATA DIRECTORY. . ( MySQL 4.0.15.)

NO_FIELD_OPTIONS. He MySQL SHOW CREATE TABLE. mysqlddump . ( MySQL 4.1.1.)

NO_KEY_OPTIONS. He MySQL
SHOW CREATE TABLE. mysqlddump .
( MySQL 4.1.1.)

NO_TABLE_OPTIONS. He MySQL-
SHOW CREATE TABLE. mysqlddump .
( MySQL 4.1.1.)

NO_UNSIGNED_SUBTRACTION.
UNSIGNED, . ,
, UNSIGNED BIGINT 100%
. ( MySQL 4.O.2.)

ONLYFULLGROUPBY. , GROUP BY , . ( MySQL 4.O.O.)

PIPES_AS_CONCAT. | | (
CONTACT ()), OR. ( MySQL 4.O.O.)

REAL_AS_FLOAT. REAL FLOAT, DOUBLE.


( MySQL 4.O.O.)

. ,
MySQL 4.1.1.

ANSI. REAL_AS_FLOAT, PIPES_AS__CONCAT, ANSI_QUOTES, IGNORE_SPACE,


ONLY_FULL_GROUP_BY. . 1.8.3.

DB2. PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,


NO_TABLE_OPTIONS, NO_FIELD_OPTIONS.

MAXDB. PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,


NO_TABLE_OPTIONS, NO_FIELD_OPTIONS.

MSSQL. PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,


NO_TABLE_OPTIONS, NO_FIELD_OPTIONS.

MYSQL323. NO_FIELD_OPTIONS.

MYSQL40. NO_FIELD_OPTIONS.

ORACLE. PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, NO_KEY_OPTIONS,


NO_TABLE_OPTIONS, NO_FIELD_OPTIONS.

POSTGRESQL. PIPES_AS_CONCAT,
ANSI_QUOTES,
NO KEY OPTIONS, NO TABLE OPTIONS, NO_FIELD OPTIONS.

IGNORE_SPACE,

234

4.

4.2.3.
, . . , . SET.
MySQL 4.0.3, mysqld . .
, .
. , .
, , ,
SET GLOBAL _. , SUPER.
. , .
, ,
SET SESSION _. , , - .
, .
, , , . ( ,
SET GLOBAL) .

, G , , , . , ,
16 :
mysqld key_buffer_size=16M
, MySQL 4.0, :
mysqld

set-variable=key_buffer_size=16M

: 16 16 .

SET. , :
mysql> SET sort_buffer_size = 10 * 1024 * 1024;
, - GLOBAL SESSION:
mysql> SET GLOBAL sortjbuffer_size = 10 * 1024 * 1024;
mysql> SET SESSION sort_buffer_size = 10 * 1024 * 1024;

4.2. MySQL

235

, , .
, ,
4.2.3.1.2.
, SET,
maximum-_, . ,
query_cache_size 32 ,
maximum-query_cache_size=32.
MySQL 4.O.2.

SHOW VARIABLES. 4.2.3.1.
m y s q l > SHOW VARIABLES;
Variable name
back log
basedir
bdb cache size
bdb home
bdb_log_buffer_size
bdb logdir
bdb max lock
bdb shared data
bdb tmpdir
bdb version
I binlog cache size
I bulk insert buffer size
I character_set
I character sets
| concurrent insert
I connect timeout
I convert character_set
I datadir
I default week format
I delay key write
I delayed insert limit
I delayed insert timeout
I delayed queue size
I flush
| flush_time
I ft boolean syntax
| ft max word len
| ft min word len
| ft query expansion limit
I ft stopword file
I have bdb
1 have innodb

Value

50
/usr/local/mysql
8388572
/usr/local/mysql
32768

|
|
|
|
|

10000
OFF
/tmp/
Sleepycat Software: ...
32768
8388608
latinl
latinl big5 czech euc kr
ON
~

|
|
|
|
|
|
|

/usr/local/mysql/data/

0
ON
100
300
I
I
1
|

1000
OFF
0
+ -><()~*:""&|

I 84
14
I20
I (built-in)
YES
I YES

4.

236
have_isam
have openssl
have query cache
have_raid
have symlink
init file
innodb additional mem pool size
1 innodb_bufferj?ool_size
I innodb data file path
I innodb data home_dir
I innodb fast shutdown
I innodb file io threads
I innodb flush log at trx commit
I innodb flush method
I innodb force recovery
I innodb lock wait timeout
I innodb_log_arch_dir
I innodb log archive
I innodb log buffer size
I innodb log file size
I innodb log files in group
I innodb_log_group_home dir
I innodb mirrored log groups
I innodb thread concurrency
I interactive timeout
1 join buffer size
I key buffer size
I key cache age threshold
I key_cache_block_size
I key cache division limit
I language
I large_files support
I local infile
I locked in memory
1 log
I log bin
I log_slave updates
log_slow_queries
log_update
I log warnings
I long query time
I low_priority__updates
I lower case table names
I max allowed packet
I max binlog cache size
I max binlog size
I max connect errors
I max connections
max delayed threads

I YES
YES
YES
NO
DISABLED
1048576
8388608
ibdatal:10M:autoextend
ON
4
1
0
50
OFF
1048576
5242880
2
./
1
8
28800
131072
16773120
I 300
1024
I 100
/usr/local/mysql/share/
ON
I ON
I OFF
I OFF
| OFF
I OFF
I OFF
| OFF
I OFF

1 io

I OFF

I 1047552
I 4294967295
I 1073741824
1 io
I 100
I 20

4.2. MySQL
max error count
max heap table size
max join size
max relay log size
max sort length
max tmp tables
max user connections
max write lock count
myisam max extra sort file size
myisam max sort file size
myisam recover options
myisam repair threads
myisam sort buffer size
net buffer length
net read timeout
net retry count
net write timeout
open files limit
pid file
port
protocol version
query_cache_limit
query cache size
query cache_type
read buffer size
read rnd buffer size
rpl recovery rank
server id
skip external_locking
skip networking
skip show database
slave net timeout
slow launch time
socket
sort buffer size
sqljnode
table cache
table_type
thread cache_size
thread stack
timezone
tmp table size
tmpdir
I tx isolation
I version
I wait timeout

237
64
16777216
4294967295

0
1024

32
0
4294967295
268435456
2147483647
force

1
8388608
16384

30
10
60
1024
/usr/local/mysql/name.pid
3306

10
1048576

0
ON
131072
262144

0
0
ON
OFF
OFF
3600

2
/tmp/mysql.sock
2097116

64
MYISAM

3
| 131072
EEST
I 33554432
/tmp/:/mnt/hd2/tmp/
I READ-COMMITTED
I 4.0.4-beta
I 28800

238

4.

. ,
, , , MySQL 3.22.
InnoDB 9.5.
, -.
6.5.2.

ansijnode. ON (), mysqld


ansi. . 1.8.3. MySQL 3.23.6 3.23.41. sql-mode.

backlog. ,
MySQL. " ",
MySQL- . (
) , . back_log , , MySQL
. ,
.
, -
TCP/IP-. . Unix, , l i s t e n ( ) , .
.
backlog, , .
basedir. MySQL. --basedir.
bdb_cache_size. ,
BDB-. BDB , mysqld
--skip-bdb, .
bdb_cache_size MySQL 3.23.14.
bdbhome. BDB.
, datadir. bdbhome
MySQL 3.23.14.
bdb_log_buffer_size. ,
BDB. BDB ,
0 mysqld skip-bdb,
. bdb_log_buf fer_size MySQL 3.23.14.
bdblogdir. , BDB .
bdb-logdir. MySQL 3.23.14.
bdb_max_lock.
BDB ( - 10 000). ,
, , -

4.2. MySQL

239

mysqld ,
:
bdb: Lock table is out of available locks
Got error 12 from . . .
bdb:
12 . . .
bdb_max_lock MySQL 3.23.29.

bdb_shared_data. ON (), bdbshared-data. MySQL 3.23.29.

bdbtmpdir. --bdb-tmpdir.
MySQL 3.23.14.

bdb_version. BDB. MySQL 3.23.31.


binlog_cache_size. , SQL- . , , MySQL 4.1.2, ( log-bin).
,
, . b i n l o g c a c h e s i z e Binlog_cache_use Binlog_cache_disk_use.
MySQL 3.23.29. . 4.8.4.

bulk_insert_buffer_size. MylSAM
INSERT.. .SELECT, INSERT...
VALUES ( . . . ) , ( . . . ) , . . . LOAD DATA INFILE.
. 0 .

'/" !
;

;
';

, . 8 . MySQL 4.O.3.
m y i s a m _ b u l k _ i n s e r t _ t r e e _ s i z e .

character_set. .
MySQL 3.23.3, MySQL 4.1.1 character_set_xxx.

character_set_client. , . MySQL 4.1.1.

character_set_connection. , ,
( ) . MySQL 4.1.1.

character_set_database. , . ,
. ,
, character_set_server.
MySQL 4.1.1.

240

4.

c h a r a c t e r s e t r e s u l t s . , . MySQL 4.1.1.

character_set_server. .
MySQL 4.1.1.

character_set_system. ,
. utf 8.
MySQL 4.1.1.

character_sets. . MySQL 3.23.15.


collation_connection. . MySQL 4.1.1.

collation_database. , .
,
. ,
, collation_server.
MySQL 4.1.1.

c o l l a t i o n s e r v e r . .
MySQL 4.1.1.

concurrent_inserts. ON ( ) MySQL INSERT SELECT ,


. , mysqld safe skip-new. MySQL 3.23.7.

connect_timeout. , mysqld
, Bad handshake (
).

datadir. MySQL.
datadir.
default_week_format. , WEEK (). MySQL 4.0.14.
delay__key_write. MylSAM. ,
DELAY_KEY_WRITE, CREATE TABLE:

OFF

DELAY_KEY_WRITE .

ON

M y S Q L DELAY_KEY_WRITE
CREATE TABLE. .

ALL

,
DELAY_KEY_WRITE .

DELAY_KEY_WRITE , ,
,
.
, -

4.2. MySQL

241

MylSAM, myisam-recover
(, myisam-recover=BACKUP, FORCE). . 4.2.1 8.1.1.
, external-locking
,
.
MySQL 3.23.8.

delayed_insert_limit. delayed_insert_limit
INSERT DELAYED SELECT.
, ,
.

delayed_insert_timeout. INSERT DELAYED


INSERT .

delayed_queue_size. INSERT DELAYED. , ,


INSERT DELAYED, , .

flush. ON (), flush.


MySQL 3.22.9.

flush_time.
flushtime ,
. Windows 9x Me,
. MySQL 3.22.18.

f t_boolean_syntax. , , IN BOOLEAN MODE. MySQL 4.0.1.


' + ->< () ~*: ""& . :
.
14 .
ASCII-, -.
- .
, 11 12.
,
.

10, 13 14 ( ':','&' ' )


.

f t_max_word_len. FULLTEXT.
MySQL 4.O.O.

f < !
\ FULLTEXT . REPAIR TABLE _ QUICK.

4.

242

ft_min_word_len. FULLTEXT.
MySQL 4.O.O.

"!: !
;

FULLTEXT . REPAIR TABLE _ QUICK.

ft_query_expansion_limit. , ,
WITH QUERY EXPANSION. MySQL 4.1.1.

f t s t o p w o r d f i l e . , -
. ; . -
( myisam/ft_static.c).
( ' ' ) , - . MySQL 4.0.10.

;"' !
\

FULLTEXT . REPAIR TABLE _ QUICK.

group_concat_max_len. GROUP_CONTACT (). MySQL 4.I.O.


havebdb. YES, mysqld BDB,
DISABLED, --skip-bdb. MySQL 3.23.30.
haveinnodb. YES, mysqld
InnoDB, DISABLED, --skip-innodb.
MySQL 3.23.37.
haveisam. YES, mysqld ISAM,
DISABLED, skip-isam. MySQL 3.23.30.
have_raid. YES, mysqld RAID. MySQL 3.23.30.
haveopenssl. YES, mysqld SSL (
) - . MySQL
3.23.43.

i n i t c o n n e c t . ,
. SQL-. (';') ,
. , , , init_connect:
SET GLOBAL init connect='SET AUTOCOMMIT=0';

4.2. MySQL

243


. , ,
, :
[mysqld]
init_connect='SET AUTOCOMMIT=0'
MySQL 4.I.2.

init_f ile. , in i t - f i l e . , SQL-, . . MySQL 3.23.2.

init_slave. init_connect, , SQL-.


, init_connect.
MySQL 4.I.2.

innodb_xxx. InnoDB 9.5.

interactive_timeout. , , .
, CLIENT_INTERACTIVE
mysql_real_connect (). . wait_timeout.

join_buffer_size. , ( ).
. , ,
. ( ,
.)

key__buffer_size. MylSAM ISAM . key_buffer_size - , . .


( , ) ,
.
25% , MySQL, . (, 50% ),
. , MySQL , .

, LOCK TABLES.
SHOW STATUS;
Keyj:ead_requests,
Key_reads, Key_write_requests Key_writes.
Keyreads Key_read__requests ,
0.01. Key_writes Key__write_requests 1,

244

4.
, , ,
,
DELAY_KEY_WRITE.

, key_buf f e r s i z e
Key_blocks_used
. MySQL 4.1.1, key_cache_block_size. :
(Key_blocks_used * key_cache_block_size) / key_buffer size
MySQL 4.1.1 1024 , ,
:
(Key_blocks_used * 1024) / key_buffer_size

. 6.4.6.
key_cache_age_threshold.
(hot sub-chain) (warm
sub-chain). , . - 100. 300.
MySQL 4.1.1. . 6.4.6.

key_cache_block_size. . - 1024. MySQL 4.1.1. . 6.4.6.

key_cache_division_limit. . - , . 1 100. - 100. MySQL 4.1.1. . 6.4.6.

language. , .

l a r g e f i l e s u p p o r t . mysqld
. MySQL 3.23.28.

local_infile. LOCAL LOAD DATA INFILE.


MySQL 4.O.3.

locked_in_memory. mysqld memlock.


MySQL 3.23.25.

log. . . 4.8.2.

log_bin. .
MySQL 3.23.14. . 4.8.4.

l o g s l a v e u p d a t e s . , ,
. ,
.
MySQL 3.23.17. . 5.8.

4.2. MySQL

245

log_slow_queries. . ,
, long_query_time.
MySQL 4.O.2. . 4.8.5.

log_update. . MySQL 3.22.18. , , , MySQL


5.0. . 4.8.3.

long_query_time. , , Slowqueries .
log-slow-queries . , , , .
. 4.8.5.

low_priority_updates. 1, INSERT,
UPDATE, DELETE LOCK TABLE WRITE , SELECT LOCK TABLE READ.
sql_low_priority_updates.
MySQL 3.22.5.

lower_case_table_names. 1,
. MySQL 3.23.6.
2 ( 4.0.18), , , . MySQL 4.0.2, , 4.1.1 - .
0, MySQL
, , ( Windows Mac OS X). 4.0.18: 0, , , , , MySQL lower_case_table_names 2.

max_allowed_packet. .
net_buf fer_length ( ), max_allowedjpacket. - , ( ) . ,
BLOB. ,
(BLOB), . max_allowed_packet - 16 MySQL 4.0
1 .
max_binlog_cache_size.
, , Multistatement transaction required more than 'max_binlog_cache_size' bytes of
storage ( -

246

4.
, ' m a x b i n l o g c a c h e s i z e ' ).
MySQL 3.23.29.

maxbinlogsize. ,
. , 1 , , 4096 . (
MySQL 4.0.14 1024 .) - 1 . MySQL 3.23.33.
, :
, , . , , , max_binlog_size.
max_relay_log_size 0, max_binlog_size . max_relay_log_size
MySQL 4.0.14.
max_connect_errors.
, . FLUSH
HOSTS.

maxconnections. . mysqld
.
6.4.8. . .2.6.
max_delayed_threads. He
INSERT DELAYED.
, , , DELAYED . 0, MySQL
DELAYED; , DELAYED.
MySQL 3.23.0.
max_error_count. , SHOW ERROR SHOW WARNINGS.
MySQL 4.1.0.
max_heap_table_size.
MEMORY (HEAP). , MAX_ROWS MEMORY. MEMORY ,
, CREATE TABLE TRANCATE
TABLE, ALTER TABLE. MySQL 3.23.0.
max_insert_delayed_threads.

maxdelayedthreads. MySQL 4.0.19.

max_join_size. SELECT, , ,
, m a x j o i n s i z e , , -

4.2. MySQL

247

, , , max_join_size, . , SELECT, , . ,

WHERE .
, DEFAULT,
SQL_BIG__SELECTS ( 0). SQL_BIG_SELECTS max_join_size .
, , .
sql_max_join_size.
max_relay_log_size. ,
, , . .
, 0 MySQL max_relay_log_size
, .
max_relay_log_size 4096 1 (),
0. 0. MySQL 4.0.14. . 5.3.
max_seeks_f or_key. , . MySQL , ,
, , . (, 100), ,
MySQL , .
MySQL 4.0.14.
max_sort_length. , BLOB
TEXT. max_sort_length, .
max_tmp_tables. ,
. ( .)
raax_user_connections. , MySQL. 0 . MySQL 3.23.34.
max_write_lock_count. ( ) ,
CREATE TABLE My ISAM, MAX_ROWS
. 2 8.
- 4. MySQL 4.I.2. .
.2.11.

248

4.

myisam_max_extra_sort_f ile_size. , My ISAM, , , .


,
. MySQL 3.23.37.
!
{ 4.0.3 .
myisam_max_sort_file_size. ,
MySQL My ISAM ( REPAIR TABLE, ALTER TABLE LOAD DATA INFILE). ,
, ,
. MySQL 3.23.37.
X' !
pi 4.0.3 .
myisam_recover_options. myisam-recover. MySQL 3.23.36.
myisam_repair_threads. 1, MylSAM
( ) Repair
by sorting. - 1. , - -.
MySQL 4.0.13.
myisam_sort_buffer_size. , My ISAM
REPAIR TABLE CREATE INDEX
ALTER INDEX. MySQL 3.23.16.
named_pipe. Windows ,
. MySQL 3.23.50.
net_buf f er_length.
. ,
, SQL, . , ,
max_allowed_packet .
net_read_timeout. ,
, .
, net_read_timeout -
, ,
. ,
net_read__timeout , . .
slave_net_timeout. MySQL 3.23.20.
net_retry_count. , , . FreeBSD , .
MySQL 3.23.7.

4.2. MySQL

249

net_write_timeout. ,
, . .
net_reead_timeout. MySQL 3.23.20.

open_f iles_limit. , mysqld.


, mysqld . 0 , MySQL . MySQL 3.23.20.

pid_f i l e . (PID).
pid-file.
MySQL 3.23.23.
port. , -. port.
protocol_version. - ,
MySQL. MySQL 3.23.18.
query_alloc_block_size. ,
.
. MySQL 4.0.16.
query_cache_limit. He , . - 1 . MySQL 4.O.I.
query_cache_min_res_unit. ,
. - 4 . 4.10.3. , MySQL 4.1.
query_cache_size. , . - 0, . , ,
query_cache_type 0.
MySQL 4.O.I.
query_cache_type. . GLOBAL
. SESSION,
.

0 OFF

He . ,
.
query_cache_size 0.
, , SELECT SQL_NO_CACHE.
,
Select SQL_CACHE.

1 ON
2 DEMAND

MySQL 4.O.3.

250

4.

query_cache_wlock_invalidate. WRITE My ISAM, , . 1 WRITE , .


, ,
. MySQL 4.0.19.
query_prealloc_size. ,
.
. query_prealloc_size,
.
MySQL 4.0.16.
range_alloc_block_size. , . MySQL 4.0.16.

read_buffer__size. , , ,
. . MySQL 4.O.3.
record_buffer.

readonly. ON, , , SUPER.


, . MySQL 4.0.14.

read_rnd_buffer_size. ,
,
. ORDER BY. , ,
. ,
. MySQL 4.O.3.
record_rnd_buffer.

safe_show_database. He , . ,
, , . . skip_show_database.
MySQL 4.O.5. MySQL
SHOW DATABASES.

secure_auth. MySQL --secure-auth,


, (
4.1) . ON
(), - OFF ().

4.2. MySQL

251

,
(, , ).
MySQL 4.1.1.
( ), , ( 4.1) .
secure_auth , ,
.

server_id. server-id. . MySQL 3.23.26.

skip_external_locking. OFF, mysqld


. MySQL 4.O.3.
skip_locking.

skipnetworking. ON, (
TCP/IP) . Unix . NetWare TCP/IP-,
ON .
MySQL 3.23.23.

skip_show_database. , SHOW
DATABASES, SHOW DATABASES. , , , . .
safe_show_database. MySQL 3.23.24. MySQL
4.0.2 SHOW DATABASES: ON SHOW DATABASES ,
SHOW DATABASES, ; OFF SHOW DATABASES ,
, SHOW DATABASES - .

slave_net_timeout. ,
, . MySQL
3.23.40.
slow_launch_time. , , Slow_launch.
MySQL 3.23.15.
socket. Unix Unix, . Windows ,
.

sort_buffer_size. , , . , ORDER BY GROUP BY.


. .4.4.

252

4.

sqlmode. SQL .
MySQL 3.23.41. . 4.2.2.

storage_engine. table_type. MySQL 4.1.2.

table_cache. .
mysqld . ,
,
Opened_tables. . 4.2.4.
Opened_tables FLUSH TABLES ( ),
table_cache .
6.4.8.

table_type. (innoDB, BDB ISAM).


, --default-table-type.
MySQL 3.23.0. . 4.2.1.

thread_cache_size. . ,
thread_cache_size.
, , , , .
, , . ( .)
Connections
Threads_created ( 4.2.4),
, . MySQL 3.23.16.

thread_concurrency. Solaris mysqld thr__setconcurrency


. . MySQL 3.23.7.

threadstack. . , crash-me, .
. . 6.1.4.

time zone. .
TZ .
--timezone mysqld_safe. MySQL
3.23.15. . .4.6.

tmp_table_size.
, MySQL My ISAM. t m p t a b l e s i z e , GROUP BY, , .

tmpdir. , .
MySQL 4.1,

4.2. MySQL

253

, . (':') Unix (';') Windows, NetWare OS/2.



. MySQL
, , tmpdir
,
. ,
, LOAD DATA INFILE.
,
.
MySQL 3.22.4.

transaction_alloc_block_size. , , ,
. MySQL 4.0.16.

transaction_prealloc_size. transaction_alloc_blocks,
. , ,
malloc().
MySQL 4.0.16.

tx_isolation. .
MySQL 4.O.3.

version. .
wait_timeout. ,
, .
waittimeout wait_timeout interactive_timeout,
( CLIENT_INTERACTIVE
mysql_real_connect ()). . interactive_timeout.
4.2.3.1.
MySQL 4.0.3,
.
. .
mysqld . . ,
.

. ,
. , , ,
SET GLOBAL _. , SUPER.

254

4.

. .
, ,
SET SESSION _. , , - .
, .
, , , .
( ,
SET GLOBAL) .
. sort_buffer_size
.
GLOBAL, :
mysql> SET GLOBAL sort_buffer_size=3Ha4eHne;
:
mysql> SET @@global.sort_buffer_size=3Ha4eHne;
SESSION, :
mysql> SET SESSION sort_buffer__si =;
:
mysql> SET @@session.sort_buffer_size=3Ha4eHJ<re;
:
mysql> SET sort_buffer_size=3Ha4eHne;
GLOBAL, SESSION LOCAL , SESSION.
GLOBAL, :
mysql> SELECT @@global.sort_buffer_size;
mysql> SHOW GLOBAL VARIABLES like 'sortjmffer_size';
SESSION, :
mysql> SELECT @@sort_buffer_size;
mysql> SELECT @@session.sort_buffer_size;
mysql> SHOW SESSION VARIABLES like 'sort_buffer_size';
LOCAL SESSION.
SELECT _ ( global., session., local.), MySQL SESSION,
, - GLOBAL.
SHOW VARIABLES, GLOBAL, SESSION LOCAL, MySQL
SESSION.

4.2. MySQL

255

GLOBAL
(GLOBAL), , , . SESSION
, , SUPER,
GLOBAL, SESSION . SESSION , ,
GLOBAL, , SESSION.
4.2.3.1.1.
, MySQL
4.1.1. :
- , , .

. , .
MySQL .
, .
:

key_buffer_size

key_cache_block_size

key_cache_division__limit

key_cache_age_threshold

, , .
, , ,
, 6.4.6.
,
_. _. :
hot_cache.key_buffer_size
hot_cache.key_cache_block_size
cold cache.key_cache_block_size
default
. , default. ,
default.key_buffer_size, key_buffer_size
.
:

, .

. (

256

4.

- ), , -, .

, ,
\ , hot-cache - , a hotcache N - .

global, session local . , @


@ global. _
.

, .
, -
.

, , . ,
:
shell> mysqld hot__cache.key_buffer_size=64K
:
[mysqld]
hot_cache.key_buffer_size=64K
hot_cache
64 , 8 .
, :
shell> mysqld --key_buffer_size=256K \
extra_cache.key_buffer_size=128K \
extra_cache.key_cachejDlock_size=2048
256 . ( --default.key_buffer_size=256K).
, extra_cache 128 , , 2048 .
, 3:1:1:
shell> mysqld key_buffer_size=6M \
hot_cache.keyjbuffer_size=2M \
cold_cache.key_buffer_size=2M

. , hotcache
10 , :
mysql> SET GLOBAL hot_cache.keyjbuffer__size = 10*1024*1024;
mysql> SET @@global.hot_cache.keyjbuffer_size = 10*1024*1024;

4.2. MySQL

257

:
mysql> SELECT @@global.hot_cache.keyjbuffer_size;

.
, LIKE.
mysql> SHOW GLOBAL VARIABLES LIKE

'hotj:ache.keyjbuffer_size';

, , .
4.2.3.1.2.
MySQL 4.0.3, SET GLOBAL SET
SESSION. SELECT. . 4.2.3.1.
. 4.1 .
, - GLOBAL SESSION ( ) - .
4.1.

autocommit
big tables
binlog_cache_size
bulk insert buffer_size
character set client
character set connection
character set results
character_set_server
collation connection
collation server
concurrent insert
connect timeout
convert_character_set
default week format
delay_key_write
delayed insert limit
delayed insert timeout
delayed_queue_size
error count
flush
flush_time
foreign key checks

OFF | ON | ALL

SESSION
SESSION
GLOBAL
GLOBAL |
GLOBAL |
GLOBAL |
GLOBAL |
GLOBAL |
GLOBAL |
GLOBAL |
GLOBAL
GLOBAL
GLOBAL |
GLOBAL |
GLOBAL
GLOBAL
GLOBAL
GLOBAL
SESSION
GLOBAL
GLOBAL
SESSION

SESSION
SESSION
SESSION
SESSION
SESSION
SESSION
SESSION

SESSION
SESSION

258

4.
. 4.1

ft_boolean_syntax
group concat max len
identity
insert id
interactive_timeout
key buffer size
last_insert_id
local__infile
log_warnings
long query time
low priority updates
max_allowed_packet
max_binlog_cache_size
max_binlog size
max connect errors
max connections
max_delayed_threads
max error count
max_heap_table size
max_insert_delayed_threads
max join size
max_relay_log_size
max seeks for key
max sort length
max tmp tables
max user connections
max_write lock count
myisam max extra sort file size
myisam_max_sort file size
myisam repair threads
myisam sort buffer size
net_buffer_length
net read timeout
net retry count
net write timeout
query alloc block size
query cache limit

GLOBAL
GLOBAL | SESSION
SESSION
SESSION
GLOBAL | SESSION
GLOBAL
SESSION
GLOBAL
GLOBAL
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL
GLOBAL
GLOBAL
GLOBAL
GLOBAL
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL
GLOBAL | SESSION
GLOBAL
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL
GLOBAL
GLOBAL
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL

4.2.

MySQL

259
. 4.1

query_cache_size
query_cache_type
query_cache_wlock_invalidate
query_prealloc_size
range_alloc_block_size
read_buffer__size
read_only
read_rnd_buffer_size
rpl_recovery_rank
safe_show_database
server_id
slave_compressed_protocol
slave_net_timeout
slow_launch__time
sort__buffer_size
sql_auto_is_null
sql_big_selects
sql_big_tables
sql_buffer_result
sql_log_bin
sql_log_off
sql_log_update
sql_low_priority__updates
sql_max_join_size
sql quote_show_create
sql_safe_updates
sql_select_limit
sql_slave_skip_counter
sql_warnings
storage_engine
table_cache
table_type
thread_cache_size
time stamp
tmp_table_size
transaction_alloc_block_size
transaction_prealloc_size

GLOBAL
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL | SESSION
GLOBAL
GLOBAL | SESSION
GLOBAL
GLOBAL
GLOBAL
GLOBAL
GLOBAL
GLOBAL
GLOBAL | SESSION
SESSION
SESSION
SESSION
SESSION
SESSION
SESSION
SESSION
GLOBAL | SESSION
GLOBAL I SESSION
SESSION
SESSION
SESSION
GLOBAL
SESSION
GLOBAL | SESSION
GLOBAL
GLOBAL | SESSION
GLOBAL
SESSION
GLOBAL I SESSION
GLOBAL | SESSION
GLOBAL | SESSION

260

4.
. 4.1

tx_isolation
unique_checks
wait_timeout
warning_count

GLOBAL | SESSION
SESSION
GLOBAL | SESSION
SESSION

"", . "" .
"" 0, 1, ON OFF. "" ;
, .
0, ENUM, 1.

42.4
,
.
SHOW STATUS:
mysql> SHOW STATUS;
I Variable name
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I
I

Aborted clients
Aborted connects
Bytes_received
Bytes_sent
Connections
Created tmp disk tables
Created tmp files
Created tmp tables
Delayed errors
Delayed insert threads
Delayed writes
Flush commands
Handler__delete
Handler read first
Handler_read key
Handler read next
Handler read prev
Handler_read rndHandler read rnd next
Handler update
Handler write
Key blocks used
I Key_read__requests

Value
0
0
155372598
1176560426
30023
0
60
8340
0
0
0
1
462604
105881
27820558
390681754
I 6022500
30546748
I 246216530
I 16945404
I 60356676
| 14955
I 96854827

|
1
|
|
|
1
|
|
1
1
1
|
|
|

4.2. MySQL
Key_reads
Key_write_requests
Key_writes
Max_used_connections
Not_flushed_delayed_rows
Not_flushed_key_blocks
Open_files
Open_streams
Open_tables
Opened_tables
Qcache_free_blocks
Qcache_free_memory
Qcache_hits
Qcache_inserts
Qcache_lowmem_prunes
Qcache_not_cached
Qcache_queries_in_cache
Qcache_total_blocks
Questions
Select_full_join
Select_full_range_j oin
Select_range
Select_range_check
Select_scan
Slave_open_temp_tables
Slave_running
Slow_launch_threads
Slow_queries
Sort_merge_passes
Sort_range
Sort_rows
Sort_scan
Table_locks_immediate
Table_locks_waited
Threads_cached
Threads_connected
Threads_created
Threads_running
Uptime

261

162040
7589728
3813196
0
0
0
2
0
1
44600
36
138488
79570
27087
3114
22989
415
912
2026873
0
0
99646
0
30802
0
OFF
0
0
30
500
30296250
4650
1920382
0
0
1
30022
1
80380

STATUS
0.
, , . _ , MySQL 3.23.47.
Qcache_xxx , MySQL 4.O.I. , , , , MySQL 3.22.
Aborted_clients. ,
. . .2.10.
Aborted_connects.
MySQL. . .2.10.

262

4.

Binlog__cache_use. , . MySQL 4.I.2.

Binlog_cache__diskjjse. ,
, binlog_cache_size
.
MySQL 4.1.2.

Bytesreceived. , .
MySQL 3.23.7.

Bytes_sent. , .
MySQL 3.23.7.

Comxxx. , .
. ,
Comdelete Cominsert
DELETE INSERT.

Connections. ( )
MySQL.

Created_tmp_disk_tables. ,
.
MySQL 3.23.24.

Created_tmp_f i l e s . , mysqld. MySQL 3.23.28.

Created_tmp_tables. , .
Created_tmp_disk_tables tmp_table_size,
, .

Delayed_errors. INSERT DELAYED , - (, d u p l i c a t e key).

Delayed_insert_threads. INSERT
DELAYED.

Delayed__writes. INSERT DELAYED.


Flushcommands. FLUSH.
Handlercommit. COMMIT.
MySQL 4.O.2.

H a n d l e r d e l e t e . , .

H a n d l e r _ r e a d _ f i r s t . , . , , , , SELECT c o l l FROM foo,


, c o l l .

Handler_read__key. .
, ,
.

4.2. MySQL

263

Handle r r e a d n e x t .
. ,
.

Handler_read_prev.
.
ORDER BY... DESC. MySQL 3.23.6.

Handlerreadrnd. , . , ,
. , ,
MySQL ,
, .

Handler_read_rnd_next.
. ,
. , .

Handler_rollback. ROLLBACK.
Handlerupdate. .
Handlerwrite. .
Key_blocks_used. . , , ; . key_buf f eresize 4.2.3.
Key_read_requests. .
Key_reads. . Key_reads , key_buffer_size, ,
. -
Key_reads/Key_read_requests.
Key_write_requests. .
Key_writes. .
Max_used_connections. , .
Not_flushed_delayed_rows.
INSERT DELAY.

Not_f lushed_key_blocks. , , .
Open_f iles. .
Openst reams. ( ).
Open_tables. .
Opened_tables. . Opened_tables
, table_cache, , .
Qcachef reeblocks. .

264

4.

Qcache_f reejnemory. .
Qcache_hits. .
Qcache_inserts. .
Qcache_lowmem_prunes. , .
Qcache_not_cached. , (
, - query_cache_type).
Qcache_queries_in_cache. .
Qcache_total_blocks. .
Questions. .
Rpl_status. ( ).

Select_full_join. (), . 0, . MySQL 3.23.25.

Select_full_range_join. ,
.
MySQL 3.23.25.

Select_range. ,
. ( , .)
MySQL 3.23.25.

Select_range_check. , . ( ,
.)
MySQL 3.23.25.

Selectscan. , . MySQL 3.23.25.

Slave_open_temp_tables. ,
SQL- .
MySQL 3.23.29.

Slave_running. ON, ,
. MySQL 3.23.16.
Slow_launch_threads. , ,
slow_launch_time, . MySQL
3.23.15.
Slow_queries. , ,
long_query_time, . . 4.8.5.

Sort_merge_passes. ,
. , sort_buffer_size. MySQL
3.23.28.

Sortrange. , .
MySQL 3.23.25.

4.3.

265

Sortrows. .
MySQL 3.23.25.

Ssl__xxx. , SSL-.
MySQL 4.O.O.

Tablelocksimmediate. , . , MySQL
3.23.33.

Table_locks_waited. , , . ,
,
, ,
. , MySQL 3.23.33.

Threads_cached. . MySQL 3.23.17.


Threads_connected. .
Threads_created. , .
Threads_created ,
thread__cache_size.
Threads_created/Connections. MySQL
3.23.31.
Threads_running. , .
Uptime. .

4.3.
, ,
, , ,
MySQL . , , MySQL
, 4.4.

4.3.1. ,

, MySQL , Internet, , ,
.
( MySQL) : ,
. , .
MySQL , ,
, ,
(Access Control List - ACL). SSL-

266

4.

MySQL. MySQL;
.
MySQL, :
( (root)
MySQL) user mysql!
. - MySQL. , user , ,
.
MySQL. GRANT REVOKE MySQL. He , . .
.
mysql -u root. , . MySQL
(root) , !
,
, root. . 2.4.5.
SHOW GRANTS, , . REVOKE .
.
. MD5(), SHAH) -
-.
. . "xfish98"
. "duag98",
"fish", ,
QWERTY. "Mhall", ;
- "Mary had a little lamb". , , .
. , ,
50% . MySQL (DMZ).
.
Internet , nmap. MySQL
3306. . , MySQL- -
- ,
_ - , MySQL:
shell> telnet _ 3306

4.3.

267

, -
, , ,
. telnet , , , : .
, .

Web-, URL-
. , , - "; DROP
DATABASE mysql;". ,
,
, .
-
.
. SELECT * FROM table WHERE
ID=234 234, 234 OR 1=1,
SELECT * FROM table WHERE
ID=234 OR 1=1. .
.
-
: SELECT * FROM table WHERE ID='234 f .
, .
MySQL
.
, , . .
, -
(, , , ). .
.
' ' ' () '"' () Web-.
MySQL - , ,
.
URL- %22 (""), %23 ('#') %27 (''')

URL-
, . .
, ,
.
MySQL . MySQL !
MySQL.

268

4.


, ,
.
, .

API- , . , ,
:
MySQL API - API- m y s q l r e a l e s c a p e s t r i n g ().
MySQL++ - escape quote .
- mysql_escape_string(),
MySQL API. 4.0.3 addslashes ().
Perl DBI - quote () -.
Java JDBC - PreparedStatement -.
API- .
() Internet. , .
, SSL SSH. MySQL SSL-, 4.0.0. SSH- , ,
( ) .
tcpdump strings.
, MySQL, ,
:
shell> tcpdump -I -i ethO -w - src or dst port 3306 | strings
( Linux .) :
, , .
, .

4.3.2. MySQL
MySQL . .
MySQL 4.1.1 . MySQL ( 4.1.1)
, , ,
, , . (
4.4.9.)
, SSH- .

4.3.

269

, , . , (
MySQL 3.22 ), .
, SSH, TCP/IP-
MySQL. Open Source SSH http://www.openssh.org/, SSH- - h t t p : //www. ssh. com/.
MySQL 4.0 OpenSSL-. .
4.5.7.
MySQL,
.
MySQL.
, . - , . , mysql ,
mysql -u ^ ___,
_ . , .
, SET PASSWORD.
user mysql. , MySQL
root, :
shell>
mysql>
->
mysql>

mysql -u root
UPDATE mysql.user SET Password=PASSWORD('_')
WHERE User='root 1 ;
FLUSH PRIVILEGES;

He MySQL (root) Unix. , , FILE, (root) (,


-root/.bashrc). , mysql root , ,
user=root.
mysqld
. Unix
mysql, . MySQL. mysqld
Unix, user,
, [mysqld] /etc/my.cnf
my. cnf, . :
[mysqld]
user=mysql

270

4.
,
, mysqldsafe
mysql. server. .3.2.
mysql , ( root)
Unix , root user.
MySQL
Unix.

. (
skipsymbolic-links.) ,
mysqld root, ,
, ! .
6.6.1.2.
, Unix, / , ,
mysqld.
PROCESS SUPER . mysqladmin processlist , , , , , , UPDATE user SET password=PASSWORD('not_secure').
mysqld ,
SUPER ( PROCESS MySQL 4.0.2) ,
(root) MySQL ,
.
SUPER ,

.
FILE . , , mysqld! -
, , SELECT... INTO OUTFILE, ,
.
DNS, IP-
. , !
, mysqld max_user_connections. GRANT , .

4.3.3. mysqld,

mysqld :

4.3.

271

local-infile[={0 11} ]. local-infile=0,


LOAD DATA. . 4.3.4.

safe-show-database. SHOW
DATABASES ,
- . 4.0.2,
( ). SHOW DATABASES, , .

safe-user-create. , GRANT ,
INSERT mysql.user.
, , :
mysql> GRANT INSERT(user) ON mysql.user TO '_}@'_;
,
,
GRANT.

secure-auth. ,
( 4.1) . , MySQL 4.1.1.

skip-grant-tables. .
! ( , , mysldadmin flushprivileges mysqladmin reload, FLUSH PRIVILEGES.)

skip-name-resolve. .
Host IP- localhost.

skip-networking. TCP/IP- .
mysqld Unix.
MySQL, 3.23.27, MIT-pthreads, Unix MIT-pthreads.

skip-show-database. SHOW DATABASES


, SHOW DATABASES, . , SHOW DATABASES
, ,
SHOW DAATABASES -
.

4.3.4. LOAD DATA LOCAL


LOAD DATA ,
, LOCAL.
LOCAL LOAD DATA
, :

272

4.

MySQL.
, , ,
LOAD DATA.
, .
Web-, Web-, LOAD DATA LOCAL , Web- (,
, SQL-). MySQL- Web-,
, , Web-.
, LOAD DATA LOCAL
MySQL 3.23.49 MySQL 4.0.2 (4.0.13 Windows) :
MySQL
MySQL 3.23.48 enablelocal-infile.
MySQL enable-local-infile ,
LOAD DATA LOCAL ,
raysql_options (. . . MYSQL_OPT_LOCAL_INFILE, 0).
LOAD DATA LOCAL , mysqld local-inf ile=0.
mysql LOAD DATA LOCAL , local-inf i l e [=1],
local-infile=0. mysqlimport local -L
. , , .
LOAD DATA LOCAL INFILE ,
:
ERROR 1148: The used command is not allowed with this MySQL version
1148:

MySQL

4.4. MySQL
MySQL , . .

4.4.1.
MySQL
, , , SELECT, INSERT, UPDATE DELETE.

4.4. MySQL

273


MySQL-,
LOAD DATA INFILE .

4.4.2.
MySQL , . MySQL
, , , , . , .
MySQL , ,
, Internet, . , joe, office.com, ,
joe, elswhere.com. MySQL ,
, ,
: joe
office. com, - elswhere. com.
MySQL :
: , .
(, ):
. ,
, , SELECT , , DROP .
( - ) , , . 4.4.7.
, ,
.
,
GRANT REVOKE
, .
, ,
.
user, db host mysql
. . 4.2.
( ), , tables_priv columnspriv,
. . 4.3.

274

4.
4.2. user, db host

user

db

host

Host
User
Password


Host
Db
User

Host
Db

Select priv
Insert priv
Update_priv
Delete priv
Index_priv
Alter_priv
Create priv
Drop priv
Grant_priv
References priv
Reload priv
Shutdown priv
Process_priv
File priv
Show db priv
Super priv
Create_tmp table priv
Lock tables priv
Execute priv
Repl_slave_priv
Repl client_priv
ssl_type
ssl cipher
x509 issuer
x509_subject
max questions
max updates
max connections


Select priv
Insert priv
Update priv
Delete priv
Index_priv
Alter_priv
Create priv
Drop priv
Grant_priv
References priv

Select priv
Insert priv
Update priv
Delete priv
Index priv
Alter priv
Create priv
Drop priv
Grant priv
References_priv

Create tmp table priv


Lock tables priv

Create tmp table priv


Lock_tables__priv

4.4. MySQL

275

4.3. tables_priv columns_priv


tables_priv

columnsjpriv

Host
Db

Host
Db

User

User

Table_name

Table_name
Column name

Table priv

Column priv

Column_priv

Timestamp

Timestamp

Grantor
Timestamp Grantor ,
.
:
() , , . ,
user, Host User , , 'thomas.loc.gov' 'bob', thomas.loc.gov, bob. , Host, User Db
' thomas. loc. gov', 'bob' ' reports', , bob thomas.loc.gov,
reports. tables_priv columns_priv ,
, .
, ,
.
, . , , 4.4.6.
, ,
. 4.4. - .
MySQL Db CHAR (32)
CHAR(60) .
, Host
. User, Password, Db Table_name .
Column_name MySQL 3.22.12 .

276

4.

4.4.

Host
User

CHAR(60)

Password

CHAR(16)

Db

CHAR(64)

Table_name

CHAR(60)

Column name

CHAR(60)

CHAR(16)

user, db host , ENUM (' N ' , ' Y') DEFAULT ' N'. ,
; ' N' ().
tables_priv columns_priv
SET. , (. . 4.5):
4.5.

tables_priv

Table_priv

'Select f , ' I n s e r t ' , 'Update', 'Delete',


'Create', 'Drop', 'Grant', 'References',
'Index', 'Alter'

tables_priv

Columnjpriv

' S e l e c t ' , ' I n s e r t ' , 'Update', 'References'

columns_priv

Column_priv

'Select', ' I n s e r t ' , 'Update', 'References'

, :

user , . user (
). .

db , ,
. ,
. , ,
.

host db, , db . , ,
, Host db
, host,
. 4.4.6.

4.4. MySQL

277

GRANT REVOKE host.


%, MySQL .

tables_priv columnspriv db,


:
, . ,
, . , , .
( RELOAD SHUTDOWN)
user,
. , . ,
, ,
user.
FILE user.
, , .
mysqld .
FLUSH PRIVILEGES mysqladmin flush-privileges mysqladmin
reload. 4.4.7 ,
.
, .
SHOW GRANTS. , , , Host User
84. example. com bob, :
mysql> SHOW GRANTS FOR 'bob'@'pc84.example.com;
mysqlaccess,
MySQL (Yves Carlier). , , mysqlaccess help. , mysqlaccess
, user, db host. ,
tables_priv columnspriv, .
4.4.8. 4.3.

44.3. , MySQL
user, db, host,
tables_priv columnspriv mysql. MySQL
, , 4.4.7.
,
MySQL , . 4.6.

278

4.

, , , .
"MySQL. ".
4.6. MySQL

ALTER

Alter_priv

DELETE

Delete_priv

INDEX

Index_priv

INSERT

Insert_priv

SELECT

Select_priv

UPDATE

Update_priv

CREATE

Create_priv

DROP

Drop_priv

GRANT

Grant_priv

REFERENCES

References_priv

Create_tmp_tablejpriv

CREATE TEMPORARY

TABLES

EXECUTE

Executejpriv

FILE

File_priv

LOCK TABLES

Lock_tables_priv

PROCESS

Processjpriv

RELOAD

Reload_priv

REPLICATION

CLIENT

Repl_client_priv

REPLICATION

SLAVE

Repl_slave_priv

SHOW DATABASES

Show_dbj?riv

SHUTDOWN

Shutdown_priv

SUPER

Super_priv

CREATE
REPLICATION

TEMPORARY

TABLES, EXECUTE, LOCK

TABLES, REPLICATION

CLIENT,

SLAVE, SHOW DATABASES SUPER M y S Q L 4 . 0 . 2 .

EXECUTE REFERENCES .
SELECT, INSERT, UPDATE DELETE .
SELECT SELECT,
. SELECT . , raysql , :
mysql> SELECT 1+1;
mysql> SELECT PI()*2;

4.4. MySQL

279

CREATE DROP
. DROP mysql , , M y S Q L !
INDEX .
. CREATE
CREATE TABLE.
ALTER ALTER TABLE
, .
GRANT , .
FILE LOAD DATA INFILE SELECT...INTO OUTFILE. ,
FILE, M y S Q L
. ( ,
,
.) FILE
, M y S Q L . .
, mysqladmin SQL-.
4.7 , mysqladmin .
4.7. mysqladmin,

RELOAD

flush-hosts, flush-logs, flush-privileges, flush-status,


flush-tables,flush-threads, refresh, reload

SHUTDOWN

shutdown

PROCESS

processlist

SUPER

kill

reload
, flushprivileges reload.
refresh , . flush-xxx , refresh,
, . , ,
flush-logs, refresh.
shutdown .
mysqladmin. SQL- .
processlist ( , , ). k i l l .
, , -

280

4.

, PROCESS, - SUPER.
MySQL 4.0.2, SUPER, , PROCESS.
CREATE TEMPORARY TABLES
TEMPORARY CREATE TABLE.
LOCK TABLES LOCK TABLES
, SELECT. ,
.
REPLICATION CLIENT SHOW MASTER STATUS SHOW
SLAVE STATUS.
REPLICATION SLAVE ,
,
. , .
SHOW DATABASES
SHOW DATABASE. , , , -
, ,
skip-show-database.
, , :
GRANT
. ,
GRANT, .
ALTER .
FILE,
, MySQL . . , SELECT,
.
SHUTDOWN, .
PROCESS , , .
SUPER
.
, mysql,
,
. , , . , ,

4.4. MySQL

281

Password user, -
, MySQL.
MySQL :
, -
. , , .
, ,
.

4.4.4. MySQL
MySQL
:
, MySQL.
.
.
, mysql
( shell>):
shell> mysql -h _ - _ -
-h, -u - hos 1=_, user=
_ password=napcwib. , -
password .
- password, ,
.
. ,
.
, auxww. . 4.5.6.
MySQL
:
- localhost.
- ODBC ( Windows) ( Unix).
, -.
, Unix joe :
shell>
shell>
shell>
shell>

mysql -h localhost -u joe


mysql -h localhost
mysql -u joe
mysql

MySQL .
,
,
, :

282

4.

[client]
. :
[client]
host=_
=_
password=napcwib
3.3.2.
. mysql MySQL_HOST, MySQL USER ( Windows NetWare). MYSQLPWD, ; . 4.5.6. .

4.4.5. , :

MySQL , , . ,
. , ,
.
:
, .
MySQL.

user (Host, User Password).
, Host USER user
, PASSWORD.
Host user :
Host IP-,
' local host' .
Host '%' '_'.
, ,
LIKE. , ' %' ,
'%.mysql.com1
mysql. com.
MySQL 3.23, Host, IP-,
, ,
:
mysql> GRANT ALL PRIVILEGES ON db.*
-> TO david@ f 192.58.197.0/255.255.255.0';

david IP- 1-_, :


1-_ & _ = 1-_

4.4. MySQL

283

, GRANT:
1-_ & 255.255.255.0 = 192.58.197.0
IP-,
MySQL, 192.58.197.0 192.58.197.255.

Host db , host, .
AND ( ), OR ( ). host 4.4.6.
Host
, ' %'.

Host IP- (, '144.155.166.%' ), , 144.155.166.somewhere.com. , MySQL , . ,


1.2.foo.com Host
. IP- IP-,
.
User ,
, . user, , ,
, , , . ,
( ).
Password ( ).
, , ,
.
Password user . MySQL , .
, , ,
, ( PASSWORD ()).
, ( ). MySQL , ! , mysql!
4.1, MySQL , , ,
. ,
TCP/IP mysql.
4.4.9.
. 4.8 , Host User user .

4.

284

4.8. Host User



User

Host

'thomas.loc.gov'

'fred'

fred,
thomas.loc.gov.

' thomas. loc. gov'

,
thomas.loc.gov.

'

' %'

' fred'

fred, .

' %'

''

' fred'

,
.
fred,
loc.gov.
fred, ..net,
. . com, . . edu (, , ).
fred, ,
IP-
144.155.166.177.

%. loc. gov'

'..%'

'fred'

'144.155.166.177'

'fred'

'144.155.166.%'

'fred'

fred,
144.155.166 .

'144.155.166.0/255.255.255.0'

' fred'

To , .

, user.
: , fred thomas. loc. gov.
() , , . :
, user, .
, .
,
.
, , , user :
I
+
I
I
I
I

Host

! User
+
%
| root
%
I Jeffrey
localhost | root
localhost |

|
+
I
I
|
I

4.4. MySQL

285


Host.
IP-. ' %' " " .
Host
User ( User " "
).
:
+
++
! Host
| User
I ...
+
+
+I localhost | root
| ...
I localhost !
| ...
I %
| Jeffrey | ...
I %
| root
| ...
+
+
+_
, . , Jeffrey
localhost, : 'localhost 1
Host ' ' User, '%'
' J e f f r e y ' .
'localhost', .
. , user :
4-

I Host

I User

+-

...

+
++
I %
I Jeffrey
| ...
I thomas.loc.gov |
| ...
+
44- :
+
++
I Host
I User
I ...
4.
+
+| thomas.loc.gov |
| ...
I %
I Jeffrey
I ...
4.
4.
4
, Jeffrey thomas.loc.gov, , , j ef f rey whitehouse. gov - .
, , , , . . . : , Jeffrey thomas.loc.gov,
'Jeffrey' User, , ! Jeffrey ,
.

286

4.

, , ,
- . ,
,
CURRENT_USER (). __, User Host user. , Jeffrey :
mysql> SELECT CURRENTJJSER();
+
+
1 CURRENTJJSER () |

f
I @localhost
+

+
|
+

,
user User. ,
Jeffrey .
CURRENTJJSER () , MySQL 4.O.6. : user
, , .

4.4.6. , :

, .
, ,
. . user, db, host,
t a b l e s p r i v columnspriv. ( 4.4.2
.)
user ,
. , user DELETE,
! , user
.
user , .
, user ( N' .
, .
db host .
:
' _ ' Host DB
. , , LIKE.
, . , '_'
, '\_' GRANT.

4.4. MySQL

287

'%' Host db " ".


Host db " host" ( ).
'%' Host host "
".
'%' Db "
".
User
.
host db,
user. db Host, Db User
host Host Db. user,
, , .
tables_priv columns_priv
.
:
'%' '_' Host
. , , LIKE.
' %' " ".
Db, Table_name Column_name
.
tables_priv columns_priv Host,
Db User. db, ,
Host .
. (
, , , . ,
-
.)
, ,
SHUTDOWN RELOAD, user,
. ,
,
. , mysqladmin shutdown,
user SHUTDOWN,
db host. ( Shutdown_priv, .)
(INSERT, UPDATE ), , , ( ) user.
, .

288

4.

user ,
, db host:
1. db Host, Db
User. Host User
MySQL, Db - ,
. Host User , .
2. db Host
,
.
3. Host db , ,
host , . Host
Db host. host , .
( !) db host, 'Y1 . ( db,
host.)
, db host, , user. , . tables_priv
colurans_priv, ,
, , .

:

OR { AND )
OR
OR
, user
, ,
, ,
. ,
. , INSERT
INTO.. .SELECT, INSERT SELECT. user, - db.
, , ,
, .
GRANT REVOKE host, MySQL. -

4.4. MySQL

289

, , , , . , host
. .
host . , public.your.domain ,
. host, ,
, ,
:
I Host
| Db | . . .
+
+
+I public.your.domain | % I . . . ( ' N')
I %. your, domain
| % I . . . ( ' Y')
, (,
SHOW GRANTS mysqlaccess), ,
, .

4.4.7.
mysqld
, .
, :
.

USE __.

.
GRANT, REVOKE SET
PASSWORD, .
, INSERT, UPDATE
DELETE, ,
, . , FLUSH PRIVILEGES
mysqladmin flush-privileges mysqladmin reload.
, ,
, , !

4.4.8.
(Access denied)
MySQL ,
, :

290

4.

, . ,
. , , , :
shell> mysql
ERROR 2003: Can't connect to MySQL server on 'host_name' (111)
shell> mysql
ERROR 2002: Can't connect to local MySQL server through socket
'/tmp/mysql.sock1 (111)
, , TCP/IP-,
Unix, , . , port
, -socket Unix.
,
. MySQL
Windows RPM Linux, mysql, .
MySQL , mysql_install_db. . 2.4.2.
, , mysql . ( data var
MySQL). , mysql
user.MYD. , mysql_install_db.

:
shell> mysql -u root test
.
, .
shell> mysql -u root mysql
, MySQL root .
,
MySQL
root.
2.4.5.
mysql_f ix_privilege_tables , MySQL ? , . ,
, ,
. . 2.5.8.

4.4. MySQL

291

, ,
, , :
shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
, , 4.4.9
.2.3.
(root)
, , , user
'root 1 User,
:
Access denied for user: lf@'unknown' to database mysql
skip-grant-tables
/etc/hosts \windows\hosts,
.
,
, . (
) ,
. ,
, Access denied (" "), , !
, --no-defaults, :
shell> mysqladmin no-defaults -u root version
3.3.2.
.
, , root:
shell> mysqladmin -u root -pxxxx ver
Access denied for user: 'root'@'localhost'

(Using password: YES)

, , , . --no-defaults, .
4.5.5.
root, mysqld
skipgrant-tables, . . .4.1.
SET PASSWORD, INSERT UPDATE
PASSWORD().
PASSWORD(), . , , ,
:

292

4.
1

mysql> SET PASSWORD FOR ' a b e ' @ ' _ ' = ' e a g l e ;

:
mysql> SET PASSWORD FOR 'abe'@'_' = PASSWORD('eagle');
GRANT mysqladmin
password PASSWORD ,
. . 4.5.5.

localhost , ,
, . localhost
Unix , MySQL,
3.23.27, MIT-pthreads: localhost Unix, MIT-pthreads .
--host=
127.0.0.1 . TCP/IP mysqld. TCP/IP-
host, . user
,
.

Access denied ,
mysql -u _, , user. mysql -u root mysql
SQL-:
mysql> SELECT * FROM user;
, Host User
MySQL.
Access denied :
, ,
, . user
,
, . ,
"Using password: NO" ,
.
, ,
MySQL, , ,
user Host, .
Host . . . is not allowed to connect to this MySQL server
. . . MySQL

4.4. MySQL

293

IP- , ,
, user ' % '
Host mysqld -log . MySQL . ( ' %'
user , . , .)
Linux
, MySQL , , , glibc.
, glibc,
MySQL . RPM-
, .
, , IP-,
, , MySQL IP-
:
shell> mysqladmin -u root -pxxxx -h some-hostname ver
Access denied for user: ' r o o t ' G 1 1 (Using password: YES)
DNS. mysqladmin flush-hosts,
DNS. . 6.5.5.
:

, DNS, .
MySQL IP-, .
/etc/hosts.

mysqld --skip-name-resolve.

mysqld skip-host-cache.

Unix, , localhost.
Unix, TCP/IP.
Windows, ,
, . (). , TCP/IP.
mysql -u root t e s t , mysql -h _
-u root ( _ - )
Access denied, , user .
, Host user , , , -

294

4.
( ). , user
' tcx 1 , DNS MySQL
' tcx. subnet. se', . user , Host IP-. (
user , Host
, , 'tcx.% 1 . ,
, '%', , .)

mysql -u _ t e s t , mysql -
_ ___ - , ,
___.
mysql -u _ , , ,
.
Access denied ,
user Host,
(.. '%' '_').
, '%' Host '' User ,
localhost . , 'localhost' Host
' ' User. localhost , '%', ,
localhost!
'localhost' Host ''
User, 'localhost'
Host ' ' User. FLUSH PRIVILEGES, .
,
db host:
Access to database denied

db Host,
, host , , , , db.
MySQL , Access
denied , SELECT.. .INTO
OUTFILE LOAD DATA INFILE, , user FILE.
(
INSERT, UPDATE DELETE) , , FLUSH PRIVILEGES flush-privileges,
. -

4.4. MySQL

295

. , root
UPDATE ,
, , ,
.
,
, , MySQL.
,
, 4.4.7.

Perl, PHP,
Python ODBC, mysql -u
_ __ mysql - _ -
__. mysql ,
, , .
( - ; passwor1=. -,
MySQL .)

mysqld --skip-grant-tables.
MySQL
mysqlaccess, ,
. , mysqladmin flush-privileges, . (
skip-grant-tables, .)
, mysqld (,
debug=d,general,query). , , .
MySQL, ,
, , MySQL. mysqldump mysql, - mysqlbug. . 1.7.1.3.
mysqldump .

4.4.9 MySQL 4.1


MySQL user mysql. , Password
User , -. -
PASSWORD ().
MySQL - :
, , , - - user .

4.

296

, ,
- , user. PASSWORD (), - , GRANT SET PASSWORD.

, - ,
. -,
PASSWORD ()
GRANT SET PASSWORD, .
MySQL 4.1 .
4.1, . , 4.1,
( 4.1),
, . , , 4.1, 4.1. , mysql 4.0 4.1 :

shell> mysql -h localhost -u root


Client does not support authentication protocol requested
by server; consider upgrading MySQL client
, ;
MySQL


, 4.1 , ( 4.1) . .2.3.
;

4.1
{
, 4.1, 4.1.1.
' ' MySQL 4.1.0 "", \ 4.1.1 . 4.1.0
'(' 4.4.9.2.
, MySQL 4.1, - , PASSWORD (), 16 :
mysql> SELECT PASSWORD('mypass');
PASSWORD('mypass') |
+
6f8cll4b58f2ce9e
|

Password user ( -)
MySQL 4.1 16 .
MySQL 4.1, PASSWORD () , 41 :

4.4. MySQL

297

mysql> SELECT PASSWORD('mypass');


+

I PASSWORD!'mypass1)

I *43c8aa34cdc98eddd3delfe9a9c2c2a9f92bb2098d75 |
+

, Password user 41
, :
, MySQL 4.1, Password
41 .
MySQL 4.1, mysql_fix_privilege_tables,
Password 16 41 . (
, - 16 .)
Password - ,
. - :
- - (16 41 ).
: - '*', - - .
- , - , , .
- , , , - , .
, - ,
Password:
(), -.
(), ,
-, :
, , 4.1,
, , -
.
, 4.1,
, -.
-, 4.1,
. ,
, :
, 4.1, - .

298

4.

4.1, - .

4.1, - .

, - ,
Password old-passwords. 4.1 -, :
Password , ,
old-password . :

Password ,
- (41 ). -
16 ( , 4.1.), ,
,
PASSWORD () GRANT
SET PASSWORD, -. , 4.1,
mysql_f ix_privilege_tables, Password.

Password ,
-. PASSWORD () GRANT SET PASSWORD -,
--old-passwords,
- .

old-passwords
, 4.1, , - .
( 4.1 - ), - user
. , 4.1 . old-passwords , :

-
.

. --old-passwords ,
- .

, ,
- ,
. (
- ,
4.1, -,
.)

, ( 4.1) , 4.1 old-passwords.


--old-passwords - , , ,

4.4. MySQL

299

. (
, , , -.)
old-passwords , -
( 4.1). , , - , . -, (,
4.1), ,
old-passwords.
4.1 :
1. Password user .
Password -.
.

- PASSWORD(), GRANT SET PASSWORD


-.
- .

old-password , ,
Password , - .

2. Password ;
old-password.

Password , -.

4.1
, -.

( 4.1)
-.

- PASSWORD!), GRANT SET PASSWORD


-.
- .

, ,
- , 4.1. , PASSWORD () GRANT SET PASSWORD, ,
- . ( 4.1) ,
4.1.
, . ,
SET PASSWORD :
mysql> SET PASSWORD FOR ''@'

= PASSWORD('mypass');

300

4.

-,
SET PASSWORD OLD_PASSWORD ():

mysql> SET PASSWORD FOR '1@!' = OLD_PASSWORD('mypass');


OLD_PASSWORD() ,
-.
3. Password ;
old-passwords.
Password , -.
4.1
, - ( ,
- , old-passwords).
( 4.1)
-.
- PASSWORD(), GRANT SET PASSWORD
-.
- .
- , old-passwords . , -
old-passwords,
, , , -.
:
1 -, .
2 - ( 4.1) ,
OLD_PASSWORD ().
3 old-passwords ,
- , , - -, , --old-passwords.
4.4.9.1.

MySQL 4.1 , PASSWORD () . , PASSWORD!) MySQL.
PASSWORD () .

4.5. MySQL

301

4.1 - , , PASSWORD ()
, . - , - , , SHA1O MD5(). ,
OLD_PASSWORD (), - . , ,
OLD_PASSWORD () .
-,
OLD_PASSWORD () , PASSWORD ().

4.4.9.2. MySQL 4.1.0


MySQL 4.1.0 4.1.1
:

- 45 , 41 .

PASSWORD () ,
PASSWORD (x) .

MySQL 4.1.0 . MySQL 4.1.0


. user ,
41 .

45.
MySQL
, MySQL. :

MySQL
, .

SSL.

4.5.1. MySQL
MySQL ( ) , .
. , MySQL, ,
:

, MySQL , (

302

4.
) Windows Unix. Unix , MySQL Unix, .
,
- user.
, ,
,
, . ,
, , .

MySQL 16 ,
.
, Unix 8 .
MySQL ,
. , Windows Unix, , ,
MySQL .
MySQL .
, Unix
. MySQL , SQL- PASSWORD (), Unix
SQL- ENCRYPT (). 4.1, MySQL
, , , . , TCP/IP mysql. ( ,
user , , ,
, MySQL.)
MySQL . , 2.4.5,
. , , , MySQL
GRANT REVOKE.

MySQL , :
shell> mysql user=monty password=guess __
, :
shell> mysql -u monty -pguess __
- . .
4.4.4.
,
(. 4.5.6).
, password -, :

4.5. MySQL

303

shell> mysql user=monty password __


shell> mysql -u monty -p ___
. (
__ ,
__ password .)
, MySQL
, 8 .
, MySQL. MySQL - . ,
MySQL , .

4.5.2. MySQL
MySQL :
GRANT.
MySQL.
GRANT, . GRANT , MySQL 3.22.11; "MySQL. ".

,
MySQL, , ,
phpMyAdmin.
, mysql . , , 2.4.5. ,
- ,
MySQL (root) , root
INSERT mysql
RELOAD.
mysql
(root) MySQL:
shell> mysql user=root mysql
root , ( ) password -.
root,
. GRANT :
mysql>
->
mysql>
->
mysql>
mysql>

GRANT ALL PRIVILEGES ON *.* TO ' m o n t y ' @ ' l o c a l h o s t 1


IDENTIFIED BY ' s o m e j > a s s ' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'monty 1 @'%'
IDENTIFIED BY ' s o m e _ p a s s ' WITH GRANT OPTION;
GRANT RELOAD,PROCESS ON *.* TO ' a d m i n ' @ ' l o c a l h o s t ' ;
GRANT USAGE ON *.* TO ' d u m m y ' @ ' l o c a l h o s t ' ;

, GRANT,
:

304

4.

monty
some_pass
1
. ('monty'@'localhost )
. ('monty'@'%') -
. ,
monty
monty. localhost
localhost, mysql_install_db,
monty . monty
. ,
Host,
monty' @ ' % ' , user. (
user 4.4.5.)

admin .
. RELOAD PROCESS,
mysqladmin reload, mysqladmin r e f r e s h mysqladmin
flush-xxx commands, mysqladmin p r o c e s s l i s t .
,
GRANT.

dummy .
.
. USAGE GRANT
' N'
. ,
.

, INSERT,
:

shell> mysql --user=root mysql


mysql> INSERT INTO user
->
VALUES (' localhost', 'monty', PASSWORD ( somejaass ) ,
->
'YVYVYVYVYVYVYVYVYVYVYVYVYVY');
mysql> INSERT INTO user

->

VALUES (' %' , 'monty' , PASSWORD (' some_pass') ,

->
'YVYVY'/YVYVYVYVYVYVYVYVYVYVY');
mysql> INSERT INTO user SET Host='localhost',User='admin',
->
Reload_priv='Y', Process_priv='Y';
mysql> INSERT INTO user (Host,User,Password)
->
VALUES('localhost 1 ,'dummy', " ) ;
mysql> FLUSH PRIVILEGES;
FLUSH PRIVILEGES INSERT , .
. GRANT FLUSH PRIVILEGES .

4.5. MySQL

305

PASSWORD () . GRANT
, PASSWORD () .
' Y' . MySQL, ' Y' INSERT. ( MySQL, 3.22.11,
; 4.0.2 .)
admin INSERT,
SET, , MySQL 3.22.11.
INSERT dummy
Host, User Password user. ,
MySQL ' N'. , GRANT USAGE.
, , , ' Y' user. user ,
.
,
.
custom obscure.
GRANT, :
s h e l l > mysql u s e r = r o o t mysql
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
->
ON b a n k a c c o u n t . *
->
TO ' c u s t o m ' @ ' l o c a l h o s t '
->
IDENTIFIED BY ' o b s c u r e ' ;
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
->
ON e x p e n s e s . *

->
TO 'custom1@'whitehouse.gov'
->
IDENTIFIED BY 'obscure';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON customer.*
-> TO 'cus torn'@'server.domain'
->
IDENTIFIED BY 'obscure';
:
bankaccount,
.
expenses,
whitehouse. gov.
customer,
server .domain.
custom GRANT, INSERT, :
shell> mysql user=root mysql
mysql> INSERT INTO user (Host,User,Password)
->
VALUES('localhost','custom',PASSWORD('obscure'));

306

4.

mysql> INSERT INTO user (Host,User,Password)


1
-> VALUES('whitehouse.gov','custom ,PASSWORD('obscure'));
mysql> INSERT INTO user (Host,User,Password)
-> VALUES('server.domain','custom',PASSWORD('obscure'));
mysql> INSERT INTO db
->
(Host,Db, User, Selectj?riv,Insert_jpriv,
->
Update_priv, Deletejpriv, Createjpriv, Dropjpriv)
->
VALUES('localhost','bankaccount','custom',

->

'YVYVYVYVYVY');

mysql> INSERT INTO db


->
(Host,Db,User,Selectjpriv,Insert jpriv,
- > Updatejpriv, DeleteJ?riv, Create_priv, Drop jpriv)
->
VALUES('whitehouse.gov','expenses','custom',
->
'Yf,'Y','Y','Y','Y','Y');
mysql> INSERT INTO db
->
(Hos t,Db,User,Select_priv,Insertjpriv,
-> Updatejpriv, Delete_priv, Create_priv, Drop_priv)
-> VALUES (' server.domain',' customer',' custom',
->
'Y','Y','Y','Y','Y','Y');
mysql> FLUSH PRIVILEGES;
INSERT user,
custom , (
'N'). INSERT db,
bankaccount, expenses customer,
. , ,
,
FLUSH PRIVILEGES, , .

(, mydomain.com), GRANT,
'%' ,
:
mysql> GRANT ...
-> ON *.*
- > ' myname' @ ' %. mydomain. com'
-> IDENTIFIED BY 'mypass1;
,
, :
mysql> INSERT INTO user (Host,User,Password,. . .)
-> VALUES (' %.mydomain. com','myname', PASSWORD ('mypass '),...);
mysql> FLUSH PRIVILEGES;

4.5.3.
MySQL
DROP USER,
MySQL 4.1.1. DELETE.

4.5. MySQL

307

MySQL :
1. SHOW GRANTS ,
.
2. REVOKE SHOW GRANTS
. , user, , ( user).
3. DROP USER user.
DROP USER MySQL 4.1.1. , 4.1.1,
, ,
user :
mysql> DELETE FROM mysql.user
-> WHERE User='_* and
mysql> FLUSH PRIVILEGES;

Host='_';

4.5.4.
MySQL 4.0.2 MySQL max_user_connections.
. ,
,
, , . MySQL,
Internet.
MySQL 4.0.2, :
.
.
.
. , , .
- user. User Host.
,
user mysql , .
, ,
max_questions, max_updates max_connections. ,
user ; . 2.5.8.
GRANT, WITH,
, . ,
, customer, , :

308

4.

mysql> GRANT ALL ON c u s t o m e r . * TO ' f r a n c i s 1 @ ' l o c a l h o s t '


->
IDENTIFIED BY ' f r a n k '
->
WITH MAX_QUERIES_PER_HOUR 20
->
MAXJJPDATESJPERJtoUR 10
->
MAX_CONNECTIONS_PER_HOUR 5 ;

WITH, ,
, . , // . GRANT
WITH, , - 0 ( ).
, GRANT USAGE (ON *. *).
francis , , 100:
mysql> GRANT USAGE ON * . * TO ' f r a n c i s ' @ ' l o c a l h o s t '
->
WITH MAX__QUERIES_PER_HOUR 1 0 0 ;


.
, 0. , francis
, :
mysql> GRANT USAGE ON * . * TO ' f r a n c i s ' @ ' l o c a l h o s t '
->
WITH MAX_CONNECTIONSJ>ER_HOUR 0 ;

, 0.
,
.
, . ,
: .
.
, . , 50, 100,
, . ,
, .
( 0) , :

0, FLUSH USER_RESOURCES (, FLUSH PRIVILEGES
mysqladmin reload).
,
. GRANT USAGE,
, , ,
.

4.5. MySQL

309

4.5.5.
, mysqladmin:
shell> mysqladmin -u _ -h _ password "_"
, , , user _
User , , Host.
- SET PASSWORD:
m y s q l > SET PASSWORD FOR ' J e f f r e y ' @ ' % '

= PASSWORD('biscuit');

, root,
mysql, . , ,
FOR:
mysql> SET PASSWORD = P A S S W O R D ( ' b i s c u i t ' ) ;

GRANT USAGE (ON *. *) :


m y s q l > GRANT USAGE ON * . * TO ' J e f f r e y ' @ ' % '

IDENTIFIED BY ' b i s c u i t ' ;


,
user:

, Password:
shell>
mysql>
->
mysql>

mysql -u r o o t mysql
INSERT INTO u s e r (Host,User,Password)
VALUES('%','Jeffrey',PASSWORD('biscuit'));
FLUSH PRIVILEGES;


UPDATE, Password:
'shell>
mysql>
->
mysql>

mysql -u root mysql


UPDATE user SET Password = PASSWORD('bagel')
WHERE Host = '%' AND User = ' f r a n c i s ' ;
FLUSH PRIVILEGES;

SET PASSWORD, INSERT UPDATE,


PASSWORD () . (
, PASSWORD () , .) , user , . :
s h e l l > mysql -u root mysql
mysql> INSERT INTO user (Host,User,Password)
->
VALUES('%','Jeffrey','biscuit');
mysql> FLUSH PRIVILEGES;

4.

310

user ,
' b i s c u i t ' . Jeffrey , , user.
' biscuit', :
shell> mysql -u Jeffrey -pbiscuit test
Access denied

GRANT.. .IDENTIFIED BY mysqladmin password, ( ) , PASSWORD () .

!
PASSWORD!) Unix. .
4.5.1.

4.5.6.

mysql.user . user
, MySQL, 4.1, .
MySQL , . , .
- pass wo r ^ , :
shell> mysql -u francis -pfrank __
, , , ps, . MySQL
, - , .
- password . :
shell> mysql -u francis -p __
Enter password: ********
'*' , . .
, , .
,
. -

4.5. MySQL

311

. ( ).
. , Unix [client] .my.cnf :
[client]
pas s wo r (1=
.my.cnf, , , . ,
400 600:
shell> chmod 600 .my.cnf
, , 3.3.2.
MYSQL_PWD.
, . ps
. , MYSQLPWD,
, ps. , ps, , , , , . .
.


.

4.5.7.
4.0.0, MySQL () MySQL
(Secure Sockets Layer - SSL). SSL, SSH Windows.
, MySQL
, . - . MySQL. ,
, .
MySQL . , , : SSL-.

4.5.7.1. SSL
, MySQL SSL, SSL 509. , ,
.

312

4.

MySQL
. , , ,
, / , . , -compress. .
, . -
. ,
,
,
.
SSL - ,
, .
, . SSL
, 509.
509 Internet.
. , "Certificate Authority" (" "),
, .
, ( ). . .
, , ,
.
SSL, X509 Internet, .

4.5.7.2.
MySQL ,
, OpenSSL, MySQL .
4.0.0.
MySQL,
:
1. OpenSSL. MySQL OpenSSL O.9.6.
OpenSSL http: //www.openessl .org.
2. MySQL configure
with-vio with-openessl.
3. ,
SSL mysql.user. , MySQL,
4.0.0. 2.5.8.
4. , mysqld OpenSSL, , have_openessl:

4.5. M y S Q L

313

mysql> SHOW VARIABLES LIKE 'have_openssl';


+
+
+
| Variable_name | Value I
+
+
+
| have_openssl

| YES

YES, , OpenSSL.

4.5.7.3. SSL- MySQL


SSL- MySQL:
DIR=NpwdVopenssl
PRIV=$DIR/private
rakdir $DIR $PRIV $DIR/newcerts
cp /usr/share/ssl/openssl.cnf $DIR
replace ./demoCA $DIR -- $DIR/openssl.cnf
# : $database, $serial
# $new_certs_dir ()
touch $DIR/index.txt
echo "01" > $DIR/serial
#
# Certificate Authority (CA)( )
#
openssl req -new -x509 -keyout $PRIV/cakey.pem -out $DIR/cacert.pem\
-config $DIR/openssl.cnf
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

:
/horae/monty/openssl/openssl.cnf
1024
RSA
++++++
++++++

'/home/monty/openssl/private/cakey.pem1
:
- :
,
.
" ", DN
(Distinguished Name).

.
.
'.' .
( ) [AU]:FI
() [- ]:.
(, ) []:
(, ) [Internet Widgits Pty Ltd]:MySQL AB

314

4.

# [ ]:
# (, ) []: MySQL
# []:
#
#
#
openssl req -new -keyout $DIR/server-key.pem -out \
$DIR/server-req.pem -days 3600 -config $DIR/openssl.cnf
# :
# /home/monty/openssl/openssl.cnf
# 1024
# RSA
#
++++++
#
++++++
#
# '/home/monty/openssl/private/cakey.pem'
# :
# - :
#
# ,
# .
# " ", DN
# (Distinguished Name).
#
# .
# .
# '.' .
#
# ( ) [AU]:FI
# () [- ]:.
# (, ) []:
# (, ) [Internet Widgits Pty Ltd]:MySQL AB
# []:
# (, ) []: MySQL
# []:
#
# , '' ,
#
# []:
# ()[]:
#
# ()
#
openssl rsa -in $DIR/server-key.pem -out $DIR/server-key.pem
#
#
#
openssl ca -policy policy_anything -out $DIR/server-cert.pem \
-config $DIR/openssl.cnf -infiles $DIR/server-req.pem

4.5. MySQL
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

:
/home/monty/openssl/openssl.cnf
:
, .

:

::'FI'
1

::'MySQL AB

::'MySQL admin'
13 14:22:46 2005 (
) ( 365 )
? [()/()]: ()

1 1 , ? [()/()]: ()

#
#
#
openssl req -new -keyout $DIR/client-key.pem -out \
$DIR/client-req.pem -days 3600 -config $DIR/openssl.cnf
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

:
/home/monty/openssl/openssl.cnf
1024
RSA
++++++
++++++

'/home/monty/openssl/client-key.pem'
:
- :
,
.
" ", DN
(Distinguished Name).

.
.
'.' .
( ) [AU]:FI
() [- ]:.
(, ) []:
(, ) [Internet Widgits Pty
Ltd]:MySQL AB
[]:
(, ) []: MySQL
[ ]:

315

316

4.

#
#
#
#

, '' ,

[]:
()[]:

#
# ()
#
openssl rsa -in $DIR/client-key.pem -out $DIR/client-key.pem
#
#
#
openssl ca -policy policy_anything -out $DIR/client-cert.pem \
-config $DIR/openssl.cnf -infiles $DIR/client-req.pem
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#

:
/home/monty/openssl/openssl.cnf
:
, .

:

::FI'

::'MySQL AB'

::'MySQL admin'
13 14:22:46 2005 (
) ( 365 )
? [()/()]: ()
1 1 , ? [()/()]: ()


my.cnf,

cnf=""
cnf="$cnf [client]"
cnf="$cnf ssl-ca=$DIR/cacert.pem"
cnf="$cnf ssl-cert=$DIR/client-cert.pem"
cnf="$cnf ssl-key=$DIR/client-key.pem"
cnf="$cnf [mysqld]"
cnf="$cnf ssl-ca=$DIR/cacert.pem"
cnf="$cnf ssl-cert=$DIR/server-cert.pem"
cnf="$cnf ssl-key=$DIR/server-key.pem"
echo $cnf | replace " " '
' > $DIR/my.cnf
SSL-, :
shell> mysqld --defaults-file=$DIR/my.cnf &
$DIR - , my. cnf.

4.5. MySQL

317

shell> mysql --defaults-file=$DIR/my.cnf


MySQL, , my.cnf , SSL.

4.5.7.4. SSL- GRANT


, MySQL
509. SSL MySQL, REQUIRE
GRANT, "MySQL. ".

4.5.7.5. SSL
, SSL,
. , MySQL 4.O.
, .

ssl. ,
SSL-. SSL. SSL-,
, sslca, ssl-cert
ssl-key.
ssl skip-ssl
SS1=0,TO , , SSL .
, --ssl SSL-. , SSL, .
SSL- -
, REQUIRE SSL
GRANT, , ,
SSL.
ssi-=_.
() SSL.

ssi-capat=_. , SSL (
).

s si-1=_. SSL, .

ssl-1\\=_. , SSL-. _ ,
openssl ciphers.
: --ssl-cipher=ALL:-AES:-EXP

ssl-ke=_. SSL,
.

318

4.

4.5.7.6. MySQL SSH


Windows
, MySQL SSH,
(David Carlson, dcarlson@mplcomm.com).
1. SSH- Windows. , ,
( ) - ,
SecureCRT (http://www.vandyke.com/).
f-secure (http://www.f-secure.com/). , Google
http://directory.google.com/Top/Computers/Security/Products_and_Tools/Cry
ptography/SSH/Clients/Windows/ .
2. Windows- SSH. Host_Name = -__1aMpec_cepBepa_MySQL, user6.=__

. userid
MySQL.
3. : (local_port: 330,
remote_host: 1-__1-___50, remote_port: 3306),
(port: 3306, host: localhost, remote port: 3306).
4. ; , .
5. SSH.
6. Windows - ODBC- (, Access).
7. Windows MySQL ODBC-
, , __8()1
MySQL localhost.
ODBC- MySQL, SSH.

46.

, . SQL-
MySQL. .
My ISAM.
InnoDB 9.9.

4.6.1.
MySQL , . , LOCK TABLES, - FLUSH
TABLES. , ,

4.6.

319

. FLUSH TABLES , , .
SQL, SELECT INTO.. .OUTFILE BACKUP
TABLE. SELECT INTO.. .OUTFILE ;
BACKUP TABLE MySQL 3.23.56 MySQL 4.0.12,
.
-
mysqldump mysqlhotcopy. . 7.8 7.9.
1. :
shell> mysqldump tab=///'/
opt __

shell> mysqlhotcopy __ ////


(*.frm, *.MYD *.MYI),
. mysqlhotcopy
. ,
innoDB, . InnoDB
, mysqlhotcopy
My IS AM ISAM.
2. mysqld, , - - l o g - b i n [ =
_]. . 4.8.4. ,
, ,
, ,
mysqldump.
MySQL , ,
, m a s t e r . i n f o r e l a y log, info. .
LOAD DATA INFILE,
SQL_LOAD-*, , - - s l a v e - l o a d tmpdir. ( , tmpdir). , LOAD DATA INFILE.
My ISAM,
REPAIR TABLE myisamchk -. 99,9% .
myisamchk , . ( ,
, l o g - b i n ; .
4.8.4.)
1. , mysqldump,
.

320

4.

2. ,
:
shell> mysqlbinlog _-. [0-9]* | mysql

(
, , ,
). ,
mysqlbinlog , 7.5.
, :
shell> I s - I - t - _.[0-9]* | xargs cat | mysql
Is ,
.
:
, SELECT * INTO OUTFILE _*
FROM '_ '.
, LOAD DATA INFILE
' _' REPLACE... ,
UNIQUE PRIMARY KEY.
REPLACE ,
.

, . . 5.1.
Veritas, :
1. FLUSH TABLES WITH READ LOCK.
2. mount vxf s snapshot.
3. UNLOCK TABLES.
4. .
5. .

4.6.2.

myisamchk My ISAM (, .MYI .MYD). isamchk ISAM (, . ISM . ISD). . 8.
myisamchk
.
, myisamchk (

4.6.

321

), myisamchk
.
myisamchk - , ( ,
), -
.
myisamchk , , FULLTEXT ,
, MySQL. , 4.6.2.2.

My ISAM SQL-, ,
myisamchk:
MylSAM CHECK TABLE
REPAIR TABLE.
MylSAM OPTIMIZE TABLE.
MylSAM ANALYZE TABLE.
, , MySQL 3.23.14.
mysqlcheck, .
myisamchk
, . ,
myisamchk, , . myisamchk .

4.6.2.1. myisamchk
myisamchk :
s h e l l > myisamchk [] ^

, myisamchk . . myisamchk help.


, myisamchk .
myisamchk , ,
.
_ - , . myisamchk , , myisamchk , .
myisamchk ,
. , , .
myisamchk.
(
.MYI).

4.

322

* .MYI. , , My ISAM
:
shell> myisamchk *.MYI
, , ,
:
shell> myisamchk ///__/* .MYI
, , ('*') MySQL:

shell> myisamchk /// ^/*I* .MYI


My ISAM ISAM :
shell> myisamchk silent fast /// /* /* .MYI
shell> isamchk silent ///_/*/*.ISM
My ISAM ISAM , :
shell> myisamchk silent force fast update-state \
-0 keyjbuffer=64M -0 sort_buffer=64M \
-0 read_buffer=lM -0 writeJmffer=lM \
///_/*/*.MYI
shell> isamchk silent force -0 keyJbuffer=64M \
-0 sortjDuffer=64M -0 read_buffer=lM -0 write_buffer=lM \
///__/*/*. ISM
64
. myisamchk
4.6.2.6.
, myisamchk
. myisamchk :
warning: clients are using or haven't closed the table properly
:
, ( , , mysqld),
, .
mysqld , , FLUSH TABLES, . , , myisamchk. - myisamchk CHECK TABLE.

4.6.2.2. myisamchk
, , , myisamchk.
, , .

help, -?. .

4.6.

323

1=_, -# _. .
_ ' d: t : , _'.

s i l e n t , -s. .
. -s (-ss) .

--verbose, -v. . .
-d -. , -v (-vv, -vvv).

v e r s i o n , -V. .

wait, -w. , , ,
, . ,
mysqld s k i p - e x t e r n a l - l o c k i n g , myisamchk.

, _=
:

decode_bits

f t_max_word_len

ft_min_word_len

key_buffer_size

523264

myisam_block_size

1024

read_buffer_size

262136

sort_buffer_size

2097144

sort_key_blocks

16

write_buffer_size

262136

s e t - v a r i a b l e =
^ -0 _= . MySQL
4.0 .
myisamchk
myisamchk h e l p :

s o r t _ b u f f e r _ s i z e , ,
recover.

key_buffer_size extend-check
(
).

s a f e - r e c o v e r .

, , (
) , .
, CHAR, VARCHAR TEXT ,

324

4.
. , sort-recover.

, ,
.
,
key_buffer_size sort_buffer_size , 25%
. ,
.
myisamblocksize - , . , MySQL 4.O.O.
f t_min_word_len f t_max_word_len ,
MySQL 4.0.0, a f t s t o p w o r d f i l e - MySQL 4.0.19.
f t_min_word_len f t_max_word_len FULLTEXT. f t_stopword_f i l e -.
.
myisamchk , ( ), FULLTEXT
, -, , . .
- , . My ISAM . , -
, myisamchk , mysqld, ft_min_word_len, ft_max_word_len ft__stopword_file. , 3, myisamchk
:
shell> myisamchk recover ft_min_word_len=3 _ . MYI
, myisamchk
,
[mysqld], [myisamchk] :
[mysqld]
ft__min_word_len=3
[myisamchk]
ft__min_word_len=3
myisamchk
REPAIR TABLE, ANALYZE TABLE, OPTIMIZE TABLE ALTER TABLE. , ,
.

4.6.2.3. myisamchk
myisamchk ,
:

4.6.

325

check, -. . , , .

-check-only-changed, -. ,
.

extend-check, -e. .
, .
.
myisamchk myisamchk medium-check ,
.
extend-check , key_buffer_size
.

fast, -F. ,
.

force, -f. , myisamchk


. , ,
repair -.

information, -i. .

medium-check, -m. , extend-check.


99,99% ,
.

--read-only, -. . ,
myisamchk , -
, (, mysqld, skip-external-locking).

update-state, -U.
.MYI. ,
check-only-changed, - mysqld, --skip-external-locking.

4.6.2.4. myisamchk
myisamchk ,
:

backup, -. .MYD ^- ..

character-sets-dir=nyTb. , . .
4.7.1.

correct-checksum. .

--data-file-length=#, -D #. () (
, "").

extend-check, -e.
.

326

4.
. ,
.

force, -f. ( __)).

~keys-used=#, -k #. myisamchk ,
. , - 0. isamchk , # . 0
, .
myisamchk
- isamchk -r.

no-symlinks, - I . He . myisamchk , .
, MySQL 4.O. 4.0
.

parallel-recover, -p. , - -,
, . MySQL
4.0.2. -.
!

quick, -q. .
-q, myisamchk
, .

recover, -r. , , ( ISAM My ISAM


). , , . -,
myisamchk , - ( , ,
).

safe-recover, -.
,
.
, -, , -
. , -. -,
, -.

key_buffer__size.

set-character-set=niwi. , .

sort-recover, -n. myisamchk


,
.

4.6.

327

--tmpdir=nyrb, - t . , . , myisamchk
TMPDIR. MySQL 4.1, tmpdir
, .
Unix
(':'), Windows, NetWare OS/2 - (';').

--unpack, -u. ,
myisampack.

4.6.2.5. myisamchk
myisamchk :

--analyze, -. . , ,
, , .
myisamchk description verbose _ SHOW
KEYS FROM ^.

description, -d. .

set-auto-increment[^],
-[].
AUTO_INCREMENT ( ,
AUTO_INCREMENT ).
, AUTO_INCREMENT
.

sort-index, -S.
. .

sort-records=#, -R #. .
SELECT ORDER BY, . (
.)
SHOW KEYS, , myisamchk. 1.

4.6.2.6. myisamchk
myisamchk .
myisamchk , -0, .
myisamchk ,
, .

3 . myisamchk. , 32 ( ):

328

4.

shell> myisamchk - sort=16M -0 =16 - read=lM - write=lM ...


- sort=16M .
, myisamchk TMPDIR. TMPDIR
, " " . , , TMPDIR
myisamchk.
myisamchk :
(
). quick ,
. ,
, ,
.
,
.
, . , .
recover --sort-recover ( safe-recover) . :
{_ + __) * _ * 2
__ myisamchk
-dv _. ( TMPDIR tmpdi=).
,
, ,
safe-recover recover.
4.6.2.7. myisamchk
mysqld skip-external-locking (
, , Unix) myisamchik, mysqld, . , mysqld , myisamchk, , , mysqladmin
flush-tables. , mysqld ,
. myisamchik , mysqld, , , .
skip-external-locking myisamchik . , ,
, , myisamchik
.

4.6.

329

myisamchik ,
, mysqld ( , skip-external-locking). ,
mysqld, , , mysqladmin flush-tables,
myisamchik.
myisamchik .
, MySQL
, . , , . . .4.2.
, My ISAM, ,
. . 8.1.4.
, My ISAM _
:

_. f rm

().

_ . MY D

_ . MY I

,
.
myisamchik .MYD .
.MYD
. quick myisamchik
.MYD, , .MYD , , .MYD. , myisamchik , .MYD,
, . myisamchik
quick .
( , , ) myisamchik
, .MYD.
quick ,
.
, , ,
myisamchik.
4.6.2.8. MyiSAM
My ISAM :
myisamchk _. 99,9% .
,
( ). , myisamchk -s silent.

330

4.

myisamchk -m _. 99,999% .
,
.
,
.
myisamchk -e _. (- ).

, , ,
.
. myisamchk ,
. ,
verbose (-v). myisamchk ,
20.
myisamchk -e -i _. , -i myisamchk .
myisamchk, , , .

4.6.2.9.
, myisamchk MylSAM (
.MYI .MYD). ISAM ( .ISM .ISD)
myisamchk isamchk.
.
MySQL 3.23.16 MylSAM
( ) CHECK TABLE REPAIR TABLE.
, , , :
__. f rm .
_.1 ( : ###).
.
.
### .
, perror
###, ### - . perror
, , :
shell> perror 126 127 132 134 135 136 141 144 145
126 = Index f i l e is crashed / Wrong f i l e format
/

127 = Record-file is crashed



132 = Old database file

4.6.

331

134 = Record was already deleted (or record f i l e crashed)


( )
135 = No more room in record f i l e

136 = No more room in index f i l e

141 = Duplicate unique key or constraint on write or update


144 = Table is crashed and l a s t repair failed

145 = Table was marked as crashed and should be repaired

, 135 ("
") 136 (" ") , . ALTER TABLE,
MAX_ROWS AVG_ROW_LENGTH:
ALTER TABLE _

MAX_ROWS=xxx

AVG_ROW_LENGTH=yyy;

, SHOW
CREATE TABLE _.
.
myisamchk .
, .
, . Unix
, , mysqld ( , ). , .
myisamchk isamchk 4.6.2.
,
, myisamchk isamchk.
, . , mysqladmin
shutdown , mysqld
mysqladmin , .
1:
myisamchk * .MYI , , myisamchk -e * .MYI. -s ( ),
.
mysqld , update-state,
myisamchk 'checked' ('').

4.

332

, myisamchk .
2.
"" ( " ") myisamchk 3.
2:
|

, myisamchk
, isamchk s o r t _ b u f f e r _ s i z e k e y _ b u f f e r _ s i z e ,
'%, 25% .

myisamchk -r -q _ ( - -q ).
. , , ,
, . . :
1. , .
2. myisamchk -r _ ( - ).
,
.
3. myisamchk - _ , safe-recover
_. , ,
( ).
"" ( " ") myisamchk 3.
3:
,
16 ,
.
. :
1. - .
2. , ()
.
shell>
mysql>
mysql>
mysql>

mysql _
SET AUTOCOMMIT=1;
TRUNCATE TABLE _;
quit

MySQL TRANCATE TABLE , DELETE FROM _.


3. . (
; , - .)

4.6.

333

2. myisamchk -r -q _ .
( , .)
MySQL 4.0.2, REPAIR TABLE
_ USE_FRM, .
4:
, . f rm .
,
.
1. 3.
2.
myisamchk -r.
2. , , ,
. , . f rm
.
, .MYD .
2 .

4.6.2.10.
, ,
myisamchk :
shell> myisamchk -r _
SQL-
OPTIMIZE TABLE. , , , . ,
OPTIMIZE TABLE, .
myisamchk , :

-S, sort-index

-R _, sort-=_

-,analyze

4.6.2.1.

4.6.3.
, , ,
. My ISAM - CHECK TABLE REPAIR TABLE, ,
MySQL 3.3.16.
- myisamchk.
myisamchk -s. -s ( - - s i l e n t )

334

4.

myisamchk ,
.
. ,
, , , - , ( " "). MylSAM myisam-recover, , MySQL 3.23.25.
, mysqldsafe
, myisamchk ,
24 ,
.pid ( ). .pid mysqld
. .pid
, mysqld .
- , , .pid.
, . MySQL AB ,
; crontab :
35 0 * * 0 ///myisamchk fast silent ///_/*/* .MYI
, , , .
(
) MySQL AB ( !),
.
myisamchk -s ,
24 ,
MySQL , MySQL AB.
MySQL .
(, VARCHAR, BLOB
TEXT)

(, ).
OPTIMIZE TABLE. ,
mysqld ,
( ):
shell> myisamchk -r -s sort-index -0 sort_buffer_size=16M */*.MYI
ISAM:
shell> isamchk - -s sort-index -0 sort_buffer_size=16M */*.ISM

4.6.4.
, .
:

4.6.

335

myisamchk -d _. myisamchk " " . , MySQL

skip-external locking, myisamchk


, . ,
myisamchk " ", .

myisamchk -d -v _. -v myisamchk
, , .

myisamchk - e i s _.
. , .

myisamchk - e i v _. - e i s ,
, .

.
:
-rw-rw-r-- I monty
tcx
317235748 Jan 12 17:30 company.MYD
-rw-rw-r 1 davida
tcx
96482304 Jan 12 18:35 company.MYM
myisamchk -d:

MylSAM file: company.MYI


Record format: Fixed length
Data records: 1403698 Deleted blocks: 0
Recordlength: 226
table description:
Key Start Len Index
Type
1 2
8 unique double
2
15 10 multip. text packed stripped
3
219 8 multip. double
4
63 10 multip. text packed stripped
5
167 2 multip. unsigned short
6
177 4 multip. unsigned long
7
155 4 multip. text
8
138 4 multip. unsigned long
9
177 4 multip. unsigned long
193 1
text
myisamchk -d -v:
MylSAM file:
Record format:
File-version:
Creation time:
Recover time:
Status:

company
Fixed length
1
1999-10-30 12:12:51
1999-10-31 19:13:01
checked

Data records:
1403698 Deleted blocks:
0
Datafile parts:
1403698 Deleted data:
0
Datafile pointer (bytes):
3 Keyfile pointer (bytes):
3
Max datafile length: 3791650815 Max keyfile length: 4294967294
Recordlength:
226

336

4.

table description:
Key Start Len Index Type
Rec/key
1 2
8 unique double
1
2
2 15
10 multip. text packed stripped
73
3
219 8 multip. double
10 multip. text packed stripped
5
4
63
5 167 2 multip. unsigned short
4840
6
177 4 multip. unsigned long
1346
7
155 4 multip. text
4995
8
138 4 multip. unsigned long
87
9 177 4 multip. unsigned long
178
193
1
text

Root
Blocksize
15845376
1024
25062400
1024
40907776
1024
1024
48097280
55200768
1024
1024
65145856
75090944
1024
85036032
1024
96481280
1024

myisamchk -eis:
Checking MylSAM file: company
Key: 1: Keyblocks used: 97% Packed: 0% Max levels: 4
Key: 2: Keyblocks used: 98% Packed: 50% Max levels: 4
Key: 3: Keyblocks used: 97% Packed: 0% Max levels: 4
Key: 4: Keyblocks used: 99% Packed: 60% Max levels: 3
Key: 5: Keyblocks used: 99% Packed: 0% Max levels: 3
Key: 6: Keyblocks used: 99% Packed: 0% Max levels: 3
Key: 7: Keyblocks used: 99% Packed: 0% Max levels: 3
Key: 8: Keyblocks used: 99% Packed: 0% Max levels: 3
Key: 9: Keyblocks used: 98% Packed: 0% Max levels: 4
Total: Keyblocks used: 98% Packed: 17%
Records :
1403698 M.recordlength:: 226
Packed:
0%
Recordspace used:
100% Empty space:
0%
Blocks/Record:
1.00
Record blocks:
1403698 Delete blocks:
0
Recorddata:
317235748
Deleted data:
0
Lost space:
0 Linkdata:
0
User time 1626.51, System time 232.36
Maximum resident set size 0, Integral resident set size 0
Non physical pagefaults 0, Physical pagefaults 627, Swaps 0
Blocks in 0 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 639, Involuntary context switches 28966
myisamchk -eiv:
Checking MylSAM file: company
Data records: 1403698 Deleted blocks:
- check file-size
- check delete-chain
block_size 1024:
index 1:
index 2:
index 3:
index 4:
index 5:
index 6:
index 7:

4.6.

337

index 8:
index 9:
No recordlinks
- check index reference
- check data record references index: 1
Key: 1: Keyblocks used: 97% Packed: 0% Max levels: 4
- check data record references index: 2
Key: 2: Keyblocks used: 98% Packed: 50% Max levels: 4
- check data record references index: 3
Key: 3: Keyblocks used: 97% Packed: 0% Max levels: 4
- check data record references index: 4
Key: 4: Keyblocks used: 99% Packed: 60% Max levels: 3
- check data record references index: 5
Key: 5: Keyblocks used: 99% Packed: 0% Max levels: 3
- check data record references index: 6
Key: 6: Keyblocks used: 99% Packed: 0% Max levels: 3
- check data record references index: 7
Key: 7: Keyblocks used: 99% Packed: 0% Max levels: 3
- check data record references index: 8
Key: 8: Keyblocks used: 99% Packed: 0% Max levels: 3
- check data record references index: 9
Key: 9: Keyblocks used: 98% Packed: 0% Max levels: 4
Total: Keyblocks used: 9% Packed: 17%
- check records and index references
[LOTS OF ROW NUMBERS DELETED]
Records:
1403698 M.recordlength: 226 Packed:
0%
Recordspace used: 100% Empty space:
0% Blocks/Record: 1.00
Record blocks: 1403698 Delete blocks:
0
Recorddata: 317235748 Deleted data:
0
Lost space:
0 Linkdata:
0
User time 1639.63, System time 251.61
Maximum resident set size 0, Integral resident set size 0
Non physical pagefaults 0, Physical pagefaults 10580, Swaps 0
Blocks in 4 out 0, Messages in 0 out 0, Signals 0
Voluntary context switches 10604, Involuntary context switches 122798
myisamchk . "Keyfile" . "Record" () "row" () .
MylSAM file. () MylSAM.
File-version. MylSAM. 2.
Creation time. /
.
Data records. .
Deleted blocks. , - . ,
. . 4.6.2.10.

338

4.

Datafile parts.
. ,
, , Data records.

Deleted data. , . , . . 4.6.2.10.

Datafile pointer. ( ) . 2, 3, 4
5 . 2 ,
MySQL . - ,
- .

Keyf i l e pointer. ( ) . 1, 2 3 . 2 ,
MySQL . .
Max datafile length. ( ).
Max keyf i l e length.
( ).
Recordlength.
( ).
Record format. , . Fixed length.
- Compressed Packed.
table description. . myisamchk
:
Key. .

Start. .

Len. .
.
,
.

Index. . - unique multiple.

. . MylSAM.
- packed, stripped empty.

Root. .

Blocksize. . 1024,

MySQL .

Rec/key. , . . 1.
( ) myisamchk -a.
, 30.

4.6.

339

, ,
table description. , , .

Keyblocks used. . myisamchk ( ,


) ( ).

Packed ( ). MySQL . CHAR, VARCHAR


DECIMAL. , ,
. 10 , 60%.

Max levels. - .
Max levels .

Records. .

M.recordlength. .
, .

Packed ( ). MySQL .
Packed .

Recordspace used. .

Empty space. .

Blocks /Record. , ( , ).
1.0. 1.0 , . , .

Recordblocks. ().
.

Deleteblocks. ().

Recorddata. .

Deleted data. ( ).

Lost space. , . ( ).

Linkdata. ,
( 4 7 ). Linkdata , .

myisampack myisamchk -d .
, , 7.2.

340

4.

4.7. MySQL

4.7.1.

MySQL ISO-8859-1 (Latin 1)
/ . .
MySQL with-extra-charsets=
complex. ,
l a t i n l MySQL.

.
, ,
,
ORDER BY GROUP BY SELECT.
--default-character-set
.
configure: with-charset=na6op -with-extra-charsets=cnncofc-Ha6opoB | complex
I a l l I none ,
0_00_030/charsets/Index. . 2.3.2.

MySQL 4.1.1, default-collation.


. ( SHOW COLLATION
.) . 2.3.2.
MySQL, . myisamchk -r -q setcharacter-set=Ha6op , .
MySQL ,
. .
SQL-
mysql_real_escape_string().
mysql_escape_string(), MySQL,
.
, ,
, , , MySQL, MySQL, , , , .

4.7. MySQL

341

character-sets-dir, , MySQL. ,
:
[client]
character-sets-dir=/usr/local/mysql/share/mysql/charsets
-
:
[client]
default-character-set=Ha6op
.

4.7.1.1.
,
mysqld default-characterset=latinl_de.
:
, , :
->
->
->
-> ss

. .
LIKE
. .
, U, , 0, , .

4.7.2.
mysqld ,
: , , , , , , , , ,
, , , , , , , , , .

mysqld, language -L.
, ,
:
shell> mysqld language=swedish

:
shell> mysqld language=/usr/local/share/swedish
.
( ) share/
MySQL.

342

4.

,
errmsg. txt, errmsg. sys :
shell> comp_err errmsg.txt errmsg.sys
MySQL errmsg.txt.

4.7.3.
* MySQL
. , MySQL.
, , , :
,
, ,
.
, ( )
, .
, l a t i n l danish - , big5
czech - .
MYSET.
,
.
1. MYSET sql/share/charsets/Index
.
2. sql/share/charsets/MYSET.conf. (
sql/share/charsets/latinl. conf.)
:
' # ' .
.


.
ctype - 257 . to_lower[],
to__upper [ ] sort_order [ ], 256 .
. 4.7.4.

3. CHARSETS_AVAILABLE
COMPILED_CHARSETS conf igure. in.
4. , .
:
1. strings/ctype-MySET. MySQL.
2. MYSET sql/share/charsets/Index
.

4.7. MySQL

343

3. ctype-*.c (, strings/
ctype-big5. ) , . , : ctype_MYST, t o_l we r J4YSET . . . 4.7.4.
4. - , :
/*
* configure
* ctype.c, ,
* , .
* .configure, number_MYSET=MYNUMBER
* .configure. strxfrm_multiply_Mir5ET=N
* .configure. mbmaxlen_MYSET=N
*/
configure
MySQL.
strxfrmjnultiply mbmaxlen . .
5. :
my_strncoll_MYST()
my_strcoll_MYSr()
my_strxfim_MYSET()
my_like_range_MYST()
. 4.7.5.
6. CHARSETS_AVAILABLE
COMPILED_CHARSETS configure.in.
7. , .
8. sql/share/charsets/README .

,
MySQL, MySQL internals. .
1.7.1.1.

4.7.4.
to_lower [ ] to_upper [ ]
, , :
to_lower [' 1 ] ' '
to_upper [' ' ] ' '
s o r t o r d e r [ ] , ,
. (
) sort_order[] to_upper[],
. MySQL

344

4.

, s o r t o r d e r [ ].
4.7.5.
type [ ] - , . ( , to_lower[], to_upper[] sort_order[]
, a ctype[] - 1.
, EOF).
mctype .h :
#define U 01
#define L 02
#define N 04
#define _S 010
Idefine _P 020
#define 040
#define 0100
#define X 0200

/*
/*
/*
/*
/*
/*
/*
/*

*/
*/
*/
*/
*/
*/
*/
*/

type [ ] , . , '' , (_), ctype['A'+l]


:
_U + _ = 01 + 0200 = 0201

4.7.5.
, sort_order [ ], .
. . big5, czech, gbk, s j i s tisl60.
, , strxfrm_multiply _MYSET=N. N ,
, my_strxfrm_MYSET
( ).

4.7.6.
,
, .
. . euc_kr, gb2312, gbk, sjis
u j is. ctype-' '. strings.
, , mbmaxlen_MYSET=N. N , ( ) .

4.7.7.
, , :

345

4.8. MySQL

, ( /usr/local/mysql/share/
mysql/charsets). , characters e t s - d i r .

,
.
, .

, .
MySQL.

, :
ERROR 1105: File '/usr/local/share/mysql/charsets/?.conf
(Errcode: 2)

not found

Index,
.
My ISAM myisamchk -dvv _.

4.8. MySQL
MySQL ,
, mysqld (. 4.9):
4.9. MySQL

, , .

ISAM

ISAM .
isam.

,
. .

, . .

,
, long_query_time, ,
, .

mysqld. mysqld
( -
) FLUSH LOGS mysqladmin
f l u s h - l o g s mysqladmin r e f r e s h .

346

4.

MySQL , ,
.
5.

4.8.1.
, , , .
mysqld_saf e , mysqld_safe .
mysqld , , .

, .
, .
MySQL 4.0.10, log-error [=_]
, mysqld . _ , mysqld _. err
. ( MySQL 4.0.10 Windows mysql.err.) FLUSH LOGS -old, a mysqld .
MySQL, Unix, mysqld_safe, _.. , mysqld_safe
1=_.
log-error ( Windows) console,
stderr ( ).
Windows .err,
console.

4.8.2.
, mysqld,
1 [=_] -1 [_]. (
_, _. log).
. ,
,
mysqld.
mysql.server ( MySQL 3.23.4 MySQL
3.23.8) safe_mysqld log, . MySQL
, log mysql.server
--log-bin. . 4.8.4.
mysqld , . , -

4.8. MySQL

347

.
, , , ,
.

( FLUSH LOG ). Unix , :
shell> mv __.log ^-old.log

shell> mysqladmin flush-logs

shell> cp _-old.log --
shell> rm _-old.log
Windows , , .
, ,
.

4.8.3.
|

I I . .
|; 4.8.4. ( {I ), . , MySQL 5.O.O.

log-update [=_] mysqld


, SQL-, . _ , .
^ , ,
. _ , mysqld
_.###, ### ,

(FLUSH LOGS, mysqladmin flush-logs mysqladmin refresh).
I

,
, , .

,
, .
, UPDATE DELETE, WHERE , .
UPDATE, .
, . .

(,
_ . # # # ) :
shell> Is - I - t - _.[0-9]* | xargs cat | mysql
Is .

348

4.

,
, ,
.

4.8.4.
, , MySQL 5.O.
.
, , , . , UPDATE DELETE,
WHERE , . UPDATE,
.
, , .
, , .
(,
, ),
. . 4.8.2.
- ,
, ,
, .
, . . 5.

1%.
, .
--log-bin [=_] mysqld
, SQL-, . _ ,
-bin . _ , ,
.
(, log-bin=
_. ), .
mysqld ,
.
(FLUSH LOGS, mysqladmin flush-logs
mysqladmin refresh). ,
, max__binlog_size.
, m a x b i n l o g s i z e :

.

4.8. MySQL

349

, , mysqld , . ,
, , ' .index 1 . log-bin-index= [_].
mysqld .
RESET MASTER,
- PURGE MASTER LOGS.
,
( ,
):
binlog-do-6=__. , ( , USE) __. , , . , .
, , . , binlog-do-db=sales
USE prices; UPDATE sales.January SET amount=amount+1000;

.
1-1-6=__.
, ( , USE) __.
,
.
, , . ,
binlog-ignore-db=sales
USE prices; UPDATE sales.January SET amount=amount+1000;
.

, , .
,
, :
1. 11-^=_/_

, .

, .

2. (binlog-do-db= __ binlog-ignore6=__) . ( - USE?)?


, .

, .

350

4.

3. . - binlog-do-db?

, ,
binlog-do-db?
, .
, .

, .

4. binlog-ignore-db . , ?
, .
, .
, , binlog-do-db=sales,
, ,
sales ( , binlog-do-db " ").
, ,
. -
mysqladmin flush-logs , ,
. , - PURGE MASTER LOGS, ( , MySQL 4.1,
).
SUPER , SET SQL__LOG_BIN=0.

mysqlbinlog. . , MySQL
:
shell> mysqlbinlog - | mysql -h ^
mysqlbinlog , , 7.5.
, MySQL.

, . , .
. BDB InnoDB, (
UPDATE, DELETE INSERT )
, COMMIT. ,
COMMIT, mysqld .
, ,
binlog_cache_size. -

4.8. MySQL

351

, . .
max__binlog_cache_size (
4 ) ,
. max_binlog_cache_size , .
, ,
CREATE.. .SELECT INSERT.. .SELECT,
. , .
3.23, 4.0 5.0.0 .
. 4.0 4.1 . . 5.5.

48.5.
log-slow-queries[=_] mysqld , SQL-,
, longquerytime .
.
_ , -slow.log. ,
, .
,
, , .
, .
,
, , , .

. mysqldumpslow,
.
log-longformat, , , . .
4.2.1.

4.8.6.
MySQL , , , (. 4.8). , .
MySQL, , ,
MySQL . .
4.6.1.
Linux (Red Hat) mysql-log-rotate.
MySQL RPM,

352

4.

. ,
! ( , , .)

, .
mysqladmin flush-logs SQL- FLUSH LOGS. MySQL 3.21
mysqladmin refresh.
:
(log)
(log-slow-queries), (mysql.log _-slow.log no
) .
(--log-update) (log-bin), , - .
,
, , . , :
shell> cd --mysql
shell> mv mysql.log mysql.old
shell> mysqladmin flush-logs
mysql. old.

49. MySQL


mysqld . ,
MySQL,
.
mysqld, .
(, Internet MySQL .)
, ,
, . . 3.3.
, , :
=_
port TCP/IP-.
socket=path
socket Unix Unix, Windows - . Windows
, .

4.9. MySQL

353

shared-memory-base-name=HM#
Windows.
, Windows . MySQL 4.1.

pid-file=nyTb

Unix. ,
.
,
:

log=
1-=

log-update=nyTb

1-=

log-isam=nyTb

bdb-logdir=nyTb

, , 4.8.6.
, -
, :
tmpdir=
bdb-tmpdi=
, ;
, MySQL .
, ,
datadir=.
!

!;<

,
! , ! ( )
;
, |;-, I
. .

,
(NFS). MySQL - !
,
, ,
.
-
.
lockd, , 100% , .

354

4.

, ( )
.
, .
MySQL ,
--basedir=nyTb ,
PID-, . (
.)
socket port. , ,
MySQL tar.
, ( ) bin/mysqldsafe .
mysqld_safe mysqld
basedir; mysqld_safe socket port. (
MySQL, 4.0, mysqld_safe safejnysqld.)
,
. ,
, ,
.

4.9.1. Windows
Windows , . Windows NT
Windows.
MySQL
2.2.1. , ,
,
, , , . 4.9.
4.9.1.1. Windows
,
. , , . , defaults-file
.
, mysqld 3307
C:\mydatal mysqld-max 3308 C:\mydata2 (
, ,
mysql, ).
. , C:\my-optsl.cnf, :

4.9. MySQL

355

[mysqld]
datadir = C:/mydatal
port = 3307
: \my-opts2. cnf:
[mysqld]
datadir = C:/mydata2
port = 3308
, :
:\> C:\mysql\bin\mysqld ~defaults-file=C:\my-optsl.cnf
:\> :\mysql\bin\mysqld-max defaults-file=C:\my-opts2.cnf
NT (
),
.
,
:
:\> C:\mysql\bin\mysqladmin port=3307 shutdown
:\> C:\mysql\bin\mysqladmin port=3308 shutdown
, , TCP/IP. Windows ,
mysqld-nt mysqld-max-nt,
,
. , , . , C:\my-optsl.cnf :
[mysqld]
datadir = C:/mydatal
port = 3307
enable-named-pipe
socket = mypipel
, :
:\> :\mysql\bin\mysqld-nt defaults-file=C:\my-optsl.cnf
:\my-opts2.cnf,
.
4.9.1.2. Windows
Windows NT MySQL
Windows. , MySQL 2.2.1.7.
MySQL 4.0.2, .
, .
,
mysqld-nt MySQL,

4.

356

: \mysql-4.0.8 : \mysql-4.0.17 . ( ,
4.0.8, 4.0.17, .)
, MySQL
i n s t a l l install-manual:
, MySQL [mysqld] .
i n s t a l l ,
[mysqld]
, . .
default-file,
[mysqld] .
& !
"X
|;
%,
$
U

||
|jf
$

MySQL, 4.0.17, ,
MySQL ( , ), , mysqld,
[mysqld] . MySQL 4.0.17, ,
, [mysqld], . [mysqld] ,
MySQL, , - , .

, , MySQL .
.
, ,
MySQL .
1. .
. , mysqld-nt 4.0.8,
mysqldl, mysqld-nt 4.0.17,
mysqld2. 4.0.8 [mysqldl ], 4.0.17 - [mysqld2 ]. , : \my. cnf :
# mysqldl
[mysqldl]
basedir = C:/mysql-4.0.8
port = 3307
enable-named-pipe
socket = mypipel
# mysqld2
[mysqld2]
basedir = C:/mysql-4.0.17
port = 3308
enable-named-pipe
socket = mypipe2

4.9. MySQL

357

, , ;
, Windows :
:\> C:\mysql-4.0.8\bin\mysqld-nt install mysqldl
:\> C:\mysql-4.0.17\bin\mysqld-nt install mysqld2
, NET START
:
:\> NET START mysqldl
:\> NET START mysqld2
, NET
STOP :
:\> NET STOP mysqldl
:\> NET STOP mysqld2
2. , , defaults-file, , . [mysqld] .
, mysqld-nt 4.0.8,
: \myoptsl. cnf, :
[mysqld]
basedir = :/mysql-4.0.8
port = 3307
enable-named-pipe
socket = mypipel
mysqld-nt 4.0.17 C:\my-opts2.cnf,
:
[mysqld]
basedir = :/mysql-4..17
port = 3308
enable-named-pipe
socket = mypipe2
( ):
:\> C:\mysql-4.0.8\bin\mysqld-nt install mysqldl
defaults-file=C:\my-optsl.cnf
C:\> C:\mysql-4.0.17\bin\mysqld-nt install mysqld2
defaults-file=C:\my-opts2.cnf
MySQL ,
--defaults-file, .
, MySQL ,
, .
MySQL, mysqld
remove, remove . MySQL ( ,
), .

358

4.

4.9.2. Unix
Unix -
TCP/IP- Unix,
.
MySQL , , PID- .
, TCP/IP- (3306) Unix (/tmp/mysql.sock).
configure, :
shell> ./configure with-tcp-por=_ \
with-unix-socket-pa=_ \
prefix=/usr/local/mysql-4.0.17
_ _ TCP/IP- Unix, prefix
, ,
MySQL.
, ,
, , , Unix:
shell> mysqladmin hos=_ =_ variables
, .
, local host, mysqladmin no
Unix, TCP/IP. MySQL
4.1 , , --protocol^TCP I SOCKET j PIPE | MEMORY}.
He , Unix TCP/IP.
. -
:
shell> mysqld_safe socke=__ =_
socket port
mysqld_safe datadir=nyTb,
.
- Unix TCP/IP :
shell> MYSQL_UNIX_PORT=/tmp/mysqld-new. sock
shell> MYSQL_TCP_PORT=3307
shell> export MYSQLJJNIXJ>ORT MYSQLJTCPJPORT
shell> mysqlJLnstall^db user=mysql
shell> mysqld_safe datadir=///_ &
, . , -

4.9. MySQL

359

,
. , !
, mysqld.
,
, , :
mysqld_safe defaults-file=nyrb

.
Unix mysqldjnulti. . 4.1.5.

4.9.3.

MySQL, , , ,
:
ho8=_ t=HOMep_nopTa, TCP/IP , host=127.0.0.1
=_, TCP/IP ,
host=localhost s=_, Unix Windows.
MySQL 4, protocol=tcp,
TCP/IP, --protocol=socket, Unix, protocol=memory, . TCP/IP- --host port. socket,
Unix , shared-memory-base-name,
. Windows.
Unix, ,
MYSQL_UNIX_PORT MYSQL_TCP_PORT, Unix TCP/IP. -
, , , . login, .
. .
Unix TCP/IP
[client] . , : \my.cnf
Windows .my.cnf Unix. . 3.3.2.

4.

360


mysql_real_connect ().
, mysql_options ().

Perl DBD::mysql
MySQL. :
$dsn =

"DBI:mysql:test;mysql_read_default_group=client;"
.
"mysql_read_default_file=/usr/local/raysql/data/my.cnf';
$dbh = DBI->connect($dsn, $user, $password);
, .

410. MySQL
4.0.1, MySQL .
SELECT ,
. ,
, , .
, () . Web-, , .
. !
: .
!/ , , .

; , mysqld
;1 .

.
MySQL Linux
Alpha 2 500 2 64 .
, , ,
13%. . , .

238%
. , ,
.

, q u e r y c a c h e s i z e 0.
. , MySQL configure without-query-cache.

4.10. MySQL

361

4.10.1.
, , ,
4.10.3 - .
, :
SELECT * FROM _
S e l e c t * from _

, ( ). , , ,
- . ,
, .

Qcache_hits, Com_select. . 4.10.4.
, ,
, . (
, MERGE,
.) ,
INSERT, UPDATE, DELETE, TRUNCATE, ALTER TABLE, DROP TABLE DROP DATABASE.

innoDB
COMMIT.
MySQL 4.0 (
). MySQL 4.1.1,
InnoDB (
, , - ).
MySQL, 5.0, , , , . MySQL 5.0 .
SELECT SQL_CALC_FOUND_ROWS. . . SELECT FOUND_ROWS().
FOUND_ROWS () , , .
,
:
BENCHMARK()

CONNECTION_ID()

CURRENT_DATE()

CURRENT_TIME()

CURDATE()

CURT IME ()

DATABASE ()

ENCRYPT () ( )

FOUND_ROWS()

GET_LOCK()

LAST_INSERT_ID()

LOAD_FILE()

MASTER_POS_WAIT()

NOW ()

RANDO

RELEASE_LOCK()

SYSDATE()

UNIX_TIMESTAMP () ( )

USER ()

CURRENT_TIMESTAMP()

:
(UDF).
.
mysql.

362

4.

:
SELECT
SELECT
SELECT
SELECT

. . . IN SHARE MODE
. . . INTO OUTFILE . . .
. . . INTO DUMPFILE . . .
* FROM . . . WHERE _increment

IS NULL

,
ODBC .

TEMPORARY.

.
.
, MySQL ,
SELECT
, , .

4.10.2. SELECT
, , SELECT:

SQL_CACHE. , query_cache_type ON DEMAND.


SQL_NO_CACHE. .

:
SELECT SQL_CACHE id, name FROM customer;
SELECT SQL_NO_CACHE id, name FROM customer;

4.10.3.
have_query_cache , :
f

mysql> SHOW VARIABLES LIKE 'have_query_cache ;


+
+
+
| Variable_name
| Value |
I have_query_cache

| YES

.
mysqld. , , query_cache_.
4.2.3, .
query_cache_size.
0, .
0, .
, query_cache_size
. :

4.10. MySQL

363

0 OFF ("") -
.

1 ON ("") - ,
SELECT SQL_NO_CACHE.

2 DEMAND (" ") - , SELECT SQL_CACHE.

GLOBAL query_cache_type
, , .
, SESSION query_cache_type. ,
:
mysql> SET SESSION query_cache_type = OFF;


, query_cache_limit.
1 .
(, )
.
. , , , . ( ), , query__cache_min_res_unit. , ,
, . , query_cache_min_res_unit:
query_cache_min_res_unit 4
.
,
,
. ,
, ()
. query_cache_min_res_unit. ,

Qcache_free_blocks Qcache_lowmem_prunes.
( Qcache_total_blocks Qcache_queries_cache), , query_cache_min_res_unit.
, (.
).

4.10.4.
MySQL :

364

4.

mysql> SHOW VARIABLES LIKE ' h a v e _ q u e r y _ c a c h e ' ;


+
+
+

I Variable_name
+
I have_query_cache

I Value
+
I YES

I
+
|

FLUSH QUERY CACHE


.
. RESET QUERY CACHE
. FLUSH TABLES.
SHOW
STATUS, :
mysql> SHOW STATUS LIKE l Qcache% ! ;
I Variable_name
I Value I
+
+
+
I Qcache_free_blocks
I 36
|
I Qcache_free_memory
I 138488 |
I Qcachejiits
I 79570 |
I Qcache_inserts
I 27087 |
I Qcache_lowmem_prunes
I 3114
|
I Qcache_not_cached
I 22989 |
i Qcache_queries_in_cache
| 415
|
I Qcache_total_blocks
I 912
|
+
+
+
4.2.4. .
SELECT :
Com_select
+ Qcache_hits
+ ,

Com_select :
Qcache_inserts
+ Qcache_not_cached
+ , /
, Qcache_total_blocks
Qcache_free_blocks . FLUSH QUERY CACHE .
(
, ).
. , .
, Qcache_lowmem_prunes,
. ,
. (least recently used - LRU). 4.10.3.

MySQL

MySQL , MySQL 3.23.15. , MySQL.


, ,
, .
( ) .
SQL, , MySQL. .
http://www.mysql.com . , .

5.1.
MySQL 3.23.15 . , (master), - , (slave).
. , . ,
,
. ,
,
.
, .
, , ,
, . , , ,
.
, :

366

5. MySQL
/ .
, , .

. SELECT
, . , , -
, . , , .
,
, .
, . . 4.6.1.

5.2.
MySQL , (, ) . ,
, (. 4.8.4).
, ; ,
.
, - , , . , , , .
, ,
, .
LOAD DATA FROM MASTER. , LOAD DATA FROM
MASTER , MySQL 4.0.0, ,
My ISAM. ,
, . , , ( MySQL 5.0),
.
- ,
LOAD DATA FROM MASTER , ,
. LOAD DATA FROM MASTER ,
, 1 1 . , ,
- , , Pentium 700 , 100 /.

5.3.

367

, ,
, . , , , , .
master-connect-retry. 60 .
, .
, ,
.

5.3.
MySQL (
- ). START SLAVE -. , . .
Binlog Dump SHOW
PROCESSLIST . - , Binlog
Dump, , (relay logs). - SQL, .
, . , ,
,
, , - SQL.
MySQL, 4.0.2, ( - - ). , - SQL-, ,
.
,
. , . , , -
, SQL , , .
, SQL , , - ,
, .
,
, .
SHOW PROCESSLIST , , , .
, SHOW PROCESSLIST.
SHOW PROCESSLIST MySQL

368

5. MySQL

4.0.15, State , ,
.
SHOW PROCESSLIST :
mysql> SHOW PROCESSLIST\G
***************************
Id: 2

2. row ***************************

User:
Host:
db:
Command:
Time:
State:

root
localhost:32931
NULL
Binlog Dump
94
Has sent all binlog to slave; waiting for binlog to
be updated
Info: NULL

2 - , . , ,
.
SHOW PROCESSLIST , :
mysql> SHOW PROCESSLIST\G
*************************** 2. row ***************************
Id: 10
User: system user
Host:
db: NULL
Command: Connect
Time: 11
State: Waiting for master to send event
Info: NULL
Id:
User:
Host:
db:
Command:
Time:
State:

11
system user

NULL
Connect
11
Has read all relay log; waiting for the slave I/O
thread to update it
Info: NULL

, 10 - , , 11 SQL, , .
, .
, Time , . . 5.9.

5.3.

369

5.3.1.
Binlog Dump
, State.
- Binlog Dump , , . .

Sending binlog event to slave ( ).


; -
, .
.

Finished reading one binlog; switching to next binlog (


; ).

, .
Has sent a l l binlog to slave; waiting for binlog to be updated ( ; ).

. , ,
, .
Waiting to finalize termination ( ).
, .

5.3.2. /

, State / .
MySQL 4.1.1, Slave_IO_State,
SHOW SLAVE STATUS. To , , SHOW SLAVE STATUS.
Connecting to master ( ).
.
Checking master version ( ).
,
, .
Registering slave on master ( ).
.
Requesting binlog dump ( ).
, .
,
.

370

5. MySQL

Waiting to reconnect after a failed binlog dump request ( ).


(- ), , , .
master-connect-retry.
Reconnecting after a failed binlog dump request ( ).
.
Waiting for master to send event ( ).
. ,
. slave_read_timeout ,
. , .
Queueing master event to the relay log (
).
,
SQL .
Waiting to reconnect after a failed master event read ( ).
( ). master-connect-retry .
Reconnecting after a failed master event read (
).
.
, Waiting for master to send
event.
Waiting for the slave SQL thread to free enough relay log space (, SQL ).
relay_log__space_limit,
, .
- , SQL , , .
Waiting for slave mutex on exit ( ).
.

5.3.

371

5.3.3. SQL

, State SQL :

Reading event from the relay log ( ).


.
Has read a l l relay log; waiting for the slave I/O thread to update i t
( ; , -
).
, - .
Waiting for slave mutex on exit ( ).
.
State SQL . , , .

5.3.4.

-relay-bin. , _ , .

, 001.
. _-re laybin, index.
.
relay-log relay-log-lindex. . 5.8.
, , mysqlbinlog. SQL , . , SQL
. , MySQL 4.0.14, FLUSH LOGS
, SQL.
:
-
( MySQL 5.0
-, .)
, , FLUSH LOGS mysqladmin
flash-logs. (
MySQL 4.0.14.)

372

5. MySQL

.
" " :
max_relay_log_size, max_relay_log_size > 0.
max_binlog_size, max_relay_log_size = 0, MySQL, 4.0.14.
. , roaster.info
relay-log.info.
, , SHOW SLAVE
STATUS. , ,
-
.
master.info -. MySQL 4.1
, SHOW SLAVE STATUS, :

1
2
3
4

Master_Log__File
Read_Master_Log_Pos
Master_Host
Master_User

( SHOW SLAVE STATUS)

6
7

Master_Port
Connect__Retry

MySQL 4.1, SSL:

1
2
3
4
5
6
7
8
9
10
11
12
13
14


Master_Log_File
Read_Master_Log_Pos
Master_Host
MasterJJser
( SHOW SLAVE STATUS)
Master_Port
Connect_Retry
Master_SSL_Allowed
Master_SSL_CA_File
Master_SSL_CA_Path
Master_SSL_Cert
Master_SSL_Cipher
Master_SSL_Key

relay-log.info SQL.
, SHOW SLAVE STATUS,
:

5.4.

1
2
3
4

Relay_Log_File
Relay_Log_Pos
Relay_Master_Log_File
Exec_Master_Log_Pos

373

, .
. ,
relay-log.info, ,
SQL .
CHANGE MASTER MASTER_LOG_FILE MASTER_LOG_POS,
,
. ,
.
LOAD
DATA INFILE, SQL_LOAD-*,
, .
LOAD DATA
INFILE. slave-load-tmpdir.
, tmpdir.

5.4
MySQL. , ,
.
, , .
, .
, ,
. , ,
, ,
.
5.9.
MySQL,
.
,
5.8.
, SQL-, , SUPER. MySQL 4.0.2 PROCESS.
1. , MySQL , ,
5.5. , .

374

5. MySQL

2. , .
REPLICATION SLAVE.
( ),
. ,
mydomain.com,
r e p l ,
,
s l a v e p a s s . -^ ,
GRANT:
mysql> GRANT REPLICATION SLAVE ON * . *
-> TO f repl'@'%.mydomain.com 1 IDENTIFIED BY ' s l a v e p a s s 1 ;
MySQL, 4.0.2, REPLICATION SLAVE . FILE:
mysql> GRANT FILE ON * . *
-> TO 'repl'@'%.mydomain.com'

IDENTIFIED BY ' s l a v e p a s s ' ;

LOAD TABLE FROM MASTER LOAD


DATA FROM MASTER ,
:

SUPER RELOAD.

SELECT , .
,
SELECT, LOAD DATA FROM MASTER.

3. My ISAM,
, FLUSH TABLES WITH READ LOCK:
mysql> FLUSH TABLES WITH READ LOCK;
, FLUSH
TABLES, . ( , .)
.
-

. , , t a r Unix PowerArchiver, WinRAR,
WinZIP Windows. tar ,
, , :
shell> tar -cvf /tmp/mysql-snapshot.tar .
, t h i s d b , :
shell> tar -cvf /tmp/mysql-snapshot.tar ./this_db
/tmp .

:

5.4.

375

shell> tar -xvf /trap/mysql-snapshot.tar


, mysql, , ,
. .
, master.info
relay-log.info. ,
FLUSH TABLES WITH READ LOCK,
:
m y s q l > SHOW MASTER STATUS;
+
+
+
+
+
I File
I Position | Binlog_Do_DB | Binlog_Ignore_DB |
+
+
+
+
+
I mysql-bin.003 |
73
|
test
| manual,mysql |
+
+
+
+
+
File , Position - . mysql-bin.003 73.
. , . ,
, .
, ,
:
m y s q l > UNLOCK TABLES;
InnoDB,
InnoDB Hot Backup. ,
- , , , . InnoDB Hot Backup - () , MySQL.
h t t p : / /www. innodb. com/manual. php.
InnoDB Hot Backup,
InnoDB InnoDB, (.frm). , :
m y s q l > FLUSH TABLES WITH READ LOCK;
m y s q l > SHOW MASTER STATUS;
, SHOW MASTER STATUS, , . , , , :
shell> mysqladmin -u root shutdown
, MylSAM-, innoDB, SQL- -

376

5. MySQL
, . mysqldump
master-data , SQL- . , .
log-bin,
, SHOW MASTER STATUS
mysqldump, . ,
,
(")4.

4. , [mysqld] my.cnf log-bin. -1!= , __


1 2 3 2 - 1. :
[mysqld]
log-bin
server-id=l
, .
5. , ,
my. cnf :
[mysqld]
server-i 6.= __
__, __, 1
2 3 2 - 1. , , :
[mysqld]
server-id=2
,
serverid, , , , .
, IP-. .
server_id, 1,
master-host, 2 - . , ,
server_id , , . server-id .
6. ,
.
.
,
MySQL, , , .

5.4.

377

mysqldump,
(. ).
7. . , s k i p - s l a v e - s t a r t , . ,
log-warnings,
(,
).
8.
mysqldump, :
s h e l l > mysql -u r o o t -p < dump_file.sql
9. ,
:
mysql> CHANGE MASTER TO
-> MASTER_HOST=' ___',
-> MASTER_USER='__',
-> MASTER_PASSWORD='_ ' ,

-> MASTER_LOG_FILE= * ___%,


-> MASTER_LOG_POS=___;
:
MASTERJiOST 60
MASTERJJSER 16
MASTER_PASSWORD 32
MASTER_LOG_FILE 255

10. :
mysql> START SLAVE;

, .
server-id,
.
server-id, :

Warning: You should set server_id to a non-0 value if master_host is set; We


force the server id to 2, but this MySQL server will not act as a slave.
: server_id ,

master_host;
server_id 2,
MySQL .
, - .
, - m a s t e r . i n f o , - r e l a y - l o g . i n f o .
,
.
, , , -

378

5. MySQL

. CHANGE MASTER TO.


!
, master. i n f o , my. cnf (. 5.8).
, , . , .

5.5.
MySQL
MySQL 3.23.
MySQL 4.0, - MySQL 5.0. , , , 5.6.
, , MySQL 4.1.x MySQL 4.0.x , . , ,
. , MySQL 4.0.0
4.0.2 , "", . (
- 4.0. , .) . 5.1 / MySQL.
5.1. MySQL


3.23.33

4.0.3

5.0.0


3.23.33

4.0.3
4.1 .


5.0

,
MySQL, . MySQL .

5.6.
, , , .

5.6.

379

5.6.1. 4.0 4.1


MySQL 3.23 MySQL 4.0
4.1. 4.0 4.0.3,
5.5.
MySQL 3.23
4.0 4.1, , 4.0 4.1. , . , ,
.
, , MySQL
3.23, - MySQL 4.0 4.1. ,
, , , 3.23,
4.0 4.1.
1. FLUSH
TABLES WITH READ LOCK.

2. , ,
. SHOW MASTER STATUS

.
SELECT MASTER_POS_WAIT().
, . STOP
SLAVE .
3. MySQL 4.0 4.1.
4. . SHOW MASTER
STATUS .
:
mysql> CHANGE MASTER TO MASTER_LOG_FILE=' __',
->
MASTERJLOG_POS=4;
mysql> START SLAVE;

5.6.2. 5.0
MySQL 3.23, 4.0 4.1
5.0.0. MySQL 4.0 4.0.3, 5.5.
, - MySQL 5.0.0 -. , (
, , , sqljnode). .
-, .
MySQL 3.23, 4.0 4.1 5.0.0, ,

380

5. MySQL

MySQL 5.O.O. , . , ,
. 5.0.0
, , . 5.0.0.
,
5.0.0 . MySQL 5.0.0
, , MySQL 5.O.O.
. , , 5.0.0, .
, - 5.0.0, , . , , 5.0.0, .
, , , .

5.7.


. ,
InnoDB, 9.7.5.

AUTO_INCREMENT,

LAST_INSERT_ID() TIMESTAMP.

USER(), UUIDO LOAD_FILE() , .


CONNECTION_ID() 4.1.1.
PASSWORD () 4.1.1 , 4.1.1 , . ,
PASSWORD () 4.1.x,
--old-password, PASSWORD(). ( , PASSWORD() MySQL
4.1.0 MySQL. MySQL 4.1.0 .)
FOREIGNKEYCHECKS , MySQL 4.0.14. sqljnode, UNIQUE_CHECKS SQL_AUTO_IS_NULL ,
5.0.0. SQL_SELECT_LIMIT table_type .
(default-character-set)
.
, , , . 5.0.x.

5.7.

381

,
. , InnoDB MylSAM. , , BEGIN/COMMIT, BEGIN.
TODO .

, ( @_), 3.23 4.0.


4.1 . ,
, MySQL 5.0. 5.0 .

, SSL,
4.1.1 .

CREATE TABLE
DATA DIRECTORY INDEX DIRECTORY, . , , , . MySQL 4.0.15,
sqljnode NO_DIR_IN_CREATE.
SQL-, , CREATE TABLE.
My ISAM .

, ,
, ,
( , ). 1.8.7.3.

M y S Q L 4.1.1 FLUSH, ANALYZE TABLE, OPTIMIZE TABLE


REPAIR TABLE ,
. ,
. , ,
.
mysql ,
GRANT, FLUSH PRIVILEGES,
. , FLUSH
TABLES, My ISAM, MERGE, FLUSH TABLES . MySQL 4.1.1,
( NO_WRITE_TO_BINLOG LOCAL). FLUSH LOGS, FLUSH MASTER, FLUSH SLAVE FLUSH TABLES
WITH READ LOCK, . (
,
.)

382

5. MySQL

MySQL .

, - . "",
SELECT .
, MEMORY (HEAP) . MySQL 4.0.18,
: ,
MEMORY , ,
, DELETE FROM
. 8.3.
, ( ), , , . , ,
, .
, ,
. :
1. STOP SLAVE.
2. SHOW STATUS lave_open_temp_tables.
3. 0, mysqladmin shutdown .
4. 0,
START SLAVE.
5. , .
.
/
--log-slave-updates. , ,
, , , -
.
, :
->

->

->

,
, , , ,
. .
,
. ,
, , ,
, .
, .

5.7.

383

, , , SQL .
, (, ) START SLAVE.
.
,
. ,
( - 60 ; master-connect-retry). . ,
slave_net_timeout . ,
slave_net_timeout (. 4.2.3).
() , , .
, , ,
. , .
- My ISAM
, .
, , ,
,
, .
, ,
, , . , , ,
()
slave-skip-errors. MySQL 3.23.47.
BEGIN/COMMIT, , -
. , .
4.0.15
, COMMIT, ,
ROLLBACK. ,
, (
, , ). 4.0.15 ,
, ( , ROLLBACK). ,

384

5. MySQL
, , , , ,
.

MySQL 3.23, MySQL 4.O.

LOAD DATA INFILE , .

LOAD DATA LOCAL INFILE ,


3.23.

3.23 RANDO
. RAND {__), RAND (). , RAND ()
UNIX_TIMESTAMP ().

5.8.
, server-id
.
1 2 3 2 - 1, , server-id=3.
,
, 4.8.4.
, . .

, , , master.info, . :
master-host
master-user
master-password
master-port
master-connect-retry
MySQL 4.1.1, :
master-ssl
master-ssl-ca
master-ssl-capath
master-ssl-cert
master-ssl-cipher
master-ssl-key
master.info MySQL 4.1.1 , ,
SSL. , ,

5.8.

385

.
4.1.1, master.info
. 4.1.1 ,
.
, SSL- .
master.info ,
, . , , ,
RESET SLAVE, .
master.info , . , master. info.
,
master.info, , master.info.
, , master.info,
( ) CHANGE MASTER TO .
, my. cnf:
[mysqld]
master-host=HeKOTopNH_xocT

, ,
my.cnf.
master.info. master. info , .
my.cnf,
_, .
CHANGE MASTER TO.
master.info , , ,
CHANGE MASTER TO.

:
[mysqld]
server-id=2
master-host=db-master.mycompany.com
master-port=3306
master-user=pertinax
master-password=freitag
master-connect-retry=60
report-host=db-slave.mycompany.com
.
CHANGE

386

5. MySQL

MASTER TO. , replicate-*,


. .

log-slave-updates. ,
, . , , SQL ,
. , bin-log,
. log-slave-updates , , , :
-> ->

, .
, , .
, --bin-log, , log-slave-updates.

log-warnings.
, . , , , . . .

--master-connect-retry=ceKyjwi. ,

. , master.info, , . ,
60 .

master-host=xocT. IP- .
, .
, master. info, , .

master-info-f =_. , . - mysql.info,


.

master-password=napcitfb. ,
.
, master. info, , .
, .

master-port=HOMep_nopTa. TCP/IP,
. , master.info, , . , . configure
, 3306.
master-ssl
master-ssl-capath=_aaoa
master-ssl-cert=H^3^aj^7a
master-ssl-cipher=cnHCOK_iuH$poB

5.8.

387

SSL. , --ssl,
ssl-ca, ssl-capath, ssl-cert, ssl-cipher ssl-key,
4.5.8.5. , master.info, , . , MySQL 4.1.1.
1-=_. , . REPLICATION SLAVE. ( MySQL 4.0.2 FILE.) ,
master .info, , . , test.
max-relay-log-size=#.
(. 4.2.3). , MySQL 4.0.14.
read-only. - , ,
SUPER. , ,
. , MySQL 4.0.14.
1-1=_. .
_-1-., _ - , , . , , ;
( max_relay_log_size), , ;
.
1-1-11=_.
. - _-1-. index,
_ - .
relay-log-inf-1=_. ,
. relaylog, info, .
relay-log-purge={0 11}. , . - 1 (). , SET GLOBAL relay_log_purge.
, MySQL 4.1.1.
--relay-log-space-limit=#.
( 0 " "). ,
. , - ,
SQL -

388

5. MySQL
. , .
, SQL ,
. -
, SQL . ,
( MySQL, 4.0.13). relay-log-space-limit
, max-relay-log-size ( max-bin-log-size,
--max-relay-log-size 0). ,
- ,
relay-log-space-limit , SQL , ,
-. -
relay-log-space-limit.

-<1-=__.
, ( USE) ___. , . , ,
UPDATE __. SET foo='bar 1 ,
, . , , , MySQL 3.23.28 ,
replicate-wild-do-table=HM#_6a3b/^aHHbfx.%. , .
, , : replicate-do-db=sales,
, UPDATE :
USE prices;
UPDATE sales.January SET amount=amount+1000;
, ,
replicate-wild-do-table=HM#_6a3bf^aHHb/x.%.
, , . (, DELETE, UPDATE, ). , .

replicate-do-=__. _.
. , , . ,
replicate-do-db. , .

replicate-ignore-db=HM#_6a3H_4aHHb/x.
,
___. , , .

5.8.

389

,
, . , .
, , : replicate-ignore-db=sales, , UPDATE :
USE prices;
UPDATE sales.January SET amount=amount+1000;
, ,
replicate-wild-ignore-table=HM#_6a3H^aHHHx. %.

explicate--1=__._. ,
( ).
, , , .
,
--replicate-ignore-db. ,
.
replicate-wild-do-table=HM#_6a3b/^aHHHx. _
,
,
. '%' '_',
, LIKE. , , . .
, .
: replicate-wild-do-table=foo% .bar% , , bar,
, f .
'%',
(CREATE DATABASE, DROP DATABASE
ALTER DATABASE). , replicate-wild-do-table=
f 00%. %, , f %.

. , my_own%db, mylownAABCdb, : replicate-wild-do-table=my\__own\%db.
, ,
. , bash :
replicate-wild-do~table=my\\_own\\%db.

replicate-wild-ignore-table=_a_ax._a^. ,
.

390

5. MySQL
,
, . . ,
.
: --replicate-wild-ignore-table=foo%.bar% , , bar,
, f oo.
,
replicatewild-ignore-table. , replicate-wild-ignore-table.

replicate~rewrite-db=HM#_H3->HM#_B.
( USE) _, __.
, ( CREATE DATABASE, DROP
DATABASE ALTER DATABASE), _ . .
, ,
replicate-*.
, '>' , , :
shell> mysqld ~replicate-rewrite-db= lt capa->oa

report-host=xocT. IP- , .
SHOW SLAVE HOSTS . , , .
, IP- TCP/IP . - (NAT) , ,
IP-
.
, MySQL 4.O.O.

report-port=HOMep_nopTa. TCP/IP , . , ,
- . , .
, MySQL 4.O.O.

skip-slave-start. , . , START SLAVE.

slave_compressed_protocol={0,1}. I, , .

5.8.

391

slave-load-tmpdir=HMH^a^a. ,
. , tmpdir. SQL
LOAD DATA INFILE, ,
, , . , , , . , ,
, . relay-log,
, .
--slave-load-tmpdir , . LOAD DATA INFILE, . .

slave-net-timeout=ceKyH^ , , - . -.
--master-connect-retry.

slave-skip-errors= [_1,_2,... | a l l ] . , ,
. SQL ,
.
, . , MySQL, , ,
. ,
, .
, SHOW SLAVE
STATUS.

( ) a l l , , , . , , . ,
, . , .
:
slave-skip-errors=1062,1053
slave-skip-errors=all

392

5. MySQL

replicate-* , , :
1. - replicate-do-db replicate-ignore-db?
. binlog-do-db binlog-ignore-db (. 4.8.4).
?
. .
. , , .
. .
2. - --replicate-*-table?
. .
. . , , (INSERT INTO sales SELECT * FROM prices:
sales ).
( ), ( "do" "ignore") . ,
. , ,
.
3. - replicate-do-table?
. ?
. .
. .
. .
4. - replicate-ignore-table?
. ?
. .
. .
. .
5. - replicate-wild-do-table?
. ?
. .
. .
. .
6. - -replicate-wild-ignore-table?
. ?
. .
. .
. .
7. replicate-* . ,
?

5.9.

393

. .
. , , . --replicate-do-table replicatewild-do-table?
. .
. .

5.9.
. , , ?
. .
- ( SHOW MASTER STATUS),
, :
1. , .
2. ,
:
m y s q l > CHANGE MASTER TO
->
MASTER_HOST='
___',
->
MASTER_USER=' __*,
->
MASTER_PASSWORD=% _
',
->
MASTER_LOG_FILE=' ___',
->
MASTERJL0G_P0S=no3Han#_B_3a ^ ;
3. START SLAVE .
,
. .
1. :
m y s q l > FLUSH TABLES WITH READ LOCK;
2. He , ( ):
shell> tar zcf /tmp/backup.tar.gz /var/lib/mysql
3. ,
:
mysql> SHOW MASTER STATUS;
4. :
m y s q l > UNLOCK TABLES;
SQL-
, . , mysqldump master-date . , .
, , , ,
. -

394

5. MySQL

. ,
,
. ,
- ,
, .
LOAD DATA FROM MASTER. ,
. LOAD DATA FROM MASTER
. , ,
My ISAM . , .
,
FLUSH TABLES WITH READ LOCK.

. ?
. .
, . , / ,
. ,
, - .
, .
. ,
? , ?
. 4.1.1 , Seconds_Behind_Master SHOW SLAVE STATUS. . , SHOW
PROCESSLIST , SQL (,
MySQL 3.23, ), , . . 5.3.
SQL , ,
( TIMESTAMP
). Time SHOW PROCESSLIST ,
SQL, .
. ,
, , 3600 Time SHOW PROCESSLIST. , , .
. , ?
. :

5.9.

395

1. :
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS;

, SHOW. - .
2. ,
MASTER_POS_WAIT() ,
:
mysql> SELECT MASTER_POS_WAIT('_', );
SELECT , .
, SELECT .
3. ,
:
mysql> UNLOCK TABLES;

. ?
. MySQL
, () . ,
1, ,
2,
2, , 1. ,
2, , , 1, , 2 . ,
, , , -
.
, , ( ),
. ,
.
, , , , . .
.
?
. . , , ,
.
skip-innodb, skip-bdb, low-priority-updates delay-key-write=ALL,
.

396

5. MySQL

MylSAM InnoDB
BDB, .
. , , ?
. , , ,
. ,
, -
, . , .
, :
safe_writer_connect()
safe_reader_connect()
safe_reader_statement()
safe_writer_statement()
saf _ , . . , , . .
, . , ,
, "/",
.
, . , , ,
, .
, , replace,
MySQL, , .
. , , ,
, , .
. MySQL ?
. MySQL
. , , ,
, , ,
, .
,
, , , ,

5.9.

397

( , maxjreads) (max_writes)
. , .
, 10% 90% ,
, max_reads 1200 - 2 * max__writes.
, 1200 ,
, , . , ,
N .
( ):
reads = 1200 - 2 * writes
reads = 9 * writes / (N + 1) ( , )
9 * writes / (AT + 1) + 2 * writes = 1200
writes = 1200 / (2 + 9/(tf + 1))
, N 1200 9
.
:
N = 0 ( , ),
1200 /11 = 109 .
N = 1, 184 .
N=8, 400 .
N=11, 480 .
, N ( -
), 600 , 5,5 .
4 .
, ,
. , , , , N . , :
?
, ?
?
. ?
. ( ), ,

398

5. MySQL

, .
, . .

,
CHANGE MASTER TO.

- DNS. bind
nsupdate DNS.

log-bin
--log-slave-updates. , STOP SLAVE, RESET
MASTER CHANGE MASTER TO . , , :

WC
\
v
WC

>

/ I \
I \
v
v
v
SI S2
S3
(master) , S - (slave) , WC - , . ,
, ,
.
/

S I , S2 S3 - , l o g - b i n l o g - s l a v e - u p d a t e s . , , ,
l o g - s l a v e - u p d a t e s ,
. - , . ,
S1. WC S I , a S2 S3 S1.
, , .
STOP SLAVE IO_THREAD, SHOW PROCESSLIST
, "Has read a l l r e l a y l o g s " ("
"). ,
. S1,
, , STOP SLAVE RESET
MASTER.
- S2 S3 - STOP SLAVE CHANGE
MASTER TO MASTER_HOST='S1' ( f S l ' S1).
, , S1
S2 S3 ( , , ). CHANGE MASTER S1 . , -

5.10.

399

4,
CHANGE MASTER. , , START SLAVE S2 S3.
WC, S1.
, WC S1,
S1,
, S1 .
:
WC

WC

/
I
| ()

\I
\ I
VV

SK--S2 S3

, CHANGE MASTER, , S2 S3, ,


S1 ,
. , (, , ),
, S1 ,
. RESET MASTER , S1,
S2 S3, . WC .

MySQL, ,
.

5.10.

, ,
:
. , .
?
SHOW MASTER STATUS. , Position
. , ,
log-bin server-id.
? SHOW SLAVE STATUS
, Slave_IO_Running Slave_SQL_Running
Yes. , ,
.
, ?
SHOW PROCESSLIST, -

400

5. MySQL

SQL State. . 5.3.


State - Connecting to master (
),
, , DNS, .
, ,
, , ,
. , , . , , , , , 5.7. , 5.11
, .
, , , (
, ), :
1. , . , . ,
, START SLAVE.
2. , ,
( ),
.
3. , , :
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ;
raysql> START SLAVE;
1,
AUTO_INCREMENT LAST_INSERT_ID().
2. 2 ,
AUTO_INCREMENT LAST_INSERT_ID ( ) , ,

.
4. , , , , , , . , .
MySQL, .

5.11.
, ,
, , ,
. , -

5.11.

401

. ,
.
, , http://bugs.mysql.com/.
( ),
:
1. , . ,
, , , .
, , ,
. . , .
2. log-slave-updates log-bin.
, ,
.
3. .
, , ,
.
, :
.
.
SHOW MASTER STATUS , .
SHOW SLAVE STATUS , .
.
4. mysqlbinlog . , :
shell> mysqlbinlog -j no3nu,MR_B_slave_status \
///__1_ | head
,
.
h t t p : //bugs .mysql. com/, .

MySQL

- ,
, . , , , ,
.
MySQL . , ,
,
.

6.1.
-
. , , .
:
. ,
- .
10 , 100
. ,
.
.
. ,
.
, , 10-20
. , , .
.
( ), , - . , - .
.

6.1.

403

.
, ,
.
, , .

6.1.1. MySQL
My ISAM MySQL , . , .
, (. 8).
MySQL , . (
, - ), MySQL :
.
"" ,
, MySQL "
" , . 0, , .
- , , .
, ,
. , 1/0 NULL.
, MySQL
. , .

6.1.2.
SQL SQL, . , ,
. ,
, !
, ,
SQL , , .
() .
, .
MySQL- crash-me , , , crash-me , ,
450 .

404

6. MySQL

, crash-me, ,
18 ,
Informix DB2.
crash-me MySQL . , , ,
. sql-bench MySQL.
Perl DBI. DBI ,
.
crash-me http://dev.mysql.com/techresources/crash-me.php. http://dev.mysql.com/tech-resources/benchmarks/.
, SQL. , MySQL
My ISAM,
.
, Oracle , ( ).
, .
, , . C++ , , C++.
, ( REPLACE, MySQL),
SQL, .
,
.
MySQL /*! */
, MySQL. /* */ ( ) SQL-.
, ,
Web-, ,
.
,
. ,
"" ,
.
.

MySQL. ,
. . . 4.10.

6.1.

405

6.1.3. MySQL
MySQL.
MySQL ,
.
, -,
,
, .
( 7
), 4-10 , . ,
.
,
. , , ( , ) , . Web-, Perl. Web-, SQL, , . modperl, .

, SQL- GIF .
Perl-, Web-.
SQL- .
, ,
, ( 50
200 - ).

ODBC,
.
, - Sun Ultra SPARCstation (2 200 ).
Linux.

6.1.4. MySQL
MySQL (benchmark suite) crash-me, .
, sql-bench
MySQL.
, , SQL .

406

6. MySQL

, ,
. .
:
MySQL.
http://dev.mysql.com/downloads/,
(. 2.3.3).
Perl Perl DBI
, DBI . DBD - ,
. , MySQL,
PostgreSQL DB2, DBD: :mysql, DBD: :Pg
DBD:: DB2. . 2.7.
, MySQL, sql-bench. ,
MySQL, sql-bench
run-all-tests:
shell> cd sql-bench
shell> perl run-all-tests

server-^

_ - .
:
shell> perl run-all-tests help
crash-me sql-bench.
, . , :
.
.
.
.
VARCHAR.
crash-me
http: //dev.mysql ..com/tech-resources/crash-me.php.

http://dev.mysql.com/tech-resources/benchmarks.

6.1.5.

, . (
"-"), .
, ,
, , ,
.

6.2. SELECT

407


MySQL (. 6.1.4).
. ,
, .
, Open Source Database
Benchmark, http://osdb.sourceforge.net/.
, .
, , .
(, ), . ,
, .
, ,

. Super Smack, http://jeremy.zawodny.com/mysql/super-sraack/.
" ", ,
.

6.2. SELECT

, :
, .
,
GRANT, MySQL , . , , tables_priv columns_priv. ,
, . , ,
, , .

MySQL, BENCHMARK ()
. : BENCHMARK {__, ).
:
| BENCHMARK(1000000,1+1)
+

I
+
1 row in s e t

|
+

0|
+
(0.32

sec)

408

6. MySQL

Pentium II400 . , MySQL 1 000 000


0,32 .
MySQL , . BENCHMARK () - ,
.

6.2.1. EXPLAIN
( SELECT)
EXPLAIN

EXPLAIN SELECT

onu,MM_select

EXPLAIN, DESCRIBE,
, MySQL SELECT:

EXPLAIN _ - DESCRIBE _
SHOW COLUMNS FROM _.

SELECT EXPLAIN, MySQL , SELECT, ,


.

EXPLAIN.
EXPLAIN , ,
SELECT,
.
ANALYZE TABLE , ,
.
, .
, SELECT, SELECT STRAIGHT_JOIN SELECT.
EXPLAIN , SELECT. , MySQL
. MySQL , (single-sweep multi-join) . , MySQL , , . , , ,
. ,
.
MySQL 4.1 EXPLAIN ,
, UNION, . : i d s e l e c t _ t y p e .
, , MySQL 4.1.

6.2. SELECT

409

EXPLAIN :

id. SELECT. SELECT .

s e l e c t _ t y p e . SELECT, :

SIMPLE. SELECT ( UNION SUBQUERY).

PRIMARY. SELECT.

UNION. SELECT UNION.

DEPENDENT UNION. SELECT UNION,


.

SUBQUERY. SELECT .

DEPENDENT SUBQUERY. SELECT ,


.

DERIVED. SELECT (
FROM).

t a b l e . , .

type. . , :

system. (= ). const.

const. , . ,
. const , .
const , PRIMARY KEY
UNIQUE .
_ const-:
SELECT * FROM _ WHERE _=1
SELECT * FROM _

WHERE __1=1 AND __2=2;

eq_ref.
. ,
const. , , PRIMARY KEY UNIQUE.
e q r e f ,
=.
, , .
MySQL eq_ref
_:
SELECT * FROM _,_
WHERE . ^ _.;

410

6. MySQL
SELECT * FROM _, __
WHERE _ . __ 1 =^ .
AND _. ___2=1;

ref. , ref ,
,
PRIMARY KEY UNIQUE ( , ). ,
.
ref ,
=.
MySQL ref _:
SELECT * FROM _ WHERE _=;
SELECT * FROM _,_
WHERE _. _=^ . ;
SELECT * FROM ^, _
WHERE _ . __ 1 =_ .
AND _. __2=1;

r e f o r n u l l . , ref, , MySQL
, NULL.
MySQL 4.1.1, .
MySQL r e f o r n u l l
_:
SELECT * FROM _
WHERE _= OR _ IS NULL;

. 6.2.6.
indexmerge. , (index Merge).
, a key_len
. 6.2.5.
uniquesubquery. ref IN :
IN (SELECT _ FROM WHERE )
uniquesubquery - , .

index_subquery. unique_subquery.
IN, :

IN (SELECT ^ FROM WHERE )

6.2. SELECT

411

range.
. key , .
k e y l e n . ref
NULL.
range , ,
: =, , >, >=, <, <=, IS NULL, <=>, BETWEEN IN:
SELECT * FROM _
WHERE ^ = 10;

SELECT *
WHERE
SELECT *
WHERE
SELECT *
WHERE

FROM _
_
BETWEEN 10 and 2 0 ;
FROM _
^
IN ( 1 0 , 2 0 , 3 0 ) ;
FROM _
_1=
10 AND _2
IN ( 1 0 , 2 0 , 3 0 ) ;

index. - , ALL, , . , ALL, . MySQL , , .

ALL. . ,
- , const, . , ALL, , .

p o s s i b l e k e y s . p o s s i b l e k e y s , MySQL . , , EXPLAIN. , possible_keys


.
NULL, , .
, WHERE, , . ,
EXPLAIN.
SHOW INDEX FROM _.

key. key (), MySQL


. NULL,
. MySQL possible_keys, FORCE INDEX, USE INDEX IGNORE INDEX.
My I SAM BDB ANALYZE TABLE
. MylSAM myisamchk analyze
. . 4.6.2.

key-len. key-len , MySQL . NULL, key NULL. -

412

6. MySQL
, key-len ,
MySQL.

ref. ref , key


.

rows. rows , , MySQL,


.

Extra. , MySQL
. , :
Distinct. MySQL , .
Not exists. MySQL LEFT JOIN

, LEFT JOIN.
,
:
SELECT * FROM tl LEFT JOIN t2 ON tl.id=t2.id
WHERE t2.id IS NULL;
, t 2 . i d NOT NULL.
MySQL t l t2 , t l . id. t2, , t 2 . i d
NULL, t2,
id. , t l MySQL
t2, , .

range checked for each record (index map: #). MySQL . ,


,
( ), . , , .
Using filesort. MySQL
.

, WHERE. .
Using index.
, , . ,
, .
Using temporary. MySQL , . , GROUP BY ORDER BY, - .

6.2. SELECT

413

Using where. WHERE ,


.
, ,
, Extra
Using where, - ALL index.

, , , , Extra Using f i l e s o r t
Using temporary.
,
rows EXPLAIN. ,
MySQL , . raax_join_size, , SELECT . . 6.5.2.
, , EXPLAIN.
, SELECT, ,
EXPLAIN:
EXPLAIN SELECT tt.TicketNumber, tt.Timeln,
tt.ProjectReference, tt.EstimatedShipDate,
tt.ActualShipDate, t t . C l i e n t I D ,
tt.ServiceCodes, tt.RepetitivelD,
tt.CurrentProcess, tt.CurrentDPPerson,
tt.RecordVolume, tt.DPPrinted, et.COUNTRY,
et_l.COUNTRY, do.CUSTNAME
FROM t t , e t , et AS e t _ l , do
WHERE tt.SubmitTime IS NULL
AND tt.ActualPC = et.EMPLOYID
AND tt.AssignedPC = et_l.EMPLOYID
AND t t . C l i e n t I D = do.CUSTNMBR;
:

It
tt
tt
et
do

ActualPC
AssignedPC
ClientID
EMPLOYID
CUSTNMBR

CHAR(IO)
CHAR(IO)
CHAR(IO)
CHAR(15)
CHAR(15)

tt
tt
tt

ActualPC
AssignedPC
ClientID

et
do

EMPLOYID ( )
CUSTNMBR ( )

tt. ActualPC .

414

6. MySQL

, , , EXPLAIN :
table type possible_keys key
key
key__len
ref
rows
key
len ref
rows Extra
et
ALL PRIMARY
NULL NULL
NULL 74
do
ALL PRIMARY
NULL NULL
NULL 2135
et_l ALL PRIMARY
NULL NULL
NULL 74
tt
ALL
AssignedPC,
NULL NULL
NULL 3872
ClientID,
ActualPC
range checked for each record (key map: 35)
type ALL , , MySQL , .
, ,
. 74 * 2135 * 74 * 3871 = 45 268 558 720 . , , .
, MySQL
, . ( ISAM
, .)
VARCHAR CHAR - ,
. tt.ActualPC CHAR(IO), a et.EMPLOYID -
CHAR (15), .
ALTER TABLE Actual PC 10 15:
mysql> ALTER TABLE t t MODIFY ActualPC VARCHAR(15);
tt.ActualPC, et.EMPLOYID VARCHAR(15).
EXPLAIN , :
table type
tt
ALL
do
et_l
et

possible_keys key
key_len ref
rows
AssignedPC,
NULL
NULL
NULL 3872
ClientID,
ActualPC
ALL
PRIMARY
NULL
NULL
NULL 2135
ange checked f o r each r e c o r d (key map: 1)
ALL
PRIMARY
NULL
NULL
NULL 74
range checked for each record (key map: 1)
eq_ref
PRIMARY
PRIMARY 15
tt.ActualPC

Extra
Using
where

, : rows
74 . .
t t . AssignedPC = e t _ l .EMPLOYID t t . C l i e n t ID =
do.CUSTNMBR:
mysql> ALTER TABLE t t MODIFY AssignedPC VARCHAR(15),
->
MODIFY C l i e n t I D VARCHAR(15);
EXPLAIN :
table type
et
ALL

possible_keys key
PRIMARY
NULL

key len ref


NULL
NULL

rows Extra
74

6.2. SELECT
tt

ref

AssignedPC,
ClientID,
ActualPC
et 1 eq ref PRIMARY
do
eq ref PRIMARY

415

ActualPC

15

et .EMPLOYID

PRIMARY
PRIMARY

15
15

tt .AssignedPC 1
tt .ClientID
1

52

Using
where

.
, , MySQL
, tt.ActualPC , t t . , MySQL
:
mysql> ANALYZE TABLE tt;
EXPLAIN :
table type
tt
ALL

possible_keys
AssignedPC
ClientID,
ActualPC
et
eq ref PRIMARY
et 1 eq_ref PRIMARY
do
eq ref PRIMARY

key
NULL

key_len reJ
NULL
NULL

PRIMARY 15
PRIMARY 15
PRIMARY 15

rows Extra
3872 Using
where

1
tt..ActualPC
tt..AssignedPC 1
tt,.ClientID
1

, rows EXPLAIN MySQL. ,


. , , STRAIGHT_JOIN SELECT, FROM .

6.2.2.
,
. , ,
(, , ). , :
l o g {_)
I l o g {__
/ 3 * 2 /
[_
+ ___))
+1
MySQL 1024 , , 4 . 500 000 3
( ), log (500,000) /log (1024/3*2/ (3+4)) + 1 = 4
.
500000 * 7 * 3/2 = 5,2
(, 2/3),
,
, .
, , , ,
, , .
, ,
log N. , -

416

6. MySQL

SQL-,
. ,
, , ,
,
( log N). ,
. MylSAM
keyjouf f er_size. . 6.5.2.

6.2.3. SELECT
, , SELECT.. .WHERE ,
, - , .
.
EXPLAIN , SELECT. . 6.4.5 6.2.1.

My ISAM:
MySQL ,
ANALYZE TABLE myisamchk analyze ,
. ,
(
1). MySQL , .
SHOW
INDEX FROM _, Cardinality, myisamchk
description --verbose .
, myisamchk
--sort-index sort-records=l ( 1).
, ,
, . ,
, ,
.

6.2.4. MySQL WHERE


,
WHERE. SELECT, WHERE DELETE UPDATE.
, MySQL ,
. MySQL ,
.
, MySQL, .
:
((a AND b) AND OR ( ( ( a AND b) AND ( AND d ) ) ) )
-> (a AND b AND c) OR (a AND b AND AND d)
:
(a<b AND b=c) AND a=5
-> b>5 AND b=c AND a=5

6.2. SELECT

417

( - ):
(>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
-> =5 OR =

COUNT (*) , WHERE,


My ISAM HEAP.
NOT NULL, .

. MySQL , SELECT .

HAVING WHERE, GROUP BY


(COUNT (), MIN () ).

WHERE

.
, .
:
.

, WHERE PRIMARY KEY


UNIQUE,
NOT NULL.
:
SELECT * FROM t WHERE _=1;
SELECT * FROM t l , t 2
WHERE tl._ =1 AND t2._=1.id;
. ORDER BY GROUP BY
, .
ORDER BY GROUP BY,
ORDER BY GROUP BY ,
, .
SQL_SMALL_RESULT, MySQL ,
.
, ,
, . ,
30% . , , , , -. .
MySQL , . , , , .

418

6. MySQL

, ,
HAVING, .

, :
SELECT COUNT (*) FROM

__;

SELECT MIN (_1), MAX (_1) FROM _;


SELECT {__2) FROM t b l __
WHERE
_2=;
SELECT . . . FROM _
ORDER BY _1,
_2,
. . . LIMIT 1 0 ;
SELECT . . . FROM __
ORDER BY _1
DESC, _2
DESC, . . . LIMIT 1 0 ;

, ,
:
SELECT _1,
__2
WHERE
_1-;

SELECT COUNT(*) FROM

FROM

WHERE _1=!
AND
_2~2;
SELECT _2
FROM _ GROUP BY __1;

:
SELECT . . . FROM

ORDER BY _1,

_2,

... ;

SELECT . . . FROM _
ORDER BY _1
DESC, _2

DESC,

... ;

6.2.5. MySQL OR
(Index Merge) ref, ref_or_null range .
, ,
ref, ref_or_null range .
, , MySQL 5.0.0;
, ,
,
.
EXPLAIN index_merge type.
key , a key_len -
.
:
SELECT *
SELECT *
WHERE
SELECT *
WHERE
AND
SELECT *
WHERE

FROM _ WHERE _1
= 10 OR _2
= 20;
FROM _
{_!
= 10 OR __2 = 20) AND _
= 30;
FROM t l , t 2
( t l . 1 IN ( 1 , 2 ) OR t l . 2 LIKE
'*')
2.1=1.;
FROM t l , t 2
tl.1=1

AND ( t 2 . k e y l = t l . OR t 2 . k e y 2 = t l .

);

6.2. SELECT

419

6.2.6. MySQL IS NULL


MySQL _ IS NULL,
__ = _. , MySQL NULL IS NULL.
SELECT * FROM _ WHERE _
SELECT * FROM _ WHERE _
SELECT * FROM _

I S NULL;
<=> NULL;

WHERE _= 1 OR __=2
OR _ IS NULL;
WHERE _ IS NULL , NOT NULL, .
, - NULL, , , LEFT JOIN.
MySQL 4.1.1
_ = AND _ IS NULL - ,
. EXPLAIN ref_or_null, .
IS NULL .
, b t2:
SELECT * FROM t l WHERE t l . a = e x p r OR t l . a I S NULL;
SELECT * FROM t l , t 2 WHERE t l . a = t 2 . a OR t 2 . a I S NULL;
SELECT * FROM t l , t 2
WHERE ( t l . a = t 2 . a OR t 2 . a I S NULL) AND t 2 . b = t l . b ;
SELECT * FROM t l , t 2
WHERE t l . a = t 2 . a AND ( t 2 . b = t l . b OR t 2 . b I S N U L L ) ;
SELECT * FROM t l , t 2
WHERE ( t l . a = t 2 . a AND t 2 . a I S NULL AND . . . )
OR ( t l . a = t 2 . a AND t 2 . a I S NULL AND . . . ) ;
ref_or_null , , NULL.
, IS NULL. MySQL ( t l . a = t 2 . a AND
t2. a IS NULL) :
SELECT * FROM t l , t 2
WHERE ( t l . a = t 2 . a AND t 2 . a I S NULL)
OR ( t l . b = t 2 . b AND t 2 . b I S NULL);

6.2.7. MySQL DISTINCT


DISTINCT ORDER BY .
, DISTINCT GROUP BY, , MySQL ORDER BY HAVING, .
MySQL GROUP BY ,
SELECT, GROUP BY.

420

6. MySQL

.
, . ,
customer.name :
mysql> SELECT o r d e r . c u s t i d , customer.name, MAX(payments)
->
FROM order,customer
->
WHERE o r d e r . c u s t i d = customer.custid
->
GROUP BY order.custid;

SQL customer.name GROUP


BY. MySQL , ANSI.
, , GROUP BY,
. .
MIN () () , . column , sort:
SUBSTR(MIN(CONCAT(RPAD(sort,6,' '),column)),7)
LIMIT _ DISTINCT MySQL ,
_ .
, , MySQL , .
, , t l t2 (
EXPLAIN), MySQL t2 (
t l ) , t2:
SELECT DISTINCT t l . a FROM t l , t 2 where t l . a = t 2 . a ;

6.2.8. MySQL LEFT JOIN RIGHT JOIN


LEFT JOIN _ MySQL :
, .
( ), LEFT JOIN.
LEFT JOIN ,
. ( , WHERE
).
, ,
, .
, MySQL .
WHERE.
, WHERE, ,
ON,
, NULL.
LEFT JOIN, ,
, _ IS NULL WHERE,

6.2. SELECT

421

_ - , NOT NULL, MySQL ( ) , , LEFT JOIN.


RIGHT JOIN , .
, . LEFT JOIN, STRAIGHT_JOIN ,
. , , , MySQL , LEFT
JOIN d:
SELECT *
FROM a,b LEFT JOIN ON (c.key=a.key) LEFT JOIN d ON (d.key=a.key)
WHERE b.key=d.key;
, :
SELECT *
FROM b , a LEFT JOIN ON ( . k e y = a . k e y )
WHERE b . k e y = d . k e y ;

LEFT JOIN d ON ( d . k e y = a . k e y )

4.0.14, MySQL LEFT JOIN:


WHERE false NULL, LEFT
JOIN .
, t2.columnl NULL, WHERE false:
SELECT * FROM t l LEFT JOIN t2 ON (columnl) WHERE t2.column2=5;
:
SELECT * FROM t l , t 2 WHERE t2.column2=5 AND tl.columnl=t2.columnl;
, MySQL t2 t l . ,
STRAIGHT_JOIN.

6.2.9. MySQL ORDER BY


MySQL , ORDER BY GROUP BY, .
, ORDER BY ,
ORDER BY WHERE.
ORDER BY
GROUP BY:
SELECT *
SELECT *
SELECT *
SELECT *
SELECT *
WHERE

FROM
FROM
FROM
FROM
FROM

t l ORDER
t l WHERE
t l WHERE
t l ORDER
tl
2=1

BY _!,_2,
... ;
_1=
ORDER BY
_2;
_1=
GROUP BY
_2;
BY _1
DESC, _2
DESC;
ORDER BY

DESC, 2

DESC;

422

6. MySQL

MySQL ORDER BY GROUP BY , -


, WHERE. :
ORDER BY :
SELECT * FROM t l ORDER BY 1, 2;
ORDER BY :
SELECT * FROM t l WHERE _2= ORDER BY _2;
ASC DESC:
SELECT * FROM t l ORDER BY _1 DESC, _2 ASC;

, , , ORDER BY:
SELECT * FROM t l WHERE 2=a ORDER BY 1;

, ORDER BY - , . ( , EXPLAIN, const.)

ORDER BY GROUP BY.

. , HASH- -.
, MySQL , :
1. . , WHERE, .
2. . sort_buffer_size.
3. , qsort (quicksort)
. . (
, .)
4. , .
5. MERGEBUFF (7)
. , .
6. , ,
MERGEBUFF2 (15).
7. ( ).
8. , . ,
,
. read_rnd_buffer_size. , , sql/records. .

6.2. SELECT

423

MySQL ,
EXPLAIN SELECT.. .ORDER BY. Using f i l e s o r t Extra,
, MySQL . . 6.2.1.
ORDER BY, , MySQL .
, :
sort_buf fer_size.
read_rnd_buf fer_size.
tmpdir,
. MySQL 4.1
, ,
. ' : ' Unix ' ; '
Windows, NetWare OS/2. .
!
:;!; , , .

MySQL GROUP BY !, 2,... ,


ORDER BY 1, 2, . . .
ORDER BY ,
MySQL , , , . GROUP BY,
,
, ORDER BY NULL, :
INSERT INTO foo
SELECT a, COUNT(*) FROM bar GROUP BY a ORDER BY NULL;

6.2.10. MySQL LIMIT


MySQL -,
LIMIT _ HAVING:
LIMIT, MySQL
,
.
LIMIT _ ORDER BY, MySQL
, _ ,
.
LIMIT _ DISTINCT, MySQL ,
_ .
GROUP BY ( ) , . LIMIT _ GROUP BY.

424

6. MySQL

MySQL , , SQL_CALC_FOUND_ROWS.
LIMIT 0 . .
, LIMIT _ .

6.2.11.
EXPLAIN ALL type, MySQL
.
:
, ,
. , 10 .
ON WHERE
.
, MySQL
( ) ,
. .
6.2.4.
( ) . MySQL
,
.
.
:
ANALYZE TABLE _ .
FORCE INDEX , MySQL,
, .
SELECT * FROM t l , t2 FORCE INDEX (__)
WHERE 11. _^2 . _;
mysqld max-seeks-for-key=1000 SET
max_seeks_for_key=1000, ,
1000 . . 4.2.3.

6.2.12. INSERT
, :
: (3)
: (2)

6.2. SELECT

: (2)

: (1 )

: (1 )

: (1)

425

, .
log N, ,
.
:

,
INSERT VALUES,
. ( ), INSERT.
, bulk_insert_buffer_size,
(. 4.2.3).

, , INSERT DELAYED.

My ISAM SELECT, .

LOAD DATA INFILE. 20 ,


INSERT.

, , LOAD
DATA INFILE .
:
1. CREATE TABLE.
2. FLUSH TABLES mysqladmin

flush-tables.

3. myisamchk keys-used=O -rq ///_/_.


.
4. LOAD DATA INFILE. , .
5. , , myisampack (. 8.1.3.3).
6. myisamchk -r -q ///_/_. ,
, , . .
7. FLUSH TABLES mysqladmin

flush-tables.

, LOAD DATA INFILE , My ISAM. , myisamchk -

426

6. MySQL
,
, LOAD DATA INFILE.
MySQL 4.0, ALTER TABLE _
DISABLE KEYS myisamchk --keys-used=O -rq ///_/
_ ALTER TABLE _ ENABLE KEYS myisamchk -r -q
///_/_. FLUSH TABLES .
, , :
LOCK TABLES a WRITE;
INSERT INTO a VALUES (1,23), (2,34), (4,33);
INSERT INTO a VALUES (8, 26), (6,29) ;
UNLOCK TABLES;
,
, ,
INSERT. ,
.
, ,
BEGIN/COMMIT LOCK TABLES.

, , . :
Connection I does 1000 inserts
Connections 2, 3, and 4 do 1 insert
Connection 5 does 1000 inserts
, 2, 3 4 1 5. , , 2, 3 4
1 5, 40% .
INSERT, UPDATE DELETE MySQL , , ,
, 5 .
, LOCK TABLE UNLOCK TABLE ( 1000 ),
. .
INSERT , LOAD
DATA INFILE, .
My ISAM
INSERT, LOAD DATA INFILE,
key_buffer_size. . 6.5.2.

6.2.13. UPDATE
SELECT . , , . , , .

6.2. SELECT

427

-
. , , .
, My ISAM,
, .
, OPTIMIZE TABLE.

6.2.14. DELETE
.
, . . 6.5.2.
, TRUNCATE TABLE
_, DELETE FROM __.

6.2.15.
:
, .

, thread_cache_size
(. 6.5.2).
-
. MySQL EXPLAIN (. 6.2.1).
SELECT My ISAM,
, ,
.
My ISAM, , . ,
, . -
OPTIMIZE TABLE .
ALTER TABLE... ORDER BY lf 2, . ..,
1, 2, . . .
, .
, "" .
, , . MySQL
:
SELECT * FROM _
WHERE _ (CONCAT {!,
AND coll='* AND co!2='';

2))

428

6. MySQL

My ISAM
(VARCHAR, BLOB TEXT).
,
. . 8.
- ,
"". , - .
, ,
. , -
My ISAM (. ),
,
, . . 8.
, , , , .
:
UPDATE SET _~
WHERE _= ;

+1

, MySQL, My ISAM ISAM, ( / ). , .


,
. , "". , -
-, .
, "" "",
, ,
, .
,
. ,
. MySQL SQL-
.

BLOB. , ,
BLOB, . , "-".

6.2. SELECT

429

( " "). ,
.
, (User-Defined
Functions - UDF) . ,
,
, .
-,
. ( MySQL Oracle),
, ,
.
INSERT DELAYED, , . , .
INSERT LOW_PRIORITY, SELECT
, .
SELECT LOWPRIORITY, , ""
. , SELECT ,
.
INSERT, ( SQL- ).
LOAD DATA INFILE . , INSERT.
AUTOINCREMENT .
OPTIMIZE TABLE ,
MylSAM, . . 8.1.3.
, -, . . 8.
Web-, .
. , Web- , , , .
,
, , , cookie .

. MySQL 3.23 .

430

6. MySQL

. , customer
name customer_name. SQL-, 18 .
,
, SQL-. , MySAM
MySQL, SQL-. ,
, ,
(
).
MySQL ( ).
.
, ( ), . , , , , . ,
, .
. , , .
, . . 5.
MylSAM DELAY_KEY_WRITE=1 ,
. , , , my is am-re cove r myisamchk. . ( , , ,
DELAY_KEY_WRITE,
.)

6.3.
6.3.1.
MySQL ISAM, My ISAM MEMORY (HEAP), BDB - InnoDB.
,
, , , . ,
.

6.3.

431

, , ,
. ,
Web- , ,
, - . MySQL - MylSAM -
.
MySQL
(deadlock) , .
, .
MySQL :
, .
.
MySQL :
,
.
.
, , , - .
, , SELECT
, .
MySQL 3.23.33, , Table_locks_waited
Table_locks_immediate:
mysql> SHOW STATUS LIKE 'Table%f;
+
+
+
| Variablename
| Value |
I Table_locks_immediate I 1151552 |
I Table_locks_waited
| 15324 |
+
+
+
MySQL 3.23.7 (3.23.5 Windows), MylSAM
INSERT SELECT ,
INSERT .
MylSAM, . , , . (
, .) , ,
.
INSERT SELECT , , -

432

6. MySQL

. :
mysql> LOCK TABLES real_table WRITE, insert_table WRITE;
mysql> INSERT INTO real_table SELECT * FROM insert_table;
mysql> TRUNCATE TABLE insert_table;
mysql> UNLOCK TABLES;
InnoDB , a BDB - .
InnoDB BDB . ,
InnoDB , a BDB - SQL-, .
:
,
.
.

.
:
,
.
, , ,
.
, , GROUP BY , .

, ,
, , .
:
, , .
,
, :
UPDATE _ SET =
WHERE __= _ ;
DELETE FROM _ WHERE
__=_;
SELECT INSERT UPDATE DELETE.
GROUP BY .
.
(, MySQL ), -

6.3.

433

. , /
, . : , .
,
. , .

, GETLOCKO RELEASE_LOCK () MySQL.
, .

6.3.2.
MySQL
( , ) ,
InnoDB BDB.
InnoDB BDB MySQL , LOCK TABLES.
LOCK TABLES, InnoDB , a BDB - , .
, , ,
.
, ,
. ,
, , .
, , . , "",
SELECT.
, , , ,
. , , ,
.
:
SELECT, .
UPDATE . , SELECT.
SELECT .
UPDATE , SELECT, SELECT
, UPDATE.
SELECT!

,
.
, SELECT . ,
.

434

6. MySQL

mysqld low-priority-updates. , , , SELECT.


SELECT UPDATE
SELECT.

, ,
, , SET
LOW_PRIORITY_UPDATES=1.
INSERT, UPDATE DELETE
LOW_PRIORITY.
SELECT , HIGH_PRIORITY.
MySQL 3.23.7, mysqld
max_write_lock_count, MySQL
SELECT, , , .
READ WRITE.
INSERT SELECT,
My ISAM,
SELECT INSERT.

,
INSERT DELAYED.

SELECT DELETE,
LIMIT DELETE.
SQL_BUFFER_RESULTS SELECT .
mysys/thr_lock.
. , .
MySQL:
, , .
LOCK TABLES (
, ). .
MySQL,
, innoDB BDB. . 9 8.4.

6.4.

435

6.4.
6.4.1.
MySQL .
( ) . , , MySQL,
.

( SDBM Focus). , .
, ,
.
- ( Oracle,
Sybase ).
() ( , Sybase -. .). ,
, . :
,
, ( , , Oracle
, - .
.).
,
( , Oracle, Sybase
, , ,
- . .).
, ( (
Sybase - . .)).
,
( ! ,
Oracle
- . .)).
.

6.4.2.
, , .
,
,
.
, .
MySQL . , / .
. . 8.

436

6. MySQL

, , .
() .
MySQL , .
,
. , MEDIUMINT , INT.
, NOT NULL. . NULL , , , . ,
.
MylSAM, (VARCHAR, TEXT
BLOB), . ,
, , . . 8.1.3.
, .
.
, .
, , , .
, .
.
,
, .
,
, . MySQL .
, , ,
,
. . 6.5.2.
,
, .

6.4.3.
MySQL .
-
SELECT.

(. 8).
, , 16
, , 256 .
.
_ {) ,
, CHAR
VARCHAR. , .

6.4.

437

MylSAM ( MySQL 4.0.14) innoDB, TEXT BLOB.


, , :
CREATE TABLE t e s t (blob_col BLOB, INDEX(blob_col(10)));
255 ( 1000 MylSAM
InnoDB, MySQL 4.1.2). , , CREATE TABLE . , , .
MySQL 3.23.23, FULLTEXT. . FULLTEXT
MylSAM, CHAR, VARCHAR TEXT.
, , ()
MySQL 4.1.0, (spatial) . MylSAM. R-.
MEMORY (HEAP) -.
MySQL 4.1.0, - ( ).

6.4.4.
MySQL , . 15 .
(. 6.4.3).
,
, .
MySQL , ,
WHERE, .
, :
CREATE TABLE t e s t (
i d INT NOT NULL,
l a s t _ n a m e CHAR(30) NOT NULL,
f i r s t _ n a m e CHAR(30) NOT NULL,
PRIMARY KEY ( i d ) ,
INDEX name ( l a s t _ n a m e , f i r s t _ n a m e ) ) ;

name last_name first_name.


, lastname , - first_name,
last name. , name
:
SELECT * FROM t e s t WHERE last_name='Widenius';
SELECT * FROM t e s t
WHERE l a s t name='Widenius' AND f i r s t name='Michael';

438

6. MySQL

SELECT * FROM test


WHERE last_name='Widenius'
AND (first_name='Michael' OR first_name='Monty1);
SELECT * FROM test
WHERE last_name='Widenius'
AND first_name >='M' AND first_name < 'N f ;
name :
SELECT * FROM test WHERE first_name='Michael;
SELECT * FROM test
WHERE last_name='Widenius' OR first_name='Michael';
, MySQL
, .

6.4.5. MySQL

. MySQL , , .
, . ,
, MySQL
,
. 1000 , ,
, 100 , . ,
1000 , ,
.
MySQL (PRIMARY KEY, UNIQUE, INDEX FULLTEXT)
-. , R-, - MEMORY (HEAP).
.
, . .
, , :
, WHERE.
. , MySQL , .
.
MIN () () _. , , WHERE _#=
, _ .
MySQL MIN () () . , , :
SELECT MIN (_2), (_2)
FROM WHERE 1-10;

6.4.

439

,
(, ORDER BY 1,
_2). DESC,
. . 6.2.9.

,
, . , ,
:
SELECT _ FROM _ WHERE _!=1

, SELECT:
mysql> SELECT * FROM _ WHERE 1=1

AND

2=2;

! 2,
. 1 2,
, , ,
.
,
. ,
, (!, 2, ),
(!), (!, 2) (!,
2, ).
MySQL , . ,
SELECT:
SELECT * FROM _ WHERE
!^!;
SELECT * FROM _ WHERE 2=2;
SELECT * FROM _ WHERE 2=2 AND =;
(!, 2, ), . WHERE ,
, .
, =, >,
>=, <, <= BETWEEN.
MySQL LIKE, LIKE - , . , SELECT :
SELECT * FROM _ WHERE _ LIKE ' P a t r i c k ! 1 ;
SELECT * FROM _ WHERE _ LIKE 'Pat%_ck!';
' P a t r i c k ' <= _ < ' P a t r i c l ' . ' Pat' <= _

< ''.

SELECT :
SELECT * FROM _ WHERE _ LIKE '%Patrick%';
SELECT * FROM WHERE LIKE _;

440

6. MySQL

LIKE .
LIKE .
MySQL 4.0 LIKE.
. . . LIKE '%%!, , MySQL Turbo Boyer-Moor .
_ IS NULL ,
_ . , AND
WHERE, . ,
,
, AND.
WHERE :
. . . WHERE _1=1 AND _2=2 AND _=3
/* = 1 OR = 2 */
. . . WHERE =1 OR A=10 AND =2
/* "_2='hello'" */
. . . WHERE _1='hello'
AND _=
/* 1, 2 */
. . . WHERE 1=1 AND 2=2 OR 1=3 AND =3;
WHERE :
/* _1 */
. . . WHERE _2=1 AND _=2
/* AND */
. . . WHERE =\ OR A=10
/* , */
. . . WHERE _1=1 OR _2-10
MySQL , . ,
,
. ( , ,
.) LIMIT ,
MySQL ,
, .
- , , :
(= ) ,
.
- ORDER BY. ( .)
MySQL , ,
( ,
). , My ISAM MEMORY -.
. (
- .)

6.4.

441

6.4.6. MylSAM
-, My ISAM
, ,
-
:
,
( ). ,
.
MySQL .
.
My ISAM.
, MySQL 4.1, :
.
.
.
ISAM. . ISAM , MySQL 3.23
My ISAM. MySQL 4.1 . ISAM .

keybuf fer_size. 0, .
, key_buffer_size , (8).
, , .
( ,
, .)
- , . .
( ,
-. . , ,
.)
.
, , . .
,
, -
. , , , .
, .
,
( ), , .
, .
, ,
, "" ("dirty"). , .

6. MySQL

442

LRU (Least Recently Used - ). , . , ( LRU) , .


6.4.6.1.
MySQL 4.1 ,
. , .
, , , , .
MySQL 4.1,
:
, , .
, ,
, .

, ( ,
,
).
.
6.4.6.2.
,
. , . , MySQL 4.1.1 .
CACHE INDEX.
, t l , t2 t3
hot_cache:
mysql> CACHE INDEX t l , t 2 , t3 IN hot_cache;

I Table

| Op
+
+
I test.tl | assign_to_keycache
I test.t2 | assign_to_keycache
I test.t3 | assign_to_keycache
+
+

I Msg_type
+
| status
| status
| status
+

| Msg_text
+
| OK
| OK
| OK
+

|
+
|
|
|
+

!
ISAM, ISAM
. ISAM
.

6.4.

443

, CACHE INDEX, SET GLOBAL . :


mysql> SET GLOBAL keycachel.keyjDuffer_size=128*1024;
, 0:
mysql> SET GLOBAL

keycachel.key_buffer_size=O;

- , . keycachel.key_buffer_size, keycachel -
, a key_buf fer_size - .
( ) , . - , .

:
"" (hot) , 20% ,
. , , .
"" (cold) , 20% , .
, .
"" (warm) , 60% , . ,
.
,
. , , , ,
, . :
,
. , ,
, , ,
.
, , , , , , -, .
, , , . , , .
6.4.6.3.
MySQL 4.1 LRU , ,
, " ".

6. MySQL

444

, LRU : ""
"" . , , ""
, key_cache_division_limit . key_cache_division_limit -
, - , .
,
"" . ( )
"" . ,
, .
- . , , ,
-.
, "" , .
.
, "" . , , key_cache_age_threshold .
, , : , N , , "" ,
N*key_cache_age_threshold/100 ,
"" . , , ,
"" .
,
, -.
,
key_cache_division_limit, 100. "" .
6.4.6.4.
, ,
, , , .
: .
,
. , , ,
, , .
, LOAD INDEX
INTO CACHE. , ()
t l t2:
mysql> LOAD INDEX INTO CACHE t l , t2 IGNORE LEAVES;
Table

| Op

| Msg_type | Msg text

6.4.

I test.tl I preload_keys | status


I test.t2 I preload_keys | status
+
+
+

445

| OK
| OK
+

|
|
+

IGNORE LEAVES , .
t l , t2.
CACHE INDEX, .
.
6.4.6.5.
MySQL 4.1 key_cache_block_size,
. , - .
- ,
- .
- . -
,
.
.
.MYI, , . -.
, key_cache_block_size .
6.4.6.6.

, :
mysql> SET GLOBAL cold__cache.key__buffer_size=4*1024*1024;
key_buffer_size
key_cache_block_size,
- . "" ,
, .
.

"" . .
, , . ,
.
, , , ,
. ,
,
.

446

6. MySQL

6.4.7. MySQL
mysqladmin status, :
Uptime: 426 Running threads: 1 Questions: 11082
Reloads: 1 Open tables: 12
Open tables ( ), 12, ,
.
MySQL - , ,
. ,
, .
, .
My ISAM , . ( ,
.) ISAM .
.

6.4.8. MySQL
table_cache, max_connections max_tmp_tables
, .
, , ,
.
, . , ,
, .
table_cache max_connections. , 200
, , 200 * /,
N - . .
, , table_cache. table_cache, MySQL , . ,
My ISAM
.
MySQL, mysqld open-files-limit. .
.2.17.
table_cache .
64 mysqld table_cache. , MySQL .
:

6.4.

447

,
.
, table_cache , .
. , - FLUSH TABLES mysqladmin flush-tables
mysqladmin refresh.
, ,
:
, ,
.
, , .
, ,
.
. ,
, ,
(, ). . :
. - .
.
HANDLER _ OPEN,
.
,
HANDLER _ CLOSE, . , ( ).
, , mysqld Opened_tables:
mysql> SHOW STATUS LIKE 'Opened_tables';

| Variable_name | Value |
+
+
+
| Opened_tables | 2741 |
+
+
+
, FLUSH TABLES,
. . 4.2.3 4.2.4.

6.49.

My ISAM ISAM , , . SELECT ,
, , ,

448

6. MySQL

, . ,
.

6.5. MySQL
6.5.1.
,
, . . , ,
.
, , !
, Solaris ( ) Linux ( 2.2 ). , Linux 2 .
2 , Large File Support (LFS) ext2. , ReiserFS XFS, 2 .
MySQL , .
.
, . , .
MySQL skip-external-locking
. MySQL 4.0 . MIT-pthreads,
flock () MIT-pthreads . Linux,
Linux . , skip-externallocking MySQL ,
. , (
) myisamchk.
,
.
, skip-externallocking, MySQL ( ) , myisamchk
( ) , .
- LOCK TABLES/UNLOCK TABLES, skip-external-locking.

449

6.5. MySQL

6.5.2.
,
mysqld, ( MySQL 4.1 verbose):
shell> mysqld verbose --help
mysqld
.
:
back log
bdb_cache_size
binlog_cache_size
connect timeout
delayed insert limit
delayed insert timeout
delayed_queue_size
flush time
interactive timeout
join buffer size
key buffer size
long_query_time
lower case table names
max_allowed_packet
max binlog cache size
max connect errors
max connections
max delayed threads
max heap table size
max join size
max_sort_length
max tmp tables
max write lock count
myisam sort buffer size
net buffer length
net read timeout
net retry count
net write timeout
read_buffer_size
read_rnd_buffer_size
slow launch time
sort buffer
table cache
thread concurrency
thread stack
tmp table size
wait timeout

current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current
current

value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:
value:

5
1048540
32768
5
100
300
1000
0
28800
131072
1048540
10
0
1048576
4294967295
10
100
20
16777216
4294967295
1024
32
4294967295
8388608
16384
30
10
60
131072
262144
2
2097116
64
10
131072
1048576
28800

mysqld, ,
, :
mysql> SHOW VARIABLES;

450

6. MySQL

, :
mysql> SHOW STATUS;
, mysqladmin:
shell> mysqladmin variables
shell> mysqladmin extended-status

4.2.3 4.2.4.
MySQL , ,
, . , ,
MySQL .
MySQL -
k e y b u f f e r s i z e tablecache. , , .

.
mysqld_safe _= _ . MySQL,
4.0. ,
:

safejnysqld raysqld_safe.

--set-variable=
_= -0 _= .

, _size, , _size. , sort__buffer_size


sort_buffer. read_buffer_size sort_buffer.
, ,
mysqld help.

, , 256 , , ,
:
shell> mysqld_safe key_buffer_size=64M table_cache=256 \
--sort_buffer_size=4M read_buffer_size=lM &
128 , , - :
shell> mysqld_safe key_buffer_size=16M sort_buffer_size=lM
,
, mysqld , mysqld ,
.
, - :
shell> mysqld_safe --key_buffer_size=512K sort_buffer_size=100K \
read buffer size=100K &

6.5. MySQL

451

:
shell> mysqldjsafe --key_buffer_size=512K sortJbuffer_size=16K \
table_cache=32 read_buffer_size=8K \
netJbuffer_length=lK &
GROUP BY ORDER BY ,
,
read_rnd_buf f e r s i z e .
MySQL support-files
my.cnf, : my-huge.cnf, my-large.cnf, my-medium.cnf my-small.cnf.
.
, mysqld
mysqld_safe, . , .
,
( , MySQL 4.1, verbose):
shell> mysqld keyJbuffer_size=32M verbose help
. , verbose
help . , ,
.
InnoDB 9.12.

6.5.3.
MySQL
Linux,

.
,
, - s t a t i c .
Linux , -03.
200
sql_yacc. , gcc/pgcc , . = MySQL,
libstdc++, . ,

Pentium, ,
, 586
( AMD).
, 10-30 %
. ,
MySQL.
gnus CodeFusion Fujitsu, ,
,
MySQL .
MySQL
. ,

452

6. MySQL

. withcharset configure.
, :
-, mysqld 1% , 2.95.2.
( -static), Linux
13% . , MySQL . ,
.
s t r i p
mysqld, 4% .
, , TCP/IP Unix,
7,5% . ( Unix, , localhost,
MySQL ).
TCP/IP , ,
8-11% , , ,
Ethernet 100 /.
( SSL), 55% , .
with-debug=full, 20% .
. , MySQL
35% . with-debug ( =full), 15%. mysqld, with-debug=full,
,
skip-safemalloc. ,
--with-debug.
Sun UltraSPARC-lie , Forte 5.0,
4% , gcc 3.2.
Sun UltraSPARC-He , Forte 5.0, 4% 32- , 64-.
2.95.2 UltraSPARC -mcpu=v8 -Wa,
-xarch=v8plusa 4% .
Solaris 2.5.1 MIT-pthreads MySQL 8-12% , Solaris.
.
Linux-x86
(-fomit-frame-pointer -fomit-frame-pointer -ffixed-ebp)
mysqld 1-4% .
MySQL Linux, MySQL
, . - ,

6.5. MySQL

453

AMD. , . ,
, AMD, ,
. MySQL Linux
, .

6.5.4. MySQL
, mysqld
. ,
, .

( key_buffer_size) , , , . . 6.5.2.

( 64 , thread_stack).

( net_buf f er_length).

( result_buf fer_length).
, max_allowed_packet. , .
.
ISAM MylSAM . ,
32- 4
. 64-
, , .
, ,
( read_rnd_buf fer_size).
,
. (memory-based, HE-tables). ( )
BLOB .
, MySQL 3.23.2, , , , tmp_table_size,
"The t a b l e ^ is f u l l " ("
_ "). 3.23.2, , My ISAM .
, , tmp_table_size mysqld
SQL- SQLBIGTABLES .
MySQL 3.20
record_buffer * 16. , record_buffer. mysqld big-tables,

454

6. MySQL

.
.
, ,
,
. . .4.4.
.
- , , ,
. .
malloc () free ().
My ISAM ISAM
, - , . ,
2 * N ( N - , BLOB).
BLOB , BLOB. ISAM My ISAM
.
, BLOB, , BLOB. ,
, BLOB.
FIFO.
64 . , . . 6.4.8.
FLUSH TABLES mysqladmin flush-tables
, ,
, . .
ps , , ,
mysqld .
. , ps Solaris
. ,
swap -s. mysqld ( , ), .

6.5.5. MySQL DNS


mysqld, , . ,
. , :

gethostbyaddr_r () gethostbyname_r (), .

6.6.

455

, gethostbyaddr () gethostbyname ().


, .
DNS, skiphost-cache. IP-
MySQL. DNS , ,
DNS skip-name-resolve, HOST_CACHE_SIZE (
128) mysqld.
, skip-host-cache.
, FLUSH HOSTS
mysqladmin flush-hosts.
TCP/IP, mysqld skip-networking.

6.6.
- .
,
, ,
. , , , , ,
- . , .
(, , , ),
, ( ) :
. , My ISAM
/ ,
,
. , ,
. . 6.6.1.

( ). ,
, - N-H N- (N- ). ,
, ( ), . , . . 6.1.5.
. , ,
.
.

456

6. MySQL

RAID 0+1
( ),
2*N , N . , ,
, .
, .
- RAID ,
. , , , RAID 0, ,
, RAID 0+1 RAID N.
RAID N , , - ,
.
Linux , hdparm ( 100%
- .) hdparm
MySQL , ,
:
hdparm -m 16 -d 1
,
,
hdparm. man-, hdparm, . hdparm , , , !
,
:
,
( - ), - noatime. inode , .

, - async. , ,
. ( Linux .)

6.6.1.

, .
, ,
, , .
-
. .

..

457

6.6.1.1. Unix
Unix , ,
MySQL.
shell> xnkdir /drl/databases/test
shell> In -s /drl/databases/test ///'_
MySQL . ,
. , dbl
MySQL, db2, dbl:
shell> cd ///'_
shell> In -s dbl db2
t b l a dbl
tbl_a db2. dbl.tbl_a, db2. tbl_a, .
,
. , , MySQL.
MySQL 4.0
mysys/my_symlink.c:
if (!(MyFlags & MY_RESOLVE_LINK) | |
(ilstat(filename,&stat_buff) && S_ISLNK(stat_buff.stjnode)))
MySQL, 4.0, mysys/mf_format.c :
if

(flag & 32 | |

(Ilstat(to,&stat_buff)

&& S_ISLNK(stat_buff.stjnode)))

:
if (1)
Windows ,
MySQL -DUSESYMDIR.
. . 6.6.3.1.
6.6.1.2. Unix
MySQL 4.0 , .
, ALTER TABLE, REPAIR TABLE
OIPTIMIZE TABLE ,
, . , , .
, realpath (). ( , Linux Solaris
realpath ().) , , SHOW VARIABLES LIKE 'have_symlink'.
MySQL 4.0
My ISAM. , , -

458

6. MySQL

, .
My ISAM :
, .
. ,
- .

.

In -s, mysqld . SQL , DATA DIRECTORY INDEX DIRECTORY CREATE TABLE.
myisamchk . , .
, .
, , , . , mysqld root,
MySQL.
ALTER TABLE...
RENAME , , .
ALTER TABLE... RENAME
, . , , . ,
.
,
skip-symbolic-links mysqld, , mysqld .
SHOW CREATE TABLE ,
, MySQL 4.0.15. mysqldump, SHOW CREATE TABLE CREATE TABLE.
,
:
ALTER TABLE DATA DIRECTORY INDEX DIRECTORY.
BACKUP TABLE RESTORE TABLE .
. f rm ( , ).
(, ) . , dbl

6.6.

459

MySQL, t b l l , dbl
tbl2, t b l l :
shell>
shell>
shell>
shell>

cd
In
In
In

///_/6
-s tbll.frm tbl2.frm
-s tbll.MYD tbl2.MYD
-s tbll.MYI tbl2.MYI

d b l . t b l l , dbl.tbl2, :
( , t b l l , ).
ALTER tbl2 .
6.6.1.3. Windows
MySQL 3.23.16, mysqld-max mysqld-max-nt Windows -DUSESYMDIR.
, .
Unix, .
MySQL 4.0, .
, skip-symbolic-links:
[mysqld]
skip-symbolic-links
MySQL 4.0 . , my.cnf my.ini
:
[mysqld]
symbolic-links
Windows MySQL, , .
_^_. sym, __ .
, MySQL C:\mysql\data,
foo, D: \data\foo.
:
1. , D:\data\foo
. foo , D:\data.
. , .
2. : \mysql\data\foo. sym, D: \data\foo\.
, foo,
D:\data\foo\. , ,
MySQL.


MySQL

MySQL,
, . , , , MySQL.
. , ,
. 3
.

7.1.


MySQL:
myisampack. MylSAM , . . 7.2.
mysql. SQL-
. . 7.3.
mysqlaccess. ,
.
mysqladmin. , ,
, , . . 7.4.
mysqlbinlog. . , ,
. . 7.5.
mysqlcc. ,
. . 7.6.
mysql check. , , , . . 7.7.

7.2. myisampack MySQL,

461

mysqldump. MySQL
SQL- -.

(Igor Romanenko). . 7.8.

mysqlhotcopy. ,
My ISAM ISAM . . 7.9.

mysqlimport. , LOAD DATA INFILE. . 7.10.

mysqlshow. , , , . . 7.11.

p e r r o r . ,
MySQL. . 7.12.

r e p l a c e . . .
7.13.

MySQL . - - h e l p ,
. mysql h e l p .
MySQL, ,
m y s q l c l i e n t , :
MYSQL_UNIX_PORT

Unix;
.

MYSQL_TCP_PORT

TCP/IP.

MYSQL_PWD

MYSQL_DEBUG

TMPDIR

MYSQL_PWD . . 4.5.6.
,
,
. . 3.3.

7.2. myisampack
MySQL,
myisampack MylSAM. ,
. myisampack 40-70%.
, , , . , ,
, Stacker MS-DOS.
MySQL mmap (), , . mmap () , MySQL
/.

462

7. MySQL

, pack_isam, ISAM. ISAM


, myisampack,
myisampack packisam,
.
:
mysqld skip-external-locking, myisampack , .
. ,
(, ). ,
.
myisampack TEXT BLOB. pack_isam
.
myisampack :
shell> myisampack [] _ . . .
(.MYI). , .
.MYI.
myisampack :

help, -?. .

--backup, -b.
_. OLD.

debug [=_], -# [_]. .


_ ' d: t :,_'.

force, -f. , ,
, ,
myisampack. (myisampack _.
. myisampack,
.) myisampack , , _.TMD . force .

-}=__, -j __. ,
, __.
, ,
( , ).

packlength=#, - #. . 1, 2 3. myisampack 1, 2
3 . myisampack
, , .
myisampack , ,
, .

7.2. myisampack MySQL,

463

silent, -s. .
, .

test, -t. He , .

tmp_di=, - .
.

verbose, -v. .
.

--version, -V. .

wait, -W. , . mysqld skip-external-locking,


myisampack , .


.
shell> Is -I station.*
-rw-rw-r 1 monty my
994128 Apr
-rw-rw-r 1 monty my
53248 Apr
-rw-rw-r 1 monty my
5767 Apr

17 19:00 station.MYD
17 19:00 station.MYI
17 19:00 station.frm

shell> myisamchk - d w station


MylSAM file:
station
Isam-version: 2
Creation time: 1996-03-13 10:08:58
Recover time: 1997-02-02 3:06:43
Data records:
1192 Deleted blocks:
0
Datafile parts:
1192 Deleted data:
0
Datafile pointer (bytes):
2 Keyfile pointer (bytes):
2
Max datafile length: 54657023 Max keyfile length:
33554431
Recordlength:
834
Record format: Fixed length
table description:
Key Start Len Index
Type
1 2
4 unique unsigned long
2
32
30 multip. text
Field
1
2
3
4
5
6
7
8
9
10
11
12
13

Start
1
2
6
10
11
31
32
62
97
132
167
171
187

Length Type
1
4
4
1
20
1
30
35
35
35
4
16
35

Root Blocksize
1024
1024
10240
1024

Rec/key
1
1

464
14

15
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

7. MySQL
222
226
242
262
282
302
332
336
340
341
349
357
365
367
369
373
377
378
380
388
392
396
400
404
405
409
413
417
421
425
429
449
479
480
481
560
639
718
797
805
806
807
827
831

4
16
20
20
20
30
4
4
1
8
8
8
2
2

4
4
1
2
8
4
4
4
4
1
4
4
4
4
4
4
20
30
1
1
79
79
79
79
8
1
1
20
4
4

shell> myisampack station.MYI


Compressing station.MYI: (1192 records)
- Calculating statistics
normal: 20 empty-space: 16 empty-zero: 12 empty-fill: 11
pre-space: 0 end-space: 12 table-lookups: 5 zero: 7
Original trees: 57 After join: 17
- Compressing file

7.2. myisampack - MySQL,


87.14%
Remember to run myisamchk -rq on compressed tables
shell> Is -1 station.*
-rw-rw-r 1 monty my
127874 Apr 17 19:00 station.MYD
-rw-rw-r 1 monty my
55296 Apr 17 19:04 station.MYI
-rw-rw-r 1 monty my
5767 Apr 17 19:00 station.frm
shell> myisamchk - d w station
MylSAM file: station
Isam-version: 2
Creation time 1996-03-13 10:08:58
Recover time: 1997-04-17 19:04:26
Data records:
1192 Deleted blocks:
0
Datafile parts:
1192 Deleted data:
0
Datafile pointer (bytes):
3 Keyfile pointer (bytes):
1
Max datafile length:
16777215 Max keyfile length:
131071
Recordlength:
834
Record format: Compressed
table description:
Key Start Len Index Type
Root Blocksize Rec/key
1 2
4
unique unsigned long
10240
1024
1
54272
1024
1
2
32
30 multip.text
Field
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

Start
1
2
6
10
11
31
32
62
97
132
167
171
187
222
226
242
262
282
302
332
336
340
341
349
357
365
367
369

Length
1
4
4
1
20
1
30
35
35
35
4
16
35
4
16
20
20
20
30
4
4
1
8
8
8
2
2
4

Type
constant
zerofill(l)
no zeros, zerofill(l)
table-lookup
no endspace,
no endspace,
no empty
no endspace,
zerofill(l)
no endspace,
no endspace,
zerofill(l)
no endspace,
no endspace,
no endspace,
no endspace,
no endspace,
always zero
always zero

not always
not always, no empty
not always, no empty
not_always, no empty
not always, no empty
not_always, no empty
not always
no empty
no empty
no empty

table-lookup
table-lookup
always zero
no zeros, zerofill(l)
no zeros, zerofill(l)

Huff tree Bits


1
0
2
9
2
9
3
9
4
0
3
9
5
9
6
9
7
9
6
9
2
9
5
9
6
9
2
9
5
9
8
9
8
9
5
9
6
9
2
9
2
9
3
9
0
9
10
0
2
9
2
9
2
9
2
9

465

466

7. MySQL
4
1
2
8
4
4
4
4
1
4
4
4
4
4
4
20
30
1
1
79
79
79
79
8
1
1
20
4
4

table-lookup
no zeros, zerofill(l)
no zeros
always zero
table-lookup
no zeros, zerofill(l)
no zeros, zerofill(l)

11
3
2
2
2
12
13
2

no zeros
always zero
no zeros
always zero
no zeros
always zero
no empty
no empty
no
no
no
no
no

endspace, no empty
empty
empty
endspace
empty

no empty
no zeros, zerofill(2)
no zeros, zerofill(l)

2
2
2
2
2
2
3
3
14
14
15
2
2
16
2
17
3
3
2
Csl

373
377
378
380
388
392
396
400
404
405
409
413
417
421
425
429
449
479
480
481
560
639
718
797
805
806
807
827
831

Csl

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

0
9
9
9
9
0
9
9
9
9
9
9
9
9
9
9
9
4
4
9
9
9
9
9
1
9
9
9
9

myisampack :
normal. , .
empty-space. , ; 1 .
empty-zero. , ; 1 .
empty-fill. ,
, ; . ,
BIGINT ( ) TINYINT ( ),
-128 127.
pre-space. , . .
end-space. , .
.
table-lookup. ,
. (Huffman) ENUM.

zero. , .

7.3. mysql

467

Original trees. .
After join. , .
, , myisamchk -dvv :
. . :

constant. .

no endspace. He .

no endspace, not_always. He
.

no endspace, no empty. He . .

table-lookup. ENUM.

z e r o f i l l ^ ) . .

no zeroes. He .

always zero. , .

Huff tree. , .

Bits. , .
, myisampack, myisamchk,
. , MySQL :
shell> myisamchk -rq sort-index analyze _ . MYI
ISAM.
packJLsam isamchk:
shell> isamchk -rq sort-index analyze _. ISM
MySQL mysqladmin flush-tables, mysqld .
, unpack
myisamchk isamchk.

7.3. mysql
mysql - SQL- ( GNU readline).
.
, ASCII-. (, ), , .
.
,
, quick. mysql , ,

468

7. MySQL

.
mysql_use_result () mysql_store_result ().
mysql . , :
s h e l l > mysql ___

s h e l l > mysql \1=_ password=napojib ___


SQL, ' ; ' , \ \G
<Enter>.
:
s h e l l > mysql ___ < s c r i p t . s q l > output.tab
mysql :

h e l p , - ? . .

batch, -. , ; .
mysql .

c h a r a c t e r - s e t s - d i r = n y T b . , .
. 4.7.1.

compress, -. ,
, .

databa=__, -D __. ,
. .

debug [=_],
_

-#

[_].

' d : t : o , _ \

'd:t:o,/tmp/mysql.trace 1 .

debug-info, -T.
.

default-character-set=Ha6op.
. . 4.7.1.

execute=onepaTop, -e . . , b a t c h .

f o r c e , -f. , SQL.

host=H/wi_xocTa, -h _. MySQL
.

--html, -H. HTML.

--ignore-space, - i . .
IGNORE_SPACE 4.2.2.

l o c a l - i n f i l e [ = {0 11} ]. LOCAL LOAD DATA


INFILE. , LOCAL.
--local-infile=0 ~ l o c a l - i n f i l e = l .
LOCAL , .

7.3. mysql

469

named-commands, -G. .
, , \*. ,
quit, /q.

no-auto-rehash, -. .
mysql ,
rehash, .

no-beep, -b. He .

no-named-commands, -g. . \*
, (;). MySQL 3.23.22, mysql , .
- .

no-pager. He . , 7.3.1.

no-tee. He .
7.3.1.

one-database, -0. , , . , , .

--pager[^]. . , PAGER.
less, more, cat [> filename] . Unix.
. 7.3.1.

pas sword [^], - []. . , (-), .


, .

=_, - _ . TCP/IP .

prompt^ _. .
mysql>. ,
, 7.3.1.

protocol={TCP I SOCKET | PIPE | MEMORY}. . MySQL 4.1.

--quick, -q. He ,
. , . mysql .

raw, -r. . batch.

reconnect. , .
. ,
skip-reconnect. MySQL 4.1.0.

470

7. MySQL

safe-updates, i-am-a-dummy, -U. UPDATE


DELETE, ,
. ,
, safe-updates . 7.3.3.

silent, -s. .
. ,
.

skip-column-names, -N. .

skip-line-numbers, -L. .
, ,
.

socket=nyTb, -S . , .

table, - t . .
,
.

tee=HM#_. . . 7.3.1.

--unbuffered, -n. .

=_, - _.
MySQL .

--verbose, -v. . . , . (, -v -v -v ).

version, -V. .

vertical, -E. .
, \G.

wait, -w. , , .

xml, -X. XML.

,
__ ^ :

connect_timeout. ( 0).

maxallowedpacket. ( 16 ).

m a x j o i n s i z e .
safe-updates ( 1 000 000).

n e t b u f f e r l e n g t h . TCP/IP (
16 ).

7.3. mysql

471

s e l e c t l i m i t . SELECT
safe-updates (go 1 000).

,
--set-1=_5= -0 _= . ,
MySQL 4.0, .
Unix mysql . .mysql J i i s t o r y . , MYSQL_HISTFILE.
,
,mysql_history, , :
MYSQLJilSTFILE /dev/null.
, .
,mysql_history, /dev/null:
shell> In -s /dev/null $HOME/.mysql_history
.

7.3.1. mysql
mysql SQL- . , mysql . , help \h
mysql:
mysql> help
MySQL commands:
(\h)
clear
(\c)
connect
(\r)
delimiter
edit
ego

(\d)
(\e)
(\G)

exit
go
help
nopager
notee
pager

(\q)
(\g)
(\h)
(\n)
(\t)
(\P)

print
prompt
quit
rehash
source

(\p)
(\R)
(\q)
(\#)
(\.)

Synonym for 4help'.


Clear command.
Reconnect to the server.
Optional arguments are db and host.
Set query delimiter.
Edit command with $EDITOR.
Send command to mysql server,
display result vertically.
Exit mysql. Same as quit.
Send command to mysql server.
Display this help.
Disable pager, print to stdout.
Don't write into outfile.
Set PAGER [to__pager] .
Print the query results via PAGER.
Print current command.
Change your mysql prompt.
Quit mysql.
Rebuild completion hash.
Execute an SQL script file.

7. MySQL

472

status
system
tee

(\s)
(\!)
(\T)

use

(\u)

MySQL:
p
(\h)
clear
(\c)
connect
(\r)
delimiter
edit
ego

(\d)
(\e)
(\G)

exit
go
help
nopager
notee
pager

(\q)
(\g).
(\h)
(\n)
(\t)
(\P)

print
prompt
quit
rehash
source

(\p)
(\R)
(\q)
(\#)
(\.)

status
system
tee

(\s)
(\!)
(\T)

use

(\u)

Takes a f i l e name as an argument.


Get status information from the server.
Execute a system shell command.
Set outfile [to__outfile] .
Append everything into given outfile.
Use another database.
Takes database name as argument.
' h e l p ' .
.
.
db host.
.
$EDITOR.
mysql,
.
mysql. To , quit.
mysql.
.
, stdout.
.
PAGER [to_pager].
PAGER.
.
mysql.
mysql.
.
SQL.
.
.
.
[to_outfile].
.
.
.

edit, nopager, pager system Unix.


status ,
. safe-updates, status
mysql, .
, tee. , , .
.
tee , tee. notee. tee
. tee , .
, tee ,
mysql .
Unix, less, more, pager.

7.3. mysql

473

, mysql PAGER .
pager
nopager. . , . , ,
, , stdout.
Unix, (), Windows . Windows
tee, ,
, pager.
pager:
, :
mysql> pager cat > /tmp/log.txt
, :
mysql> pager less -n -i -S
-S. . . -S less , .
-S less,
.
less:
shell> man less

:

mysql> pager cat | tee /drl/tmp/res.txt \


| tee /dr2/tmp/res2.txt | less -n -i -S
,
, /drl /dr2, less.
tee pager. tee pager, less, less . Unix- tee,
pager, mysql tee , tee
, Unix .
tee , , Unix-
tee, pager, .
, tee mysql. ,
, .

474

7. MySQL

MySQL 4.0.2, mysql> . , , :

\v

\d

\h

TCP/IP.

\U

u s e r_n ame @ h s t _ n ame.

\\

'V.

\t

( ).

\_

\R

24- .

12- .

, .

\Y

, .

\D

\s

\w

(, Tue,...).

am/pm.

\0

(Jan, Feb,...).

, .

' \ ' .
prompt , mysql
- mysql>.
:

. mysql, :
shell> export MYSQLJ>S1=" (\u@\h) [\d]> "

. [mysql] MySQL - /etc/my.cnf


.my. cnf . :
[mysql]
prompt=(\\u@\\h) [\\d]>\\_

7.3. mysql

475

, . , prompt
, , .
, . ( 3.3.2.) , . , \s
,
. , , ::>:
[mysql]
prompt="\\r:\\m:\\s> "
.
prompt mysql, :
shell> mysql --prompt=" (\u@\h) [\d]> "
{) [__] >
. , prompt ( \R), :
mysql> prompt (\u@\h) [\d]>\_
PROMPT set to '(\u@\h) [\d]>\_'
{) [^]>
{) [_]> prompt
Returning to default PROMPT of mysql>
mysql>

7.3.2. SQL-
mysql :
shell> mysql __
SQL- ,
mysql . , _, . mysql,
:
shell> mysql __ < _
USE __.
:
shell> mysql < ^
mysql , SQL-,
source, \.:
mysql> source _;
mysql> \. _

7. MySQL

476

7.3.3. mysql
, mysql
.
7.3.3.1.
,
, . , , ,
:
m y s q l > SELECT * FROM m a i l s WHERE LENGTH(txt) < 300 LIMIT 300,1\G
***************************
i# r o w
***************************

msg_nro:
date:
time_zone:
mail_from:
reply:
mail_to:
sbj:
txt:

3068
2000-03-01 23:29:50
+0200
Monty
monty@no.spam.com
"Thimble Smith" <tim@no.spam.com>
UTF-8
> "Thimble" == Thimble Smith writes:

Thimble> Hi. I think this is a good idea. Is anyone familiar


Thimble> with UTF-8 or Unicode? Otherwise, I'll put this on my
Thimble> TODO list and see what happens.
Yes, please do that.
Regards,
Monty
file: inbox-jani-1
hash: 190402944
1 row in set (0.09 sec)
7.3.3.2. - -safe-updates
--safe-updates ( i-am-a-dummy) .
MySQL 3.23.11. , DELETE FROM __ WHERE.
. --safe-updates
, . .
--safe-updates, mysql
:
SET SQL_SAFE_UPDATES=l,SQL_SELECT_LIMIT=1000,

SQL_MAX_JOIN_SIZE=1000000;

SET :
UPDATE DELETE,
WHERE
LIMIT ( ). :
UPDATE _ SET not_key_column=# WHERE key_column=#;
UPDATE _ SET not_key_column=# LIMIT 1;

7.4. MySQL- mysqladmin

477

SELECT 1000 ,
LIMIT.
SELECT, 1 000 000 , .
, 1000 1000000,
, select_limit max_join_size:
shell> mysql --safe-updates --select_limit=500 --max_join_size=10000

7.3.3.3. mysql
mysql ,
. mysql , , :
, ,
. - , , :
mysql> SET @a=l;
Query OK, 0 rows affected (0.05 sec)
mysql> INSERT INTO t VALUES(@a);
ERROR 2006: MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1
Current database: test
Query OK, 1 row affected (1.30 sec)
mysql> SELECT * FROM t;
I a
|
+
+
| NULL |

1 row in set (0.05 sec)


@ ,
. , mysql
,
skip-reconnection.

7.4.
MySQL- mysqladmin
mysqladmin - ,
.
, , .
mysqladmin :
s h e l l > mysqladmin

[]

[-]

mysqladmin :

...

478

7. MySQL

create ___. .

drop __. .

extended-status. .

flush-hosts. .

flush-logs. .

flush-privileges. ( , reload).

flush-status. .

flush-tables. .

flush-threads. ( MySQL 3.23.16).

k i l l , ,.... .

password -. . ,
mysqladmin.

ping. , .

processlist. . ,
SHOW PROCESSLIST. verbose,
SHOW FULL PROCESSLIST.

reload. ( , flush-privileges).

refresh. , .

shutdown. .

s t a r t - s l a v e . (
MySQL 3.23.16).

status. .

stop-slave. (
MySQL 3.23.16).

variables. .

version. .

. :
shell> mysqladmin proc stat
+
+
+
+
+
+
+
+
+
I Id | User | Host
| db | Command
| Time | State I Info |
I 6 | monty | localhost I
I Processlist | 0
|
+
+
+
+
+
+
+
Uptime: 10077 Threads: 1 Questions: 9 Slow queries: 0
Opens: 6 Flush tables: 1 Open tables: 2
Memory in use: 1092K Max memory used: 1116K
status mysqladmin :

Uptime. .

Threads. ().

I
+

|
+

7.4. MySQL- mysqladmin

479

Questions. .
Slow queries. ,
long_query_time .
Opens. , .
Flush tables. flush . . . , refresh
reload.
Open tables. , .
Memory in use. ,
mysqld. , MySQL
--with-debug-full.
Maximum memory used. , mysqld. , MySQL
with-debug-full.
mysqladmin shutdown,
Unix, mysqladmin , , , .
mysqladmin :
help, -?. .
character-sets-dir=nyTb. , .
. 4.7.1.
compress, -. , , .
count=#, - #. , .
sleep (-i).

debug[=__], -# [^]. .
_ 'd:t:o,_*.
'd:t:,/tmp/mysqladmin.trace'.

force, -f. He drop database.


.

host=HM#_xocTa, -h __. MySQL .


password[=], -[]. . , (-), .
, .
t=HOMep_nopTaf - . TCP/IP .
protocol={TCP I SOCKET I PIPE | MEMORY}. . MySQL 4.1.
r e l a t i v e , -. ,
-i.

extended-status.

480

7. MySQL

silent, -s. ,
.

si 1=, - i .
.

socket=nyTb, -S . , .

=_, - _.
MySQL .

verbose, -v. . .

version, -V. .

vertical, -E. . relative,


.

wait [=#], -w [#]. , , . , ( 1).

_=
:

connect __timeout. ( 0).

shutdown_timeout. ( 0).

, set-variable=
_= -0 _=. ,
MySQL 4.0, .

7.5.
mysqlbinlog
, ,
. mysqlbinlog.
, MySQL 3.23.14.
mysqlbinlog :
shell> mysqlbinlog [] - . . .
,
:
shell> mysqlbinlog binlog.0000003

binlog.000003,

, binlog.000003, , ,
, , .
mysqlbinlog
MySQL.
, read-f romremote-server. ,
, ,
.

7.5. mysqlbinlog

481

, , , ,
read-from-remote-server. : host,
password, port, protocol, socket user.
mysqlbinlog , . ,
.
4.8.4.
mysqlbinlog :
help, -?. .
databa=:__, -d __. , ( ).
force-read, -f. .
host=HM#_xocTa, -h _. MySQL
.
local-load=nyTb, -1 . LOAD DATA INFILE.

of f set=N, -o N. N .

pas sword [=], -[]. . , (-), .


, .
port=HOMep_nopTa, -P _. TCP/IP .
position=N, - j N. N.
protocol={TCP I SOCKET | PIPE I MEMORY}. . MySQL 4.1.
read-from-remote-server, -R. MySQL. , . host, password, port, protocol,
socket user.

r e s u l t - f -=, - . .

short-form, -s. , , .
--socket=nyTb, -S . , .
-_9 - _.
MySQL .
version, -V. .
_=
:
open_files_limit.
.

482

7. MySQL

mysqlbinlog mysql,
, . , (. 4.6.1):
shell> mysqlbinlog ^-. 000001 | mysql

shell> mysqlbinlog _-. [0-9]* | mysql


mysqlbinlog , (,
, - ).
, mysql.
mysqlbinlog --position, ,
.
, MySQL, , ,
. , ,
:
shell> mysqlbinlog _-.000001 | mysql # !!
shell> mysqlbinlog _-.000002 | mysql # !!
, , , CREATE TEMPORARY TABLE,
- , .
mysql , .
, " ".
, . :
shell> mysqlbinlog __-. 000001 ^-. 000002 | mysql
:
shell> mysqlbinlog _-bin.000001 > /tmp/statements.sql
shell> mysqlbinlog _-.000002 /tmp/statements.sql
shell> mysql -e "source /tmp/statements.sql"
MySQL 3.23 LOAD DATA INFILE.
. MySQL 4.0.14, , mysqlbinlog , LOAD DATA INFILE, .
mysqlbinlog LOAD DATA INFILE,
. , ,
. , local-load.

7.6. MySQL mysqlcc

483

mysqlbinlog LOAD DATA INFILE LOAD DATA LOCAL


INFILE ( , LOCAL), , , , , LOCAL.
|

, LOAD DATA INFILE, ,


, .
, .
___ - # - #.

, mysqlbinlog mysqld.
LOAD DATA INFILE.
MySQL 4.1 mysqlbinlog ,
mysql, , , . MySQL 4.1
.

7.6. MySQL mysqlcc


MySQL, mysqlcc, -
, MySQL. , . , .
mysqlcc MySQL, http://dev.mysql.com/downloads/. mysqlcc Windows Linux.
mysqlcc, . :
shell> mysqlcc []
mysqlcc :

--help, -?. .

blocking-queries, -b. .

compress, -. ,
, .
connection-name=HM#, - . server.

databa=__, -d __. . .

--history-size=#, -H #. .

--host=HM#_xocTa, -h __. MySQL .


local-infile[ = {0|l}]. LOCAL LOAD DATA
INFILE. , LOCAL.

484

7. MySQL
local-infile=0 local-infile=l.
LOCAL , .

pass word [-], -[]. . ,


(-), .
, .
plugins_path=MM#, -g . ,
MySQL.
port=HOMep_nopTa, -P ^. TCP/IP .
query, -q. .
register, -r. Register Server (
).
server=HM*, -s . MySQL.
socket=nyTb, -S . , .
syntax, -. .
syntax_f =, -Y . .
translationj?ath=HM#, -T . ,
MySQL.

=__, - _.
MySQL .

version, -V. .
_=
:
connect_timeout. ( 0).
max_allowed_packet. ( 16 ).
max_join_size.
--safe-updates ( 1 000 000).
net_buffer_length. TCP/IP (
16 ).
select_limit. SELECT
safe-updates ( 1 000).
,
set-variable=_= -0 _=. ,
MySQL 4.0, .

7.7. mysqlcheck

485

7.7.
mysqlcheck
mysqlcheck MylSAM.
, mysqlcheck ,
MySQL 3.23.38.
mysqlcheck myisamchk, .
, mysqlcheck
mysqld, myisamchk - . mysqlcheck ,
.
mysqlcheck SQL- CHECK TABLE, REPAIR TABLE, ANALYZE TABLE
OPTIMIZE TABLE . ,
,
.
mysqlcheck:
shell> mysqlcheck [] _6_ []
shell> raysqlcheck [] databases _1 [__2 _...]
shell> mysqlcheck [] all-databases
--databases
all-databases, .
mysqlcheck , . (check)
. , , mysqlcheck mysqlrepair mysqlrepair, mysqlcheck. mysqlrepair, .
mysqlcheck
:
mysqlrepair
repair,
mysqlanalyze
analyze,
mysqloptimize
optimize.
mysqlcheck :

help, -?. .

all-databases, -. .

all-in-1, - 1 . , ,
, .

analyze, -. .
--auto-repair. , . , .

character-sets-dir=nyTb. , .
. 4.7.1.

486

7. MySQL

--check, -. .

check-only-changed, -. ,
.

compress. , , .

databases, -. . , .

debug[=_], -# [_]. .
_ ' d: t : , _'.

default-character-set=Ha6op.
. . 4.7.1.

extended, -e. , , 100% ,


.
,
, ,
"" .

--fast, -F. , .

force, -f. SQL.

host=HM*_xocTa, -h _. MySQL
.

medium-check, -m. , ,
extended. 99,99% ,
.

optimize, -. .

--password[^], -[]. . ,
(-), .
, .

port=_, - _. TCP/IP .

protocol={TCP | SOCKET | PIPE | MEMORY}. . MySQL 4.1.

quick, -q. , .
.
, . .

repair, -r. , ,
, - .

silent, -s. .
, .

7.8. mysqldump

487

socket=nyTb, -S . , .

tables. --databases -.
.

use=_, - _.
MySQL .

verbose, -v. .
.

--version, -V. .

7.8.
mysqldump
mysqldump

SQL- ( MySQL). SQL-,
/ .
,
mysqlhotcopy mysqldump. . 7.9.
mysqldump:
s h e l l > mysqldump [] __ []
shell> mysqldurap [] databases _1 [_2 _...]
shell> mysqldurap [] all-databases
databases a l l databases, .
,
mysqldump, mysqldump help.
mysqldump quick opt, mysqldump , .
, . MySQL 4.1,
opt , --skip-opt.
mysqldump , MySQL, opt - .
, , inf -inf,
NaN (not-a-number), mysqldump NULL. , :
mysql>
mysql>
mysql>
mysql>

inf
-inf

CREATE TABLE t (f DOUBLE);


INSERT INTO t VALUES(le+111111111111111111111);
INSERT INTO t V A L U E S ( - l e l l l l l l l l l l l l l l l l l l l l l ) ;
SELECT f FROM t ;

7. MySQL
mysqldump :
%
INSERT INTO t VALUES (NULL);
INSERT INTO t VALUES (NULL);
,
, .
mysqldump :

help, -?. .

add-drop-table. CREATE TABLE DROP


TABLE.

add-locks. LOCK TABLE UNLOCK


TABLE. , . .
6.2.12.

--all-databases, -. . , databases .

all-keywords. ,
. ,
- .

comments [ = {011} ]. 0,
. , , . --skip-comments , --comments=0. 1, . MySQL 4.0.17.

compatible-name=HM*. , MySQL.
mysql323, mysql40, postgresql, oracle,
mssql, db2, sapdb, no_key_options, no_table_options no_field_options. , . , , SQL . . 4.2.2.
MySQL 4.1.0 .
.

complete-insert, -. INSERT, .

compress, -. ,
, .

create-options. MySQL
CREATE TABLE. MySQL 4.1.2 all.

7.8. mysqldump

489

--databases, -. .
. . . USE
__ .
debug [=_], -# [_]. .
_ ' d: t : , _'.
default-character-set=Ha6op.
. . 4.7.1. ,
MySQL 4.1.2, utf 8; lati.nl.

delayed. , INSERT DELAYED.

delete-master-logs.
.
f i r s t - s l a v e . MySQL 3.23.57 ( MySQL 3.23)
MySQL 4.0.13 ( MySQL 4.0).
disable-keys, -. INSERT
/ * ! 40000 ALTER TABLE ^ DISABLE KEYS */ / * ! 40000 ALTER TABLE

_ ENABLE KEYS */.


MySQL, .
My ISAM.
extended-insert, -e. INSERT, VALUES. .
fields-terminates-by=...
fields-enclosed-by=...
fields-optionally-enclosed-by=...
fields-escaped-by=...
fields~terminated-by=...
- , LOAD DATA INFILE.

f i r s t - s l a v e , -x. .

flush-logs, -F.
. , a l l databases ( -),
.

force, -f. ,
SQL.

host=HM*_xocTa, -h _. MySQL, ( localhost).


lock-tables, -1. . READ LOCK,
My ISAM.
,
. ,

490

7. MySQL
.
.

master-data. first-slave,
CHANGE MASTER TO,
,
SQL- .

no-create-db, -. CREATE DATABASE /* 132312


IF NOT EXISTS*/ __,
, databases all-databases.

no-create-info, -t. He CREATE TABLE, .

no-data, -d. He . ,
.

opt. ; ,
quick add-drop-table add-locks create-options disable-keys
extended-insert --lock-tables. ,
MySQL. MySQL 4.1, --opt ,
skip-opt. , opt,
skip. , skip-add-drop-table skip-quick.

password [^], -[]. . ,


(-), .
, .

t=HOMep_nop, - __. TCP/IP .

protocol={TCP I SOCKET | PIPE | MEMORY}. . MySQL 4.1.

quick, -q. .
mysqldump ,
.

--quote-names, -Q. , ' N '.


SQL- ANSI_QUOTES,
. MySQL 4.1.1, quote-names
.

result-file=$awi, -r . .
Windows,
\' '\\' ( , ).

single-transaction. SQL- BEGIN


. innoDB READ COMMITED,
,
BEGIN, .

7.8. mysqldump

491

,
. ,
MylSAM HEAP .
single-transaction MySQL 4.O.2.
lock-tables , LOCK TABLES .

socket=nyTb, -S . ,
localhost ( ).

tab=nyrb, -T . -.
mysqldump _. sql,
CREATE TABLE, _. txt, . - , .
.txt
. f ields lines-xxx.

j? , mysqldump , mysqld. MySQL FILE, a


, .

--tables. --databases -. ,
, .

=_, - __.
MySQL .

--verbose, -v. . .

version, -V. .

where='_*/', -w _where*. , WHERE. , , , .


:
"where=user='jimf'"
"-wuserid>l"
"-wuserickl"

xml, -X. XML-.

_=
:
max_allowed_packet. - . 16
MySQL 4.0 1 - 4.0 .

492

7. MySQL
(
--extended-insert --opt), mysqldump
max_allowed_packet. ,
, max_allowed_packet , , .

n e t b u f fer_length. - .

set-var 1=__= - _= .
, MySQL 4.0, .
, mysqldump :
shell> mysqldump opt __ > backup-file. sql
:
shell> mysql __ < backup-file.sql

shell> mysql -e "source /---/backup-file. sql" ___


mysqldump MySQL :
shell> mysqldump opt __ | mysql hos=- - \
_ __

:
shell> mysqldump databases __1 [__2 . . . ] > \
my__databases. sql
, all-databases:
shell> mysqldump all-databases > all_databases.sql

4.6.1.

7.9.
mysqhotcopy
mysqhotcopy - Perl, LOCK TABLES, FLUSH
TABLES scp .
,
, .
mysqhotcopy My ISAM ISAM
Unix , MySQL 4.0.18, NetWare.
shell> mysqlhotcopy __ [///_)
shell> mysqlhotcopy ___1...___ ///_
shell> mysqlhotcopy __./_/
mysqhotcopy :

7.10. mysqlimport

493

h e l p , - ? . .

allowold. He , ( _old).

1^=__._.
__. _.

debug. .

dryrun, -n. .

f l u s h l o g . , .

keepold. He ()
.

method=#. ( scp).

n o i n d i c e s . He .
. myisamchk
- r q isamchk -rq.

password[=], -[]. . , MySQL, .

port=HOMep_nopra, -P _ . TCP/IP .

q u i e t , -q. , .

--=. ,
.

socket=nyTb, -S . Unix, .

suf f =. .

tmpdir=nyTb. ( /tmp).

=_, - __.
MySQL .

mysqhotcopy [ c l i e n t ] [mysqhotcopy]
.
mysqhotcopy, ,
, SELECT RELOAD ( FLUSH TABLES).
p e r l d o c
mysqhotcopy:

shell> perldoc mysqlhotcopy

7.10. mysqlimport
mysqlimport
SQL- LOAD DATA INFILE. mysqlimport
LOAD DATA INFILE.

494

7. MySQL

mysqlimport :
shell> mysqlimport [] __ ^! [_2...]
, , mysqlimport
,
. , p a t i e n t . t x t ,
p a t i e n t . t e x t p a t i e n t p a t i e n t ,
mysqlimport :

h e l p , - ? . .

col=_, - ^. , .
.

compress, -. ,
, .

debug [=_], -# [__]. .


_ ' d: t : , _'.

d e l e t e , -D. .

fields-terminates-by=...
fields-enclosed-by=...
fields-optionally-enclosed-by=...
fields-escaped-by=...
fields-terminated-by=...
- , LOAD DATA INFILE.

f o r c e , -f. . , , .
.

host=HM#_xoccra, -h _. MySQL ( l o c a l h o s t ) .

i g n o r e , - i . . r e p l a c e .

i g n o r e - l i n e s = n . .

l o c a l , -L. . ,
, l o c a l h o s t (
).

- - l o c k - t a b l e s , - 1 .
. , .

password[=], -[]. . ,
(-), .
, .

1=_ - _. TCP/IP .

protocol={TCP I SOCKET | PIPE | MEMORY}. . MySQL 4.1.

7.11.

, mysqlshow

495

--replace, -. replace ignore


,
. --replace,
. ignore,
. ,
, , .

silent, -s. .
.

socket=nyrb, -S . , .

=_, - __.
MySQL .

verbose, -v. . .

version, -V. .

mysqlimport:
shell> mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))'
shell> ed
a
100 Max Sydow
101 Count Dracula

test

w imptest.txt
32
q
shell> od -c imptest.txt
0000000
0000020
0000040

1 0 0
\ t M
1 \ t C o u n

a
t

S
D

y
r

o
a

w
c

\ n1
0
a \ n

shell> mysqlimport local test imptest.txt


test.imptest: Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
shell> mysql -e 'SELECT * FROM imptesf test
I id
+
I 100
I 101
+

7.11.

|n
I
+
+
| Max Sydow
|
| Count Dracula |
+
+

,
mysqlshow

mysqlshow
, , .
mysqlshow SQL-
SHOW. , , mysql.

496

7. MySQL

mysqlshow :
shell> mysqlshow [] [__ [_ [_]]]
, .
, .
,
.
, MySQL ,
, .
SQL ('*','?','%' '_'), , .
,
( Unix ),
. '*' '?'
SQL '%' '_'. , '_' , mysqlshow
, . ,
'%' .
mysqlshow :

--help, -?. .

character-sets-dir=nyTb. , .
. 4.7.1.
compress, -. ,
, .
debug [=_], -# [_]. .
_ 'd: t:,_'.

default-character-set= .
. . 4.7.1.
~host=MM_xocTa, -h _. MySQL .

keys, -. .

--password[=], -[ ]. . ,
(-), .
, .
port=HOMep_nopra, -P _. TCP/IP .

--protocol={TCP | SOCKET | PIPE | MEMORY}. . MySQL 4.1.


socket=nyib, -S . , .

status, -i. .

=_, - _.
MySQL .
verbose, -v. . . , .

7.13. replace

497

version, -V. .

7.12. perror

MySQL :
... (errno: #)
... (Errcode: #)
, ,
perror.
perror . perror :
s h e l l > perror [] _ . . .

:
shell> perror 13 64
Error code 13: Permission denied
Error code 64: Machine is not on the network
, . .

7.13. replace
replace . .
, . , b f i l e l f ile2:
shell> replace a b b a f i l e l f i l e 2 ...
, ,
.
, , ,
, .
, replace
. .
replace msql2mysql :

-?, - I . .

-# _. . _
' d: t : , _'.

-s. .
, .

-v. . ,
.

-V. .


MySQL

ySQL , . MySQL ,
:
ISAM, .
My ISAM . MySQL 4.1 , MySQL
5.0 .
MySQL 3.23.0 MylSAM
HEAP. MylSAM ISAM. HEAP " "
(in-memory table). MySQL 3.23.25 MERGE, MylSAM . MySQL .
HEAP MEMORY.
innoDB BDB,
, MySQL 3.23.
MySQL 3.23.34. BDB
MySQL-Max , . InnoDB MySQL-Max
MySQL 3.23. MySQL 4.0, InnoDB . , MySQL , .
MySQL,
InnoDB, 9.
MySQL ,
. CREATE TABLE
ENGINE TYPE:

8.1. MylSAM

499

CREATE TABLE t (i INT) ENGINE = INNODB;


CREATE TABLE t (i INT) TYPE = MEMORY;
ENGINE ,
MySQL, 4.0.18. TYPE , MySQL 3.23.0 - MySQL, .
ENGINE TYPE, My ISAM.
, , table_type.
ALTER
TABLE, :
ALTER TABLE t ENGINE = MYISAM;
ALTER TABLE t TYPE = BDB;

^ ,
, MySQL My ISAM. ,
MySQL, . (,
, -
.)
, My ISAM MySQL. MySQL 4.1 .
MySQL . f rm,
.
, . . f rm
. , , .
() .
(Non-Transaction-Safe
Table - NTST) (Transaction-Safe Table - TST),
:
. MySQL
, .
COMMIT ( , ).
ROLLBACK ( , ).
, . (
.)
, .

500

8. MySQL

, innoDB MySQL 3.23, , , innodb_data_file_path.


4.0, InnoDB , ( ).
. 9.4.
,
:
.
.
.
,
. , , .

8.1. MylSAM
MySQL 3.23 My ISAM .
ISAM .
My ISAM ,
, . . f rm , .MYD (MYData),
.MYI (MYIndex).
, My ISAM, ENGINE TYPE:
CREATE TABLE t (i INT) ENGINE = MYISAM;
CREATE TABLE t (i INT) TYPE = MYISAM;
. My ISAM
, .
My ISAM
myisamchk (. 4.6.2.7). myisampack MylSAM,
(. 7.2).
ISAM MylSAM :
,
.
, ,
( , ),
IEEE ( ). ,
.

8.1. MylSAM

501

; ,
. ,
, , - .

, ( 63 ); , .

, .

.
64 (
MySQL 4.1.2 32).
. 16.
1000 ( MySQL 4.1.2
500). .
250 ,
( 1024 ).
BLOB TEXT.
NULL.
0-1 .

,
.

My ISAM , ISAM.
, My ISAM
, ISAM,
My ISAM .
(
AUTOINCREMENT) ,
.
.

AUTO_INCREMENT.
My ISAM
INSERT/UPDATE, AUTO_INCREMENT
( 10%). , ISAM. ( , AUTO_INCREMENT
.) AUTO_INCREMENT ALTER TABLE myisamchk.

,
INSERT ,
. ( -

8. MySQL

502

.)

. ()
, .
,
( DATA DIRECTORY INDEX
DIRECTORY CREATE

TABLE).

MySQL 4.1 .
My ISAM , ,
. mysqld
--myisam-recover, MylSAM ( ),
.
myisamchk ,
update-state. fast,
, .
analyze myisamchk
, , ISAM.
myisamchk BLOB VARCHAR;
pack_isam- .
My ISAM , MySQL :
VARCHAR; VARCHAR , .
VARCHAR , .
VARCHAR CHAR 64 .
UNIQUE .
UNIQUE . (
,
UNIQUE.)

8.1.1. MylSAM
MylSAM mysqld:

my is am- re cove =.
MylSAM.

delay-key-write=ALL.
MylSAM.

MylSAM (, % MySQL myisamchk) . f; .

8.1. MylSAM

503

external-locking ,
delay-key-write.
. 4.2.1.
My ISAM :
bulk_insert_buffer__size. ,
.

myisam_max_extra_sort_file_size. , MySQL
, ,
.
|

&

MySQL 4.0.3 ,
- .

m y i s a m m a x s o r t f i l e s i z e . , ,
, .
!
*/* MySQL 4.0.3 ,
|% - .

myisam_sort_buf fer_size. , .
. 4.2.3.
raysqld
myisam-recover. , MylSAM,
, ,
skipexternal-locking. , :
.
, ( , ).
(, - ), , .
,
( ).
.

, --myisam-recover FORCE,
:
Error: Couldn't repair table: test.gOOpages

504

8. MySQL

: : test.gOOpages
FORCE, :
Warning: Found 344 of 354 rows when repairing ./test/gOOpages
: 344 354 ./test/gOOpages
,
BACKUP, ,
_-- .. .

8.1.2. ,
My ISAM -. [_+4) /0.67, . , .
. , * ,
, ,
VARCHAR, . , .
MylSAM .
PACK_KEYS=1.
,
.

8.1.3. MylSAM
My ISAM . ( )
. , ,
myisampack.
CREATE ALTER ,
BLOB TEXT, ROW_FORMAT
FIXED DYNAMIC. CHAR VARCHAR CHAR
FIXED VARCHAR DYNAMIC.
, ALTER TABLE ROW_FORMAT={COMPRESSED | DEFAULT}.
8.1.3.1.
( )
MylSAM . ,
( VARCHAR, BLOB TEXT). .

8.1. MylSAM

505

My ISAM (
). ,
. , : . ,
.
, MySQL My ISAM . myisamchk ,
. , My ISAM .
:
CHAR, NUMERIC DECIMAL
.
.
.
( , ).
, . OPTIMIZE TABLE myisamchk -r.
,
.
8.1.3.2.
, My ISAM (VARCHAR, BLOB TEXT) ROW_FORMAT=DYNAMIC.
, ,
. , , .
OPTIMIZE TABLE
myisamchk. , , ,
.
:
,
4.
, ,
( ) (
). , ,
NULL. -

8. MySQL

506

, ,
. .
,
.
, .
, ,
. ,
, , .
OPTIMIZE TABLE myisamchk -,
.
myisamchk -ei.
, ,
; , (
).

:
3
+
+
+
+
+

{ + 7) / 8
{ )
{ )
{ )
{ NULL + 7) / 8

6 .
.
20 ,
.
. myisamchk -ed.
myisamchk -r.
8.1.3.3.
myisampack.
3.23.19, MySQL myisampack.
( MySQL GPL.) myisampack
; , ,
myisampack. myisamchk. ( ISAM
pack_isam isamchk.)
:
. , (, -).

8.1. MylSAM

507

,
. (1-3 ), . -. . :

.
.
.
,
. , BIGINT ( ) TINYINT (
), -128 127.

,
ENUM.

.
.

8.1-4. , MylSAM
, MySQL , , ,
.
8.1.4.1. MylSAM
MylSAM ( , SQL, , ), .
:
mysqld.
.
.
, ,
(, myisamchk).
MySQL MylSAM.
:

:
Incorrect key f i l e for table: ' . . . ' . Try to repair i t
: ' . . . ' .

.
CHECK TABLE. MylSAM REPAIR TABLE. -

508

8. MySQL

mysqld , myisamchk. . 4.6.2.1.


, . , ,
. :
restarted mysqld, ,
. , .
,
. . .4.2.
8.1.4.2. ,
My ISAM (.MY I) ,
. CHECK TABLE myisamchk :
clients are using or haven't closed the table properly

, . ,
, .
:
MySQL
.
.
(
FLUSH TABLES ), , .
,
, .
, , ,
.
, :
My ISAM LOCK TABLES FLUSH TABLES.
MySQL . (
, , MySQL
, .)
myisamchk --recover
myisamchk --update-state , mysqld.
mysqld;
REPAIR TABLE CHECK TABLE,
. CHECK TABLE, -

8.2. MERGE

509

. REPAIR TABLE, .
, . 4.9.

8.2. MERGE
MERGE MySQL 3.23.25. MRG__MyISAM.
.
MERGE ,
My ISAM, . "" , .
, - ,
.
myisampack. . 7.2.
MERGE MySQL .
, .
. frm , .MRG ,
. (
, MERGE. MySQL 4.1.1.)
, MERGE, SELECT, DELETE,
UPDATE ( MySQL 4.0) INSERT. ,
, MERGE.
MERGE DROP,
MERGE. , MERGE, .
MERGE UN ION=( - ),
, . ,
MERGE
UNION, INSERT_METHOD .
N0,
MERGE .
MERGE:
mysql> CREATE TABLE t l (
->
->

a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,


m e s s a g e CHAR(20));

mysql> CREATE TABLE t 2 (


->
->

a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,


m e s s a g e CHAR(20));

mysql> INSERT INTO t l (message) VALUES ( ' T e s t i n g ' ) , ( ' t a b l e ' ) , ( ' t l ) ;
mysql> INSERT INTO t2 (message) VALUES ('Testing),('table'),('t2');
mysql> CREATE TABLE t o t a l (
->
a INT NOT NULL AUTO_INCREMENT,
->
m e s s a g e CHAR(20), INDEX(a))
-> TYPE=MERGE U N I O N = ( t l , t 2 ) INSERT METHOD=LAST;

510

8. MySQL

, MERGE , PRIMARY KEY, My ISAM. ,


MERGE ,
.
MERGE, :
mysql> SELECT * FROM total;
++
+
I a | message |
++
+
1 | Testing |
2 | table
|
3 I tl
|
1 | Testing |
2 | table
|
3 I t2
I
+ +
+
, .MRG
MySQL:
shell> cd /__1/__
shell> Is -1 tl t2 > total.MRG
shell> mysqladmin flush-tables
My ISAM MERGE, :
DROP .
ALTER TABLE _ UNION= (...)
, .
. MRG FLUSH TABLE MERGE
, .
MERGE:
. , ,
, myisampack MERGE,
.
.
. MERGE
, . (
, RAID.)
. , ,
, , MERGE .
MERGE
.

8.2. MERGE

511

.
, MERGE, .

. MERGE
,
. , MERGE. (, MERGE , .)

, , MERGE . , ,
.

MERGE .
My ISAM, My ISAM - .
My ISAM ,
MERGE, .
( memcpy () ).
MERGE:
MERGE My ISAM.

MERGE . 10 MERGE, 10 ,
(10* 10)+10 . (10
10 10 ,
.)

. MERGE
, , .
, MERGE , .
. MERGE eq_ref,
ref. eq_ref ref 6.2.1.

8.2.1. , MERGE
MERGE :

ALTER TABLE MERGE


, .
My ISAM ,
.

512

8. MySQL

MySQL 4.1.1 MERGE


.

REPLACE .

DROP TABLE, ALTER TABLE DELETE FROM WHERE, a REPAIR TABLE, TRUNCATE TABLE, OPTIMIZE TABLE ANALYZE
TABLE , MERGE, , , "".
, MERGE, , , . FLUSH TABLES,
"" MERGE.

MERGE UNIQUE . INSERT My ISAM ( ,


INSERTMETHOD). MySQL ,
My ISAM, , .

MySQL 3.23.49 DELETE FROM ^


WHERE . , .MRG.

RENAME TABLE MERGE


. MySQL
4.1.x.

MERGE, , , .
MERGE, MySQL , , , , . MERGE My ISAM,
.
MERGE . ALTER TABLE UNIQUE , MERGE, ALTER TABLE MERGE,
, , MERGE,
. ( - , ALTER
TABLE UNIQUE , .) .
DROP TABLE, ,
MERGE, Windows, MERGE MySQL. Windows ,
MERGE ( FLUSH TABLES) MERGE,
. .

8.3. MEMORY (HEAP)

513

8.3.
MEMORY (HEAP)
MEMORY , . MySQL 4.1, MEMORY HEAP, MEMORY.
MEMORY .
. f rm, ,
. , MEMORY,
ENGINE TYPE:
CREATE TABLE t (i INT) ENGINE = MEMORY;
CREATE TABLE t (i INT) TYPE = HEAP;
MEMORY . . -
, MEMORY, .
, . f rm , .
, MEMORY:
mysql> CREATE TABLE t e s t TYPE=MEMORY
-> SELECT ip,SUM(downloads) AS down
-> FROM log_table GROUP BY ip;
mysql> SELECT COUNT(ip),AVG(down) FROM t e s t ;
mysql> DROP TABLE t e s t ;
MEMORY :
MEMORY .
100%- (
). MEMORY
.
. . MEMORY
,
.
MEMORY 32 , 16 ,
500 .
MySQL 4.1 MEMORY
. MySQL 4.1,
, USING
, MEMORY HASH BTREE:
CREATE TABLE
(id

INT,

lookup
INDEX USING HASH

(id))

ENGINE = MEMORY;
CREATE
(id

TABLE
INT,

lookup
INDEX USING BTREE

ENGINE = MEMORY;

(id))

514

8. MySQL
- ,
6.4.5.

MEMORY ( ).
MEMORY ( ) , , ,
. ( ).
BTREE.
MEMORY .
MEMORY BLOB TEXT.

MEMORY AUTO_INCREMENT.

MySQL 4.0.2 MEMORY


, NULL.

MEMORY ( ).

MEMORY,
, ,
, . , " " (on-disk table), .
tmp_table_size.
MEMORY .
, tmp_table_size , MEMORY.
MAX_ROWS CREATE TABLE.
MEMORY,
.
, MEMORY,
, DELETE
TRUNCATE_TABLE, DROP TABLE.

MEMORY
MySQL, i n i t - f i l e . ,
INSERT INTO. . .SELECT LOAD DATA INFILE. . 4.2.1.

, MEMORY, , .
, ,
. MySQL 4.0.18, MEMORY

8.4. BDB (BerkleyDB)

515

, DELETE FROM ,
. ,


. MEMORY
i n i t - f i l e ,
.
, MEMORY, :
SUM_OVER_ALL_KEYS(max_length_of_key + sizeof(char*) * 2)
+ ALIGN(length_of_row+l, sizeof(char*))
ALIGN () ,
char. sizeof (char*) 4
32- 8 64-.

8.4. BDB
(BerkleyDB)
Sleepycat Software MySQL Berkley DB,
BDB .
MySQL, 3.23.34, MySQl-Max.
BDB .
COMMIT ROLLBACK . MySQL BDB, ,
MySQL. BDB MySQL .
MySQL AB
Sleepycat,
MySQL/BDB. ( Berkley DB,
MySQL - , .)
BDB,
.
Sleepycat, , , . , BDB ,
. ,
- , Berkley DB , MySQL. . 1.4.1.
Berkley DB Sleepycat
http://www.sleepycat.com.

8. MySQL

516

8.4.1. , BDB
BDB :
Linux 2.x Intel

Sun Solaris (SPARC 86)

FreeBSD4.x/5.x(x86, sparc64)
IBM AIX 4.3.x

SCO OpenServer

SCO UnixWare 7.1.x

BDB
:
Linux 2.x Alpha
Linux 2.x AMD64
Linux 2.x IA-64

Linux 2.x s390

Mac OS X

]*; !
f*

%\ . , '. .

MySQL
BDB, mysqld , , BDB :
bdb: architecture lacks fast mutexes: applications cannot be threaded
Can't i n i t databases
bdb: :


MySQL BDB skip-bdb.

8.4.2. BDB
MySQL,
Berkley DB,
. ( MySQl-Max BDB.)
MySQL ,
BDB, configure with-berkley-db . MySQl 3.23.34
, :
shell> ./configure with-berkeley-db [-]
2.2.5, 4.1.2 2.3.

8.4. BDB (BerkleyDB)

517

8.4.3. BDB
BDB mysqld:

--bdb-home=. BDB. , datadir.

bdb-lock-detect=Mero4. BDB.
DEFAULT, OLDEST, RANDOM YOUNGEST.

bdb-logdir=. BDB.

bdb-no-recover. He Berkley DB .

bdb-no-sync. He BDB.

bdb-shared-data. Berkley DB . (
DBPRIVATE Berkley DB.)

bdb-tmpdir=nyrb. BDB.

skip-bdb. He BDB.

. 4.2.1.
BDB:
bdbmaxlock. ,
BDB.
. 4.2.3.
--skip-bdb, MySQL
Berkley DB, - .
BDB.
BDB, MySQL My ISAM.
, BDB, mysqld
--bdb-no-recover. mysqld BDB, . . 2.4.4.
bdb_max_lock , BDB.
10 000. , , mysqld , :
bdb: Lock table is out of available locks
Got error 12 from . . .
binlog_cache_size max_binlog_cache_size,
. .
4.8.4.

8.4.4. BDB
BDB .
, . . f rm , . db - .

518

8. MySQL

, BDB, ENGINE TYPE:


CREATE TABLE t (i INT) ENGINE = BDB;
CREATE TABLE t (i INT) TYPE = BDB;
ENGINE TYPE BerkleyDB BDB.
BDB . :
(
), BDB ,
.
,
, COMMIT. ROLLBACK, .
BEGIN WORK, , SET AUTOCOMMIT=0, .
BDB.
BDB 31 , 16 , 1024 ( MySQL 4.0
500 ).
,
BDB (PRIMARY KEY).
, MySQL
. 5 ,
.
(PRIMARY KEY) , , .
,
, .
InnoDB, , .
, BDB,
, MySQL
, . MylSAM
, .
, My ISAM,
BDB -,
.
,
My ISAM. , BDB
, My ISAM.

8.4. BDB (BerkleyDB)

519

BDB ,
. , BDB
My IS AM.
BDB , SELECT
COUNT (*) FROM _ .
.
MySQL , BDB.
DELETE ROLLBACK, MySQL. MySQL ,
,
. , ,
.
ANALYZE TABLE OPTIMIZE TABLE.

BDB .
LOCK TABLES BDB ,
. LOCK TABLES , MySQL
(
, ). ,
, .
, BDB
. bdb-logdir.
, BDB ( , ).
BDB, MySQL , . BDB FLUSH LOGS.
, MySQL. . 4.6.1.

!| , , BDB ff , .

, BDB , .
BDB ,
(, 28) . My ISAM ISAM, mysqld
,
.

520

8. MySQL

8.4.5.
BDB
BDB
. BDB
(, 256 ), mysqld
--no-auto-rehash. MySQL 4.O.

SHOW TABLE STATUS


BDB.

.

.

8.4.6. BDB
,
, BDB.
.db ,
. ,
, .
BDB
.
BDB
mysqldump, BDB
( .frm .db) BDB. BDB
; log.XXXXXXXXXX ( ).
, NULL, , NULL. BDB
.

8.4.7. ,
BDB
mysqld , ,
BDB :
bdb: Ignoring log file: .../log.XXXXXXXXXX:
unsupported log version #
BDB (
log.XXXXXXXXXX) mysqld.
mysqldump opt, BDB, .
BDB,
, MySQL :

8.5. ISAM
001119 23:43:56
001119 23:43:56

bdb:
bdb:

521
Missing log f i l e i d entry
txn_abort: Log undo failed for LSN:
1 3644744: Invalid

, ,
, BDB
. ( .)

8.5. ISAM
MySQL ISAM. MySQL
3.23, MylSAM,
. ISAM . MySQL 4.1 , . MySQL 5.0 .
MySQL ISAM.
ISAM ,
My ISAM, ISAM My ISAM ALTER TABLE:
mysql> ALTER TABLE _ TYPE = MYISAM;
MylSAM 8.1.
ISAM .
, . . f rm , .ISD, -
.ISM.
ISAM -.
ISAM
isamchk. . 4.6.2.7.
ISAM :
.
.

16 16 .

256 ( ).
;
, .
MylSAM ISAM.
, :
ISAM .
, 4 .
.
( ).
.
MERGE.

522

8. MySQL


isamchk, myisamchk.
pack_isam, myisampack.
BACKUP TABLE
RESTORE TABLE.
CHECK TABLE, REPAIR TABLE,
OPTIMIZE

TABLE ANALYZE TABLE.

He .
.
.

9

InnoDB
9.1. InnoDB
InnoDB ( ACID)
MySQL, , , . InnoDB
SELECT
( , Oracle). . InnoDB ,
. InnoDB FOREIGN KEY. SQL
InnoDB MySQL,
.
InnoDB ,
.
.
MySQL, InnoDB
. InnoDB ,
( ). InnoDB , , My ISAM, . InnoDB , 2 .
MySQL 4.0, InnoDB . InnoDB MySQL 3.23
9.3.
InnoDB , , , . ,
, InnoDB Slashdot.org.
InnoDB 1 Mytrix, Inc.,
InnoDB ,
800 / .

524

9. InnoDB

InnoDB GNU GPL 2


( 1991 ). MySQL/InnoDB GPL, MySQL Pro :
https://order.mysql.com/?sub=pg&pg_no=l

9.2. ,
InnoDB
Innobase Oy,
InnoDB:
Web-: http://www.InnoDB.com/
: sales@InnoDB.com
: +358-9-6969 3250 ()
+358-40-5617367 ()
Innobase Oy Inc.
World Trade Center Helsinki
Aleksanterinkatu 17
P.O. Box 800
00101 Helsinki
Finland

9.3. InnoDB MySQL 3.23


MySQL 4.0, InnoDB ,
MySQL 3.23.
MySQL 3.23.34, InnoDB MySQL MySQL-Max 3.23.
Windows MySQL-Max .
MySQL, InnoDB,
MySQL. MySQL 3.23, MySQL-Max ,
mysqld MySQL-Max. MySQL MySQL-Max
. . 2.2.5 4.1.2.
MySQL InnoDB, MySQL
3.23.34 http://www.mysql.com/
MySQL with-InnoDB. . 2.3.
InnoDB MySQL 3.23, InnoDB [mysqld] my.cnf. Windows my.ini. InnoDB ,
InnoDB . ( MySQL 4.0,
, InnoDB , .
,
; 9.4.)

9.4. InnoDB

525

InnoDB
MySQL 3.23 innodb_data_file_path. ,
InnoDB
10 , [mysqld] :
[mysqld]
innodb_data_file_path=ibdata::autoextend
InnoDB ibdatal MySQL.
innodb_data_home_dir. . 9.4.

9.4. InnoDB
InnoDB MySQL 3.23 9.3.
MySQL 4.0, InnoDB . InnoDB, MySQL skip-InnoDB.
InnoDB - .
InnoDB, MySQL 4.0
10 ibdatal
5 ib_logfileO ib_logfilel
MySQL ( MySQL 4.0.0 4.0.1
64 , ). MySQL 3.23
InnoDB .
!
,
InnoDB, . , ,
.

InnoDB
innodb_data_file_path [mysqld] my.cnf. Windows
my.ini. innodb_data_file_path
.
, :
innodb_data_file_path=
__1 [; __2) . . .

,
, , ,
MySQL 4.0:
[mysqld]
innodb_data_file_path=ibdatal::autoextend
10 ibdatal. ,
MySQL.
G,
.

526

9. InnoDB

, ibdatal 50 ibdata2 50 :
[mysqld]
innodb_data_file_path=ibdatal:50;ibdata2:50M:autoextend
,
:
:_ (: autoextend (: max:__))

autoextend, ,
innodb_data_file_path. autoextend
, MySQL 3.23.50 4.0.2.
autoextend , InnoDB
, . 8 .
,
, . 9.8.
InnoDB ,
, 2 . , max. ,
ibdatal 500 :
[mysqld]
innodb_data_file_path=ibdatal:10M:autoextend:max:500M
InnoDB
MySQL. ,
innodb_data_home_dir. , ibdatal
ibdata2 /ibdata, InnoDB :
[mysqld]
innodb_data_home_dir=/ibdata
innodb_data_file_path=/ibdatal:50M;ibdata2:50M:autoextend

II !
InnoDB , , / i b d a t a . |; . mkdir Unix DOS.

InnoDB ,
innodb_data_home_dir ,
. innodb_data_home_dir
my.cnf, "" ./,
MySQL.
innodb_data_home_dir , ,
innodb_data_f ilejpath. :

9.4. InnoDB

527

[mysqld]
innodb_data_home_dir=innodb_data_file_path=
ibdata/ibdatal:50M/ibdata/ibdata2:50M:autoextend
my.cnf
, 128
. my.cnf my.ini InnoDB. ,
MySQL-Max 3.23.50 MySQL 4.0.2 ,
autoextend.
Unix Windows, .
ibdatal
ib_logfileO ib_logfilel MySQL. ,
InnoDB
ib_arch_log_0000000000:
[mysqld]
# MySQL
# ...
#
# .
#
# .
innodb_data_file_path = ibdatal:10M:autoextend
#
#
# 50 80% ,
set-variable = innodb_buffer_pool_size=70M
set-variable = innodb_additional_mem_pool_size=10M
#
#
# 25% ,
set-variable = innodb_log_file_size=20M
set-variable = innodb_log_buffer_size=8M
#
innodb_flush_log_at_trx_commit=l
, MySQL . , ,
.
, 2 . 4 ,
- 10 .
InnoDB,
MySQL .
, . ,
Windows mysqld-max C:\mysql\bin,
:
:\> :\mysql\bin\mysqld-max

console

9. InnoDB

528

,
, , InnoDB .
9.6 , InnoDB.
Windows?
Windows :
- my. cnf . ini.
. cnf :.
my.ini WINDIR; , C:\WINDOWS
C:\WINNT. WINDIR SET :
:\> SET WINDIR
Windir=C:\WINNT
, : , my. ini.
Unix?
Unix mysqld , ,
:

/etc/my, cnf. .

_/my.cnf. .

defaults-extra-file. , defaults-extra-file.

~/.my. cnf. .

_ MySQL, configure mysqld ( /usr/local/mysql/data


/usr/local/var ).
, mysqld , --defaults-option
:
mysqld
defaults-file=Bam_nyTb_K_my_cnf
my.cnf
, , Linux,
2 60 ( /, /dr2 /dr3).

my. cnf InnoDB.
[mysqld]
# MySQL
# ...
innodb_data_home_dir =
#
#
# .
# innodb__data_file_path .
innodb_data_file_path=/ibdata/ibdatal:2000M;

9.4. InnoDB

529

/dr2/ibdata/ibdata2:2000M:autoextend
#
#
# 50 80% ;
# Linux x86 ,
# 2 .
set-variable = innodb_buffer_pool_size=lG
set-variable = innodb_additional_mem_pool_size=20M
innodb_logjgroup_home_dir = /dr3/iblogs
#
# innodb_log_arch_dir ,
# innodb_log_group_home_dir
# ( 4.0.6, ).
innodb_log_arch_dir = /dr3/iblogs
set-variable = innodb_log_files_in_group=2
#
#
# 15% ,
set-variable = innodb_log_file_size=250M
set-variable = innodb_log_buffer_size=8M
#
innodb_flush_log_at_trx_commit=l
set-variable = innodb_lock_wait_timeout=50
#
# ,
# .
#innodb_flush_method=fdatasync
#set-variable = innodb_thread_concurrency=5
, .
InnoDB , .
,
.
. InnoDB (
), -. . 9.15.2.
% !

i;
5
,

GNU/Linux x86 .
g l i b c ,
. ,
2 :

/ innodb_buffer_pool_size
i + key_buffer
\
|; + max__connections *
(sort_buffer_size+read_buffer_size+binlog__cache__size)
y: + max_connections * 2
( 2 , MySQL AB 256 ) , , , sort_buf fer_size + read_buf fer_size.

9. InnoDB

530

MySQL 4.1, 64 32 Windows. . innodb_buf fer_pool_awe_mem_mb


9.5.
mysqld?
:
[mysqld]
skip-external-locking
set-variable = max_connections=200
set-variable = read__buffer_size=lM
set-variable = sort_buffer=lM
#
# key_buffer
# 5-50% ,
#
# MylSAM, a key_buffer_size +
# InnoDB
# 80% .
set-variable = key_buffer size=...

9.5. InnoDB
, InnoDB. MySQL 4.0
_=
. MySQL 4.0 set-va.riable=HMH_onu,HH= -0 _= .

innodb_additional_mem_pool_size. , InnoDB
. , . ,
InnoDB , MySQL .
- 1 .
innodb_buf fer_pool_awe_mem_mb. ( ),
AWE 32- Windows. ,
MySQL 4.1.0, 32- Windows.
32- Windows 4 ( Address Windowing Extentions, AWE),
InnoDB
AWE. 64000.
, innodb_buffer_pool_size
32- mysqld, InnoDB
AWE. innodb_buffer_pool_size
500 .

innodb_buf fer_pool_size. , InnoDB


. ,
.

9.5. InnoDB

531

,
80% .
,

.

innodb_data__f ile_path. .
innodb__data_home_dir , . (1 = 1024 )
G. 10 . 2 .
innodb_data_filejpath, 10 ibdatal ( MySQL 4.0 ). 3.23.44, ,
, , 4 . . . 9.15.2.

innodb_data_home_dir. InnoDB.
,
MySQL. , innodb_data__file__path
.

innodb_fast_shutdown. InnoDB . , . 1, InnoDB . , MySQL


3.23.44 4.0.1. 1 , 3.23.50.

innodb_file_to_threads. - InnoDB.
4. Windows , . Unix
. InnoDB , .
, MySQL 3.23.37.

innodb_file_per_table. , InnoDB
. ibd ( ), . .
9.7.6. , MySQL 4.1.1.
innodb_flush_log_at_trx_commit. 1,

, , . . , , 0 2, . ,

9. InnoDB

532

. 2, . 1 ( MySQL 4.0.13 ).

innodb_f lushjnethod. Unix. fdatasync, InnoDB fsyncO


. O_DSYNC,
InnoDB 0_SYNC ,
f sync () - . 0_DIRECT ( GNU/Linux, MySQL 4.0.14),
InnoDB , a fsyncO -
. , InnoDB f datasynk O_DSYNK , Unix . ,
MySQL 3.23.40.
innodb_force_recovery

|! !
||
||
||
lm

! 1-6 ( 9.9.1).
InnoDB , napa 0. , MySQL 3.23.44.

innodb_lock_wait_timeout. - ( ), InnoDB ,
. InnoDB
. LOCK
TABLES , InnoDB, InnoDB . -. - 50 .

innodb_log_archjdir. ,
( , ).
, innodb_log_group_home_dir. 4.0.6, .

innodb_log_archive. . MySQL
,
InnoDB . .

innodb_log_buffer_size. , InnoDB .
1-8 . 1 .
,
.
,
-.

9.5. InnoDB

533

innodb_log_file__size. .
32- 4 . 5 .
, 1 , N- . ,

, -. : .

innodb_log__f iles_in_group. .
InnoDB . 2.

innodb_log_group_home_dir. InnoDB. , innodb_log_arch_dir.


InnoDB, MySQL
5 ib__logfileO
ib_logfilel.

innodb_max_dirty_pages_pct. 0 100. 90. InnoDB ,


. , 4.0.13 4.1.1.
(SUPER),
. :
SET GLOBAL innodb_max_dirty_pages_pct=3HaveHne;

innodb_mirrored_log_groups. , .
1.
innodb_open_files. ,
InnoDB . . ibd, InnoDB
. - 10. 300. , MySQL 4.1.1.
, .ibd,
InnoDB. --open-files-limit
.
innodb_thread_concurrency. InnoDB InnoDB, , .
8. , SHOW INNODB STATUS , , , ,
"" (thread thrashing).
.
,
, -

534

9. InnoDB
. , .
500 , . , MySQL 3.23.44 4.0.1.

9.6. InnoDB
, MySQL my.cnf InnoDB, MySQL, , InnoDB ,
MySQL . InnoDB , . , .
MySQL
InnoDB, mysqldsafe Windows.
mysqld.
Unix, mysqld. Windows --console.
, InnoDB
, InnoDB .
:
InnoDB: The f i r s t specified datafile /home/heikki/data/ibdatal
did not e x i s t :
InnoDB: a new database to be created!
InnoDB: Setting file /home/heikki/data/ibdatal size to 134217728
InnoDB: Database physically writes the file full: wait...
InnoDB: datafile /home/heikki/data/ibdata2 did not exist:
new to be created
InnoDB: Setting file /home/heikki/data/ibdata2 size to 262144000
InnoDB: Database physically writes the file full: wait...
InnoDB: Log file /home/heikki/data/logs/ib_logfileO did not exist:
new to be created
InnoDB: Setting log file /home/heikki/data/logs/ib_logfileO size to 5242880
InnoDB: Log file /home/heikki/data/logs/ib_logfilel did not exist:
new to be created
InnoDB: Setting log file /home/heikki/data/logs/ib_logfilel size to 5242880
InnoDB: Log file /home/heikki/data/logs/ib_logfile2 did not exist:
new to be created
InnoDB: Setting log file /home/heikki/data/logs/ib_logfile2 size to 5242880
InnoDB: Started
MySQLd: ready for connections
InnoDB. MySQL MySQL, mysql.
MySQL mysqladmin shutdown,
:
010321 18:33:34 mysqld: Normal shutdown
010321 18:33:34 mysqld: Shutdown Complete
InnoDB: Starting shutdown...
InnoDB: Shutdown completed

9.7. InnoDB

535

,
.
ib_arch_log_0000000000. , InnoDB . MySQL
, , :
InnoDB: Started
mysqld: ready for connections

9.6.1. , InnoDB
InnoDB , ,
:
InnoDB.
mysqld .
mysqld my.cnf my.ini , , .
.
, .
innodb_data_home_dir
innodb_data_file_path.
, InnoDB - ,
, InnoDB. ,
. - InnoDB, . f rm ( . ibd,
),
MySQL. InnoDB .
MySQL ,
.

9.7. InnoDB
, MySQL mysql t e s t .
InnoDB, SQL- ENGINE = InnoDB TYPE = InnoDB:
CREATE TABLE customers (a INT, b CHAR (20), INDEX (a)) ENGINE=InnoDB;
CREATE TABLE customers (a INT, b CHAR (20), INDEX (a)) TYPE=InnoDB;
SQL-
InnoDB, , my.cnf. ,
t e s t MySQL customers.frm.
InnoDB ' t e s t / c u s t o m e r s ' .
, customers ,
InnoDB.

536

9. InnoDB

SHOW TABLE STATUS InnoDB InnoDB.


Comment
SHOW TABLE STATUS, :
SHOW TABLE STATUS FROM t e s t LIKE ' c u s t o m e r s '
, , SHOW
InnoDB, .
SQL. ,
.

9.7.1. InnoDB
API-
, MySQL,
, SQL- . , SQL- SET AUTOCOMMIT=0 COMMIT ROLLBACK . , START
TRANSACTION COMMIT ROLLBACK. MySQL 4.0.11 START
TRANSACTION BEGIN. . , .
s h e l l > mysql t e s t
Welcome t o t h e MySQL monitor. Commands end with ; or \g.
Your MySQL connection i d i s 5 t o s e r v e r v e r s i o n : 3.23.50-log
Type ' h e l p ; ' o r ' \ h ' f o r h e l p . Type ' \ c ' t o c l e a r t h e b u f f e r .
m y s q l > CREATE TABLE CUSTOMER (A I N T , CHAR ( 2 0 ) , INDEX ( A ) )
- > TYPE=InnoDB;
Query OK, 0 rows a f f e c t e d ( 0 . 0 0 s e c )
mysql> BEGIN;
Query OK, 0 rows a f f e c t e d ( 0 . 0 0 s e c )
mysql> INSERT INTO CUSTOMER VALUES ( 1 0 , ' H e i k k i ' ) ;
Query OK, 1 row a f f e c t e d ( 0 . 0 0 s e c )
mysql> COMMIT;
Query OK, 0 rows a f f e c t e d ( 0 . 0 0 s e c )
mysql> SET AUTOCOMMIT=0;
Query OK, 0 rows a f f e c t e d ( 0 . 0 0 s e c )
mysql> INSERT INTO CUSTOMER VALUES ( 1 5 , ' J o h n ' ) ;
Query OK, 1 row a f f e c t e d ( 0 . 0 0 s e c )
mysql> ROLLBACK;
Query OK, 0 rows a f f e c t e d ( 0 . 0 0 s e c )
mysql> SELECT * FROM CUSTOMER;
+
4+
I A
| B
|
+
4+
I 10
| Heikki |
+

1 row in set (0.00 sec)


mysql>

9.7. InnoDB

537

API-, PHP, Perl DBI/DBD, JDBC, ODBC ,


( COMMIT) MySQL
, , SQL-, SELECT
INSERT. API-
.

9.7.2. MylSAM InnoDB


, MySQL mysql (, user host) InnoDB .
My ISAM.
, ( )
InnoDB, [mysqld] my.cnf my.ini (
MySQL 3.23.43) def ault-table-type=InnoDB.
MylSAM, InnoDB
, . InnoDB -
InnoDB, ALTER TABLE.. .TYPE=INNODB;
InnoDB , INSERT INTO...SELECT * FROM...
UNIQUE , ,
MySQL 3.23.52, , : SET UNIQUE_CHECKS=O.

-, InnoDB
.
,
:
INSERT INTO _ SELECT * FROM _
WHERE __ > AND ^ <= _;

, , .

InnoDB, . , 80% . InnoDB.
,
: InnoDB , MylSAM.
ALTER TABLE
, , , . InnoDB
,
. -. , 30
, .
, , , ,

538

9. InnoDB

-.
9.9.1.

9.7.3. AUTOJNCREMENT InnoDB


AUTO_INCREMENT,
InnoDB , (auto-increment counter).
. , .
,
AUTO_INCREMENT ai_col, InnoDB . , , InnoDB
:
SELECT MAX ( a i _ c o l )

FROM T FOR UPDATE;

, , . ,
1. SHOW
TABLE STATUS, , ( ) . , , .
InnoDB .
, AUTO_INCREMENT
NULL 0 INSERT, InnoDB ,
.
, ,
, ,
, ,
. , InnoDB
, .
InnoDB AUTO-INC,
SQL-, .
, , AUTO_INCREMENT.
AUTO_INC .
, AUTO__INCREMENT, . , .
,
,
,
.

9.7. InnoDB

539

9,7.4. (FOREIGN KEY)


MySQL 3.23.43b, InnoDB
.
InnoDB :
[CONSTRAINT ]
FOREIGN KEY []
REFERENCES tbl_j\ame
{__,

{__,
...)

...)

[ON DELETE {CASCADE | SET NULL | NO~ACTION | RESTRICT | SET DEFAULT}]


[ON UPDATE {CASCADE | SET NULL | NO ACTION | RESTRICT | SET DEFAULT}]

InnoDB. , , ,
. , ,
, , ,
. .
InnoDB .
.
InnoDB
, ,
. . . SET NULL,
, NOT NULL.
MySQL 1005 CREATE TABLE,
150, , ,
. ALTER TABLE:
150, ,
.
MySQL 4.0.13, SHOW INNIDB STATUS InnoDB .
MySQL 3.23.50, InnoDB
, NULL.
SQL. , InnoDB
,
. , RESTRICT, , InnoDB - .
MySQL 3.23.50, ON DELETE CASCADE ON DELETE SET NULL. ON UPDATE 4.0.8 . ON
DELETE CASCADE, , InnoDB
,
.
ON DELETE SET NULL, -

540

9. InnoDB

, NULL. SET
DEFAULT , .
InnoDB
(depth-first algorithm),
.
SQL. ON UPDATE CASCADE ON UPDATE
NULL ,
, RESTRICT.
, ON UPDATE CASCADE
ON UPDATE SET NULL. ,
, . ,
MySQL 4.0.13, ON DELETE SET NULL. ON DELETE CASCADE ON DELETE.
parent
child :
CREATE TABLE p a r e n t ( i d INT NOT NULL,
PRIMARY KEY (id)
) TYPE=INNODB;
CREATE TABLE c h i l d ( i d INT, p a r e n t _ i d INT,
INDEX p a r _ i n d ( p a r e n t _ i d ) ,
FOREIGN KEY (parent_id) REFERENCES p a r e n t ( i d )
ON DELETE CASCADE
) TYPE=INNODB;
, product_order
.
product. customer:
CREATE TABLE p r o d u c t ( c a t e g o r y INT NOT NULL, i d INT NOT NULL,
p r i c e DECIMAL,
PRIMARY K E Y ( c a t e g o r y , i d ) ) TYPE=INNODB;
CREATE TABLE c u s t o m e r ( i d INT NOT NULL,
PRIMARY KEY ( i d ) ) TYPE=INNODB;
CREATE TABLE p r o d u c t _ o r d e r (no INT NOT NULL AUTO_INCREMENT,
p r o d u c t _ c a t e g o r y INT NOT NULL,
p r o d u c t _ _ i d INT NOT NULL,
c u s t o m e r _ i d INT NOT NULL,
PRIMARY KEY(no),

INDEX (product_category, product_id),


FOREIGN KEY (product_category, product_id)
REFERENCES product(category, id)
ON UPDATE CASCADE ON DELETE RESTRICT,
INDEX (customer_id),
FOREIGN KEY (customer_id)
REFERENCES customer(id)) TYPE=INNODB;
MySQL 3.23.50, InnoDB
, ALTER TABLE:

9.7. InnoDB

541

ALTER TABLE __
ADD [CONSTRAINT ] FOREIGN KEY []
(__,...)
REFERENCES t b l _ n a m e {__,
...)
[ON DELETE {CASCADE | SET NULL | NO ACTION | RESTRICT | SET DEFAULT}]
[ON UPDATE {CASCADE | SET NULL | NO ACTION | RESTRICT | SET DEFAULT}]

He , . , ALTER TABLE
.
MySQL 4.0.13, InnoDB ALTER
TABLE :
ALTER TABLE _

DROP FOREIGN KEY

__;

, CONSTRAINT,
FOREIGN KEY . ( MySQL
4.0.18, .) __ . , SHOW CREATE TABLE, :
mysql> SHOW CREATE TABLE i b t e s t l l c \ G
***************************
im r o w

***************************

Table: ibtestllc
Create Table: CREATE TABLE ibtestllc v (

int(ll) NOT NULL auto_increment,
4 4
D int(ll) NOT NULL default '0',
4 V
B varchar(200) NOT NULL default ",
N 4
C varchar(175) default NULL,
PRIMARY KEY ( 4 A\V D \ * B 4 ) ,
KEY 4 B N ( 4 B\4 C N ) ,
KEY ( % C % ),
CONSTRAINT ^ 0 _ 3 8 7 7 5 4 FOREIGN KEY ( V A \ 4 D 4 )
REFERENCES 4 i b t e s t l l a N f A \ 4 D 4 )
ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT N 0 _ 3 8 7 7 6 4 FOREIGN KEY ( 4 B \ ^ C )
4
4
N
REFERENCES 4 b t e s t l l a
f B \ C )
ON DELETE CASCADE ON UPDATE CASCADE
) TYPE=InnoDB C H A R S E T = l a t i n l
1 rowi n s e t (0.01 s e c )
mysql> ALTER TABLE i b t e s t l l c DROP FOREIGN KEY

0_38775;

MySQL 3.23.50, InnoDB ( ) ,


FOREIGN KEY.. .REFERENCES... MySQL 4.0.5,
InnoDB lower_case_table_names.
MySQL 3.23.50 ALTER TABLE CREATE INDEX ,
: ALTER TABLE , . ALTER TABLE
, . , DROP

542

9. InnoDB

TABLE CREATE TABLE. ALTER TABLE MySQL


RENAME TABLE, ,
. CREATE INDEX MySQL ,
ALTER TABLE, .
MySQL 3.23.50, InnoDB
SHOW CREATE TABLE:
SHOW CREATE TABLE _;
mysql dump .
:
SHOW TABLE STATUS FROM __ LIKE '_*
Comment () .
InnoDB , . InnoDB .
, , mysql dump
FOREIGN_KEY_CHECKS 0 ( MySQL 4.1.1).
, .
mysql , :
mysql> SET FOREIGN_KEY_CHECKS = 0;
mysql> SOURCE __;
mysql> SET FOREIGN_KEY_CHECKS = 1;
,
, .
. FORE IGN_KEY_CHECKS , MySQL 3.23.52. MySQL 4.O.3.
FOREIGN_KEY_CHECKS ,
LOAD DATA.

InnoDB , , . , , .
, , .
; ,
, .
, MySQL 1005
150 .

9.7. InnoDB

543

9.7.5. InnoDB MySQL


MySQL InnoDB , MylSAM.
: . ,
InnoDB My ISAM.
,
InnoDB ,
.frm InnoDB, . , 9.10.
, InnoDB , .
, , InnoDB Hot Backup.
InnoDB :

LOAD TABLE FROM MASTER InnoDB. : 1) ; 2) ALTER TABLE


_ TYPE=MyISAM LOAD TABLE _ FROM MASTER, ALTER TABLE
InnoDB.

MySQL 4.0.6 SLAVE STOP


. , SLAVE START
. .
MySQL 4.0.6

, SLAVE STOP.
MySQL 4.0.11 SET FOREIGN_KEY_CHECKS=0
.
, , .
. MySQL , MySQL SQL-, . SQL-. ,
, . . ,
, SQL ,
.

9. InnoDB

544

9.7.6.

MySQL 4.1.1, InnoDB . " ", .
f

'i MySQL 4.1.1 ,


'if 4.0. 4.1.0! , j InnoDB .

4.0,
InnoDB.
InnoDB MySQL 4.1.1 ,
, MySQL 4.0.18
4.0. 4.., mysqld, , .
SHOW INNODB STATUS ,
waiting for server activity. mysqld
4.0.18 4.0. , ,
.
, [mysqld]
my. cnf :
[mysqld]
innodb_file_per_table
InnoDB
_.ibd,
, .
MylSAM, MylSAM _.
_.MYI. InnoDB .ibd.
_. f rm , .
innodb_file_per_table my.cnf , InnoDB .
innodb_f ile_per__table .
, . idb,
,
. ,
,
, .
InnoDB .
InnoDB .idb. ibdata, InnoDB
.

9.7. InnoDB

545

.ibd ,
MylSAM. : 1) InnoDB; 2)
InnoDB
.
MySQL . ibd

RENAME TABLE:
RENAME TABLE ___._
TO ___. _ ;
. ibd, MySQL:
1. ALTER TABLE:
ALTER TABLE _ DISCARD TABLESPACE;
! . ibd .
2. .ibd
.
3. ALTER TABLE:
ALTER TABLE _ IMPORT TABLESPACE;
. idb , :

,
.

,
.

mysqld . ibd
.

. ibd :
1. mysqld .
2. , SHOW INNODB STATUS , ,
InnoDB Waiting for server a c t i v i t y .
. ibd .
. ibd InnoDB HOT Backup:
1. InnoDB HOT Backup InnoDB.
2. mysqld ,
. ibd .
TODO . ibd
MySQL. . ibd.

546

9. lnnoDB

9.8.
InnoDB
, , lnnoDB
.
MySQL 3.23.50 MySQL 4.0.2,
InnoDB , . autoextend. ,
InnoDB 8 .
, - , . MySQL, my.cnf, innodb_data_file_path,
.
autoextend, my.cnf
. ,
, (1024*1024 = 1 )
innodb_data_file_path. .
, innodb_data_f ile_path .
, ibdatal:
innodb_data_home_dir =
innodb_data_file_path =

/ibdata/ibdatal::autoextend

,
988 . .
innodb_data__home_dir =
innodb_data_file_path = /ibdata/ibdatal:988M;/disk2/ibdata2:50M:autoextend

, . InnoDB .
.
, :
1. mysqldump InnoDB.
2. .
3. .
4. .
5. .
6. .
InnoDB,
MySQL ,
- .
- ,

9.9. InnoDB

547

.
, my. cnf
MySQL. raysqld ,
, .

9.9.
InnoDB
,
.
InnoDB Hot
Backup,
InnoDB . InnoDB Hot Backup
, . InnoDB Hot Backup , MySQL 390 .
, InnoDB Hot Backup :
http://www.InnoDB.com/order.html
MySQL, , :
1. MySQL , .
2. .
3. InnoDB .
4. my. cnf .
5. . f rm InnoDB .
InnoDB ,
, , .

mysqldump. ,
. , ,
,
. , , , mysqldump
single-transsaction, , .
InnoDB , MySQL . , ,
:
mysqlbinlog _-. 123 | mysql
MySQL , . InnoDB

548

9. InnoDB

. ,
InnoDB .
InnoDB :
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:

Database was not shut down normally.


Starting recovery from log files...
Starting log scan based on checkpoint at
log sequence number 0 13674004
Doing recovery: scanned up to log sequence
Doing recovery: scanned up to log sequence
Doing recovery: scanned up to log sequence
Doing recovery: scanned up to log sequence

InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
mysqld:

Doing recovery: scanned up to log sequence number 0 20555264


Doing recovery: scanned up to log sequence number 0 20620800
Doing recovery: scanned up to log sequence number 0 20664 692
1 uncommitted transaction(s) which must be rolled back
Starting rollback of uncommitted transactions
Rolling back trx no 16745
Rolling back of trx no 16745 completed
Rollback of uncommitted transactions completed
Starting an apply batch of log records to the database...
Apply batch completed
Started
ready for connections

number
number
number
number

0
0
0
0

13739520
13805056
13870592
13936128

, .
. , , .

, . SQL- CHECK TABLE,
.
innodb_tablespace_monitor.
, ,
. . , .

9.9.1.
, ,
, SELECT INTO OUTFILE. ,
. SELECT * FROM _ InnoDB, InnoDB .
MySQL 3.23.44 , InnoDB; ,

9.9. InnoDB

549

. ,
[mysqld] :
[mysqld]
innodb_force_recovery

=4

MySQL 4.0 :
[mysqld]
set-variable = innodb_force_recovery=4
innodb_force_recovery
.
.
, 4, . 6, , , , -
.

1 (SRV_FORCE_IGNORE_CORRUPT). ;
SELECT * FROM _ ,
.

2 (SRVFORCENOBACKGROUND). .
, .

3 (SRV_FORCE_NO_TRX_UNDO). He .

4 (sRVFORCENOIBUFMERGE). . ,
; .

5 (SRV_FORCE_NO_UNDO_LOG_SCAN). He : InnoDB .

(SRV_FORCE_NO_LOG_RED0)- He
.

.
InnoDB INSERT, UPDATE
DELETE, innodb_f orce_recovery .
MySQL 3.23.53 4.0.4, DROP
CREATE .
, ,
.
, ALTER TABLE.
mysqld innodb_f orce_recovery 3, .
DROP , .

550

9. InnoDB

9.9.2.
InnoDB , "
" (fuzzy checkpoint). InnoDB
. , SQL-, .
InnoDB ,
. , , , . InnoDB .
InnoDB . ,
, . , InnoDB . , InnoDB , ,
, . , ,
InnoDB .
, - . ,
. , ,
.

9.10. InnoDB

Windows InnoDB . Unix Windows , , . Unix .
, [mysqld]
my. cnf :
[mysqld]
set-variable = lower_case_table_names=l
Windows lower_case_table_names 1.
MylSAM, InnoDB
,
. InnoDB , ( 9.9). , FLOAT
DOUBLE ,
: , .

9.11. InnoDB

551

,
, ,
mysqldump ,
.
, , ,
,
. .

9.11. InnoDB

InnoDB .
InnoDB
, Oracle. InnoDB ,
:
, , InnoDB.

9.11.1. InnoDB
AUTOCOMMIT
InnoDB .
, SQL- . MySQL .
SET
AUTOCOMMIT=0, , .
SQL- COMMIT ROLLBACK . InnoDB,
. COMMIT, , ,
. ROLLBACK, , , .
, START TRANSACTION BEGIN
COMMIT ROLLBACK.

9.11.2. InnoDB
(TRANSACTION ISOLATION LEVEL)
SQL: 1992 InnoDB (REPEATABLE READ). MySQL

552

9. InnoDB

4.0.5, InnoDB ,
SQL. transaction-isolation
,
. , [raysqld] my.cnf :
[mysqld]
transaction-isolation = {READ-UNCOMMITTED | READ-COMMITTED
| REPEATABLE-READ | SERIALIZABLE}

:
SET [SESSION | GLOBAL] TRANSACTION ISOLATION LEVEL
{READ UNCOMMITTED | READ COMMITTED
I REPEATABLE READ | SERIALIZABLE}
, --transaction-isolation , SET TRANSACTION - .
(
) . GLOBAL,
,
( ). (SUPER).
SESSION, , , .
(
) .
MySQL 3.23.50 SET TRANSACTION
InnoDB. 4.0.5 REPEATABLE READ
SERIALIZABLE.

:
SELECT @@global.tx_isolation;
SELECT @@tx_isolation;
InnoDB " " (next-key locking). , InnoDB
"" (gap) ,
. .
.
InnoDB:
READ UNCOMMITTED. SELECT . , , "" ( - " ").
, READ COMMITTED.

9.11. InnoDB

553

READ COMMITTED. Oracle. SELECT...


FOR UPDATE SELECT.. .LOCK IN SHARE MODE ,
. ,
.
UPDATE DELETE,
, , . UPDATE DELETE InnoDB
, . ,
MySQL, " " (phantom row).
, Oracle:
, , . . 9.11.3.

REPEATABLE READ. InnoDB .


SELECT... FOR UPDATE, SELECT. . .LOCK IN SHARE MODE, UPDATE DELETE,
, ,
. , , ,
.
:
, . ,
( SELECT), . . 9.11.3.

SERIALIZABLE. REPEATABLE READ, SELECT SELECT... LOCK IN SHARE MODE.

9.11.3.
, InnoDB

. , , , , . , , .
REPEATABLE READ, ,
,
.
-
.

554

9. InnoDB

. InnoDB
SELECT READ COMMITTED
REPEATABLE READ.
, , .

9.11.4. : SELECT... FOR UPDATE


SELECT... LOCK IN SHARE MODE
. , child, , parent .
,
.
, parent ,
.
child, ? ,
parent.
(SELECT) , LOCK IN SHARE MODE:
SELECT

* FROM PARENT WHERE NAME = ' J o n e s '

LOCK IN SHARE MODE;

.
. ,
,
.
'Jones', child .
. child_codes, , child. ,
,
; ,
,
.
LOCK IN SHARE MODE : , , ,
.
: (1) , 1,
, (2) FOR
UPDATE, .
:

9.11. InnoDB

555

SELECT counter_field FROM child_codes FOR UPDATE;


UPDATE child_codes SET counter_field = counter_field + 1;
SELECT...FOR UPDATE ,
.
, SQL- UPDATE.
, SELECT.. .FOR UPDATE.
MySQL
:
UPDATE child_codes SET counter_field = LAST_INSERT_ID(counter_field + DESELECT LAST_INSERT_ID();
SELECT (
). .

9.11.5. :
" "
InnoDB , " " (next-key locking). , .
.
, InnoDB , . R ,
R .
, " "
("phantom problem"). , child , 100,
:
SELECT * FROM c h i l d WHERE i d > 100 FOR UPDATE;

, id . , , id 100. ,
,
.
SELECT , . :
,
. ,
" " .
InnoDB , . : , InnoDB, , id
100.

556

9. InnoDB

, . , , ,
, , , . ,
"" - .

9.11.6. InnoDB
, , - REPEATABLE READ. ( SELECT) InnoDB ,
.
, , . .
,
SELECT.
(multi-versioned
concurrency control).
User A
SET AUTOCOMMIT=0;
time
|
SELECT * FROM t ;
I
empty s e t
|

User
SET AUTOCOMMIT=0;

INSERT INTO t VALUES ( 1 ,

2);

I
v

SELECT * FROM t ;
empty s e t
COMMIT;
SELECT * FROM t ;
empty s e t
COMMIT;
SELECT * FROM t ;

1 row in set
, ,
, ,
, , .
" " , :
SELECT * FROM t LOCK IN SHARE MODE;

9.11. InnoDB

557

9.11.7. ,
SQL- InnoDB
, UPDATE DELETE , SQL-.
, WHERE,
. InnoDB WHERE,
, .
,
.
, InnoDB
, .
, , , MySQL
, ,
. , ,
.
, .
SELECT... FROM , SERIALIZABLE. SERIALIZABLE .

SELECT.. .FROM.. .LOCK IN SHARE MODE


.

SELECT.. .FROM.. .FOR UPDATE .

INSERT INTO.. .VALUES (...) . ,



. , .

AUTO_INCRESEMENT
InnoDB , AUTOINCREMENT. InnoDB AUTO-INC, SQL-,
. . 9.11.1.
MySQL 3.23.50 SHOW TABLE STATUS,
AUTOINCRESEMENT, AUTO_INCREMENT. ,
SHOW TABLE STATUS , . MySQL
3.23.50, InnoDB
AUTO_INCRESEMENT, - .

558

9. InnoDB
INSERT INTO T SELECT... FROM S WHERE... ( ) . S , , S
. InnoDB
, SQL-
, .

CREATE TABLE... SELECT... SELECT


, .
REPLACE , , . , , .

UPDATE.. .WHERE...
, .

DELETE FROM.. .WHERE...


, .
FOREIGN KEY, ,
, , , . InnoDB .

LOCK TABLES... . MySQL.


InnoDB ,
. . 9.11.9.
, MySQL ,
, - . , ,
. . 9.17.

9.11.8. MySQL

MySQL . , MySQL
SQL-, .
, , MySQL .
SQL- , /
. . 9.16.
SQL-
MySQL:

9.11. InnoDB

559

ALTER TABLE, BEGIN, CREATE INDEX, DROP DATABASE, DROP INDEX, DROP TABLE,
LOAD MASTER DATA, LOCK TABLES, RENAME TABLE, SET AUTOCOMMIT=1, START
TRANSACTION, TRUNCATE, UNLOCK TABLES.

CREATE TABLES ( ,
MySQL, 4.0.13, ).
CREATE TABLE InnoDB . , ROLLBACK, ,
CREATE TABLE,
.

9.11.9.
InnoDB
. MySQL 4.0.5, InnoDB
. , , . MySQL 4.0.5 InnoDB , , , ,
.
InnoDB , MySQL- LOCK TABLES
, InnoDB. innodb_lock_wait_timeout.
InnoDB , .
, SQL-,
, SQL-, . , InnoDB ,
, SQL- .

9.11.10.
. , ,
.
,
, .
InnoDB . ,
. - ,
; (, ).
:
, SHOW INNODB STATUS.

560

9. InnoDB
.
MySQL 3.23.52 MySQL 4.0.3, MySQL.

,
. , .
. .
(SELECT.. .FOR UPDATE .. .LOCK IN
SHARE MODE), , READ COMMITTED.

, , .

. ,
, .
EXPLAIN SELECT, , MySQL
.

: , SELECT ,
FOR UPDATE LOCK IN SHARE MODE. READ COMMITTED, .
, . , t i n t2, :
LOCK TABLES t l WRITE, t2 READ, . . . ;
[do something with tables t l and t2 h e r e ] ;
UNLOCK TABLES;
, . , LOCK
TABLES , BEGIN, a UNLOCK TABLES
, COMMIT.

"" ,
. ,
. .
,
, . MySQL
-.

9.12. InnoDB

561

9.12.
InnoDB
top Unix Task Manager ( ) Windows
, 70%, ,
, , . ,
. ,
80% .
. InnoDB , . 167 , 167
, , , "" .
,
my.cnf innodb_flush_log_at_trx_commit
. , InnoDB , .
, .
InnoDB , . ,

,
.
, 8 .
CHAR VARCHAR,
.
CHAR N , NULL. -.
( MySQL 3.23.39 .) Linux Unix f datasync
.
InnoDB fdatasync. , my.cnf
innodb_f lushjnethod O_DSYNC, .
InnoDB , MySQL , .
,
SET AUTOCOMMIT COMMIT:
SET AUTOCOMMIT=0;
/* SQL- ... */
COMMIT;

562

9. InnoDB
opt mysqldump, , InnoDB,
SET AUTOCOMMIT COMMIT.

: InnoDB
, -,
.
30 , . , .
,
, .
. 9.9.1.

, . ,
DROP TABLE TRUNCATE ( MySQL 4.0
), DELETE FROM _.
, INSERT ,
:
INSERT INTO _ VALUES (1,2), (5,5), ...;
, InnoDB.
UNIQUE , ,
MySQL 3.23.52 MySQL 4.0.3, ,
:
SET UNIQUE_CHECKS=O;
-, InnoDB
.
FOREIGN KEY, ,
MySQL 3.23.52 MySQL 4.0.3,
, :
SET FOREIGN_KEY_CHECKS=0;

-.
,
, MySQL 4.0:
[mysqld]
query_cache_type = ON
query_cache__size = 10M
MySQL 4.0 . MySQL 4.1.1 .

9.12. InnoDB

563

9.12.1. SHOW INNODB STATUS InnoDB


MySQL 3.23.41, InnoDB InnoDB,
InnoDB. MySQL 3.23.52
MySQL 4.0.3, SQL-onepaTopf SHOW INNODB STATUS InnoDB SQL.
. mysql, ,
\G:
mysql> SHOW INNODB STATUS\G
InnoDB - mysqld.
. InnoDB
15 .
.err, MySQL.
. Windows
console,
, .
:
, .
, .

, .
, -.
.
InnoDB.

InnoDB
mysqld, SQL-:
CREATE TABLE innodbjnonitor(a INT) TYPE=InnoDB;
:
DROP TABLE innodbjnonitor;
CREATE TABLE InnoDB SQL: innodbjnonitor InnoDB. InnoDB . , ,
CREATE TABLE .
.
innodb_lock_monitor,
innodbjnonitor, . innodb_tablespace_monitor , ,
. MySQL 3.23.44
innodb_table_monitor, InnoDB.

564

9. InnoDB

, InnoDB:
mysql> SHOW INNODB STATUS\G
*************************** im
Status:

r o w

***************************

030709 13:00:59 INNODB MONITOR OUTPUT


Per second averages calculated from the last 18 seconds
SEMAPHORES
OS WAIT ARRAY INFO: reservation count 413452, signal count 378357
--Thread 32782 has waited at btrOsea.c line 1477 for 0.00 seconds the
semaphore:
X-lock on RW-latch at 41a28668 created in file btrOsea.c line 135
a writer (thread id 32782) has reserved it in mode wait exclusive
number of readers 1, waiters flag 1
Last time read locked in file btrOsea.c line 731
Last time write locked in file btrOsea.c line 1347
Mutex spin waits 0, rounds 0, OS waits 0
RW-shared spins 108462, OS waits 37964; RW-excl spins 681824, OS waits 375485
LATEST FOREIGN KEY ERROR
030709 13:00:59 Transaction:
TRANSACTION 0 290328284, ACTIVE 0 sec, process no 3195, OS thread id 34831
inserting
15 lock struct (s), heap size 2496, undo log entries 9
MySQL thread id 25, query id 4668733 localhost heikki update
insert into ibtestlla (D, , ) values (5, 'khDk' ,'khDk1)
Foreign key constraint fails for table test/ibtestlla:
v

CONSTRAINT 0_219242 FOREIGN KEY f A \ D ) REFERENCES 4btestllb ( A\ D )


ON DELETE CASCADE ON UPDATE CASCADE
Trying to add in child table, in index PRIMARY tuple:
0: len 4; hex 80000101; asc
;; 1: len 4; hex 80000005; asc
;; 2: len 4;
hex 6b68446b; asc khDk;; 3: len 6; hex 0000114e0edc; asc ...N..;; 4: len 7; hex
00000000c3e0a7; asc
;; 5: len 4; hex 6b68446b; asc khDk;;
But in parent table test/ibtestllb, in index PRIMARY,
the closest match we can find is record:
RECORD: info bits 0 0: len 4; hex 8000015b; asc ...[;; 1: len 4; hex 80000005; a
sc
;; 2: len 3; hex 6b6864; asc khd;; 3: len 6; hex 0000111ef3eb; asc
;; 4: len 7; hex 800001001e0084; asc
;; 5: len 3; hex 6b6864; asc khd;;
LATEST DETECTED DEADLOCK
030709 12:59:58
*** (1) TRANSACTION:
TRANSACTION 0 290252780, ACTIVE 1 sec, process no 3185, OS thread id 30733
inserting
LOCK WAIT 3 lock struct(s), heap size 320, undo log entries 146

9.12. InnoDB

565

MySQL thread id 21, query id 4553379 localhost heikki update


INSERT INTO alexl VALUES(86, 86,
1
f !
794,'aA35818','bb ,'c79166\'d4766t , el87358f
l
l
,'g84586', h794',date_format( 2001-04-03 12:54:22','%Y-%m-%d %H:%i'),7
*** (1) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 48310 n bits 568 table test/alexl index symbole
trx id 0 290252780 lock mode S waiting
Record lock, heap no 324 RECORD: info bits 0 0: len 7; hex 61613335383138; asc a
a35818;; 1:
*** (2) TRANSACTION:
TRANSACTION 0 290251546, ACTIVE 2 sec, process no 3190, OS thread id 32782
inserting
130 lock struct(s), heap size 11584, undo log entries 437
MySQL thread id 23, query id 4554396 localhost heikki update
REPLACE INTO alexl VALUES(NULL, 32, NULL,!aa3572','','c3572','d6012t', " ,
NULL,fh396', NULL, NULL, 7.31,7.31,7.31,200)
*** (2) HOLDS THE LOCK(S):
RECORD LOCKS space id 0 page no 48310 n bits 568 table test/alexl index symbole
trx id 0 290251546 lockjnode X locks rec but not gap
Record lock, heap no 324 RECORD: info bits 0 0: len 7; hex 61613335383138; asc a
a35818;; 1:
*** (2) WAITING FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 48310 n bits 568 table test/alexl index symbole
trx id 0 290251546 lockjnode X locks gap before rec insert intention waiting
Record lock, heap no 82 RECORD: info bits 0 0: len 7; hex 61613335373230; asc aa
35720;; 1:
*** WE ROLL BACK TRANSACTION (1)
TRANSACTIONS
Trx id counter 0 290328385
Purge done for trx's n:o < 0 290315608 undo n:o < 0 17
Total number of lock structs in row lock hash table 70
LIST OF TRANSACTIONS FOR EACH SESSION:
-TRANSACTION 0 0, not started, process no 3491, OS thread id 42002
MySQL thread id 32, query id 4668737 localhost heikki
show innodb status
TRANSACTION 0 290328384, ACTIVE 0 sec, process no 3205, OS thread id
38929 inserting
1 lock struct(s), heap size 320
MySQL thread id 29, query id 4668736 localhost heikki update
insert into speedc values (1519229,1,
'hgjhjgghggjgjgjgjgjggjgjgjgjgjgggjgjgjlhh
gghggggghhjhghgggggghjhghghghghghhhhghghghj hhj ghj ghj kghj ghj ghj ghj fhj fh
TRANSACTION 0 290328383, ACTIVE 0 sec, process no 3180, OS thread id
28684 committing
1 lock struct(s), heap size 320, undo log entries 1
MySQL thread id 19, query id 4668734 localhost heikki update
insert into speedcm values (1603393,1,
'hgjhjgghggjgjgjgjgjggjgjgjgjgjgggjgjgjlh
hgghggggghhj hghgggggghj hghghghghghhhhghghghj hhj ghj ghj kghj ghj ghj ghj fhj f

566

9. InnoDB

-TRANSACTION 0 290328327, ACTIVE 0 sec, process no 3200, OS thread id


36880 starting index read
LOCK WAIT 2 lock struct(s), heap size 320
MySQL thread id 27, query id 4668644 localhost heikki Searching rows for update
update ibtestlla set = 'kHdkkkk' where A = 89572
TRX HAS BEEN WAITING 0 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 0 page no 65556 n bits 232 table test/ibtestlla index PRIM
ARY trx id 0 290328327 lockjnode X waiting
Record lock, heap no 1 RECORD: info bits 0 0: len 9; hex 73757072656d756d00; asc
supremum.;;
TRANSACTION 0 290328284, ACTIVE 0 sec, process no 3195, OS thread id
34831 rollback of SQL statement
ROLLING BACK 14 lock struct(s), heap size 2496, undo log entries 9
MySQL thread id 25, query id 4668733 localhost heikki update
insert into ibtestlla (D, , ) values (5, 'khDk' ,'khDk1)
TRANSACTION 0 290327208, ACTIVE 1 sec, process no 3190, OS thread id 32782
58 lock struct (s), heap size 5504, undo log entries 159
MySQL thread id 23, query id 4668732 localhost heikki update
REPLACE INTO alexl VALUES(86, 46,
538, f aa95666 f , f bb', ! c95666 f , f d9486t l , f e200498f
',fg86814\

h538',date_format('2001-04-03 12:54:22','%Y-%m-%d

%H:%i),

-TRANSACTION 0 290323325, ACTIVE 3 sec, process no 3185, OS thread id


30733 inserting
4 lock struct (s), heap size 1024, undo log entries 165
MySQL thread id 21, query id 4668735 localhost heikki update
INSERT INTO alexl VALUES(NULL, 49, NULL,faa42837', " ,c56319','dl719t','',
NULL, 32, NULL, NULL, 7.31,7.31,7.31,200)
FILE I/O
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
151671 OS file reads, 94747 OS file writes, 8750 OS fsyncs
25.44 reads/s, 18494 avg bytes/read, 17.55 writes/s, 2.33 fsyncs/s
INSERT BUFFER AND ADAPTIVE HASH INDEX
Ibuf for space 0: size 1, free list len 19, seg size 21,
85004 inserts, 85004 merged recs, 26669 merges
Hash table size 207619, used cells 14461, node heap has 16 buffer (s)
1877.67 hash searches/s, 5121.10 non-hash searches/s
LOG
Log sequence number 18 1212842764

9.12. InnoDB

567

Log flushed up to 18 1212665295


Last checkpoint at 18 1135877290
0 pending log writes, 0 pending chkp writes
4341 log i/o's done, 1.22 log i/o's/second
BUFFER POOL AND MEMORY
Total memory allocated 84966343; in additional pool allocated 1402624
Buffer pool size 3200
Free buffers 110
Database pages 3074
Modified db pages 2674
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 171380, created 51968, written 194688
28.72 reads/s, 20.72 creates/s, 47.55 writes/s
Buffer pool hit rate 999 / 1000
ROW OPERATIONS
0 queries inside InnoDB, 0 queries in queue
Main thread process no. 3004, id 7176, state: purging
Number of rows inserted 3738558, updated 127415, deleted 33707, read 755779
1586.13 inserts/s, 50.89 updates/s, 28.44 deletes/s, 107.88 reads/s
END OF INNODB MONITOR OUTPUT
1 row in set (0.05 sec)
.
TRANSACTIONS ,
.
.
SEMAPHORES , , , /. , ,
-,
InnoDB.
.
innodb_thread_concurrency 8.
BUFFER POOL AND MEMORY
.
- ,
.
ROW OPERATION , .

568

9. InnoDB

9.13.
InnoDB ,
.
, Oracle (rollback segment).
, , InnoDB . 6 ,
. ,
. 7- , (roll
pointer). , . ,
,
.
InnoDB , . .

.
.
; , , InnoDB ,
.
, , . InnoDB , , .
. , .
InnoDB , SQL-. , InnoDB
, , . (purge).
- , SQL.

9.14.
MySQL . f rm, . InnoDB
InnoDB .
MySQL , . f rm,
InnoDB. -

9.14.

569

innoDB
. f rm. DROP DATABASE InnoDB , MySQL 3.23.43.
InnoDB ,
- (clustered index). (PRIMARY KEY), .
, MySQL
UNIQUE, NOT NULL,
, InnoDB .
, InnoDB ,
, InnoDB . 6- ,
. ,
.
,
,
. -, .
( ) InnoDB . InnoDB
.
, ,
.
InnoDB CHAR VARCHAR , ,
.

9.14.1.
InnoDB -,
. 16 .
InnoDB 1/16
.
( ), 15/16.
, 1/2 15/16.
1/2, InnoDB , .

9.14.2.
, . ,
.

570

9. InnoDB

, ,
.
, , InnoDB.
,
, InnoDB ,
. , InnoDB . , InnoDB
. , ,
.

.
-.
15 .

9.14.3.
,
. InnoDB ,
, , .
InnoDB , , .
, , ,
- . InnoDB
, -, ,
InnoDB -.
: . InnoDB , .
InnoDB
,
.

9.14.4.
InnoDB :

InnoDB , 6 .
,
.

, . , 6
7 .
, 6-
.

9.15. -

571

,
.
. 128 , 1 , - 2 .
InnoDB , CHAR (10),
. InnoDB VARCHAR.
, InnoDB CHAR VARCHAR.

SQL- NULL 0 .
. NULL , NULL .

9.15.
-
9.15.1. -
- InnoDB
-. InnoDB -, -, .
InnoDB :
InnoDB, , , - .
InnoDB, ,
,
-.
MySQL 3.23.41, InnoDB , (doublewrite).

Unix fsync ().
, InnoDB
, (doublewrite buffer). . ,
InnoDB .

572

9. InnoDB

9.15.2.

MySQL 3.23.41, . ,
Windows Unix -
, . .

innodb_data_f ile_path newraw.
. : 1
InnoDB - 1024*1024 , 1 1 000 000 .
[mysqld]
innodb_data_home_dir=
innodb_data_filejpath=/dev/hddl:3Gnewraw;/dev/hdd2:2Gnewraw
InnoDB newraw . InnoDB, InnoDB
. ( 3.23.44, InnoDB , newraw.)
InnoDB ,
newraw raw:
[mysqld]
i n n db__da t a_h ome_d i r=
innodb_data_file_path=/dev/hddl:5Graw;/dev/hdd2:2Graw
, InnoDB .
Windows, MySQL 4.1.1,
, :
[mysqld]
innodb_data_home_dir=
innodb_data_file_path=//./D::10Gnewraw
//./ \\.\ Windows, .
,
, MySQL.

9.15.3.
InnoDB ,
. , . .
, . InnoDB , .

9.15. -

573

, 16 . , (extent),
64 . ""
InnoDB "". " "
,
.
InnoDB : -
-, - . , , .
,
InnoDB 32 . InnoDB
. ,
InnoDB 4 .

, InnoDB , .
SHOW TABLE STATUS
InnoDB
. InnoDB
. .
, InnoDB . ,
,
.
, ,
, .

9.15.4.
, . ,
, 64- , ,
.
ALTER TABLE:
ALTER TABLE _ TYPE=InnoDB
MySQL .
- mysqldump , .
, -
, InnoDB
.

574

9. InnoDB

9.16.
innoDB SQL.
, ,
SQL-, . InnoDB
.
InnoDB:
, MySQL Table is full ( ), InnoDB SQL-.
.
, INSERT INTO.. .SELECT. , , , SQL-, IGNORE.
"row too long" (" ") SQL.
MySQL (
InnoDB),
SQL-.

9.16.1. InnoDB
InnoDB,
, , .

1005 (ER_CANT_CREATE_TABLE). .
150, , , .

1016 (ER_CANT_OPEN_FILE). InnoDB


InnoDB . f rm . . 9.18.1.

1114 (ER_RECORD_FILE_FULL). InnoDB . ,


.

1205 (ER_LOCK_WAIT_TIMEOUT). .
.

1213 (ER_LOCK_DEADLOCK). . .

1216 (ER_NO_REFERENCED_ROW). ; . .

1217 (ER_ROW_IS_REFERENCED). ,
; . .

9.16.

575

9.16.2.
perror,
MySQL.
Linux. Linux
(http://www.iglu.org.i1/lxr/source/include/asrai386/errno.h).
1 (EPERM). .
2 (ENOENT). .
3 (ESRCH). .
4 (EINTR). .
5 (). -.
6 (ENXIO). .
7 (E2BIG). .
8 (ENOEXEC). .
9 (EBADF). .
10 (ECHILD). .
11 (EAGAIN). .
12 (ENOMEM). .
13 (EACCES). .

14 (EFAULT). .

15 (ENOTBLK). .
16 (EBUSY). .
17 (EEXIST). .
18 (EXDEV). .
19 (ENODEV). .
20 (ENOTDIR). .

21 (EISDIR). .

22 (EINVAL). .

23 (ENFILE). .
24 (EMFILE). .
25 (ENOTTY). i o c t l .
26 (ETXTBSY). .
27 (EFBIG). .
28 (ENOSPC). .
29 (ESPIPE). .
3 0 (EROFS). .
31 (EMLINK). .

576

9. InnoDB


Windows. Microsoft :
http://msdn.microsoft.com/library/default.asp?url=/library/
en-us/debug/base/system_error_codes.asp

1 (ERROR_INVALID_FUNCTION). .

2 (ERROR_FILE_NOT_FOUND). .

3 (ERROR_PATH_NOT_FOUND). .

4 (ERROR_TOO_MANY_OPEN_FILES). .

5 (ERROR_ACCESS_DENIED). .

(ERROR_INVALID_HANDLE). .

7 (ERROR_ARENA__TRASHED). .

8 (ERROR_NOT_ENOUGH_MEMORY). .

9 (ERROR_INVALID_BLOCK). .

10 (ERRORJBAD_ENVIRONMENT). .

11 (ERROR_BAD_FORMAT). .

12 (ERROR_INVALID_ACCESS). .

13 (ERROR_INVALID_DATA). .

14 (ERROR_OUTOFMEMORY). .

15 (ERROR_INVALID_DRIVE). .

16 (ERROR_CURRENT_DIRECTORY). .

17 (ERROR_NOT_SAME_DEVICE).
.

18 (ERROR_NO_MORE_FILES). .

19 (ERROR_WRITE_PROTECT). .

20 (ERROR_BAD_UNIT). .

21 (ERROR_NOT_READY). .

22 (ERROR_BAD_COMMAND). .

23 (ERROR_CRC). ( ).

24 (ERROR_BAD_LENGTH). .

25 (ERROR_SEEK).
.

26 (ERROR_NOT_DOS__DISK). .

27 (ERROR_SECTOR_NOT_FOUND). .

28 (ERROR_OUT_OF_PAPER). .

29 (ERROR_WRITE_FAULT). .

30 (ERRORREADFAULT) . .

9.17. InnoDB

577

31 (ERROR_GEN_FAILURE). , , .

32 (ERROR_SHARING_VIOLATION). ,
.

33 (ERROR_LOCK_VIOLATION). , .

34 (ERROR_WRONG_DISK). . %2 (
: %3) % 1 .

36

(ERROR_SHARING_BUFFER_EXCEEDED). -

38 (ERROR_HANDLE_EOF). .

39 (ERRORJiANDLE_DlSK_FULL). .

112 (ERROR_DISK_FULL). .
123 (ERROR_INVALID_NAME). , .

1450 (ERROR_NO__SYSTEM_RESOURCES). .

9.17. InnoDB

|
fj

1000 .

1024 .

, BLOB TEXT,
; ,
8000 . LONGBLOB LONGTEXT 4 , , BLOB TEXT, - 4 .
InnoDB 512 BLOB TEXT , .


2 .

InnoDB 4 .

10 . 4
(64 ), .

InnoDB FULLTEXT.

Windows InnoDB
. Unix
Windows , ,
.

MySQL mysql My ISAM InnoDB!


. , MySQL
, mysql_install_db.

578

9. InnoDB

InnoDB . (
.) SELECT
COUNT(*) FROM T, InnoDB ,
, .
,
, . ,
MySQL. SHOW TABLE STATUS, .
. 9.12.

AUTOINCREMENT .
AUTOINCREMENT. My ISAM
AUTOINCREMENT .

InnoDB AUTO_INCREMENT
CREATE TABLE ALTER TABLE.
InnoDB,
,
.

MySQL InnoDB
AUTOINCREMENT ( , ,
).

AUTOINCREMENT
, InnoDB BIGINT -9223372036854775808, a BIGINT
UNSIGNED - 1. BIGINT 64 , , ,
, BIGINT . . MylSAM - MySQL, - .

DELETE FROM _ , ,
.

TRUNCATE _ DELETE FROM __ InnoDB AUTO__INCREMENT.

SHOW TABLE STATUS InnoDB,


, .
SQL.

,
:
CREATE TABLE T (A CHAR(20), INT, UNIQUE (A(5))) TYPE = InnoDB;
, InnoDB .
MySQL 4.0.14 4.1.1 .

INSERT DELAYED InnoDB .

9.18. InnoDB

579

MySQL LOCK TABLES


InnoDB, SQL-. ,

,
. ,
, ,
. .
, , , InnoDB, . , ,
(
).
MySQL 3.23.52 . , .
MySQL 3.23.52.
LOAD TABLE FROM MASTER
. My ISAM, ,
InnoDB.
InnoDB 16 .

8 64 . UNIV_PAGE_SIZE
UNIV_PAGE_SIZE_SHIFT univ.i.

9.18. InnoDB
: -
, , MySQL,
_. err mysql. err Windows.
MySQL , mysqld_safe Windows.
, mysqld ,
. Windows
console,
.
, InnoDB.
,
, innodbmonitor, InnoDB.
, innodb_lock_monitor. , innodb_table_monitor, InnoDB.

580

9. InnoDB

, , CHECK
TABLE.

9.18.1.
InnoDB
, MySQL . f rm, ,
InnoDB . . frm DROP
DATABASE MySQL, 3.23.44, , . frm InnoDB.
CREATE TABLE. , .
, InnoDB, , "" InnoDB, .frm.
:
InnoDB: Error: table test/parent already exists in InnoDB internal
InnoDB: data dictionary. Have you deleted the .frm file
InnoDB: and not used DROP TABLE? Have you used DROP DATABASE
InnoDB: for InnoDB tables in MySQL version <= 3.23.43?
InnoDB: See the Restrictions section of the InnoDB manual.
InnoDB: You can drop the orphaned table inside InnoDB by
InnoDB: creating an InnoDB table with the same name in another
InnoDB: database and moving the .frm file to the current database.
InnoDB: Then MySQL thinks the table exists, and DROP TABLE will
InnoDB: succeed.
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:
InnoDB:

: test/parent
InnoDB. , .frm
DROP TABLE. ,
DROP DATABASE InnoDB MySQL 3.23.43.
. "Restrictions" ("") InnoDB.
"" InnoDB,
InnoDB
.frm .
MySQL ,
DROP TABLE .

, ,
.
,
M y S Q L . InnoDB:
f

ERROR 1016: Can't open file: child2.InnoDB'. (errno: 1)


:
InnoDB: Cannot find table test/child2 from the internal data dictionary
InnoDB: of InnoDB though the .frm file for the table exists. Maybe you

9.18. InnoDB

581

InnoDB: have deleted and recreated InnoDB data f i l e s but have forgotten
InnoDB: to delete the corresponding .frm files of InnoDB tables?
InnoDB:
InnoDB:
InnoDB:
InnoDB:

test/child2
InnoDB, .frm
,


.
InnoDB,
.frm InnoDB.

"" . frm, InnoDB. .


MySQL ALTER TABLE, ""
InnoDB. innodb_table_monitor,
# s q l . . . , MySQL ,
.
, MySQL 3.23.48.
"" #sql_id , rsql_id_recover__innodb_tmp_table
:
CREATE TABLE rsql_id_recover_innodb__tmp_table 4 (...) TYPE=InnoDB;
, , , '-'.
.
,
CREATE TABLE rsql_id.frm
#sql_id.frm . ,

, '#'.
.

10
MaxDB

axDB - . MaxDB
, SAP DB.

10.1. MaxDB
SAP DB 80- , (Adabas). . SAP AG, , (Walldorf), ,
, SAP DB.
SAP
SAP, - R/3. ,
SAP DB ,
Oracle, Microsoft SQL Server DB2 IBM. 2000 SAP AG SAP
DB GNU GPL, , . 2003 2000 SAP AG
SAP DB ,
2000 , ,
APO/LiveCache.
2003 MySQL AB SAP AG . MySQL AB SAP DB, , , GNU GPL. 2003 SAP
DB - MaxDB.

10.2.
MaxDB , , MySQL AB. To MaxDB GNU General Public License, . 1.4.
MySQL MaxDB ,
SAP.

10.5. MaxDB MySQL

583

MaxDB 7.5.00 2003


.

10.3. , MaxDB
MaxDB - http: //www.mysql. com/products/maxdb.
, http://www.sapdb.org, .

10.4 MaxDB
MaxDB - . , , . ,
. Microsoft Clustered Server
, .
Windows-, .

10.5. MaxDB MySQL



MaxDB MySQL:
MaxDB - . MySQL -, .
MaxDB , MySQL. ,
MaxDB IBM OS/2.
MaxDB - . MySQL TCP/IP ( SSL- ), (
Unix- ) (
Windows NT).
MaxDB . MySQL 5.0. MaxDB
SQL, MySQL 5.1. MaxDB
, , .
MaxDB , Web-
. MySQL - , (MySQL Control Center,
MySQL Administrator) . Web MySQL .
MaxDB , MySQL. MaxDB RDO,
ADO .NET, MySQL. MaxDB SQL C/C++.

584

10. MaxDB

MaxDB , MySQL: , , (alerts)


- .

10.6.
MaxDB MySQL
MaxDB,
7.5.00. MaxDB
MySQL.
- MySQL MaxDB MySQL.
MySQL MaxDB, mysql, mysqldump mysqlimport. mysqldump,

( ) .
MySQL MaxDB . MySQL, MaxDB
. , .
. 5.1.

10.7. MaxDB
MySQL, MaxDB ,
.
,
. . 10.1
MaxDB, MySQL.
MySQL , MySQL
. - ,
MaxDB MySQL, , .
. MaxDB MySQL
-
MaxDB
MaxDB

MySQL

ADDTIMEO

,
"@table"
SQL
SQL

ALPHA

SQL

ARRAY

A S C I I ()

SQL

ASCII (),

AUTOCOMMIT

,
ON ()

, OFF ()

ADDATE ()

ADDATE (), MySQL 4.1.1


ADDTIME (), MySQL 4.1.1

10.7. MaxDB

585
.

-
MaxDB
MaxDB

MySQL

BOOLEAN

,

TRUE, FALSE NULL

BOOLEAN MySQL 4.1.0,


BOOL, TINYINT (1). ,
TINYINT, , NULL. TRUE FALSE 1

CHECK

CHECK TABLE - ,

COLUMN

COLUMN,

CHAR()

SQL

CHAR () - , ,
.

COMMIT

, ,

COSHO

SQL

SQL

() -

CREATE

SQL,

CREATE

DATABASE

SQL

DATABASE ( ) ; DATABASE
, , CREATE DATABASE

DATE()

SQL

CURRENT_DATE

DATEDIFFO

SQL

DATEDIFF ( ) , MySQL 4.1.1

DAY()

SQL

DAYOFWEEK()

SQL

DAYOFWEEK ( ) , 1, MaxDB MySQL

SQL

DISTINCT, :
SELECT DISTINCT

DISTINCT

AVG, MAX, MIN, SUM

DROP INDEX, ,

EBCDIC ()

SQL

EXPAND ()

SQL

EXPLAIN

EXPLAIN, ,

FIXED ()

SQL

FLOAT ()

SQL

HEX()

SQL

HEX ( ) , ,

INDEX ()

SQL

INSTR () LOCATE ( ) , ,

DROP

DROP INDEX,

586

10. MaxDB
. 10.1

-
MaxDB
MaxDB

MySQL

INDEX, IGNORE INDEX


USE INDEX, IGNORE INDEX
,

- FROM SELECT; ,
SELECT; , SELECT...FROM...USE INDEX
SELECT...USE INDEX

INDEX

USE

INITCAPO

SQL

LENGTH()

SQL

LENGTH (), ,

LFILLO

SQL

LIKE

LIKE, LIKE MaxDB


MySQL REGEX

LIKE


LIKE MaxDB
"%"," ", " C o n t r o l u n d e r l i n e " , "Control-up
arrow", " * " " ? "

MySQL
"%" " "

LPAD()

SQL

LPAD (),

LTRIMO

SQL

LTRIM (),

MAKEDATEO

SQL

MAKEDATE (), MySQL 4.1.1

I M E ( )

SQL

IME (), MySQL 4.1.1

MAPCHARO

SQL

MICROSECOND()

SQL

MICROSECOND (), MySQL 4.1.1

NOROUND()

SQL

NULL

NULL; MaxDB NULL, , , . MySQL


.

PI

SQL

PI (), ,
MySQL

REF

RFILLO

SQL

ROWNO

LIMIT

WHERE
RPAD()

SQL

RPAD (),

RTRIM()

SQL

RTRIM (),

SEQUENCE

CREATE SEQUENCE,DROP

AUTO_INCREMENT, ,

SEQUENCE

10.7. MaxDB

587
. 10.1

MaxDB


MaxDB

MySQL

SINHO

SQL

SOUNDS ()

SQL

SOUNDEX ( ) ,

STATISTICS

UPDATE STATISTICS

ANALYZE TABLE, ,

SUBSTRO

SQL

SUBSTRING ( ) ,

SUBTIMEO

SQL

SUBTIME ( ) , MySQL 4.1.1

SYNONYM

CREATE [PUBLIC] SYNONYM,


RENAME SYNONYM,
DROP SYNONYM
TANHO

SQL

TIMEO

SQL

CURRENT_TIME

TIMEDIFFO

SQL

TIMEDIFF ( ) , MySQL 4.1.1

TIMESTAMPO

SQL

TIMESTAMP ( ) , MySQL 4.1.1

TIMESTAMPO

DAYOFMONTHO
DAYOFYEAR()

SQL

TIMEZONEO

SQL

TRANSACTION()

TRANSLATE()

SQL

REPLACE ( ) ,

TRIMO

SQL

TRIM ( ) ,

TRUNCO

SQL

TRUNCATEO,

USE

USER

SQL

USER ( ) , ,
, MySQL

UTC_DIFF ()

SQL

UTC_DATE ( ) , , UTC_DIFF ()

SQL,
COALESCE ()

COALESCE ( ) ,

VARIANCE()

SQL

VARIANCE ( ) , MySQL 4.1.0

WEEKOFYEARO

SQL

WEEKOFYEAR ( ) , MySQL 4.1.1

VALUE()




MySQL


, ,
MySQL. ,
.

.1.
, , - ,
:

, ,
( , , ), :
. , <Caps Lock>.
Caps Lock , .
( , .)

ping .

, MySQL, .

. (
.)
. , - , , . , , glibc, .

.1.

589

-,
, .

, , ,
kbdjnode -a.

(/var/log/messages )
. ,
MySQL, MySQL. . 4.8.

, ,
, . top, ps,
(Task Manager) - , , .

top, df , ,
, , - .

- ,
. , , .

, , , MySQL ,
.

, , , . ,
, MySQL. ,
. , , . .
, ,
. , , " ". .
1. , :

(core dump)?

? top.
. ,
, .

mysqld, - mysqladmin -u root ping mysqladmin - root


processlist?


MySQL? (, mysql.) He ?
- ?

, ,
1.7.1.2.

590

. MySQL

.2.
MySQL
,
MySQL. ,
MySQL.

.2.1.
Access denied ( ) .
MySQL, . . 4.4.8,
4.4.2.

.2.2. []
MySQL
MySQL Unix mysqld : Unix, (
/tmp/mysql.sock), TCP/IP, . Unix- , TCP/IP, ,
. Unix- ,
localhost.
MySQL Windows 9x Me, TCP/IP. Windows NT, 2000,
enable-named-pipe,
, , .
MySQL. mysqld, MySQL
. , TCP/IP. , ' . ' .
(2002) Can't connect t o . . . (He ...)
, MySQL,
Unix- TCP/IP.
, mysqld
. ( ps Unix Windows).
, (. 2.4.4).
mysqld , , . TCP/IP Unix-
; 1__ IP- , .
shell>
shell>
shell>
shell>
shell>
shell>

mysqladmin
mysqladmin
mysqladmin
mysqladmin
mysqladmin
mysqladmin

version
variables
-h 'hostname4 version variables
-h 'hostname4 port=3306 version
-h 1__ version
protocol=socket socket=/tmp/mysql.sock version

.2. MySQL

591

hostname. hostname ( ) mysqladmin.


hostname,
Windows, ( )
-. -h 127.0.0.1,
TCP/IP .
Can' t connect to local
MySQL server ( MySQL):
mysqld.
, MIT-pthreads.
, , MySQL
MIT-pthreads. . 2.1.1. MIT-pthreads Unix-. , Unix-,
. :
shell> mysqladmin -h hostname4 version
- Unix-, mysqld (
/tmp/mysql. sock). , , /tmp.
mysqladmin version, , ,
mysqladmin . , mysql.sock, - . . .4.5.
mysqld socket=/path/to/socket, . , MySQL. socket . .
.4.5.
Linux, ( ). mysqld
(, k i l l mysqlzap) ,
mysqld. . .4.2.

, Unix-, .
, , mysqld --socket, , ,
.
Can' t connect to MySQL server on
( MySQL ),
, , :

592

. MySQL

, , t e l n e t 3306
<Enter>. (3306 - ,
MySQL. , .) MySQL ,
, .
: t e l n e t : Unable to connect to remote host: Connection
refused (telnet: : ), , .
,
Unix- mysqladmin -h localhost variables.
TCP/IP, ( port).

, mysqld --skip-nrtworkingservice. ,
TCP/IP.

.2.3.
MySQL 4.1 , , , ,
. 4.1,
:
shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
:
, 4.1.1 .
,
,
.
, , . SET PASSWORD
OLD_PASSWORD():

mysql> SET PASSWORD FOR


->

' '

@ ' '

= OLD_J?ASSWORD (' _')

UPDATE FLUSH PRIVILEGES:


mysql> UPDATE m y s q l . u s e r SET Password = OLD_PASSWORD('_')
-> WHERE Host = '* AND U s e r =
'1;
mysql> FLUSH PRIVILEGES;

^ . MySQL ,
, .

.2. MySQL

593

1. mysqld --old-password.
2. ,
4.1.
:
mysql> SELECT Host, User, Password FROM mysql.user
-> WHERE LENGTH(Password) > 16;
, ,
User Host, OLDPASSWORDO
SET PASSWORD UPDATE, .

4.4.9.

.2.4.
MySQL , password -, :
shell> mysql -u _ -
Enter password:
, ,
, , , Enter password:. , ,
,
( ). , MySQL.
, MySQL, 8 ,
.

.2.5. __
, , mysqld
' _', :
Host '_1 is blocked because of many connection errors.
Unblock with 'mysqladmin flush-hosts'
' * .
'mysqladmin flush-hosts'
max_connect_errors. , max_connect_errors
, , - (, - ),
, mysqladmin flush-hosts FLUSH HOSTS.
. 4.2.3.
mysqld 10 . , :
shell> mysqld_safe max_connect_errors=10000 &
,
, TCP/IP .

594

. MySQL

,
max_connect_errors.

.2.6.
mysqld Too many connections
( ), , .

maxconnections. 100.
, mysqld, .
mysqld max_connections+l . SUPER. SUPER , ( ), SHOW PROCESSLIST ,
.
, MySQL, . Linux
Solaris 500-1000 ,
, , .

.2.7.
, mysql,
, , mysql , :
mysql: Out of memory at line 42, 'malloc.c 1
mysql: needed 8136 byte (8k), memory in use: 12481367 bytes (12189k)
ERROR 2008: MySQL client ran out of memory
, .
, ? , . mysql quick.
API mysql_use_result(),
, ( - ).

.2.8. MySQL
Lost connection t o s e r v e r during query ( ).
MySQL s e r v e r has gone away ( MySQL ) , -.
( - ):

CR_SERVER_GONE_ERROR

CR_SERVER_LOST

,
( ) .

.2. MySQL

595

.
, wait_timeout mysqld. . 4.2.3.
, ,
.
, - ,
, KILL mysqladmin k i l l .
MySQL server has gone away , , . , .
, , mysqladmin version .
- , mysqld ,
mysqld. , . . .4.2.
,
. mysqld , ,
, , - .
(, BLOB), ,
maxallowedpacket, 1 . ,
. .2.9.
, 16
, - 4.0.8, - 4.0.8 .
, ,
:
, MySQL.
. . .4.2.
mysqld ,
CHECK TABLE,
?
wait_timeout? (
mysqladmin variables.)
mysqld log, ,
?
. 1.7.1.2.

.2.9.
- SQL-,
MySQL, , .
MySQL 3.23 16 , - ,
- . MySQL 4.0.1,
1 .

596

. MySQL

MySQL mysqld ,
max_allowedj?acket , Packet too large ( ) . Lost connection to MySQL server during query (
MySQL ).
, max_allowed_packet, ,
, .
mysql,
max_allowed_packet 16 . , MySQL 4.0.
4.0 , mysql :
mysql> mysql max_allowed_packet=32M
32 .
max_allowed_packet 1 .
, (,
BLOB). , 16 , :
mysql> mysqld max_allowedjpacket=16M
MySQL 4.0 :
mysql> mysqld set-variable=max_allowedjpacket=16M
max_allowed_packet .
, 16 , :
[mysqld]
max_allowed_packet=16M
MySQL 4.0 -:
[mysqld]
set-variable = max_allowed_packet=16M
, . , mysqld , ,
. , , , ,
, .
, BLOB, mysqld
. , , ulimit -d 256000 mysqld_safe
.

.2. MySQL

597

.2.10.
- (. 4.8.1). MySQL 3.23.40,
warnings ( log-warnings, MySQL 4.0.3),
:
010301 14:38:23 Aborted connection 854 to db: 'users' user: 'josh'
Aborted connection ( )
, :
mysql_close () .
, wait_timeout
interactive_timeout , . . 4.2.3.
, .
,
Aborted_clients.
Aborted_clients
:
.
.
.
, connect_timeout . . 4.2.3.
- , , -
!
,
:
Ethernet- Linux, , . Ethernet Linux .
, FTP
. "---",
, Linux.
, / , , , .
- ,
.
TCP/IP.
, , , . , .
max_allowed_packet ,
, mysqld. . .2.9.

598

. MySQL

.2.11.
:
MySQL , , 3.23 , , tmp__table_size . , -0 tmp_table_size=#,
mysqld , SQL SQL_BIG_TABLES .
mysqld big-tables.
, SQL_BIG_TABLES .
MySQL 3.23, .
tmp_table_size , My ISAM, .
InnoDB , InnoDB. . 9.8.
ISAM My ISAM , 2 ,
- .
My ISAM, ,
, . ( MAX_ROWS , MySQL myisam_data_pointer_size. 4 4 .) . 4.2.3.

:
SHOW TABLE STATUS FROM database LIKE '_';
myisamchk -dv ///--.
, ALTER
TABLE:
ALTER TABLE _ MAX_ROWS=1000000000 AVG_ROW
AVGROWLENGTH TEXT
BLOB. MySQL , .

.2.12. /

, , MySQL
:
Can't create/write to file !\\sqla3fe_0.ism'.
Windows, Unix . mysqld tmpdir,
[mysqld] . , C:\temp
:

.2. MySQL

599

[mysqld]
tmpdir=C:/temp
: /temp . . 3.3.2.
perror. ,
,
:
shell> perror 28
Error code 28: No space left on device

A.2.13.
Commands out of sync; you can't run t h i s
command now ( ; ) , ,
.
, , mysql_use_result () mysql_free_result (). , , ,
mysql_use_result () mysql_store_result ().

.2.14.
, , mysqld
, user
:
Found wrong password for user: 'some_user'@'some_hostf; ignoring user

:
, mysqld user.
, mysqlshow mysql user
Password; 16 . ,
, scripts/add_long_password.
( 8 ), a mysqld --old-protocol.
user, , mysqld
old-protocol.
user, PASSWORD (). mysql user, PASSWORD ():
x

mysql> UPDATE user SET Password=PASSWORD( _ )


-> WHERE User='* AND Host=' 1 ;

A.2.15. '
, ,
:

600

. MySQL

Table '^* doesn't exist


Can't find f i l e : '_} (errno: 2)
, , :
MySQL , ,
.
, ,
Windows,
.
, , SHOW
TABLES.

.2.16.
:
MySQL Connection Failed: Can't i n i t i a l i z e character set _
:
,
. ,
configure with-char=_ with-extra-charsets=
_. . 2.3.2.
MySQL with-extra-charsets=
complex, . .
4.7.1.
, mysqld, , .
:
. .
2.3.2.
, .
character-set-dir.

.2.17.
MySQL ERROR ' . . . ' not found (errno: 23),
Can't open f i l e : . . . (errno: 24), errno 23
errno 24, , MySQL . perror, :

shell> perror 23
File table overflow

.. ,

601

shell> perror 24
Too many open f i l e s

shell> perror 11
Resource temporarily unavailable

, mysqld
. mysqld,
, .
mysqld, ,
,
table_cache ( 64).
max_connections ( - 100).
open-files-limit mysqld_safe, ( MySQL
3.23.30) open_files_limit. . 4.2.3.
- . . 3.3.2.
mysqld,
, mysqld_safe. ulimit -n 256. '#',
, 256, ,
mysqld.
open-files-limit ulimit ,
, . "" , , mysqld_safe
mysqld root ( ,
user,
root ).
, , .
^

rl t c s h , u l i m i t ! || , .
mysqld_saf e sh.

.. ,
.3.1.
MySQL
MySQL
,
mysql_, :
/tmp/ccFKsdPa.o: In function N main f :
/tmp/ccFKsdPa.o(.text+Oxb): undefined reference to 4 mysql_init f
/tmp/ccFKsdPa.o(.text+0x31): undefined reference to 4 mysql_real_connect'

602

. MySQL

/tmp/ccFKsdPa.o (,t.ext+0x57) : undefined reference to N mysql_real_connect'


/tmp/ccFKsdPa.o(.text+0x69): undefined reference to 4 mysql_error'
/tmp/ccFKsdPa.o(.text+0x9a): undefined reference to 4 mysql_close'
, - -Imysqlclient
, ,
. , :
shell> mysql_config libs
mysqi__config ,
.
undefined reference, uncompress
compress, -lz
.
undefined reference ,
, connect,
, , .
undefined reference , :
mf_format.(.text+0x201) : undefined reference to l x s t a t 1
, MySQL
, 100% . MySQL . . 2.3.
,
MySQL. ,
mysql_, ,
mysqlclient, , libmysqlclient.so. , ,
. ,
:
, libmysqlclient.so,
LD_LIBRARY_PATH.
, libmysqlclient.so,
LD_LIBRARY.
libmysqlclient.so , , /lib, ,
ldconf ig.

.
, ,
.

.. ,

603

.3.2. MySQL

MySQL 4.0.17 4.1.2, Windows


. (
. ,
MySQL 3.23.54.)
Unix MySQL- mysqld . , , Unix root. mysqld _, :
1. , ( mysqladmin shutdown).
2. ,
_ (,
root):
shell> chown -R ^ /'//mysql/'_
, , _.
MySQL , , , chown -R .
3. _.
MySQL 3.22 ,
root, =_. mysqld , ,
, _.
4. , , user
[mysqld] /etc/my.cnf my.cnf .
:
[mysqld]
-_
Unix- ,
MySQL root . , ,
mysql user=root . ( MySQL - , ,
.) . 2.4.

.3.3.
, , UMASK , mysqld. ,
MySQL , :

604

. MySQL

ERROR: Can't find f i l e : '//_.frm'

(Errcode: 13)

UMASK 0660. ,
mysqld_safe :
shell> UMASK=384 # = 600
shell> export UMASK
shell> mysqld_safe &
MySQL RAID-
0700. UMASK_DIR.
, ,
UMASK UMASK_DIR. , , :
shell> UMASK_DIR=504 # = 770
shell> export UMASKJHR
shell> mysqld__safe &
MySQL 3.23.25 , UMASK UMASK_DIR , .
. .

.4. ,
.4.1. root
root MySQL, root. (.
4.3.1).
root , ,
. Windows.
Unix .
Windows.
1. Administrator ().
2. MySQL, . , Windows, (Service manager):
S t a r t s Control Panel^AdministratJve Tools^Services (^ ^ => ).
MySQL .
, ,
.
3. :
c
c
c
c
Start >Run t>cmd(yc >Bo >cmd).
4. , MySQL : \mysql.
, .
DOS :
:\> C:\mysql\bin\mysqld-nt --skip-grant-tables

.4. ,

605

, .
5. , ( ):
:\> C:\mysql\bin\mysqladmin -u root
flush-privileges password "_"
:\> C:\mysql\bin\mysqladmin - root - shutdown
'_* , . . ,
.
6. MySQL, .
, Windows
Services ( Windows). ,
, .
7. .
Unix root :
1. root ,
mysqld.
2. .pid, .
,
. /var/lib/mysql/, /var/run/mysqld/
/usr/local/mysql/data/. , .pid, a
mysql, .
MySQL, k i l l (
k i l l -9) mysqld, .pid, :
shell> k i l l "cat /--1/_.<1*
cat. k i l l .
3. MySQL skip-grant-tables:
shell> mysqld_safe skip-grant-tables &
4. MySQL root@localhost:
shell> mysqladmin -u root flush-privileges password " _"
"_ " , .
5. MySQL, .
6. .
,
mysql:
1. mysqld skip-grant-tables, .
2. :
shell> mysql -u root

606

. MySQL

3. mysql:
mysql> UPDATE mysql.user SET Password=PASSWORD ('_')
->
WHERE U s e r = ' r o o t ' ;
mysql> FLUSH PRIVILEGES;

'_ , .
4. MySQL, .
5. .

.4.2. , MySQL
MySQL .
, , ,
- . , , ,
.
, - , mysqld,
. , mysqld, mysqladmin version. mysqld
,
(. 4.8.1).
mysqld
resolve_stack_dump. , , , 100% .

. MySQL write ()
SQL- , . ( ,
delay-key-write; , .) , , mysqld , ,
. MySQL
SQL-, mysqld
flush.
, , , - :
MySQL .
mysqld,
.

mysqld, .
mysqld, , ( lockd),
mysqld skip-external-locking.

.4. ,

607

, , mysqld.

. , , . , ALTER TABLE .

, ,
, , . ,
:

mysqld mysqladmin shutdown, myisamchk silent


force */* .MY I , My ISAM, mysqld. , . .
4.

mysqld --log ,
, , .
95% . - . . 4.8.2. ,
, . .
1.7.1.3.

,
.

mysql-test. MySQL. , . sql-bench , , - sql-bench MySQL.

fork_big.pl ( t e s t s ).

MySQL , , - . MySQL , .
, . MySQL
with-debug with-debug=full configure MySQL.

, .

skip-external-locking mysqld.
lockd . skip-externallocking mysqld . ( ,
mysqld , myisamchk. , .)

608

. MySQL

mysqladmin -u root processlist, ,


mysqld , ? mysqld
"" , .
, , , mysqladmin -u root processlist
.

mysqladmin -i 5 status mysqladmin -i


5 -r status, , .
:
1. mysqld gdb ( ).
2. .
3.
. gdb
, mysqld gdb:
backtrace
info local
up
info local
up
info local
gdb , ,
info threads
thread #, # - .
Perl-, mysqld .
(. 1.7.1.3).
, . MySQL , ,
(, , ).
, , VARCHAR ( BLOB TEXT), VARCHAR CHAR
ALTER TABLE. MySQL .
, .
, ,
MySQL AB
,
,
, .

.4. ,

609

.4.3. MySQL
, MySQL :

, ,
; , ,
.

, :
, .

, mysqladmin k i l l .
,
( ).

, . "" ,
, ,
.

, REPAIR TABLE
OPTIMIZE TABLE, LOAD DATA INFILE ALTER TABLE.
, , .
, MySQL ,
. ALTER
TABLE, .

.4.4. MySQL
MySQL TMPDIR , . TMPDIR , MySQL .
/tmp, /var/tmp /usr/tmp. ,
mysqld tmpdir,
.
MySQL 4.1, ,
. " : " Unix
" ; " Windows, NetWare OS/2.
S !
Ji
Q

, ,
, .

MySQL ,
--tmpdir , , , , . -

610

. MySQL

, LOAD DATA INFILE. ,


.
MySQL . ,
, mysqld .
, ,
, .
(ORDER BY GROUP BY) MySQL
. :
( + sizeof{ ))
*
*2
4 ,
.
SELECT MySQL .
SQL_*.
ALTER TABLE ,
.

.4.5. MySQL
/tmp/mysql.sock
Unix, , /tmp/mysql.sock. , Unix tmp .
Unix, , /tmp
, , root. ,
sticky /tmp, root :
shell> chmod +t /tmp
, , Is -Id /tmp. t, .
,
Unix-. ,
. :
. ,
/etc/my.cnf :
[mysqld]
socket=/path/to/socket
[client]
socket=/path/to/socket
socket mysqldsaf e, .

.4. ,

611

MYSQL_UNIX_PORT Unix-.
MySQL , . withunix-socket-path configure. . 2.3.2.
, ,
:
shell> mysqladmin soctet=///_a

version

.4.6.
SELECT NOW (), GMT,
, . , UNIX_TIMESTAMP() . , , , mysqldsafe
mysql. server. . .
timezone=
__ mysqldsafe. TZ mysqld.
. ,
, .

,
MySQL.
.
,
, . , , .
MySQL
. . 3.3.2.
.1.

C++ ( configure).

CFLAGS

( configure).

CXXFLAGS

C++ ( configure).

DBIJJSER

Perl DBI.

( configure).

DBI_TRACE

Perl DBI.

mysql
$/.mysql_history.

libmysqlclient.so.

LD_RUN_PATH
MYSQL_DEBUG
MYSQLJilSTFILE
MYSQL_HOST
MYSQL PS1

.
mysql;
$/.mysql_history.
, mysql.
mysql.

613

. . 1

MYSQL_ PWD

raysqld.
, ! . 4.5.6.

MYSQL_ TCP_PORT

TCP/IP.

MYSQL_UNIX_PORT

Unix;
.

PATH

MySQL.

TMPDIR

TZ

. . .4.6.

UMASK_ DIR

;
.

UMASK

USER

Windows NetWare?
raysqld.


API-, 19; 20; 31; 68; 158; 163; 165;
268; 536; 537
G
GnuPG, 90-92
GPL, . GNU General Public
License, 18; 29; 32-34; 36; 39; 56; 141; 506;
524;582
innodb_additional_mem_pool_size, 236; 527;
529; 530
innodb_buffer_pool_awe memmb, 530
innodb_buffer_pool_size, 236; 527; 529; 530
innodb_data_file_path, 215; 236; 500; 525-528;
531; 535; 546; 572
innodb_data_home_dir, 236; 525-528; 531;
535;546;572
innodbfastshutdown, 236; 531
innodb_file_per_table, 531; 544
innodbfiletothreads, 531
innodb_flush_log_at_trx_cornrnit, 236; 527;
529; 531; 561
innodb_flush_method, 236; 529; 532; 561
innodb_force_recovery, 236; 532; 549
innodb_lock_wait_timeout, 236; 529; 532; 559
innodb_log_arch_dir, 236; 529; 532; 533
innodblogarchive, 236; 532
innodb_log_buffer_size, 236; 527; 529; 532
innodbjog_file_size, 236; 527; 529; 533
innodblogfilesingroup, 236; 529; 533
innodb_log_group_home_dir, 236; 529; 532;
533
innodb_max_dirty_pages_pct, 533
innodbmirroredloggroups, 236; 533
innodbopenfiles, 533
innodbthreadconcurrency, 236; 529; 533; 567

SMP, .
, 78; 170; 172;
175; 177
-temp-pool, 161; 230

, 62

readline,32; 104; 107; 132; 190; 191; 467


regexp, 32; 45; 493

, 47; 70; 388; 432; 532;


557-560

, 15

, 345; 348
, 345
, 345; 351
, 226; 345; 347
, 100; 101; 103; 148; 345; 346; 597
ISAM, 345

, 29; 37; 38; 43; 65; 66; 68; 100; 539;


541; 542; 562

1005 (ER_CANT_CREATE_TABLE), 574
1016 (ER_CANT_OPEN_FILE), 574
1114 (ER_RECORD_FILE_FULL), 574
1205 (ER_LOCK_WAIT_TIMEOUT), 574
1213 (ER_LOCK_DEADLOCK), 574
1216 (ER_NO_REFERENCED_ROW), 574
1217 (ER_ROW_IS_REFERENCED), 574
MySQL AB
http://www.mysql.com, 15
, 29; 30
, 21; 24; 28; 31; 40
, 28

,87;88; 188
,88
/, 89
-5.0, 86
, 85; 177
, 85
egcs,89; 118; 122; 178; 179; 183; 189; 190


gcc, 85-90; 118; 122; 123; 127-131; 173;
176-190; 192-196; 199; 200;451
pgcc,82; 122; 451; 452
xlC_r,87; 188

CHANGE , 59
DELAYED, 46; 59; 63; 71; 164; 172; 224;
241; 246; 262; 425; 429; 434; 489; 578
DROP INDEX, 59; 165; 559; 585
DROP , 59
IF EXISTS, 17; 25; 59
IGNORE, 44; 58; 59; 68; 72; 162; 232; 233;
411; 444; 445; 468; 549; 574; 586
LIMIT, 39; 46; 47; 59; 158; 380; 418; 420;
423; 424; 434; 440; 476; 477; 586
LOW_PRIORITY, 59; 161; 227; 429; 434
ORDER BY, 21; 46; 59; 72-74; 162; 165;
166; 250; 251; 263; 327; 340; 412; 417419; 421-423; 427; 439; 440; 451; 610
SQL_SMALL_RESULT, 59; 417
WHERE, 20; 21; 58; 61; 64; 66; 70; 74; 75;
151; 152; 157; 247; 267; 269; 307; 309;
347; 348; 362; 409-413; 416-422; 424;
427; 428; 432; 437-440; 476; 491; 512;
537; 554; 555; 557; 558; 586; 592; 593;
599; 606
MD5, 61; 90; 91; 93; 266;
301; 427
, 42

GNU General Public License, 15;


18; 32; 582

M

BDB, 23; 62; 71; 98; 126; 147-149; 155; 214;
215; 223; 228; 238; 239; 242; 252; 350;
396; 411; 430; 432-434; 498; 499; 515521
HEAP, 40; 70; 73; 246; 382; 417; 422; 429;
430; 437; 438; 453; 491; 498; 513
InnoDB, 23; 24; 29; 37; 38; 43; 62; 64; 65; 68;
72; 97; 98; 100; 103; 120; 126; 147; 156;
161; 214; 215; 223; 229; 238; 242; 243;
252; 318; 319; 350; 361; 375; 380; 381;
396; 430; 432; 433; 434; 437; 451; 490;
498;500; 518; 523-564; 567-574; 577581;598
MEMORY, 42; 246; 358; 382; 430; 437; 438;
440; 469; 479; 481; 486; 490; 494; 496;
498; 499; 513-515; 567; 576

615
MERGE, 25; 42; 72; 75; 105; 361; 381; 498;
509; 510-512; 521; 549
MylSAM, 20; 22-25; 37; 38; 40; 42; 45; 46;
59; 62; 64; 65; 68; 72; 153; 159; 160; 161;
163-165; 168; 213; 215; 218; 223-227;
229; 230; 239-241; 243; 247; 248; 250;
252; 318-322; 324; 326; 329; 330; 333338; 345; 366; 374; 375; 381; 383; 394;
396; 403; 404; 411; 416; 417; 425^31;
434; 436; 437; 440; 441; 446; 447; 453455; 457; 458; 460; 461; 463; 465; 485;
489; 491; 492; 498-505; 507-512; 517519; 521; 523; 530; 537; 543-545; 550;
577-579; 598; 607
InnoDB, 563; 579

H
, 63

bash, 112; 185; 186; 203; 210; 389


Bourne, 17; 210
sh, 16; 126; 145; 146; 185; 186; 191; 203; 210;
601
tcsh, 17; 112; 203; 210; 601
zsh,210

ALTER TABLE, 24; 45; 46; 59; 71; 75; 105;


156; 159; 163-165; 246; 248; 279; 324;
331; 361; 414; 426; 427; 457; 458; 489;
499; 501; 504; 510-512; 521; 537; 539541; 543; 545; 549; 559; 573; 578; 581;
598;607-610
ANALYZE TABLE, 59; 71; 72; 321; 324;
381; 408; 411; 415; 416; 424; 485; 512;
519; 522;587
CHECK TABLE, 55; 59; 113; 164; 165; 229;
321; 322; 330; 333; 485; 507; 508; 522;
548; 580; 585; 595
CREATE DATABASE, 59; 389; 390; 490; 585
CREATE TABLE, 24; 25; 40; 45; 53; 59; 61;
65; 71; 105; 155; 156; 230; 233; 240; 246;
247; 279; 280; 331; 381; 425; 437; 458;
487; 488; 490; 491; 495; 498-500; 502;
509; 513; 514; 518; 535; 536; 539-542;
558; 559; 563; 578; 580; 581
AVG_ROW_LENGTH, 24; 96; 331; 598
MAX_ROWS, 24; 96; 246; 247; 331; 514;
598
DROP DATABASE, 59; 105; 162; 164; 267;
361; 389; 390; 559; 569; 580
EXPLAIN, 21; 52; 53; 59; 408; 409; 411; 413416; 418-420; 422-424; 427; 560; 585

616
EXPLAIN SELECT, 52; 53; 59; 408; 413;
423; 560
FLUSH, 53; 59; 71; 75; 105; 151; 152; 229;
246; 252; 262; 269; 271; 277; 289; 294;
304; 306-309; 318; 320; 322; 345-348;
352; 364; 371; 374; 375; 379; 381; 393395; 425; 426; 447; 454; 455; 492; 493;
508; 510; 512; 519; 592; 593; 606
GRANT, 139; 140; 152; 160; 165; 221; 228;
266; 270; 271; 273; 277-280; 282; 283;
286; 288; 289; 292; 296; 298-300; 302310; 317; 374; 381; 407
LOAD DATA INFILE, 44; 47; 59; 72; 105;
106; 224; 231; 239; 244; 248; 253; 273;
279; 294; 319; 320; 373; 384; 391; 425;
426; 429; 461; 468; 481-483; 489; 493;
494; 514; 609; 610
LOCK TABLES, 63; 64; 243; 278; 280; 318;
426; 432-434; 448; 491; 492; 508; 519;
532;558-560; 579
OPTIMIZE TABLE, 59; 71; 72; 164; 321;
324; 333; 334; 381; 427; 429; 485; 505;
506; 512; 519; 522; 609
RENAME DATABASE, 43
RENAME TABLE', 42; 59; 512; 542; 545; 559
REPAIR TABLE, 55; 59; 71; 72; 113; 157;
162; 163; 229; 241; 242; 248; 319; 321;
324; 330; 333; 381; 457; 485; 507; 508;
512; 522; 609
REPLACE, 21; 44; 59; 70; 72; 227; 320; 404;
512; 558; 565;566; 587
RESET, 17; 59; 349; 364; 385; 398; 399
SHOW INDEX, 162; 411; 416
SHOW MASTER STATUS, 161; 280; 375;
376; 379; 393; 395; 399; 401
SHOW OPEN TABLES, 162
SHOW SLAVE STATUS, 162; 280; 369; 372;
391; 394; 399; 401
UNLOCK TABLES, 63; 320; 375; 393; 395;
426; 432; 448; 559; 560

AIX, 77; 86;87;90;188-190; 214; 516
Amiga, 77
BSDI,77;90; 185; 186
FreeBSD, 77; 88; 89; 130; 131; 145; 183; 184;
248; 516
HP-UX, 77; 87; 187; 188; 214
Linux, 24; 77; 78; 81; 85; 86; 89; 91; 92; 94;
107; 109; 122; 127; 131; 133; 135; 138;
145; 161; 170-174; 176-178; 184; 197;
199; 213; 214; 216; 218; 225; 228; 230;
268; 290; 293; 351; 360; 405; 448; 451;
452; 456; 457; 483; 516; 528; 529; 532;
561; 575; 591; 594; 597


Mac OS, 77; 81; 88; 109-111; 114; 117; 138;
144; 179; 214; 218; 245;516
NetBSD,77;185
Novell NetWare, 77; 112
OpenBSD, 77; 185
OS/2 Warp, 77; 196
SCO OpenServer, 77; 194; 516
SCO UnixWare, 78; 196; 516
SGI Irix, 78; 89; 193
Solaris, 24; 77; 78; 86; 127; 130-132; 179183; 214; 218; 224; 227; 252; 448; 452;
454; 457; 516; 594
SunOS, 78; 89; 131; 190
Tru64Unix,78
UNIX, 16; 21; 22; 38; 77; 141; 144; 194; 358;
359; 361; 384; 461; 611; 613
Windows, 15; 16; 21; 22; 38; 49; 51; 52; 55;
56; 78; 91; 93;95-99; 101-107; 133-138;
144; 148-154; 156; 159; 167; 168; 197;
198; 203; 206; 208-210; 213; 214;224;
225; 229; 230; 241; 245; 248; 251; 253;
272; 281; 282; 290; 293; 302; 311; 318;
327; 346; 347; 352-355; 357; 359; 374;
423; 431; 457; 459; 473; 483; 490; 512;
524; 525; 527; 528; 530; 531; 534; 550;
561; 563; 572; 576; 577; 579; 583; 590;
591; 598; 600; 603-605; 609; 613

-analyze, 327; 333; 411; 416; 485; 502


~ansi,57;223;238
AVG_ROW_LENGTH, 24; 96; 331; 598
-backup, 325; 462
-basedir, 216; 224; 354
-big-tables, 224; 453; 598
bind-address, 224
bulk_insert_buffer_size, 161; 235; 239; 257;
425; 503
-character-sets-dir, 224; 325; 341; 345; 468;
479; 485; 496
-character-sets-dir, 224; 325; 468; 479; 485; 496
-check, 93; 325; 485; 486; 493
check-only-changed, 325; 486
-chroot, 224
-config-file, 220
-console, 100; 101; 224; 346; 527; 534; 563;
579
-core-file, 176; 216; 224
core-file-size, 216
correct-checksum, 325
-datadir,216;224;353;358
-data-file-length, 325
-debug, 101; 136; 149; 224; 295; 323; 462;
468; 479; 486; 489; 493; 494; 496


-default-character-set, 224; 340; 380; 468;
486; 489; 496
-default-collation, 224; 340
-defaults-extra-file, 207; 209; 216
-defaults-file, 209; 216; 359
-default-storage-engine, 224
-default-table-type, 224; 252
-delay-key-write, 224; 225; 229; 395; 502;
503; 606
-delay-key-write-for-all-tables, 225
-description, 327; 416
-des-key-file, 225
-enable-locking, 161; 225
-enable-named-pipe, 225; 590
-err-log, 216
-example, 220
-exit-info, 225
-extend-check, 323; 325
-external-locking, 132; 161; 225; 241; 503
-fast, 322; 325; 334; 486; 502
-flush, 225; 241; 489; 493; 606
-force, 171; 322; 325; 326; 462; 468; 479;
481; 486; 489; 494; 607
-help, 16; 22; 101; 119; 121; 136; 140; 141;
147; 168; 203; 204; 207; 212; 220; 223;
277; 321-323; 406; 450; 451; 461; 462;
468; 479; 481; 483; 485; 487; 488; 493;
494; 496
-information, 325
-init-file, 225; 243; 514; 515
-keys-used, 326; 425; 426
-language, 225; 341
--ledir, 217
-log, 72; 74; 141; 161; 216; 217; 220; 224;
226; 227; 239; 245; 319; 346-349; 351353; 376; 377; 382; 386; 398; 399; 401;
595; 597; 607
-log-bin, 72; 226; 239; 319; 346; 348; 349;
352; 353; 376; 398; 399; 401
-log-bin-index, 226; 349
-log-error, 161; 216; 217; 224; 226; 346; 353
-log-isam, 226; 353
log-long-format, 226; 351
-log-queries-not-using-indexes, 226
-log-short-format, 226
-log-slave-updates, 382; 386; 398; 401
-log-slow-queries, 226; 245; 351; 352
-log-update, 226; 347; 352; 353
log-warnings, 161; 227
-log-warnings, 227; 377; 386; 597
-low-priority-updates, 227; 395; 434
-master-connect-retry, 367; 370; 383; 384;
386;391

617
-master-host, 384; 386
-master-info-file, 386
master-password, 384; 386
-master-port, 384; 386
-master-ssl, 384; 386; 387
-master-ssl-ca, 384; 386
-master-ssl-capath, 384; 386
master-ssl-cert, 384; 386
-master-ssl-cipher, 384; 386
-master-ssl-key, 384; 387
-master-user, 384; 387
MAX_ROWS, 24; 96; 246; 247; 331; 514; 598
-max-relay-log-size, 387; 388
-medium-check, 325; 486
-memlock, 227; 244
-myisam-recover, 227; 241; 248; 334; 430;
502; 503
mysqladmin, 220
-mysqld,217;220
-mysqld-version, 217
-new, 155; 157; 208; 228
-nice, 217
-no-defaults, 209; 217; 291
-no-log, 220
no-symlinks, 326
-old-passwords, 159; 298-300
-old-protocol, 166; 228; 599
-one-thread, 228
-open-files-limit, 184; 185; 217; 228; 446;
533;601
-pager, 469; 472
-parallel-recover, 326
-password, 220; 281; 295; 310
-pid-file, 217; 221; 228; 249; 353
-port, 149; 209; 217; 228; 249; 290; 352; 354;
355; 358; 359; 469; 479; 481; 484; 486;
490; 493; 494; 496; 590
-print-defaults, 154; 209
query_cache_type, 161; 237; 249; 259; 264;
362;363;562
-quick, 169; 207; 326; 328; 329; 467; 469;
486; 487; 490; 594
read_buffer_size, 161; 237; 250; 259; 323;
449; 450; 451; 529; 530
read_rnd_buffer_size, 161; 237; 250; 259;
422; 423; 449; 451; 453
-read-only, 325; 387
-recover, 323; 324; 326; 328; 508
-relay-log, 371; 387; 391
-relay-log-index, 387
-relay-log-info-file, 387
relay-log-purge, 387
relay-log-space-limit, 387

618
-replicate-do-db, 388; 392
--replicate-do-table, 388; 392; 393
-replicate-ignore-db, 388; 389; 392
--replicate-ignore-table, 389; 392
--replicate-rewrite-db, 390
-replicate-wild-do-table, 388; 389; 392; 393
-replicate-wild-ignore-table, 389; 390; 392
-report-host, 390
-report-port, 390
-safe-mode, 228
-safe-recover, 323; 326; 328; 332
-safe-show-database, 160; 228; 271
-safe-user-create, 228; 271
-secure-auth, 228; 250; 271
-set-auto-increment, 327
-set-character-set, 124; 153; 326; 340
-silent, 136; 322; 323; 329; 333; 334; 463;
470; 480; 486; 495; 607
-skip-bdb, 215; 228; 238; 242; 395; 516; 517
skip-concurrent-insert, 229
skip-delay-key-write, 229
-skip-external-locking, 113; 161; 227; 229;
323; 325; 328; 329; 448; 462; 463; 503;
606;607
-skip-grant-tables, 140; 229; 271; 291; 295;
604; 605
-skip-host-cache, 229; 293; 455
-skip-innodb, 161; 215; 229; 242; 395
skip-isam, 229; 242
-skip-locking, 161; 229
-skip-name-resolve, 104; 184; 229; 271; 293;
455
skip-networking, 229; 271; 455
-skip-new, 229; 240
-skip-safemalloc, 230; 452
-skip-show-database, 230; 271; 280
-skip-slave-start, 377; 390
-skip-stack-trace, 230
-skip-symbolic-links, 229; 458
-skip-thread-priority, 186; 230
slave_compressed_protocol, 390
-slave-load-tmpdir, 319; 373; 391
slave-net-timeout, 391
-slave-skip-errors, 383; 391
-socket, 104; 209; 217; 230; 352; 354; 358;
359; 470; 480; 481; 484; 487; 491; 493;
495; 496; 590; 591; 610; 611
sort_buffer_size, 161; 234; 237; 251; 254;
259; 264; 323; 324; 332; 334; 422; 423;
450; 451; 529
-sort-index, 327; 333; 334; 416; 467
-sort-records, 327; 333; 416
-sort-recover, 324; 326; 328


-sql-mode, 57; 58; 158; 162; 223; 230; 232; 238
-symbolic-links, 229
~tcp-ip, 220
-temp-pool, 161; 230
timezone, 217
"tmpdir, 230; 327; 328; 353; 493; 598; 609
-transaction-isolation, 58; 158; 230; 552
-unpack, 327; 467
-update-state, 322; 325; 331; 502; 508
-user, 106; 115-117; 119-121; 139-141; 144;
146; 171; 182; 185; 203; 217; 220; 221;
224; 231; 269; 281; 302-305; 468; 470;
480; 481; 484; 487; 491; 493; 495; 496;
601; 603
-verbose, 147; 205; 223; 323; 327; 330; 416;
449; 451; 463; 470; 478; 480; 487; 491;
495; 496
-version, 205; 220; 231; 323; 463; 470; 480;
481; 484; 487; 491; 495; 497
-wait, 323; 463; 470; 480
-with-berkleydb, 82
-with-debug, 82; 90; 124; 131; 189; 224; 230;
452; 479; 607
-with-innodb, 82; 85-89; 194; 214
-with-libwrap, 82; 194
-with-names-z-libs, 82
without-innodb, 161
-with-raid, 82

RPM, 90; 107; 108; 109; 145; 203; 213;


218; 219

autocommit, 257
backjog, 182; 235; 238; 449
basedir, 98; 134; 146; 147; 235; 238; 354;
356;357
bdb_cache_size, 235; 238; 449
bdbjiome, 235; 238
bdb_log_buffer_size, 235; 238
bdbjogdir, 235; 238
bdb_max_lock, 235; 238; 239; 517
bdb_shared_data, 235; 239
bdbjmpdir, 235; 239
bdb_version, 235; 239
bigjables, 257; 259
binlog_cache_size, 235; 239; 245; 257; 262;
350; 351; 449; 517; 529
bulk_insert_buffer_size, 161; 235; 239; 257;
425; 503
character_set, 235; 239; 240; 257
character_sets, 235; 240
concurrent_insert, 235; 240; 257


connecttimeout, 209; 235; 240; 257; 449;
470;480; 484; 597
convert_character_set, 235; 257
datadir, 97; 98; 134; 140; 146; 147; 207; 218;
222; 235; 238; 240; 355; 358; 517
default_week_format, 235; 240; 257
delay_key_write, 235; 240; 257
delayed_insert_limit, 235; 241; 257; 449
delayed_insert_timeout, 235; 241; 257; 449
delayed_queue_size, 235; 241; 257; 449
flush, 71; 140; 229; 235; 241; 257; 271; 277;
279; 289; 293-295; 304; 328; 329; 345;
347; 348; 350; 352; 425; 447; 449; 454;
455; 467; 478; 479; 510; 567; 593; 605
flushjime, 235; 241; 257; 449
ft_boolean_syntax, 235; 241; 258
ft_max_word_len, 235; 241; 323; 324
ft_min_word_len, 235; 242; 323; 324
ft_query_expansion_limit, 235; 242
ft_stopword_fiie, 235; 242; 324
have_bdb,215;235;242
have_innodb,215;235;242
have_isam,215;236;242
have_openssl, 215; 236; 242; 313
have_query_cache, 215; 236; 362; 364
have_raid,215;236;242
have_symlink, 215; 236; 457
init_file, 236; 243
innodb_additional_mem_pool_size, 236;
527; 529; 530
innodb_buffer_pool_size, 236; 527; 529; 530
innodb_data_file_path, 215; 236; 500; 525528;531;535;546; 572
innodb_data_home_dir, 236; 525-528; 531;
535; 546;572
innodb_fast_shutdown, 236; 531
mnodb_file_io_threads, 236
innodb_flush_log_at_trx_commit, 236; 527;
529;531; 561
innodb_flush_method, 236; 529; 532; 561
innodb_force_recovery, 236; 532; 549
innodbjock_wait_timeout, 236; 529; 532;
559
innodb_log_arch_dir, 236; 529; 532; 533
innodb_log_archive, 236; 532
innodb_log_buffer_size, 236; 527; 529; 532
innodb_log_file_size, 236; 527; 529; 533
innodb_log_files_in_group, 236; 529; 533
innodb_log_group_home_dir, 236; 529; 532;
533
innodb_mirrored_log_groups, 236; 533
innodb_thread_concurrency, 236; 529; 533;
567
interactive_timeout, 236; 243; 253; 258; 449;
597
join_buffer_size, 236; 243; 449

619
key_buffer_size, 72; 166; 208; 231; 234;
236; 243; 244; 255-258; 263; 323-326;
332; 416; 426; 441; 443; 445; 449-451;
453; 530
key__cache__age_threshold, 236; 244; 255;
444
key_cache_block_size, 236; 244; 255; 256;
445
key_cache_division_limit, 236; 244; 255;
444
language, 222; 236; 244
large_files_support, 236
locaUnfiie, 236; 244; 258
locked_in_memory, 236; 244
log, 47; 71; 74; 100; 120; 129; 141; 148; 155;
161; 182; 226; 227; 236; 238; 244-247;
258; 259; 293; 319; 346; 347; 351; 352;
368; 370-373; 375-377; 386-388; 398;
415; 425; 473; 493; 513; 520; 521; 527;
534-536; 548; 564-567; 589
log_bin, 236; 244; 259
log_slave_updates, 236; 244
log_slow_queries, 236; 245
log_update, 236; 245; 259
log_warnings, 236; 258
long_query_time, 45; 226; 236; 245; 258;
264; 345;351;449; 479
low_priority_updates, 236; 245; 258; 259
lower_case_table_names, 55; 236; 245; 449;
541;550
max_allowed_packet, 208; 210; 211; 236;
245; 248; 258; 449; 453; 470; 484; 491;
492;595;596;597
max_binlog_cache_size, 236; 245; 258; 351;
449; 517
max_binlog_size, 236; 246; 258; 348; 372
max_connect_errors, 236; 246; 258; 449;
593;594
max_connections, 174; 228; 236; 246; 258;
274; 307; 446; 449; 529; 530; 594; 601
max_delayed_threads, 236; 246; 258; 449
maxerrorcount, 237; 246; 258
max_heap_table_size, 237; 246; 258; 449
maxjoin_size, 237; 246; 247; 258; 259; 413;
449; 470; 477; 484
max_relay_log_size, 237; 246; 247; 258;
372;387
max_sort_length, 73; 237; 247; 258; 449
maxjmpjables, 237; 247; 258; 446; 449
max_user_connections, 237; 247; 258; 270;
307
max_write_lock_count, 237; 247; 258; 434;
449
myisam_max_extra_sort_file_size, 161; 237;
248; 258; 503
myisam_max_sort_file_size, 237; 248; 258;
503

620


myisam_recover_options, 237; 248
myisam_repair_threads, 237; 248; 258
myisam_sort_buffer_size, 237; 248; 258;
449; 503
net_buffer_length, 237; 245; 248; 258; 449;
451; 453; 470; 484; 492
net_read_timeout, 237; 248; 258; 449
net_retry_count, 237; 248; 258; 449
net_write_timeout, 237; 249; 258; 449
openjilesjimit, 237; 249; 481; 601
pid_file, 237; 249
port, 100; 126; 141; 143; 146; 149; 208; 222;
237; 249; 268; 318; 354-359; 385; 592
protocol_version, 237; 249
query_cache_limit, 237; 249; 259; 363
query_cache_size, 231; 235; 237; 249; 259;
360; 362; 562
query_cache_type, 161; 237; 249; 259; 264;
362;363; 562
read_buffer_size, 161; 237; 250; 259; 323;
449-451; 529; 530
read_md_buffer_size, 161; 237; 250; 259;
422; 423; 449; 451; 453
rpl_recovery_rank, 237; 259
serverjd, 237; 251; 259; 376; 377
skip_external_locking, 237; 251
skip_networking, 237; 251
skip_show_database, 237; 250; 251
slavejiettimeout, 237; 248; 251; 259; 383
slowjaunchjime, 237; 251; 259; 264; 449
socket, 100; 122; 126; 141; 143; 146; 149;
186; 208; 222; 237; 251; 290; 354-359;
590; 591; 610; 611
sort_buffer_size, 161; 234; 237; 251; 254;
259; 264; 323; 324; 332; 334;422; 423;
450;451;529
sql_mode, 57; 58; 158; 232; 237; 252; 379;
380; 381
table_cache, 228; 237; 252; 259; 263; 446;
447; 449; 450; 451; 601
tablejype, 237; 252; 259; 380; 499
thread_cache_size, 237; 252; 259; 265; 427
thread_stack, 176; 237; 252; 449; 453
timezone, 237; 252; 611
tmp_table_size, 237; 252; 259; 262; 449;
453; 514; 598
tmpdir, 230; 237; 239; 252; 253; 319; 327;
353; 373; 391; 423; 517; 599
tx_isolation, 237; 253; 260; 552
version, 52; 54; 103; 132; 141; 182; 195;
216; 217; 237; 253; 272; 291;335;337;
369; 463; 465; 478; 520; 536; 580; 590;
591; 595; 606; 611
waitjimeout, 184; 237; 243; 253; 260; 449;
595;597
warning_count, 260

Aborted_clients, 260; 261; 597


Abortedconnects, 260; 261
Bytes_received, 260; 262
Bytes_sent, 260; 262
Connections, 252; 260; 262; 265; 426
Created_tmp_disk_tables, 260; 262
Createdjmp_files, 260; 262
Created_tmp_tables, 260; 262
Delayed_errors, 260; 262
Delayedinsertthreads, 260; 262
Delayedwrites, 260; 262
Flushcommands, 260; 262
Handler_delete, 260; 262
Handler_read_first, 260; 262
Handler_read_key, 260; 262
Handler_read_next, 260; 263
Handler_read_prev, 260; 263
Handlerreadrnd, 260; 263
Handler_read__rnd_next, 260; 263
Handlerupdate, 260; 263
Handlerwrite, 260; 263
Key_blocks_used, 244; 260; 263
Key_read_requests, 243; 260; 263
Key_reads,243;261;263
Key_write_requests, 243; 261; 263
Key_writes,243;261;263
Max_used_connections, 261; 263
Not_flushed_delayed_rows, 261; 263
Not_flushed_key_blocks, 261; 263
Open_files,261;263
Open_streams, 261; 263
Open_tables,261;263
Openedjables, 252; 261; 263; 447
Qcachejree_blocks, 261; 263; 363; 364
Qcachejfree_memory, 261; 264; 364
Qcachejiits, 261; 264; 361; 364
Qcachejnserts, 261; 264; 364
Qcache_lowmem_prunes, 261; 264; 363; 364
Qcache_not_cached, 261; 264; 364
Qcache_queries_in_cache, 261; 264; 364
Qcachejotal_blocks, 261; 264; 363; 364
Questions, 141; 261; 264; 446; 478; 479
Select_fulljoin,261;264
Select_full_rangejoin, 261; 264
Select_range, 261; 264
Select_range_check, 261; 264
Select_scan, 261; 264
Slave_open_temp_tables, 261; 264
Slave_running, 261; 264
Slowjaunchjhreads, 261; 264
Slow_queries, 245; 261; 264
Sort_merge_passes, 261; 264
Sort_range, 261; 264
Sort_rows,261;265
Sort_scan, 261
Table_locks_immediate, 261; 265; 431

621


Table_locks_waited, 261; 265; 431
Threads_cached, 261; 265
Threads_connected, 261; 265
Threads_created, 252; 261; 265
Threads_running, 261; 265
Uptime, 141; 261; 265; 446; 478
, 39; 61; 66; 410
, 23
MIT-pthreads, 47; 73; 127; 131; 132; 149;
179; 183; 184; 190; 271; 292; 448; 452; 591
, 37; 43; 66

CREATE TEMPORARY TABLES, 160


EXECUTE, 160; 278
FILE, 160
LOCK TABLES, 160
REPLICATION CLIENT, 160; 278; 280
REPLICATION SLAVE, 160; 278; 280; 374;
387
SHOW DATABASES, 160; 177; 228; 230;
250; 251; 271; 278; 280
SUPER, 160; 234; 250; 253; 255; 270; 278280; 350; 373; 374; 387; 533; 552; 594

mysql, 15-18; 21; 25; 26; 28-34; 36; 37; 39;


41-46; 48; 50; 51; 53-56; 58; 60; 61; 64;
67; 68; 71; 72; 74; 80; 81; 83-123; 125127; 131-146; 148-155; 157-160; 163;
165-169; 171-173; 175; 177; 178; 179189; 191-203; 205-211; 213-215; 217219; 221-223; 228; 230; 232; 234-237;
243; 253; 254; 256; 257; 260; 266-273;
277-283; 286; 290-300; 302-310; 312;
313; 317; 320; 332; 340; 341; 345-347;
350-352; 354-358; 360-364; 368; 374;
375; 377; 379; 381; 386; 393; 395; 400;
401; 404; 406; 407; 414; 415; 420; 431;
432; 439; 442-445; 447; 449; 450; 459461; 467-469; 471-477; 482; 483; 487;
492; 495; 509; 510; 513; 521; 524; 527;
528; 534-537; 541; 542; 547; 563; 564;
577; 579; 584; 589; 59(-594; 596; 597;
599; 601-607; 610-612
mysqladmin, 16; 46; 52-54; 74; 96; 101-103;
105-107; 110; 112; 113; 132; 139-141;
145; 148; 151; 152; 167; 169; 186; 190;
193; 202; 203; 206; 220; 222; 229; 270;
271; 277; 279; 287; 289; 291-293; 295;
304; 308-310; 328; 329; 331; 345; 347;
348; 350; 352; 355; 358; 371; 375; 382;
425; 446; 447; 450; 454; 455; 460; 467;
477-479; 510; 534; 589-593; 595; 603;
605-609; 611

mysqlc, 104
mysqlcc, 127; 202; 206; 460; 483
mysqlcheck, 22; 202; 206; 321; 460; 485
mysqld, 38; 43; 46; 47; 53; 54; 55;^57; 71; 74;
82; 85; 86; 89; 93; 94; 96; 98-104; 06;
109-111; 113-123; 129-132; 134; 135;
140; 141; 143-149; 153-155; 158; 160167; 170-178; 180-186; 190-193; 195;
197; 202; 206-208; 212- 232; 234; 238240; 242-244; 246; 249; 251-253; 256;
262; 269-272; 277; 289; 291-293; 295;
312; 316; 319; 322-325; 328; 329; 331;
334; 341; 345-352; 354-360; 362; 376;
385; 390; 424; 434; 446; 447; 449-455;
458; 459; 462; 463; 467; 479; 483; 485;
491; 502; 503; 507; 508; 516; 517; 519;
520; 524-528; 530; 534; 535; 537; 544;
545; 547-550; 552; 562; 563; 572; 579;
589-601; 603-611; 613
--ansi, 57; 223; 238
-sql-mode, 57; 58; 158; 162; 223; 230; 232;
238
mysqldhow, 107
mysqld-max, 82; 96; 98; 99; 212; 213; 216;
217; 225; 354; 355; 459; 527
mysqld-max-nt, 98; 99; 225; 355; 459
mysqld-nt, 98; 99; 106; 225; 355-357; 604
mysqld-opt, 98; 99
mysqldump, 53; 54; 65; 66; 107; 153; 155157; 160; 164; 168; 169; 202; 203; 206;
208; 232; 295; 319; 376; 377; 393; 458;
461; 487; 488; 490-492; 520; 542; 546;
547; 551; 562; 573; 584
mysqlhotcopy, 202; 206; 209; 319; 461; 487;
492; 493
mysqlimport, 169; 202; 206; 272; 461; 493495;584
mysqlshow, 103; 137; 141; 202; 203; 206;
461; 495; 496; 599
WinMySQLAdmin, 96; 98; 167

-, 43; 242; 249

ANSI, 18; 47; 56-58; 61; 87; 118; 188; 232;


233; 420; 490
ANSI_QUOTES, 58; 232; 233; 490
DB2, 233; 404; 406; 582
IGNORE_SPACE, 58; 232; 233; 468
MAXDB, 233
MSSQL, 233
MYSQL323, 233
MYSQL40, 233

622
NO_AUTO_VALUE_ON_ZERO, 232
NO_DIR_IN_CREATE, 233; 381
NO_FIELD_OPTIONS, 233
NO_KEY_OPTIONS, 233
NO_TABLE_OPTIONS, 233
NO_UNSIGNED_SUBTRACTION, 233
ONLY_FULL_GROUP_BY, 58; 233
ORACLE, 233
PIPES_AS_CONCAT, 58; 233
POSTGRESQL, 233
REAL_AS_FLOAT, 58; 233
, 23; 40; 71; 365; 366; 380; 395;
396; 543;584
--log-slave-updates, 382; 386; 398; 401
--log-warnings, 227; 377; 386; 597
master-connect-retry, 367; 370; 383; 384;
386;391
-master-host, 384; 386
master-info-file, 386
-master-password, 384; 386
-master-port, 384; 386
-master-ssl, 384; 386; 387
master-ssl-ca, 384; 386
-master-ssl-capath, 384; 386
master-ssl-cert, 384; 386

-master-ssl-cipher, 384; 386


-master-ssl-key, 384; 387
-master-user, 384; 387
max-relay-log-size, 387; 388
-read-only, 325; 387
-relay-log, 371; 387; 391
-relay-log-index, 387

relay-log-info-file, 387
-relay-log-purge, 387
-relay-log-space-limit, 387
-replicate-do-db, 388; 392
~replicate-do-table, 388; 392; 393
-replicate-ignore-db, 388; 389; 392
-replicate-ignore-table, 389; 392
replicate-rewrite-db, 390
-replicate-wild-do-table, 388; 389; 392; 393
-replicate-wild-ignore-table, 389; 390; 392
-report-host, 390
-report-port, 390
-skip-slave-start, 377; 390
slave_compressed_protocol, 390
-slave-load-tmpdir, 319; 373; 391
slave-net-timeout, 391
-slave-skip-errors, 383; 391
BitKeeper, 39; 41; 42; 79; 80; 82;
83; 124; 125; 127; 133; 135; 136

, 46; 47; 78; 104; 172; 370; 371; 455;


516; 533; 567
, 18
, 39; 223

, 78; 170
, 18
MySQL, 48
anounce, 48
benchmarks, 49; 175; 404; 406
benchmarks-digest, 49
bugs, 48; 50; 51; 53; 54; 84; 126; 213; 401
bugs-digest, 48
gui-tools, 49
gui-tools-digest, 49
internals, 48; 90; 127; 172; 343
internals-digest, 48
Java, 49
java-digest, 49
msql-mysql-modules, 50
msql-mysql-modules-digest, 50
myodbc, 49
myodbc-digest, 49
mysql, 48
mysql-digest, 48
mysqldoc, 49; 127
mysqldoc-digest, 49
packagers, 49
packagers-digest, 49
plusplus, 49; 50
plusplus-digest, 50
Win32, 49; 133
win32-digest, 49

SQL
1999, 18;56
2003, 18; 42; 56
SQL-92, 18; 56
, .
, 18; 19; 28; 29; 31; 33; 35; 36; 39;
47; 49; 56; 60; 62; 63; 67; 68; 79; 81; 150;
231; 403; 404; 407

bin/mysqlbug, 85
Build-tools/Do-compile, 85
configure, 46; 54; 85-90; 118; 119; 121-124;
126-131; 161; 164; 173; 176-196; 312;
340; 342; 343; 358; 360; 386; 452; 516;
528; 600; 607; 611; 612

623


mysql.server, 116; 120; 144-146; 173; 181;
202; 206; 213; 218; 219; 223; 270; 346;
611
mysql_fix_privilege_tables, 154; 158; 159;
165; 168; 213; 290; 297; 298
mysql_install_db, 94; ; 115; 116; 118; 120;
138; 139; 140; 142-144; 149; 171; 184;
191; 202; 213; 290; 304; 358; 577
mysql_multi, 202; 213; 219; 220-222; 359
mysqlaccess, 54; 117; 277; 289; 295; 460
mysqld_safe, 47; 74; 110; 111; 114; 115; 117;
119; 121; 140; 141; 144-147; 153; 160;
161; 174-176; 184; 185; 190; 191; 195;
202; 206; 213; 215-218; 220-224; 228;
252; 270; 334; 346; 354; 358; 359; 450;
451; 534; 579; 593; 596; 601; 604; 605;
610; 611
scripts/make_binary_distribution, 85; 95

BIT, 43; 61
DATE, 20; 25; 45; 46; 69; 157; 165; 166; 361;
585;587
DATETIME, 20; 25; 44; 46; 69; 157; 158; 166
SET, 20; 44; 46; 57-60; 64; 67; 69; 73-75;
124; 150-152; 155; 156; 158; 161; 196;
210; 227; 231; 232; 234; 235; 242; 243;
253; 254; 256; 257; 269; 270; 276; 289;
291; 292; 296; 298-300; 304; 305; 309;
332; 349; 350; 363; 387-389; 400; 424;
428; 432; 434; 443; 445; 476; 477; 518;
528; 533;536;537; 539-543; 551; 552;
555; 556; 559; 561; 562; 592; 593; 599;
606
TIMESTAMP, 20; 25; 26; 44; 46; 157; 166;
228; 361; 380; 384; 394; 587; 611
TINYINT,43;466;507;585
, 37; 65

, 551; 552
READ COMMITTED, 230; 237; 552
READ UNCOMMITTED, 230; 552
REPEATABLE READ, 230; 552
SERIALIZABLE, 58; 158; 230; 552; 553; 557

gunzip, 114-119; 169; 198


myisamchk, 22; 24; 55; 113; 124; 153; 157;
163; 165; 203; 206; 213; 229; 319-340;
345; 411; 416; 425; 426; 430; 448; 458;
463; 465; 467; 485; 493; 500-502; SOSSOS; 522;598; 607
myisampack, 24; 45; 203; 206; 327; 339; 425;
460-464; 466; 467; 500; 504; 506; 509;
510; 522
mysqlaccess, 54; 117; 277; 289; 295; 460
mysqlbinlog, 72; 106; 203; 206; 320; 350;
371; 401; 460;480-483;547
mysqlhotcopy, 202; 206; 209; 319; 461; 487;
492; 493
perror, 203; 330; 461; 497; 575; 599-601
replace, 67; 193; 313; 316; 396; 461; 494; 495;
497
tar, 54; 81; 85; 91; 92; 94; 109; 110; 114-119;
131; 136; 171; 178; 179; 194; 195; 198;
354; 374; 375; 393

my.cnf, 97; 98; 106; 113; 118; 120; 134; 145147; 154; 167; 174; 206; 207; 209; 218220; 222; 231; 269; 311; 316; 317; 356;
359; 360; 376; 378; 385; 451; 459; 474;
524-528; 534; 535; 537; 544; 546; 547;
550; 552; 561; 603; 610
my.ini, 97; 98; 134; 206; 459; 524; 525; 527;
528; 535; 537

ext2, 24; 448
ReiserFS, 24; 78; 448

ADD_TO_SET, 44
ANY(), 45
EVERY(), 45
REMOVE_FROM_SET, 44
SOME(), 45
X
, 37; 42; 65; 429

-
MySQL AB

MySQL.
..
.

"".
101509, , . , . 43, . 1.
31.03.2005. 70X100/16.
Times. .
. . . 50,31. .-. . 39,64.
3000 . 1384.

" "
,
.
197110, -, ., 15.