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
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
17543
17544
17545
17546
17547
17548
17549
17550
17551
17552
17553
17554
17555
17556
17557
17558
17559
17560
17561
17562
17563
17564
17565
17566
17567
17568
17569
17570
17571
17572
17573
17574
17575
17576
17577
17578
17579
17580
17581
17582
17583
17584
17585
17586
17587
17588
17589
17590
17591
17592
17593
17594
17595
17596
17597
17598
17599
17600
17601
17602
17603
17604
17605
17606
17607
17608
17609
17610
17611
17612
17613
17614
17615
17616
17617
17618
17619
17620
17621
17622
17623
17624
17625
17626
17627
17628
17629
17630
17631
17632
17633
17634
17635
17636
17637
17638
17639
17640
17641
17642
17643
17644
17645
17646
17647
17648
17649
17650
17651
17652
17653
17654
17655
17656
17657
17658
17659
17660
17661
17662
17663
17664
17665
17666
17667
17668
17669
17670
17671
17672
17673
17674
17675
17676
17677
17678
17679
17680
17681
17682
17683
17684
17685
17686
17687
17688
17689
17690
17691
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
17702
17703
17704
17705
17706
17707
17708
17709
17710
17711
17712
17713
17714
17715
17716
17717
17718
17719
17720
17721
17722
17723
17724
17725
17726
17727
17728
17729
17730
17731
17732
17733
17734
17735
17736
17737
17738
17739
17740
17741
17742
17743
17744
17745
17746
17747
17748
17749
17750
17751
17752
17753
17754
17755
17756
17757
17758
17759
17760
17761
17762
17763
17764
17765
17766
17767
17768
17769
17770
17771
17772
17773
17774
17775
17776
17777
17778
17779
17780
17781
17782
17783
17784
17785
17786
17787
17788
17789
17790
17791
17792
17793
17794
17795
17796
17797
17798
17799
17800
17801
17802
17803
17804
17805
17806
17807
17808
17809
17810
17811
17812
17813
17814
17815
17816
17817
17818
17819
17820
17821
17822
17823
17824
17825
17826
17827
17828
17829
17830
17831
17832
17833
17834
17835
17836
17837
17838
17839
17840
17841
17842
17843
17844
17845
17846
17847
17848
17849
17850
17851
17852
17853
17854
17855
17856
17857
17858
17859
17860
17861
17862
17863
17864
17865
17866
17867
17868
17869
17870
17871
17872
17873
17874
17875
17876
17877
17878
17879
17880
17881
17882
17883
17884
17885
17886
17887
17888
17889
17890
17891
17892
17893
17894
17895
17896
17897
17898
17899
17900
17901
17902
17903
17904
17905
17906
17907
17908
17909
17910
17911
17912
17913
17914
17915
17916
17917
17918
17919
17920
17921
17922
17923
17924
17925
17926
17927
17928
17929
17930
17931
17932
17933
17934
17935
17936
17937
17938
17939
17940
17941
17942
17943
17944
17945
17946
17947
17948
17949
17950
17951
17952
17953
17954
17955
17956
17957
17958
17959
17960
17961
17962
17963
17964
17965
17966
17967
17968
17969
17970
17971
17972
17973
17974
17975
17976
17977
17978
17979
17980
17981
17982
17983
17984
17985
17986
17987
17988
17989
17990
17991
17992
17993
17994
17995
17996
17997
17998
17999
18000
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
18111
18112
18113
18114
18115
18116
18117
18118
18119
18120
18121
18122
18123
18124
18125
18126
18127
18128
18129
18130
18131
18132
18133
18134
18135
18136
18137
18138
18139
18140
18141
18142
18143
18144
18145
18146
18147
18148
18149
18150
18151
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
18189
18190
18191
18192
18193
18194
18195
18196
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233
18234
18235
18236
18237
18238
18239
18240
18241
18242
18243
18244
18245
18246
18247
18248
18249
18250
18251
18252
18253
18254
18255
18256
18257
18258
18259
18260
18261
18262
18263
18264
18265
18266
18267
18268
18269
18270
18271
18272
18273
18274
18275
18276
18277
18278
18279
18280
18281
18282
18283
18284
18285
18286
18287
18288
18289
18290
18291
18292
18293
18294
18295
18296
18297
18298
18299
18300
18301
18302
18303
18304
18305
18306
18307
18308
18309
18310
18311
18312
18313
18314
18315
18316
18317
18318
18319
18320
18321
18322
18323
18324
18325
18326
18327
18328
18329
18330
18331
18332
18333
18334
18335
18336
18337
18338
18339
18340
18341
18342
18343
18344
18345
18346
18347
18348
18349
18350
18351
18352
18353
18354
18355
18356
18357
18358
18359
18360
18361
18362
18363
18364
18365
18366
18367
18368
18369
18370
18371
18372
18373
18374
18375
18376
18377
18378
18379
18380
18381
18382
18383
18384
18385
18386
18387
18388
18389
18390
18391
18392
18393
18394
18395
18396
18397
18398
18399
18400
18401
18402
18403
18404
18405
18406
18407
18408
18409
18410
18411
18412
18413
18414
18415
18416
18417
18418
18419
18420
18421
18422
18423
18424
18425
18426
18427
18428
18429
18430
18431
18432
18433
18434
18435
18436
18437
18438
18439
18440
18441
18442
18443
18444
18445
18446
18447
18448
18449
18450
18451
18452
18453
18454
18455
18456
18457
18458
18459
18460
18461
18462
18463
18464
18465
18466
18467
18468
18469
18470
18471
18472
18473
18474
18475
18476
18477
18478
18479
18480
18481
18482
18483
18484
18485
18486
18487
18488
18489
18490
18491
18492
18493
18494
18495
18496
18497
18498
18499
18500
18501
18502
18503
18504
18505
18506
18507
18508
18509
18510
18511
18512
18513
18514
18515
18516
18517
18518
18519
18520
18521
18522
18523
18524
18525
18526
18527
18528
18529
18530
18531
18532
18533
18534
18535
18536
18537
18538
18539
18540
18541
18542
18543
18544
18545
18546
18547
18548
18549
18550
18551
18552
18553
18554
18555
18556
18557
18558
18559
18560
18561
18562
18563
18564
18565
18566
18567
18568
18569
18570
18571
18572
18573
18574
18575
18576
18577
18578
18579
18580
18581
18582
18583
18584
18585
18586
18587
18588
18589
18590
18591
18592
18593
18594
18595
18596
18597
18598
18599
18600
18601
18602
18603
18604
18605
18606
18607
18608
18609
18610
18611
18612
18613
18614
18615
18616
18617
18618
18619
18620
18621
18622
18623
18624
18625
18626
18627
18628
18629
18630
18631
18632
18633
18634
18635
18636
18637
18638
18639
18640
18641
18642
18643
18644
18645
18646
18647
18648
18649
18650
18651
18652
18653
18654
18655
18656
18657
18658
18659
18660
18661
18662
18663
18664
18665
18666
18667
18668
18669
18670
18671
18672
18673
18674
18675
18676
18677
18678
18679
18680
18681
18682
18683
18684
18685
18686
18687
18688
18689
18690
18691
18692
18693
18694
18695
18696
18697
18698
18699
18700
18701
18702
18703
18704
18705
18706
18707
18708
18709
18710
18711
18712
18713
18714
18715
18716
18717
18718
18719
18720
18721
18722
18723
18724
18725
18726
18727
18728
18729
18730
18731
18732
18733
18734
18735
18736
18737
18738
18739
18740
18741
18742
18743
18744
18745
18746
18747
18748
18749
18750
18751
18752
18753
18754
18755
18756
18757
18758
18759
18760
18761
18762
18763
18764
18765
18766
18767
18768
18769
18770
18771
18772
18773
18774
18775
18776
18777
18778
18779
18780
18781
18782
18783
18784
18785
18786
18787
18788
18789
18790
18791
18792
18793
18794
18795
18796
18797
18798
18799
18800
18801
18802
18803
18804
18805
18806
18807
18808
18809
18810
18811
18812
18813
18814
18815
18816
18817
18818
18819
18820
18821
18822
18823
18824
18825
18826
18827
18828
18829
18830
18831
18832
18833
18834
18835
18836
18837
18838
18839
18840
18841
18842
18843
18844
18845
18846
18847
18848
18849
18850
18851
18852
18853
18854
18855
18856
18857
18858
18859
18860
18861
18862
18863
18864
18865
18866
18867
18868
18869
18870
18871
18872
18873
18874
18875
18876
18877
18878
18879
18880
18881
18882
18883
18884
18885
18886
18887
18888
18889
18890
18891
18892
18893
18894
18895
18896
18897
18898
18899
18900
18901
18902
18903
18904
18905
18906
18907
18908
18909
18910
18911
18912
18913
18914
18915
18916
18917
18918
18919
18920
18921
18922
18923
18924
18925
18926
18927
18928
18929
18930
18931
18932
18933
18934
18935
18936
18937
18938
18939
18940
18941
18942
18943
18944
18945
18946
18947
18948
18949
18950
18951
18952
18953
18954
18955
18956
18957
18958
18959
18960
18961
18962
18963
18964
18965
18966
18967
18968
18969
18970
18971
18972
18973
18974
18975
18976
18977
18978
18979
18980
18981
18982
18983
18984
18985
18986
18987
18988
18989
18990
18991
18992
18993
18994
18995
18996
18997
18998
18999
19000
19001
19002
19003
19004
19005
19006
19007
19008
19009
19010
19011
19012
19013
19014
19015
19016
19017
19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
19029
19030
19031
19032
19033
19034
19035
19036
19037
19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
19049
19050
19051
19052
19053
19054
19055
19056
19057
19058
19059
19060
19061
19062
19063
19064
19065
19066
19067
19068
19069
19070
19071
19072
19073
19074
19075
19076
19077
19078
19079
19080
19081
19082
19083
19084
19085
19086
19087
19088
19089
19090
19091
19092
19093
19094
19095
19096
19097
19098
19099
19100
19101
19102
19103
19104
19105
19106
19107
19108
19109
19110
19111
19112
19113
19114
19115
19116
19117
19118
19119
19120
19121
19122
19123
19124
19125
19126
19127
19128
19129
19130
19131
19132
19133
19134
19135
19136
19137
19138
19139
19140
19141
19142
19143
19144
19145
19146
19147
19148
19149
19150
19151
19152
19153
19154
19155
19156
19157
19158
19159
19160
19161
19162
19163
19164
19165
19166
19167
19168
19169
19170
19171
19172
19173
19174
19175
19176
19177
19178
19179
19180
19181
19182
19183
19184
19185
19186
19187
19188
19189
19190
19191
19192
19193
19194
19195
19196
19197
19198
19199
19200
19201
19202
19203
19204
19205
19206
19207
19208
19209
19210
19211
19212
19213
19214
19215
19216
19217
19218
19219
19220
19221
19222
19223
19224
19225
19226
19227
19228
19229
19230
19231
19232
19233
19234
19235
19236
19237
19238
19239
19240
19241
19242
19243
19244
19245
19246
19247
19248
19249
19250
19251
19252
19253
19254
19255
19256
19257
19258
19259
19260
19261
19262
19263
19264
19265
19266
19267
19268
19269
19270
19271
19272
19273
19274
19275
19276
19277
19278
19279
19280
19281
19282
19283
19284
19285
19286
19287
19288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
19301
19302
19303
19304
19305
19306
19307
19308
19309
19310
19311
19312
19313
19314
19315
19316
19317
19318
19319
19320
19321
19322
19323
19324
19325
19326
19327
19328
19329
19330
19331
19332
19333
19334
19335
19336
19337
19338
19339
19340
19341
19342
19343
19344
19345
19346
19347
19348
19349
19350
19351
19352
19353
19354
19355
19356
19357
19358
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383
19384
19385
19386
19387
19388
19389
19390
19391
19392
19393
19394
19395
19396
19397
19398
19399
19400
19401
19402
19403
19404
19405
19406
19407
19408
19409
19410
19411
19412
19413
19414
19415
19416
19417
19418
19419
19420
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433
19434
19435
19436
19437
19438
19439
19440
19441
19442
19443
19444
19445
19446
19447
19448
19449
19450
19451
19452
19453
19454
19455
19456
19457
19458
19459
19460
19461
19462
19463
19464
19465
19466
19467
19468
19469
19470
19471
19472
19473
19474
19475
19476
19477
19478
19479
19480
19481
19482
19483
19484
19485
19486
19487
19488
19489
19490
19491
19492
19493
19494
19495
19496
19497
19498
19499
19500
19501
19502
19503
19504
19505
19506
19507
19508
19509
19510
19511
19512
19513
19514
19515
19516
19517
19518
19519
19520
19521
19522
19523
19524
19525
19526
19527
19528
19529
19530
19531
19532
19533
19534
19535
19536
19537
19538
19539
19540
19541
19542
19543
19544
19545
19546
19547
19548
19549
19550
19551
19552
19553
19554
19555
19556
19557
19558
19559
19560
19561
19562
19563
19564
19565
19566
19567
19568
19569
19570
19571
19572
19573
19574
19575
19576
19577
19578
19579
19580
19581
19582
19583
19584
19585
19586
19587
19588
19589
19590
19591
19592
19593
19594
19595
19596
19597
19598
19599
19600
19601
19602
19603
19604
19605
19606
19607
19608
19609
19610
19611
19612
19613
19614
19615
19616
19617
19618
19619
19620
19621
19622
19623
19624
19625
19626
19627
19628
19629
19630
19631
19632
19633
19634
19635
19636
19637
19638
19639
19640
19641
19642
19643
19644
19645
19646
19647
19648
19649
19650
19651
19652
19653
19654
19655
19656
19657
19658
19659
19660
19661
19662
19663
19664
19665
19666
19667
19668
19669
19670
19671
19672
19673
19674
19675
19676
19677
19678
19679
19680
19681
19682
19683
19684
19685
19686
19687
19688
19689
19690
19691
19692
19693
19694
19695
19696
19697
19698
19699
19700
19701
19702
19703
19704
19705
19706
19707
19708
19709
19710
19711
19712
19713
19714
19715
19716
19717
19718
19719
19720
19721
19722
19723
19724
19725
19726
19727
19728
19729
19730
19731
19732
19733
19734
19735
19736
19737
19738
19739
19740
19741
19742
19743
19744
19745
19746
19747
19748
19749
19750
19751
19752
19753
19754
19755
19756
19757
19758
19759
19760
19761
19762
19763
19764
19765
19766
19767
19768
19769
19770
19771
19772
19773
19774
19775
19776
19777
19778
19779
19780
19781
19782
19783
19784
19785
19786
19787
19788
19789
19790
19791
19792
19793
19794
19795
19796
19797
19798
19799
19800
19801
19802
19803
19804
19805
19806
19807
19808
19809
19810
19811
19812
19813
19814
19815
19816
19817
19818
19819
19820
19821
19822
19823
19824
19825
19826
19827
19828
19829
19830
19831
19832
19833
19834
19835
19836
19837
19838
19839
19840
19841
19842
19843
19844
19845
19846
19847
19848
19849
19850
19851
19852
19853
19854
19855
19856
19857
19858
19859
19860
19861
19862
19863
19864
19865
19866
19867
19868
19869
19870
19871
19872
19873
19874
19875
19876
19877
19878
19879
19880
19881
19882
19883
19884
19885
19886
19887
19888
19889
19890
19891
19892
19893
19894
19895
19896
19897
19898
19899
19900
19901
19902
19903
19904
19905
19906
19907
19908
19909
19910
19911
19912
19913
19914
19915
19916
19917
19918
19919
19920
19921
19922
19923
19924
19925
19926
19927
19928
19929
19930
19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
19942
19943
19944
19945
19946
19947
19948
19949
19950
19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
19962
19963
19964
19965
19966
19967
19968
19969
19970
19971
19972
19973
19974
19975
19976
19977
19978
19979
19980
19981
19982
19983
19984
19985
19986
19987
19988
19989
19990
19991
19992
19993
19994
19995
19996
19997
19998
19999
20000
20001
20002
20003
20004
20005
20006
20007
20008
20009
20010
20011
20012
20013
20014
20015
20016
20017
20018
20019
20020
20021
20022
20023
20024
20025
20026
20027
20028
20029
20030
20031
20032
20033
20034
20035
20036
20037
20038
20039
20040
20041
20042
20043
20044
20045
20046
20047
20048
20049
20050
20051
20052
20053
20054
20055
20056
20057
20058
20059
20060
20061
20062
20063
20064
20065
20066
20067
20068
20069
20070
20071
20072
20073
20074
20075
20076
20077
20078
20079
20080
20081
20082
20083
20084
20085
20086
20087
20088
20089
20090
20091
20092
20093
20094
20095
20096
20097
20098
20099
20100
20101
20102
20103
20104
20105
20106
20107
20108
20109
20110
20111
20112
20113
20114
20115
20116
20117
20118
20119
20120
20121
20122
20123
20124
20125
20126
20127
20128
20129
20130
20131
20132
20133
20134
20135
20136
20137
20138
20139
20140
20141
20142
20143
20144
20145
20146
20147
20148
20149
20150
20151
20152
20153
20154
20155
20156
20157
20158
20159
20160
20161
20162
20163
20164
20165
20166
20167
20168
20169
20170
20171
20172
20173
20174
20175
20176
20177
20178
20179
20180
20181
20182
20183
20184
20185
20186
20187
20188
20189
20190
20191
20192
20193
20194
20195
20196
20197
20198
20199
20200
20201
20202
20203
20204
20205
20206
20207
20208
20209
20210
20211
20212
20213
20214
20215
20216
20217
20218
20219
20220
20221
20222
20223
20224
20225
20226
20227
20228
20229
20230
20231
20232
20233
20234
20235
20236
20237
20238
20239
20240
20241
20242
20243
20244
20245
20246
20247
20248
20249
20250
20251
20252
20253
20254
20255
20256
20257
20258
20259
20260
20261
20262
20263
20264
20265
20266
20267
20268
20269
20270
20271
20272
20273
20274
20275
20276
20277
20278
20279
20280
20281
20282
20283
20284
20285
20286
20287
20288
20289
20290
20291
20292
20293
20294
20295
20296
20297
20298
20299
20300
20301
20302
20303
20304
20305
20306
20307
20308
20309
20310
20311
20312
20313
20314
20315
20316
20317
20318
20319
20320
20321
20322
20323
20324
20325
20326
20327
20328
20329
20330
20331
20332
20333
20334
20335
20336
20337
20338
20339
20340
20341
20342
20343
20344
20345
20346
20347
20348
20349
20350
20351
20352
20353
20354
20355
20356
20357
20358
20359
20360
20361
20362
20363
20364
20365
20366
20367
20368
20369
20370
20371
20372
20373
20374
20375
20376
20377
20378
20379
20380
20381
20382
20383
20384
20385
20386
20387
20388
20389
20390
20391
20392
20393
20394
20395
20396
20397
20398
20399
20400
20401
20402
20403
20404
20405
20406
20407
20408
20409
20410
20411
20412
20413
20414
20415
20416
20417
20418
20419
20420
20421
20422
20423
20424
20425
20426
20427
20428
20429
20430
20431
20432
20433
20434
20435
20436
20437
20438
20439
20440
20441
20442
20443
20444
20445
20446
20447
20448
20449
20450
20451
20452
20453
20454
20455
20456
20457
20458
20459
20460
20461
20462
20463
20464
20465
20466
20467
20468
20469
20470
20471
20472
20473
20474
20475
20476
20477
20478
20479
20480
20481
20482
20483
20484
20485
20486
20487
20488
20489
20490
20491
20492
20493
20494
20495
20496
20497
20498
20499
20500
20501
20502
20503
20504
20505
20506
20507
20508
20509
20510
20511
20512
20513
20514
20515
20516
20517
20518
20519
20520
20521
20522
20523
20524
20525
20526
20527
20528
20529
20530
20531
20532
20533
20534
20535
20536
20537
20538
20539
20540
20541
20542
20543
20544
20545
20546
20547
20548
20549
20550
20551
20552
20553
20554
20555
20556
20557
20558
20559
20560
20561
20562
20563
20564
20565
20566
20567
20568
20569
20570
20571
20572
20573
20574
20575
20576
20577
20578
20579
20580
20581
20582
20583
20584
20585
20586
20587
20588
20589
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614
20615
20616
20617
20618
20619
20620
20621
20622
20623
20624
20625
20626
20627
20628
20629
20630
20631
20632
20633
20634
20635
20636
20637
20638
20639
20640
20641
20642
20643
20644
20645
20646
20647
20648
20649
20650
20651
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664
20665
20666
20667
20668
20669
20670
20671
20672
20673
20674
20675
20676
20677
20678
20679
20680
20681
20682
20683
20684
20685
20686
20687
20688
20689
20690
20691
20692
20693
20694
20695
20696
20697
20698
20699
20700
20701
20702
20703
20704
20705
20706
20707
20708
20709
20710
20711
20712
20713
20714
20715
20716
20717
20718
20719
20720
20721
20722
20723
20724
20725
20726
20727
20728
20729
20730
20731
20732
20733
20734
20735
20736
20737
20738
20739
20740
20741
20742
20743
20744
20745
20746
20747
20748
20749
20750
20751
20752
20753
20754
20755
20756
20757
20758
20759
20760
20761
20762
20763
20764
20765
20766
20767
20768
20769
20770
20771
20772
20773
20774
20775
20776
20777
20778
20779
20780
20781
20782
20783
20784
20785
20786
20787
20788
20789
20790
20791
20792
20793
20794
20795
20796
20797
20798
20799
20800
20801
20802
20803
20804
20805
20806
20807
20808
20809
20810
20811
20812
20813
20814
20815
20816
20817
20818
20819
20820
20821
20822
20823
20824
20825
20826
20827
20828
20829
20830
20831
20832
20833
20834
20835
20836
20837
20838
20839
20840
20841
20842
20843
20844
20845
20846
20847
20848
20849
20850
20851
20852
20853
20854
20855
20856
20857
20858
20859
20860
20861
20862
20863
20864
20865
20866
20867
20868
20869
20870
20871
20872
20873
20874
20875
20876
20877
20878
20879
20880
20881
20882
20883
20884
20885
20886
20887
20888
20889
20890
20891
20892
20893
20894
20895
20896
20897
20898
20899
20900
20901
20902
20903
20904
20905
20906
20907
20908
20909
20910
20911
20912
20913
20914
20915
20916
20917
20918
20919
20920
20921
20922
20923
20924
20925
20926
20927
20928
20929
20930
20931
20932
20933
20934
20935
20936
20937
20938
20939
20940
20941
20942
20943
20944
20945
20946
20947
20948
20949
20950
20951
20952
20953
20954
20955
20956
20957
20958
20959
20960
20961
20962
20963
20964
20965
20966
20967
20968
20969
20970
20971
20972
20973
20974
20975
20976
20977
20978
20979
20980
20981
20982
20983
20984
20985
20986
20987
20988
20989
20990
20991
20992
20993
20994
20995
20996
20997
20998
20999
21000
21001
21002
21003
21004
21005
21006
21007
21008
21009
21010
21011
21012
21013
21014
21015
21016
21017
21018
21019
21020
21021
21022
21023
21024
21025
21026
21027
21028
21029
21030
21031
21032
21033
21034
21035
21036
21037
21038
21039
21040
21041
21042
21043
21044
21045
21046
21047
21048
21049
21050
21051
21052
21053
21054
21055
21056
21057
21058
21059
21060
21061
21062
21063
21064
21065
21066
21067
21068
21069
21070
21071
21072
21073
21074
21075
21076
21077
21078
21079
21080
21081
21082
21083
21084
21085
21086
21087
21088
21089
21090
21091
21092
21093
21094
21095
21096
21097
21098
21099
21100
21101
21102
21103
21104
21105
21106
21107
21108
21109
21110
21111
21112
21113
21114
21115
21116
21117
21118
21119
21120
21121
21122
21123
21124
21125
21126
21127
21128
21129
21130
21131
21132
21133
21134
21135
21136
21137
21138
21139
21140
21141
21142
21143
21144
21145
21146
21147
21148
21149
21150
21151
21152
21153
21154
21155
21156
21157
21158
21159
21160
21161
21162
21163
21164
21165
21166
21167
21168
21169
21170
21171
21172
21173
21174
21175
21176
21177
21178
21179
21180
21181
21182
21183
21184
21185
21186
21187
21188
21189
21190
21191
21192
21193
21194
21195
21196
21197
21198
21199
21200
21201
21202
21203
21204
21205
21206
21207
21208
21209
21210
21211
21212
21213
21214
21215
21216
21217
21218
21219
21220
21221
21222
21223
21224
21225
21226
21227
21228
21229
21230
21231
21232
21233
21234
21235
21236
21237
21238
21239
21240
21241
21242
21243
21244
21245
21246
21247
21248
21249
21250
21251
21252
21253
21254
21255
21256
21257
21258
21259
21260
21261
21262
21263
21264
21265
21266
21267
21268
21269
21270
21271
21272
21273
21274
21275
21276
21277
21278
21279
21280
21281
21282
21283
21284
21285
21286
21287
21288
21289
21290
21291
21292
21293
21294
21295
21296
21297
21298
21299
21300
21301
21302
21303
21304
21305
21306
21307
21308
21309
21310
21311
21312
21313
21314
21315
21316
21317
21318
21319
21320
21321
21322
21323
21324
21325
21326
21327
21328
21329
21330
21331
21332
21333
21334
21335
21336
21337
21338
21339
21340
21341
21342
21343
21344
21345
21346
21347
21348
21349
21350
21351
21352
21353
21354
21355
21356
21357
21358
21359
21360
21361
21362
21363
21364
21365
21366
21367
21368
21369
21370
21371
21372
21373
21374
21375
21376
21377
21378
21379
21380
21381
21382
21383
21384
21385
21386
21387
21388
21389
21390
21391
21392
21393
21394
21395
21396
21397
21398
21399
21400
21401
21402
21403
21404
21405
21406
21407
21408
21409
21410
21411
21412
21413
21414
21415
21416
21417
21418
21419
21420
21421
21422
21423
21424
21425
21426
21427
21428
21429
21430
21431
21432
21433
21434
21435
21436
21437
21438
21439
21440
21441
21442
21443
21444
21445
21446
21447
21448
21449
21450
21451
21452
21453
21454
21455
21456
21457
21458
21459
21460
21461
21462
21463
21464
21465
21466
21467
21468
21469
21470
21471
21472
21473
21474
21475
21476
21477
21478
21479
21480
21481
21482
21483
21484
21485
21486
21487
21488
21489
21490
21491
21492
21493
21494
21495
21496
21497
21498
21499
21500
21501
21502
21503
21504
21505
21506
21507
21508
21509
21510
21511
21512
21513
21514
21515
21516
21517
21518
21519
21520
21521
21522
21523
21524
21525
21526
21527
21528
21529
21530
21531
21532
21533
21534
21535
21536
21537
21538
21539
21540
21541
21542
21543
21544
21545
21546
21547
21548
21549
21550
21551
21552
21553
21554
21555
21556
21557
21558
21559
21560
21561
21562
21563
21564
21565
21566
21567
21568
21569
21570
21571
21572
21573
21574
21575
21576
21577
21578
21579
21580
21581
21582
21583
21584
21585
21586
21587
21588
21589
21590
21591
21592
21593
21594
21595
21596
21597
21598
21599
21600
21601
21602
21603
21604
21605
21606
21607
21608
21609
21610
21611
21612
21613
21614
21615
21616
21617
21618
21619
21620
21621
21622
21623
21624
21625
21626
21627
21628
21629
21630
21631
21632
21633
21634
21635
21636
21637
21638
21639
21640
21641
21642
21643
21644
21645
21646
21647
21648
21649
21650
21651
21652
21653
21654
21655
21656
21657
21658
21659
21660
21661
21662
21663
21664
21665
21666
21667
21668
21669
21670
21671
21672
21673
21674
21675
21676
21677
21678
21679
21680
21681
21682
21683
21684
21685
21686
21687
21688
21689
21690
21691
21692
21693
21694
21695
21696
21697
21698
21699
21700
21701
21702
21703
21704
21705
21706
21707
21708
21709
21710
21711
21712
21713
21714
21715
21716
21717
21718
21719
21720
21721
21722
21723
21724
21725
21726
21727
21728
21729
21730
21731
21732
21733
21734
21735
21736
21737
21738
21739
21740
21741
21742
21743
21744
21745
21746
21747
21748
21749
21750
21751
21752
21753
21754
21755
21756
21757
21758
21759
21760
21761
21762
21763
21764
21765
21766
21767
21768
21769
21770
21771
21772
21773
21774
21775
21776
21777
21778
21779
21780
21781
21782
21783
21784
21785
21786
21787
21788
21789
21790
21791
21792
21793
21794
21795
21796
21797
21798
21799
21800
21801
21802
21803
21804
21805
21806
21807
21808
21809
21810
21811
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836
21837
21838
21839
21840
21841
21842
21843
21844
21845
21846
21847
21848
21849
21850
21851
21852
21853
21854
21855
21856
21857
21858
21859
21860
21861
21862
21863
21864
21865
21866
21867
21868
21869
21870
21871
21872
21873
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886
21887
21888
21889
21890
21891
21892
21893
21894
21895
21896
21897
21898
21899
21900
21901
21902
21903
21904
21905
21906
21907
21908
21909
21910
21911
21912
21913
21914
21915
21916
21917
21918
21919
21920
21921
21922
21923
21924
21925
21926
21927
21928
21929
21930
21931
21932
21933
21934
21935
21936
21937
21938
21939
21940
21941
21942
21943
21944
21945
21946
21947
21948
21949
21950
21951
21952
21953
21954
21955
21956
21957
21958
21959
21960
21961
21962
21963
21964
21965
21966
21967
21968
21969
21970
21971
21972
21973
21974
21975
21976
21977
21978
21979
21980
21981
21982
21983
21984
21985
21986
21987
21988
21989
21990
21991
21992
21993
21994
21995
21996
21997
21998
21999
22000
22001
22002
22003
22004
22005
22006
22007
22008
22009
22010
22011
22012
22013
22014
22015
22016
22017
22018
22019
22020
22021
22022
22023
22024
22025
22026
22027
22028
22029
22030
22031
22032
22033
22034
22035
22036
22037
22038
22039
22040
22041
22042
22043
22044
22045
22046
22047
22048
22049
22050
22051
22052
22053
22054
22055
22056
22057
22058
22059
22060
22061
22062
22063
22064
22065
22066
22067
22068
22069
22070
22071
22072
22073
22074
22075
22076
22077
22078
22079
22080
22081
22082
22083
22084
22085
22086
22087
22088
22089
22090
22091
22092
22093
22094
22095
22096
22097
22098
22099
22100
22101
22102
22103
22104
22105
22106
22107
22108
22109
22110
22111
22112
22113
22114
22115
22116
22117
22118
22119
22120
22121
22122
22123
22124
22125
22126
22127
22128
22129
22130
22131
22132
22133
22134
22135
22136
22137
22138
22139
22140
22141
22142
22143
22144
22145
22146
22147
22148
22149
22150
22151
22152
22153
22154
22155
22156
22157
22158
22159
22160
22161
22162
22163
22164
22165
22166
22167
22168
22169
22170
22171
22172
22173
22174
22175
22176
22177
22178
22179
22180
22181
22182
22183
22184
22185
22186
22187
22188
22189
22190
22191
22192
22193
22194
22195
22196
22197
22198
22199
22200
22201
22202
22203
22204
22205
22206
22207
22208
22209
22210
22211
22212
22213
22214
22215
22216
22217
22218
22219
22220
22221
22222
22223
22224
22225
22226
22227
22228
22229
22230
22231
22232
22233
22234
22235
22236
22237
22238
22239
22240
22241
22242
22243
22244
22245
22246
22247
22248
22249
22250
22251
22252
22253
22254
22255
22256
22257
22258
22259
22260
22261
22262
22263
22264
22265
22266
22267
22268
22269
22270
22271
22272
22273
22274
22275
22276
22277
22278
22279
22280
22281
22282
22283
22284
22285
22286
22287
22288
22289
22290
22291
22292
22293
22294
22295
22296
22297
22298
22299
22300
22301
22302
22303
22304
22305
22306
22307
22308
22309
22310
22311
22312
22313
22314
22315
22316
22317
22318
22319
22320
22321
22322
22323
22324
22325
22326
22327
22328
22329
22330
22331
22332
22333
22334
22335
22336
22337
22338
22339
22340
22341
22342
22343
22344
22345
22346
22347
22348
22349
22350
22351
22352
22353
22354
22355
22356
22357
22358
22359
22360
22361
22362
22363
22364
22365
22366
22367
22368
22369
22370
22371
22372
22373
22374
22375
22376
22377
22378
22379
22380
22381
22382
22383
22384
22385
22386
22387
22388
22389
22390
22391
22392
22393
22394
22395
22396
22397
22398
22399
22400
22401
22402
22403
22404
22405
22406
22407
22408
22409
22410
22411
22412
22413
22414
22415
22416
22417
22418
22419
22420
22421
22422
22423
22424
22425
22426
22427
22428
22429
22430
22431
22432
22433
22434
22435
22436
22437
22438
22439
22440
22441
22442
22443
22444
22445
22446
22447
22448
22449
22450
22451
22452
22453
22454
22455
22456
22457
22458
22459
22460
22461
22462
22463
22464
22465
22466
22467
22468
22469
22470
22471
22472
22473
22474
22475
22476
22477
22478
22479
22480
22481
22482
22483
22484
22485
22486
22487
22488
22489
22490
22491
22492
22493
22494
22495
22496
22497
22498
22499
22500
22501
22502
22503
22504
22505
22506
22507
22508
22509
22510
22511
22512
22513
22514
22515
22516
22517
22518
22519
22520
22521
22522
22523
22524
22525
22526
22527
22528
22529
22530
22531
22532
22533
22534
22535
22536
22537
22538
22539
22540
22541
22542
22543
22544
22545
22546
22547
22548
22549
22550
22551
22552
22553
22554
22555
22556
22557
22558
22559
22560
22561
22562
22563
22564
22565
22566
22567
22568
22569
22570
22571
22572
22573
22574
22575
22576
22577
22578
22579
22580
22581
22582
22583
22584
22585
22586
22587
22588
22589
22590
22591
22592
22593
22594
22595
22596
22597
22598
22599
22600
22601
22602
22603
22604
22605
22606
22607
22608
22609
22610
22611
22612
22613
22614
22615
22616
22617
22618
22619
22620
22621
22622
22623
22624
22625
22626
22627
22628
22629
22630
22631
22632
22633
22634
22635
22636
22637
22638
22639
22640
22641
22642
22643
22644
22645
22646
22647
22648
22649
22650
22651
22652
22653
22654
22655
22656
22657
22658
22659
22660
22661
22662
22663
22664
22665
22666
22667
22668
22669
22670
22671
22672
22673
22674
22675
22676
22677
22678
22679
22680
22681
22682
22683
22684
22685
22686
22687
22688
22689
22690
22691
22692
22693
22694
22695
22696
22697
22698
22699
22700
22701
22702
22703
22704
22705
22706
22707
22708
22709
22710
22711
22712
22713
22714
22715
22716
22717
22718
22719
22720
22721
22722
22723
22724
22725
22726
22727
22728
22729
22730
22731
22732
22733
22734
22735
22736
22737
22738
22739
22740
22741
22742
22743
22744
22745
22746
22747
22748
22749
22750
22751
22752
22753
22754
22755
22756
22757
22758
22759
22760
22761
22762
22763
22764
22765
22766
22767
22768
22769
22770
22771
22772
22773
22774
22775
22776
22777
22778
22779
22780
22781
22782
22783
22784
22785
22786
22787
22788
22789
22790
22791
22792
22793
22794
22795
22796
22797
22798
22799
22800
22801
22802
22803
22804
22805
22806
22807
22808
22809
22810
22811
22812
22813
22814
22815
22816
22817
22818
22819
22820
22821
22822
22823
22824
22825
22826
22827
22828
22829
22830
22831
22832
22833
22834
22835
22836
22837
22838
22839
22840
22841
22842
22843
22844
22845
22846
22847
22848
22849
22850
22851
22852
22853
22854
22855
22856
22857
22858
22859
22860
22861
22862
22863
22864
22865
22866
22867
22868
22869
22870
22871
22872
22873
22874
22875
22876
22877
22878
22879
22880
22881
22882
22883
22884
22885
22886
22887
22888
22889
22890
22891
22892
22893
22894
22895
22896
22897
22898
22899
22900
22901
22902
22903
22904
22905
22906
22907
22908
22909
22910
22911
22912
22913
22914
22915
22916
22917
22918
22919
22920
22921
22922
22923
22924
22925
22926
22927
22928
22929
22930
22931
22932
22933
22934
22935
22936
22937
22938
22939
22940
22941
22942
22943
22944
22945
22946
22947
22948
22949
22950
22951
22952
22953
22954
22955
22956
22957
22958
22959
22960
22961
22962
22963
22964
22965
22966
22967
22968
22969
22970
22971
22972
22973
22974
22975
22976
22977
22978
22979
22980
22981
22982
22983
22984
22985
22986
22987
22988
22989
22990
22991
22992
22993
22994
22995
22996
22997
22998
22999
23000
23001
23002
23003
23004
23005
23006
23007
23008
23009
23010
23011
23012
23013
23014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
23027
23028
23029
23030
23031
23032
23033
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058
23059
23060
23061
23062
23063
23064
23065
23066
23067
23068
23069
23070
23071
23072
23073
23074
23075
23076
23077
23078
23079
23080
23081
23082
23083
23084
23085
23086
23087
23088
23089
23090
23091
23092
23093
23094
23095
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108
23109
23110
23111
23112
23113
23114
23115
23116
23117
23118
23119
23120
23121
23122
23123
23124
23125
23126
23127
23128
23129
23130
23131
23132
23133
23134
23135
23136
23137
23138
23139
23140
23141
23142
23143
23144
23145
23146
23147
23148
23149
23150
23151
23152
23153
23154
23155
23156
23157
23158
23159
23160
23161
23162
23163
23164
23165
23166
23167
23168
23169
23170
23171
23172
23173
23174
23175
23176
23177
23178
23179
23180
23181
23182
23183
23184
23185
23186
23187
23188
23189
23190
23191
23192
23193
23194
23195
23196
23197
23198
23199
23200
23201
23202
23203
23204
23205
23206
23207
23208
23209
23210
23211
23212
23213
23214
23215
23216
23217
23218
23219
23220
23221
23222
23223
23224
23225
23226
23227
23228
23229
23230
23231
23232
23233
23234
23235
23236
23237
23238
23239
23240
23241
23242
23243
23244
23245
23246
23247
23248
23249
23250
23251
23252
23253
23254
23255
23256
23257
23258
23259
23260
23261
23262
23263
23264
23265
23266
23267
23268
23269
23270
23271
23272
23273
23274
23275
23276
23277
23278
23279
23280
23281
23282
23283
23284
23285
23286
23287
23288
23289
23290
23291
23292
23293
23294
23295
23296
23297
23298
23299
23300
23301
23302
23303
23304
23305
23306
23307
23308
23309
23310
23311
23312
23313
23314
23315
23316
23317
23318
23319
23320
23321
23322
23323
23324
23325
23326
23327
23328
23329
23330
23331
23332
23333
23334
23335
23336
23337
23338
23339
23340
23341
23342
23343
23344
23345
23346
23347
23348
23349
23350
23351
23352
23353
23354
23355
23356
23357
23358
23359
23360
23361
23362
23363
23364
23365
23366
23367
23368
23369
23370
23371
23372
23373
23374
23375
23376
23377
23378
23379
23380
23381
23382
23383
23384
23385
23386
23387
23388
23389
23390
23391
23392
23393
23394
23395
23396
23397
23398
23399
23400
23401
23402
23403
23404
23405
23406
23407
23408
23409
23410
23411
23412
23413
23414
23415
23416
23417
23418
23419
23420
23421
23422
23423
23424
23425
23426
23427
23428
23429
23430
23431
23432
23433
23434
23435
23436
23437
23438
23439
23440
23441
23442
23443
23444
23445
23446
23447
23448
23449
23450
23451
23452
23453
23454
23455
23456
23457
23458
23459
23460
23461
23462
23463
23464
23465
23466
23467
23468
23469
23470
23471
23472
23473
23474
23475
23476
23477
23478
23479
23480
23481
23482
23483
23484
23485
23486
23487
23488
23489
23490
23491
23492
23493
23494
23495
23496
23497
23498
23499
23500
23501
23502
23503
23504
23505
23506
23507
23508
23509
23510
23511
23512
23513
23514
23515
23516
23517
23518
23519
23520
23521
23522
23523
23524
23525
23526
23527
23528
23529
23530
23531
23532
23533
23534
23535
23536
23537
23538
23539
23540
23541
23542
23543
23544
23545
23546
23547
23548
23549
23550
23551
23552
23553
23554
23555
23556
23557
23558
23559
23560
23561
23562
23563
23564
23565
23566
23567
23568
23569
23570
23571
23572
23573
23574
23575
23576
23577
23578
23579
23580
23581
23582
23583
23584
23585
23586
23587
23588
23589
23590
23591
23592
23593
23594
23595
23596
23597
23598
23599
23600
23601
23602
23603
23604
23605
23606
23607
23608
23609
23610
23611
23612
23613
23614
23615
23616
23617
23618
23619
23620
23621
23622
23623
23624
23625
23626
23627
23628
23629
23630
23631
23632
23633
23634
23635
23636
23637
23638
23639
23640
23641
23642
23643
23644
23645
23646
23647
23648
23649
23650
23651
23652
23653
23654
23655
23656
23657
23658
23659
23660
23661
23662
23663
23664
23665
23666
23667
23668
23669
23670
23671
23672
23673
23674
23675
23676
23677
23678
23679
23680
23681
23682
23683
23684
23685
23686
23687
23688
23689
23690
23691
23692
23693
23694
23695
23696
23697
23698
23699
23700
23701
23702
23703
23704
23705
23706
23707
23708
23709
23710
23711
23712
23713
23714
23715
23716
23717
23718
23719
23720
23721
23722
23723
23724
23725
23726
23727
23728
23729
23730
23731
23732
23733
23734
23735
23736
23737
23738
23739
23740
23741
23742
23743
23744
23745
23746
23747
23748
23749
23750
23751
23752
23753
23754
23755
23756
23757
23758
23759
23760
23761
23762
23763
23764
23765
23766
23767
23768
23769
23770
23771
23772
23773
23774
23775
23776
23777
23778
23779
23780
23781
23782
23783
23784
23785
23786
23787
23788
23789
23790
23791
23792
23793
23794
23795
23796
23797
23798
23799
23800
23801
23802
23803
23804
23805
23806
23807
23808
23809
23810
23811
23812
23813
23814
23815
23816
23817
23818
23819
23820
23821
23822
23823
23824
23825
23826
23827
23828
23829
23830
23831
23832
23833
23834
23835
23836
23837
23838
23839
23840
23841
23842
23843
23844
23845
23846
23847
23848
23849
23850
23851
23852
23853
23854
23855
23856
23857
23858
23859
23860
23861
23862
23863
23864
23865
23866
23867
23868
23869
23870
23871
23872
23873
23874
23875
23876
23877
23878
23879
23880
23881
23882
23883
23884
23885
23886
23887
23888
23889
23890
23891
23892
23893
23894
23895
23896
23897
23898
23899
23900
23901
23902
23903
23904
23905
23906
23907
23908
23909
23910
23911
23912
23913
23914
23915
23916
23917
23918
23919
23920
23921
23922
23923
23924
23925
23926
23927
23928
23929
23930
23931
23932
23933
23934
23935
23936
23937
23938
23939
23940
23941
23942
23943
23944
23945
23946
23947
23948
23949
23950
23951
23952
23953
23954
23955
23956
23957
23958
23959
23960
23961
23962
23963
23964
23965
23966
23967
23968
23969
23970
23971
23972
23973
23974
23975
23976
23977
23978
23979
23980
23981
23982
23983
23984
23985
23986
23987
23988
23989
23990
23991
23992
23993
23994
23995
23996
23997
23998
23999
24000
24001
24002
24003
24004
24005
24006
24007
24008
24009
24010
24011
24012
24013
24014
24015
24016
24017
24018
24019
24020
24021
24022
24023
24024
24025
24026
24027
24028
24029
24030
24031
24032
24033
24034
24035
24036
24037
24038
24039
24040
24041
24042
24043
24044
24045
24046
24047
24048
24049
24050
24051
24052
24053
24054
24055
24056
24057
24058
24059
24060
24061
24062
24063
24064
24065
24066
24067
24068
24069
24070
24071
24072
24073
24074
24075
24076
24077
24078
24079
24080
24081
24082
24083
24084
24085
24086
24087
24088
24089
24090
24091
24092
24093
24094
24095
24096
24097
24098
24099
24100
24101
24102
24103
24104
24105
24106
24107
24108
24109
24110
24111
24112
24113
24114
24115
24116
24117
24118
24119
24120
24121
24122
24123
24124
24125
24126
24127
24128
24129
24130
24131
24132
24133
24134
24135
24136
24137
24138
24139
24140
24141
24142
24143
24144
24145
24146
24147
24148
24149
24150
24151
24152
24153
24154
24155
24156
24157
24158
24159
24160
24161
24162
24163
24164
24165
24166
24167
24168
24169
24170
24171
24172
24173
24174
24175
24176
24177
24178
24179
24180
24181
24182
24183
24184
24185
24186
24187
24188
24189
24190
24191
24192
24193
24194
24195
24196
24197
24198
24199
24200
24201
24202
24203
24204
24205
24206
24207
24208
24209
24210
24211
24212
24213
24214
24215
24216
24217
24218
24219
24220
24221
24222
24223
24224
24225
24226
24227
24228
24229
24230
24231
24232
24233
24234
24235
24236
24237
24238
24239
24240
24241
24242
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267
24268
24269
24270
24271
24272
24273
24274
24275
24276
24277
24278
24279
24280
24281
24282
24283
24284
24285
24286
24287
24288
24289
24290
24291
24292
24293
24294
24295
24296
24297
24298
24299
24300
24301
24302
24303
24304
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317
24318
24319
24320
24321
24322
24323
24324
24325
24326
24327
24328
24329
24330
24331
24332
24333
24334
24335
24336
24337
24338
24339
24340
24341
24342
24343
24344
24345
24346
24347
24348
24349
24350
24351
24352
24353
24354
24355
24356
24357
24358
24359
24360
24361
24362
24363
24364
24365
24366
24367
24368
24369
24370
24371
24372
24373
24374
24375
24376
24377
24378
24379
24380
24381
24382
24383
24384
24385
24386
24387
24388
24389
24390
24391
24392
24393
24394
24395
24396
24397
24398
24399
24400
24401
24402
24403
24404
24405
24406
24407
24408
24409
24410
24411
24412
24413
24414
24415
24416
24417
24418
24419
24420
24421
24422
24423
24424
24425
24426
24427
24428
24429
24430
24431
24432
24433
24434
24435
24436
24437
24438
24439
24440
24441
24442
24443
24444
24445
24446
24447
24448
24449
24450
24451
24452
24453
24454
24455
24456
24457
24458
24459
24460
24461
24462
24463
24464
24465
24466
24467
24468
24469
24470
24471
24472
24473
24474
24475
24476
24477
24478
24479
24480
24481
24482
24483
24484
24485
24486
24487
24488
24489
24490
24491
24492
24493
24494
24495
24496
24497
24498
24499
24500
24501
24502
24503
24504
24505
24506
24507
24508
24509
24510
24511
24512
24513
24514
24515
24516
24517
24518
24519
24520
24521
24522
24523
24524
24525
24526
24527
24528
24529
24530
24531
24532
24533
24534
24535
24536
24537
24538
24539
24540
24541
24542
24543
24544
24545
24546
24547
24548
24549
24550
24551
24552
24553
24554
24555
24556
24557
24558
24559
24560
24561
24562
24563
24564
24565
24566
24567
24568
24569
24570
24571
24572
24573
24574
24575
24576
24577
24578
24579
24580
24581
24582
24583
24584
24585
24586
24587
24588
24589
24590
24591
24592
24593
24594
24595
24596
24597
24598
24599
24600
24601
24602
24603
24604
24605
24606
24607
24608
24609
24610
24611
24612
24613
24614
24615
24616
24617
24618
24619
24620
24621
24622
24623
24624
24625
24626
24627
24628
24629
24630
24631
24632
24633
24634
24635
24636
24637
24638
24639
24640
24641
24642
24643
24644
24645
24646
24647
24648
24649
24650
24651
24652
24653
24654
24655
24656
24657
24658
24659
24660
24661
24662
24663
24664
24665
24666
24667
24668
24669
24670
24671
24672
24673
24674
24675
24676
24677
24678
24679
24680
24681
24682
24683
24684
24685
24686
24687
24688
24689
24690
24691
24692
24693
24694
24695
24696
24697
24698
24699
24700
24701
24702
24703
24704
24705
24706
24707
24708
24709
24710
24711
24712
24713
24714
24715
24716
24717
24718
24719
24720
24721
24722
24723
24724
24725
24726
24727
24728
24729
24730
24731
24732
24733
24734
24735
24736
24737
24738
24739
24740
24741
24742
24743
24744
24745
24746
24747
24748
24749
24750
24751
24752
24753
24754
24755
24756
24757
24758
24759
24760
24761
24762
24763
24764
24765
24766
24767
24768
24769
24770
24771
24772
24773
24774
24775
24776
24777
24778
24779
24780
24781
24782
24783
24784
24785
24786
24787
24788
24789
24790
24791
24792
24793
24794
24795
24796
24797
24798
24799
24800
24801
24802
24803
24804
24805
24806
24807
24808
24809
24810
24811
24812
24813
24814
24815
24816
24817
24818
24819
24820
24821
24822
24823
24824
24825
24826
24827
24828
24829
24830
24831
24832
24833
24834
24835
24836
24837
24838
24839
24840
24841
24842
24843
24844
24845
24846
24847
24848
24849
24850
24851
24852
24853
24854
24855
24856
24857
24858
24859
24860
24861
24862
24863
24864
24865
24866
24867
24868
24869
24870
24871
24872
24873
24874
24875
24876
24877
24878
24879
24880
24881
24882
24883
24884
24885
24886
24887
24888
24889
24890
24891
24892
24893
24894
24895
24896
24897
24898
24899
24900
24901
24902
24903
24904
24905
24906
24907
24908
24909
24910
24911
24912
24913
24914
24915
24916
24917
24918
24919
24920
24921
24922
24923
24924
24925
24926
24927
24928
24929
24930
24931
24932
24933
24934
24935
24936
24937
24938
24939
24940
24941
24942
24943
24944
24945
24946
24947
24948
24949
24950
24951
24952
24953
24954
24955
24956
24957
24958
24959
24960
24961
24962
24963
24964
24965
24966
24967
24968
24969
24970
24971
24972
24973
24974
24975
24976
24977
24978
24979
24980
24981
24982
24983
24984
24985
24986
24987
24988
24989
24990
24991
24992
24993
24994
24995
24996
24997
24998
24999
25000
25001
25002
25003
25004
25005
25006
25007
25008
25009
25010
25011
25012
25013
25014
25015
25016
25017
25018
25019
25020
25021
25022
25023
25024
25025
25026
25027
25028
25029
25030
25031
25032
25033
25034
25035
25036
25037
25038
25039
25040
25041
25042
25043
25044
25045
25046
25047
25048
25049
25050
25051
25052
25053
25054
25055
25056
25057
25058
25059
25060
25061
25062
25063
25064
25065
25066
25067
25068
25069
25070
25071
25072
25073
25074
25075
25076
25077
25078
25079
25080
25081
25082
25083
25084
25085
25086
25087
25088
25089
25090
25091
25092
25093
25094
25095
25096
25097
25098
25099
25100
25101
25102
25103
25104
25105
25106
25107
25108
25109
25110
25111
25112
25113
25114
25115
25116
25117
25118
25119
25120
25121
25122
25123
25124
25125
25126
25127
25128
25129
25130
25131
25132
25133
25134
25135
25136
25137
25138
25139
25140
25141
25142
25143
25144
25145
25146
25147
25148
25149
25150
25151
25152
25153
25154
25155
25156
25157
25158
25159
25160
25161
25162
25163
25164
25165
25166
25167
25168
25169
25170
25171
25172
25173
25174
25175
25176
25177
25178
25179
25180
25181
25182
25183
25184
25185
25186
25187
25188
25189
25190
25191
25192
25193
25194
25195
25196
25197
25198
25199
25200
25201
25202
25203
25204
25205
25206
25207
25208
25209
25210
25211
25212
25213
25214
25215
25216
25217
25218
25219
25220
25221
25222
25223
25224
25225
25226
25227
25228
25229
25230
25231
25232
25233
25234
25235
25236
25237
25238
25239
25240
25241
25242
25243
25244
25245
25246
25247
25248
25249
25250
25251
25252
25253
25254
25255
25256
25257
25258
25259
25260
25261
25262
25263
25264
25265
25266
25267
25268
25269
25270
25271
25272
25273
25274
25275
25276
25277
25278
25279
25280
25281
25282
25283
25284
25285
25286
25287
25288
25289
25290
25291
25292
25293
25294
25295
25296
25297
25298
25299
25300
25301
25302
25303
25304
25305
25306
25307
25308
25309
25310
25311
25312
25313
25314
25315
25316
25317
25318
25319
25320
25321
25322
25323
25324
25325
25326
25327
25328
25329
25330
25331
25332
25333
25334
25335
25336
25337
25338
25339
25340
25341
25342
25343
25344
25345
25346
25347
25348
25349
25350
25351
25352
25353
25354
25355
25356
25357
25358
25359
25360
25361
25362
25363
25364
25365
25366
25367
25368
25369
25370
25371
25372
25373
25374
25375
25376
25377
25378
25379
25380
25381
25382
25383
25384
25385
25386
25387
25388
25389
25390
25391
25392
25393
25394
25395
25396
25397
25398
25399
25400
25401
25402
25403
25404
25405
25406
25407
25408
25409
25410
25411
25412
25413
25414
25415
25416
25417
25418
25419
25420
25421
25422
25423
25424
25425
25426
25427
25428
25429
25430
25431
25432
25433
25434
25435
25436
25437
25438
25439
25440
25441
25442
25443
25444
25445
25446
25447
25448
25449
25450
25451
25452
25453
25454
25455
25456
25457
25458
25459
25460
25461
25462
25463
25464
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489
25490
25491
25492
25493
25494
25495
25496
25497
25498
25499
25500
25501
25502
25503
25504
25505
25506
25507
25508
25509
25510
25511
25512
25513
25514
25515
25516
25517
25518
25519
25520
25521
25522
25523
25524
25525
25526
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539
25540
25541
25542
25543
25544
25545
25546
25547
25548
25549
25550
25551
25552
25553
25554
25555
25556
25557
25558
25559
25560
25561
25562
25563
25564
25565
25566
25567
25568
25569
25570
25571
25572
25573
25574
25575
25576
25577
25578
25579
25580
25581
25582
25583
25584
25585
25586
25587
25588
25589
25590
25591
25592
25593
25594
25595
25596
25597
25598
25599
25600
25601
25602
25603
25604
25605
25606
25607
25608
25609
25610
25611
25612
25613
25614
25615
25616
25617
25618
25619
25620
25621
25622
25623
25624
25625
25626
25627
25628
25629
25630
25631
25632
25633
25634
25635
25636
25637
25638
25639
25640
25641
25642
25643
25644
25645
25646
25647
25648
25649
25650
25651
25652
25653
25654
25655
25656
25657
25658
25659
25660
25661
25662
25663
25664
25665
25666
25667
25668
25669
25670
25671
25672
25673
25674
25675
25676
25677
25678
25679
25680
25681
25682
25683
25684
25685
25686
25687
25688
25689
25690
25691
25692
25693
25694
25695
25696
25697
25698
25699
25700
25701
25702
25703
25704
25705
25706
25707
25708
25709
25710
25711
25712
25713
25714
25715
25716
25717
25718
25719
25720
25721
25722
25723
25724
25725
25726
25727
25728
25729
25730
25731
25732
25733
25734
25735
25736
25737
25738
25739
25740
25741
25742
25743
25744
25745
25746
25747
25748
25749
25750
25751
25752
25753
25754
25755
25756
25757
25758
25759
25760
25761
25762
25763
25764
25765
25766
25767
25768
25769
25770
25771
25772
25773
25774
25775
25776
25777
25778
25779
25780
25781
25782
25783
25784
25785
25786
25787
25788
25789
25790
25791
25792
25793
25794
25795
25796
25797
25798
25799
25800
25801
25802
25803
25804
25805
25806
25807
25808
25809
25810
25811
25812
25813
25814
25815
25816
25817
25818
25819
25820
25821
25822
25823
25824
25825
25826
25827
25828
25829
25830
25831
25832
25833
25834
25835
25836
25837
25838
25839
25840
25841
25842
25843
25844
25845
25846
25847
25848
25849
25850
25851
25852
25853
25854
25855
25856
25857
25858
25859
25860
25861
25862
25863
25864
25865
25866
25867
25868
25869
25870
25871
25872
25873
25874
25875
25876
25877
25878
25879
25880
25881
25882
25883
25884
25885
25886
25887
25888
25889
25890
25891
25892
25893
25894
25895
25896
25897
25898
25899
25900
25901
25902
25903
25904
25905
25906
25907
25908
25909
25910
25911
25912
25913
25914
25915
25916
25917
25918
25919
25920
25921
25922
25923
25924
25925
25926
25927
25928
25929
25930
25931
25932
25933
25934
25935
25936
25937
25938
25939
25940
25941
25942
25943
25944
25945
25946
25947
25948
25949
25950
25951
25952
25953
25954
25955
25956
25957
25958
25959
25960
25961
25962
25963
25964
25965
25966
25967
25968
25969
25970
25971
25972
25973
25974
25975
25976
25977
25978
25979
25980
25981
25982
25983
25984
25985
25986
25987
25988
25989
25990
25991
25992
25993
25994
25995
25996
25997
25998
25999
26000
26001
26002
26003
26004
26005
26006
26007
26008
26009
26010
26011
26012
26013
26014
26015
26016
26017
26018
26019
26020
26021
26022
26023
26024
26025
26026
26027
26028
26029
26030
26031
26032
26033
26034
26035
26036
26037
26038
26039
26040
26041
26042
26043
26044
26045
26046
26047
26048
26049
26050
26051
26052
26053
26054
26055
26056
26057
26058
26059
26060
26061
26062
26063
26064
26065
26066
26067
26068
26069
26070
26071
26072
26073
26074
26075
26076
26077
26078
26079
26080
26081
26082
26083
26084
26085
26086
26087
26088
26089
26090
26091
26092
26093
26094
26095
26096
26097
26098
26099
26100
26101
26102
26103
26104
26105
26106
26107
26108
26109
26110
26111
26112
26113
26114
26115
26116
26117
26118
26119
26120
26121
26122
26123
26124
26125
26126
26127
26128
26129
26130
26131
26132
26133
26134
26135
26136
26137
26138
26139
26140
26141
26142
26143
26144
26145
26146
26147
26148
26149
26150
26151
26152
26153
26154
26155
26156
26157
26158
26159
26160
26161
26162
26163
26164
26165
26166
26167
26168
26169
26170
26171
26172
26173
26174
26175
26176
26177
26178
26179
26180
26181
26182
26183
26184
26185
26186
26187
26188
26189
26190
26191
26192
26193
26194
26195
26196
26197
26198
26199
26200
26201
26202
26203
26204
26205
26206
26207
26208
26209
26210
26211
26212
26213
26214
26215
26216
26217
26218
26219
26220
26221
26222
26223
26224
26225
26226
26227
26228
26229
26230
26231
26232
26233
26234
26235
26236
26237
26238
26239
26240
26241
26242
26243
26244
26245
26246
26247
26248
26249
26250
26251
26252
26253
26254
26255
26256
26257
26258
26259
26260
26261
26262
26263
26264
26265
26266
26267
26268
26269
26270
26271
26272
26273
26274
26275
26276
26277
26278
26279
26280
26281
26282
26283
26284
26285
26286
26287
26288
26289
26290
26291
26292
26293
26294
26295
26296
26297
26298
26299
26300
26301
26302
26303
26304
26305
26306
26307
26308
26309
26310
26311
26312
26313
26314
26315
26316
26317
26318
26319
26320
26321
26322
26323
26324
26325
26326
26327
26328
26329
26330
26331
26332
26333
26334
26335
26336
26337
26338
26339
26340
26341
26342
26343
26344
26345
26346
26347
26348
26349
26350
26351
26352
26353
26354
26355
26356
26357
26358
26359
26360
26361
26362
26363
26364
26365
26366
26367
26368
26369
26370
26371
26372
26373
26374
26375
26376
26377
26378
26379
26380
26381
26382
26383
26384
26385
26386
26387
26388
26389
26390
26391
26392
26393
26394
26395
26396
26397
26398
26399
26400
26401
26402
26403
26404
26405
26406
26407
26408
26409
26410
26411
26412
26413
26414
26415
26416
26417
26418
26419
26420
26421
26422
26423
26424
26425
26426
26427
26428
26429
26430
26431
26432
26433
26434
26435
26436
26437
26438
26439
26440
26441
26442
26443
26444
26445
26446
26447
26448
26449
26450
26451
26452
26453
26454
26455
26456
26457
26458
26459
26460
26461
26462
26463
26464
26465
26466
26467
26468
26469
26470
26471
26472
26473
26474
26475
26476
26477
26478
26479
26480
26481
26482
26483
26484
26485
26486
26487
26488
26489
26490
26491
26492
26493
26494
26495
26496
26497
26498
26499
26500
26501
26502
26503
26504
26505
26506
26507
26508
26509
26510
26511
26512
26513
26514
26515
26516
26517
26518
26519
26520
26521
26522
26523
26524
26525
26526
26527
26528
26529
26530
26531
26532
26533
26534
26535
26536
26537
26538
26539
26540
26541
26542
26543
26544
26545
26546
26547
26548
26549
26550
26551
26552
26553
26554
26555
26556
26557
26558
26559
26560
26561
26562
26563
26564
26565
26566
26567
26568
26569
26570
26571
26572
26573
26574
26575
26576
26577
26578
26579
26580
26581
26582
26583
26584
26585
26586
26587
26588
26589
26590
26591
26592
26593
26594
26595
26596
26597
26598
26599
26600
26601
26602
26603
26604
26605
26606
26607
26608
26609
26610
26611
26612
26613
26614
26615
26616
26617
26618
26619
26620
26621
26622
26623
26624
26625
26626
26627
26628
26629
26630
26631
26632
26633
26634
26635
26636
26637
26638
26639
26640
26641
26642
26643
26644
26645
26646
26647
26648
26649
26650
26651
26652
26653
26654
26655
26656
26657
26658
26659
26660
26661
26662
26663
26664
26665
26666
26667
26668
26669
26670
26671
26672
26673
26674
26675
26676
26677
26678
26679
26680
26681
26682
26683
26684
26685
26686
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711
26712
26713
26714
26715
26716
26717
26718
26719
26720
26721
26722
26723
26724
26725
26726
26727
26728
26729
26730
26731
26732
26733
26734
26735
26736
26737
26738
26739
26740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761
26762
26763
26764
26765
26766
26767
26768
26769
26770
26771
26772
26773
26774
26775
26776
26777
26778
26779
26780
26781
26782
26783
26784
26785
26786
26787
26788
26789
26790
26791
26792
26793
26794
26795
26796
26797
26798
26799
26800
26801
26802
26803
26804
26805
26806
26807
26808
26809
26810
26811
26812
26813
26814
26815
26816
26817
26818
26819
26820
26821
26822
26823
26824
26825
26826
26827
26828
26829
26830
26831
26832
26833
26834
26835
26836
26837
26838
26839
26840
26841
26842
26843
26844
26845
26846
26847
26848
26849
26850
26851
26852
26853
26854
26855
26856
26857
26858
26859
26860
26861
26862
26863
26864
26865
26866
26867
26868
26869
26870
26871
26872
26873
26874
26875
26876
26877
26878
26879
26880
26881
26882
26883
26884
26885
26886
26887
26888
26889
26890
26891
26892
26893
26894
26895
26896
26897
26898
26899
26900
26901
26902
26903
26904
26905
26906
26907
26908
26909
26910
26911
26912
26913
26914
26915
26916
26917
26918
26919
26920
26921
26922
26923
26924
26925
26926
26927
26928
26929
26930
26931
26932
26933
26934
26935
26936
26937
26938
26939
26940
26941
26942
26943
26944
26945
26946
26947
26948
26949
26950
26951
26952
26953
26954
26955
26956
26957
26958
26959
26960
26961
26962
26963
26964
26965
26966
26967
26968
26969
26970
26971
26972
26973
26974
26975
26976
26977
26978
26979
26980
26981
26982
26983
26984
26985
26986
26987
26988
26989
26990
26991
26992
26993
26994
26995
26996
26997
26998
26999
27000
27001
27002
27003
27004
27005
27006
27007
27008
27009
27010
27011
27012
27013
27014
27015
27016
27017
27018
27019
27020
27021
27022
27023
27024
27025
27026
27027
27028
27029
27030
27031
27032
27033
27034
27035
27036
27037
27038
27039
27040
27041
27042
27043
27044
27045
27046
27047
27048
27049
27050
27051
27052
27053
27054
27055
27056
27057
27058
27059
27060
27061
27062
27063
27064
27065
27066
27067
27068
27069
27070
27071
27072
27073
27074
27075
27076
27077
27078
27079
27080
27081
27082
27083
27084
27085
27086
27087
27088
27089
27090
27091
27092
27093
27094
27095
27096
27097
27098
27099
27100
27101
27102
27103
27104
27105
27106
27107
27108
27109
27110
27111
27112
27113
27114
27115
27116
27117
27118
27119
27120
27121
27122
27123
27124
27125
27126
27127
27128
27129
27130
27131
27132
27133
27134
27135
27136
27137
27138
27139
27140
27141
27142
27143
27144
27145
27146
27147
27148
27149
27150
27151
27152
27153
27154
27155
27156
27157
27158
27159
27160
27161
27162
27163
27164
27165
27166
27167
27168
27169
27170
27171
27172
27173
27174
27175
27176
27177
27178
27179
27180
27181
27182
27183
27184
27185
27186
27187
27188
27189
27190
27191
27192
27193
27194
27195
27196
27197
27198
27199
27200
27201
27202
27203
27204
27205
27206
27207
27208
27209
27210
27211
27212
27213
27214
27215
27216
27217
27218
27219
27220
27221
27222
27223
27224
27225
27226
27227
27228
27229
27230
27231
27232
27233
27234
27235
27236
27237
27238
27239
27240
27241
27242
27243
27244
27245
27246
27247
27248
27249
27250
27251
27252
27253
27254
27255
27256
27257
27258
27259
27260
27261
27262
27263
27264
27265
27266
27267
27268
27269
27270
27271
27272
27273
27274
27275
27276
27277
27278
27279
27280
27281
27282
27283
27284
27285
27286
27287
27288
27289
27290
27291
27292
27293
27294
27295
27296
27297
27298
27299
27300
27301
27302
27303
27304
27305
27306
27307
27308
27309
27310
27311
27312
27313
27314
27315
27316
27317
27318
27319
27320
27321
27322
27323
27324
27325
27326
27327
27328
27329
27330
27331
27332
27333
27334
27335
27336
27337
27338
27339
27340
27341
27342
27343
27344
27345
27346
27347
27348
27349
27350
27351
27352
27353
27354
27355
27356
27357
27358
27359
27360
27361
27362
27363
27364
27365
27366
27367
27368
27369
27370
27371
27372
27373
27374
27375
27376
27377
27378
27379
27380
27381
27382
27383
27384
27385
27386
27387
27388
27389
27390
27391
27392
27393
27394
27395
27396
27397
27398
27399
27400
27401
27402
27403
27404
27405
27406
27407
27408
27409
27410
27411
27412
27413
27414
27415
27416
27417
27418
27419
27420
27421
27422
27423
27424
27425
27426
27427
27428
27429
27430
27431
27432
27433
27434
27435
27436
27437
27438
27439
27440
27441
27442
27443
27444
27445
27446
27447
27448
27449
27450
27451
27452
27453
27454
27455
27456
27457
27458
27459
27460
27461
27462
27463
27464
27465
27466
27467
27468
27469
27470
27471
27472
27473
27474
27475
27476
27477
27478
27479
27480
27481
27482
27483
27484
27485
27486
27487
27488
27489
27490
27491
27492
27493
27494
27495
27496
27497
27498
27499
27500
27501
27502
27503
27504
27505
27506
27507
27508
27509
27510
27511
27512
27513
27514
27515
27516
27517
27518
27519
27520
27521
27522
27523
27524
27525
27526
27527
27528
27529
27530
27531
27532
27533
27534
27535
27536
27537
27538
27539
27540
27541
27542
27543
27544
27545
27546
27547
27548
27549
27550
27551
27552
27553
27554
27555
27556
27557
27558
27559
27560
27561
27562
27563
27564
27565
27566
27567
27568
27569
27570
27571
27572
27573
27574
27575
27576
27577
27578
27579
27580
27581
27582
27583
27584
27585
27586
27587
27588
27589
27590
27591
27592
27593
27594
27595
27596
27597
27598
27599
27600
27601
27602
27603
27604
27605
27606
27607
27608
27609
27610
27611
27612
27613
27614
27615
27616
27617
27618
27619
27620
27621
27622
27623
27624
27625
27626
27627
27628
27629
27630
27631
27632
27633
27634
27635
27636
27637
27638
27639
27640
27641
27642
27643
27644
27645
27646
27647
27648
27649
27650
27651
27652
27653
27654
27655
27656
27657
27658
27659
27660
27661
27662
27663
27664
27665
27666
27667
27668
27669
27670
27671
27672
27673
27674
27675
27676
27677
27678
27679
27680
27681
27682
27683
27684
27685
27686
27687
27688
27689
27690
27691
27692
27693
27694
27695
27696
27697
27698
27699
27700
27701
27702
27703
27704
27705
27706
27707
27708
27709
27710
27711
27712
27713
27714
27715
27716
27717
27718
27719
27720
27721
27722
27723
27724
27725
27726
27727
27728
27729
27730
27731
27732
27733
27734
27735
27736
27737
27738
27739
27740
27741
27742
27743
27744
27745
27746
27747
27748
27749
27750
27751
27752
27753
27754
27755
27756
27757
27758
27759
27760
27761
27762
27763
27764
27765
27766
27767
27768
27769
27770
27771
27772
27773
27774
27775
27776
27777
27778
27779
27780
27781
27782
27783
27784
27785
27786
27787
27788
27789
27790
27791
27792
27793
27794
27795
27796
27797
27798
27799
27800
27801
27802
27803
27804
27805
27806
27807
27808
27809
27810
27811
27812
27813
27814
27815
27816
27817
27818
27819
27820
27821
27822
27823
27824
27825
27826
27827
27828
27829
27830
27831
27832
27833
27834
27835
27836
27837
27838
27839
27840
27841
27842
27843
27844
27845
27846
27847
27848
27849
27850
27851
27852
27853
27854
27855
27856
27857
27858
27859
27860
27861
27862
27863
27864
27865
27866
27867
27868
27869
27870
27871
27872
27873
27874
27875
27876
27877
27878
27879
27880
27881
27882
27883
27884
27885
27886
27887
27888
27889
27890
27891
27892
27893
27894
27895
27896
27897
27898
27899
27900
27901
27902
27903
27904
27905
27906
27907
27908
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933
27934
27935
27936
27937
27938
27939
27940
27941
27942
27943
27944
27945
27946
27947
27948
27949
27950
27951
27952
27953
27954
27955
27956
27957
27958
27959
27960
27961
27962
27963
27964
27965
27966
27967
27968
27969
27970
27971
27972
27973
27974
27975
27976
27977
27978
27979
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992
27993
27994
27995
27996
27997
27998
27999
28000
28001
28002
28003
28004
28005
28006
28007
28008
28009
28010
28011
28012
28013
28014
28015
28016
28017
28018
28019
28020
28021
28022
28023
28024
28025
28026
28027
28028
28029
28030
28031
28032
28033
28034
28035
28036
28037
28038
28039
28040
28041
28042
28043
28044
28045
28046
28047
28048
28049
28050
28051
28052
28053
28054
28055
28056
28057
28058
28059
28060
28061
28062
28063
28064
28065
28066
28067
28068
28069
28070
28071
28072
28073
28074
28075
28076
28077
28078
28079
28080
28081
28082
28083
28084
28085
28086
28087
28088
28089
28090
28091
28092
28093
28094
28095
28096
28097
28098
28099
28100
28101
28102
28103
28104
28105
28106
28107
28108
28109
28110
28111
28112
28113
28114
28115
28116
28117
28118
28119
28120
28121
28122
28123
28124
28125
28126
28127
28128
28129
28130
28131
28132
28133
28134
28135
28136
28137
28138
28139
28140
28141
28142
28143
28144
28145
28146
28147
28148
28149
28150
28151
28152
28153
28154
28155
28156
28157
28158
28159
28160
28161
28162
28163
28164
28165
28166
28167
28168
28169
28170
28171
28172
28173
28174
28175
28176
28177
28178
28179
28180
28181
28182
28183
28184
28185
28186
28187
28188
28189
28190
28191
28192
28193
28194
28195
28196
28197
28198
28199
28200
28201
28202
28203
28204
28205
28206
28207
28208
28209
28210
28211
28212
28213
28214
28215
28216
28217
28218
28219
28220
28221
28222
28223
28224
28225
28226
28227
28228
28229
28230
28231
28232
28233
28234
28235
28236
28237
28238
28239
28240
28241
28242
28243
28244
28245
28246
28247
28248
28249
28250
28251
28252
28253
28254
28255
28256
28257
28258
28259
28260
28261
28262
28263
28264
28265
28266
28267
28268
28269
28270
28271
28272
28273
28274
28275
28276
28277
28278
28279
28280
28281
28282
28283
28284
28285
28286
28287
28288
28289
28290
28291
28292
28293
28294
28295
28296
28297
28298
28299
28300
28301
28302
28303
28304
28305
28306
28307
28308
28309
28310
28311
28312
28313
28314
28315
28316
28317
28318
28319
28320
28321
28322
28323
28324
28325
28326
28327
28328
28329
28330
28331
28332
28333
28334
28335
28336
28337
28338
28339
28340
28341
28342
28343
28344
28345
28346
28347
28348
28349
28350
28351
28352
28353
28354
28355
28356
28357
28358
28359
28360
28361
28362
28363
28364
28365
28366
28367
28368
28369
28370
28371
28372
28373
28374
28375
28376
28377
28378
28379
28380
28381
28382
28383
28384
28385
28386
28387
28388
28389
28390
28391
28392
28393
28394
28395
28396
28397
28398
28399
28400
28401
28402
28403
28404
28405
28406
28407
28408
28409
28410
28411
28412
28413
28414
28415
28416
28417
28418
28419
28420
28421
28422
28423
28424
28425
28426
28427
28428
28429
28430
28431
28432
28433
28434
28435
28436
28437
28438
28439
28440
28441
28442
28443
28444
28445
28446
28447
28448
28449
28450
28451
28452
28453
28454
28455
28456
28457
28458
28459
28460
28461
28462
28463
28464
28465
28466
28467
28468
28469
28470
28471
28472
28473
28474
28475
28476
28477
28478
28479
28480
28481
28482
28483
28484
28485
28486
28487
28488
28489
28490
28491
28492
28493
28494
28495
28496
28497
28498
28499
28500
28501
28502
28503
28504
28505
28506
28507
28508
28509
28510
28511
28512
28513
28514
28515
28516
28517
28518
28519
28520
28521
28522
28523
28524
28525
28526
28527
28528
28529
28530
28531
28532
28533
28534
28535
28536
28537
28538
28539
28540
28541
28542
28543
28544
28545
28546
28547
28548
28549
28550
28551
28552
28553
28554
28555
28556
28557
28558
28559
28560
28561
28562
28563
28564
28565
28566
28567
28568
28569
28570
28571
28572
28573
28574
28575
28576
28577
28578
28579
28580
28581
28582
28583
28584
28585
28586
28587
28588
28589
28590
28591
28592
28593
28594
28595
28596
28597
28598
28599
28600
28601
28602
28603
28604
28605
28606
28607
28608
28609
28610
28611
28612
28613
28614
28615
28616
28617
28618
28619
28620
28621
28622
28623
28624
28625
28626
28627
28628
28629
28630
28631
28632
28633
28634
28635
28636
28637
28638
28639
28640
28641
28642
28643
28644
28645
28646
28647
28648
28649
28650
28651
28652
28653
28654
28655
28656
28657
28658
28659
28660
28661
28662
28663
28664
28665
28666
28667
28668
28669
28670
28671
28672
28673
28674
28675
28676
28677
28678
28679
28680
28681
28682
28683
28684
28685
28686
28687
28688
28689
28690
28691
28692
28693
28694
28695
28696
28697
28698
28699
28700
28701
28702
28703
28704
28705
28706
28707
28708
28709
28710
28711
28712
28713
28714
28715
28716
28717
28718
28719
28720
28721
28722
28723
28724
28725
28726
28727
28728
28729
28730
28731
28732
28733
28734
28735
28736
28737
28738
28739
28740
28741
28742
28743
28744
28745
28746
28747
28748
28749
28750
28751
28752
28753
28754
28755
28756
28757
28758
28759
28760
28761
28762
28763
28764
28765
28766
28767
28768
28769
28770
28771
28772
28773
28774
28775
28776
28777
28778
28779
28780
28781
28782
28783
28784
28785
28786
28787
28788
28789
28790
28791
28792
28793
28794
28795
28796
28797
28798
28799
28800
28801
28802
28803
28804
28805
28806
28807
28808
28809
28810
28811
28812
28813
28814
28815
28816
28817
28818
28819
28820
28821
28822
28823
28824
28825
28826
28827
28828
28829
28830
28831
28832
28833
28834
28835
28836
28837
28838
28839
28840
28841
28842
28843
28844
28845
28846
28847
28848
28849
28850
28851
28852
28853
28854
28855
28856
28857
28858
28859
28860
28861
28862
28863
28864
28865
28866
28867
28868
28869
28870
28871
28872
28873
28874
28875
28876
28877
28878
28879
28880
28881
28882
28883
28884
28885
28886
28887
28888
28889
28890
28891
28892
28893
28894
28895
28896
28897
28898
28899
28900
28901
28902
28903
28904
28905
28906
28907
28908
28909
28910
28911
28912
28913
28914
28915
28916
28917
28918
28919
28920
28921
28922
28923
28924
28925
28926
28927
28928
28929
28930
28931
28932
28933
28934
28935
28936
28937
28938
28939
28940
28941
28942
28943
28944
28945
28946
28947
28948
28949
28950
28951
28952
28953
28954
28955
28956
28957
28958
28959
28960
28961
28962
28963
28964
28965
28966
28967
28968
28969
28970
28971
28972
28973
28974
28975
28976
28977
28978
28979
28980
28981
28982
28983
28984
28985
28986
28987
28988
28989
28990
28991
28992
28993
28994
28995
28996
28997
28998
28999
29000
29001
29002
29003
29004
29005
29006
29007
29008
29009
29010
29011
29012
29013
29014
29015
29016
29017
29018
29019
29020
29021
29022
29023
29024
29025
29026
29027
29028
29029
29030
29031
29032
29033
29034
29035
29036
29037
29038
29039
29040
29041
29042
29043
29044
29045
29046
29047
29048
29049
29050
29051
29052
29053
29054
29055
29056
29057
29058
29059
29060
29061
29062
29063
29064
29065
29066
29067
29068
29069
29070
29071
29072
29073
29074
29075
29076
29077
29078
29079
29080
29081
29082
29083
29084
29085
29086
29087
29088
29089
29090
29091
29092
29093
29094
29095
29096
29097
29098
29099
29100
29101
29102
29103
29104
29105
29106
29107
29108
29109
29110
29111
29112
29113
29114
29115
29116
29117
29118
29119
29120
29121
29122
29123
29124
29125
29126
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151
29152
29153
29154
29155
29156
29157
29158
29159
29160
29161
29162
29163
29164
29165
29166
29167
29168
29169
29170
29171
29172
29173
29174
29175
29176
29177
29178
29179
29180
29181
29182
29183
29184
29185
29186
29187
29188
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201
29202
29203
29204
29205
29206
29207
29208
29209
29210
29211
29212
29213
29214
29215
29216
29217
29218
29219
29220
29221
29222
29223
29224
29225
29226
29227
29228
29229
29230
29231
29232
29233
29234
29235
29236
29237
29238
29239
29240
29241
29242
29243
29244
29245
29246
29247
29248
29249
29250
29251
29252
29253
29254
29255
29256
29257
29258
29259
29260
29261
29262
29263
29264
29265
29266
29267
29268
29269
29270
29271
29272
29273
29274
29275
29276
29277
29278
29279
29280
29281
29282
29283
29284
29285
29286
29287
29288
29289
29290
29291
29292
29293
29294
29295
29296
29297
29298
29299
29300
29301
29302
29303
29304
29305
29306
29307
29308
29309
29310
29311
29312
29313
29314
29315
29316
29317
29318
29319
29320
29321
29322
29323
29324
29325
29326
29327
29328
29329
29330
29331
29332
29333
29334
29335
29336
29337
29338
29339
29340
29341
29342
29343
29344
29345
29346
29347
29348
29349
29350
29351
29352
29353
29354
29355
29356
29357
29358
29359
29360
29361
29362
29363
29364
29365
29366
29367
29368
29369
29370
29371
29372
29373
29374
29375
29376
29377
29378
29379
29380
29381
29382
29383
29384
29385
29386
29387
29388
29389
29390
29391
29392
29393
29394
29395
29396
29397
29398
29399
29400
29401
29402
29403
29404
29405
29406
29407
29408
29409
29410
29411
29412
29413
29414
29415
29416
29417
29418
29419
29420
29421
29422
29423
29424
29425
29426
29427
29428
29429
29430
29431
29432
29433
29434
29435
29436
29437
29438
29439
29440
29441
29442
29443
29444
29445
29446
29447
29448
29449
29450
29451
29452
29453
29454
29455
29456
29457
29458
29459
29460
29461
29462
29463
29464
29465
29466
29467
29468
29469
29470
29471
29472
29473
29474
29475
29476
29477
29478
29479
29480
29481
29482
29483
29484
29485
29486
29487
29488
29489
29490
29491
29492
29493
29494
29495
29496
29497
29498
29499
29500
29501
29502
29503
29504
29505
29506
29507
29508
29509
29510
29511
29512
29513
29514
29515
29516
29517
29518
29519
29520
29521
29522
29523
29524
29525
29526
29527
29528
29529
29530
29531
29532
29533
29534
29535
29536
29537
29538
29539
29540
29541
29542
29543
29544
29545
29546
29547
29548
29549
29550
29551
29552
29553
29554
29555
29556
29557
29558
29559
29560
29561
29562
29563
29564
29565
29566
29567
29568
29569
29570
29571
29572
29573
29574
29575
29576
29577
29578
29579
29580
29581
29582
29583
29584
29585
29586
29587
29588
29589
29590
29591
29592
29593
29594
29595
29596
29597
29598
29599
29600
29601
29602
29603
29604
29605
29606
29607
29608
29609
29610
29611
29612
29613
29614
29615
29616
29617
29618
29619
29620
29621
29622
29623
29624
29625
29626
29627
29628
29629
29630
29631
29632
29633
29634
29635
29636
29637
29638
29639
29640
29641
29642
29643
29644
29645
29646
29647
29648
29649
29650
29651
29652
29653
29654
29655
29656
29657
29658
29659
29660
29661
29662
29663
29664
29665
29666
29667
29668
29669
29670
29671
29672
29673
29674
29675
29676
29677
29678
29679
29680
29681
29682
29683
29684
29685
29686
29687
29688
29689
29690
29691
29692
29693
29694
29695
29696
29697
29698
29699
29700
29701
29702
29703
29704
29705
29706
29707
29708
29709
29710
29711
29712
29713
29714
29715
29716
29717
29718
29719
29720
29721
29722
29723
29724
29725
29726
29727
29728
29729
29730
29731
29732
29733
29734
29735
29736
29737
29738
29739
29740
29741
29742
29743
29744
29745
29746
29747
29748
29749
29750
29751
29752
29753
29754
29755
29756
29757
29758
29759
29760
29761
29762
29763
29764
29765
29766
29767
29768
29769
29770
29771
29772
29773
29774
29775
29776
29777
29778
29779
29780
29781
29782
29783
29784
29785
29786
29787
29788
29789
29790
29791
29792
29793
29794
29795
29796
29797
29798
29799
29800
29801
29802
29803
29804
29805
29806
29807
29808
29809
29810
29811
29812
29813
29814
29815
29816
29817
29818
29819
29820
29821
29822
29823
29824
29825
29826
29827
29828
29829
29830
29831
29832
29833
29834
29835
29836
29837
29838
29839
29840
29841
29842
29843
29844
29845
29846
29847
29848
29849
29850
29851
29852
29853
29854
29855
29856
29857
29858
29859
29860
29861
29862
29863
29864
29865
29866
29867
29868
29869
29870
29871
29872
29873
29874
29875
29876
29877
29878
29879
29880
29881
29882
29883
29884
29885
29886
29887
29888
29889
29890
29891
29892
29893
29894
29895
29896
29897
29898
29899
29900
29901
29902
29903
29904
29905
29906
29907
29908
29909
29910
29911
29912
29913
29914
29915
29916
29917
29918
29919
29920
29921
29922
29923
29924
29925
29926
29927
29928
29929
29930
29931
29932
29933
29934
29935
29936
29937
29938
29939
29940
29941
29942
29943
29944
29945
29946
29947
29948
29949
29950
29951
29952
29953
29954
29955
29956
29957
29958
29959
29960
29961
29962
29963
29964
29965
29966
29967
29968
29969
29970
29971
29972
29973
29974
29975
29976
29977
29978
29979
29980
29981
29982
29983
29984
29985
29986
29987
29988
29989
29990
29991
29992
29993
29994
29995
29996
29997
29998
29999
30000
30001
30002
30003
30004
30005
30006
30007
30008
30009
30010
30011
30012
30013
30014
30015
30016
30017
30018
30019
30020
30021
30022
30023
30024
30025
30026
30027
30028
30029
30030
30031
30032
30033
30034
30035
30036
30037
30038
30039
30040
30041
30042
30043
30044
30045
30046
30047
30048
30049
30050
30051
30052
30053
30054
30055
30056
30057
30058
30059
30060
30061
30062
30063
30064
30065
30066
30067
30068
30069
30070
30071
30072
30073
30074
30075
30076
30077
30078
30079
30080
30081
30082
30083
30084
30085
30086
30087
30088
30089
30090
30091
30092
30093
30094
30095
30096
30097
30098
30099
30100
30101
30102
30103
30104
30105
30106
30107
30108
30109
30110
30111
30112
30113
30114
30115
30116
30117
30118
30119
30120
30121
30122
30123
30124
30125
30126
30127
30128
30129
30130
30131
30132
30133
30134
30135
30136
30137
30138
30139
30140
30141
30142
30143
30144
30145
30146
30147
30148
30149
30150
30151
30152
30153
30154
30155
30156
30157
30158
30159
30160
30161
30162
30163
30164
30165
30166
30167
30168
30169
30170
30171
30172
30173
30174
30175
30176
30177
30178
30179
30180
30181
30182
30183
30184
30185
30186
30187
30188
30189
30190
30191
30192
30193
30194
30195
30196
30197
30198
30199
30200
30201
30202
30203
30204
30205
30206
30207
30208
30209
30210
30211
30212
30213
30214
30215
30216
30217
30218
30219
30220
30221
30222
30223
30224
30225
30226
30227
30228
30229
30230
30231
30232
30233
30234
30235
30236
30237
30238
30239
30240
30241
30242
30243
30244
30245
30246
30247
30248
30249
30250
30251
30252
30253
30254
30255
30256
30257
30258
30259
30260
30261
30262
30263
30264
30265
30266
30267
30268
30269
30270
30271
30272
30273
30274
30275
30276
30277
30278
30279
30280
30281
30282
30283
30284
30285
30286
30287
30288
30289
30290
30291
30292
30293
30294
30295
30296
30297
30298
30299
30300
30301
30302
30303
30304
30305
30306
30307
30308
30309
30310
30311
30312
30313
30314
30315
30316
30317
30318
30319
30320
30321
30322
30323
30324
30325
30326
30327
30328
30329
30330
30331
30332
30333
30334
30335
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360
30361
30362
30363
30364
30365
30366
30367
30368
30369
30370
30371
30372
30373
30374
30375
30376
30377
30378
30379
30380
30381
30382
30383
30384
30385
30386
30387
30388
30389
30390
30391
30392
30393
30394
30395
30396
30397
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410
30411
30412
30413
30414
30415
30416
30417
30418
30419
30420
30421
30422
30423
30424
30425
30426
30427
30428
30429
30430
30431
30432
30433
30434
30435
30436
30437
30438
30439
30440
30441
30442
30443
30444
30445
30446
30447
30448
30449
30450
30451
30452
30453
30454
30455
30456
30457
30458
30459
30460
30461
30462
30463
30464
30465
30466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
30479
30480
30481
30482
30483
30484
30485
30486
30487
30488
30489
30490
30491
30492
30493
30494
30495
30496
30497
30498
30499
30500
30501
30502
30503
30504
30505
30506
30507
30508
30509
30510
30511
30512
30513
30514
30515
30516
30517
30518
30519
30520
30521
30522
30523
30524
30525
30526
30527
30528
30529
30530
30531
30532
30533
30534
30535
30536
30537
30538
30539
30540
30541
30542
30543
30544
30545
30546
30547
30548
30549
30550
30551
30552
30553
30554
30555
30556
30557
30558
30559
30560
30561
30562
30563
30564
30565
30566
30567
30568
30569
30570
30571
30572
30573
30574
30575
30576
30577
30578
30579
30580
30581
30582
30583
30584
30585
30586
30587
30588
30589
30590
30591
30592
30593
30594
30595
30596
30597
30598
30599
30600
30601
30602
30603
30604
30605
30606
30607
30608
30609
30610
30611
30612
30613
30614
30615
30616
30617
30618
30619
30620
30621
30622
30623
30624
30625
30626
30627
30628
30629
30630
30631
30632
30633
30634
30635
30636
30637
30638
30639
30640
30641
30642
30643
30644
30645
30646
30647
30648
30649
30650
30651
30652
30653
30654
30655
30656
30657
30658
30659
30660
30661
30662
30663
30664
30665
30666
30667
30668
30669
30670
30671
30672
30673
30674
30675
30676
30677
30678
30679
30680
30681
30682
30683
30684
30685
30686
30687
30688
30689
30690
30691
30692
30693
30694
30695
30696
30697
30698
30699
30700
30701
30702
30703
30704
30705
30706
30707
30708
30709
30710
30711
30712
30713
30714
30715
30716
30717
30718
30719
30720
30721
30722
30723
30724
30725
30726
30727
30728
30729
30730
30731
30732
30733
30734
30735
30736
30737
30738
30739
30740
30741
30742
30743
30744
30745
30746
30747
30748
30749
30750
30751
30752
30753
30754
30755
30756
30757
30758
30759
30760
30761
30762
30763
30764
30765
30766
30767
30768
30769
30770
30771
30772
30773
30774
30775
30776
30777
30778
30779
30780
30781
30782
30783
30784
30785
30786
30787
30788
30789
30790
30791
30792
30793
30794
30795
30796
30797
30798
30799
30800
30801
30802
30803
30804
30805
30806
30807
30808
30809
30810
30811
30812
30813
30814
30815
30816
30817
30818
30819
30820
30821
30822
30823
30824
30825
30826
30827
30828
30829
30830
30831
30832
30833
30834
30835
30836
30837
30838
30839
30840
30841
30842
30843
30844
30845
30846
30847
30848
30849
30850
30851
30852
30853
30854
30855
30856
30857
30858
30859
30860
30861
30862
30863
30864
30865
30866
30867
30868
30869
30870
30871
30872
30873
30874
30875
30876
30877
30878
30879
30880
30881
30882
30883
30884
30885
30886
30887
30888
30889
30890
30891
30892
30893
30894
30895
30896
30897
30898
30899
30900
30901
30902
30903
30904
30905
30906
30907
30908
30909
30910
30911
30912
30913
30914
30915
30916
30917
30918
30919
30920
30921
30922
30923
30924
30925
30926
30927
30928
30929
30930
30931
30932
30933
30934
30935
30936
30937
30938
30939
30940
30941
30942
30943
30944
30945
30946
30947
30948
30949
30950
30951
30952
30953
30954
30955
30956
30957
30958
30959
30960
30961
30962
30963
30964
30965
30966
30967
30968
30969
30970
30971
30972
30973
30974
30975
30976
30977
30978
30979
30980
30981
30982
30983
30984
30985
30986
30987
30988
30989
30990
30991
30992
30993
30994
30995
30996
30997
30998
30999
31000
31001
31002
31003
31004
31005
31006
31007
31008
31009
31010
31011
31012
31013
31014
31015
31016
31017
31018
31019
31020
31021
31022
31023
31024
31025
31026
31027
31028
31029
31030
31031
31032
31033
31034
31035
31036
31037
31038
31039
31040
31041
31042
31043
31044
31045
31046
31047
31048
31049
31050
31051
31052
31053
31054
31055
31056
31057
31058
31059
31060
31061
31062
31063
31064
31065
31066
31067
31068
31069
31070
31071
31072
31073
31074
31075
31076
31077
31078
31079
31080
31081
31082
31083
31084
31085
31086
31087
31088
31089
31090
31091
31092
31093
31094
31095
31096
31097
31098
31099
31100
31101
31102
31103
31104
31105
31106
31107
31108
31109
31110
31111
31112
31113
31114
31115
31116
31117
31118
31119
31120
31121
31122
31123
31124
31125
31126
31127
31128
31129
31130
31131
31132
31133
31134
31135
31136
31137
31138
31139
31140
31141
31142
31143
31144
31145
31146
31147
31148
31149
31150
31151
31152
31153
31154
31155
31156
31157
31158
31159
31160
31161
31162
31163
31164
31165
31166
31167
31168
31169
31170
31171
31172
31173
31174
31175
31176
31177
31178
31179
31180
31181
31182
31183
31184
31185
31186
31187
31188
31189
31190
31191
31192
31193
31194
31195
31196
31197
31198
31199
31200
31201
31202
31203
31204
31205
31206
31207
31208
31209
31210
31211
31212
31213
31214
31215
31216
31217
31218
31219
31220
31221
31222
31223
31224
31225
31226
31227
31228
31229
31230
31231
31232
31233
31234
31235
31236
31237
31238
31239
31240
31241
31242
31243
31244
31245
31246
31247
31248
31249
31250
31251
31252
31253
31254
31255
31256
31257
31258
31259
31260
31261
31262
31263
31264
31265
31266
31267
31268
31269
31270
31271
31272
31273
31274
31275
31276
31277
31278
31279
31280
31281
31282
31283
31284
31285
31286
31287
31288
31289
31290
31291
31292
31293
31294
31295
31296
31297
31298
31299
31300
31301
31302
31303
31304
31305
31306
31307
31308
31309
31310
31311
31312
31313
31314
31315
31316
31317
31318
31319
31320
31321
31322
31323
31324
31325
31326
31327
31328
31329
31330
31331
31332
31333
31334
31335
31336
31337
31338
31339
31340
31341
31342
31343
31344
31345
31346
31347
31348
31349
31350
31351
31352
31353
31354
31355
31356
31357
31358
31359
31360
31361
31362
31363
31364
31365
31366
31367
31368
31369
31370
31371
31372
31373
31374
31375
31376
31377
31378
31379
31380
31381
31382
31383
31384
31385
31386
31387
31388
31389
31390
31391
31392
31393
31394
31395
31396
31397
31398
31399
31400
31401
31402
31403
31404
31405
31406
31407
31408
31409
31410
31411
31412
31413
31414
31415
31416
31417
31418
31419
31420
31421
31422
31423
31424
31425
31426
31427
31428
31429
31430
31431
31432
31433
31434
31435
31436
31437
31438
31439
31440
31441
31442
31443
31444
31445
31446
31447
31448
31449
31450
31451
31452
31453
31454
31455
31456
31457
31458
31459
31460
31461
31462
31463
31464
31465
31466
31467
31468
31469
31470
31471
31472
31473
31474
31475
31476
31477
31478
31479
31480
31481
31482
31483
31484
31485
31486
31487
31488
31489
31490
31491
31492
31493
31494
31495
31496
31497
31498
31499
31500
31501
31502
31503
31504
31505
31506
31507
31508
31509
31510
31511
31512
31513
31514
31515
31516
31517
31518
31519
31520
31521
31522
31523
31524
31525
31526
31527
31528
31529
31530
31531
31532
31533
31534
31535
31536
31537
31538
31539
31540
31541
31542
31543
31544
31545
31546
31547
31548
31549
31550
31551
31552
31553
31554
31555
31556
31557
31558
31559
31560
31561
31562
31563
31564
31565
31566
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591
31592
31593
31594
31595
31596
31597
31598
31599
31600
31601
31602
31603
31604
31605
31606
31607
31608
31609
31610
31611
31612
31613
31614
31615
31616
31617
31618
31619
31620
31621
31622
31623
31624
31625
31626
31627
31628
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641
31642
31643
31644
31645
31646
31647
31648
31649
31650
31651
31652
31653
31654
31655
31656
31657
31658
31659
31660
31661
31662
31663
31664
31665
31666
31667
31668
31669
31670
31671
31672
31673
31674
31675
31676
31677
31678
31679
31680
31681
31682
31683
31684
31685
31686
31687
31688
31689
31690
31691
31692
31693
31694
31695
31696
31697
31698
31699
31700
31701
31702
31703
31704
31705
31706
31707
31708
31709
31710
31711
31712
31713
31714
31715
31716
31717
31718
31719
31720
31721
31722
31723
31724
31725
31726
31727
31728
31729
31730
31731
31732
31733
31734
31735
31736
31737
31738
31739
31740
31741
31742
31743
31744
31745
31746
31747
31748
31749
31750
31751
31752
31753
31754
31755
31756
31757
31758
31759
31760
31761
31762
31763
31764
31765
31766
31767
31768
31769
31770
31771
31772
31773
31774
31775
31776
31777
31778
31779
31780
31781
31782
31783
31784
31785
31786
31787
31788
31789
31790
31791
31792
31793
31794
31795
31796
31797
31798
31799
31800
31801
31802
31803
31804
31805
31806
31807
31808
31809
31810
31811
31812
31813
31814
31815
31816
31817
31818
31819
31820
31821
31822
31823
31824
31825
31826
31827
31828
31829
31830
31831
31832
31833
31834
31835
31836
31837
31838
31839
31840
31841
31842
31843
31844
31845
31846
31847
31848
31849
31850
31851
31852
31853
31854
31855
31856
31857
31858
31859
31860
31861
31862
31863
31864
31865
31866
31867
31868
31869
31870
31871
31872
31873
31874
31875
31876
31877
31878
31879
31880
31881
31882
31883
31884
31885
31886
31887
31888
31889
31890
31891
31892
31893
31894
31895
31896
31897
31898
31899
31900
31901
31902
31903
31904
31905
31906
31907
31908
31909
31910
31911
31912
31913
31914
31915
31916
31917
31918
31919
31920
31921
31922
31923
31924
31925
31926
31927
31928
31929
31930
31931
31932
31933
31934
31935
31936
31937
31938
31939
31940
31941
31942
31943
31944
31945
31946
31947
31948
31949
31950
31951
31952
31953
31954
31955
31956
31957
31958
31959
31960
31961
31962
31963
31964
31965
31966
31967
31968
31969
31970
31971
31972
31973
31974
31975
31976
31977
31978
31979
31980
31981
31982
31983
31984
31985
31986
31987
31988
31989
31990
31991
31992
31993
31994
31995
31996
31997
31998
31999
32000
32001
32002
32003
32004
32005
32006
32007
32008
32009
32010
32011
32012
32013
32014
32015
32016
32017
32018
32019
32020
32021
32022
32023
32024
32025
32026
32027
32028
32029
32030
32031
32032
32033
32034
32035
32036
32037
32038
32039
32040
32041
32042
32043
32044
32045
32046
32047
32048
32049
32050
32051
32052
32053
32054
32055
32056
32057
32058
32059
32060
32061
32062
32063
32064
32065
32066
32067
32068
32069
32070
32071
32072
32073
32074
32075
32076
32077
32078
32079
32080
32081
32082
32083
32084
32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
32097
32098
32099
32100
32101
32102
32103
32104
32105
32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
32118
32119
32120
32121
32122
32123
32124
32125
32126
32127
32128
32129
32130
32131
32132
32133
32134
32135
32136
32137
32138
32139
32140
32141
32142
32143
32144
32145
32146
32147
32148
32149
32150
32151
32152
32153
32154
32155
32156
32157
32158
32159
32160
32161
32162
32163
32164
32165
32166
32167
32168
32169
32170
32171
32172
32173
32174
32175
32176
32177
32178
32179
32180
32181
32182
32183
32184
32185
32186
32187
32188
32189
32190
32191
32192
32193
32194
32195
32196
32197
32198
32199
32200
32201
32202
32203
32204
32205
32206
32207
32208
32209
32210
32211
32212
32213
32214
32215
32216
32217
32218
32219
32220
32221
32222
32223
32224
32225
32226
32227
32228
32229
32230
32231
32232
32233
32234
32235
32236
32237
32238
32239
32240
32241
32242
32243
32244
32245
32246
32247
32248
32249
32250
32251
32252
32253
32254
32255
32256
32257
32258
32259
32260
32261
32262
32263
32264
32265
32266
32267
32268
32269
32270
32271
32272
32273
32274
32275
32276
32277
32278
32279
32280
32281
32282
32283
32284
32285
32286
32287
32288
32289
32290
32291
32292
32293
32294
32295
32296
32297
32298
32299
32300
32301
32302
32303
32304
32305
32306
32307
32308
32309
32310
32311
32312
32313
32314
32315
32316
32317
32318
32319
32320
32321
32322
32323
32324
32325
32326
32327
32328
32329
32330
32331
32332
32333
32334
32335
32336
32337
32338
32339
32340
32341
32342
32343
32344
32345
32346
32347
32348
32349
32350
32351
32352
32353
32354
32355
32356
32357
32358
32359
32360
32361
32362
32363
32364
32365
32366
32367
32368
32369
32370
32371
32372
32373
32374
32375
32376
32377
32378
32379
32380
32381
32382
32383
32384
32385
32386
32387
32388
32389
32390
32391
32392
32393
32394
32395
32396
32397
32398
32399
32400
32401
32402
32403
32404
32405
32406
32407
32408
32409
32410
32411
32412
32413
32414
32415
32416
32417
32418
32419
32420
32421
32422
32423
32424
32425
32426
32427
32428
32429
32430
32431
32432
32433
32434
32435
32436
32437
32438
32439
32440
32441
32442
32443
32444
32445
32446
32447
32448
32449
32450
32451
32452
32453
32454
32455
32456
32457
32458
32459
32460
32461
32462
32463
32464
32465
32466
32467
32468
32469
32470
32471
32472
32473
32474
32475
32476
32477
32478
32479
32480
32481
32482
32483
32484
32485
32486
32487
32488
32489
32490
32491
32492
32493
32494
32495
32496
32497
32498
32499
32500
32501
32502
32503
32504
32505
32506
32507
32508
32509
32510
32511
32512
32513
32514
32515
32516
32517
32518
32519
32520
32521
32522
32523
32524
32525
32526
32527
32528
32529
32530
32531
32532
32533
32534
32535
32536
32537
32538
32539
32540
32541
32542
32543
32544
32545
32546
32547
32548
32549
32550
32551
32552
32553
32554
32555
32556
32557
32558
32559
32560
32561
32562
32563
32564
32565
32566
32567
32568
32569
32570
32571
32572
32573
32574
32575
32576
32577
32578
32579
32580
32581
32582
32583
32584
32585
32586
32587
32588
32589
32590
32591
32592
32593
32594
32595
32596
32597
32598
32599
32600
32601
32602
32603
32604
32605
32606
32607
32608
32609
32610
32611
32612
32613
32614
32615
32616
32617
32618
32619
32620
32621
32622
32623
32624
32625
32626
32627
32628
32629
32630
32631
32632
32633
32634
32635
32636
32637
32638
32639
32640
32641
32642
32643
32644
32645
32646
32647
32648
32649
32650
32651
32652
32653
32654
32655
32656
32657
32658
32659
32660
32661
32662
32663
32664
32665
32666
32667
32668
32669
32670
32671
32672
32673
32674
32675
32676
32677
32678
32679
32680
32681
32682
32683
32684
32685
32686
32687
32688
32689
32690
32691
32692
32693
32694
32695
32696
32697
32698
32699
32700
32701
32702
32703
32704
32705
32706
32707
32708
32709
32710
32711
32712
32713
32714
32715
32716
32717
32718
32719
32720
32721
32722
32723
32724
32725
32726
32727
32728
32729
32730
32731
32732
32733
32734
32735
32736
32737
32738
32739
32740
32741
32742
32743
32744
32745
32746
32747
32748
32749
32750
32751
32752
32753
32754
32755
32756
32757
32758
32759
32760
32761
32762
32763
32764
32765
32766
32767
32768
32769
32770
32771
32772
32773
32774
32775
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800
32801
32802
32803
32804
32805
32806
32807
32808
32809
32810
32811
32812
32813
32814
32815
32816
32817
32818
32819
32820
32821
32822
32823
32824
32825
32826
32827
32828
32829
32830
32831
32832
32833
32834
32835
32836
32837
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850
32851
32852
32853
32854
32855
32856
32857
32858
32859
32860
32861
32862
32863
32864
32865
32866
32867
32868
32869
32870
32871
32872
32873
32874
32875
32876
32877
32878
32879
32880
32881
32882
32883
32884
32885
32886
32887
32888
32889
32890
32891
32892
32893
32894
32895
32896
32897
32898
32899
32900
32901
32902
32903
32904
32905
32906
32907
32908
32909
32910
32911
32912
32913
32914
32915
32916
32917
32918
32919
32920
32921
32922
32923
32924
32925
32926
32927
32928
32929
32930
32931
32932
32933
32934
32935
32936
32937
32938
32939
32940
32941
32942
32943
32944
32945
32946
32947
32948
32949
32950
32951
32952
32953
32954
32955
32956
32957
32958
32959
32960
32961
32962
32963
32964
32965
32966
32967
32968
32969
32970
32971
32972
32973
32974
32975
32976
32977
32978
32979
32980
32981
32982
32983
32984
32985
32986
32987
32988
32989
32990
32991
32992
32993
32994
32995
32996
32997
32998
32999
33000
33001
33002
33003
33004
33005
33006
33007
33008
33009
33010
33011
33012
33013
33014
33015
33016
33017
33018
33019
33020
33021
33022
33023
33024
33025
33026
33027
33028
33029
33030
33031
33032
33033
33034
33035
33036
33037
33038
33039
33040
33041
33042
33043
33044
33045
33046
33047
33048
33049
33050
33051
33052
33053
33054
33055
33056
33057
33058
33059
33060
33061
33062
33063
33064
33065
33066
33067
33068
33069
33070
33071
33072
33073
33074
33075
33076
33077
33078
33079
33080
33081
33082
33083
33084
33085
33086
33087
33088
33089
33090
33091
33092
33093
33094
33095
33096
33097
33098
33099
33100
33101
33102
33103
33104
33105
33106
33107
33108
33109
33110
33111
33112
33113
33114
33115
33116
33117
33118
33119
33120
33121
33122
33123
33124
33125
33126
33127
33128
33129
33130
33131
33132
33133
33134
33135
33136
33137
33138
33139
33140
33141
33142
33143
33144
33145
33146
33147
33148
33149
33150
33151
33152
33153
33154
33155
33156
33157
33158
33159
33160
33161
33162
33163
33164
33165
33166
33167
33168
33169
33170
33171
33172
33173
33174
33175
33176
33177
33178
33179
33180
33181
33182
33183
33184
33185
33186
33187
33188
33189
33190
33191
33192
33193
33194
33195
33196
33197
33198
33199
33200
33201
33202
33203
33204
33205
33206
33207
33208
33209
33210
33211
33212
33213
33214
33215
33216
33217
33218
33219
33220
33221
33222
33223
33224
33225
33226
33227
33228
33229
33230
33231
33232
33233
33234
33235
33236
33237
33238
33239
33240
33241
33242
33243
33244
33245
33246
33247
33248
33249
33250
33251
33252
33253
33254
33255
33256
33257
33258
33259
33260
33261
33262
33263
33264
33265
33266
33267
33268
33269
33270
33271
33272
33273
33274
33275
33276
33277
33278
33279
33280
33281
33282
33283
33284
33285
33286
33287
33288
33289
33290
33291
33292
33293
33294
33295
33296
33297
33298
33299
33300
33301
33302
33303
33304
33305
33306
33307
33308
33309
33310
33311
33312
33313
33314
33315
33316
33317
33318
33319
33320
33321
33322
33323
33324
33325
33326
33327
33328
33329
33330
33331
33332
33333
33334
33335
33336
33337
33338
33339
33340
33341
33342
33343
33344
33345
33346
33347
33348
33349
33350
33351
33352
33353
33354
33355
33356
33357
33358
33359
33360
33361
33362
33363
33364
33365
33366
33367
33368
33369
33370
33371
33372
33373
33374
33375
33376
33377
33378
33379
33380
33381
33382
33383
33384
33385
33386
33387
33388
33389
33390
33391
33392
33393
33394
33395
33396
33397
33398
33399
33400
33401
33402
33403
33404
33405
33406
33407
33408
33409
33410
33411
33412
33413
33414
33415
33416
33417
33418
33419
33420
33421
33422
33423
33424
33425
33426
33427
33428
33429
33430
33431
33432
33433
33434
33435
33436
33437
33438
33439
33440
33441
33442
33443
33444
33445
33446
33447
33448
33449
33450
33451
33452
33453
33454
33455
33456
33457
33458
33459
33460
33461
33462
33463
33464
33465
33466
33467
33468
33469
33470
33471
33472
33473
33474
33475
33476
33477
33478
33479
33480
33481
33482
33483
33484
33485
33486
33487
33488
33489
33490
33491
33492
33493
33494
33495
33496
33497
33498
33499
33500
33501
33502
33503
33504
33505
33506
33507
33508
33509
33510
33511
33512
33513
33514
33515
33516
33517
33518
33519
33520
33521
33522
33523
33524
33525
33526
33527
33528
33529
33530
33531
33532
33533
33534
33535
33536
33537
33538
33539
33540
33541
33542
33543
33544
33545
33546
33547
33548
33549
33550
33551
33552
33553
33554
33555
33556
33557
33558
33559
33560
33561
33562
33563
33564
33565
33566
33567
33568
33569
33570
33571
33572
33573
33574
33575
33576
33577
33578
33579
33580
33581
33582
33583
33584
33585
33586
33587
33588
33589
33590
33591
33592
33593
33594
33595
33596
33597
33598
33599
33600
33601
33602
33603
33604
33605
33606
33607
33608
33609
33610
33611
33612
33613
33614
33615
33616
33617
33618
33619
33620
33621
33622
33623
33624
33625
33626
33627
33628
33629
33630
33631
33632
33633
33634
33635
33636
33637
33638
33639
33640
33641
33642
33643
33644
33645
33646
33647
33648
33649
33650
33651
33652
33653
33654
33655
33656
33657
33658
33659
33660
33661
33662
33663
33664
33665
33666
33667
33668
33669
33670
33671
33672
33673
33674
33675
33676
33677
33678
33679
33680
33681
33682
33683
33684
33685
33686
33687
33688
33689
33690
33691
33692
33693
33694
33695
33696
33697
33698
33699
33700
33701
33702
33703
33704
33705
33706
33707
33708
33709
33710
33711
33712
33713
33714
33715
33716
33717
33718
33719
33720
33721
33722
33723
33724
33725
33726
33727
33728
33729
33730
33731
33732
33733
33734
33735
33736
33737
33738
33739
33740
33741
33742
33743
33744
33745
33746
33747
33748
33749
33750
33751
33752
33753
33754
33755
33756
33757
33758
33759
33760
33761
33762
33763
33764
33765
33766
33767
33768
33769
33770
33771
33772
33773
33774
33775
33776
33777
33778
33779
33780
33781
33782
33783
33784
33785
33786
33787
33788
33789
33790
33791
33792
33793
33794
33795
33796
33797
33798
33799
33800
33801
33802
33803
33804
33805
33806
33807
33808
33809
33810
33811
33812
33813
33814
33815
33816
33817
33818
33819
33820
33821
33822
33823
33824
33825
33826
33827
33828
33829
33830
33831
33832
33833
33834
33835
33836
33837
33838
33839
33840
33841
33842
33843
33844
33845
33846
33847
33848
33849
33850
33851
33852
33853
33854
33855
33856
33857
33858
33859
33860
33861
33862
33863
33864
33865
33866
33867
33868
33869
33870
33871
33872
33873
33874
33875
33876
33877
33878
33879
33880
33881
33882
33883
33884
33885
33886
33887
33888
33889
33890
33891
33892
33893
33894
33895
33896
33897
33898
33899
33900
33901
33902
33903
33904
33905
33906
33907
33908
33909
33910
33911
33912
33913
33914
33915
33916
33917
33918
33919
33920
33921
33922
33923
33924
33925
33926
33927
33928
33929
33930
33931
33932
33933
33934
33935
33936
33937
33938
33939
33940
33941
33942
33943
33944
33945
33946
33947
33948
33949
33950
33951
33952
33953
33954
33955
33956
33957
33958
33959
33960
33961
33962
33963
33964
33965
33966
33967
33968
33969
33970
33971
33972
33973
33974
33975
33976
33977
33978
33979
33980
33981
33982
33983
33984
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009
34010
34011
34012
34013
34014
34015
34016
34017
34018
34019
34020
34021
34022
34023
34024
34025
34026
34027
34028
34029
34030
34031
34032
34033
34034
34035
34036
34037
34038
34039
34040
34041
34042
34043
34044
34045
34046
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059
34060
34061
34062
34063
34064
34065
34066
34067
34068
34069
34070
34071
34072
34073
34074
34075
34076
34077
34078
34079
34080
34081
34082
34083
34084
34085
34086
34087
34088
34089
34090
34091
34092
34093
34094
34095
34096
34097
34098
34099
34100
34101
34102
34103
34104
34105
34106
34107
34108
34109
34110
34111
34112
34113
34114
34115
34116
34117
34118
34119
34120
34121
34122
34123
34124
34125
34126
34127
34128
34129
34130
34131
34132
34133
34134
34135
34136
34137
34138
34139
34140
34141
34142
34143
34144
34145
34146
34147
34148
34149
34150
34151
34152
34153
34154
34155
34156
34157
34158
34159
34160
34161
34162
34163
34164
34165
34166
34167
34168
34169
34170
34171
34172
34173
34174
34175
34176
34177
34178
34179
34180
34181
34182
34183
34184
34185
34186
34187
34188
34189
34190
34191
34192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
34205
34206
34207
34208
34209
34210
34211
34212
34213
34214
34215
34216
34217
34218
34219
34220
34221
34222
34223
34224
34225
34226
34227
34228
34229
34230
34231
34232
34233
34234
34235
34236
34237
34238
34239
34240
34241
34242
34243
34244
34245
34246
34247
34248
34249
34250
34251
34252
34253
34254
34255
34256
34257
34258
34259
34260
34261
34262
34263
34264
34265
34266
34267
34268
34269
34270
34271
34272
34273
34274
34275
34276
34277
34278
34279
34280
34281
34282
34283
34284
34285
34286
34287
34288
34289
34290
34291
34292
34293
34294
34295
34296
34297
34298
34299
34300
34301
34302
34303
34304
34305
34306
34307
34308
34309
34310
34311
34312
34313
34314
34315
34316
34317
34318
34319
34320
34321
34322
34323
34324
34325
34326
34327
34328
34329
34330
34331
34332
34333
34334
34335
34336
34337
34338
34339
34340
34341
34342
34343
34344
34345
34346
34347
34348
34349
34350
34351
34352
34353
34354
34355
34356
34357
34358
34359
34360
34361
34362
34363
34364
34365
34366
34367
34368
34369
34370
34371
34372
34373
34374
34375
34376
34377
34378
34379
34380
34381
34382
34383
34384
34385
34386
34387
34388
34389
34390
34391
34392
34393
34394
34395
34396
34397
34398
34399
34400
34401
34402
34403
34404
34405
34406
34407
34408
34409
34410
34411
34412
34413
34414
34415
34416
34417
34418
34419
34420
34421
34422
34423
34424
34425
34426
34427
34428
34429
34430
34431
34432
34433
34434
34435
34436
34437
34438
34439
34440
34441
34442
34443
34444
34445
34446
34447
34448
34449
34450
34451
34452
34453
34454
34455
34456
34457
34458
34459
34460
34461
34462
34463
34464
34465
34466
34467
34468
34469
34470
34471
34472
34473
34474
34475
34476
34477
34478
34479
34480
34481
34482
34483
34484
34485
34486
34487
34488
34489
34490
34491
34492
34493
34494
34495
34496
34497
34498
34499
34500
34501
34502
34503
34504
34505
34506
34507
34508
34509
34510
34511
34512
34513
34514
34515
34516
34517
34518
34519
34520
34521
34522
34523
34524
34525
34526
34527
34528
34529
34530
34531
34532
34533
34534
34535
34536
34537
34538
34539
34540
34541
34542
34543
34544
34545
34546
34547
34548
34549
34550
34551
34552
34553
34554
34555
34556
34557
34558
34559
34560
34561
34562
34563
34564
34565
34566
34567
34568
34569
34570
34571
34572
34573
34574
34575
34576
34577
34578
34579
34580
34581
34582
34583
34584
34585
34586
34587
34588
34589
34590
34591
34592
34593
34594
34595
34596
34597
34598
34599
34600
34601
34602
34603
34604
34605
34606
34607
34608
34609
34610
34611
34612
34613
34614
34615
34616
34617
34618
34619
34620
34621
34622
34623
34624
34625
34626
34627
34628
34629
34630
34631
34632
34633
34634
34635
34636
34637
34638
34639
34640
34641
34642
34643
34644
34645
34646
34647
34648
34649
34650
34651
34652
34653
34654
34655
34656
34657
34658
34659
34660
34661
34662
34663
34664
34665
34666
34667
34668
34669
34670
34671
34672
34673
34674
34675
34676
34677
34678
34679
34680
34681
34682
34683
34684
34685
34686
34687
34688
34689
34690
34691
34692
34693
34694
34695
34696
34697
34698
34699
34700
34701
34702
34703
34704
34705
34706
34707
34708
34709
34710
34711
34712
34713
34714
34715
34716
34717
34718
34719
34720
34721
34722
34723
34724
34725
34726
34727
34728
34729
34730
34731
34732
34733
34734
34735
34736
34737
34738
34739
34740
34741
34742
34743
34744
34745
34746
34747
34748
34749
34750
34751
34752
34753
34754
34755
34756
34757
34758
34759
34760
34761
34762
34763
34764
34765
34766
34767
34768
34769
34770
34771
34772
34773
34774
34775
34776
34777
34778
34779
34780
34781
34782
34783
34784
34785
34786
34787
34788
34789
34790
34791
34792
34793
34794
34795
34796
34797
34798
34799
34800
34801
34802
34803
34804
34805
34806
34807
34808
34809
34810
34811
34812
34813
34814
34815
34816
34817
34818
34819
34820
34821
34822
34823
34824
34825
34826
34827
34828
34829
34830
34831
34832
34833
34834
34835
34836
34837
34838
34839
34840
34841
34842
34843
34844
34845
34846
34847
34848
34849
34850
34851
34852
34853
34854
34855
34856
34857
34858
34859
34860
34861
34862
34863
34864
34865
34866
34867
34868
34869
34870
34871
34872
34873
34874
34875
34876
34877
34878
34879
34880
34881
34882
34883
34884
34885
34886
34887
34888
34889
34890
34891
34892
34893
34894
34895
34896
34897
34898
34899
34900
34901
34902
34903
34904
34905
34906
34907
34908
34909
34910
34911
34912
34913
34914
34915
34916
34917
34918
34919
34920
34921
34922
34923
34924
34925
34926
34927
34928
34929
34930
34931
34932
34933
34934
34935
34936
34937
34938
34939
34940
34941
34942
34943
34944
34945
34946
34947
34948
34949
34950
34951
34952
34953
34954
34955
34956
34957
34958
34959
34960
34961
34962
34963
34964
34965
34966
34967
34968
34969
34970
34971
34972
34973
34974
34975
34976
34977
34978
34979
34980
34981
34982
34983
34984
34985
34986
34987
34988
34989
34990
34991
34992
34993
34994
34995
34996
34997
34998
34999
35000
35001
35002
35003
35004
35005
35006
35007
35008
35009
35010
35011
35012
35013
35014
35015
35016
35017
35018
35019
35020
35021
35022
35023
35024
35025
35026
35027
35028
35029
35030
35031
35032
35033
35034
35035
35036
35037
35038
35039
35040
35041
35042
35043
35044
35045
35046
35047
35048
35049
35050
35051
35052
35053
35054
35055
35056
35057
35058
35059
35060
35061
35062
35063
35064
35065
35066
35067
35068
35069
35070
35071
35072
35073
35074
35075
35076
35077
35078
35079
35080
35081
35082
35083
35084
35085
35086
35087
35088
35089
35090
35091
35092
35093
35094
35095
35096
35097
35098
35099
35100
35101
35102
35103
35104
35105
35106
35107
35108
35109
35110
35111
35112
35113
35114
35115
35116
35117
35118
35119
35120
35121
35122
35123
35124
35125
35126
35127
35128
35129
35130
35131
35132
35133
35134
35135
35136
35137
35138
35139
35140
35141
35142
35143
35144
35145
35146
35147
35148
35149
35150
35151
35152
35153
35154
35155
35156
35157
35158
35159
35160
35161
35162
35163
35164
35165
35166
35167
35168
35169
35170
35171
35172
35173
35174
35175
35176
35177
35178
35179
35180
35181
35182
35183
35184
35185
35186
35187
35188
35189
35190
35191
35192
35193
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218
35219
35220
35221
35222
35223
35224
35225
35226
35227
35228
35229
35230
35231
35232
35233
35234
35235
35236
35237
35238
35239
35240
35241
35242
35243
35244
35245
35246
35247
35248
35249
35250
35251
35252
35253
35254
35255
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268
35269
35270
35271
35272
35273
35274
35275
35276
35277
35278
35279
35280
35281
35282
35283
35284
35285
35286
35287
35288
35289
35290
35291
35292
35293
35294
35295
35296
35297
35298
35299
35300
35301
35302
35303
35304
35305
35306
35307
35308
35309
35310
35311
35312
35313
35314
35315
35316
35317
35318
35319
35320
35321
35322
35323
35324
35325
35326
35327
35328
35329
35330
35331
35332
35333
35334
35335
35336
35337
35338
35339
35340
35341
35342
35343
35344
35345
35346
35347
35348
35349
35350
35351
35352
35353
35354
35355
35356
35357
35358
35359
35360
35361
35362
35363
35364
35365
35366
35367
35368
35369
35370
35371
35372
35373
35374
35375
35376
35377
35378
35379
35380
35381
35382
35383
35384
35385
35386
35387
35388
35389
35390
35391
35392
35393
35394
35395
35396
35397
35398
35399
35400
35401
35402
35403
35404
35405
35406
35407
35408
35409
35410
35411
35412
35413
35414
35415
35416
35417
35418
35419
35420
35421
35422
35423
35424
35425
35426
35427
35428
35429
35430
35431
35432
35433
35434
35435
35436
35437
35438
35439
35440
35441
35442
35443
35444
35445
35446
35447
35448
35449
35450
35451
35452
35453
35454
35455
35456
35457
35458
35459
35460
35461
35462
35463
35464
35465
35466
35467
35468
35469
35470
35471
35472
35473
35474
35475
35476
35477
35478
35479
35480
35481
35482
35483
35484
35485
35486
35487
35488
35489
35490
35491
35492
35493
35494
35495
35496
35497
35498
35499
35500
35501
35502
35503
35504
35505
35506
35507
35508
35509
35510
35511
35512
35513
35514
35515
35516
35517
35518
35519
35520
35521
35522
35523
35524
35525
35526
35527
35528
35529
35530
35531
35532
35533
35534
35535
35536
35537
35538
35539
35540
35541
35542
35543
35544
35545
35546
35547
35548
35549
35550
35551
35552
35553
35554
35555
35556
35557
35558
35559
35560
35561
35562
35563
35564
35565
35566
35567
35568
35569
35570
35571
35572
35573
35574
35575
35576
35577
35578
35579
35580
35581
35582
35583
35584
35585
35586
35587
35588
35589
35590
35591
35592
35593
35594
35595
35596
35597
35598
35599
35600
35601
35602
35603
35604
35605
35606
35607
35608
35609
35610
35611
35612
35613
35614
35615
35616
35617
35618
35619
35620
35621
35622
35623
35624
35625
35626
35627
35628
35629
35630
35631
35632
35633
35634
35635
35636
35637
35638
35639
35640
35641
35642
35643
35644
35645
35646
35647
35648
35649
35650
35651
35652
35653
35654
35655
35656
35657
35658
35659
35660
35661
35662
35663
35664
35665
35666
35667
35668
35669
35670
35671
35672
35673
35674
35675
35676
35677
35678
35679
35680
35681
35682
35683
35684
35685
35686
35687
35688
35689
35690
35691
35692
35693
35694
35695
35696
35697
35698
35699
35700
35701
35702
35703
35704
35705
35706
35707
35708
35709
35710
35711
35712
35713
35714
35715
35716
35717
35718
35719
35720
35721
35722
35723
35724
35725
35726
35727
35728
35729
35730
35731
35732
35733
35734
35735
35736
35737
35738
35739
35740
35741
35742
35743
35744
35745
35746
35747
35748
35749
35750
35751
35752
35753
35754
35755
35756
35757
35758
35759
35760
35761
35762
35763
35764
35765
35766
35767
35768
35769
35770
35771
35772
35773
35774
35775
35776
35777
35778
35779
35780
35781
35782
35783
35784
35785
35786
35787
35788
35789
35790
35791
35792
35793
35794
35795
35796
35797
35798
35799
35800
35801
35802
35803
35804
35805
35806
35807
35808
35809
35810
35811
35812
35813
35814
35815
35816
35817
35818
35819
35820
35821
35822
35823
35824
35825
35826
35827
35828
35829
35830
35831
35832
35833
35834
35835
35836
35837
35838
35839
35840
35841
35842
35843
35844
35845
35846
35847
35848
35849
35850
35851
35852
35853
35854
35855
35856
35857
35858
35859
35860
35861
35862
35863
35864
35865
35866
35867
35868
35869
35870
35871
35872
35873
35874
35875
35876
35877
35878
35879
35880
35881
35882
35883
35884
35885
35886
35887
35888
35889
35890
35891
35892
35893
35894
35895
35896
35897
35898
35899
35900
35901
35902
35903
35904
35905
35906
35907
35908
35909
35910
35911
35912
35913
35914
35915
35916
35917
35918
35919
35920
35921
35922
35923
35924
35925
35926
35927
35928
35929
35930
35931
35932
35933
35934
35935
35936
35937
35938
35939
35940
35941
35942
35943
35944
35945
35946
35947
35948
35949
35950
35951
35952
35953
35954
35955
35956
35957
35958
35959
35960
35961
35962
35963
35964
35965
35966
35967
35968
35969
35970
35971
35972
35973
35974
35975
35976
35977
35978
35979
35980
35981
35982
35983
35984
35985
35986
35987
35988
35989
35990
35991
35992
35993
35994
35995
35996
35997
35998
35999
36000
36001
36002
36003
36004
36005
36006
36007
36008
36009
36010
36011
36012
36013
36014
36015
36016
36017
36018
36019
36020
36021
36022
36023
36024
36025
36026
36027
36028
36029
36030
36031
36032
36033
36034
36035
36036
36037
36038
36039
36040
36041
36042
36043
36044
36045
36046
36047
36048
36049
36050
36051
36052
36053
36054
36055
36056
36057
36058
36059
36060
36061
36062
36063
36064
36065
36066
36067
36068
36069
36070
36071
36072
36073
36074
36075
36076
36077
36078
36079
36080
36081
36082
36083
36084
36085
36086
36087
36088
36089
36090
36091
36092
36093
36094
36095
36096
36097
36098
36099
36100
36101
36102
36103
36104
36105
36106
36107
36108
36109
36110
36111
36112
36113
36114
36115
36116
36117
36118
36119
36120
36121
36122
36123
36124
36125
36126
36127
36128
36129
36130
36131
36132
36133
36134
36135
36136
36137
36138
36139
36140
36141
36142
36143
36144
36145
36146
36147
36148
36149
36150
36151
36152
36153
36154
36155
36156
36157
36158
36159
36160
36161
36162
36163
36164
36165
36166
36167
36168
36169
36170
36171
36172
36173
36174
36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
36185
36186
36187
36188
36189
36190
36191
36192
36193
36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
36204
36205
36206
36207
36208
36209
36210
36211
36212
36213
36214
36215
36216
36217
36218
36219
36220
36221
36222
36223
36224
36225
36226
36227
36228
36229
36230
36231
36232
36233
36234
36235
36236
36237
36238
36239
36240
36241
36242
36243
36244
36245
36246
36247
36248
36249
36250
36251
36252
36253
36254
36255
36256
36257
36258
36259
36260
36261
36262
36263
36264
36265
36266
36267
36268
36269
36270
36271
36272
36273
36274
36275
36276
36277
36278
36279
36280
36281
36282
36283
36284
36285
36286
36287
36288
36289
36290
36291
36292
36293
36294
36295
36296
36297
36298
36299
36300
36301
36302
36303
36304
36305
36306
36307
36308
36309
36310
36311
36312
36313
36314
36315
36316
36317
36318
36319
36320
36321
36322
36323
36324
36325
36326
36327
36328
36329
36330
36331
36332
36333
36334
36335
36336
36337
36338
36339
36340
36341
36342
36343
36344
36345
36346
36347
36348
36349
36350
36351
36352
36353
36354
36355
36356
36357
36358
36359
36360
36361
36362
36363
36364
36365
36366
36367
36368
36369
36370
36371
36372
36373
36374
36375
36376
36377
36378
36379
36380
36381
36382
36383
36384
36385
36386
36387
36388
36389
36390
36391
36392
36393
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418
36419
36420
36421
36422
36423
36424
36425
36426
36427
36428
36429
36430
36431
36432
36433
36434
36435
36436
36437
36438
36439
36440
36441
36442
36443
36444
36445
36446
36447
36448
36449
36450
36451
36452
36453
36454
36455
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468
36469
36470
36471
36472
36473
36474
36475
36476
36477
36478
36479
36480
36481
36482
36483
36484
36485
36486
36487
36488
36489
36490
36491
36492
36493
36494
36495
36496
36497
36498
36499
36500
36501
36502
36503
36504
36505
36506
36507
36508
36509
36510
36511
36512
36513
36514
36515
36516
36517
36518
36519
36520
36521
36522
36523
36524
36525
36526
36527
36528
36529
36530
36531
36532
36533
36534
36535
36536
36537
36538
36539
36540
36541
36542
36543
36544
36545
36546
36547
36548
36549
36550
36551
36552
36553
36554
36555
36556
36557
36558
36559
36560
36561
36562
36563
36564
36565
36566
36567
36568
36569
36570
36571
36572
36573
36574
36575
36576
36577
36578
36579
36580
36581
36582
36583
36584
36585
36586
36587
36588
36589
36590
36591
36592
36593
36594
36595
36596
36597
36598
36599
36600
36601
36602
36603
36604
36605
36606
36607
36608
36609
36610
36611
36612
36613
36614
36615
36616
36617
36618
36619
36620
36621
36622
36623
36624
36625
36626
36627
36628
36629
36630
36631
36632
36633
36634
36635
36636
36637
36638
36639
36640
36641
36642
36643
36644
36645
36646
36647
36648
36649
36650
36651
36652
36653
36654
36655
36656
36657
36658
36659
36660
36661
36662
36663
36664
36665
36666
36667
36668
36669
36670
36671
36672
36673
36674
36675
36676
36677
36678
36679
36680
36681
36682
36683
36684
36685
36686
36687
36688
36689
36690
36691
36692
36693
36694
36695
36696
36697
36698
36699
36700
36701
36702
36703
36704
36705
36706
36707
36708
36709
36710
36711
36712
36713
36714
36715
36716
36717
36718
36719
36720
36721
36722
36723
36724
36725
36726
36727
36728
36729
36730
36731
36732
36733
36734
36735
36736
36737
36738
36739
36740
36741
36742
36743
36744
36745
36746
36747
36748
36749
36750
36751
36752
36753
36754
36755
36756
36757
36758
36759
36760
36761
36762
36763
36764
36765
36766
36767
36768
36769
36770
36771
36772
36773
36774
36775
36776
36777
36778
36779
36780
36781
36782
36783
36784
36785
36786
36787
36788
36789
36790
36791
36792
36793
36794
36795
36796
36797
36798
36799
36800
36801
36802
36803
36804
36805
36806
36807
36808
36809
36810
36811
36812
36813
36814
36815
36816
36817
36818
36819
36820
36821
36822
36823
36824
36825
36826
36827
36828
36829
36830
36831
36832
36833
36834
36835
36836
36837
36838
36839
36840
36841
36842
36843
36844
36845
36846
36847
36848
36849
36850
36851
36852
36853
36854
36855
36856
36857
36858
36859
36860
36861
36862
36863
36864
36865
36866
36867
36868
36869
36870
36871
36872
36873
36874
36875
36876
36877
36878
36879
36880
36881
36882
36883
36884
36885
36886
36887
36888
36889
36890
36891
36892
36893
36894
36895
36896
36897
36898
36899
36900
36901
36902
36903
36904
36905
36906
36907
36908
36909
36910
36911
36912
36913
36914
36915
36916
36917
36918
36919
36920
36921
36922
36923
36924
36925
36926
36927
36928
36929
36930
36931
36932
36933
36934
36935
36936
36937
36938
36939
36940
36941
36942
36943
36944
36945
36946
36947
36948
36949
36950
36951
36952
36953
36954
36955
36956
36957
36958
36959
36960
36961
36962
36963
36964
36965
36966
36967
36968
36969
36970
36971
36972
36973
36974
36975
36976
36977
36978
36979
36980
36981
36982
36983
36984
36985
36986
36987
36988
36989
36990
36991
36992
36993
36994
36995
36996
36997
36998
36999
37000
37001
37002
37003
37004
37005
37006
37007
37008
37009
37010
37011
37012
37013
37014
37015
37016
37017
37018
37019
37020
37021
37022
37023
37024
37025
37026
37027
37028
37029
37030
37031
37032
37033
37034
37035
37036
37037
37038
37039
37040
37041
37042
37043
37044
37045
37046
37047
37048
37049
37050
37051
37052
37053
37054
37055
37056
37057
37058
37059
37060
37061
37062
37063
37064
37065
37066
37067
37068
37069
37070
37071
37072
37073
37074
37075
37076
37077
37078
37079
37080
37081
37082
37083
37084
37085
37086
37087
37088
37089
37090
37091
37092
37093
37094
37095
37096
37097
37098
37099
37100
37101
37102
37103
37104
37105
37106
37107
37108
37109
37110
37111
37112
37113
37114
37115
37116
37117
37118
37119
37120
37121
37122
37123
37124
37125
37126
37127
37128
37129
37130
37131
37132
37133
37134
37135
37136
37137
37138
37139
37140
37141
37142
37143
37144
37145
37146
37147
37148
37149
37150
37151
37152
37153
37154
37155
37156
37157
37158
37159
37160
37161
37162
37163
37164
37165
37166
37167
37168
37169
37170
37171
37172
37173
37174
37175
37176
37177
37178
37179
37180
37181
37182
37183
37184
37185
37186
37187
37188
37189
37190
37191
37192
37193
37194
37195
37196
37197
37198
37199
37200
37201
37202
37203
37204
37205
37206
37207
37208
37209
37210
37211
37212
37213
37214
37215
37216
37217
37218
37219
37220
37221
37222
37223
37224
37225
37226
37227
37228
37229
37230
37231
37232
37233
37234
37235
37236
37237
37238
37239
37240
37241
37242
37243
37244
37245
37246
37247
37248
37249
37250
37251
37252
37253
37254
37255
37256
37257
37258
37259
37260
37261
37262
37263
37264
37265
37266
37267
37268
37269
37270
37271
37272
37273
37274
37275
37276
37277
37278
37279
37280
37281
37282
37283
37284
37285
37286
37287
37288
37289
37290
37291
37292
37293
37294
37295
37296
37297
37298
37299
37300
37301
37302
37303
37304
37305
37306
37307
37308
37309
37310
37311
37312
37313
37314
37315
37316
37317
37318
37319
37320
37321
37322
37323
37324
37325
37326
37327
37328
37329
37330
37331
37332
37333
37334
37335
37336
37337
37338
37339
37340
37341
37342
37343
37344
37345
37346
37347
37348
37349
37350
37351
37352
37353
37354
37355
37356
37357
37358
37359
37360
37361
37362
37363
37364
37365
37366
37367
37368
37369
37370
37371
37372
37373
37374
37375
37376
37377
37378
37379
37380
37381
37382
37383
37384
37385
37386
37387
37388
37389
37390
37391
37392
37393
37394
37395
37396
37397
37398
37399
37400
37401
37402
37403
37404
37405
37406
37407
37408
37409
37410
37411
37412
37413
37414
37415
37416
37417
37418
37419
37420
37421
37422
37423
37424
37425
37426
37427
37428
37429
37430
37431
37432
37433
37434
37435
37436
37437
37438
37439
37440
37441
37442
37443
37444
37445
37446
37447
37448
37449
37450
37451
37452
37453
37454
37455
37456
37457
37458
37459
37460
37461
37462
37463
37464
37465
37466
37467
37468
37469
37470
37471
37472
37473
37474
37475
37476
37477
37478
37479
37480
37481
37482
37483
37484
37485
37486
37487
37488
37489
37490
37491
37492
37493
37494
37495
37496
37497
37498
37499
37500
37501
37502
37503
37504
37505
37506
37507
37508
37509
37510
37511
37512
37513
37514
37515
37516
37517
37518
37519
37520
37521
37522
37523
37524
37525
37526
37527
37528
37529
37530
37531
37532
37533
37534
37535
37536
37537
37538
37539
37540
37541
37542
37543
37544
37545
37546
37547
37548
37549
37550
37551
37552
37553
37554
37555
37556
37557
37558
37559
37560
37561
37562
37563
37564
37565
37566
37567
37568
37569
37570
37571
37572
37573
37574
37575
37576
37577
37578
37579
37580
37581
37582
37583
37584
37585
37586
37587
37588
37589
37590
37591
37592
37593
37594
37595
37596
37597
37598
37599
37600
37601
37602
37603
37604
37605
37606
37607
37608
37609
37610
37611
37612
37613
37614
37615
37616
37617
37618
37619
37620
37621
37622
37623
37624
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649
37650
37651
37652
37653
37654
37655
37656
37657
37658
37659
37660
37661
37662
37663
37664
37665
37666
37667
37668
37669
37670
37671
37672
37673
37674
37675
37676
37677
37678
37679
37680
37681
37682
37683
37684
37685
37686
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699
37700
37701
37702
37703
37704
37705
37706
37707
37708
37709
37710
37711
37712
37713
37714
37715
37716
37717
37718
37719
37720
37721
37722
37723
37724
37725
37726
37727
37728
37729
37730
37731
37732
37733
37734
37735
37736
37737
37738
37739
37740
37741
37742
37743
37744
37745
37746
37747
37748
37749
37750
37751
37752
37753
37754
37755
37756
37757
37758
37759
37760
37761
37762
37763
37764
37765
37766
37767
37768
37769
37770
37771
37772
37773
37774
37775
37776
37777
37778
37779
37780
37781
37782
37783
37784
37785
37786
37787
37788
37789
37790
37791
37792
37793
37794
37795
37796
37797
37798
37799
37800
37801
37802
37803
37804
37805
37806
37807
37808
37809
37810
37811
37812
37813
37814
37815
37816
37817
37818
37819
37820
37821
37822
37823
37824
37825
37826
37827
37828
37829
37830
37831
37832
37833
37834
37835
37836
37837
37838
37839
37840
37841
37842
37843
37844
37845
37846
37847
37848
37849
37850
37851
37852
37853
37854
37855
37856
37857
37858
37859
37860
37861
37862
37863
37864
37865
37866
37867
37868
37869
37870
37871
37872
37873
37874
37875
37876
37877
37878
37879
37880
37881
37882
37883
37884
37885
37886
37887
37888
37889
37890
37891
37892
37893
37894
37895
37896
37897
37898
37899
37900
37901
37902
37903
37904
37905
37906
37907
37908
37909
37910
37911
37912
37913
37914
37915
37916
37917
37918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
37931
37932
37933
37934
37935
37936
37937
37938
37939
37940
37941
37942
37943
37944
37945
37946
37947
37948
37949
37950
37951
37952
37953
37954
37955
37956
37957
37958
37959
37960
37961
37962
37963
37964
37965
37966
37967
37968
37969
37970
37971
37972
37973
37974
37975
37976
37977
37978
37979
37980
37981
37982
37983
37984
37985
37986
37987
37988
37989
37990
37991
37992
37993
37994
37995
37996
37997
37998
37999
38000
38001
38002
38003
38004
38005
38006
38007
38008
38009
38010
38011
38012
38013
38014
38015
38016
38017
38018
38019
38020
38021
38022
38023
38024
38025
38026
38027
38028
38029
38030
38031
38032
38033
38034
38035
38036
38037
38038
38039
38040
38041
38042
38043
38044
38045
38046
38047
38048
38049
38050
38051
38052
38053
38054
38055
38056
38057
38058
38059
38060
38061
38062
38063
38064
38065
38066
38067
38068
38069
38070
38071
38072
38073
38074
38075
38076
38077
38078
38079
38080
38081
38082
38083
38084
38085
38086
38087
38088
38089
38090
38091
38092
38093
38094
38095
38096
38097
38098
38099
38100
38101
38102
38103
38104
38105
38106
38107
38108
38109
38110
38111
38112
38113
38114
38115
38116
38117
38118
38119
38120
38121
38122
38123
38124
38125
38126
38127
38128
38129
38130
38131
38132
38133
38134
38135
38136
38137
38138
38139
38140
38141
38142
38143
38144
38145
38146
38147
38148
38149
38150
38151
38152
38153
38154
38155
38156
38157
38158
38159
38160
38161
38162
38163
38164
38165
38166
38167
38168
38169
38170
38171
38172
38173
38174
38175
38176
38177
38178
38179
38180
38181
38182
38183
38184
38185
38186
38187
38188
38189
38190
38191
38192
38193
38194
38195
38196
38197
38198
38199
38200
38201
38202
38203
38204
38205
38206
38207
38208
38209
38210
38211
38212
38213
38214
38215
38216
38217
38218
38219
38220
38221
38222
38223
38224
38225
38226
38227
38228
38229
38230
38231
38232
38233
38234
38235
38236
38237
38238
38239
38240
38241
38242
38243
38244
38245
38246
38247
38248
38249
38250
38251
38252
38253
38254
38255
38256
38257
38258
38259
38260
38261
38262
38263
38264
38265
38266
38267
38268
38269
38270
38271
38272
38273
38274
38275
38276
38277
38278
38279
38280
38281
38282
38283
38284
38285
38286
38287
38288
38289
38290
38291
38292
38293
38294
38295
38296
38297
38298
38299
38300
38301
38302
38303
38304
38305
38306
38307
38308
38309
38310
38311
38312
38313
38314
38315
38316
38317
38318
38319
38320
38321
38322
38323
38324
38325
38326
38327
38328
38329
38330
38331
38332
38333
38334
38335
38336
38337
38338
38339
38340
38341
38342
38343
38344
38345
38346
38347
38348
38349
38350
38351
38352
38353
38354
38355
38356
38357
38358
38359
38360
38361
38362
38363
38364
38365
38366
38367
38368
38369
38370
38371
38372
38373
38374
38375
38376
38377
38378
38379
38380
38381
38382
38383
38384
38385
38386
38387
38388
38389
38390
38391
38392
38393
38394
38395
38396
38397
38398
38399
38400
38401
38402
38403
38404
38405
38406
38407
38408
38409
38410
38411
38412
38413
38414
38415
38416
38417
38418
38419
38420
38421
38422
38423
38424
38425
38426
38427
38428
38429
38430
38431
38432
38433
38434
38435
38436
38437
38438
38439
38440
38441
38442
38443
38444
38445
38446
38447
38448
38449
38450
38451
38452
38453
38454
38455
38456
38457
38458
38459
38460
38461
38462
38463
38464
38465
38466
38467
38468
38469
38470
38471
38472
38473
38474
38475
38476
38477
38478
38479
38480
38481
38482
38483
38484
38485
38486
38487
38488
38489
38490
38491
38492
38493
38494
38495
38496
38497
38498
38499
38500
38501
38502
38503
38504
38505
38506
38507
38508
38509
38510
38511
38512
38513
38514
38515
38516
38517
38518
38519
38520
38521
38522
38523
38524
38525
38526
38527
38528
38529
38530
38531
38532
38533
38534
38535
38536
38537
38538
38539
38540
38541
38542
38543
38544
38545
38546
38547
38548
38549
38550
38551
38552
38553
38554
38555
38556
38557
38558
38559
38560
38561
38562
38563
38564
38565
38566
38567
38568
38569
38570
38571
38572
38573
38574
38575
38576
38577
38578
38579
38580
38581
38582
38583
38584
38585
38586
38587
38588
38589
38590
38591
38592
38593
38594
38595
38596
38597
38598
38599
38600
38601
38602
38603
38604
38605
38606
38607
38608
38609
38610
38611
38612
38613
38614
38615
38616
38617
38618
38619
38620
38621
38622
38623
38624
38625
38626
38627
38628
38629
38630
38631
38632
38633
38634
38635
38636
38637
38638
38639
38640
38641
38642
38643
38644
38645
38646
38647
38648
38649
38650
38651
38652
38653
38654
38655
38656
38657
38658
38659
38660
38661
38662
38663
38664
38665
38666
38667
38668
38669
38670
38671
38672
38673
38674
38675
38676
38677
38678
38679
38680
38681
38682
38683
38684
38685
38686
38687
38688
38689
38690
38691
38692
38693
38694
38695
38696
38697
38698
38699
38700
38701
38702
38703
38704
38705
38706
38707
38708
38709
38710
38711
38712
38713
38714
38715
38716
38717
38718
38719
38720
38721
38722
38723
38724
38725
38726
38727
38728
38729
38730
38731
38732
38733
38734
38735
38736
38737
38738
38739
38740
38741
38742
38743
38744
38745
38746
38747
38748
38749
38750
38751
38752
38753
38754
38755
38756
38757
38758
38759
38760
38761
38762
38763
38764
38765
38766
38767
38768
38769
38770
38771
38772
38773
38774
38775
38776
38777
38778
38779
38780
38781
38782
38783
38784
38785
38786
38787
38788
38789
38790
38791
38792
38793
38794
38795
38796
38797
38798
38799
38800
38801
38802
38803
38804
38805
38806
38807
38808
38809
38810
38811
38812
38813
38814
38815
38816
38817
38818
38819
38820
38821
38822
38823
38824
38825
38826
38827
38828
38829
38830
38831
38832
38833
38834
38835
38836
38837
38838
38839
38840
38841
38842
38843
38844
38845
38846
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871
38872
38873
38874
38875
38876
38877
38878
38879
38880
38881
38882
38883
38884
38885
38886
38887
38888
38889
38890
38891
38892
38893
38894
38895
38896
38897
38898
38899
38900
38901
38902
38903
38904
38905
38906
38907
38908
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921
38922
38923
38924
38925
38926
38927
38928
38929
38930
38931
38932
38933
38934
38935
38936
38937
38938
38939
38940
38941
38942
38943
38944
38945
38946
38947
38948
38949
38950
38951
38952
38953
38954
38955
38956
38957
38958
38959
38960
38961
38962
38963
38964
38965
38966
38967
38968
38969
38970
38971
38972
38973
38974
38975
38976
38977
38978
38979
38980
38981
38982
38983
38984
38985
38986
38987
38988
38989
38990
38991
38992
38993
38994
38995
38996
38997
38998
38999
39000
39001
39002
39003
39004
39005
39006
39007
39008
39009
39010
39011
39012
39013
39014
39015
39016
39017
39018
39019
39020
39021
39022
39023
39024
39025
39026
39027
39028
39029
39030
39031
39032
39033
39034
39035
39036
39037
39038
39039
39040
39041
39042
39043
39044
39045
39046
39047
39048
39049
39050
39051
39052
39053
39054
39055
39056
39057
39058
39059
39060
39061
39062
39063
39064
39065
39066
39067
39068
39069
39070
39071
39072
39073
39074
39075
39076
39077
39078
39079
39080
39081
39082
39083
39084
39085
39086
39087
39088
39089
39090
39091
39092
39093
39094
39095
39096
39097
39098
39099
39100
39101
39102
39103
39104
39105
39106
39107
39108
39109
39110
39111
39112
39113
39114
39115
39116
39117
39118
39119
39120
39121
39122
39123
39124
39125
39126
39127
39128
39129
39130
39131
39132
39133
39134
39135
39136
39137
39138
39139
39140
39141
39142
39143
39144
39145
39146
39147
39148
39149
39150
39151
39152
39153
39154
39155
39156
39157
39158
39159
39160
39161
39162
39163
39164
39165
39166
39167
39168
39169
39170
39171
39172
39173
39174
39175
39176
39177
39178
39179
39180
39181
39182
39183
39184
39185
39186
39187
39188
39189
39190
39191
39192
39193
39194
39195
39196
39197
39198
39199
39200
39201
39202
39203
39204
39205
39206
39207
39208
39209
39210
39211
39212
39213
39214
39215
39216
39217
39218
39219
39220
39221
39222
39223
39224
39225
39226
39227
39228
39229
39230
39231
39232
39233
39234
39235
39236
39237
39238
39239
39240
39241
39242
39243
39244
39245
39246
39247
39248
39249
39250
39251
39252
39253
39254
39255
39256
39257
39258
39259
39260
39261
39262
39263
39264
39265
39266
39267
39268
39269
39270
39271
39272
39273
39274
39275
39276
39277
39278
39279
39280
39281
39282
39283
39284
39285
39286
39287
39288
39289
39290
39291
39292
39293
39294
39295
39296
39297
39298
39299
39300
39301
39302
39303
39304
39305
39306
39307
39308
39309
39310
39311
39312
39313
39314
39315
39316
39317
39318
39319
39320
39321
39322
39323
39324
39325
39326
39327
39328
39329
39330
39331
39332
39333
39334
39335
39336
39337
39338
39339
39340
39341
39342
39343
39344
39345
39346
39347
39348
39349
39350
39351
39352
39353
39354
39355
39356
39357
39358
39359
39360
39361
39362
39363
39364
39365
39366
39367
39368
39369
39370
39371
39372
39373
39374
39375
39376
39377
39378
39379
39380
39381
39382
39383
39384
39385
39386
39387
39388
39389
39390
39391
39392
39393
39394
39395
39396
39397
39398
39399
39400
39401
39402
39403
39404
39405
39406
39407
39408
39409
39410
39411
39412
39413
39414
39415
39416
39417
39418
39419
39420
39421
39422
39423
39424
39425
39426
39427
39428
39429
39430
39431
39432
39433
39434
39435
39436
39437
39438
39439
39440
39441
39442
39443
39444
39445
39446
39447
39448
39449
39450
39451
39452
39453
39454
39455
39456
39457
39458
39459
39460
39461
39462
39463
39464
39465
39466
39467
39468
39469
39470
39471
39472
39473
39474
39475
39476
39477
39478
39479
39480
39481
39482
39483
39484
39485
39486
39487
39488
39489
39490
39491
39492
39493
39494
39495
39496
39497
39498
39499
39500
39501
39502
39503
39504
39505
39506
39507
39508
39509
39510
39511
39512
39513
39514
39515
39516
39517
39518
39519
39520
39521
39522
39523
39524
39525
39526
39527
39528
39529
39530
39531
39532
39533
39534
39535
39536
39537
39538
39539
39540
39541
39542
39543
39544
39545
39546
39547
39548
39549
39550
39551
39552
39553
39554
39555
39556
39557
39558
39559
39560
39561
39562
39563
39564
39565
39566
39567
39568
39569
39570
39571
39572
39573
39574
39575
39576
39577
39578
39579
39580
39581
39582
39583
39584
39585
39586
39587
39588
39589
39590
39591
39592
39593
39594
39595
39596
39597
39598
39599
39600
39601
39602
39603
39604
39605
39606
39607
39608
39609
39610
39611
39612
39613
39614
39615
39616
39617
39618
39619
39620
39621
39622
39623
39624
39625
39626
39627
39628
39629
39630
39631
39632
39633
39634
39635
39636
39637
39638
39639
39640
39641
39642
39643
39644
39645
39646
39647
39648
39649
39650
39651
39652
39653
39654
39655
39656
39657
39658
39659
39660
39661
39662
39663
39664
39665
39666
39667
39668
39669
39670
39671
39672
39673
39674
39675
39676
39677
39678
39679
39680
39681
39682
39683
39684
39685
39686
39687
39688
39689
39690
39691
39692
39693
39694
39695
39696
39697
39698
39699
39700
39701
39702
39703
39704
39705
39706
39707
39708
39709
39710
39711
39712
39713
39714
39715
39716
39717
39718
39719
39720
39721
39722
39723
39724
39725
39726
39727
39728
39729
39730
39731
39732
39733
39734
39735
39736
39737
39738
39739
39740
39741
39742
39743
39744
39745
39746
39747
39748
39749
39750
39751
39752
39753
39754
39755
39756
39757
39758
39759
39760
39761
39762
39763
39764
39765
39766
39767
39768
39769
39770
39771
39772
39773
39774
39775
39776
39777
39778
39779
39780
39781
39782
39783
39784
39785
39786
39787
39788
39789
39790
39791
39792
39793
39794
39795
39796
39797
39798
39799
39800
39801
39802
39803
39804
39805
39806
39807
39808
39809
39810
39811
39812
39813
39814
39815
39816
39817
39818
39819
39820
39821
39822
39823
39824
39825
39826
39827
39828
39829
39830
39831
39832
39833
39834
39835
39836
39837
39838
39839
39840
39841
39842
39843
39844
39845
39846
39847
39848
39849
39850
39851
39852
39853
39854
39855
39856
39857
39858
39859
39860
39861
39862
39863
39864
39865
39866
39867
39868
39869
39870
39871
39872
39873
39874
39875
39876
39877
39878
39879
39880
39881
39882
39883
39884
39885
39886
39887
39888
39889
39890
39891
39892
39893
39894
39895
39896
39897
39898
39899
39900
39901
39902
39903
39904
39905
39906
39907
39908
39909
39910
39911
39912
39913
39914
39915
39916
39917
39918
39919
39920
39921
39922
39923
39924
39925
39926
39927
39928
39929
39930
39931
39932
39933
39934
39935
39936
39937
39938
39939
39940
39941
39942
39943
39944
39945
39946
39947
39948
39949
39950
39951
39952
39953
39954
39955
39956
39957
39958
39959
39960
39961
39962
39963
39964
39965
39966
39967
39968
39969
39970
39971
39972
39973
39974
39975
39976
39977
39978
39979
39980
39981
39982
39983
39984
39985
39986
39987
39988
39989
39990
39991
39992
39993
39994
39995
39996
39997
39998
39999
40000
40001
40002
40003
40004
40005
40006
40007
40008
40009
40010
40011
40012
40013
40014
40015
40016
40017
40018
40019
40020
40021
40022
40023
40024
40025
40026
40027
40028
40029
40030
40031
40032
40033
40034
40035
40036
40037
40038
40039
40040
40041
40042
40043
40044
40045
40046
40047
40048
40049
40050
40051
40052
40053
40054
40055
40056
40057
40058
40059
40060
40061
40062
40063
40064
40065
40066
40067
40068
40069
40070
40071
40072
40073
40074
40075
40076
40077
40078
40079
40080
40081
40082
40083
40084
40085
40086
40087
40088
40089
40090
40091
40092
40093
40094
40095
40096
40097
40098
40099
40100
40101
40102
40103
40104
40105
40106
40107
40108
40109
40110
40111
40112
40113
40114
40115
40116
40117
40118
40119
40120
40121
40122
40123
40124
40125
40126
40127
40128
40129
40130
40131
40132
40133
40134
40135
40136
40137
40138
40139
40140
40141
40142
40143
40144
40145
40146
40147
40148
40149
40150
40151
40152
40153
40154
40155
40156
40157
40158
40159
40160
40161
40162
40163
40164
40165
40166
40167
40168
40169
40170
40171
40172
40173
40174
40175
40176
40177
40178
40179
40180
40181
40182
40183
40184
40185
40186
40187
40188
40189
40190
40191
40192
40193
40194
40195
40196
40197
40198
40199
40200
40201
40202
40203
40204
40205
40206
40207
40208
40209
40210
40211
40212
40213
40214
40215
40216
40217
40218
40219
40220
40221
40222
40223
40224
40225
40226
40227
40228
40229
40230
40231
40232
40233
40234
40235
40236
40237
40238
40239
40240
40241
40242
40243
40244
40245
40246
40247
40248
40249
40250
40251
40252
40253
40254
40255
40256
40257
40258
40259
40260
40261
40262
40263
40264
40265
40266
40267
40268
40269
40270
40271
40272
40273
40274
40275
40276
40277
40278
40279
40280
40281
40282
40283
40284
40285
40286
40287
40288
40289
40290
40291
40292
40293
40294
40295
40296
40297
40298
40299
40300
40301
40302
40303
40304
40305
40306
40307
40308
40309
40310
40311
40312
40313
40314
40315
40316
40317
40318
40319
40320
40321
40322
40323
40324
40325
40326
40327
40328
40329
40330
40331
40332
40333
40334
40335
40336
40337
40338
40339
40340
40341
40342
40343
40344
40345
40346
40347
40348
40349
40350
40351
40352
40353
40354
40355
40356
40357
40358
40359
40360
40361
40362
40363
40364
40365
40366
40367
40368
40369
40370
40371
40372
40373
40374
40375
40376
40377
40378
40379
40380
40381
40382
40383
40384
40385
40386
40387
40388
40389
40390
40391
40392
40393
40394
40395
40396
40397
40398
40399
40400
40401
40402
40403
40404
40405
40406
40407
40408
40409
40410
40411
40412
40413
40414
40415
40416
40417
40418
40419
40420
40421
40422
40423
40424
40425
40426
40427
40428
40429
40430
40431
40432
40433
40434
40435
40436
40437
40438
40439
40440
40441
40442
40443
40444
40445
40446
40447
40448
40449
40450
40451
40452
40453
40454
40455
40456
40457
40458
40459
40460
40461
40462
40463
40464
40465
40466
40467
40468
40469
40470
40471
40472
40473
40474
40475
40476
40477
40478
40479
40480
40481
40482
40483
40484
40485
40486
40487
40488
40489
40490
40491
40492
40493
40494
40495
40496
40497
40498
40499
40500
40501
40502
40503
40504
40505
40506
40507
40508
40509
40510
40511
40512
40513
40514
40515
40516
40517
40518
40519
40520
40521
40522
40523
40524
40525
40526
40527
40528
40529
40530
40531
40532
40533
40534
40535
40536
40537
40538
40539
40540
40541
40542
40543
40544
40545
40546
40547
40548
40549
40550
40551
40552
40553
40554
40555
40556
40557
40558
40559
40560
40561
40562
40563
40564
40565
40566
40567
40568
40569
40570
40571
40572
40573
40574
40575
40576
40577
40578
40579
40580
40581
40582
40583
40584
40585
40586
40587
40588
40589
40590
40591
40592
40593
40594
40595
40596
40597
40598
40599
40600
40601
40602
40603
40604
40605
40606
40607
40608
40609
40610
40611
40612
40613
40614
40615
40616
40617
40618
40619
40620
40621
40622
40623
40624
40625
40626
40627
40628
40629
40630
40631
40632
40633
40634
40635
40636
40637
40638
40639
40640
40641
40642
40643
40644
40645
40646
40647
40648
40649
40650
40651
40652
40653
40654
40655
40656
40657
40658
40659
40660
40661
40662
40663
40664
40665
40666
40667
40668
40669
40670
40671
40672
40673
40674
40675
40676
40677
40678
40679
40680
40681
40682
40683
40684
40685
40686
40687
40688
40689
40690
40691
40692
40693
40694
40695
40696
40697
40698
40699
40700
40701
40702
40703
40704
40705
40706
40707
40708
40709
40710
40711
40712
40713
40714
40715
40716
40717
40718
40719
40720
40721
40722
40723
40724
40725
40726
40727
40728
40729
40730
40731
40732
40733
40734
40735
40736
40737
40738
40739
40740
40741
40742
40743
40744
40745
40746
40747
40748
40749
40750
40751
40752
40753
40754
40755
40756
40757
40758
40759
40760
40761
40762
40763
40764
40765
40766
40767
40768
40769
40770
40771
40772
40773
40774
40775
40776
40777
40778
40779
40780
40781
40782
40783
40784
40785
40786
40787
40788
40789
40790
40791
40792
40793
40794
40795
40796
40797
40798
40799
40800
40801
40802
40803
40804
40805
40806
40807
40808
40809
40810
40811
40812
40813
40814
40815
40816
40817
40818
40819
40820
40821
40822
40823
40824
40825
40826
40827
40828
40829
40830
40831
40832
40833
40834
40835
40836
40837
40838
40839
40840
40841
40842
40843
40844
40845
40846
40847
40848
40849
40850
40851
40852
40853
40854
40855
40856
40857
40858
40859
40860
40861
40862
40863
40864
40865
40866
40867
40868
40869
40870
40871
40872
40873
40874
40875
40876
40877
40878
40879
40880
40881
40882
40883
40884
40885
40886
40887
40888
40889
40890
40891
40892
40893
40894
40895
40896
40897
40898
40899
40900
40901
40902
40903
40904
40905
40906
40907
40908
40909
40910
40911
40912
40913
40914
40915
40916
40917
40918
40919
40920
40921
40922
40923
40924
40925
40926
40927
40928
40929
40930
40931
40932
40933
40934
40935
40936
40937
40938
40939
40940
40941
40942
40943
40944
40945
40946
40947
40948
40949
40950
40951
40952
40953
40954
40955
40956
40957
40958
40959
40960
40961
40962
40963
40964
40965
40966
40967
40968
40969
40970
40971
40972
40973
40974
40975
40976
40977
40978
40979
40980
40981
40982
40983
40984
40985
40986
40987
40988
40989
40990
40991
40992
40993
40994
40995
40996
40997
40998
40999
41000
41001
41002
41003
41004
41005
41006
41007
41008
41009
41010
41011
41012
41013
41014
41015
41016
41017
41018
41019
41020
41021
41022
41023
41024
41025
41026
41027
41028
41029
41030
41031
41032
41033
41034
41035
41036
41037
41038
41039
41040
41041
41042
41043
41044
41045
41046
41047
41048
41049
41050
41051
41052
41053
41054
41055
41056
41057
41058
41059
41060
41061
41062
41063
41064
41065
41066
41067
41068
41069
41070
41071
41072
41073
41074
41075
41076
41077
41078
41079
41080
41081
41082
41083
41084
41085
41086
41087
41088
41089
41090
41091
41092
41093
41094
41095
41096
41097
41098
41099
41100
41101
41102
41103
41104
41105
41106
41107
41108
41109
41110
41111
41112
41113
41114
41115
41116
41117
41118
41119
41120
41121
41122
41123
41124
41125
41126
41127
41128
41129
41130
41131
41132
41133
41134
41135
41136
41137
41138
41139
41140
41141
41142
41143
41144
41145
41146
41147
41148
41149
41150
41151
41152
41153
41154
41155
41156
41157
41158
41159
41160
41161
41162
41163
41164
41165
41166
41167
41168
41169
41170
41171
41172
41173
41174
41175
41176
41177
41178
41179
41180
41181
41182
41183
41184
41185
41186
41187
41188
41189
41190
41191
41192
41193
41194
41195
41196
41197
41198
41199
41200
41201
41202
41203
41204
41205
41206
41207
41208
41209
41210
41211
41212
41213
41214
41215
41216
41217
41218
41219
41220
41221
41222
41223
41224
41225
41226
41227
41228
41229
41230
41231
41232
41233
41234
41235
41236
41237
41238
41239
41240
41241
41242
41243
41244
41245
41246
41247
41248
41249
41250
41251
41252
41253
41254
41255
41256
41257
41258
41259
41260
41261
41262
41263
41264
41265
41266
41267
41268
41269
41270
41271
41272
41273
41274
41275
41276
41277
41278
41279
41280
41281
41282
41283
41284
41285
41286
41287
41288
41289
41290
41291
41292
41293
41294
41295
41296
41297
41298
41299
41300
41301
41302
41303
41304
41305
41306
41307
41308
41309
41310
41311
41312
41313
41314
41315
41316
41317
41318
41319
41320
41321
41322
41323
41324
41325
41326
41327
41328
41329
41330
41331
41332
41333
41334
41335
41336
41337
41338
41339
41340
41341
41342
41343
41344
41345
41346
41347
41348
41349
41350
41351
41352
41353
41354
41355
41356
41357
41358
41359
41360
41361
41362
41363
41364
41365
41366
41367
41368
41369
41370
41371
41372
41373
41374
41375
41376
41377
41378
41379
41380
41381
41382
41383
41384
41385
41386
41387
41388
41389
41390
41391
41392
41393
41394
41395
41396
41397
41398
41399
41400
41401
41402
41403
41404
41405
41406
41407
41408
41409
41410
41411
41412
41413
41414
41415
41416
41417
41418
41419
41420
41421
41422
41423
41424
41425
41426
41427
41428
41429
41430
41431
41432
41433
41434
41435
41436
41437
41438
41439
41440
41441
41442
41443
41444
41445
41446
41447
41448
41449
41450
41451
41452
41453
41454
41455
|
\input texinfo @c -*-texinfo-*-
@c Copyright 1997, 1998, 1999, 2000 TcX AB, Detron HB and MySQL Finland AB
@c
@c *********************************************************
@c Note that @node names are used on our Website.
@c So do not change node names without checking
@c Makefile.am and SitePages first.
@c *********************************************************
@c
@c %**start of header
@setfilename mysql.info
@c We want the types in the same index
@syncodeindex tp fn
@c Get version info. This file is generated by the Makefile!!
@include include.texi
@ifclear tex-debug
@c This removes the black squares in the right margin
@finalout
@end ifclear
@c Set background for HTML
@set _body_tags BGCOLOR=silver TEXT=#000000 LINK=#101090 VLINK=#7030B0
@c Set some style elements for the manual in HTML form. 'suggested'
@c natural language colours: aqua, black, blue, fuchsia, gray, green,
@c lime, maroon, navy, olive, purple, red, silver, teal, white, and
@c yellow. From Steeve Buehler <ahr@YogElements.com>
@set _extra_head <style> code {color:purple} tt {color:green} samp {color:navy} pre {color:maroon} </style>
@settitle @strong{MySQL} Reference Manual for version @value{mysql_version}.
@c We want single-sided heading format, with chapters on new pages. To
@c get double-sided format change 'on' below to 'odd'
@setchapternewpage on
@paragraphindent 0
@c %**end of header
@ifinfo
@format
START-INFO-DIR-ENTRY
* mysql: (mysql). @strong{MySQL} documentation.
END-INFO-DIR-ENTRY
@end format
@end ifinfo
@titlepage
@sp 10
@center @titlefont{@strong{MySQL} Reference Manual}
@sp 10
@center Copyright @copyright{} 1997, 1998, 1999, 2000 TcX AB, Detron HB and MySQL Finland AB
@end titlepage
@c This should be added. The HTML conversion also needs a MySQL version
@c number somewhere.
@iftex
@c change this to double if you want formatting for double-sided
@c printing
@headings single
@everyheading @thispage @| @| @thischapter
@everyfooting @| @| Version: @value{mysql_version} Printed: @today{}
@end iftex
@node Top, Introduction, (dir), (dir)
@c @ifhtml
@c <IMG SRC="Images/mysql-logo.gif">
@c <!--Image doesn't exist. Can't find suitable replacement. (Matt) -->
@c @end ifhtml
@ifinfo
This is a manual for @strong{MySQL}. This version is about the
@value{mysql_version} version of @strong{MySQL}. For a @strong{3.20}
version see the relevant distribution.
@end ifinfo
@menu
* Introduction:: General Information about @strong{MySQL}
* Questions:: @strong{MySQL} mailing lists and how to ask questions or report errors (bugs)
* Licensing and Support:: @strong{MySQL} licensing and support
* Installing:: Installing @strong{MySQL}
* Compatibility:: How standards-compatible is @strong{MySQL}?
* Privilege system:: The @strong{MySQL} access privilege system
* Reference:: @strong{MySQL} language reference
* Table types:: @strong{MySQL} table types
* Tutorial:: @strong{MySQL} Tutorial
* Server:: @strong{MySQL} Server
* Replication:: Replication
* Performance:: Getting maximum performance from @strong{MySQL}
* MySQL Benchmarks:: The @strong{MySQL} benchmark suite
* Tools:: @strong{MySQL} Utilities
* Maintenance:: Maintaining a @strong{MySQL} installation
* Adding functions:: Adding new functions to @strong{MySQL}
* Adding procedures:: Adding new procedures to @strong{MySQL}
* ODBC:: @strong{MySQL} ODBC Support
* Common programs:: Using @strong{MySQL} with some common programs
* Problems:: Problems
* Common problems:: Solving some common problems with @strong{MySQL}
* Clients:: @strong{MySQL} client tools and APIs
* Comparisons:: How does @strong{MySQL} compare with other databases?
* MySQL internals:: @strong{MySQL} internals
* Environment variables:: @strong{MySQL} environment variables
* Users:: Some @strong{MySQL} users
* Contrib:: Contributed programs
* Credits:: Contributors to @strong{MySQL}
* News:: @strong{MySQL} change history
* Bugs:: Known errors and design deficiencies in @strong{MySQL}
* TODO:: List of things we want to add to @strong{MySQL} in the future (The TODO)
* Porting:: Comments on porting to other systems
* Regexp:: Description of @strong{MySQL} regular expression syntax
* Unireg:: What is Unireg?
* GPL license:: GNU General Public License
* LGPL license:: GNU Library General Public License
* Function Index:: SQL command, type and function index
* Concept Index:: Concept Index
@detailmenu --- The Detailed Node Listing ---
General Information about MySQL
* What-is:: What is @strong{MySQL}?
* Manual-info:: About this manual
* History:: History of @strong{MySQL}
* MySQL-Books:: Books about MySQL
* Features:: The main features of @strong{MySQL}
* Stability:: How stable is @strong{MySQL}?
* Year 2000 compliance:: Year 2000 compliance
* General-SQL:: General SQL information and tutorials
* Useful Links:: Useful @strong{MySQL}-related links
About this manual
* Manual conventions:: Conventions used in this manual
MySQL mailing lists and how to ask questions or report errors (bugs)
* Mailing-list:: The @strong{MySQL} mailing lists
* Asking questions:: Asking questions or reporting bugs
* Bug reports:: How to report bugs or problems
* Answering questions:: Guidelines for answering questions on the mailing list
MySQL licensing and support
* Licensing policy:: @strong{MySQL} licensing policy
* Copyright:: Copyrights used by @strong{MySQL}
* Licensing examples:: Example licensing situations
* Cost:: @strong{MySQL} licensing and support costs
* Support:: Types of commercial support
Copyrights used by MySQL
* Copyright changes:: Possible future copyright changes
Example licensing situations
* Products that use MySQL:: Selling products that use @strong{MySQL}
* ISP:: ISP @strong{MySQL} services
* Web server:: Running a web server using @strong{MySQL}.
@strong{MySQL} licensing and support costs
* Payment information:: Payment information
* Contact information:: Contact information
Types of commercial support
* Basic email support:: Basic email support
* Extended email support:: Extended email support
* Login support:: Login support
* Extended login support:: Extended login support
Installing MySQL
* Getting MySQL:: How to get @strong{MySQL}
* Which OS:: Operating systems supported by @strong{MySQL}
* Which version:: Which @strong{MySQL} version to use
* Many versions:: How and when updates are released
* Installation layouts:: Installation layouts
* Installing binary:: Installing a @strong{MySQL} binary distribution
* Installing source:: Installing a @strong{MySQL} source distribution
* Compilation problems:: Problems compiling?
* MIT-pthreads:: MIT-pthreads notes
* Perl support:: Perl installation comments
* Source install system issues:: System-specific issues
* Win32:: Win32 notes
* OS/2:: OS/2 notes
* MySQL binaries::
* Post-installation:: Post-installation setup and testing
* Upgrade:: Is there anything special to do when upgrading/downgrading @strong{MySQL}?
Installing a MySQL binary distribution
* Linux-RPM:: Linux RPM files
* Building clients:: Building client programs
* Binary install system issues:: System-specific issues
System-specific issues
* Binary notes-Linux:: Linux notes
* Binary notes-HP-UX:: HP-UX notes
Installing a MySQL source distribution
* Quick install:: Quick installation overview
* Applying patches:: Applying patches
* configure options:: Typical @code{configure} options
Perl installation comments
* Perl installation:: Installing Perl on Unix
* ActiveState Perl:: Installing ActiveState Perl on Win32
* Win32 Perl:: Installing the @strong{MySQL} Perl distribution on Win32
* Perl support problems:: Problems using the Perl @code{DBI}/@code{DBD} interface
System-specific issues
* Solaris:: Solaris notes
* Solaris 2.7:: Solaris 2.7 / 2.8 notes
* Solaris x86:: Solaris x86 notes
* SunOS:: SunOS 4 notes
* Linux:: Linux notes (all Linux versions)
* Alpha-DEC-Unix:: Alpha-DEC-Unix notes
* Alpha-DEC-OSF1:: Alpha-DEC-OSF1 notes
* SGI-Irix:: SGI-Irix notes
* FreeBSD:: FreeBSD notes
* NetBSD:: NetBSD notes
* OpenBSD:: OpenBSD 2.5 notes
* BSDI:: BSD/OS notes
* SCO:: SCO notes
* SCO Unixware:: SCO Unixware 7.0 notes
* IBM-AIX:: IBM-AIX notes
* HP-UX 10.20:: HP-UX 10.20 notes
* HP-UX 11.x:: HP-UX 11.x notes
* MacOSX:: MacOSX notes
Linux notes (all Linux versions)
* Linux-x86:: Linux-x86 notes
* Linux-RedHat50:: RedHat 5.0 notes
* Linux-RedHat51:: RedHat 5.1 notes
* Linux-SPARC:: Linux-SPARC notes
* Linux-Alpha:: Linux-Alpha notes
* MKLinux:: MkLinux notes
* Qube2:: Qube2 Linux notes
* Linux-Ia64::
BSD/OS notes
* BSDI2:: BSD/OS 2.x notes
* BSDI3:: BSD/OS 3.x notes
* BSDI4:: BSD/OS 4.x notes
Win32 notes
* Win32 installation:: Installing @strong{MySQL} on Win32
* Win95 start:: Starting @strong{MySQL} on Win95 / Win98
* NT start:: Starting @strong{MySQL} on NT / Win2000
* Win32 running:: Running @strong{MySQL} on Win32
* Win32 and SSH:: Connecting to a remote @strong{MySQL} from Win32 with SSH
* Win32 symbolic links:: Splitting data across different disks under Win32
* Win32 compiling::
* Win32 vs Unix:: @strong{MySQL}-Win32 compared to Unix @strong{MySQL}
Post-installation setup and testing
* mysql_install_db:: Problems running @code{mysql_install_db}
* Starting server:: Problems starting the @strong{MySQL} server
* Automatic start:: Starting and stopping @strong{MySQL} automatically
* Command-line options:: Command-line options
* Option files:: Option files
Is there anything special to do when upgrading/downgrading MySQL?
* Upgrading-from-3.22:: Upgrading from a 3.22 version to 3.23
* Upgrading-from-3.21:: Upgrading from a 3.21 version to 3.22
* Upgrading-from-3.20:: Upgrading from a 3.20 version to 3.21
* Upgrading-to-arch:: Upgrading to another architecture
How standards-compatible is MySQL?
* Extensions to ANSI:: @strong{MySQL} extensions to ANSI SQL92
* Ansi mode:: Runnning @strong{MySQL} in ANSI mode
* Differences from ANSI:: @strong{MySQL} differences compared to ANSI SQL92
* Missing functions:: Functionality missing from @strong{MySQL}
* Standards:: What standards does @strong{MySQL} follow?
* Commit-rollback:: How to cope without @code{COMMIT}-@code{ROLLBACK}
Functionality missing from MySQL
* Missing Sub-selects:: Sub-selects
* Missing SELECT INTO TABLE:: @code{SELECT INTO TABLE}
* Missing Transactions:: Transactions
* Missing Triggers:: Triggers
* Missing Foreign Keys:: Foreign Keys
* Missing Views:: Views
* Missing comments:: @samp{--} as the start of a comment
Foreign Keys
* Broken Foreign KEY:: Reasons NOT to use foreign keys
The MySQL access privilege system
* General security:: General security
* Security:: How to make @strong{MySQL} secure against crackers
* What Privileges:: What the privilege system does
* User names:: @strong{MySQL} user names and passwords
* Connecting:: Connecting to the @strong{MySQL} server
* Password security:: Keeping your password secure
* Privileges provided:: Privileges provided by @strong{MySQL}
* Privileges:: How the privilege system works
* Connection access:: Access control, stage 1: Connection verification
* Request access:: Access control, stage 2: Request verification
* Privilege changes:: When privilege changes take effect
* Default privileges:: Setting up the initial @strong{MySQL} privileges
* Adding users:: Adding new user privileges to @strong{MySQL}
* Passwords:: How to set up passwords
* Access denied:: Causes of @code{Access denied} errors
MySQL language reference
* Literals:: Literals: how to write strings and numbers
* Variables:: User variables
* Column types:: Column types
* Functions:: Functions
* CREATE DATABASE:: @code{CREATE DATABASE} syntax
* DROP DATABASE:: @code{DROP DATABASE} syntax
* CREATE TABLE:: @code{CREATE TABLE} syntax
* ALTER TABLE:: @code{ALTER TABLE} syntax
* DROP TABLE:: @code{DROP TABLE} syntax
* OPTIMIZE TABLE:: @code{OPTIMIZE TABLE} syntax
* CHECK TABLE:: @code{CHECK TABLE} syntax
* ANALYZE TABLE::
* REPAIR TABLE:: @code{REPAIR TABLE} syntax
* DELETE:: @code{DELETE} syntax
* SELECT:: @code{SELECT} syntax
* JOIN:: @code{JOIN} syntax
* INSERT:: @code{INSERT} syntax
* REPLACE:: @code{REPLACE} syntax
* LOAD DATA:: @code{LOAD DATA INFILE} syntax
* UPDATE:: @code{UPDATE} syntax
* USE:: @code{USE} syntax
* FLUSH:: @code{Flush} syntax (clearing caches)
* KILL:: @code{KILL} syntax
* SHOW:: @code{SHOW} syntax (Get information about tables, columns, ...)
* EXPLAIN:: @code{EXPLAIN} syntax (Get information about a @code{SELECT})
* DESCRIBE:: @code{DESCRIBE} syntax (Get information about names of columns)
* COMMIT:: @code{BEGIN/COMMIT/ROLLBACK} syntax
* LOCK TABLES:: @code{LOCK TABLES/UNLOCK TABLES} syntax
* SET OPTION:: @code{SET OPTION} syntax
* GRANT:: @code{GRANT} and @code{REVOKE} syntax
* CREATE INDEX:: @code{CREATE INDEX} syntax
* DROP INDEX:: @code{DROP INDEX} syntax
* Comments:: Comment syntax
* CREATE FUNCTION:: @code{CREATE FUNCTION} syntax
* Reserved words:: Is @strong{MySQL} picky about reserved words?
Literals: how to write strings and numbers
* String syntax:: Strings
* Number syntax:: Numbers
* Hexadecimal values:: Hexadecimal values
* NULL values:: @code{NULL} values
* Legal names:: Database, table, index, column and alias names
Database, table, index, column and alias names
* Name case sensitivity:: Case sensitivity in names
Column types
* Storage requirements:: Column type storage requirements
* Numeric types:: Numeric types
* Date and time types:: Date and time types
* String types:: String types
* Choosing types:: Choosing the right type for a column
* Indexes:: Column indexes
* Multiple-column indexes:: Multiple-column indexes
* Other-vendor column types:: Using column types from other database engines
Date and time types
* Y2K issues:: Y2K issues and date types
* DATETIME:: The @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} types
* TIME:: The @code{TIME} type
* YEAR:: The @code{YEAR} type
String types
* CHAR:: The @code{CHAR} and @code{VARCHAR} types
* BLOB:: The @code{BLOB} and @code{TEXT} types
* ENUM:: The @code{ENUM} type
* SET:: The @code{SET} type
Functions for use in @code{SELECT} and @code{WHERE} clauses
* Grouping functions:: Grouping functions
* Arithmetic functions:: Normal arithmetic operations
* Bit functions:: Bit functions
* Logical functions:: Logical operations
* Comparison functions:: Comparison operators
* String comparison functions:: String comparison functions
* Casts:: Cast operators
* Control flow functions:: Control flow functions
* Mathematical functions:: Mathematical functions
* String functions:: String functions
* Date and time functions:: Date and time functions
* Miscellaneous functions:: Miscellaneous functions
* Group by functions:: Functions for @code{GROUP BY} clause
@code{CREATE TABLE} syntax
* Silent column changes:: Silent column changes
@code{SHOW} syntax (Get information about tables, columns,...)
* SHOW DATABASE INFO::
* SHOW TABLE STATUS::
* SHOW STATUS::
* SHOW VARIABLES::
* SHOW PROCESSLIST::
* SHOW GRANTS::
MySQL table types
* MyISAM:: MyISAM tables
* ISAM:: ISAM tables
* HEAP:: HEAP tables
* BDB:: BDB or Berkeley_db tables
MyISAM tables
* Key space:: Space needed for keys
* MyISAM table formats:: MyISAM table formats
MyISAM table formats
* Static format:: Static (Fixed-length) table characteristics
* Dynamic format:: Dynamic table characteristics
* Compressed format:: Compressed table characteristics
MySQL Tutorial
* Connecting-disconnecting:: Connecting to and disconnecting from the server
* Entering queries:: Entering queries
* Examples:: Examples
* Searching on two keys:: Searching on two keys
* Database use:: Creating and using a database
* Getting information:: Getting information about databases and tables
* Batch mode:: Using @code{mysql} in batch mode
* Twin:: Queries from twin project
Examples of common queries
* example-Maximum-column:: The maximum value for a column
* example-Maximum-row:: The row holding the maximum of a certain column
* example-Maximum-column-group:: Maximum of column: per group: only the values
* example-Maximum-column-group-row:: The rows holding the group-wise maximum of a certain field
* example-Foreign keys:: Using foreign keys
Creating and using a database
* Creating database:: Creating a database
* Creating tables:: Creating a table
* Loading tables:: Loading data into a table
* Retrieving data:: Retrieving information from a table
* Multiple tables:: Using more than one table
Retrieving information from a table
* Selecting all:: Selecting all data
* Selecting rows:: Selecting particular rows
* Selecting columns:: Selecting particular columns
* Sorting rows:: Sorting rows
* Date calculations:: Date calculations
* Working with NULL:: Working with @code{NULL} values
* Pattern matching:: Pattern matching
* Counting rows:: Counting rows
Queries from twin project
* Twin pool:: Find all non-distributed twins
* Twin event:: Show a table on twin pair status
MySQL server functions
* Languages:: What languages are supported by @strong{MySQL}?
* Table size:: How big @strong{MySQL} tables can be
What languages are supported by MySQL?
* Character sets:: The character set used for data and sorting
* Adding character set:: Adding a new character set
* String collating:: String collating support
* Multi-byte characters:: Multi-byte character support
Replication in MySQL
* Replication Intro:: Introduction
* Replication Implementation:: Replication Implementation Overview
* Replication HOWTO:: HOWTO
* Replication Features:: Replication Features
* Replication Options:: Replication Options in my.cnf
* Replication SQL:: SQL Commands related to replication
Getting maximum performance from MySQL
* Optimize Basics:: Optimization overview
* System:: System/Compile time and startup parameter tuning
* Data size:: Get your data as small as possible
* MySQL indexes:: How @strong{MySQL} uses indexes
* Query Speed:: Speed of queries that access or update data
* Tips:: Other optimization tips
* Benchmarks:: Using your own benchmarks
* Design:: Design choices
* Design Limitations:: MySQL design limitations/tradeoffs
* Portability:: Portability
* Internal use:: What have we used MySQL for?
System/Compile time and startup parameter tuning
* Compile and link options:: How compiling and linking affects the speed of MySQL
* Disk issues:: Disk issues
* Server parameters:: Tuning server parameters
* Table cache:: How MySQL opens and closes tables
* Creating many tables:: Drawbacks of creating large numbers of tables in the same database
* Open tables:: Why so many open tables?
* Memory use:: How MySQL uses memory
* Internal locking:: How MySQL locks tables
* Table locking:: Table locking issues
Disk issues
* Symbolic links:: Using symbolic links for databases and tables
Speed of queries that access or update data
* Estimating performance:: Estimating query performance
* SELECT speed:: Speed of @code{SELECT} queries
* Where optimizations:: How MySQL optimizes @code{WHERE} clauses
* LEFT JOIN optimization:: How MySQL optimizes @code{LEFT JOIN}
* LIMIT optimization:: How MySQL optimizes @code{LIMIT}
* Insert speed:: Speed of @code{INSERT} queries
* Update speed:: Speed of @code{UPDATE} queries
* Delete speed:: Speed of @code{DELETE} queries
MySQL Utilites
* Programs:: What do the executables do?
* mysql:: The command line tool
* mysqladmin:: Administering a @strong{MySQL} server
* mysqldump:: Dumping the structure and data from @strong{MySQL} databases and tables
* mysqlimport:: Importing data from text files
* mysqlshow:: Showing databases, tables and columns
* myisampack:: The @strong{MySQL} compressed read-only table generator
Maintaining a MySQL installation
* Table maintenance:: Table maintenance and crash recovery
* Maintenance regimen:: Setting up a table maintenance regimen
* Table-info:: Getting information about a table
* Crash recovery:: Using @code{myisamchk} for crash recovery
* Log files:: Log file maintenance
Using @code{myisamchk} for table maintenance and crash recovery
* myisamchk syntax:: @code{myisamchk} invocation syntax
* myisamchk memory:: @code{myisamchk} memory usage
@code{myisamchk} invocation syntax
* myisamchk general options::
* myisamchk check options::
* myisamchk repair options::
* myisamchk other options::
Using @code{myisamchk} for crash recovery
* Check:: How to check tables for errors
* Repair:: How to repair tables
* Optimization:: Table optimization
Adding new functions to MySQL
* Adding UDF:: Adding a new user-definable function
* Adding native function:: Adding a new native function
Adding a new user-definable function
* UDF calling sequences:: UDF calling sequences
* UDF arguments:: Argument processing
* UDF return values:: Return values and error handling
* UDF compiling:: Compiling and installing user-definable functions
Adding new procedures to MySQL
* procedure analyse:: Procedure analyse
* Writing a procedure:: Writing a procedure.
MySQL ODBC Support
* Which ODBC OS:: Operating systems supported by @strong{MyODBC}
* ODBC administrator:: How to fill in the various fields in the ODBC administrator program
* ODBC Problems:: How to report problems with @strong{MySQL} ODBC
* MyODBC clients:: Programs known to work with @strong{MyODBC}
* ODBC and last_insert_id:: How to get the value of an @code{AUTO_INCREMENT} column in ODBC
* MyODBC bug report:: Reporting problems with MyODBC
Using @code{MySQL} with some common programs
* Apache:: Using @strong{MySQL} with Apache
Problems and common errors
* What is crashing:: How to determinate what is causing problems
* Crashing:: What to do if @strong{MySQL} keeps crashing
* Link errors:: Problems when linking with the @strong{MySQL} client library
* Common errors:: Some common errors when using @strong{MySQL}
* Full disk:: How @strong{MySQL} handles a full disk
* Multiple sql commands:: How to run SQL commands from a text file
* Temporary files:: Where @strong{MySQL} stores temporary files
* Problems with mysql.sock:: How to protect @file{/tmp/mysql.sock}
* Error Access denied:: @code{Access denied} error
* Changing MySQL user :: How to run @strong{MySQL} as a normal user
* Resetting permissions:: How to reset a forgotten password.
* File permissions :: Problems with file permissions
* Not enough file handles:: File not found
* Using DATE:: Problems using @code{DATE} columns
* Timezone problems:: Timezone problems
* Case sensitivity:: Case sensitivity in searches
* Problems with NULL:: Problems with @code{NULL} values
* Problems with alias:: Problems with @code{alias}
* Deleting from related tables:: Deleting rows from related tables
* No matching rows:: Solving problems with no matching rows
* ALTER TABLE problems:: Problems with @code{ALTER TABLE}.
* Change column order:: How to change the order of columns in a table
Some common errors when using MySQL
* Gone away:: @code{MySQL server has gone away} error
* Can not connect to server:: @code{Can't connect to [local] MySQL server} error
* Blocked host:: @code{Host '...' is blocked} error
* Too many connections:: @code{Too many connections} error
* Out of memory:: @code{Out of memory} error
* Packet too large:: @code{Packet too large} error
* Communication errors::
* Full table:: @code{The table is full} error
* Commands out of sync:: @code{Commands out of sync} error in client
* Ignoring user:: @code{Ignoring user} error
* Cannot find table:: @code{Table 'xxx' doesn't exist} error
Solving some common problems with MySQL
* Log Replication:: Database replication with update log
* Backup:: Database backups
* Update log:: The update log
* Multiple servers:: Running multiple @strong{MySQL} servers on the same machine
MySQL client tools and APIs
* C:: @strong{MySQL} C API
* C API datatypes:: C API datatypes
* C API function overview:: C API function Overview
* C API functions:: C API function descriptions
* Perl:: @strong{MySQL} Perl API
* Eiffel:: @strong{MySQL} Eiffel wrapper
* Java:: @strong{MySQL} Java connectivity (JDBC)
* PHP:: @strong{MySQL} PHP API
* Cplusplus:: @strong{MySQL} C++ APIs
* Python:: @strong{MySQL} Python APIs
* Tcl:: @strong{MySQL} Tcl APIs
C API function descriptions
* mysql_affected_rows:: @code{mysql_affected_rows()}
* mysql_close:: @code{mysql_close()}
* mysql_connect:: @code{mysql_connect()}
* mysql_change_user:: @code{mysql_change_user()}
* mysql_character_set_name:: @code{mysql_character_set_name()}
* mysql_create_db:: @code{mysql_create_db()}
* mysql_data_seek:: @code{mysql_data_seek()}
* mysql_debug:: @code{mysql_debug()}
* mysql_drop_db:: @code{mysql_drop_db()}
* mysql_dump_debug_info:: @code{mysql_dump_debug_info()}
* mysql_eof:: @code{mysql_eof()}
* mysql_errno:: @code{mysql_errno()}
* mysql_error:: @code{mysql_error()}
* mysql_escape_string:: @code{mysql_escape_string()}
* mysql_fetch_field:: @code{mysql_fetch_field()}
* mysql_fetch_fields:: @code{mysql_fetch_fields()}
* mysql_fetch_field_direct:: @code{mysql_fetch_field_direct()}
* mysql_fetch_lengths:: @code{mysql_fetch_lengths()}
* mysql_fetch_row:: @code{mysql_fetch_row()}
* mysql_field_count:: @code{mysql_field_count()}
* mysql_field_seek:: @code{mysql_field_seek()}
* mysql_field_tell:: @code{mysql_field_tell()}
* mysql_free_result:: @code{mysql_free_result()}
* mysql_get_client_info:: @code{mysql_get_client_info()}
* mysql_get_host_info:: @code{mysql_get_host_info()}
* mysql_get_proto_info:: @code{mysql_get_proto_info()}
* mysql_get_server_info:: @code{mysql_get_server_info()}
* mysql_info:: @code{mysql_info()}
* mysql_init:: @code{mysql_init()}
* mysql_insert_id:: @code{mysql_insert_id()}
* mysql_kill:: @code{mysql_kill()}
* mysql_list_dbs:: @code{mysql_list_dbs()}
* mysql_list_fields:: @code{mysql_list_fields()}
* mysql_list_processes:: @code{mysql_list_processes()}
* mysql_list_tables:: @code{mysql_list_tables()}
* mysql_num_fields:: @code{mysql_num_fields()}
* mysql_num_rows:: @code{mysql_num_rows()}
* mysql_options:: @code{mysql_options()}
* mysql_ping:: @code{mysql_ping()}
* mysql_query:: @code{mysql_query()}
* mysql_real_connect:: @code{mysql_real_connect()}
* mysql_real_escape_string:: @code{mysql_real_escape_string()}
* mysql_real_query:: @code{mysql_real_query()}
* mysql_reload:: @code{mysql_reload()}
* mysql_row_seek:: @code{mysql_row_seek()}
* mysql_row_tell:: @code{mysql_row_tell()}
* mysql_select_db:: @code{mysql_select_db()}
* mysql_shutdown:: @code{mysql_shutdown()}
* mysql_stat:: @code{mysql_stat()}
* mysql_store_result:: @code{mysql_store_result()}
* mysql_thread_id:: @code{mysql_thread_id()}
* mysql_use_result:: @code{mysql_use_result()}
* NULL mysql_store_result:: Why is it that after @code{mysql_query()} returns success, @code{mysql_store_result()} sometimes returns @code{NULL?}
* Query results:: What results can I get from a query?
* Getting unique ID:: How can I get the unique ID for the last inserted row?
* C API linking problems:: Problems linking with the C API
* Thread-safe clients:: How to make a thread-safe client
MySQL Perl API
* DBI with DBD:: @code{DBI} with @code{DBD::mysql}
* Perl DBI Class:: The @code{DBI} interface
* DBI-info:: More @code{DBI}/@code{DBD} information
MySQL PHP API
* PHP problems:: Common problems with MySQL and PHP
How MySQL compares to other databases
* Compare mSQL:: How @strong{MySQL} compares to @code{mSQL}
* Compare PostgreSQL:: How @strong{MySQL} compares with PostgreSQL
How MySQL compares to @code{mSQL}
* Using mSQL tools:: How to convert @code{mSQL} tools for @strong{MySQL}
* Protocol differences:: How @code{mSQL} and @strong{MySQL} client/server communications protocols differ
* Syntax differences:: How @code{mSQL} 2.0 SQL syntax differs from @strong{MySQL}
MySQL internals
* MySQL threads:: MySQL threads
MySQL change history
* News-3.23.x:: Changes in release 3.23.x (Released as alpha)
* News-3.22.x:: Changes in release 3.22.x (Recommended version)
* News-3.21.x:: Changes in release 3.21.x
* News-3.20.x:: Changes in release 3.20.x
* News-3.19.x:: Changes in release 3.19.x
Changes in release 3.23.x (Released as alpha)
* News-3.23.22:: Changes in release 3.23.22
* News-3.23.21:: Changes in release 3.23.21
* News-3.23.20:: Changes in release 3.23.20
* News-3.23.19:: Changes in release 3.23.19
* News-3.23.18:: Changes in release 3.23.18
* News-3.23.17:: Changes in release 3.23.17
* News-3.23.16:: Changes in release 3.23.16
* News-3.23.15:: Changes in release 3.23.15
* News-3.23.14:: Changes in release 3.23.14
* News-3.23.13:: Changes in release 3.23.13
* News-3.23.12:: Changes in release 3.23.12
* News-3.23.11:: Changes in release 3.23.11
* News-3.23.10:: Changes in release 3.23.10
* News-3.23.9:: Changes in release 3.23.9
* News-3.23.8:: Changes in release 3.23.8
* News-3.23.7:: Changes in release 3.23.7
* News-3.23.6:: Changes in release 3.23.6
* News-3.23.5:: Changes in release 3.23.5
* News-3.23.4:: Changes in release 3.23.4
* News-3.23.3:: Changes in release 3.23.3
* News-3.23.2:: Changes in release 3.23.2
* News-3.23.1:: Changes in release 3.23.1
* News-3.23.0:: Changes in release 3.23.0
Changes in release 3.22.x
* News-3.22.35:: Changes in release 3.22.35
* News-3.22.34:: Changes in release 3.22.34
* News-3.22.33:: Changes in release 3.22.33
* News-3.22.32:: Changes in release 3.22.32
* News-3.22.31:: Changes in release 3.22.31
* News-3.22.30:: Changes in release 3.22.30
* News-3.22.29:: Changes in release 3.22.29
* News-3.22.28:: Changes in release 3.22.28
* News-3.22.27:: Changes in release 3.22.27
* News-3.22.26:: Changes in release 3.22.26
* News-3.22.25:: Changes in release 3.22.25
* News-3.22.24:: Changes in release 3.22.24
* News-3.22.23:: Changes in release 3.22.23
* News-3.22.22:: Changes in release 3.22.22
* News-3.22.21:: Changes in release 3.22.21
* News-3.22.20:: Changes in release 3.22.20
* News-3.22.19:: Changes in release 3.22.19
* News-3.22.18:: Changes in release 3.22.18
* News-3.22.17:: Changes in release 3.22.17
* News-3.22.16:: Changes in release 3.22.16
* News-3.22.15:: Changes in release 3.22.15
* News-3.22.14:: Changes in release 3.22.14
* News-3.22.13:: Changes in release 3.22.13
* News-3.22.12:: Changes in release 3.22.12
* News-3.22.11:: Changes in release 3.22.11
* News-3.22.10:: Changes in release 3.22.10
* News-3.22.9:: Changes in release 3.22.9
* News-3.22.8:: Changes in release 3.22.8
* News-3.22.7:: Changes in release 3.22.7
* News-3.22.6:: Changes in release 3.22.6
* News-3.22.5:: Changes in release 3.22.5
* News-3.22.4:: Changes in release 3.22.4
* News-3.22.3:: Changes in release 3.22.3
* News-3.22.2:: Changes in release 3.22.2
* News-3.22.1:: Changes in release 3.22.1
* News-3.22.0:: Changes in release 3.22.0
Changes in release 3.21.x
* News-3.21.33:: Changes in release 3.21.33
* News-3.21.32:: Changes in release 3.21.32
* News-3.21.31:: Changes in release 3.21.31
* News-3.21.30:: Changes in release 3.21.30
* News-3.21.29:: Changes in release 3.21.29
* News-3.21.28:: Changes in release 3.21.28
* News-3.21.27:: Changes in release 3.21.27
* News-3.21.26:: Changes in release 3.21.26
* News-3.21.25:: Changes in release 3.21.25
* News-3.21.24:: Changes in release 3.21.24
* News-3.21.23:: Changes in release 3.21.23
* News-3.21.22:: Changes in release 3.21.22
* News-3.21.21a:: Changes in release 3.21.21a
* News-3.21.21:: Changes in release 3.21.21
* News-3.21.20:: Changes in release 3.21.20
* News-3.21.19:: Changes in release 3.21.19
* News-3.21.18:: Changes in release 3.21.18
* News-3.21.17:: Changes in release 3.21.17
* News-3.21.16:: Changes in release 3.21.16
* News-3.21.15:: Changes in release 3.21.15
* News-3.21.14b:: Changes in release 3.21.14b
* News-3.21.14a:: Changes in release 3.21.14a
* News-3.21.13:: Changes in release 3.21.13
* News-3.21.12:: Changes in release 3.21.12
* News-3.21.11:: Changes in release 3.21.11
* News-3.21.10:: Changes in release 3.21.10
* News-3.21.9:: Changes in release 3.21.9
* News-3.21.8:: Changes in release 3.21.8
* News-3.21.7:: Changes in release 3.21.7
* News-3.21.6:: Changes in release 3.21.6
* News-3.21.5:: Changes in release 3.21.5
* News-3.21.4:: Changes in release 3.21.4
* News-3.21.3:: Changes in release 3.21.3
* News-3.21.2:: Changes in release 3.21.2
* News-3.21.0:: Changes in release 3.21.0
Changes in release 3.20.x
* News-3.20.18:: Changes in release 3.20.18
* News-3.20.17:: Changes in release 3.20.17
* News-3.20.16:: Changes in release 3.20.16
* News-3.20.15:: Changes in release 3.20.15
* News-3.20.14:: Changes in release 3.20.14
* News-3.20.13:: Changes in release 3.20.13
* News-3.20.11:: Changes in release 3.20.11
* News-3.20.10:: Changes in release 3.20.10
* News-3.20.9:: Changes in release 3.20.9
* News-3.20.8:: Changes in release 3.20.8
* News-3.20.7:: Changes in release 3.20.7
* News-3.20.6:: Changes in release 3.20.6
* News-3.20.3:: Changes in release 3.20.3
* News-3.20.0:: Changes in releases 3.20.0
Changes in release 3.19.x
* News-3.19.5:: Changes in release 3.19.5
* News-3.19.4:: Changes in release 3.19.4
* News-3.19.3:: Changes in release 3.19.3
List of things we want to add to MySQL in the future (The TODO)
* TODO future:: Things that must done in the very near future
* TODO sometime:: Things that have to be done sometime
* TODO unplanned:: Some things we don't have any plans to do
Comments on porting to other systems
* Debugging server:: Debugging a @strong{MySQL} server
* Debugging client:: Debugging a @strong{MySQL} client
* The DBUG package:: The DBUG package
* Locking methods::
* RTS-threads:: Comments about RTS threads
* Thread packages:: Differences between different thread packages
@end detailmenu
@end menu
@cindex Overview
@cindex General Information
@node Introduction, Questions, Top, Top
@chapter General Information about MySQL
@menu
* What-is:: What is @strong{MySQL}?
* Manual-info:: About this manual
* History:: History of @strong{MySQL}
* MySQL-Books:: Books about MySQL
* Features:: The main features of @strong{MySQL}
* Stability:: How stable is @strong{MySQL}?
* Year 2000 compliance:: Year 2000 compliance
* General-SQL:: General SQL information and tutorials
* Useful Links:: Useful @strong{MySQL}-related links
@end menu
This is the @strong{MySQL} reference manual; it documents @strong{MySQL}
version @value{mysql_version}. As @strong{MySQL} is work in progress,
the manual gets updated frequently. So there is a very good chance that
this version is out of date, unless you are looking at it on-line. The
most recent version of this manual is available at
@uref{http://www.mysql.com/documentation/} in many different formats. If you
have a hard time finding the information in the manual, you can try its
searchable PHP version at @uref{http://www.mysql.com/documentation/manual.php} .
@strong{MySQL} is a very fast, multi-threaded, multi-user and robust SQL
(Structured Query Language) database server.
@strong{MySQL} is free software. It is licensed with the @strong{GNU
GENERAL PUBLIC LICENSE} @uref{http://www.gnu.org/}. @xref{Licensing and
Support}.
@uref{http://www.mysql.com/, The @strong{MySQL} home page}
provides the latest information about @strong{MySQL}.
The following list describes some useful sections of the manual:
@itemize @bullet
@item
For a discussion of @strong{MySQL}'s capabilities, see @ref{Features}.
@item
For installation instructions, see @ref{Installing}. For tips on porting
@strong{MySQL} to new machines or operating systems, see @ref{Porting}.
@item
For information about upgrading from a 3.21 release, see
@ref{Upgrading-from-3.21}.
@item
For a tutorial introduction to @strong{MySQL}, see
@ref{Tutorial}.
@item
For examples of SQL and benchmarking information, see the benchmarking
directory (@file{sql-bench} in the distribution).
@item
For a history of new features and bug fixes, see @ref{News}.
@item
For a list of currently known bugs and misfeatures, see @ref{Bugs}.
@item
For future plans, see @ref{TODO}.
@item
For a list of all the contributors to this project, see @ref{Credits}.
@end itemize
@strong{IMPORTANT:}
@c if the @email is at the beginning of a line the texi2html fails
Reports of errors (often called bugs), as well as questions and comments
should be sent to the mailing list at @email{mysql@@lists.mysql.com}.
@xref{Bug reports}.
The @code{mysqlbug} script should be used to generate bug reports.
@c FIX! RPMs are also binary
For source distributions, the @code{mysqlbug} script can be found in the
@file{scripts} directory. For binary distributions, @code{mysqlbug} can
be found in the @file{bin} directory.
@c FIX! Remeber to create the alias!
If you have any suggestions concerning additions or corrections to this
manual, please send them to the manual team at
(@email{docs@@mysql.com}).
This is a reference manual; it does not provide general instruction on SQL
or relational database concepts. If you want general information about SQL,
see @ref{General-SQL}. For books that focus more specifically on
@strong{MySQL}, see @ref{MySQL-Books}.
@cindex @strong{MySQL}, what it is
@node What-is, Manual-info, Introduction, Introduction
@section What is MySQL
@table @asis
@item @strong{MySQL} is a database management system.
A database is a structured collection of data. It may be anything from a
simple shopping list to a picture gallery or the vast amounts of
information in a corporate network. To add, access and process data
stored in a computer database, you need a database management system
such as @strong{MySQL}. Since computers are very good at handling large
amounts of data, database management plays a central role in computing,
as stand-alone utilities or as parts of other applications.
@item @strong{MySQL} is a relational database management system.
A relational database stores data in separate tables rather than putting
all the data in one big storeroom. This adds speed and flexibility. The
tables are linked by defined relations making it possible to combine
data from several tables on request. The SQL part of @strong{MySQL}
stands for "Structured Query Language" - the most common standardized
language used to access databases.
@item @strong{MySQL} is Open Source Software
Open source means that it is possible to use and modify for
anyone. Anybody can download @strong{MySQL} from the Internet and use it
without paying anything. Anybody so inclined can study the source code
and change it to fit their needs. @strong{MySQL} uses the GPL (GNU
General Public License) @uref{http://www.gnu.org}, to define what You
may and may not do with the software in different situations. If you
feel uncomfortable with the GPL or need to embed @strong{MySQL} into a
commercial application you can buy a commercially licensed version from
us.
@item Why use @strong{MySQL}?
@strong{MySQL} is very fast, reliable and easy to use. If that is what
You are looking for you should give it a try. @strong{MySQL} also has a
very practical set of features developed in very close cooperation with
our users. You can find a performance comparison of @strong{MySQL}
to some other database managers on our benchmark page. @xref{Benchmarks}.
@strong{MySQL} was originally developed to handle very large databases
much faster than existing solutions and has been successfully used in
highly demanding production environments for several years. Though
under constant development, @strong{MySQL} today offers a rich and very
useful set of functions. The connectivity, speed and security makes
@strong{MySQL} highly suited for accessing databases on the Internet.
@item The technical features of @strong{MySQL}
For advanced technical information, @ref{Reference}. @strong{MySQL} is
a client/server system that consists of an multi-threaded SQL server
that supports different backends, several different client programs and
libraries, administrative tools and a programming interface.
@item @strong{MySQL} has a lot of contributed software available.
This makes it much more likely that you will find that your favorite
application/language already supports @strong{MySQL}.
@end table
@cindex How to pronounce @strong{MySQL}
@cindex @strong{MySQL}, how to pronounce
The official way to pronounce @strong{MySQL} is ``My Ess Que Ell'' (not
MY-SEQUEL). But we try to avoid correcting people who say MY-SEQUEL
@strong{MySQL} core values
We want @strong{MySQL} to be
@itemize @bullet
@item
The best and the most used database in the world
@item
Available to all and affordable for all
@item
Easy to use
@item
Continuously improved while remaining fast and safe
@item
Fun to use and fun to improve
@item
Free from bugs
@end itemize
@strong{MySQL AB} and the people of @strong{MySQL AB}
@itemize @bullet
@item
Promote Open Source Philosophy and support the Open Source Community
@item
Aims to be good citizens
@item
Prefer partners that share our values and mind-set
@item
Answer mail and give support
@item
Is a virtual company networking with others
@item
Work against software patents
@end itemize
@cindex Manual information
@node Manual-info, History, What-is, Introduction
@section About this manual
@menu
* Manual conventions:: Conventions used in this manual
@end menu
This manual is currently available in Texinfo, plain text, Info, HTML,
PostScript and PDF versions. Because of their size, PostScript and PDF
versions are not included with the main @strong{MySQL} distribution, but
are available for separate download at
@uref{http://www.mysql.com/}.
The primary document is the Texinfo file. The HTML version is produced
automatically using a modified version of @code{texi2html}. The plain
text and Info versions are produced with @code{makeinfo}. The Postscript
version is produced using @code{texi2dvi} and @code{dvips}. The PDF
version is produced with @code{pdftex}.
This manual is written and maintained by David Axmark, Michael (Monty)
Widenius and Paul DuBois. For other contributors, see @ref{Credits}.
@node Manual conventions, , Manual-info, Manual-info
@subsection Conventions used in this manual
This manual uses certain typographical conventions:
@table @asis
@item @code{constant}
Constant-width font is used for command names and options; SQL statements;
database, table and column names; C and Perl code; and environment variables.
Example: ``To see how @code{mysqladmin} works, invoke it with the
@code{--help} option.''
@item @file{filename}
Constant-width font with surrounding quotes is used for filenames and
pathnames. Example: ``The distribution is installed under the
@file{/usr/local/} directory.''
@item @samp{c}
Constant-width font with surrounding quotes is also used to indicate
character sequences. Example: ``To specify a wildcard, use the @samp{%}
character.''
@item @emph{italic}
Italic font is used for emphasis, @emph{like this}.
@item @strong{boldface}
Boldface font is used for access privilege names (e.g., ``do not grant the
@strong{process} privilege lightly'') and occasionally to convey
@strong{especially strong emphasis}.
@end table
When commands are shown that are meant to be executed by a particular
program, the program is indicated by the prompt shown with the command. For
example, @code{shell>} indicates a command that you execute from your login
shell, and @code{mysql>} indicates a command that you execute from the
@code{mysql} client program:
@example
shell> type a shell command here
mysql> type a mysql command here
@end example
Shell commands are shown using Bourne shell syntax. If you are using a
@code{csh}-style shell, you may need to issue commands slightly differently.
For example, the sequence to set an environment variable and run a command
looks like this in Bourne shell syntax:
@example
shell> VARNAME=value some_command
@end example
For @code{csh}, you would execute the sequence like this:
@example
shell> setenv VARNAME value
shell> some_command
@end example
Database, table and column names often must be substituted into commands. To
indicate that such substitution is necessary, this manual uses
@code{db_name}, @code{tbl_name} and @code{col_name}. For example, you might
see a statement like this:
@example
mysql> SELECT col_name FROM db_name.tbl_name;
@end example
This means that if you were to enter a similar statement, you would supply
your own database, table and column names, perhaps like this:
@example
mysql> SELECT author_name FROM biblio_db.author_list;
@end example
SQL statements may be written in uppercase or lowercase. When this manual
shows a SQL statement, uppercase is used for particular keywords if those
keywords are under discussion (to emphasize them) and lowercase is used for
the rest of the statement. For example, you might see the following in a
discussion of the @code{SELECT} statement:
@example
mysql> SELECT count(*) FROM tbl_name;
@end example
On the other hand, in a discussion of the @code{COUNT()} function, the
same statement would be written like this:
@example
mysql> select COUNT(*) from tbl_name;
@end example
If no particular emphasis is intended, all keywords are written uniformly
in uppercase.
In syntax descriptions, square brackets (@samp{[} and @samp{]}) are used
to indicate optional words or clauses:
@example
DROP TABLE [IF EXISTS] tbl_name
@end example
When a syntax element consists of a number of alternatives, the alternatives
are separated by vertical bars (@samp{|}). When one member from a set of
choices may be chosen, the alternatives are listed within square brackets
(@samp{[} and @samp{]}):
@example
TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
@end example
When one member from a set of choices must be chosen, the alternatives are
listed within braces (@samp{@{} and @samp{@}}):
@example
@{DESCRIBE | DESC@} tbl_name @{col_name | wild@}
@end example
@cindex @strong{MySQL} version
@node History, MySQL-Books, Manual-info, Introduction
@section History of MySQL
We once started out with the intention of using @code{mSQL} to connect to our
tables using our own fast low-level (ISAM) routines. However, after some
testing we came to the conclusion that @code{mSQL} was not fast enough or
flexible enough for our needs. This resulted in a new SQL interface to our
database but with almost the same API interface as @code{mSQL}. This API was
chosen to ease porting of third-party code.
The derivation of the name @strong{MySQL} is not perfectly clear. Our base
directory and a large number of our libraries and tools have had the prefix
``my'' for well over 10 years. However, Monty's daughter (some years younger)
is also named My. So which of the two gave its name to @strong{MySQL} is
still a mystery, even for us.
@node MySQL-Books, Features, History, Introduction
@section Books about MySQL
While this manual is still the right place for up to date techical
information, its primary goal is to contain everything there is to know
about @strong{MySQL}. And it is sometimes nice to have a bound book to read
in bed or while you travel. Here is a list of books about @strong{MySQL} (in
English).
@multitable @columnfractions .3 .7
@item Title @tab @uref{http://www2.newriders.com/cfm/prod_book.cfm?RecordID=584,MySQL}
@item Publisher @tab New Riders
@item Author @tab Paul DuBois
@item Pub Date @tab 1st Edition December 1999
@item ISBN @tab 0735709211
@item Pages @tab 800
@item Price @tab $49.99 US
@item Downloadable examples @tab @uref{http://www.mysql.com/Contrib/Examples/samp_db.tar.gz, @code{samp_db.tar.gz}}
@item Errata @tab @uref{http://www.mysql.com/documentation/pauls-mysql-book-errata.html, are available here}
@end multitable
Foreword by Michael ``Monty'' Widenius, @strong{MySQL} Moderator
In @strong{MySQL}, Paul DuBois provides you with a comprehensive guide to
one of the most popular relational database systems. Paul has
contributed to the online documentation for @strong{MySQL}, and is an
active member of the @strong{MySQL} community. The principal @strong{MySQL}
developer, Monty Widenius, and a network of his fellow developers
reviewed the manuscript, providing Paul with the kind of insight
no one else could supply.
Instead of merely giving you a general overview of @strong{MySQL}, Paul
teaches you how to make the most of its capabilities. Through two
sample database applications that run throughout the book, he
gives you solutions to problems you're sure to face. He helps you
integrate @strong{MySQL} efficiently with third-party tools, such as PHP
and Perl, enabling you to generate dynamic Web pages through
database queries. He teaches you to write programs that access
@strong{MySQL} databases, and also provides a comprehensive set of
references to column types, operators, functions, SQL syntax,
@strong{MySQL} programming, C API, Perl @code{DBI}, and PHP API.
@strong{MySQL} simply gives you the kind of information you won't find
anywhere else.
If you use @strong{MySQL}, this book provides you with:
@itemize @bullet
@item
An introduction to @strong{MySQL} and SQL
@item
Coverage of @strong{MySQL}'s data types and how to use them
@item
Thorough treatment of how to write client programs in C
@item
A guide to using the Perl @code{DBI} and PHP APIs for developing
command-line and Web-based applications
@item
Tips on administrative issues such as user accounts, backup,
crash recovery, and security
@item
Help in choosing an ISP for @strong{MySQL} access
@item
A comprehensive reference for @strong{MySQL}'s data types, operators,
functions, and SQL statements and utilities
@item
Complete reference guides for @strong{MySQL}'s C API, the Perl @code{DBI} API,
and PHP's @strong{MySQL}-related functions
@end itemize
@multitable @columnfractions .3 .7
@item Title @tab @uref{http://www.oreilly.com/catalog/msql/noframes.html,MySQL & mSQL}
@item Publisher @tab O'Reilly
@item Authors @tab Randy Jay Yarger, George Reese & Tim King
@item Pub Date @tab 1st Edition July 1999
@item ISBN @tab 1-56592-434-7, Order Number: 4347
@item Pages @tab 506
@item Price @tab $34.95
@end multitable
This book teaches you how to use @strong{MySQL} and @code{mSQL}, two popular and
robust database products that support key subsets of SQL on both Linux
and UNIX systems. Anyone who knows basic C, Java, Perl, or Python can
write a program to interact with a database, either as a stand-alone
application or through a Web page. This book takes you through the
whole process, from installation and configuration to programming
interfaces and basic administration. Includes ample tutorial
material.
@multitable @columnfractions .3 .7
@item Title @tab @uref{http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0672319144,Sams Teach Yourself MySQL in 21 Days}
@item Publisher @tab Sams
@item Authors @tab Mark Maslakowski and Tony Butcher
@item Pub Date @tab June 2000
@item ISBN @tab 0672319144
@item Pages @tab N/A
@item Price @tab $39.99
@end multitable
Sams Teach Yourself @strong{MySQL} in 21 Days is for intermediate Linux users
who want to move into databases. A large share of the audience to be web
developers needing a database to store large amounts of information that can
be retrieved via the Web. Sams Teach Yourself @strong{MySQL} in 21 Days is a
practical, step-by-step tutorial. The reader will learn to design and employ
this open source database technology into his/her web site using practical,
hands-on examples to follow.
@multitable @columnfractions .3 .7
@item Title @tab @uref{http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0761524452,E-Commerce Solutions with MySQL}
@item Publisher @tab Prima
@item Authors @tab N/A
@item Pub Date @tab September 2000
@item ISBN @tab 0761524452
@item Pages @tab 500
@item Price @tab $39.99
@end multitable
No description available.
@multitable @columnfractions .3 .7
@item Title @tab @uref{http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=1861004281,Professional MySQL Programming}
@item Publisher @tab Wrox
@item Authors @tab N/A
@item Pub Date @tab July 2000
@item ISBN @tab 1861004281
@item Pages @tab 1000
@item Price @tab $49.99
@end multitable
No description available.
@multitable @columnfractions .3 .7
@item Title @tab @uref{http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=0672317842,PHP3 and MySQL Web Development}
@item Publisher @tab N/A
@item Authors @tab William Jason Gilmore
@item Pub Date @tab October 2000
@item ISBN @tab 672317842
@item Pages @tab N/A
@item Price @tab $39.99
@end multitable
No description available.
@node Features, Stability, MySQL-Books, Introduction
@section The main features of MySQL
The following list describes some of the important characteristics
of @strong{MySQL}:
@c This list is too technical and should be divided into one feature
@c list comparable to commercial competition and a very technical on
@c with max limits (from crash-me) and so on.
@itemize @bullet
@item
Fully multi-threaded using kernel threads. That means it easily can
use multiple CPUs if available.
@item
C, C++, Eiffel, Java, Perl, PHP, Python and Tcl APIs. @xref{Clients}.
@item
Works on many different platforms. @xref{Which OS}.
@item
Many column types: signed/unsigned integers 1, 2, 3, 4 and 8 bytes
long, @code{FLOAT}, @code{DOUBLE}, @code{CHAR}, @code{VARCHAR},
@code{TEXT}, @code{BLOB}, @code{DATE}, @code{TIME}, @code{DATETIME},
@code{TIMESTAMP}, @code{YEAR}, @code{SET} and @code{ENUM} types. @xref{Column
types}.
@item
Very fast joins using an optimized one-sweep multi-join.
@item
Full operator and function support in the @code{SELECT} and @code{WHERE}
parts of queries. Example:
@example
mysql> SELECT CONCAT(first_name, " ", last_name) FROM tbl_name
WHERE income/dependents > 10000 AND age > 30;
@end example
@item
SQL functions are implemented through a highly-optimized class library and
should be as fast as they can get! Usually there shouldn't be any memory
allocation at all after query initialization.
@item
Full support for SQL @code{GROUP BY} and @code{ORDER BY}
clauses. Support for group functions (@code{COUNT()},
@code{COUNT(DISTINCT)}, @code{AVG()}, @code{STD()}, @code{SUM()},
@code{MAX()} and @code{MIN()}).
@item
Support for @code{LEFT OUTER JOIN} with ANSI SQL and ODBC syntax.
@item
You can mix tables from different databases in the same query (as of
version 3.22).
@item
A privilege and password system which is very flexible and secure, and
which allows host-based verification. Passwords are secure because all
password traffic when connecting to a server is encrypted.
@item
ODBC (Open-DataBase-Connectivity) support for Windows95 (with source). All
ODBC 2.5 functions and many others. For example, you can use Access to
connect to your @strong{MySQL} server. @xref{ODBC}.
@item
Very fast B-tree disk tables with index compression.
@item
16 indexes per table are allowed. Each index may consist of 1 to 16 columns
or parts of columns. The maximum index length is 256 bytes (this may be
changed when compiling @strong{MySQL}). An index may use a prefix of a
@code{CHAR} or @code{VARCHAR} field.
@item
Fixed-length and variable-length records.
@item
In-memory hash tables which are used as temporary tables.
@item
Handles large databases. We are using @strong{MySQL} with some
databases that contain 50,000,000 records.
@item
All columns have default values. You can use @code{INSERT} to insert a
subset of a table's columns; those columns that are not explicitly given
values are set to their default values.
@item
Uses GNU Automake, Autoconf, and @code{libtool} for portability.
@item
Written in C and C++. Tested with a broad range of different compilers.
@item
A very fast thread-based memory allocation system.
@item
No memory leaks. Tested with a commercial memory leakage detector
(@code{purify}).
@item
Includes @code{myisamchk}, a very fast utility for table checking, optimization
and repair.
@xref{Maintenance}.
@item
Full support for several different character sets, including
ISO-8859-1 (Latin1), big5, ujis, and more. For example, the
Scandinavian characters `@ringaccent{a}', `@"a' and `@"o' are allowed
in table and column names.
@item
All data are saved in the chosen character set. All comparisons for normal
string columns are case insensitive.
@item
Sorting is done according to the chosen character set (the Swedish
way by default). It is possible to change this when the @strong{MySQL} server
is started up. To see an example of very advanced sorting, look at the
Czech sorting code. @strong{MySQL} supports many different character sets
that can be specified at compile and run time.
@item
Aliases on tables and columns are allowed as in the SQL92 standard.
@item
@code{DELETE}, @code{INSERT}, @code{REPLACE}, and @code{UPDATE} return
how many rows were changed (affected). It is possible to return the number
of rows matched instead by setting a flag when connecting to the server.
@item
Function names do not clash with table or column names. For example, @code{ABS}
is a valid column name. The only restriction is that for a function call, no
spaces are allowed between the function name and the @samp{(} that follows it.
@xref{Reserved words}.
@item
All @strong{MySQL} programs can be invoked with the @code{--help} or @code{-?}
options to obtain online assistance.
@item
The server can provide error messages to clients in many
languages. @xref{Languages}.
@item
Clients may connect to the @strong{MySQL} server using TCP/IP connections or
Unix sockets, or named pipes under NT.
@item
The @strong{MySQL}-specific @code{SHOW} command can be used to retrieve
information about databases, tables and indexes. The @code{EXPLAIN} command
can be used to determine how the optimizer resolves a query.
@end itemize
@cindex Stability
@node Stability, Year 2000 compliance, Features, Introduction
@section How stable is MySQL?
This section addresses the questions, ``How stable is
@strong{MySQL}?'' and, ``Can I depend on @strong{MySQL} in this project?''
Here we will try to clarify some issues and to answer some of the more
important questions that seem to concern many people. This section has been
put together from information gathered from the mailing list (which is very
active in reporting bugs).
At TcX, @strong{MySQL} has worked without any problems in our projects since
mid-1996. When @strong{MySQL} was released to a wider public, we noticed that
there were some pieces of ``untested code'' that were quickly found by the
new users who made queries in a manner different than our own. Each new
release has had fewer portability problems than the previous one (even though
each has had many new features), and we hope that it will be possible to label
one of the next releases ``stable''.
Each release of @strong{MySQL} has been usable and there have been problems
only when users start to use code from ``the gray zones''. Naturally, outside
users can't know what the gray zones are; this section attempts to indicate
those that are currently known. The descriptions deal with the 3.22.x
version of @strong{MySQL}. All known and reported bugs are fixed in the
latest version, with the exception of the bugs listed in the bugs section,
which are things that are ``design''-related. @xref{Bugs}.
@strong{MySQL} is written in multiple layers and different independent
modules. These modules are listed below with an indication of how
well-tested each of them is:
@table @strong
@item The ISAM table handler --- Stable
This manages storage and retrieval of all data in @strong{MySQL} 3.22
and earlier versions. In all @strong{MySQL} releases there hasn't been a
single (reported) bug in this code. The only known way to get a
corrupted table is to kill the server in the middle of an update. Even
that is unlikely to destroy any data beyond rescue, because all data are
flushed to disk between each query. There hasn't been a single bug
report about lost data because of bugs in @strong{MySQL}, either.
@item The MyISAM table handler --- Beta
This is new in @strong{MySQL} 3.23. It's largely based on the ISAM table code
but has a lot of new very useful features.
@item The parser and lexical analyser --- Stable
There hasn't been a single reported bug in this system for a long time.
@item The C client code --- Stable
No known problems. In early 3.20 releases, there were some limitations in
the send/receive buffer size. As of 3.21.x, the buffer size is now dynamic up
to a default of 24M.
@item Standard client programs --- Stable
These include @code{mysql}, @code{mysqladmin} and @code{mysqlshow},
@code{mysqldump}, and @code{mysqlimport}.
@item Basic SQL --- Stable
The basic SQL function system and string classes and dynamic memory
handling. Not a single reported bug in this system.
@item Query optimizer --- Stable
@item Range optimizer --- Gamma
@item Join optimizer --- Stable
@item Locking --- Gamma
This is very system-dependent. On some systems there are big problems
using standard OS locking (@code{fcntl()}). In these cases, you should run the
@strong{MySQL} daemon with the @code{--skip-locking} flag. Problems are known
to occur on some Linux systems and on SunOS when using NFS-mounted file
systems.
@item Linux threads --- Gamma
The major problem found has been with the @code{fcntl()} call, which is
fixed by using the @w{@code{--skip-locking}} option to
@code{mysqld}. Some people have reported lockup problems with the 0.5
release. LinuxThreads will need to be recompiled if you plan to use
1000+ concurrent connections. Although it is possible to run that many
connections with the default LinuxThreads ( however, you will never go
above 1021 ), the default stack spacing of 2 MB makes the application
unstable, and we have been able to reproduce a coredump after creating
1021 idle connections. See Linux Notes for more details.
@item Solaris 2.5+ pthreads --- Stable
We use this for all our production work.
@item MIT-pthreads (Other systems) --- Gamma
There have been no reported bugs since 3.20.15 and no known bugs since
3.20.16. On some systems, there is a ``misfeature'' where some operations are
quite slow (a 1/20 second sleep is done between each query). Of course,
MIT-pthreads may slow down everything a bit, but index-based @code{SELECT}
statements are usually done in one time frame so there shouldn't be a mutex
locking/thread juggling.
@item Other thread implementions --- Alpha - Beta
The ports to other systems are still very new and may have bugs, possibly
in @strong{MySQL}, but most often in the thread implementation itself.
@item @code{LOAD DATA ...}, @code{INSERT ... SELECT} --- Stable
Some people have thought they have found bugs here, but these usually have
turned out to be misunderstandings. Please check the manual before reporting
problems!
@item @code{ALTER TABLE} --- Stable
Small changes in 3.22.12.
@item DBD --- Stable
Now maintained by Jochen Wiedmann
@email{wiedmann@@neckar-alb.de}. Thanks!
@item @code{mysqlaccess} --- Stable
Written and maintained by Yves Carlier
@email{Yves.Carlier@@rug.ac.be}. Thanks!
@item @code{GRANT} --- Gamma
Big changes made in @strong{MySQL} 3.22.12.
@item @strong{MyODBC} (uses ODBC SDK 2.5) --- Gamma
It seems to work well with some programs.
@end table
MySQL AB provides email support for paying customers, but the @strong{MySQL}
mailing list usually provides answers to common questions. Bugs are
usually fixed right away with a patch; for serious bugs, there is almost
always a new release.
@cindex Year 2000 compliance
@node Year 2000 compliance, General-SQL, Stability, Introduction
@section Year 2000 compliance
@strong{MySQL} itself has no problems with Year 2000 (Y2K) compliance:
@itemize @bullet
@item
@strong{MySQL} uses Unix time functions and has no problems with dates
until @code{2069}; all 2-digit years are regarded to be in the range
@code{1970} to @code{2069}, which means that if you store @code{01} in a
@code{year} column, @strong{MySQL} treats it as @code{2001}.
@item
All @strong{MySQL} date
functions are stored in one file @file{sql/time.cc} and coded very carefully
to be year 2000-safe.
@item
In @strong{MySQL} 3.22 and later versions, the new @code{YEAR} column type
can store years @code{0} and @code{1901} to @code{2155} in 1 byte and display
them using 2 or 4 digits.
@end itemize
You may run into problems with applications that use @strong{MySQL} in a
way that is not Y2K-safe. For example, many old applications store
or manipulate years using 2-digit values (which are ambiguous) rather than
4-digit values. This problem may be compounded by applications that use
values such as @code{00} or @code{99} as ``missing'' value indicators.
Unfortunately, these problems may be difficult to fix, because different
applications may be written by different programmers, each of whom may
use a different set of conventions and date-handling functions.
Here is a simple demonstration illustrating that @strong{MySQL} doesn't have
any problems with dates until the year 2030!
@example
mysql> DROP TABLE IF EXISTS y2k;
mysql> CREATE TABLE y2k (date date, date_time datetime, time_stamp timestamp);
mysql> INSERT INTO y2k VALUES ("1998-12-31","1998-12-31 23:59:59",19981231235959);
mysql> INSERT INTO y2k VALUES ("1999-01-01","1999-01-01 00:00:00",19990101000000);
mysql> INSERT INTO y2k VALUES ("1999-09-09","1999-09-09 23:59:59",19990909235959);
mysql> INSERT INTO y2k VALUES ("2000-01-01","2000-01-01 00:00:00",20000101000000);
mysql> INSERT INTO y2k VALUES ("2000-02-28","2000-02-28 00:00:00",20000228000000);
mysql> INSERT INTO y2k VALUES ("2000-02-29","2000-02-29 00:00:00",20000229000000);
mysql> INSERT INTO y2k VALUES ("2000-03-01","2000-03-01 00:00:00",20000301000000);
mysql> INSERT INTO y2k VALUES ("2000-12-31","2000-12-31 23:59:59",20001231235959);
mysql> INSERT INTO y2k VALUES ("2001-01-01","2001-01-01 00:00:00",20010101000000);
mysql> INSERT INTO y2k VALUES ("2004-12-31","2004-12-31 23:59:59",20041231235959);
mysql> INSERT INTO y2k VALUES ("2005-01-01","2005-01-01 00:00:00",20050101000000);
mysql> INSERT INTO y2k VALUES ("2030-01-01","2030-01-01 00:00:00",20300101000000);
mysql> INSERT INTO y2k VALUES ("2050-01-01","2050-01-01 00:00:00",20500101000000);
mysql> SELECT * FROM y2k;
+------------+---------------------+----------------+
| date | date_time | time_stamp |
+------------+---------------------+----------------+
| 1998-12-31 | 1998-12-31 23:59:59 | 19981231235959 |
| 1999-01-01 | 1999-01-01 00:00:00 | 19990101000000 |
| 1999-09-09 | 1999-09-09 23:59:59 | 19990909235959 |
| 2000-01-01 | 2000-01-01 00:00:00 | 20000101000000 |
| 2000-02-28 | 2000-02-28 00:00:00 | 20000228000000 |
| 2000-02-29 | 2000-02-29 00:00:00 | 20000229000000 |
| 2000-03-01 | 2000-03-01 00:00:00 | 20000301000000 |
| 2000-12-31 | 2000-12-31 23:59:59 | 20001231235959 |
| 2001-01-01 | 2001-01-01 00:00:00 | 20010101000000 |
| 2004-12-31 | 2004-12-31 23:59:59 | 20041231235959 |
| 2005-01-01 | 2005-01-01 00:00:00 | 20050101000000 |
| 2030-01-01 | 2030-01-01 00:00:00 | 20300101000000 |
| 2050-01-01 | 2050-01-01 00:00:00 | 00000000000000 |
+------------+---------------------+----------------+
13 rows in set (0.00 sec)
@end example
This shows that the @code{DATE} and @code{DATETIME} types are will not
give any problems with future dates (they handle dates until the year
9999).
The @code{TIMESTAMP} type, that is used to store the current time, has a
range up to only @code{2030-01-01}. @code{TIMESTAMP} has a range of
@code{1970} to @code{2030} on 32-bit machines (signed value). On 64-bit
machines it handles times up to @code{2106} (unsigned value).
Even though @strong{MySQL} is Y2K-compliant, it is your responsibility to
provide unambiguous input. See @ref{Y2K issues} for @strong{MySQL}'s rules
for dealing with ambiguous date input data (data containing 2-digit year
values).
@node General-SQL, Useful Links, Year 2000 compliance, Introduction
@section General SQL information and tutorials
This book has been recommended by a several people on the @strong{MySQL}
mailing list:
@example
Judith S. Bowman, Sandra L. Emerson and Marcy Darnovsky
The Practical SQL Handbook: Using Structured Query Language
Second Edition
Addison-Wesley
ISBN 0-201-62623-3
http://www.awl.com
@end example
This book has also received some recommendations by @strong{MySQL} users:
@example
Martin Gruber
Understanding SQL
ISBN 0-89588-644-8
Publisher Sybex 510 523 8233
Alameda, CA USA
@end example
A SQL tutorial is available on the net at
http://www.geocities.com/SiliconValley/Vista/2207/sql1.html
SQL in 21 Tagen (online book in German language):
http://www.mut.de/leseecke/buecher/sql/inhalt.htm
@node Useful Links, , General-SQL, Introduction
@section Useful MySQL-related links
Apart from the following links, you can find and download a lot of
@strong{MySQL} programs, tools and APIs from the
@uref{http://www.mysql.com/Contrib/, Contrib directory}.
@subheading Tutorials
@itemize @bullet
@item @uref{http://www.devshed.com/resource/advanced/mysql/index.html, A
beginner's tutorial of how to start using @strong{MySQL}}
@item @uref{http://www.analysisandsolutions.com/code/mybasic.htm}
Beginners @strong{MySQL} Tutorial on how to install and set up
@strong{MySQL} on a Windows machine.
@item @uref{http://www.devshed.com/Server_Side/MySQL/, A lot of @strong{MySQL} tutorials}
@item @uref{http://www.linuxplanet.com/linuxplanet/tutorials/1046/1/,
Setting Up a @strong{MySQL}-Based Website}
@item @uref{http://www.hotwired.com/webmonkey/backend/tutorials/tutorial1.html, @strong{MySQL}-Perl tutorial}
@item @uref{http://www.iserver.com/support/contrib/perl5/modules.html,Installing new Perl modules that require locally installed modules}
@item @uref{http://www.hotwired.com/webmonkey/databases/tutorials/tutorial4.html, PHP/@strong{MySQL} Tutorial}
@item @uref{http://www.useractive.com/, Hands on tutorial for @strong{MySQL}}
@end itemize
@subheading Porting MySQL / Using MySQL on different systems
@itemize @bullet
@item @uref{http://xclave.macnn.com/MySQL/,The MacOS Xclave}.
Running @strong{MySQL} on MacOSX
@item @uref{http://www.prnet.de/RegEx/mysql.html, MySql for MacOSX Server}
@item @uref{http://www.lilback.com/macsql/, Client libraries for the Macintosh}
@end itemize
@subheading Perl related links
@itemize @bullet
@item
@c Added 991122
@uref{http://haven.e-cactus.com/dbi_mysql, Perl DBI with @strong{MySQL} FAQ}
@end itemize
@subheading MySQL discussion forums
@itemize @bullet
@item
@uref{http://www.weberdev.com/, Examples using @strong{MySQL}; (check Top 20)}
@item
@uref{http://futurerealm.com/forum/futureforum.htm, FutureForum Web Discussion Software}
@end itemize
@c We should get longer descriptions for things in this category!
@subheading Commercial applications that support MySQL
@itemize @bullet
@item
@uref{http://www.supportwizard.com/, SupportWizard; Interactive helpdesk
on the web (This product includes a licensed copy of @strong{MySQL})}
@item
@uref{http://www.stweb.org/, StWeb}
StWeb - Stratos Web and Application server - an easy-to-use, cross
platform, Internet/Intranet development and deployment system for
development of web-enabled applications. The standard version of StWeb
has a native interface to @strong{MySQL} database.
@item
@uref{http://www.rightnowtech.com/, Right Now Web; Web automation for customer service}
@item
@uref{http://www.icaap.org/Bazaar/, Bazaar; Interactive Discussion Forums with web interface}
@item
@uref{http://www.phonesweep.com/, PhoneSweepT} is the world's first
commercial Telephone Scanner. Many break-ins in recent years have come
not through the Internet, but through unauthorized dial-up
modems. PhoneSweep lets you find these modems by repeatedly placing
phone calls to every phone number that your organization
controls. PhoneSweep has a built-in expert system that can recognize
more than 250 different kinds of remote-access programs, including
Carbon Copy(TM), pcANYWHERE(TM), and Windows NT RAS. All information is stored
in the SQL database. It then generates a comprehensive report detailing
which services were discovered on which dial-up numbers in your
organization.
@end itemize
@subheading SQL Clients/Report writers
@itemize @bullet
@item
@uref{http://www.urbanresearch.com/software/utils/urbsql/index.html,
@strong{MySQL} Editor/Utility for MS Windows Platforms.}
@item
@uref{http://www.xnot.com/kmysql, KDE @strong{MySQL} client}
@item
@c EMAIL: bilhaut_f@mail.cpod.fr (Frédérik Bilhaut)
@uref{http://www.penguinpowered.com/~kmysql, KMySQL}
KMySQL is a database client for KDE that primarily supports @strong{MySQL}.
@item
@uref{http://www.ecker-software.de, Win32 GUI client}
A Win32 GUI client by David Ecker.
@item
@uref{http://www.icaap.org/software/kiosk/, Kiosk; a @strong{MySQL} client for
database management}. Written in Perl. Will be a part of Bazaar.
@item
@uref{http://www.geocities.com/SiliconValley/Ridge/4280/GenericReportWriter/grwhome.html, A free report writer in Java}
@item
@uref{http://www.javaframework.de,MySQLExport}
Export of @strong{MySQL} create statements and data in a lot of
different formats (SQL, HTML, CVS, text, ZIP, GZIP...)
@end itemize
@subheading Distributions that include MySQL
@itemize @bullet
@item
@uref{http://www.suse.com/, SuSE Linux (Suse 6.1 and above)}
@end itemize
@subheading Web development tools that support @strong{MySQL}
@itemize @bullet
@item
@uref{http://www.php.net/, PHP: A server-side HTML-embedded scripting
language}
@item
@uref{http://www.midgard-project.org, The Midgard Application Server; a
powerful Web development environment based on @strong{MySQL} and PHP}
@item
@uref{http://www.smartworker.org, SmartWorker is a platform for web application development}
@item
@uref{http://xsp.lentus.se/, XSP: e(X)tendible (S)erver (P)ages and is a
HTML embedded tag language written in Java (previously known as XTAGS)}
@item
@uref{http://www.dbServ.de/, dbServ} is an extension to a web server to
integrate databases output into your HTML code. You may use any HTML
function in your output. Only the client will stop you. It works as
standalone server or as JAVA servlet.
@item
@uref{http://www.chilisoft.com/, Platform independent ASP from Chili!Soft}
@c @item
@c no answer from server 990830
@c @uref{http://www.voicenet.com/~zellert/tjFM, A JDBC driver for @strong{MySQL}}
@item
@uref{http://www.wernhart.priv.at/php/, @strong{MySQL} + PHP demos}
@item
@uref{http://www.dbwww.com/, ForwardSQL: HTML interface to manipulate @strong{MySQL} databases}
@item
@uref{http://www.daa.com.au/~james/www-sql/, WWW-SQL: Display database
information}
@item
@uref{http://www.minivend.com/minivend/, Minivend: A Web shopping cart}
@item
@uref{http://www.heitml.com/, HeiTML: A server-side extension of HTML and
a 4GL language at the same time}
@item
@uref{http://www.metahtml.com/, Metahtml: A Dynamic Programming Language
for WWW Applications}
@item
@uref{http://www.binevolve.com/, VelocityGen for Perl and Tcl}
@item
@uref{http://hawkeye.net/, Hawkeye Internet Server Suite}
@item
@uref{http://www.fastflow.com/, Network Database Connection For Linux}
@item
@uref{http://www.wdbi.net/,
WDBI: Web browser as a universal front end to databases which supports
@strong{MySQL} well.}
@item
@uref{http://www.webgroove.com/, WebGroove Script: HTML compiler and server-side scripting language}
@item
@uref{http://www.ihtml.com/, A server-side web site scripting language}
@item
@uref{ftp://ftp.igc.apc.org/pub/myodbc/README, How to use @strong{MySQL} with ColdFusion on Solaris}
@item
@uref{http://calistra.com/MySQL/,Calistra's ODBC @strong{MySQL} Administrator}
@item
@uref{http://www.webmerger.com, Webmerger}
This CGI tool interprets files and generates dynamic output
based on a set of simple tags. Ready-to-run drivers for @strong{MySQL} and PostgreSQL
through ODBC.
@item
@uref{http://phpclub.unet.ru/index_e.php3, PHPclub}. Tips and tricks for PHP
@item
@uref{http://www.penguinservices.com/scripts, @strong{MySQL} and Perl Scripts}
@item
@uref{http://www.widgetchuck.com, The Widgetchuck; Web Site Tools and Gadgets}
@item
@uref{http://www.adcycle.com/, AdCycle} advertising management software
@item
@uref{http://www.bidsystems.com/pwPage, pwPage} provides an extremely
fast and simple approach to the creation of database forms. That is,
if a database table exists and an HTML page has been constructed using
a few simple guidelines, pwPage can be immediately used for table data
selections, insertions, updates, deletions and selectable table content
reviewing.
@item
@uref{http://www.omnis-software.com/products/studio/studio.html, OMNIS}
OMNIS Studio is a rapid application development (RAD) tool.
@end itemize
@subheading Database design tools with MySQL support
@itemize @bullet
@item
@uref{http://www.mysql.com/dezign/index.html, "DeZign for
databases" is a database development tool using an
entity relationship diagram (ERD).}
@end itemize
@subheading Web servers with @strong{MySQL} tools
@itemize @bullet
@item
@uref{http://bourbon.netvision.net.il/mysql/mod_auth_mysql/, An Apache
authentication module}
@item
@uref{http://www.roxen.com/, The Roxen Challenger Web server}
@end itemize
@subheading Extensions for other programs
@itemize @bullet
@item
@uref{http://www.seawood.org/msql_bind/, @strong{MySQL} support for BIND
(The Internet Domain Name Server)}
@item
@uref{http://www.inet-interactive.com/sendmail, @strong{MySQL} support for
Sendmail and Procmail}
@end itemize
@subheading Using @code{MySQL} with other programs
@itemize @bullet
@item
@uref{http://www.iserver.com/support/addonhelp/database/mysql/msaccess.html, Using @strong{MySQL} with Access}
@item
@uref{http://www.iserver.com/support/contrib/perl5/modules.html,Installing new Perl modules that require locally installed modules}
@end itemize
@subheading ODBC related links
@itemize @bullet
@item
@uref{http://www.iodbc.org/,Popular iODBC Driver Manager (libiodbc) now available in Open Source format}
@item
@uref{http://users.ids.net/~bjepson/freeODBC/,The FreeODBC Pages}
@item
@uref{http:/http://genix.net/unixODBC/,unixodbc}
The unixODBC Project goals are to develop and promote unixODBC to be the
definitive standard for ODBC on the Linux platform.
This is to include GUI support for KDE.
@item
@uref{http://www.sw-soft.com/products/BtrieveODBC/}
A @strong{MySQL}-based ODBC drivers for Btrieve
@end itemize
@subheading @strong{API} related links
@itemize @bullet
@item
@uref{http://www.amedea.cz/mysqlx/index.html, MySQL COM extension}
With this COM objects You can use MySQL also on Windows platform with ASP
pages or Delphi, Visual Basic, Visual C++, ... languages.
@item
@uref{http://www.jppp.com, www.jppp.com}
Partially implemented TDataset-compatible components for @strong{MySQL}.
@item
@uref{http://www.riverstyx.net/qpopmysql/,qpopmysql}
A patch to allow POP3 authentication from a @strong{MySQL} database.
There's also a link to Paul Khavkine's patch for Procmail to allow
any MTA to deliver to users in a @strong{MySQL} database.
@item
@uref{http://www.pbc.ottawa.on.ca,Visual Basic class generator for Active X}
@item
@uref{http://www.lilback.com/macsql/, Client libraries for the Macintosh}
@c @item
@c @uref{http://tfdec1.fys.kuleuven.ac.be/~michael/fpc-linux/mysql,
@c @strong{MySQL} binding to Free Pascal}
@item
@uref{http://www.dedecker.net/jessie/scmdb/, SCMDB}.
SCMDB is an add-on for SCM that ports the mysql C library to scheme (SCM).
With this library scheme developers can make connections to a mySQL
database and use embedded SQL in their programs.
@end itemize
@subheading Other @strong{MySQL}-related links
@itemize @bullet
@item
@uref{http://www.wix.com/mysql-hosting, Registry of Web providers who
support @strong{MySQL}}
@item
@uref{http://www.softagency.co.jp/mysql/index.en.phtml, Links about using
@strong{MySQL} in Japan/Asia}
@item
@uref{http://www.open.com.au/products.html, Commercial Web defect tracking
system}
@item
@uref{http://www.stonekeep.com/pts/, PTS: Project Tracking System}
@item
@uref{http://tomato.nvgc.vt.edu/~hroberts/mot, Job and software tracking
system}
@c @item
@c Error 404 990830
@c @uref{http://home.wxs.nl/cgi-bin/planeteers/pgidszoek.cgi, Full-text search engine using @strong{MySQL}}
@item
@uref{http://www.cynergi.net/non-secure/exportsql/, ExportSQL: A script
to export data from Access95+}
@item
@uref{http://SAL.KachinaTech.COM/H/1/MYSQL.html, SAL (Scientific
Applications on Linux) @strong{MySQL} entry}
@c Removed 990510
@c @item
@c @uref{http://www.cgishop.com/bin/mysqllist, @strong{MySQL} Apps and
@c Utilities Listing}
@c @item
@c @uref{http://www.luth.se/~goggi/proj/mysql/man/mysql.pdf, The
@c @strong{MySQL} reference manual in Adobe PDF format}
@item
@uref{http://www.infotech-nj.com/itech/index.shtml, A consulting company
which mentions @strong{MySQL} in the right company}
@item
@uref{http://www.pmpcs.com/, PMP Computer Solutions. Database developers using
@strong{MySQL} and @code{mSQL}}
@item
@uref{http://www.aewa.org, Airborne Early Warning Association }
@item
@uref{http://abattoir.cc.ndsu.nodak.edu/~nem/mysql/udf/, @strong{MySQL} UDF Registry}
@item
@uref{http://21ccs.com/~gboersm/y2kmatrix/, Y2K tester}
@end itemize
@subheading SQL and database interfaces
@itemize @bullet
@item
@uref{http://java.sun.com/products/jdbc/, The JDBC database access API}
@item
@uref{http://www.gagme.com/mysql, Patch for @code{mSQL} Tcl}
@item
@uref{http://www.amsoft.ru/easysql/, EasySQL: An ODBC-like driver manager}
@item
@uref{http://www.lightlink.com/hessling/rexxsql.html, A REXX interface to SQL databases}
@item
@uref{http://www.binevolve.com/~tdarugar/tcl-sql, Tcl interface}
@end itemize
@subheading Examples of MySQL use
@itemize @bullet
@item
@c Added 990601
@c EMAIL: thuss@little6.com (Todd Huss)
@uref{http://www.little6.com/about/linux/, Little6 Inc} An online contract and job finding site that is powered by @strong{MySQL}, PHP3 and Linux.
@item
@c Added 990521
@c EMAIL: nh@delec.com (Hillbrecht Nicole)
@uref{http://www.delec.com/is/products/prep/examples/BookShelf/index.html, DELECis} A tool which makes it very easy to create an automatically generated table documentation. They have used @strong{MySQL} as an example.
@c @item
@c Added 990531. Removed 000201 -> No answer from server
@c EMAIL: sfambro@hotmail.com (Steve Fambro)
@c @uref{http://shredder.elen.utah.edu/steve.html, Steve Fambro}
@c Uses @strong{MySQL} and webmerger. There is an employee database, and a
@c license plate database with all of the registered Utah vehicles (over
@c 1.2 million). The License plate field is indexed.....so the *searches*
@c are instantaneous.
@item
@c Added 990521
@c EMAIL: info@worldrecords.com (Jim Rota)
@uref{http://www.worldrecords.com, World Records} A search engine for information about music that uses @strong{MySQL} and PHP.
@item
@uref{http://www.webtechniques.com/archives/1998/01/note/,
A Contact Database using @strong{MySQL} and PHP}
@item
@uref{http://modems.rosenet.net/mysql/, Web based interface and Community Calender with PHP}
@item
@uref{http://www.odbsoft.com/cook/sources.htm, Perl package to generate html from a SQL table structure and for generating SQL statements from an html form.}
@item
@uref{http://www.gusnet.cx/proj/telsql/,Basic telephone database using @code{DBI}/@code{DBD}}.
@item
@uref{http://tecfa.unige.ch/guides/java/staf2x/ex/jdbc/coffee-break, JDBC examples by Daniel K. Schneider}
@item
@uref{http://www.spade.com/linux/howto/PostgreSQL-HOWTO-41.html,SQL BNF}
@item
@uref{http://www.ooc.com/, Object Oriented Concepts Inc; CORBA applications with examples in source}
@item
@uref{http://www.pbc.ottawa.on.ca/,DBWiz; Includes an example of how to manage own cursors in VB}
@item
@uref{http://keilor.cs.umass.edu/pluribus/, Pluribus}
Pluribus, is a free search engine that learns to improve
the quality of its results over time. Pluribus works by recording
which pages a user prefers among those returned for a query. A user
votes for a page by selecting it; Pluribus then uses that knowledge
to improve the quality of the results when someone else submits the
same (or similar) query. Uses PHP and @strong{MySQL}.
@item
@c EMAIL: paul@sword.damocles.com (Paul Bannister)
@uref{http://www.stopbit.com/, Stopbit}
A technology news site using @strong{MySQL} and PHP
@item
@c Added 990604
@c EMAIL: ah@dybdahl.dk
@uref{http://www.jokes2000.com/scripts/, Example scripts at Jokes2000}
@item
@uref{http://www.linuxsupportline.com/~kalendar/ KDE based calendar manager}
The calendar manager has both single user (file based) and multi user
(@strong{MySQL} database) support.
@item
@uref{http://tim.desert.net/~tim/imger/,Example of storing/retrieving images with @strong{MySQL} and CGI}
@item
@uref{http://www.penguinservices.com/scripts, Online shopping cart system}
@item
@c Added 990928 from editor@city-gallery.com
@uref{http://www.city-gallery.com/album/, Old Photo Album}
The album is a collaborative popular history of photography project that
generates all pages from data stored in a @strong{MySQL} database. Pages are
dynamically generated through a php3 interface to the database content.
Users contribute images and descriptions. Contributed images are stored
on the web server to avoid storing them in the database as BLOBs. All
other information is stored in on the shared @strong{MySQL} server.
@end itemize
@subheading General database links
@itemize @bullet
@item
@uref{http://www.pcslink.com/~ej/dbweb.html, Database Jump Site}
@item
@uref{http://black.hole-in-the.net/guy/webdb/, Homepage of the webdb-l
(Web Databases) mailing list.}
@item
@uref{http://www.symbolstone.org/technology/perl/DBI/index.html,
Perl @code{DBI}/@code{DBD} modules homepage}
@item
@uref{http://www.student.uni-koeln.de/cygwin/, Cygwin tools. UNIX on top of Windows}
@item
@uref{http://dbasecentral.com/, dbasecentral.com; Development and distribution of powerful and easy-to-use database applications and systems.}
@item
@uref{http://www.Tek-Tips.com, Tek-Tips Forums} Tek-Tips Forums are 800+
independent peer-to-peer non-commercial support forums for Computer
Professionals. Features include automatic e-mail notification of
responses, a links library, and member confidentiality guaranteed.
@end itemize
There are also many web pages that use
@strong{MySQL}. @xref{Users}. Send any additions to this list to
@email{webmaster@@mysql.com}. We now require that you show a
@strong{MySQL} logo somewhere (It is okay to have it on a ``used tools'' page
or something similar) to be added.
@cindex Reporting errors
@cindex @strong{MySQL} mailing lists
@node Questions, Licensing and Support, Introduction, Top
@chapter MySQL mailing lists and how to ask questions or report errors (bugs)
@menu
* Mailing-list:: The @strong{MySQL} mailing lists
* Asking questions:: Asking questions or reporting bugs
* Bug reports:: How to report bugs or problems
* Answering questions:: Guidelines for answering questions on the mailing list
@end menu
@node Mailing-list, Asking questions, Questions, Questions
@section The MySQL mailing lists
To subscribe to the main @strong{MySQL} mailing list, send a message to the
electronic mail address @email{mysql-subscribe@@lists.mysql.com}.
To unsubscribe from the main @strong{MySQL} mailing list, send a message to
the electronic mail address @email{mysql-unsubscribe@@lists.mysql.com}.
Only the address to which you send your messages is significant. The
subject line and the body of the message are ignored.
@c the last two addresses in this paragraph are NOT @email because they
@c shouldn't be live links.
If your reply address is not valid, you can specify your address explicitly.
Adding a hyphen to the subscribe or unsubscribe command word, followed by
your address with the @samp{@@} character in your address replaced by a
@samp{=}. For example, to subscribe @code{john@@host.domain}, send a message
to @code{mysql-subscribe-john=host.domain@@lists.mysql.com}.
Mail to @email{mysql-subscribe@@lists.mysql.com} or
@email{mysql-unsubscribe@@lists.mysql.com} is handled automatically by the
ezmlm mailing list processor. Information about ezmlm is available at
@uref{http://www.ezmlm.org, The ezmlm Website}.
To post a message to the list itself, send your message to
@code{mysql@@lists.mysql.com}. However, please @emph{do not} send mail about
subscribing or unsubscribing to @email{mysql@@lists.mysql.com}, because any
mail sent to that address is distributed automatically to thousands of other
users.
Your local site may have many subscribers to @email{mysql@@lists.mysql.com}.
If so, it may have a local mailing list, so that messages sent from
@code{lists.mysql.com} to your site are propagated to the local list. In such
cases, please contact your system administrator to be added to or dropped
from the local @strong{MySQL} list.
The following @strong{MySQL} mailing lists exist:
@table @code
@item announce
This is for announcement of new versions of @strong{MySQL} and related
programs. This is a low volume list that we think all @strong{MySQL}
users should be on.
@item mysql
The main list for general @strong{MySQL} discussion. Please note that some
topics are better discussed on the more-specialized lists. If you post to the
wrong list, you may not get an answer!
@item mysql-digest
The @code{mysql} list in digest form. That means you get all individual
messages, sent as one large mail message once a day.
@item bugs
On this list you should only post a full, repeatable bug report, using
the @code{mysqlbug} script (if you are running on Windows, you should
include a description of the operating system and the @strong{MySQL} version).
Preferably, you should test the problem using the latest stable or
development version of @strong{MySQL} before posting!
Anyone should be able to repeat the bug by just using 'mysql test <
script' on the included test case. All bugs posted on this list will be
corrected or documented in the next @strong{MySQL} release! If there are only
small code changes involved, we will also post a patch that fixes the problem.
@item bugs-digest
The @code{bugs} list in digest form
@item developer
A list for people who work on the @strong{MySQL} code. On this list one
can also discuss @strong{MySQL} development and post patches.
@item developer-digest
A digest version of the @code{developer} list.
@item java
Discussion about @strong{MySQL} and Java. Mostly about the JDBC drivers.
@item java-digest
A digest version of the @code{java} list.
@item win32
All things concerning @strong{MySQL} on Microsoft operating systems such as
Windows NT.
@item win32-digest
A digest version of the @code{win32} list.
@item myodbc
All things concerning connecting to @strong{MySQL} with ODBC.
@item myodbc-digest
A digest version of the @code{myodbc} list.
@item plusplus
All things concerning programming with the C++ API to @strong{MySQL}.
@item plusplus-digest
A digest version of the @code{plusplus} list.
@item msql-mysql-modules
A list about the Perl support in @strong{MySQL}.
@item msql-mysql-modules-digest
A digest version of the @code{msql-mysql-modules} list.
@end table
You subscribe or unsubscribe to all lists in the same way as described
above. In your subscribe or unsubscribe message, just put the appropriate
mailing list name rather than @code{mysql}. For example, to subscribe to or
unsubscribe from the @code{myodbc} list, send a message to
@email{myodbc-subscribe@@lists.mysql.com} or
@email{myodbc-unsubscribe@@lists.mysql.com}.
@cindex Net etiquette
@node Asking questions, Bug reports, Mailing-list, Questions
@section Asking questions or reporting bugs
Before posting a bug report or question, please do the following:
@itemize @bullet
@item
Start by searching the @strong{MySQL} online manual at:
@example
@uref{http://www.mysql.com/documentation/manual.php}
@end example
We try to keep the manual up to date by
updating it frequently with solutions to newly found problems!
@item
Search the @strong{MySQL} mailing list archives:
@example
@uref{http://www.mysql.com/documentation/}
@end example
@item
You can also use @uref{http://www.mysql.com/search.html} to search all the
web pages (including the manual) that are located at
@uref{http://www.mysql.com/}.
@end itemize
If you can't find an answer in the manual or the archives, check with your
local @strong{MySQL} expert. If you still can't find an answer to your
question, go ahead and read the next section about how to send mail to
@email{mysql@@lists.mysql.com}.
@cindex Bug reports
@cindex Reporting bugs
@node Bug reports, Answering questions, Asking questions, Questions
@section How to report bugs or problems
Writing a good bug report takes patience, but doing it right the first
time saves time for us and for you. A good bug report containing a full
test case for the bug will make it very likely that we will fix it in
the next release. This section will help you write your report correctly
so that you don't waste your time doing things that may not help us much
or at all.
We encourage everyone to use the @code{mysqlbug} script to generate a bug
report (or a report about any problem), if possible. @code{mysqlbug} can be
found in the @file{scripts} directory in the source distribution, or, for a
binary distribution, in the @file{bin} directory under your @strong{MySQL}
installation directory. If you are unable to use @code{mysqlbug}, you should
still include all the necessary information listed in this section.
The @code{mysqlbug} script helps you generate a report by determining much
of the following information automatically, but if something important is
missing, please include it with your message! Please read this section
carefully and make sure that all the information described here is included
in your report.
If you can make a test case which clearly shows the bug, you should post
it to the @email{bugs@@list.mysql.com} list. Note that on this list you
should only post a full, repeatable bug report, using the @code{mysqlbug}
script (if you are running on Windows, you should include a
description of the operating system and the @strong{MySQL} version).
Preferably, you should test the problem using the latest stable or development
version of @strong{MySQL} before posting! Anyone should be able to repeat the
bug by just using 'mysql test < script' on the included test case or run
the shell / perl script that is included in the bug report. All bugs
posted on this list will be corrected or documented in the next @strong{MySQL}
release! If there are only small code changes involved, to correct this
problem, we will also post a patch that fixes the problem.
Remember that it is possible to respond to a message containing too much
information, but not to one containing too little. Often people omit facts
because they think they know the cause of a problem and assume that some
details don't matter. A good principle is: if you are in doubt about stating
something, state it! It is a thousand times faster and less troublesome to
write a couple of lines more in your report than to be forced to ask again
and wait for the answer because you didn't include enough information the
first time.
The most common errors are that people don't indicate the version number of
the @strong{MySQL} distribution they are using, or don't indicate what
platform they have @strong{MySQL} installed on (including the platform
version number). This is highly relevant information and in 99 cases out of
100 the bug report is useless without it! Very often we get questions like
``Why doesn't this work for me?'' and then we find that the feature
requested wasn't implemented in that @strong{MySQL} version, or that a bug
described in a report has been fixed already in newer @strong{MySQL}
versions. Sometimes the error is platform dependent; in such cases, it is
next to impossible to fix anything without knowing the operating system and
the version number of the platform.
Remember also to provide information about your compiler, if it is related to
the problem. Often people find bugs in compilers and think the problem is
@strong{MySQL} related. Most compilers are under development all the time and
become better version by version, too. To determine whether or not your
problem depends on your compiler, we need to know what compiler is used.
Note that every compiling problem should be regarded as a bug report and
reported accordingly.
It is most helpful when a good description of the problem is included in the
bug report. That is, a good example of all the things you did that led to
the problem and the problem itself exactly described. The best reports are
those that include a full example showing how to reproduce the bug or
problem.
If a program produces an error message, it is very important to include the
message in your report! If we try to search for something from the archives
using programs, it is better that the error message reported exactly matches
the one that the program produces. (Even the case sensitivity should be
observed!) You should never try to remember what the error message was;
instead, copy and paste the entire message into your report!
If you have a problem with MyODBC, you should try to genereate a MyODBC
trace file. @xref{MyODBC bug report}.
Please remember that many of the people who will read your report will
do so using an 80-column display. When generating reports or examples
using the @code{mysql} command line tool, you should therefore use
the @code{--vertical} option (or the @code{\G} statement terminator)
for output which would exceed the available width for such a display
(for example, with the @code{EXPLAIN SELECT} statement; see the
example below).
Please include the following information in your report:
@itemize @bullet
@item
The version number of the @strong{MySQL} distribution you are using (for
example, @strong{MySQL} 3.22.22). You can find out which version you are
running by executing @code{mysqladmin version}. @code{mysqladmin} can be
found in the @file{bin} directory under your @strong{MySQL} installation
directory.
@item
The manufacturer and model of the machine you are working on.
@item
The operating system name and version. For most operating systems, you can
get this information by executing the Unix command @code{uname -a}.
@item
Sometimes the amount of memory (real and virtual) is relevant.
If in doubt, include these values.
@item
If you are using a source distribution of @strong{MySQL}, the name and
version number of the compiler used is needed.
If you have a binary distribution, the distribution name is needed.
@item
If the problem occurs during compilation, include the exact error
message(s) and also a few lines of context around the offending code in the
file where the error occurred.
@item
If any database table is related to the problem, include the output from
@code{mysqldump --no-data db_name tbl_name1 tbl_name2 ...} This is very easy
to do and is a powerful way to get information about any table in a database
that will help us create a situation matching the one you have.
@item
For speed-related bugs or problems with @code{SELECT} statements, you should
always include the output of @code{EXPLAIN SELECT ...}, and at least the
number of rows that the @code{SELECT} statement produces. The more
information you give about your situation, the more likely it is that someone
can help you! For example, the following is an example of a very good bug
report (it should of course be posted with the @code{mysqlbug} script):
Example run using the @code{mysql} command line tool (note the use of the
@code{\G} statement terminator for statements whose output width would
otherwise exceed that of an 80-column display device):
@example
mysql> SHOW VARIABLES;
mysql> SHOW COLUMNS FROM ...\G
<output-from-SHOW-COLUMNS>
mysql> EXPLAIN SELECT ...\G
<output-from-EXPLAIN>
mysql> FLUSH STATUS;
mysql> SELECT ...;
<A short version of the output from SELECT,
including the time taken to run the query>
mysql> SHOW STATUS;
<output from SHOW STATUS>
@end example
@item
If a bug or problem occurs while running @strong{MySQL}, try to provide an
input script that will reproduce the anomaly. This script should include any
necessary source files. The more closely the script can reproduce your
situation, the better.
If you can't provide a script, you should at least include the output
from @code{mysqladmin variables extended-status processlist} in your mail to
provide some information of how your system is performing!
@item
If you think that @strong{MySQL} produces a strange result from a query,
include not only the result, but also your opinion of what the result
should be and an account describing the basis for your opinion.
@item
When giving an example of the problem, it's better to use the variable names,
table names, etc., that exist in your actual situation than to come up with
new names. The problem could be related to the name of a variable, table,
etc.! These cases are rare, perhaps, but it is better to be safe than
sorry. After all, it should be easier for you to provide an example that
uses your actual situation and it is by all means better for us. In case you
have data you don't want to show to others, you can use @code{ftp} to
transfer it to @uref{ftp://support.mysql.com/pub/mysql/secret/}. If the data are
really top secret and you don't want to show them even to us, then go ahead
and provide an example using other names, but please regard this as the last
choice.
@item
Include all the options given to the relevant programs, if possible. For
example, indicate the options that you use when you start the @code{mysqld}
daemon and that you use to run any @strong{MySQL} client programs. The
options to programs like @code{mysqld} and @code{mysql}, and to the
@code{configure} script are often keys to answers and very relevant! It is
never a bad idea to include them anyway! If you use any modules, such as
Perl or PHP, please include the version number(s) of those as well.
@item
If you can't produce a test case in a few rows, or if the test table
is too big to be mailed to the mailing list (more than 10 rows), you should
dump your tables using @code{mysqldump} and create a @file{README} file
that describes your problem.
Create a compressed archive of your files using
@code{tar} and @code{gzip} or @code{zip}, and use @code{ftp}
to transfer the archive to @uref{ftp://support.mysql.com/pub/mysql/secret/}.
Then send a short description of the problem to @email{mysql@@lists.mysql.com}.
@item
If your question is related to the privilege system, please include the
output of @code{mysqlaccess}, the output of @code{mysqladmin reload} and all
the error messages you get when trying to connect! When you test your
privileges, you should first run @code{mysqlaccess}. After this, execute
@code{mysqladmin reload version}, and last you should try to connect with the
program that gives you trouble. @code{mysqlaccess} can be found in the
@file{bin} directory under your @strong{MySQL} installation directory.
@item
If you have a patch for a bug, that is good, but don't assume the patch is
all we need, or that we will use it even if you don't provide some necessary
information such as test cases showing the bug that your patch fixes. We
might find problems with your patch or we might not understand it at all; if
so, we can't use it.
If we can't verify exactly what the patch is meant for, we won't use it.
Test cases will help us here. Show that the patch will handle all the
situations that may occur. If we find a borderline case (even a rare one)
where the patch won't work, the patch may be useless.
@item
Guesses about what the bug is, why it occurs, or what it depends on,
are usually wrong. Even we can't guess such things without first
using a debugger to determine the real cause of a bug.
@item
Indicate in your mail message that you have checked the reference manual
and mail archive so others know that you have tried to solve your
problem yourself.
@item
If you get a @code{parse error}, please check your syntax closely! If
you can't find something wrong with it, it's extremely likely that your
current version of @strong{MySQL} doesn't support the query you are
using. If you are using the current version and the manual at
@uref{http://www.mysql.com/documentation/manual.php} doesn't cover the syntax you are
using, @strong{MySQL} doesn't support your query. In this case, your
only options are to implement the syntax yourself or email
@email{mysql-licensing@@mysql.com} and ask for an offer to implement it!
If the manual covers the syntax you are using, but you have an older version
of @strong{MySQL}, you should check the @strong{MySQL} change history to see
when the syntax was implemented. @xref{News}. In this case, you have the
option of upgrading to a newer version of @strong{MySQL}.
@item
If you have a problem such that your data appears corrupt or you get
errors when you access some particular table, you should first check and then
try repairing your tables with @code{myisamchk}.
@xref{Maintenance}.
@item
If you often get corrupted tables you should try to find out when and
why this happens! In this case, the
@file{mysql-data-directory/'hostname'.err} file may contain some
information about what happened. Please include any relevant
information from this file in your bug report! Normally @code{mysqld}
should @strong{NEVER} crash a table if nothing killed it in the middle
of an update! If you can find the source of why @code{mysqld} dies,
it's much easier for us to provide you with a fix for the problem!
@xref{What is crashing}.
@item
If possible, download the most recent version of @strong{MySQL} and check
whether or not it solves your problem. All versions of @strong{MySQL} are
thoroughly tested and should work without problems! We believe in making
everything as backward compatible as possible and you should be able to
switch @strong{MySQL} versions in minutes! @xref{Which version}.
@end itemize
If you are a support customer, please cross-post the bug report to
@email{mysql-support@@mysql.com} for higher priority treatment, as well as to
the appropriate mailing list to see if someone else has experienced (and
perhaps solved) the problem.
For information on reporting bugs in @strong{MyODBC}, see @ref{ODBC
Problems}.
For solutions to some common problems, see @xref{Problems}.
When answers are sent to you individually and not to the mailing list,
it is considered good etiquette to summarize the answers and send the
summary to the mailing list so that others may have the benefit of
responses you received that helped you solve your problem!
@cindex Net etiquette
@node Answering questions, , Bug reports, Questions
@section Guidelines for answering questions on the mailing list
If you consider your answer to have broad interest, you may want to post it
to the mailing list instead of replying directly to the individual who
asked. Try to make your answer general enough that people other than the
original poster may benefit from it. When you post to the list, please make
sure that your answer is not a duplication of a previous answer.
Try to summarize the essential part of the question in your reply; don't feel
obliged to quote the entire original message.
Please don't post mail messages from your browser with HTML mode turned on!
Many users don't read mail with a browser!
@cindex Licensing terms
@cindex Support terms
@node Licensing and Support, Installing, Questions, Top
@chapter MySQL licensing and support
@menu
* Licensing policy:: @strong{MySQL} licensing policy
* Copyright:: Copyrights used by @strong{MySQL}
* Licensing examples:: Example licensing situations
* Cost:: @strong{MySQL} licensing and support costs
* Support:: Types of commercial support
@end menu
This chapter describes @strong{MySQL} support and licensing
arrangements:
@itemize @bullet
@item The copyrights under which @strong{MySQL} is distributed
(@pxref{Copyright})
@item Sample situations illustrating when a license is required
(@pxref{Licensing examples})
@item Support costs (@pxref{Cost}), and support benefits
(@pxref{Support})
@item Commercial licensing costs
@end itemize
@cindex Licensing policy
@node Licensing policy, Copyright, Licensing and Support, Licensing and Support
@section MySQL licensing policy
The formal terms of the GPL license can be found at @ref{GPL license}.
Basically, our licensing policy and intepretation of the GPL is as follows:
Note that older versions of @strong{MySQL} are still using a more strict
license. See the documentation for that version for more information.
If you need a commercial @strong{MySQL} license, because the GPL license
doesn't suit your application, you can buy one at
https://order.mysql.com/license.htmy.
For normal internal use, @strong{MySQL} costs nothing. You do not have
to pay us if you do not want to.
@heading A license is required if:
@itemize @minus
@item
You link a part of the of @strong{MySQL} that has a GPL Copyright to a
program which is not free software (embedded usage of the @strong{MySQL}
server). In this case your application would also become GPL through the
clause in the GPL license that acts as a virus. By licensing
@strong{MySQL} from us under a commercial license you will avoid this
problem.
@item
You have a commercial application that ONLY works with @strong{MySQL}
and ships the application with the @strong{MySQL} server. This is
because we view this a linking even if it is done over the network.
@item You have a distribute @code{MySQL} and you don't provide the
source code for your copy of the @strong{MySQL} server, as defined in
the GPL license.
@end itemize
@heading A license is @strong{NOT} required if:
@itemize @minus
@item
You do not need a license to include the client code in commercial
programs. The client access part of @strong{MySQL} licensed with the
LGPL @code{GNU Library General Public License}. The @code{mysql} command
line client includes code from the @code{readline} library that is under
the @code{GPL}.
@item
If your use of @strong{MySQL} does not require a license, but you
like @strong{MySQL} and want to encourage further development, you are
certainly welcome to purchase a license or @strong{MySQL} support anyway.
@item
If you use @strong{MySQL} in a commercial context such that
you profit by its use, we ask that you further the development of
@strong{MySQL} by purchasing some level of support. We feel that if
@strong{MySQL} helps your business, it is reasonable to ask that you help
@strong{MySQL}. (Otherwise, if you ask us support questions, you are not
only using for free something into which we've put a lot a work, you're
asking us to provide free support, too.)
@end itemize
For circumstances under which a @strong{MySQL} license is required, you
need a license per machine that runs the @code{mysqld} server. However,
a multiple-CPU machine counts as a single machine, and there is no
restriction on the number of @strong{MySQL} servers that run on one
machine, or on the number of clients concurrently connected to a server
running on that machine!
If you have any questions as to whether or not a license is required for
your particular use of @strong{MySQL}, please read this again and then
contact us. @xref{Contact information}.
If you require a @strong{MySQL} license, the easiest way to pay for it
is to use the license form on @strong{MySQL}'s secure server at
https://order.mysql.com/license.htmy. Other forms of payment are
discussed in @ref{Payment information}.
@cindex Copyright
@node Copyright, Licensing examples, Licensing policy, Licensing and Support
@section Copyrights used by MySQL
@menu
* Copyright changes:: Possible future copyright changes
@end menu
There are several different copyrights on the @strong{MySQL} distribution:
@enumerate
@item
The @strong{MySQL}-specific source needed to build the
@code{mysqlclient} library is licensed under the @code{LGPL} and
programs in the @file{client} directory is GPL. Each file has a header
that shows which copyright is used for that file.
@item The client library and the (GNU @code{getopt}) library are covered
by the ``GNU LIBRARY LIBRARY GENERAL PUBLIC LICENSE''.
@item Some parts of the source (the @code{regexp} library) are covered
by a Berkeley style copyright.
@item All the source in the server and the (GNU @code{readline}) library
is covered by the ``GNU GENERAL PUBLIC LICENSE''. @xref{GPL
license}. This is also available as the file @file{COPYING} in the
distributions.
@end enumerate
One goal with this is that the SQL client library should be free enough
so that it is possible to add @strong{MySQL} support in commercial products
without any license. So in this case we choose the LGPL license.
This means that you can use @strong{MySQL} for free with any program that uses
any of the free software licences. @strong{MySQL} is also free for any end user
for his own/company usage.
But if you use @strong{MySQL} for something important to you, you may
want to help secure its development by purchasing licenses or a support
contract, @ref{Support}.
@node Copyright changes, , Copyright, Copyright
@subsection Copyright changes
The stable versions are of @strong{MySQL} are still using a more strict
license. See the documatation for that version for more information.
@node Licensing examples, Cost, Copyright, Licensing and Support
@section Example licensing situations
@menu
* Products that use MySQL:: Selling products that use @strong{MySQL}
* ISP:: ISP @strong{MySQL} services
* Web server:: Running a web server using @strong{MySQL}.
@end menu
This section describes some situations illustrating whether or not you
must license the @strong{MySQL} server. Generally these examples
involve providing @strong{MySQL} as a integrated part of a product.
Note that a single @strong{MySQL} license covers any number of CPUs and
@code{mysqld} servers on a machine! It also has not limit on the number
of clients that connect to one server in any way.
@node Products that use MySQL, ISP, Licensing examples, Licensing examples
@subsection Selling products that use @strong{MySQL}
To determine whether or not you need a @strong{MySQL} license when
selling your application, you should ask whether the proper functioning
of your application is depentent on the use of @strong{MySQL} and
whether you include the @strong{MySQL} server with your product. There
are several cases to consider:
@itemize @bullet
@item
Does your application require @strong{MySQL} to function properly?
If your product requires @strong{MySQL}, you need a license for any
machine that runs the @code{mysqld} server. For example, if you've
designed your application around @strong{MySQL}, then you've really made
a commercial product that requires the engine, so you need a license.
If your application does not require @strong{MySQL}, you need not obtain
a license. For example, if @strong{MySQL} just added some new optional
features to your product (such as adding logging to a database if
@strong{MySQL} is used rather than logging to a text file), it should
fall within normal use, and a license would not be required.
In other words, you need a license if you sell a product designed
specifically for use with @strong{MySQL} or that requires the
@strong{MySQL} server to function at all. This is true whether or not
you provide @strong{MySQL} for your client as part of your product
distribution.
It also depends on what you're doing for the client. Do you plan to
provide your client with detailed instructions on installing
@strong{MySQL} with your software? Then your product may be contingent
on the use of @strong{MySQL}; if so, you need to buy a license. If you
are simply tying into a database that you expect already to have been
installed by the time your software is purchased, then you probably
don't need a license.
@end itemize
@node ISP, Web server, Products that use MySQL, Licensing examples
@subsection ISP @strong{MySQL} services
Internet Service Providers (ISPs) often host @strong{MySQL} servers for
their customers. With the GPL license this does not require a license.
On the other hand, we do encourage people to use ISP:s that has
@strong{MySQL} support as this will give them the confidence that if
they get some problem with their @strong{MySQL} installation, their ISP
will be able to solve the problem for them (in some cases with the help
from the @strong{MySQL} development team).
All @code{ISPs} that wants to keep themself up to date should subscribe
to our announce mailing list so that they can be aware of fatal issues
that may be relevant for their @code{MySQL} installations.
Note that if the @code{ISP} doesn't have a license for @code{MySQL},
they should give their customers at least read access to the source of
the @code{MySQL} installation so that their customer can verify that
it's patched correctly.
@node Web server, , ISP, Licensing examples
@subsection Running a web server using @strong{MySQL}
If you use @strong{MySQL} in conjunction with a web server on Unix, you
don't have to pay for a license.
This is true even if you run a commercial web server that uses
@strong{MySQL}, because you are not selling an embedded @strong{MySQL}
version yourself. However, in this case we would like you to purchase
@strong{MySQL} support, because @strong{MySQL} is helping your
enterprise.
@cindex Costs, licensing and support
@cindex Licensing costs
@cindex Support costs
@node Cost, Support, Licensing examples, Licensing and Support
@section @strong{MySQL} licensing and support costs
@menu
* Payment information:: Payment information
* Contact information:: Contact information
@end menu
Our current license prices are shown below. These prices are now under
review because of the change to a GPL copyright. New prices and terms
will be posted on the @strong{MySQL} web site
@uref{http://www.mysql.com/} as soon as they are ready.
All prices are in US Dollars. If you pay by credit card, the currency is
EURO (European Union Euro) so the prices will differ slightly.
@multitable @columnfractions .25 .2 .3
@item @strong{Number of licenses} @tab @strong{Price per copy} @tab @strong{Total}
@item 1 @tab US $200 @tab US $200
@item 10 pack @tab US $150 @tab US $1500
@item 50 pack @tab US $120 @tab US $6000
@end multitable
For high volume (OEM) purchases, the following prices apply:
@multitable @columnfractions .25 .2 .3 .25
@item @strong{Number of licenses} @tab @strong{Price per copy} @tab @strong{Minimum at one time} @tab @strong{Minimum payment}
@item 100-999 @tab US $40 @tab 100 @tab US $4000
@item 1000-2499 @tab US $25 @tab 200 @tab US $5000
@item 2500-4999 @tab US $20 @tab 400 @tab US $8000
@end multitable
For OEM purchases, you must act as the middle-man for eventual problems
or extension requests from your users. We also require that OEM
customers have at least an extended email support contract. Note that
OEM licenses only apply for products where the user doesn't have direct
access to the @strong{MySQL} server (embedded system). In other words:
The @strong{MySQL} server should only be used with the application
that was supplied you.
If you have a low-margin high-volume product, you can always talk to us
about other terms (for example, a percent of the sale price). If you do,
please be informative about your product, pricing, market and any other
information that may be relevant.
A full-price license is not a support agreement and includes very minimal
support. This means that we try to answer any relevant question. If the
answer is in the documentation, we will direct you to the appropriate
section. If you have not purchased a license or support, we probably will not
answer at all.
If you discover what we consider a real bug, we are likely to fix it in
any case. But if you pay for support we will notify you about the fix
status instead of just fixing it in a later release.
More comprehensive support is sold separately. Descriptions of what each
level of support includes are given in @ref{Support}. Costs for the various
types of commercial support are shown below. Support level prices are in
EURO (European Union Euro). One EURO is about 1.17 USD.
@multitable @columnfractions .3 .3
@item @strong{Type of support} @tab @strong{Cost per year}
@item Basic email support @tab EURO 170
@item Extended email support @tab EURO 1000
@item Login support @tab EURO 2000
@item Extended login support @tab EURO 5000
@end multitable
You may upgrade from any
lower level of support to a higher level of support for the difference
between the prices of the two support levels.
@cindex Payment information
@node Payment information, Contact information, Cost, Cost
@subsection Payment information
Currently we can take SWIFT payments, cheques or credit cards.
Payment should be made to:
@example
Postgirot Bank AB
105 06 STOCKHOLM, SWEDEN
TCX DataKonsult AB
BOX 6434
11382 STOCKHOLM, SWEDEN
SWIFT address: PGSI SESS
Account number: 96 77 06 - 3
@end example
Specify: license and/or support and your name and email address.
In Europe and Japan you can use EuroGiro (that should be less expensive) to the
same account.
If you want to pay by cheque, make it payable to ``MySQL Finland AB'' and
mail it to the address below:
@example
TCX DataKonsult AB
BOX 6434, Torsgatan 21
11382 STOCKHOLM, SWEDEN
@end example
If you want to pay by credit card over the Internet, you can use
@uref{https://order.mysql.com/license.htmy, MySQL AB's secure license form}.
You can also print a copy of the license form, fill it in and send it by fax
to:
+46-8-729 69 05
If you want us to bill you, you can use the license form and write ``bill
us'' in the comment field. You can also mail a message to
@email{sales@@mysql.com} (@strong{not} @email{mysql@@lists.mysql.com}!)
with your company information and ask us to bill you.
@cindex Contact information
@node Contact information, , Payment information, Cost
@subsection Contact information
For commercial licensing, or if you have any questions about any of the
information in this section, please contact the @strong{MySQL} licensing
team. The much preferred method is by E-Mail to
@email{mysql-licensing@@mysql.com}. Fax is also possible but handling of
these may take much longer (Fax +46-8-729 69 05).
@example
David Axmark
Detron HB
Kungsgatan 65 B
753 21 UPPSALA
SWEDEN
Voice Phone +46-18-10 22 80
(Timezone GMT+1. Swedish and English spoken)
@end example
@cindex Support, types
@cindex Types of support
@node Support, , Cost, Licensing and Support
@section Types of commercial support
@menu
* Basic email support:: Basic email support
* Extended email support:: Extended email support
* Login support:: Login support
* Extended login support:: Extended login support
@end menu
@node Basic email support, Extended email support, Support, Support
@subsection Basic email support
Basic email support is a very inexpensive support option and should be
thought of more as a way to support our development of @strong{MySQL}
than as a real support option. We at @strong{MySQL} do give a lot of free support
in all the different @strong{MySQL} lists and the money we get from
basic eamil support is largely used to make this possible.
At this support level, the @strong{MySQL} mailing lists are the preferred
means of communication. Questions normally should be mailed to the primary
mailing list (@email{mysql@@lists.mysql.com}) or one of the other regular
lists (for example, @email{win32@@lists.mysql.com} for Windows-related
@strong{MySQL} questions), as someone else already may have experienced and
solved the problem you have. @xref{Asking questions}.
However, by purchasing basic email support, you also have access to the
support address @email{mysql-support@@mysql.com}, which is not available
as part of the minimal support that you get by purchasing a
@strong{MySQL} license. This means that for especially critical
questions, you can cross-post your message to
@email{mysql-support@@mysql.com}. (If the message contains sensitive
data, you should post only to @email{mysql-support@@mysql.com}.)
@emph{REMEMBER!} to ALWAYS include your registration number and
expiration date when you send a message to
@email{mysql-support@@mysql.com}.
Note that if you have encountered a critical repeatable bug and follow
the rules outlined in the manual section of how to report bugs and send
it to @email{bugs@@lists.mysql.com} we promise to try to fix this as
soon as possible, independent of your support level! @xref{Bug reports}.
Basic email support includes the following types of service:
@itemize @bullet
@item
If your question is already answered in the manual, we will inform you of the
correct section in which you can find the answer. If the answer is not in
the manual, we will point you in the right direction to solve your problem.
@item
We guarantee a timely answer for your email messages. We can't guarantee
that we can solve any problem, but at least you will receive an answer if we
can contact you by email.
@item
We will help with unexpected problems when you install @strong{MySQL} from a
binary distribution on supported platforms. This level of support does not
cover installing @strong{MySQL} from a source distribution. ``Supported''
platforms are those for which @strong{MySQL} is known to work.
@xref{Which OS}.
@item
We will help you with bugs and missing features. Any bugs that are found are
fixed for the next @strong{MySQL} release. If the bug is critical for
you, we will mail you a patch for it as soon the bug is fixed. Critical
bugs always have the highest priority for us, to ensure that they are
fixed as soon as possible.
@item
Your suggestions for the further development of @strong{MySQL} will be
taken into consideration. By taking email support you have already
helped the further development of @strong{MySQL}. If you want to have
more input, upgrade to a higher level of support.
@item
If you want us to help optimize your system, you must upgrade to a
higher level of support.
@item
@cindex @code{myisampack}
We include a binary version of the @code{myisampack} packing tool for
creating fast compressed read-only databases. The current server includes
support for reading such databases but not the packing tool used to
create them.
@end itemize
@node Extended email support, Login support, Basic email support, Support
@subsection Extended email support
Extended email support includes everything in basic email support with
these additions:
@itemize @bullet
@item
Your email will be dealt with before mail from basic email support users and
non-registered users.
@item
Your suggestions for the further development of @strong{MySQL} will
receive strong consideration. Simple extensions that suit the basic
goals of @strong{MySQL} are implemented in a matter of days. By taking
extended email support you have already helped the further development
of @strong{MySQL}.
@item
Typical questions that are covered by extended email support are:
@itemize @minus
@item
We will answer and (within reason) solve questions that relate to possible
bugs in @strong{MySQL}. As soon as the bug is found and corrected, we
will mail a patch for it.
@item
We will help with unexpected problems when you install @strong{MySQL} from a
source or binary distribution on supported platforms.
@item
We will answer questions about missing features and offer hints how to work
around them.
@item
We will provide hints on optimizing @code{mysqld} for your situation.
@end itemize
@item
You are allowed to influence the priority of items on the @strong{MySQL}
TODO. This will ensure that the features you really need will be implemented
sooner than they might be otherwise.
@end itemize
@node Login support, Extended login support, Extended email support, Support
@subsection Login support
Login support includes everything in extended email support with
these additions:
@itemize @bullet
@item
Your email will be dealt with even before mail from extended email
support users.
@item
Your suggestions for the further development of @strong{MySQL} will
be taken into very high consideration. Realistic extensions that can be
implemented in a couple of hours and that suit the basic goals of
@strong{MySQL} will be implemented as soon as possible.
@item
If you have a very specific problem, we can try to log in on your system
to solve the problem ``in place.''
@item
Like any database vendor, we can't guarantee that we can rescue any data from
crashed tables, but if the worst happens we will help you rescue as much as
possible. @strong{MySQL} has proven itself very reliable, but anything is
possible due to circumstances beyond our control (for example, if your system
crashes or someone kills the server by executing a @code{kill -9} command).
@item
We will provide hints on optimizing your system and your queries.
@item
You are allowed to call a @strong{MySQL} developer (in moderation) and
discuss your @strong{MySQL}-related problems.
@end itemize
@node Extended login support, , Login support, Support
@subsection Extended login support
Extended login support includes everything in login support with these
additions:
@itemize @bullet
@item
Your email has the highest possible priority.
@item
We will actively examine your system and help you optimize it and your
queries. We may also optimize and/or extend @strong{MySQL} to better
suit your needs.
@item
You may also request special extensions just for you. For example:
@example
mysql> select MY_FUNC(col1,col2) from table;
@end example
@item
We will provide a binary distribution of all important @strong{MySQL}
releases for your system, as long as we can get an account on a
similar system. In the worst case, we may require access to your system
to be able to create a binary distribution.
@item
If you can provide accommodations and pay for traveler fares, you can even
get a @strong{MySQL} developer to visit you and offer you help with your
troubles. Extended login support entitles you to one personal
encounter per year, but we are as always very flexible towards our customers!
@end itemize
@node Installing, Compatibility, Licensing and Support, Top
@chapter Installing MySQL
@menu
* Getting MySQL:: How to get @strong{MySQL}
* Which OS:: Operating systems supported by @strong{MySQL}
* Which version:: Which @strong{MySQL} version to use
* Many versions:: How and when updates are released
* Installation layouts:: Installation layouts
* Installing binary:: Installing a @strong{MySQL} binary distribution
* Installing source:: Installing a @strong{MySQL} source distribution
* Compilation problems:: Problems compiling?
* MIT-pthreads:: MIT-pthreads notes
* Perl support:: Perl installation comments
* Source install system issues:: System-specific issues
* Win32:: Win32 notes
* OS/2:: OS/2 notes
* MySQL binaries::
* Post-installation:: Post-installation setup and testing
* Upgrade:: Is there anything special to do when upgrading/downgrading @strong{MySQL}?
@end menu
This chapter describes how to obtain and install @strong{MySQL}:
@itemize @bullet
@item
For a list of sites from which you can obtain @strong{MySQL}, see
@ref{Getting MySQL, , Getting @strong{MySQL}}.
@item
To see which platforms are supported, see @ref{Which OS}.
@item
Several versions of @strong{MySQL} are available, in both binary and
source distributions. To determine which version and type of
distribution you should use, see @ref{Many versions}.
@item
Installation instructions for binary and source distributions are described
in @ref{Installing binary}, and @ref{Installing source}. Each set of
instructions includes a section on system-specific problems you may run
into.
@item
For post-installation procedures, see @ref{Post-installation}. These
procedures apply whether you install @strong{MySQL} using a binary or
source distribution.
@end itemize
@cindex Downloading
@cindex @strong{MySQL} version
@cindex Version, latest
@cindex Getting @strong{MySQL}
@node Getting MySQL, Which OS, Installing, Installing
@section How to get MySQL
Check the @uref{http://www.mysql.com/, @strong{MySQL} home page} for
information about the current version and for downloading instructions.
If you have problems downloading from our main site, try using on of the
mirrors listed below.
Please report bad or out of date mirrors to @email{webmaster@@mysql.com}.
@c START_OF_MIRROR_LISTING
@strong{Europe:}
@itemize @bullet
@item
@c EMAIL: sl@iuinfo.tuwien.ac.at (Tony Sprinzl)
@image{Flags/austria} Austria [Univ. of Technology/Vienna] @
@uref{http://gd.tuwien.ac.at/db/mysql/, WWW}
@uref{ftp://gd.tuwien.ac.at/db/mysql/, FTP}
@item
@c EMAIL: delian@naturella.com (Delian Delchev)
@image{Flags/bulgaria} Bulgaria [Naturella] @
@uref{http://archive.nat.bg/pub/mirror/mysql/, WWW}
@uref{ftp://ftp.ntrl.net/pub/mirror/mysql/, FTP}
@item
@c Added: 990614
@c EMAIL: vuksan@veus.hr (Vladimir Vuksan)
@image{Flags/croatia} Croatia [HULK] @
@uref{http://ftp.linux.hr/pub/mysql/, WWW}
@uref{ftp://ftp.linux.hr/pub/mysql/, FTP}
@item
@c Added: 990614
@c EMAIL: kas@informatics.muni.cz (Jan Kasprzak)
@image{Flags/czech-republic} Czech Republic [Masaryk University in Brno] @
@uref{http://mysql.linux.cz/index.html, WWW}
@uref{ftp://ftp.fi.muni.cz/pub/mysql/, FTP}
@item
@c Added: 990920
@c EMAIL: <radek@sopik.cz> (Radek Libovicky)
@image{Flags/czech-republic} Czech Republic [www.sopik.cz] @
@uref{http://www.mysql.cz/, WWW}
@item
@c Added: 000418
@c EMAIL: <feela@ipex.cz> (Ondrej Feela Filip)
@image{Flags/czech-republic} Czech Republic [www.gin.cz] @
@uref{http://mysql.gin.cz/, WWW}
@uref{ftp://ftp.gin.cz/pub/MIRRORS/www.mysql.com/, FTP}
@item
@c removed 991020 (no DNS entry). New name 991026. Added 991121
@c Statistics at http://mirror.borsen.dk/
@c EMAIL: mirrorman@borsen.dk (Michael Kyed)
@image{Flags/denmark} Denmark [Borsen] @
@uref{ http://mysql.borsen.dk/, WWW}
@item
@c EMAIL: mkp@socsci.auc.dk (Martin Kasper Petersen)
@image{Flags/denmark} Denmark [SunSITE] @
@uref{http://SunSITE.auc.dk/mysql/, WWW}
@uref{ftp://SunSITE.auc.dk/pub/databases/mysql/, FTP}
@c @item
@c Tõnu does not work there anymore :-) 990720
@c EMAIL: tonu@tradenet.ee (Tõnu Samuel)
@c @image{Flags/estonia} Estonia [Tradenet] @
@c @uref{http://mysql.tradenet.ee, WWW}
@item
@c EMAIL: tonu@spamm.ee (Tõnu Samuel)
@image{Flags/estonia} Estonia [OKinteractive] @
@uref{http://mysql.mirror.ok.ee, WWW}
@item
@c Changed 990531
@c EMAIL: Steeve.Devergne@minet.net (Steeve Devergne)
@image{Flags/france} France [minet] @
@uref{http://www.minet.net/devel/mysql/, WWW}
@item
@c EMAIL: Jaakko.Hyvatti@eunet.fi
@image{Flags/finland} Finland [EUnet] @
@uref{http://mysql.eunet.fi/, WWW}
@item
@c Added 990829
@c EMAIL: tomi.hakala@clinet.fi (Tomi Hakala)
@image{Flags/finland} Finland [clinet] @
@uref{ftp://ftp.clinet.fi/mirrors/ftp.mysql.org/pub/mysql/, FTP}
@item
@c Added 981208
@c EMAIL: noel@uni-bonn.de (Noel Koethe)
@image{Flags/germany} Germany [Bonn University, Bonn] @
@uref{http://www.wipol.uni-bonn.de/MySQL//, WWW}
@uref{ftp://ftp.wipol.uni-bonn.de/pub/mirror/MySQL/, FTP}
@item
@c EMAIL: th@rz.fh-wolfenbuettel.de (Thorsten Ludewig)
@image{Flags/germany} Germany [Wolfenbuettel] @
@uref{http://www.fh-wolfenbuettel.de/ftp/pub/database/mysql/, WWW}
@uref{ftp://ftp.fh-wolfenbuettel.de/pub/database/mysql/, FTP}
@item
@c Ok 980114. Removed 981208 (down > 3 days) ok 981214
@c EMAIL: straub@gks.de (Hans-Peter Straub)
@image{Flags/germany} Germany [Staufen] @
@uref{http://mysql.staufen.de/, WWW}
@item
@c Added 990614
@c EMAIL: thomas.rohde@ecrc.de (Thomas Rohde)
@image{Flags/germany} Germany [Cable & Wireless] @
@uref{ftp://ftp.ecrc.net/pub/database/mysql/, FTP}
@item
@c Added 981208
@c EMAIL: christias@noc.ntua.gr (Panagiotis Christias)
@image{Flags/greece} Greece [NTUA, Athens] @
@uref{http://www.ntua.gr/mysql/, WWW}
@uref{ftp://ftp.ntua.gr/pub/databases/mysql/, FTP}
@c @item
@c File not found 990730
@c EMAIL: torlasz@xenia.sote.hu (Laszlo L. Tornoc)
@c @image{Flags/hungary} Hungary [Xenia] @
@c @uref{http://xenia.sote.hu/ftp/mirrors/www.mysql.com/, WWW}
@c @uref{ftp://xenia.sote.hu/pub/mirrors/www.mysql.com/,FTP}
@item
@c EMAIL: mirrors@gm.is (Tomas Edwardsson)
@image{Flags/iceland} Island [GM] @
@uref{http://mysql.gm.is/, WWW}
@uref{ftp://ftp.gm.is/pub/mysql, WWW}
@c @item
@c Out of date 990906
@c EMAIL: bourbon@netvision.net.il (Zeev Suraski)
@c @image{Flags/israel} Israel [Netvision] @
@c @uref{http://mysql.netvision.net.il/, WWW}
@c @item
@c Not working 99.03.06
@c EMAIL: maruzz@matrice.it (Giovanni Maruzzelli)
@c @image{Flags/italy} Italy [Matrice] @
@c @uref{http://www.matrice.it/risorse/mysql/, WWW}
@item
@c EMAIL: irena@yacc.it
@image{Flags/italy} Italy [Teta Srl] @
@uref{http://www.teta.it/mysql/, WWW}
@item
@c Added 991121
@c EMAIL: nick@iol.ie (Nick Hilliard)
@image{Flags/ireland} Ireland [Ireland On-Line/Dublin] @
@uref{http://mysql.iol.ie, WWW}
@uref{ftp://ftp.iol.ie/pub/mysql, FTP}
@item
@c EMAIL: W.Sylwestrzak@icm.edu.pl (Wojtek Sylwestrzak)
@c mirroring nightly at 05:25
@image{Flags/poland} Poland [Sunsite] @
@uref{http://sunsite.icm.edu.pl/mysql/, WWW}
@uref{ftp://sunsite.icm.edu.pl/pub/unix/mysql/, FTP}
@c @item
@c EMAIL: melo@co.telenet.pt (Pedro Melo)
@c Temp out of service (email from Pedro)
@c @image{Flags/portugal} Portugal [IP] @
@c @uref{http://mysql.ip.pt, WWW}
@item
@c EMAIL: Equipa de suporte do Leirianet <support@leirianet.pt>
@image{Flags/portugal} Portugal [lerianet] @
@uref{http://mysql.leirianet.pt, WWW}
@uref{ftp://ftp.leirianet.pt/pub/mysql/,FTP}
@item
@c EMAIL: kuzmin@dn.ru (Roma Kuzmin)
@image{Flags/russia} Russia [DirectNet] @
@uref{http://mysql.directnet.ru, WWW}
@uref{ftp://ftp.dn.ru/pub/MySQL, FTP}
@c @item
@c down 990113
@c EMAIL: nikkic@cityline.ru (Nikki Chumakov)
@c @image{Flags/russia} Russia [Cityline] @
@c @uref{ftp://mysql.cityline.ru/pub/mysql, FTP}
@c @uref{http://mysql.cityline.ru, WWW}
@c EMAIL: bar@izhcom.ru (Alexander I Barkov)
@item
@image{Flags/russia} Russia [IZHCOM] @
@uref{http://mysql.udm.net/, WWW}
@uref{ftp://ftp.izhcom.ru/pub/mysql/,FTP}
@item
@c Added 990507
@c EMAIL: demon@gpad.ac.ru (Dima Sivachenko)
@image{Flags/russia} Russia [Scientific Center/Chernogolovka] @
@uref{ftp://ftp.chg.ru/pub/databases/mysql/, FTP}
@item
@c EMAIL: sebi@dnttm.ro (Sebastian DEAC)
@image{Flags/romania} Romania [Timisoara] @
@uref{http://www.dnttm.ro/mysql, WWW}
@uref{ftp://ftp.dnttm.ro/pub/mysql, FTP}
@item
@c EMAIL: tim@lbi.ro (Bogdan Surdu)
@image{Flags/romania} Romania [Bucharest] @
@uref{http://www.lbi.ro/MySQL, WWW}
@uref{ftp://ftp.lbi.ro/mirrors/ftp.tcx.se, FTP}
@c @item
@c Removed 20000521 because there is no mirror here.
@c EMAIL: jips@masterd.es (Juan Ignacio Pérez Sacristán)
@c @image{Flags/spain} Spain [MasterD]
@c @uref{http://mysql.masterd.es, WWW}
@item
@c EMAIL: Patrik.Karen@sdi.slu.se (Patrik Karen)
@c ftp -> remove old files
@image{Flags/sweden} Sweden [Sunet] @
@uref{http://ftp.sunet.se/pub/unix/databases/relational/mysql/, WWW}
@uref{ftp://ftp.sunet.se/pub/unix/databases/relational/mysql/, FTP}
@item
@c EMAIL: archive@sunsite.cnlab-switch.ch (Thomas Lenggenhager)
@image{Flags/switzerland} Switzerland [Sunsite] @
@uref{http://sunsite.cnlab-switch.ch/ftp/mirror/mysql/, WWW}
@uref{ftp://sunsite.cnlab-switch.ch/mirror/mysql/, FTP}
@c @item
@c @c simon@oyster.co.uk (Simon Gornall)
@c @image{Flags/great-britain} UK [Oyster/UK] @
@c @uref{ftp://ftp.oyster.co.uk/pub/mysql, FTP}
@item
@c gareth@omnipotent.net (Gareth Watts)
@image{Flags/great-britain} UK [Omnipotent/UK] @
@uref{http://mysql.omnipotent.net/, WWW}
@uref{ftp://mysql.omnipotent.net/, FTP}
@item
@c keet@mordor.plig.net (Christiaan Keet)
@image{Flags/great-britain} UK [PLiG/UK] @
@uref{http://ftp.plig.org/pub/mysql/, WWW}
@uref{ftp://ftp.plig.org/pub/mysql/, FTP}
@c @item
@c unknown
@c @image{Flags/great-britain} UK [MicroMuse] @
@c @uref{ftp://ftp.micromuse.co.uk/pub/packages/unix/databases/mysql/, FTP}
@item
@c lmjm@icparc.ic.ac.uk (Lee McLoughlin)
@image{Flags/great-britain} UK [SunSITE] @
@uref{http://sunsite.org.uk/packages/mysql/, WWW}
@uref{ftp://sunsite.org.uk/packages/mysql/, FTP}
@item
@c sander@paco.net (Alexander Ivanov)
@image{Flags/ukraine} Ukraine [PACO] @
@uref{http://mysql.paco.net.ua, WWW}
@uref{ftp://mysql.paco.net.ua/, FTP}
@end itemize
@strong{North America:}
@itemize @bullet
@c @item
@c Not ok 990101 (only to 981007)
@c EMAIL: sysop@polarcom.com (Seamus Venasse)
@c @image{Flags/canada} Canada [Polaris Computing] @
@c @uref{http://mysql.polaris.ca/, WWW}
@item
@c Ok 980109
@c EMAIL: wojtek@tryc.on.ca (Wojtjeck Tryc)
@image{Flags/canada} Canada [Tryc] @
@uref{http://web.tryc.on.ca/mysql/, WWW}
@item
@c not updated 990218. Added again 990918
@c EMAIL: rhooper@cyberus.ca (Roy Hooper)
@image{Flags/canada} Canada [Cyberus] @
@uref{http://mysql.cyberus.ca/, WWW}
@uref{ftp://mysql.cyberus.ca/, FTP}
@item
@c EMAIL: mleber@he.net (Mike Leber)
@c Added 980312
@image{Flags/usa} USA [Hurricane Electric/San Jose] @
@uref{http://mysql.he.net, WWW}
@item
@c EMAIL: meltzer@icsnet.com (Jeffrey Meltzer)
@c Added 000108
@image{Flags/usa} USA [Meltzer/New York State] @
@uref{ftp://ftp.meltzer.org/pub/mysql/, FTP}
@c @item
@c No such directory 990830
@c EMAIL: tps@users.buoy.com (Tim Sailer)
@c @image{Flags/usa} USA [Buoy/New York] @
@c @uref{http://www.buoy.com/mysql/, WWW}
@c @item
@c EMAIL: db@hpnc.com (Douglas Bowyer)
@c Added 980107, removed 981124 because of 'file not found'
@c @image{Flags/usa} USA [Hypernet Communications/Dallas] @
@c @uref{http://epsilon.hpnc.com/mysql, WWW}
@c @item @c **********************************
@c Not updated 980106
@c EX: twh@iquest.net (Thomas Holt) who no longer works there
@c @image{Flags/usa} USA [IQuest/Indiana] @
@c @uref{http://mirrors.iquest.net/mysql/, WWW}
@c @item @c **********************************
@c Only a partial mirror so we exclude it from the list
@c EX: lindberg@id.wustl.edu (Fred Lindberg)
@c @image{Flags/usa} USA [Washington University/St. Louis] @
@c @uref{ftp://ftp.id.wustl.edu/pub/database/mysql/, FTP}
@c removed 991111 -> no answer
@c @item
@c EMAIL: andrew@netcasting.net (Andrew Sawyers)
@c @image{Flags/usa} USA [Netcasting/West Coast] @
@c @uref{ftp://ftp.netcasting.net/pub/mysql/, FTP}
@c @item
@c No mirror! 980809 David
@c EMAIL: savages@savages.com (Shaun Savage)
@c @image{Flags/usa} USA [Savages/Oregon] @
@c @uref{http://mysql.savages.com, WWW}
@item
@c EMAIL: tcobb@staff.circle.net (Troy Cobb)
@image{Flags/usa} USA [Circle Net/North Carolina] @
@uref{http://www.mysql.net, WWW}
@item
@c EMAIL: paul@gina.net (Paul Vining)
@c mirrors ftp.sunet.se
@image{Flags/usa} USA [Gina net/Florida] @
@uref{http://www.gina.net/mysql/, WWW}
@c Out of date 2000-01-08 (Not updated since 1999-10)
@c @item
@c EMAIL: wswanson@pingzero.net (Wylie Swanson)
@c mirrors mysql.org
@c @image{Flags/usa} USA [pingzero/Los Angeles] @
@c @uref{http://mysql.pingzero.net/, WWW}
@item
@c EMAIL: ftpkeeper@mirror.sit.wisc.edu
@image{Flags/usa} USA [Wisconsin University/Wisconsin] @
@uref{http://mirror.sit.wisc.edu/mysql/, WWW}
@uref{ftp://mirror.sit.wisc.edu/mirrors/mysql/, FTP}
@item
@c EMAIL: ftp-admin@digex.net
@image{Flags/usa} USA [DIGEX] @
@uref{ftp://ftp.digex.net/pub/packages/database/mysql/, FTP}
@item
@c EMAIL: andrew.sawyers@thelinuxstore.com
@image{Flags/usa} USA [LinuxWired/Scottsdale, AZ] @
@uref{http://mysql.linuxwired.net/, WWW}
@uref{ftp://ftp.linuxwired.net/pub/mirrors/mysql/, FTP}
@end itemize
@strong{South America:}
@itemize @bullet
@item
@c EMAIL: gaiser@matrix.com.br (Roberto Gaiser)
@image{Flags/brazil} Brazil [Matrix] @
@uref{http://mysql.matrix.com.br, WWW}
@item
@c jpabuyer@vision.cl
@image{Flags/chile} Chile [Vision] @
@uref{http://mysql.vision.cl/, WWW}
@c @item
@c Removed 990730
@c @c EMAIL: dan@amerikanclaris.com (Danilo Lotina F.)
@c @image{Flags/chile} Chile [Amerikanclaris] @
@c @uref{http://www.labs.amerikanclaris.cl/mysql, WWW}
@c @uref{ftp://ftp.amerikanclaris.cl/pub/mysql, FTP}
@end itemize
@strong{Asia:}
@itemize @bullet
@item
@c EMAIL: mirnshi@netchina.com.cn (Meng Lingbo)
@image{Flags/china} China [Freecode] @
@uref{http://mysql.freecode.com.cn, WWW}
@item
@c EMAIL: Vincent_Fong@innovator.com.hk (Vincent Fong)
@image{Flags/china} China [Hong Kong] @
@uref{http://mysql.islnet.net, WWW}
@item
@c EMAIL: george@netfirm.net (Hongsheng Zhu)
@image{Flags/china} China [Netfirm] @
@uref{http://mysql.netfirm.net, WWW}
@item
@c EMAIL: ahmlhs@nmsvr.chosun.com (Ho-sun Lee)
@image{Flags/south-korea} Korea [KREONet] @
@uref{http://linux.kreonet.re.kr/mysql/, WWW}
@c @item
@c ftp -> remove old files
@c EX: ahmlhs@nmsvr.chosun.com (Ho-sun Lee)
@c @image{Flags/south-korea} Korea [KREONet] @
@c @uref{ftp://linux.kreonet.re.kr/pub/tools/db/mysql/, FTP}
@item
@c Ok 980805
@c EMAIL: takeshi@SoftAgency.co.jp
@image{Flags/japan} Japan [Soft Agency] @
@uref{http://www.softagency.co.jp/MySQL, WWW}
@c @item
@c Ok 980109 Removed 990730
@c EMAIL: satoshi@HappySize.co.jp (Satoshi TATSUOKA)
@c @image{Flags/japan} Japan [HappySize] @
@c @uref{http://www.happysize.co.jp/mysql/, WWW}
@c @uref{ftp://ftp.happysize.co.jp/pub/mysql/, FTP}
@item
@c Ok 981204
@c EMAIL: hiroyuki@nucba.ac.jp (hiroyuki kurimoto)
@image{Flags/japan} Japan [Nagoya Syouka University] @
@uref{http://mirror.nucba.ac.jp/mirror/mysql, WWW}
@uref{ftp://mirror.nucba.ac.jp/mirror/mysql, FTP}
@c @item
@c Removed 990308
@c EMAIL: terence@com5.net (Terence Chan)
@c @image{Flags/singapore} Singapore [Com5 Productions] @
@c @uref{http://mysql.com5.net, WWW}
@c @uref{ftp://ftp.com5.net/pub/mysql, FTP}
@item
@c EMAIL: csy@hjc.edu.sg
@image{Flags/singapore} Singapore [HJC] @
@uref{http://mysql.hjc.edu.sg, WWW}
@uref{ftp://ftp.hjc.edu.sg/mysql, FTP}
@item
@c 991118: Removed because a user complained about that the page contains
@c nothing about MySQL. 991119: Added again because it is a mirror again
@c EMAIL: dean@ht.net.tw (Dean Lin)
@image{Flags/taiwan} Taiwan [HT] @
@uref{http://mysql.ht.net.tw, WWW}
@item
@c EMAIL: linda@ttn.com.tw (Linda Hu)
@image{Flags/taiwan} Taiwan [TTN] @
@uref{http://mysql.ttn.net, WWW}
@c @item
@c Ok 980321 No connect -> removed 990730
@c EMAIL: tby@ccca.nctu.edu.tw (Bao-Yi Tuang)
@c @image{Flags/taiwan} Taiwan [NCTU] @
@c @uref{http://mysql.taconet.com.tw, WWW}
@c @item
@c Out of date 990905 (~2 months)
@c @item @c **********************************
@c Error 980106
@c EX: WolfySu@acer.net (Wolfy Su)
@c @image{Flags/taiwan} Taiwan [Acer] @
@c @uref{http://mysql.acer.net/, WWW}
@c @item @c **********************************
@c files to delete
@c EX: service@wownet.net
@c @image{Flags/taiwan} Taiwan [Wownet] @
@c @uref{ftp://ftp.wownet.net/mysql/, FTP}
@c @item @c **********************************
@c No conntact 980106
@c EX: serge@oneway.net
@c @image{Flags/taiwan} Taiwan [Oneway] @
@c @uref{ftp://ftp.oneway.com.tw/pub/mysql/, FTP}
@end itemize
@strong{Australia:}
@itemize @bullet
@item
@c Added 980610
@c EMAIL: jason@dstc.edu.au (Jason Andrade)
@image{Flags/australia} Australia [AARNet/Queensland] @
@uref{http://mirror.aarnet.edu.au/mysql, WWW}
@uref{ftp://mirror.aarnet.edu.au/pub/mysql, FTP}
@c @item
@c Added 980805. Removed 000102 'no such directory'
@c EMAIL: sdd@ntccc.tas.gov.au (Scott Donovan)
@c @image{Flags/australia} Australia [Tas] @
@c @uref{http://ftp.tas.gov.au/mysql, WWW}
@c @uref{ftp://ftp.tas.gov.au/pub/mysql, FTP}
@item
@c Ok 980623
@c EMAIL: samh@bluep.com (Sam Hadzajlic)
@image{Flags/australia} Australia [Blue Planet/Melbourne] @
@uref{http://mysql.bluep.com/, WWW}
@c removed because ftp was not working 990729 & 30
@c @uref{ftp://mysql.bluep.com/pub/mirror1/mysql/, FTP}
@item
@c Added 990531
@c EMAIL: gavin@itworks.com.au (Gavin Cameron)
@image{Flags/australia} Australia [ITworks Consulting/Victoria] @
@uref{http://mysql.itworks.com.au, WWW}
@c @item
@c 980610 Only the toplevel dir!
@c EMAIL: lucifer@maths.uq.edu.au (David Conran)
@c @image{Flags/australia} Australia FTP @
@c @uref{ftp://ftp.sage-au.org.au/pub/database/mysql, [Sage]}
@end itemize
@strong{Africa:}
@itemize @bullet
@item
@c Ok 981010
@c EMAIL: nick@mweb.com (Nick Rosenberg)
@image{Flags/south-africa1} South-Africa [Mweb/] @
@uref{http://www.mysql.mweb.co.za, WWW}
@item
@c Ok 981010
@c EMAIL: oskar@is.co.za (Oskar Pearson)
@image{Flags/south-africa1} South-Africa [The Internet Solution/Johannesburg] @
@uref{ftp://ftp.is.co.za/linux/mysql/, FTP}
@end itemize
@c END_OF_MIRROR_LISTING
@node Which OS, Which version, Getting MySQL, Installing
@section Operating systems supported by MySQL
We use GNU Autoconf so it is possible to port @strong{MySQL} to all modern
systems with working Posix threads and a C++ compiler. (To compile only the
client code, a C++ compiler is required but not threads.) We use and develop
the software ourselves primarily on Sun Solaris (versions 2.5 & 2.6) and to a
lesser extent on RedHat Linux 5.0.
@strong{MySQL} has been reported to compile sucessfully on the following
operating system/thread package combinations. Note that for many operating
systems, the native thread support works only in the latest versions.
@itemize @bullet
@item
AIX 4.x with native threads. @xref{IBM-AIX}.
@item
BSDI 2.x with the included MIT-pthreads package. @xref{BSDI}.
@item
BSDI 3.0, 3.1 and 4.x with native threads. @xref{BSDI}.
@item
DEC UNIX 4.x with native threads. @xref{Alpha-DEC-Unix}.
@item
FreeBSD 2.x with the included MIT-pthreads package. @xref{FreeBSD}.
@item
FreeBSD 3.x with native threads. @xref{BSDI}.
@item
HP-UX 10.20 with the included MIT-pthreads package. @xref{HP-UX 10.20}.
@item
HP-UX 11.x with the native threads. @xref{HP-UX 11.x}.
@item
Linux 2.0+ with LinuxThreads 0.7.1 or @code{glibc} 2.0.7 . @xref{Linux}.
@item
MacOS X Server. @xref{MacOSX}.
@item
NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make). @xref{NetBSD}.
@item
OpenBSD > 2.5 with native therads. OpenBSD < 2.5 with the included
MIT-pthreads package. @xref{OpenBSD}.
@item
OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4. @xref{OS/2}.
@item
SGI Irix 6.x with native threads. @xref{SGI-Irix}.
@item
Solaris 2.5 and above with native threads on SPARC and x86. @xref{Solaris}.
@item
SunOS 4.x with the included MIT-pthreads package. @xref{Solaris}.
@item
SCO OpenServer with a recent port of the FSU Pthreads package. @xref{SCO}.
@item
SCO UnixWare 7.0.1. @xref{SCO Unixware}.
@item
Tru64 Unix
@item
Win95, Win98, NT and Win2000. @xref{Win32}.
@end itemize
@cindex @strong{MySQL} binary distribution
@cindex @strong{MySQL} source distribution
@cindex Release numbers
@cindex Version, choosing
@cindex Choosing version
@node Which version, Many versions, Which OS, Installing
@section Which MySQL version to use
The first decision to make is whether you want to use the latest development
release or the last stable release:
@itemize @bullet
@item
Normally, if you are beginning to use @strong{MySQL} for the first time
or trying to port it to some system for which there is no binary
distribution, we recommend going with the development release (currently
@value{mysql_version}. This is because there are usually no really
serious bugs in the development release, and you can easily test it on
your machine with the @code{crash-me} and benchmark tests.
@xref{Benchmarks}. Note that all @strong{MySQL} releases are
checked with the @strong{MySQL} benchmarks and an extensive test suite
before each release.
@item
Otherwise, if you are running an old system and want to upgrade, but
don't want to take chances with the development version, you should
upgrade to the latest in the same branch you are using (where only the
last version number is newer than yours). We have tried to fix only
fatal bugs and make small, relatively safe changes to that version.
@end itemize
The second decision to make is whether you want to use a source distribution or
a binary distribution:
@itemize @bullet
@item
If you want to run @strong{MySQL} on a platform for which a current binary
distribution exists, use that. Generally, it will be easier to install
than a source distribution.
@item
If you want to read (and/or modify) the C and C++ code that makes up
@strong{MySQL}, you should get a source distribution. The source code is
always the ultimate manual. Source distributions also contain more
tests and examples than binary distributions.
@end itemize
The @strong{MySQL} naming scheme uses release numbers that consist of three
numbers and a suffix. For example, a release name like
@code{mysql-3.21.17-beta} is interpreted like this:
@itemize @bullet
@item
The first number (@code{3}) describes the file format. All
version 3 releases have the same file format. When a version 4 appears, every
table will have to be converted to the new format (nice tools for this will
be included, of course).
@item
The second number (@code{21}) is the release level. Normally there are two to
choose from. One is the release/stable branch (currently @code{22}) and the
other is the development branch (currently @code{23}) . Normally both are
stable, but the development version may have quirks, missing documentation on
new features or may fail to compile on some systems.
@item
The third number (@code{17}) is the version number within the
release level. This is incremented for each new distribution. Usually you
want the latest version for the release level you have choosen.
@item
The suffix (@code{beta}) indicates the stability level of the release.
The possible suffixes are:
@itemize @minus
@item @code{alpha} indicates that the release contains some large section of
new code that hasn't been 100% tested. Known bugs (usually there are none)
should be documented in the News section. @xref{News}. There are also new
commands and extensions in most alpha releases. Active development that
may involve major code changes can occur on an alpha release, but everything
will be tested before doing a release. There should be no known bugs in any
@code{MySQL} release.
@item
@code{beta} means that all new code has been tested. No major new
features that could cause corruption on old code are added. There should
be no known bugs. A version changes from alpha to beta when there
haven't been any reported fatal bugs within an alpha version for at least
a month and we don't plan to add any features that could make any old command
more unreliable.
@item
@code{gamma} is a beta that has been around a while and seems to work fine.
Only minor fixes are added. This is what many other companies call a release.
@item
If there is no suffix, it means that the version has been run for a
while at many different sites with no reports of bugs other than
platform-specific bugs. Only critical bug fixes are applied to the
release. This is what we call a stable release.
@end itemize
@end itemize
All versions of @strong{MySQL} are run through our standard tests and
benchmarks to ensure that they are relatively safe to use. Because the
standard tests are extended over time to check for all previously found bugs,
the test suite keeps getting better.
Note that all releases have been tested at least with:
@table @asis
@item An internal test suite
This is part of a production system for a customer. It has many tables with
hundreds of megabytes of data.
@item The @strong{MySQL} benchmark suite
This runs a range of common queries. It is also a test to see whether the
latest batch of optimizations actually made the code faster.
@xref{Benchmarks}.
@item The @code{crash-me} test
This tries to determine what features the database supports and what its
capabilities and limitations are.
@xref{Benchmarks}.
@end table
Another test is that we use the newest @strong{MySQL} version in our internal
production environment, on at least one machine. We have more than 100
gigabytes of data to work with.
@node Many versions, Installation layouts, Which version, Installing
@section How and when updates are released
@strong{MySQL} is evolving quite rapidly here at MySQL AB and we want
to share this with other @strong{MySQL} users. We try to make a release
when we have very useful features that others seem to have a need for.
We also try to help out users who request features that are easy to
implement. We also take note of what our licensed users want to have and
we especially take note of what our extended email supported customers
want and try to help them out.
No one has to download a new release. The News section will tell you if
the new release has something you really want. @xref{News}.
We use the following policy when updating @strong{MySQL}:
@itemize @bullet
@item
For each minor update, the last number in the version string is incremented.
When there are major new features or minor incompatibilities with previous
versions, the second number in the version string is incremented. When the
file format changes, the first number is increased.
@item
Stable tested releases are meant to appear about 1-2 times a year, but
if small bugs are found, a release with only bug-fixes will be released.
@item
Working releases are meant to appear about every 1-8 weeks.
@item
Binary distributions for some platforms will be made by us for major releases.
Other people may make binary distributions for other systems but probably
less frequently.
@item
We usually make patches available as soon as we have located and fixed
small bugs.
@item
For non-critical but annoying bugs, we will make patches available if they
are sent to us. Otherwise we will combine many of them into a larger
patch.
@item
If there is, by any chance, a fatal bug in a release we will make a new
release as soon as possible. We would like other companies to do this,
too. :)
@end itemize
The current stable release is 3.22; We have already moved active
development to 3.23. Bugs will still be fixed in the stable version. We
don't believe in a complete freeze, as this also leaves out bug fixes
and things that ``must be done''. ``Somewhat frozen'' means that we may
add small things that ``almost surely will not affect anything that's
already working''.
@node Installation layouts, Installing binary, Many versions, Installing
@section Installation layouts
This section describes the default layout of the directories created by
installing binary and source distributions.
A binary distribution is installed by unpacking it at the installation
location you choose (typically @file{/usr/local/mysql}) and creates the
following directories in that location:
@multitable @columnfractions .3 .7
@item @strong{Directory} @tab @strong{Contents of directory}
@item @file{bin} @tab Client programs and the @code{mysqld} server
@item @file{data} @tab Log files, databases
@item @file{include} @tab Include (header) files
@item @file{lib} @tab Libraries
@item @file{scripts} @tab @code{mysql_install_db}
@item @file{share/mysql} @tab Error message files
@item @file{sql-bench} @tab Benchmarks
@end multitable
A source distribution is installed after you configure and compile it. By
default, the installation step installs files under @file{/usr/local}, in the
following subdirectories:
@multitable @columnfractions .3 .7
@item @strong{Directory} @tab @strong{Contents of directory}
@item @file{bin} @tab Client programs and scripts
@item @file{include/mysql} @tab Include (header) files
@item @file{info} @tab Documentation in Info format
@item @file{lib/mysql} @tab Libraries
@item @file{libexec} @tab The @code{mysqld} server
@item @file{share/mysql} @tab Error message files
@item @file{sql-bench} @tab Benchmarks and @code{crash-me} test
@item @file{var} @tab Databases and log files.
@end multitable
Within an installation directory, the layout of a source installation differs
from that of a binary installation in the following ways:
@itemize @bullet
@item
The @code{mysqld} server is installed in the @file{libexec}
directory rather than in the @file{bin} directory.
@item
The data directory is @file{var} rather than @file{data}.
@item
@code{mysql_install_db} is installed in the @file{/usr/local/bin} directory
rather than in @file{/usr/local/mysql/scripts}.
@item
The header file and library directories are @file{include/mysql} and
@file{lib/mysql} rather than @file{include} and @file{lib}.
@end itemize
You can create your own binary installation from a compiled source
distribution, by executing the script @file{scripts/make_binary_distribution}.
@node Installing binary, Installing source, Installation layouts, Installing
@section Installing a MySQL binary distribution
@menu
* Linux-RPM:: Linux RPM files
* Building clients:: Building client programs
* Binary install system issues:: System-specific issues
@end menu
You need the following tools to install a @strong{MySQL} binary distribution:
@itemize @bullet
@item
GNU @code{gunzip} to uncompress the distribution.
@item
A reasonable @code{tar} to unpack the distribution. GNU @code{tar} is
known to work.
@end itemize
@cindex RPM
@cindex RedHat Package Manager
An alternative installation method under Linux is to use RPM (RedHat Package
Manager) distributions. @xref{Linux-RPM}.
@c texi2html fails to split chapters if I use strong for all of this.
If you run into problems, @strong{PLEASE ALWAYS USE} @code{mysqlbug} when
posting questions to @email{mysql@@lists.mysql.com}. Even if the problem
isn't a bug, @code{mysqlbug} gathers system information that will help others
solve your problem. By not using @code{mysqlbug}, you lessen the likelihood
of getting a solution to your problem! You will find @code{mysqlbug} in the
@file{bin} directory after you unpack the distribution. @xref{Bug reports}.
The basic commands you must execute to install and use a @strong{MySQL}
binary distribution are:
@example
shell> gunzip < mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s mysql-VERSION-OS mysql
shell> cd mysql
shell> scripts/mysql_install_db
shell> bin/safe_mysqld &
@end example
You can add new users using the @code{bin/mysql_setpermission} script if
you install the @code{DBI} and @code{Msql-Mysql-modules} Perl modules.
Here follows a more detailed description:
To install a binary distribution, follow the steps below, then proceed
to @ref{Post-installation}, for post-installation setup and testing:
@enumerate
@item
Pick the directory under which you want to unpack the distribution, and move
into it. In the example below, we unpack the distribution under
@file{/usr/local} and create a directory @file{/usr/local/mysql} into which
@strong{MySQL} is installed. (The following instructions therefore assume
you have permission to create files in @file{/usr/local}. If that directory
is protected, you will need to perform the installation as @code{root}.)
@item
Obtain a distribution file from one of the sites listed in
@ref{Getting MySQL, , Getting @strong{MySQL}}.
@strong{MySQL} binary distributions are provided as compressed @code{tar}
archives and have names like @file{mysql-VERSION-OS.tar.gz}, where
@code{VERSION} is a number (e.g., @code{3.21.15}), and @code{OS} indicates
the type of operating system for which the distribution is intended (e.g.,
@code{pc-linux-gnu-i586}).
@item
Unpack the distribution and create the installation directory:
@example
shell> gunzip < mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s mysql-VERSION-OS mysql
@end example
The first command creates a directory named @file{mysql-VERSION-OS}. The
second command makes a symbolic link to that directory. This lets you refer
more easily to the installation directory as @file{/usr/local/mysql}.
@item
Change into the installation directory:
@example
shell> cd mysql
@end example
You will find several files and subdirectories in the @code{mysql} directory.
The most important for installation purposes are the @file{bin} and
@file{scripts} subdirectories.
@table @file
@item bin
@tindex PATH environment variable
@tindex Environment variable, PATH
This directory contains client programs and the server
You should add the full pathname of this directory to your
@code{PATH} environment variable so that your shell finds the @strong{MySQL}
programs properly. @xref{Environment variables}.
@item scripts
This directory contains the @code{mysql_install_db} script used to initialize
the server access permissions.
@end table
@item
If you would like to use @code{mysqlaccess} and have the @strong{MySQL}
distribution in some nonstandard place, you must change the location where
@code{mysqlaccess} expects to find the @code{mysql} client. Edit the
@file{bin/mysqlaccess} script at approximately line 18. Search for a line
that looks like this:
@example
$MYSQL = '/usr/local/bin/mysql'; # path to mysql executable
@end example
Change the path to reflect the location where @code{mysql} actually is
stored on your system. If you do not do this, you will get a @code{broken
pipe} error when you run @code{mysqlaccess}.
@item
Create the @strong{MySQL} grant tables (necessary only if you haven't
installed @strong{MySQL} before):
@example
shell> scripts/mysql_install_db
@end example
Note that @strong{MySQL} versions older than 3.22.10 started the
@strong{MySQL} server when you run @code{mysql_install_db}. This is no
longer true!
@item
If you want to install support for the Perl @code{DBI}/@code{DBD} interface,
see @ref{Perl support}.
@item
If you would like @strong{MySQL} to start automatically when you boot your
machine, you can copy @code{support-files/mysql.server} to the location where
your system has its startup files. More information can be found in the
@code{support-files/mysql.server} script itself, and in @ref{Automatic
start}.
@end enumerate
After everything has been unpacked and installed, you should initialize
and test your distribution.
You can start the @strong{MySQL} server with the following command:
@example
shell> bin/safe_mysqld &
@end example
@xref{Post-installation}.
@cindex RPM
@cindex RedHat Package Manager
@c This node name is special
@node Linux-RPM, Building clients, Installing binary, Installing binary
@subsection Linux RPM notes
The recommended way to install @strong{MySQL} on Linux is by using an RPM
file. The @strong{MySQL} RPMs are currently being built on a RedHat 5.2
system but should work on other versions of Linux that support @code{rpm} and
use @code{glibc}.
If you have problems with an RPM file, for example @code{Sorry, the host
'xxxx' could not be looked up}, see @ref{Binary notes-Linux}.
The RPM files you may want to use are:
@itemize @bullet
@item @code{MySQL-VERSION.i386.rpm}
The @strong{MySQL} server. You will need this unless you only want to
connect to another @strong{MySQL} server running on another machine.
@item @code{MySQL-client-VERSION.i386.rpm}
The standard @strong{MySQL} client programs. You probably always want to
install this package.
@item @code{MySQL-bench-VERSION.i386.rpm}
Tests and benchmarks. Requires Perl and msql-mysql-modules RPMs.
@item @code{MySQL-devel-VERSION.i386.rpm}
Libraries and include files needed if you want to compile other
@strong{MySQL} clients, such as the Perl modules.
@item @code{MySQL-VERSION.src.rpm}
This contains the source code for all of the above packages. It can also
be used to try to build RPMs for other architectures (for example, Alpha
or SPARC).
@end itemize
To see all files in an RPM package:
@example
shell> rpm -qpl MySQL-VERSION.i386.rpm
@end example
To perform a standard minimal installation, run this command:
@example
shell> rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm
@end example
To install just the client package:
@example
shell> rpm -i MySQL-client-VERSION.i386.rpm
@end example
The RPM places data in @file{/var/lib/mysql}. The RPM also creates the
appropriate entries in @file{/etc/rc.d/} to start the server automatically
at boot time. (This means that if you have performed a previous
installation, you may want to make a copy of your previously-installed
@strong{MySQL} startup file if you made any changes to it, so you don't lose
your changes.)
After installing the RPM file(s), the @file{mysqld} daemon should be running
and you should now be able to start using @strong{MySQL}.
@xref{Post-installation}.
If something goes wrong, can find more information in the binary
installation chapter. @xref{Installing binary}.
@cindex Client programs, building
@cindex Linking
@node Building clients, Binary install system issues, Linux-RPM, Installing binary
@subsection Building client programs
If you compile @strong{MySQL} clients that you've written yourself or that
you obtain from a third party, they must be linked using the
@code{-lmysqlclient} option on the link command. You may also need to
specify a @code{-L} option to tell the linker where to find the library. For
example, if the library is installed in @file{/usr/local/mysql/lib}, use
@code{-L/usr/local/mysql/lib -lmysqlclient} on the link command.
For clients that use @strong{MySQL} header files, you may need to specify a
@code{-I} option when you compile them (for example,
@code{-I/usr/local/mysql/include}), so the compiler can find the header
files.
@node Binary install system issues, , Building clients, Installing binary
@subsection System-specific issues
@menu
* Binary notes-Linux:: Linux notes
* Binary notes-HP-UX:: HP-UX notes
@end menu
The following sections indicate some of the issues that have been observed
on particular systems when installing @strong{MySQL} from a binary
distribution.
@node Binary notes-Linux, Binary notes-HP-UX, Binary install system issues, Binary install system issues
@subsubsection Linux notes
@strong{MySQL} needs at least Linux 2.0.
The binary release is linked with @code{-static}, which means you not
normally need not worry about which version of the system libraries you
have. You need not install LinuxThreads, either. A program linked with
@code{-static} is slightly bigger than a dynamically-linked program but
also slightly faster (3-5%). One problem however is that you can't use
user definable functions (UDFs) with a statically-linked program. If
you are going to write or use UDF functions (this is something only for
C or C++ programmers) you must compile @strong{MySQL} yourself, using
dynamic linking.
If you are using a @code{libc}-based system (instead of a @code{glibc2}
system), you will probably get some problems with hostname resolving and
getpwnam() with the binary release. (This is because @code{glibc}
unfortunately depends on some external libraries to resolve hostnames
and getwpent() , even when compiled with @code{-static}). In this case
you probably get the following error message when you run
@code{mysql_install_db}:
@example
Sorry, the host 'xxxx' could not be looked up
@end example
or the following error when you try to run mysqld with the @code{--user}
option:
@example
getpwnam: No such file or directory
@end example
You can solve this problem one of the following ways:
@itemize @bullet
@item
Get a @strong{MySQL} source distribution (an RPM or the @code{tar}
distribution) and install this instead.
@item
Execute @code{mysql_install_db --force}; This will not execute the
@code{resolveip} test in @code{mysql_install_db}. The downside is that
you can't use host names in the grant tables; you must use IP numbers
instead (except for @code{localhost}). If you are using an old @strong{MySQL}
release that doesn't support @code{--force} you have to remove the
@code{resolveip} test in @code{mysql_install} with an editor.
@item
Start mysqld with @code{su} instead of using @code{--user}.
@end itemize
The Linux-Intel binary and RPM releases of @strong{MySQL} are configured
for the highest possible speed. We are always trying to use the fastest
stable compiler available.
@strong{MySQL} Perl support requires Perl 5.004_03 or newer.
@node Binary notes-HP-UX, , Binary notes-Linux, Binary install system issues
@subsubsection HP-UX notes
Some of the binary distributions of @strong{MySQL} for HP-UX is
distributed as an HP depot file and as a tar file. To use the depot
file you must be running at least HP-UX 10.x to have access to HP's
software depot tools.
The HP version of @strong{MySQL} was compiled on an HP 9000/8xx server
under HP-UX 10.20, and uses MIT-pthreads. It is known to work
well under this configuration.
@strong{MySQL} 3.22.26 and newer can also be built with HP's native
thread package.
Other configurations that may work:
@itemize @bullet
@item
HP 9000/7xx running HP-UX 10.20+
@item
HP 9000/8xx running HP-UX 10.30
@end itemize
The following configurations almost definitely won't work:
@itemize @bullet
@item
HP 9000/7xx or 8xx running HP-UX 10.x where x < 2
@item
HP 9000/7xx or 8xx running HP-UX 9.x
@end itemize
To install the distribution, use one of the commands below, where
@code{/path/to/depot} is the full pathname of the depot file:
@itemize @bullet
@item
To install everything, including the server, client and development tools:
@example
shell> /usr/sbin/swinstall -s /path/to/depot mysql.full
@end example
@item
To install only the server:
@example
shell> /usr/sbin/swinstall -s /path/to/depot mysql.server
@end example
@item
To install only the client package:
@example
shell> /usr/sbin/swinstall -s /path/to/depot mysql.client
@end example
@item
To install only the development tools:
@example
shell> /usr/sbin/swinstall -s /path/to/depot mysql.developer
@end example
@end itemize
The depot places binaries and libraries in @file{/opt/mysql} and data in
@file{/var/opt/mysql}. The depot also creates the appropriate entries in
@file{/sbin/init.d} and @file{/sbin/rc2.d} to start the server automatically
at boot time. Obviously, this entails being @code{root} to install.
To install the HP-UX tar distribution, you must have a copy of GNU @code{tar}.
@node Installing source, Compilation problems, Installing binary, Installing
@section Installing a MySQL source distribution
You need the following tools to build and install @strong{MySQL} from source:
@itemize @bullet
@item
GNU @code{gunzip} to uncompress the distribution.
@item
A reasonable @code{tar} to unpack the distribution. GNU @code{tar} is
known to work.
@item
A working ANSI C++ compiler. @code{gcc} >= 2.8.1, @code{egcs} >=
1.0.2, SGI C++ and SunPro C++ are some of the compilers that are known to
work. @code{libg++} is not needed when using @code{gcc}. @code{gcc}
2.7.x has a bug that makes it impossible to compile some perfectly legal
C++ files, such as @file{sql/sql_base.cc}. If you only have @code{gcc} 2.7.x,
you must upgrade your @code{gcc} to be able to compile @strong{MySQL}.
@item
A good @code{make} program. GNU @code{make} is always recommended and is
sometimes required. If you have problems, we recommend trying GNU
@code{make} 3.75 or newer.
@end itemize
@c texi2html fails to split chapters if I use strong for all of this.
If you run into problems, @strong{PLEASE ALWAYS USE @code{mysqlbug}} when
posting questions to @email{mysql@@lists.mysql.com}. Even if the problem
isn't a bug, @code{mysqlbug} gathers system information that will help others
solve your problem. By not using @code{mysqlbug}, you lessen the likelihood
of getting a solution to your problem! You will find @code{mysqlbug} in the
@file{scripts} directory after you unpack the distribution. @xref{Bug
reports}.
@menu
* Quick install:: Quick installation overview
* Applying patches:: Applying patches
* configure options:: Typical @code{configure} options
@end menu
@node Quick install, Applying patches, Installing source, Installing source
@subsection Quick installation overview
The basic commands you must execute to install a @strong{MySQL} source
distribution are (from an unpacked @code{tar} file):
@example
shell> configure
shell> make
shell> make install
shell> scripts/mysql_install_db
shell> /usr/local/mysql/bin/safe_mysqld &
@end example
If you start from a source RPM, then do the following.
@example
shell> rpm --rebuild MySQL-VERSION.src.rpm
@end example
This will make a binary RPM that you can install.
You can add new users using the @code{bin/mysql_setpermission} script if
you install the @code{DBI} and @code{Msql-Mysql-modules} Perl modules.
Here follows a more detailed description:
To install a source distribution, follow the steps below, then proceed
to @ref{Post-installation}, for post-installation initialization and testing.
@enumerate
@item
Pick the directory under which you want to unpack the distribution, and move
into it.
@item
Obtain a distribution file from one of the sites listed in
@ref{Getting MySQL, , Getting @strong{MySQL}}.
@strong{MySQL} source distributions are provided as compressed @code{tar}
archives and have names like @file{mysql-VERSION.tar.gz}, where
@code{VERSION} is a number like @value{mysql_version}.
@item
Unpack the distribution into the current directory:
@example
shell> gunzip < mysql-VERSION.tar.gz | tar xvf -
@end example
This command creates a directory named @file{mysql-VERSION}.
@item
Change into the top-level directory of the unpacked distribution:
@example
shell> cd mysql-VERSION
@end example
@item
Configure the release and compile everything:
@example
shell> ./configure --prefix=/usr/local/mysql
shell> make
@end example
When you run @code{configure}, you might want to specify some options.
Run @code{./configure --help} for a list of options.
@ref{configure options, , @code{configure} options}, discusses some of the
more useful options.
If @code{configure} fails, and you are going to send mail to
@email{mysql@@lists.mysql.com} to ask for assistance, please include any
lines from @file{config.log} that you think can help solve the problem. Also
include the last couple of lines of output from @code{configure} if
@code{configure} aborts. Post the bug report using the @code{mysqlbug}
script. @xref{Bug reports}.
If the compile fails, see @ref{Compilation problems}, for help with
a number of common problems.
@item
Install everything:
@example
shell> make install
@end example
You might need to run this command as @code{root}.
@item
Create the @strong{MySQL} grant tables (necessary only if you haven't
installed @strong{MySQL} before):
@example
shell> scripts/mysql_install_db
@end example
Note that @strong{MySQL} versions older than 3.22.10 started the
@strong{MySQL} server when you run @code{mysql_install_db}. This is no
longer true!
@item
If you want to install support for the Perl @code{DBI}/@code{DBD} interface,
see @ref{Perl support}.
@item
If you would like @strong{MySQL} to start automatically when you boot your
machine, you can copy @code{support-files/mysql.server} to the location where
your system has its startup files. More information can be found in the
@code{support-files/mysql.server} script itself, and in @ref{Automatic
start}.
@end enumerate
After everything has been installed, you should initialize and test your
distribution.
You can start the @strong{MySQL} server with the following command,
where @code{BINDIR} is the directory in which @code{safe_mysqld} is
installed (@file{/usr/local/bin} by default):
@example
shell> BINDIR/safe_mysqld &
@end example
If that command fails immediately with @code{mysqld daemon ended} then you can
find some information in the file
@file{mysql-data-directory/'hostname'.err}. The likely reason is that
you already have another @code{mysqld} server running. @xref{Multiple
servers}.
@xref{Post-installation}.
@node Applying patches, configure options, Quick install, Installing source
@subsection Applying patches
Sometimes patches appear on the mailing list or are placed in the
@uref{http://www.mysql.com/Downloads/Patches,patches area} of the
@strong{MySQL} Web site.
To apply a patch from the mailing list, save the message in which the patch
appears in a file, change into the top-level directory of your @strong{MySQL}
source tree and run these commands:
@example
shell> patch -p1 < patch-file-name
shell> rm config.cache
shell> make clean
@end example
Patches from the FTP site are distributed as plain text files or as files
compressed with @code{gzip}. Apply a plain patch as shown above for
mailing list patches. To apply a compressed patch, change into the
top-level directory of your @strong{MySQL} source tree and run these
commands:
@example
shell> gunzip < patch-file-name.gz | patch -p1
shell> rm config.cache
shell> make clean
@end example
After applying a patch, follow the instructions for a normal source install,
beginning with the @code{./configure} step. After running the @code{make
install} step, restart your @strong{MySQL} server.
You may need to bring down any currently running server before you run
@code{make install}. (Use @code{mysqladmin shutdown} to do this.) Some
systems do not allow you to install a new version of a program if it replaces
the version that is currently executing.
@node configure options, , Applying patches, Installing source
@subsection Typical @code{configure} options
The @code{configure} script gives you a great deal of control over how
you configure your @strong{MySQL} distribution. Typically you do this
using options on the @code{configure} command line. You can also affect
@code{configure} using certain environment variables. @xref{Environment
variables}. For a list of options supported by @code{configure}, run
this command:
@example
shell> ./configure --help
@end example
Some of the more commonly-used @code{configure} options are described below:
@itemize @bullet
@item
To compile just the @strong{MySQL} client libraries and client programs and
not the server, use the @code{--without-server} option:
@example
shell> ./configure --without-server
@end example
If you don't have a C++ compiler, @code{mysql} will not compile (it is the
one client program that requires C++). In this case,
you can remove the code in @code{configure} that tests for the C++ compiler
and then run @code{./configure} with the @code{--without-server} option. The
compile step will still try to build @code{mysql}, but you can ignore any
warnings about @file{mysql.cc}. (If @code{make} stops, try @code{make -k}
to tell it to continue with the rest of the build even if errors occur.)
@item
If you don't want your log files and database directories located under
@file{/usr/local/var}, use a @code{configure} command something like one
of these:
@example
shell> ./configure --prefix=/usr/local/mysql
shell> ./configure --prefix=/usr/local \
--localstatedir=/usr/local/mysql/data
@end example
The first command changes the installation prefix so that everything is
installed under @file{/usr/local/mysql} rather than the default of
@file{/usr/local}. The second command preserves the default installation
prefix, but overrides the default location for database directories
(normally @file{/usr/local/var}) and changes it to
@code{/usr/local/mysql/data}.
@item
If you are using Unix and you want the @strong{MySQL} socket located somewhere
other than the default location (normally in the directory @file{/tmp} or
@file{/var/run}, use a @code{configure} command like this:
@example
shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
@end example
Note that the given file must be an absolute pathname!
@item
If you want to compile statically-linked programs (e.g., to make a binary
distribution, to get more speed or to work around problems with some RedHat
distributions), run @code{configure} like this:
@example
shell> ./configure --with-client-ldflags=-all-static \
--with-mysqld-ldflags=-all-static
@end example
@item
If you are using @code{gcc} and don't have @code{libg++} or @code{libstdc++}
installed, you can tell @code{configure} to use @code{gcc} as your C++
compiler:
@tindex CC environment variable
@tindex Environment variable, CC
@tindex CXX environment variable
@tindex Environment variable, CXX
@example
shell> CC=gcc CXX=gcc ./configure
@end example
When you use @code{gcc} as your C++ compiler, it will not attempt to link in
@code{libg++} or @code{libstdc++}.
If the build fails and produces errors about your compiler or linker not
being able to create the shared library @file{libmysqlclient.so.#} (@samp{#}
is a version number), you can work around this problem by giving the
@code{--disable-shared} option to @code{configure}. In this case,
@code{configure} will not build a shared @code{libmysqlclient.so.#} library.
@item
You can configure @strong{MySQL} not to use @code{DEFAULT} column values for
non-@code{NULL} columns (i.e., columns that are not allowed to be
@code{NULL}). This causes @code{INSERT} statements to generate an error
unless you explicitly specify values for all columns that require a
non-@code{NULL} value. To suppress use of default values, run
@code{configure} like this:
@tindex CXXFLAGS environment variable
@tindex Environment variable, CXXFLAGS
@example
shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure
@end example
@item
By default, @strong{MySQL} uses the ISO-8859-1 (Latin1) character set. To
change the default set, use the @code{--with-charset} option:
@example
shell> ./configure --with-charset=CHARSET
@end example
@code{CHARSET} may be one of @code{big5}, @code{cp1251}, @code{cp1257},
@code{czech}, @code{danish},@code{dec8}, @code{dos}, @code{euc_kr},
@code{gb2312}, @code{gbk}, @code{german1}, @code{hebrew}, @code{hp8},
@code{hungarian}, @code{koi8_ru}, @code{koi8_ukr}, @code{latin1}, @code{latin2},
@code{sjis}, @code{swe7}, @code{tis620}, @code{ujis}, @code{usa7},
@code{win1251} or @code{win1251ukr}.
@xref{Character sets}.
If you want to convert characters between the server and the client,
you should take a look at the @code{SET OPTION CHARACTER SET} command.
@xref{SET OPTION, , @code{SET OPTION}}.
@cindex @code{myisamchk}
@strong{Warning:} If you change character sets after having created any
tables, you will have to run @code{myisamchk -r -q} on every table. Your
indexes may be sorted incorrectly otherwise. (This can happen if you
install @strong{MySQL}, create some tables, then reconfigure
@strong{MySQL} to use a different character set and reinstall it.)
@item
To configure
@strong{MySQL} with debugging code, use the @code{--with-debug} option:
@example
shell> ./configure --with-debug
@end example
This causes a safe memory allocator to be included that can find some errors
and that provides output about what is happening.
@xref{Debugging server}.
@item
If your client programs are using threads, you need to compile the
@strong{MySQL} client library to be thread safe with
@code{--with-thread-safe-client}; this forces the library to use thread
safe functions calls for some functions that are not thread safe by
default. You pay a very small performance penalty by doing this, but
generally it's quite safe to use this option.
@item
Options that pertain to particular systems can be found in the
system-specific sections later in this chapter.
@xref{Source install system issues}.
@end itemize
@node Compilation problems, MIT-pthreads, Installing source, Installing
@section Problems compiling?
All @strong{MySQL} programs compile cleanly for us with no warnings on
Solaris using @code{gcc}. On other systems, warnings may occur due to
differences in system include files. See @ref{MIT-pthreads}, for warnings
that may occur when using MIT-pthreads. For other problems, check the list
below.
The solution to many problems involves reconfiguring. If you do need to
reconfigure, take note of the following:
@cindex Running @code{configure} after prior invocation
@cindex @code{configure}, running after prior invocation
@itemize @bullet
@item
If @code{configure} is run after it already has been run, it may use
information that was gathered during its previous invocation. This
information is stored in @file{config.cache}. When @code{configure} starts
up, it looks for that file and reads its contents if it exists, on the
assumption that the information is still correct. That assumption is invalid
when you reconfigure.
@item
Each time you run @code{configure}, you must run @code{make} again
to recompile. However, you may want to remove old object files from previous
builds first, because they were compiled using different configuration options.
@end itemize
To prevent old configuration information or object files from being used,
run these commands before rerunning @code{configure}:
@example
shell> rm config.cache
shell> make clean
@end example
Alternatively, you can run @code{make distclean}.
The list below describes some of the problems compiling @strong{MySQL}
that have been found to occur most often:
@itemize @bullet
@item
@cindex @code{cc1plus} problems
@cindex @code{fatal signal 11}
@cindex @code{sql_yacc.cc} problems
@cindex Internal compiler errors
@cindex Virtual memory problems while compiling
If you get errors when compiling @file{sql_yacc.cc} such as the ones shown
below, you have probably run out of memory or swap space:
@example
Internal compiler error: program cc1plus got fatal signal 11
or
Out of virtual memory
or
Virtual memory exhausted
@end example
The problem is that @code{gcc} requires huge amounts of memory to compile
@file{sql_yacc.cc} with inline functions. Try running @code{configure} with
the @code{--with-low-memory} option:
@example
shell> ./configure --with-low-memory
@end example
This option causes @code{-fno-inline} to be added to the compile line if you
are using @code{gcc} and @code{-O0} if you are using something else. You
should try the @code{--with-low-memory} option even if you have so much
memory and swap space that you think you can't possibly have run out. This
problem has been observed to occur even on systems with generous hardware
configurations, and the @code{--with-low-memory} option usually fixes it.
@item
By default, @code{configure} picks @code{c++} as the compiler name and
GNU @code{c++} links with @code{-lg++}. If you are using @code{gcc},
that behavior can cause problems during configuration such as this:
@cindex C++ compiler cannot create executables
@example
configure: error: installation or configuration problem:
C++ compiler cannot create executables.
@end example
@tindex CXX environment variable
@tindex Environment variable, CXX
You might also observe problems during compilation related to
@code{g++}, @code{libg++} or @code{libstdc++}.
One cause of these problems is that you may not have @code{g++}, or you may
have @code{g++} but not @code{libg++} or @code{libstdc++}. Take a look at
the @file{config.log} file. It should contain the exact reason why your c++
compiler didn't work! To work around these problems, you can use @code{gcc}
as your C++ compiler. Try setting the environment variable @code{CXX} to
@code{"gcc -O3"}. For example:
@tindex CXX environment variable
@tindex Environment variables, CXX
@example
shell> CXX="gcc -O3" ./configure
@end example
This works because @code{gcc} compiles C++ sources as well as @code{g++}
does, but does not link in @code{libg++} or @code{libstdc++} by default.
Another way to fix these problems, of course, is to install @code{g++},
@code{libg++} and @code{libstdc++}.
@item
If your compile fails with errors such as any of the following,
you must upgrade your version of @code{make} to GNU @code{make}:
@example
making all in mit-pthreads
make: Fatal error in reader: Makefile, line 18:
Badly formed macro assignment
or
make: file `Makefile' line 18: Must be a separator (:
or
pthread.h: No such file or directory
@end example
@cindex Solaris troubleshooting
@cindex FreeBSD troubleshooting
@cindex Troubleshooting, Solaris
@cindex Troubleshooting, FreeBSD
Solaris and FreeBSD are known to have troublesome @code{make} programs.
GNU @code{make} version 3.75 is known to work.
@tindex CC environment variable
@tindex Environment variable, CC
@tindex CXX environment variable
@tindex Environment variable, CXX
@tindex CFLAGS environment variable
@tindex Environment variable, CFLAGS
@tindex CXXFLAGS environment variable
@tindex Environment variable, CXXFLAGS
@item
If you want to define flags to be used by your C or C++ compilers, do so by
adding the flags to the @code{CFLAGS} and @code{CXXFLAGS} environment
variables. You can also specify the compiler names this way using @code{CC}
and @code{CXX}. For example:
@example
shell> CC=gcc
shell> CFLAGS=-O6
shell> CXX=gcc
shell> CXXFLAGS=-O6
shell> export CC CFLAGS CXX CXXFLAGS
@end example
See @ref{MySQL binaries}, for a list of flag definitions that have been found
to be useful on various systems.
@item
If you get an error message like this,
you need to upgrade your @code{gcc} compiler:
@example
client/libmysql.c:273: parse error before `__attribute__'
@end example
@code{gcc} 2.8.1 is known to work, but we recommend using @code{gcc} 2.95.2 or
@code{egcs} 1.0.3a instead.
@item
If you get errors such as those shown below when compiling @code{mysqld},
@code{configure} didn't correctly detect the type of the last argument to
@code{accept()}, @code{getsockname()} or @code{getpeername()}:
@example
cxx: Error: mysqld.cc, line 645: In this statement, the referenced
type of the pointer value "&length" is "unsigned long", which
is not compatible with "int".
new_sock = accept(sock, (struct sockaddr *)&cAddr, &length);
@end example
To fix this, edit the @file{config.h} file (which is generated by
@code{configure}). Look for these lines:
@example
/* Define as the base type of the last arg to accept */
#define SOCKET_SIZE_TYPE XXX
@end example
Change @code{XXX} to @code{size_t} or @code{int}, depending on your
operating system. (Note that you will have to do this each time you run
@code{configure}, because @code{configure} regenerates @file{config.h}.)
@item
The @file{sql_yacc.cc} file is generated from @file{sql_yacc.yy}. Normally
the build process doesn't need to create @file{sql_yacc.cc}, because
@strong{MySQL} comes with an already-generated copy. However, if you do need
to recreate it, you might encounter this error:
@example
"sql_yacc.yy", line xxx fatal: default action causes potential...
@end example
This is a sign that your version of @code{yacc} is deficient.
You probably need to install @code{bison} (the GNU version of @code{yacc})
and use that instead.
@item
If you need to debug @code{mysqld} or a @strong{MySQL} client, run
@code{configure} with the @code{--with-debug} option, then recompile and
link your clients with the new client library.
@xref{Debugging client}.
@end itemize
@node MIT-pthreads, Perl support, Compilation problems, Installing
@section MIT-pthreads notes
This section describes some of the issues involved in using MIT-pthreads.
Note that on Linux you should NOT use MIT-pthreads but install LinuxThreads!
@xref{Linux}.
If your system does not provide native thread support, you will need to
build @strong{MySQL} using the MIT-pthreads package. This includes
most FreeBSD systems, SunOS 4.x, Solaris 2.4 and earlier, and some others.
@xref{Which OS}.
@itemize @bullet
@item
On most systems, you can force MIT-pthreads to be used by running
@code{configure} with the @code{--with-mit-threads} option:
@example
shell> ./configure --with-mit-threads
@end example
Building in a non-source directory is not supported when using
MIT-pthreads, because we want to minimize our changes to this code.
@item
MIT-pthreads doesn't support the @code{AF_UNIX} protocol used to implement
Unix sockets. This means that if you compile using MIT-pthreads, all
connections must be made using TCP/IP (which is a little slower). If you
find after building @strong{MySQL} that you cannot connect to the local
server, it may be that your client is attempting to connect to
@code{localhost} using a Unix socket as the default. Try making a TCP/IP
connection with @code{mysql} by using a host option (@code{-h} or
@code{--host}) to specify the local host name explicitly.
@item
The checks that determine whether or not to use MIT-pthreads occur only
during the part of the configuration process that deals with the server
code. If you have configured the distribution using @code{--without-server}
to build only the client code, clients will not know whether or not
MIT-pthreads is being used and will use Unix socket connections by default.
Because Unix sockets do not work under MIT-pthreads, this means you will need
to use @code{-h} or @code{--host} when you run client programs.
@item
When @strong{MySQL} is compiled using MIT-pthreads, system locking is
disabled by default for performance reasons. You can tell the server to use
system locking with the @code{--use-locking} option.
@item
Sometimes the pthread @code{bind()} command fails to bind to a socket without
any error message (at least on Solaris). The result is that all connections
to the server fail. For example:
@example
shell> mysqladmin version
mysqladmin: connect to server at '' failed;
error: 'Can't connect to mysql server on localhost (146)'
@end example
The solution to this is to kill the @code{mysqld} server and restart it.
This has only happened to us when we have forced the server down and done
a restart immediately.
@item
With MIT-pthreads, the @code{sleep()} system call isn't interruptible with
@code{SIGINT} (break). This is only noticeable when you run @code{mysqladmin
--sleep}. You must wait for the @code{sleep()} call to terminate before the
interrupt is served and the process stops.
@item
When linking you may receive warning messages like these (at least on
Solaris); they can be ignored:
@example
ld: warning: symbol `_iob' has differing sizes:
(file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
file /usr/lib/libc.so value=0x140);
/my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
ld: warning: symbol `__iob' has differing sizes:
(file /my/local/pthreads/lib/libpthread.a(findfp.o) value=0x4;
file /usr/lib/libc.so value=0x140);
/my/local/pthreads/lib/libpthread.a(findfp.o) definition taken
@end example
@item
Some other warnings also can be ignored:
@example
implicit declaration of function `int strtoll(...)'
implicit declaration of function `int strtoul(...)'
@end example
@item
We haven't gotten @code{readline} to work with MIT-pthreads. (This isn't
needed, but may be interesting for someone.)
@end itemize
@node Perl support, Source install system issues, MIT-pthreads, Installing
@section Perl installation comments
@menu
* Perl installation:: Installing Perl on Unix
* ActiveState Perl:: Installing ActiveState Perl on Win32
* Win32 Perl:: Installing the @strong{MySQL} Perl distribution on Win32
* Perl support problems:: Problems using the Perl @code{DBI}/@code{DBD} interface
@end menu
@node Perl installation, ActiveState Perl, Perl support, Perl support
@subsection Installing Perl on Unix
Perl support for @strong{MySQL} is provided by means of the
@code{DBI}/@code{DBD} client interface. @xref{Perl}. The Perl
@code{DBD}/@code{DBI} client code requires Perl 5.004 or later. The
interface @emph{will not work} if you have an older version of Perl.
@strong{MySQL} Perl support also requires that you've installed
@strong{MySQL} client programming support. If you installed @strong{MySQL}
from RPM files, client programs are in the client RPM, but client programming
support is in the developer RPM. Make sure you've installed the latter RPM.
As of release 3.22.8, Perl support is distributed separately from the main
@strong{MySQL} distribution. If you want to install Perl support, the files
you will need can be obtained from @uref{http://www.mysql.com/Downloads/Contrib/}.
The Perl distributions are provided as compressed @code{tar} archives and
have names like @file{MODULE-VERSION.tar.gz}, where @code{MODULE} is the
module name and @code{VERSION} is the version number. You should get the
@code{Data-Dumper}, @code{DBI}, and @code{Msql-Mysql-modules} distributions
and install them in that order. The installation procedure is shown below.
The example shown is for the @code{Data-Dumper} module, but the procedure is
the same for all three distributions.
@enumerate
@item
Unpack the distribution into the current directory:
@example
shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf -
@end example
This command creates a directory named @file{Data-Dumper-VERSION}.
@item
Change into the top-level directory of the unpacked distribution:
@example
shell> cd Data-Dumper-VERSION
@end example
@item
Build the distribution and compile everything:
@example
shell> perl Makefile.PL
shell> make
shell> make test
shell> make install
@end example
@end enumerate
The @code{make test} command is important, because it verifies that the
module is working. Note that when you run that command during the
@code{Msql-Mysql-modules} installation to exercise the interface code, the
@strong{MySQL} server must be running or the test will fail.
It is a good idea to rebuild and reinstall the @code{Msql-Mysql-modules}
distribution whenever you install a new release of @strong{MySQL},
particularly if you notice symptoms such as all your @code{DBI} scripts
dumping core after you upgrade @strong{MySQL}.
If you don't have the right to install Perl modules in the system directory
or if you to install local Perl modules, the following reference may help
you:
@example
@uref{http://www.iserver.com/support/contrib/perl5/modules.html}
@end example
Look under the heading
@code{Installing New Modules that Require Locally Installed Modules}.
@node ActiveState Perl, Win32 Perl, Perl installation, Perl support
@subsection Installing ActiveState Perl on Win32
To install the @strong{MySQL} @code{DBD} module with ActiveState Perl on
Win32, you should do the following:
@itemize @bullet
@item Open a DOS shell.
@item If required, set the HTTP_proxy variable. For example, you might try:
@code{set HTTP_proxy=my.proxy.com:3128}
@item Start the PPM program: @code{C:\perl\bin\ppm.pl}
@item If you have not already done so, install @code{DBI}: @code{install DBI}
@item If this succeeds, install @code{ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd}
@end itemize
The above should work at least with ActiveState Perl 5.6.
If you can't get the above to work, you should instead install the
@strong{MyODBC} driver and connect to @strong{MySQL} server through
ODBC.
@example
use DBI;
$dbh= DBI->connect("DBI:ODBC:$dsn","$user","$password") ||
die "Got error $DBI::errstr when connecting to $dsn\n";
@end example
@node Win32 Perl, Perl support problems, ActiveState Perl, Perl support
@subsection Installing the MySQL Perl distribution on Win32
The @strong{MySQL} Perl distribution contains @code{DBI},
@code{DBD:MySQL} and @code{DBD:ODBC}.
@itemize @bullet
@item Get the Perl distribution for Win32 from
@uref{http://www.mysql.com/download.html}.
@item Unzip the distribution in @code{C:} so that you get a @file{C:\PERL} directory.
@item Add the directory @file{C:\PERL\BIN} to your path.
@item Add the directory @file{C:\PERL\BIN\MSWin32-x86-thread} or
@file{C:\PERL\BIN\MSWin32-x86} to your path.
@item Test that @code{perl} works by executing @code{perl -v} in a DOS shell.
@end itemize
@node Perl support problems, , Win32 Perl, Perl support
@subsection Problems using the Perl @code{DBI}/@code{DBD} interface
If Perl reports that it can't find the @code{../mysql/mysql.so} module,
then the problem is probably that Perl can't locate the shared library
@file{libmysqlclient.so}.
You can fix this by any of the following methods:
@itemize @bullet
@item
Compile the @code{Msql-Mysql-modules} distribution with @code{perl
Makefile.PL -static -config} rather than @code{perl Makefile.PL}
@item
Copy @code{libmysqlclient.so} to the directory where your other shared
libraries are located (probably @file{/usr/lib} or @file{/lib}).
@item
On @code{Linux} you can add the pathname of the directory where
@code{libmysqlclient.so} is located to the @file{/etc/ld.so.conf} file.
@item
@tindex LD_RUN_PATH environment variable
@tindex Environment variable, LD_RUN_PATH
Add the pathname of the directory where @code{libmysqlclient.so} is located
to the @code{LD_RUN_PATH} environment variable.
@end itemize
If you get the following errors from @code{DBD-mysql},
you are probably using @code{gcc} (or using an old binary compiled with
@code{gcc}):
@example
/usr/bin/perl: can't resolve symbol '__moddi3'
/usr/bin/perl: can't resolve symbol '__divdi3'
@end example
Add @code{-L/usr/lib/gcc-lib/... -lgcc} to the link command when the
@file{mysql.so} library gets built (check the output from @code{make} for
@file{mysql.so} when you compile the Perl client). The @code{-L} option
should specify the pathname of the directory where @file{libgcc.a} is located
on your system.
Another cause of this problem may be that Perl and @strong{MySQL} aren't both
compiled with @code{gcc}. In this case, you can solve the mismatch by
compiling both with @code{gcc}.
If you want to use the Perl module on a system that doesn't support dynamic
linking (like SCO) you can generate a static version of Perl that includes
@code{DBI} and @code{DBD-mysql}. The way this works is that you generate a
version of Perl with the @code{DBI} code linked in and install it on top of
your current Perl. Then you use that to build a version of Perl that
additionally has the @code{DBD} code linked in, and install that.
On SCO, you must have the following environment variables set:
@example
shell> LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib
or
shell> LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:/usr/progressive/lib:/usr/skunk/lib
shell> LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:/usr/progressive/lib:/usr/skunk/lib
shell> MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:/usr/skunk/man:
@end example
First, create a Perl that includes a statically-linked @code{DBI} by running
these commands in the directory where your @code{DBI} distribution is
located:
@example
shell> perl Makefile.PL -static -config
shell> make
shell> make install
shell> make perl
@end example
Then you must install the new Perl. The output of @code{make perl} will
indicate the exact @code{make} command you will need to execute to perform
the installation. On SCO, this is @code{make -f Makefile.aperl inst_perl
MAP_TARGET=perl}.
Next, use the just-created Perl to create another Perl that also includes a
statically-linked @code{DBD::mysql} by running these commands in the
directory where your @code{Msql-Mysql-modules} distribution is located:
@example
shell> perl Makefile.PL -static -config
shell> make
shell> make install
shell> make perl
@end example
Finally, you should install this new Perl. Again, the output of @code{make
perl} indicates the command to use.
@node Source install system issues, Win32, Perl support, Installing
@section System-specific issues
The following sections indicate some of the issues that have been observed to
occur on particular systems when installing @strong{MySQL} from a source
distribution.
@menu
* Solaris:: Solaris notes
* Solaris 2.7:: Solaris 2.7 / 2.8 notes
* Solaris x86:: Solaris x86 notes
* SunOS:: SunOS 4 notes
* Linux:: Linux notes (all Linux versions)
* Alpha-DEC-Unix:: Alpha-DEC-Unix notes
* Alpha-DEC-OSF1:: Alpha-DEC-OSF1 notes
* SGI-Irix:: SGI-Irix notes
* FreeBSD:: FreeBSD notes
* NetBSD:: NetBSD notes
* OpenBSD:: OpenBSD 2.5 notes
* BSDI:: BSD/OS notes
* SCO:: SCO notes
* SCO Unixware:: SCO Unixware 7.0 notes
* IBM-AIX:: IBM-AIX notes
* HP-UX 10.20:: HP-UX 10.20 notes
* HP-UX 11.x:: HP-UX 11.x notes
* MacOSX:: MacOSX notes
@end menu
@node Solaris, Solaris 2.7, Source install system issues, Source install system issues
@subsection Solaris notes
On Solaris, you may run into trouble even before you get the @strong{MySQL}
distribution unpacked! Solaris @code{tar} can't handle long file names, so
you may see an error like this when you unpack @strong{MySQL}:
@example
x mysql-3.22.12-beta/bench/Results/ATIS-mysql_odbc-NT_4.0-cmp-db2,informix,ms-sql,mysql,oracle,solid,sybase, 0 bytes, 0 tape blocks
tar: directory checksum error
@end example
In this case, you must use GNU @code{tar} (@code{gtar}) to unpack the
distribution. You can find a precompiled copy for Solaris at
@uref{http://www.mysql.com/Downloads/}.
Sun native threads work only on Solaris 2.5 and higher. For 2.4 and
earlier versions, @strong{MySQL} will automatically use
MIT-pthreads. @xref{MIT-pthreads}.
If you get the following error from configure:
@example
checking for restartable system calls... configure: error can not run test
programs while cross compiling
@end example
This means that you have something wrong with your compiler installation!
In this case you should upgrade your compiler to a newer version. You may
also be able to solve this problem by inserting the following row into the
@code{config.cache} file:
@example
ac_cv_sys_restartable_syscalls=$@{ac_cv_sys_restartable_syscalls='no'@}
@end example
If you are using Solaris on a SPARC, the recommended compiler is
@code{gcc} 2.95.2. You can find this at @uref{http://gcc.gnu.org/}.
Note that @code{egs} 1.1.1 and @code{gcc} 2.8.1 don't work reliably on
SPARC!
The recommended @code{configure} line when using @code{gcc} 2.95.2 is:
@example
shell> CC=gcc CFLAGS="-O6" \
CXX=gcc CXXFLAGS="-O6 -felide-constructors -fno-exceptions -fno-rtti" \
./configure --prefix=/usr/local/mysql --with-low-memory
@end example
If you have the Sun Workshop 4.2 compiler, you can run @code{configure} like
this:
CC=cc CFLAGS="-xstrconst -Xa -xO4 -native -mt" CXX=CC CXXFLAGS="-xO4 -native -noex -mt" ./configure --prefix=/usr/local/mysql
@example
shell> CC=cc CFLAGS="-Xa -fast -xO4 -native -xstrconst -mt" \
CXX=CC CXXFLAGS="-noex -XO4 -mt" \
./configure
@end example
You may also have to edit the @code{configure} script to change this line:
@example
#if !defined(__STDC__) || __STDC__ != 1
@end example
to this:
@example
#if !defined(__STDC__)
@end example
If you turn on @code{__STDC__} with the @code{-Xc} option, the Sun compiler
can't compile with the Solaris @file{pthread.h} header file. This is a Sun
bug (broken compiler or broken include file).
If @code{mysqld} issues the error message shown below when you run it, you have
tried to compile @strong{MySQL} with the Sun compiler without enabling the
multi-thread option (@code{-mt}):
@example
libc internal error: _rmutex_unlock: rmutex not held
@end example
Add @code{-mt} to @code{CFLAGS} and @code{CXXFLAGS} and try again.
If you get the following error when compiling @strong{MySQL} with @code{gcc},
it means that your @code{gcc} is not configured for your version of Solaris!
@example
shell> gcc -O3 -g -O2 -DDBUG_OFF -o thr_alarm ...
./thr_alarm.c: In function `signal_hand':
./thr_alarm.c:556: too many arguments to function `sigwait'
@end example
The proper thing to do in this case is to get the newest version of
@code{gcc} and compile it with your current @code{gcc} compiler! At
least for Solaris 2.5, almost all binary versions of @code{gcc} have
old, unusable include files that will break all programs that use
threads (and possibly other programs)!
Solaris doesn't provide static versions of all system libraries
(@code{libpthreads} and @code{libdl}), so you can't compile @strong{MySQL}
with @code{--static}. If you try to do so, you will get the error:
@example
ld: fatal: library -ldl: not found
@end example
If too many processes try to connect very rapidly to @code{mysqld}, you will
see this error in the @strong{MySQL} log:
@example
Error in accept: Protocol error
@end example
You might try starting the server with the @code{--set-variable back_log=50}
option as a workaround for this. @xref{Command-line options}.
If you are linking your own @strong{MySQL} client, you might get the
following error when you try to execute it:
@example
ld.so.1: ./my: fatal: libmysqlclient.so.#: open failed: No such file or directory
@end example
The problem can be avoided by one of the following methods:
@itemize @bullet
@item
Link the client with the following flag (instead of @code{-Lpath}):
@code{-Wl,r/full-path-to-libmysqlclient.so}.
@item
Copy @code{libmysqclient.so} to @file{/usr/lib}.
@item
@tindex LD_RUN_PATH environment variable
@tindex Environment variable, LD_RUN_PATH
Add the pathname of the directory where @code{libmysqlclient.so} is located
to the @code{LD_RUN_PATH} environment variable before running your client.
@end itemize
When using the @code{--with-libwrap} configure option, you must also
include the libraries that @code{libwrap.a} needs:
@example
--with-libwrap="/opt/NUtcpwrapper-7.6/lib/libwrap.a -lnsl -lsocket
@end example
If you have problems with that configure or @strong{MySQL} tries to link
with @code{-lz} and you don't have this installed, you have two options:
@itemize @bullet
@item
If you want to be able to use the compressed communication protocol,
you need to get and install zlib from ftp.gnu.org.
@item
Configure with @code{--with-named-z-libs=no}
@end itemize
If you are using gcc and have problems with loading @code{UDF} functions
into @code{MySQL}, try adding @code{-lgcc} to the link line for the
@code{UDF} function.
@node Solaris 2.7, Solaris x86, Solaris, Source install system issues
@subsection Solaris 2.7 / 2.8 notes
You can normally use a Solaris 2.6 binary on Solaris 2.7 and 2.8. Most
of the Solaris 2.6 issues also apply for Solaris 2.7 and 2.8.
Note that @strong{MySQL} 3.23.4 and above should be able to autodetect
new versions of Solaris and enable workarounds for the following
problems!
Solaris 2.7 / 2.8 has some bugs in the include files. You may see the
following error when you use @code{gcc}:
@example
/usr/include/widec.h:42: warning: `getwc' redefined
/usr/include/wchar.h:326: warning: this is the location of the previous
definition
@end example
If this occurs, you can do the following to fix the problem:
Copy @code{/usr/include/widec.h} to
@code{.../lib/gcc-lib/os/gcc-version/include} and change line 41 from:
@example
#if !defined(lint) && !defined(__lint)
to
#if !defined(lint) && !defined(__lint) && !defined(getwc)
@end example
Alternatively, you can edit @file{/usr/include/widec.h} directly. Either
way, after you make the fix, you should remove @file{config.cache} and run
@code{configure} again!
If you get errors like this when you run @code{make}, it's because @code{configure}
didn't detect the @file{curses.h} file (probably because of the error in
@code{/usr/include/widec.h}:
@example
In file included from mysql.cc:50:
/usr/include/term.h:1060: syntax error before `,'
/usr/include/term.h:1081: syntax error before `;'
@end example
The solution to this is to do one of the following steps:
@itemize @bullet
@item
Edit @file{/usr/include/widec.h} as indicted above and rerun configure
@item
Remove the @code{#define HAVE_TERM} line from @file{config.h} file and
run @code{make} again.
@item
Configure with @code{CFLAGS=-DHAVE_CURSES CXXFLAGS=-DHAVE_CURSES ./configure}
@end itemize
@node Solaris x86, SunOS, Solaris 2.7, Source install system issues
@subsection Solaris x86 notes
If you are using @code{gcc} or @code{egcs} on Solaris x86 and you
experience problems with core dumps under load, you should use the
following @code{configure} command:
@example
shell> CC=gcc CFLAGS="-O6 -fomit-frame-pointer" \
CXX=gcc \
CXXFLAGS="-O6 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" \
./configure --prefix=/usr/local/mysql
@end example
This will avoid problems with the @code{libstdc++} library and with C++
exceptions.
If this doesn't help, you should compile a debug version and run
it with a trace file or under @code{gdb}. @xref{Debugging server}.
@node SunOS, Linux, Solaris x86, Source install system issues
@subsection SunOS 4 notes
On SunOS 4, MIT-pthreads is needed to compile @strong{MySQL}, which in turn
means you will need GNU @code{make}.
Some SunOS 4 systems have problems with dynamic libraries and
@code{libtool}. You can use the following @code{configure} line to avoid
this problem:
@example
shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static
@end example
When compiling @code{readline}, you may get warnings about duplicate defines.
These may be ignored.
When compiling @code{mysqld}, there will be some @code{implicit declaration
of function} warnings. These may be ignored.
@node Linux, Alpha-DEC-Unix, SunOS, Source install system issues
@subsection Linux notes (all Linux versions)
@strong{MySQL} uses LinuxThreads on Linux. If you are using an old Linux
version that doesn't have @code{glibc2}, you must install LinuxThreads before
trying to compile
@strong{MySQL}. @uref{http://www.mysql.com/Downloads/Linux}
Note that @code{glibc} versions before and including 2.1.1 has a fatal
bug in @code{pthread_mutex_timedwait} handling, which is used when you
do @code{INSERT DELAYED}. If you are using @code{INSERT DELAYED}, you
@strong{MUST} add the following patch to your glibc library:
@uref{http://www.mysql.com/Downloads/Patches/glibc-pthread_cond_timedwait.patch}.
@strong{MySQL} 3.23.7 and the @strong{MySQL} 3.22.32 contains a
temporary workaround for this bug.
If you plan to have 1000+ concurrent connections, you will need to make
some changes to LinuxThreads, recompile it, and re-link MySQL against
the new libpthread.a . Increase PTHREAD_THREADS_MAX in
sysdeps/unix/sysv/linux/bits/local_lim.h to 4096 and decrease STACK_SIZE
in internals.h to 256 KB . Note that MySQL will not be stable with
around 1000 connections if STACK_SIZE is the default of 2 MB.
If you have glibc 2.1.3-65 or newer, you don't have to increase STACK_SIZE;
You can instead just change the @code{thread_stack} value for @code{mysqld}.
If you use a lot of concurrent connections, you may suffer from a 2.2
kernel "feature" that penalizes a process for forking or cloning a child
in an attempt to prevent a fork bomb attack. This will cause MySQL not
to scale well as you increase the number of concurrent clients. On
single CPU systems, we have seen this manifested in a very slow thread
creation - which means it may take a long time to connect to MySQL ( as
long as 1 minute), and it may take just as long to shut it down. On
multiple CPU systems, we have observed a gradual drop in query speed as
the number of clients increases. In the process of trying to find a
solution, we have received a kernel patch from one of our users, who
claimed it made a lot of difference for his site. We have done some
limited testing in which the patch greatly improved the scalabitility of
MySQL. The patch is available
@uref{http://www.mysql.com/Downloads/Patches/linux-fork.patch,here} - be
warned, though, that we assume no reponsibility for any damage that this
patch could do - use at your own risk. We have also been told by the
Linux kernel developers that this problem is fixed in 2.4, although we
have not yet done any testing.
If you can't start @code{mysqld} or if @code{mysql_install_db} doesn't work,
please continue reading! This only happens on Linux system with problems in
the LinuxThreads or @code{libc}/@code{glibc} libraries. There are a lot of
simple workarounds to get @strong{MySQL} to work! The simplest is to use the
binary version of @strong{MySQL} (not the RPM) for Linux x86. One nice
aspect of this version is that it's probably 10% faster than any version you
would compile yourself! @xref{Compile and link options}.
One known problem with the binary distribution is that with older Linux
systems that use @code{libc} (like RedHat 4.x or Slackware), you will get
some non-fatal problems with hostname resolution
@xref{Binary notes-Linux}.
@code{myisamchk} hangs with @code{libc.so.5.3.12}. Upgrading to the newest
@code{libc} fixes this problem.
When using LinuxThreads you will see a minimum of three processes
running. These are in fact threads. There will be one thread for the
LinuxThreads manager, one thread to handle connections, and one thread
to handle alarms and signals.
Note that the linux kernel and the linuxthread library can by default
only have 1024 threads. This means that you can only have up to 1021
connections to MySQL on a unpatched system. The page
@uref{http://www.volano.com/linuxnotes.html} contains information how to
go around this limit.
If you see a dead @code{mysqld} daemon process with @code{ps}, this usually
means that you have found a bug in @strong{MySQL} or you have got a corrupted
table. @xref{Crashing}.
If you are using LinuxThreads and @code{mysqladmin shutdown} doesn't work,
you must upgrade to LinuxThreads 0.7.1 or newer.
If you are using RedHat, you might get errors like this:
@example
/usr/bin/perl is needed...
/usr/sh is needed...
/usr/sh is needed...
@end example
If so, you should upgrade your version of @code{rpm} to
@file{rpm-2.4.11-1.i386.rpm} and @file{rpm-devel-2.4.11-1.i386.rpm} (or later).
You can get the upgrades of libraries to RedHat 4.2 from
@uref{ftp://ftp.redhat.com/updates/4.2/i386}. Or
@uref{http://www.sunsite.unc.edu/pub/Linux/distributions/redhat/code/rpm/}
for other distributions.
If you are linking your own @strong{MySQL} client and get the error:
@example
ld.so.1: ./my: fatal: libmysqlclient.so.4: open failed: No such file or directory
@end example
when executing them, the problem can be avoided by one of the following
methods:
@itemize @bullet
@item
Link the client with the following flag (instead of @code{-Lpath}):
@code{-Wl,r/path-libmysqlclient.so}.
@item
Copy @code{libmysqclient.so} to @file{/usr/lib}.
@item
@tindex LD_RUN_PATH environment variable
@tindex Environment variable, LD_RUN_PATH
Add the pathname of the directory where @code{libmysqlclient.so} is located
to the @code{LD_RUN_PATH} environment variable before running your client.
@end itemize
If you are using the Fujitsu compiler @code{(fcc / FCC)} you will have
some problems compiling @strong{MySQL} because the Linux header files are very
@code{gcc} oriented.
The following @code{configure} line should work with @code{fcc/FCC}:
@example
CC=fcc CFLAGS="-O -K fast -K lib -K omitfp -Kpreex -D_GNU_SOURCE -DCONST=const -DNO_STRTOLL_PROTO" CXX=FCC CXXFLAGS="-O -K fast -K lib -K omitfp -K preex --no_exceptions --no_rtti -D_GNU_SOURCE -DCONST=const -Dalloca=__builtin_alloca -DNO_STRTOLL_PROTO '-D_EXTERN_INLINE=static __inline'" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-low-memory
@end example
@menu
* Linux-x86:: Linux-x86 notes
* Linux-RedHat50:: RedHat 5.0 notes
* Linux-RedHat51:: RedHat 5.1 notes
* Linux-SPARC:: Linux-SPARC notes
* Linux-Alpha:: Linux-Alpha notes
* MKLinux:: MkLinux notes
* Qube2:: Qube2 Linux notes
* Linux-Ia64::
@end menu
@node Linux-x86, Linux-RedHat50, Linux, Linux
@subsubsection Linux-x86 notes
@strong{MySQL} requires @code{libc} version 5.4.12 or newer. It's known to
work with @code{libc} 5.4.46. @code{glibc} version 2.0.6 and later should
also work. There have been some problems with the @code{glibc} RPMs from
RedHat so if you have problems, check whether or not there are any updates!
The @code{glibc} 2.0.7-19 and 2.0.7-29 RPMs are known to work.
On some older Linux distributions, @code{configure} may produce an error
like this:
@example
Syntax error in sched.h. Change _P to __P in the /usr/include/sched.h file.
See the Installation chapter in the Reference Manual.
@end example
Just do what the error message says and add an extra underscore to the
@code{_P} macro that has only one underscore, then try again.
You may get some warnings when compiling; those shown below can be ignored:
@example
mysqld.cc -o objs-thread/mysqld.o
mysqld.cc: In function `void init_signals()':
mysqld.cc:315: warning: assignment of negative value `-1' to `long unsigned int'
mysqld.cc: In function `void * signal_hand(void *)':
mysqld.cc:346: warning: assignment of negative value `-1' to `long unsigned int'
@end example
In Debian GNU/Linux, if you want @strong{MySQL} to start automatically when
the system boots, do the following:
@example
shell> cp support-files/mysql.server /etc/init.d/mysql.server
shell> /usr/sbin/update-rc.d mysql.server defaults 99
@end example
@code{mysql.server} can be found in the @file{share/mysql} directory
under the @strong{MySQL} installation directory, or in the
@file{support-files} directory of the @strong{MySQL} source tree.
If @code{mysqld} always core dumps when it starts up, the problem may be that
you have an old @file{/lib/libc.a}. Try renaming it, then remove
@file{sql/mysqld} and do a new @code{make install} and try again. This
problem has been reported on some Slackware installations. RedHat 5.0 has
also a similar problem with some new @code{glibc} versions.
@xref{Linux-RedHat50}.
If you get the following error when linking @code{mysqld},
it means that your @file{libg++.a} is not installed correctly:
@example
/usr/lib/libc.a(putc.o): In function `_IO_putc':
putc.o(.text+0x0): multiple definition of `_IO_putc'
@end example
You can avoid using @file{libg++.a} by running @code{configure} like this:
@example
shell> CXX=gcc ./configure
@end example
@node Linux-RedHat50, Linux-RedHat51, Linux-x86, Linux
@subsubsection RedHat 5.0 notes
If you have any problems with @strong{MySQL} on RedHat, you should start by
upgrading @code{glibc} to the newest possible version!
If you install all the official RedHat patches (including
@code{glibc-2.0.7-19} and @code{glibc-devel-2.0.7-19}), both the
binary and source distributions of @strong{MySQL} should work without
any trouble!
The updates are needed because there is a bug in @code{glibc} 2.0.5 in how
@code{pthread_key_create} variables are freed. With @code{glibc} 2.0.5, you
must use a statically-linked @strong{MySQL} binary distribution. If you
want to compile from source, you must install the corrected version of
LinuxThreads from @uref{http://www.mysql.com/Downloads/Linux} or upgrade your
@code{glibc}.
If you have an incorrect version of @code{glibc} or LinuxThreads, the symptom
is that @code{mysqld} crashes after each connection. For example,
@code{mysqladmin version} will crash @code{mysqld} when it finishes!
Another symptom of incorrect libraries is that @code{mysqld} crashes at
once when it starts. On some Linux systems, this can be fixed by configuring
like this:
@example
shell> ./configure --with-mysqld-ldflags=-all-static
@end example
On Redhat 5.0, the easy way out is to install the @code{glibc} 2.0.7-19 RPM
and run @code{configure} @strong{without} the
@code{--with-mysqld-ldflags=-all-static} option.
For the source distribution of @code{glibc} 2.0.7, a patch that is easy to
apply and is tested with @strong{MySQL} may be found at:
@example
@uref{http://www.mysql.com/Download/Linux/glibc-2.0.7-total-patch.tar.gz}
@end example
If you experience crashes like these when you build @strong{MySQL}, you can
always download the newest binary version of @strong{MySQL}. This is
statically-linked to avoid library conflicts and should work on all Linux
systems!
@strong{MySQL} comes with an internal debugger that can generate
trace files with a lot of information that can be used to find and solve a
wide range of different problems.
@xref{Debugging server}.
@node Linux-RedHat51, Linux-SPARC, Linux-RedHat50, Linux
@subsubsection RedHat 5.1 notes
The @code{glibc} of RedHat 5.1 (@code{glibc} 2.0.7-13) has a memory leak, so
to get a stable @strong{MySQL} version, you must upgrade @code{glibc} to
2.0.7-19, downgrade @code{glibc} or use a binary version of @code{mysqld}. If
you don't do this, you will encounter memory problems (out of memory, etc.,
etc.). The most common error in this case is:
@example
Can't create a new thread (errno 11). If you are not out of available
memory, you can consult the manual for any possible OS dependent bug
@end example
After you have upgraded to @code{glibc} 2.0.7-19, you can configure
@strong{MySQL} with dynamic linking (the default), but you @strong{cannot}
run @code{configure} with the @code{--with-mysqld-ldflags=-all-static} option
until you have installed @code{glibc} 2.0.7-19 from source!
You can check which version of @code{glibc} you have with @code{rpm -q glibc}.
@node Linux-SPARC, Linux-Alpha, Linux-RedHat51, Linux
@subsubsection Linux-SPARC notes
In some implementations, @code{readdir_r()} is broken. The symptom is that
@code{SHOW DATABASES} always returns an empty set. This
can be fixed by removing @code{HAVE_READDIR_R} from @file{config.h} after
configuring and before compiling.
Some problems will require patching your Linux installation. The patch can
be found at
@uref{http://www.mysql.com/Downloads/patches/Linux-sparc-2.0.30.diff}. This patch is
against the Linux distribution @file{sparclinux-2.0.30.tar.gz} that is
available at @code{vger.rutgers.edu} (a version of Linux that was
never merged with the official 2.0.30). You must also install
LinuxThreads 0.6 or newer.
Thanks to @email{jacques@@solucorp.qc.ca} for this information.
@node Linux-Alpha, MKLinux, Linux-SPARC, Linux
@subsubsection Linux-Alpha notes
@strong{MySQL} 3.23.12 is the first @strong{MySQL} version that is
tested on Linux-Alpha. If you plan to use @strong{MySQL} on
Linux-Alpha, you should ensure that you have this version or newer.
We have tested @strong{MySQL} on Alpha with our benchmarks + test suite and
it appears to work nicely. The main thing we haven't yet had time to test
is how things works with many concurrent users.
When we compiled @strong{MySQL} we where using SuSE 6.3, kernel 2.2.13-SMP,
egcs 1.1.2 and libc-2.1.2-28.
We used the following configure line:
@example
CFLAGS="-O6 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --disable-shared
@end example
If you have access to Compaq's C compiler, the following configure line
will give you about 9 % more performance:
@example
CC=ccc CFLAGS="-fast -O3 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti -mcpu=ev6 -Wa,-mev6" CXXLDFLAGS='/usr/lib/compaq/libots-2.2.7/libots.so /usr/lib/compaq/cpml-5.0.0/libcpml_ev6.a' ./configure --prefix=/usr/local/mysql --disable-shared
@end example
Note that the last example assumes your are using an Alpha EV6 processor.
Some known problems when running @strong{MySQL} on Linux-Alpha:
@itemize @bullet
@item
If you create many files ( > 10000) in one directory (as done by the
@code{test-create} in the @strong{MySQL} benchmarks, mysqld may report
the error @code{Can't create/write to file '...' (Errcode: 12)}. This
is probably a bug in the Linux-Alpha kernel.
@item
Debugging threaded applications like @strong{MySQL} will not work with
@code{gdb 4.18}. You should download and use gdb 5.0 instead!
@item
If you try linking mysqld staticly, the resulting image will core dump
at start. In other words, @strong{DON'T} use
@code{--with-mysqld-ldflags=-all-static}
@end itemize
We don't yet know if the following old information is still relevant, so we
leave this here until we have had time to test Linux-Alpha properly.
If you have problems with signals (@strong{MySQL} dies unexpectedly
under high load) you may have found an OS bug with threads and
signals. In this case you can tell @strong{MySQL} not to use signals by
configuring with:
@example
shell> CFLAGS=-DDONT_USE_THR_ALARM \
CXXFLAGS=-DDONT_USE_THR_ALARM \
./configure ...
@end example
This doesn't affect the performance of @strong{MySQL}, but has the side
effect that you can't kill clients that are ``sleeping'' on a connection with
@code{mysqladmin kill} or @code{mysqladmin shutdown}. Instead, the client
will die when it issues its next command.
@node MKLinux, Qube2, Linux-Alpha, Linux
@subsubsection MkLinux notes
@strong{MySQL} should work on MkLinux with the newest @code{glibc} package
(tested with @code{glibc} 2.0.7).
@node Qube2, Linux-Ia64, MKLinux, Linux
@subsubsection Qube2 Linux notes
To get @strong{MySQL} to work on Qube2, (Linux Mips), you need the
newest @code{glibc} libraries (@code{glibc-2.0.7-29C2} is known to
work). You must also use the @code{egcs} C++ compiler
(@code{egcs-1.0.2-9}, @code{gcc 2.95.2} or newer).
@node Linux-Ia64, , Qube2, Linux
@subsubsection Linux Ia64 notes
To get @code{MySQL} to compile on Linux Ia64, we had to do the following
(we assume that this will be easier when next gcc version for ia64 is
released).
Using @code{gcc-2.9-final}:
@example
CFLAGS="-O2" CXX=gcc CXXFLAGS="-O2 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-extra-charsets=complex
@end example
After this you have to edit @file{config.h} and remove the
@code{HAVE_ATOMIC_ADD} line.
After @code{make} you will get an error that @code{sql/opt_range.cc}
will not compile (internal compiler error). To fix this, go to the sql
directory and type @code{make} again. Copy the compile line, but change
-O2 to -O0. The file should now compile.
Now you can do:
@example
cd ..
make
make_install
@end example
and @strong{mysqld} should be ready to run.
@node Alpha-DEC-Unix, Alpha-DEC-OSF1, Linux, Source install system issues
@subsection Alpha-DEC-Unix notes
When compiling threaded programs under Digital UNIX, the documentation
recommends using the @code{-pthread} option for @code{cc} and @code{cxx} and
the libraries @code{-lmach -lexc} (in addition to @code{-lpthread}). You
should run @code{configure} something like this:
@example
shell> CC="cc -pthread" CXX="cxx -pthread -O" \
./configure --with-named-thread-libs="-lpthread -lmach -lexc -lc"
@end example
When compiling @code{mysqld}, you may see a couple of warnings like this:
@example
mysqld.cc: In function void handle_connections()':
mysqld.cc:626: passing long unsigned int *' as argument 3 of
accept(int,sockadddr *, int *)'
@end example
You can safely ignore these warnings. They occur because @code{configure}
can detect only errors, not warnings.
If you start the server directly from the command line, you may have problems
with it dying when you log out. (When you log out, your outstanding processes
receive a @code{SIGHUP} signal.) If so, try starting the server like this:
@example
shell> nohup mysqld [options] &
@end example
@code{nohup} causes the command following it to ignore any @code{SIGHUP}
signal sent from the terminal. Alternatively, start the server by running
@code{safe_mysqld}, which invokes @code{mysqld} using @code{nohup} for you.
@node Alpha-DEC-OSF1, SGI-Irix, Alpha-DEC-Unix, Source install system issues
@subsection Alpha-DEC-OSF1 notes
If you have problems compiling and have DEC @code{CC} and @code{gcc}
installed, try running @code{configure} like this:
@example
shell> CC=cc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 \
./configure --prefix=/usr/local/mysql
@end example
If you get problems with the @file{c_asm.h} file, you can create and use
a 'dummy' @file{c_asm.h} file with:
@example
shell> touch include/c_asm.h
shell> CC=gcc CFLAGS=-I./include \
CXX=gcc CXXFLAGS=-O3 \
./configure --prefix=/usr/local/mysql
@end example
Note that the following problems with the @code{ld} program can be fixed
by downloading the latest DEC (Compaq) patch kit from:
@uref{http://ftp.support.compaq.com/public/unix/}.
On OSF1 V4.0D and compiler "DEC C V5.6-071 on Digital UNIX V4.0 (Rev. 878)"
the compiler had some strange behavior (undefined @code{asm} symbols).
@code{/bin/ld} also appears to be broken (problems with @code{_exit
undefined} errors occuring while linking @code{mysqld}). On this system, we
have managed to compile @strong{MySQL} with the following @code{configure}
line, after replacing @code{/bin/ld} with the version from OSF 4.0C:
@example
shell> CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql
@end example
With the Digital compiler "C++ V6.1-029", the following should work:
@example
CC=cc -pthread
CFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all -arch host
CXX=cxx -pthread
CXXFLAGS=-O4 -ansi_alias -ansi_args -fast -inline speed -speculate all -arch host
export CC CFLAGS CXX CXXFLAGS
./configure --prefix=/usr/mysql/mysql --with-low-memory --enable-large-files --with-mysqld-ldflags=-all-static --disable-shared --with-named-thread-libs="-lmach -lexc -lc"
@end example
In some versions of OSF1, the @code{alloca()} function is broken. Fix
this by removing the line in @file{config.h} that defines @code{'HAVE_ALLOCA'}.
The @code{alloca()} function also may have an incorrect prototype in
@code{/usr/include/alloca.h}. This warning resulting from this can be ignored.
@code{configure} will use the following thread libraries automatically:
@code{--with-named-thread-libs="-lpthread -lmach -lexc -lc"}.
When using @code{gcc}, you can also try running @code{configure} like this:
@example
shell> CFLAGS=-D_PTHREAD_USE_D4 CXX=gcc CXXFLAGS=-O3 ./configure ....
@end example
If you have problems with signals (@strong{MySQL} dies unexpectedly
under high load) you may have found an OS bug with threads and
signals. In this case you can tell @strong{MySQL} not to use signals by
configuring with:
@example
shell> CFLAGS=-DDONT_USE_THR_ALARM \
CXXFLAGS=-DDONT_USE_THR_ALARM \
./configure ...
@end example
This doesn't affect the performance of @strong{MySQL}, but has the side
effect that you can't kill clients that are ``sleeping'' on a connection with
@code{mysqladmin kill} or @code{mysqladmin shutdown}. Instead, the client
will die when it issues its next command.
With @code{gcc} 2.95.2, you will probably run into the following compile error:
@example
sql_acl.cc:1456: Internal compiler error in `scan_region', at except.c:2566
Please submit a full bug report.
@end example
To fix this you should change to the @code{sql} directory and do a 'cut
and paste' of the last @code{gcc} line, but change @code{-O3} to @code{-O0} (or add
@code{-O0} immediately after @code{gcc} if you don't have any @code{-O}
option on your compile line. After this is done you can just change back to
the top level directly and run @code{make} again.
@node SGI-Irix, FreeBSD, Alpha-DEC-OSF1, Source install system issues
@subsection SGI-Irix notes
If you are using Irix 6.5.3 or newer @code{mysqld} will only be able to
create threads if you run it as a user with @code{CAP_SCHED_MGT}
privileges (like @code{root}) or give the @code{mysqld} server this privilege
with the following shell command:
@example
shell> chcap "CAP_SCHED_MGT+epi" /opt/mysql/libexec/mysqld
@end example
You may have to undefine some things in @file{config.h} after running
@code{configure} and before compiling.
In some Irix implementations, the @code{alloca()} function is broken. If the
@code{mysqld} server dies on some @code{SELECT} statements, remove the lines
from @file{config.h} that define @code{HAVE_ALLOC} and @code{HAVE_ALLOCA_H}.
If @code{mysqladmin create} doesn't work, remove the line from
@file{config.h} that defines @code{HAVE_READDIR_R}. You may have to remove
the @code{HAVE_TERM_H} line as well.
SGI recommends that you install all of the patches on this page as a set:
http://support.sgi.com/surfzone/patches/patchset/6.2_indigo.rps.html
At the very minimum, you should install the latest kernel rollup, the
latest @code{rld} rollup, and the latest @code{libc} rollup.
You definately need all the POSIX patches on this page, for pthreads support:
http://support.sgi.com/surfzone/patches/patchset/6.2_posix.rps.html
If you get the something like the following error when compiling
@file{mysql.cc}:
@example
"/usr/include/curses.h", line 82: error(1084): invalid combination of type
@end example
Then type the following in the top-level directory of your @strong{MySQL}
source tree:
@example
shell> extra/replace bool curses_bool < /usr/include/curses.h > include/curses.h
shell> make
@end example
There have also been reports of scheduling problems. If only one thread is
running, things go slow. Avoid this by starting another client. This may lead
to a 2-to-10-fold increase in execution speed thereafter for the other
thread. This is a poorly-understood problem with Irix threads; you may have
to improvise to find solutions until this can be fixed.
If you are compiling with @code{gcc}, you can use the following
@code{configure} command:
@example
shell> CC=gcc CXX=gcc CXXFLAGS=-O3 \
./configure --prefix=/usr/local/mysql --with-thread-safe-client --with-named-thread-libs=-lpthread
@end example
@node FreeBSD, NetBSD, SGI-Irix, Source install system issues
@subsection FreeBSD notes
FreeBSD 3.x is recommended for running @strong{MySQL} since it the thread package
is much more integrated.
The easiest and therefor the preferred way to install is to use the
mysql-server and mysql-client ports available on
@uref{http://www.freebsd.org}
Using these gives you:
@itemize @bullet
@item
A working @strong{MySQL} with all optimizations known to work on your version
of FreeBSD enabled.
@item
Automatic configuration and build.
@item
Startup scripts installed in /usr/local/etc/rc.d
@item
Ability to see which files that are installed with pkg_info -L. And to
remove them all with pkg_delete if you no longer want @strong{MySQL} on that
machine.
@end itemize
It is recomended to use MIT-pthreads on FreeBSD 2.x and native threads on
versions 3 and up. It is possible to run with with native threads on some late
2.2.x versions but you may encounter problems shutting down mysqld.
Be sure to have your name resolver setup correct. Otherwise you may
experience resolver delays or failures when connecting to mysqld.
Make sure that the @code{localhost} entry in the @file{/etc/hosts} file is
correct (otherwise you will have problems connecting to the database). The
@file{/etc/hosts} file should start with a line:
@example
127.0.0.1 localhost localhost.your.domain
@end example
If you notice that @code{configure} will use MIT-pthreads, you should read
the MIT-pthreads notes. @xref{MIT-pthreads}.
If you get an error from @code{make install} that it can't find
@file{/usr/include/pthreads}, @code{configure} didn't detect that you need
MIT-pthreads. This is fixed by executing these commands:
@example
shell> rm config.cache
shell> ./configure --with-mit-threads
@end example
The behavior of FreeBSD @code{make} is slightly different from that of GNU
@code{make}. If you have @code{make}-related problems, you should install GNU
@code{make}.
FreeBSD is also known to have a very low default file handle limit.
@xref{Not enough file handles}. Uncomment the ulimit -n section in
safe_mysqld or raise the limits for the mysqld user in /etc/login.conf
(and rebuild it witg cap_mkdb /etc/login.conf) also be sure you set the
appropriate Class for this user in the password file if you are not
using the default (use: chpass mysqld-user-name)
If you get problems with the current date in @strong{MySQL}, setting the
@code{TZ} variable will probably help. @xref{Environment variables}.
To get a secure and stable system you should only use FreeBSD kernels
that are marked @code{-STABLE}
@node NetBSD, OpenBSD, FreeBSD, Source install system issues
@subsection NetBSD notes
To compile on NetBSD you need GNU @code{make}. Otherwise the compile will crash
when @code{make} tries to run @code{lint} on C++ files.
@node OpenBSD, BSDI, NetBSD, Source install system issues
@subsection OpenBSD 2.5 notes
On OpenBSD 2.5, you can compile @strong{MySQL} with native threads with the
following options:
@example
CFLAGS=-pthread CXXFLAGS=-pthread ./configure --with-mit-threads=no
@end example
@node BSDI, SCO, OpenBSD, Source install system issues
@subsection BSD/OS notes
@menu
* BSDI2:: BSD/OS 2.x notes
* BSDI3:: BSD/OS 3.x notes
* BSDI4:: BSD/OS 4.x notes
@end menu
@node BSDI2, BSDI3, BSDI, BSDI
@subsubsection BSD/OS 2.x notes
If you get the following error when compiling @strong{MySQL}, your
@code{ulimit} value for virtual memory is too low:
@example
item_func.h: In method `Item_func_ge::Item_func_ge(const Item_func_ge &)':
item_func.h:28: virtual memory exhausted
make[2]: *** [item_func.o] Error 1
@end example
Try using @code{ulimit -v 80000} and run @code{make} again. If this
doesn't work and you are using @code{bash}, try switching to @code{csh}
or @code{sh}; some BSDI users have reported problems with @code{bash}
and @code{ulimit}.
If you are using @code{gcc}, you may also use have to use the
@code{--with-low-memory} flag for @code{configure} to be able to compile
@file{sql_yacc.cc}.
If you get problems with the current date in @strong{MySQL}, setting the
@code{TZ} variable will probably help. @xref{Environment variables}.
@node BSDI3, BSDI4, BSDI2, BSDI
@subsubsection BSD/OS 3.x notes
Upgrade to BSD/OS 3.1. If that is not possible, install BSDIpatch M300-038.
Use the following command when configuring @strong{MySQL}:
@example
shell> env CXX=shlicc++ CC=shlicc2 \
./configure \
--prefix=/usr/local/mysql \
--localstatedir=/var/mysql \
--without-perl \
--with-unix-socket-path=/var/mysql/mysql.sock
@end example
The following is also known to work:
@example
shell> env CC=gcc CXX=gcc CXXFLAGS=-O3 \
./configure \
--prefix=/usr/local/mysql \
--with-unix-socket-path=/var/mysql/mysql.sock
@end example
You can change the directory locations if you wish, or just use the
defaults by not specifying any locations.
If you have problems with performance under heavy load, try using the
@code{--skip-thread-priority} option to @code{safe_mysqld}! This will run
all threads with the same priority; on BSDI 3.1, this gives better
performance (at least until BSDI fixes their thread scheduler).
If you get the error @code{virtual memory exhausted} while compiling,
you should try using @code{ulimit -v 80000} and run @code{make} again.
If this doesn't work and you are using @code{bash}, try switching to
@code{csh} or @code{sh}; some BSDI users have reported problems with
@code{bash} and @code{ulimit}.
@node BSDI4, , BSDI3, BSDI
@subsubsection BSD/OS 4.x notes
BSDI 4.x has some thread related bugs. If you want to use @strong{MySQL}
on this, you should install all thread related patches. At least
M400-023 should be installed.
On some BSDI 4.x systems, you may get problems with shared libraries. The
symptom is that you can't execute any client programs, like for example
@code{mysqladmin}. In this case you need to reconfigure not to use
shared libraries with the @code{--disable-shared} option to configure.
@node SCO, SCO Unixware, BSDI, Source install system issues
@subsection SCO notes
The current port is tested only on a ``sco3.2v5.0.4'' and
``sco3.2v5.0.5'' system. There has also been a lot of progress on a
port to ``sco 3.2v4.2''.
For the moment the recommended compiler on OpenServer is gcc 2.95.2. With this
you should be able to compile @code{MySQL} with just:
@example
CC=gcc CXX=gcc ./configure ... (options)
@end example
@enumerate
@item
For OpenServer 5.0.X you need to use GDS in Skunkware 95 (95q4c). This
is necessary because GNU @code{gcc} 2.7.2 in Skunkware 97 does not have
GNU @code{as}. You can also use @code{egcs} 1.1.2 or newer
@uref{http://www.egcs.com/}. If you are using @code{egcs} 1.1.2 you have
to execute the following command:
@example
shell> cp -p /usr/include/pthread/stdtypes.h /usr/local/lib/gcc-lib/i386-pc-sco3.2v5.0.5/egcs-2.91.66/include/pthread/
@end example
@item
You need the port of GCC 2.5.? for this product and the Development
system. They are required on this version of SCO UNIX. You cannot
just use the GCC Dev system.
@item
You should get the FSU Pthreads package and install it first. This can be
found at
@uref{http://www.cs.wustl.edu/~schmidt/ACE_wrappers/FSU-threads.tar.gz}.
You can also get a precompiled package from
@uref{http://www.mysql.com/Downloads/SCO/FSU-threads-3.5c.tar.gz}.
@item
FSU Pthreads can be compiled with SCO UNIX 4.2 with tcpip. Or
OpenServer 3.0 or Open Desktop 3.0 (OS 3.0 ODT 3.0), with the SCO
Development System installed using a good port of GCC 2.5.X ODT or OS
3.0 you will need a good port of GCC 2.5.? There are a lot of problems
without a good port. The port for this product requires the SCO UNIX
Development system. Without it, you are missing the libraries and the
linker that is needed.
@item
To build FSU Pthreads on your system, do the following:
@enumerate
@item
Run @code{./configure} in the @file{threads/src} directory and select
the SCO OpenServer option. This command copies @file{Makefile.SCO5} to
@file{Makefile}.
@item
Run @code{make}.
@item
To install in the default @file{/usr/include} directory, login as root,
then @code{cd} to the @file{thread/src} directory, and run @code{make
install}.
@end enumerate
@item
Remember to use GNU @code{make} when making @strong{MySQL}.
@item
On OSR 5.0.5, you should use the following configure line:
@example
shell> CC="gcc -DSCO" CXX="gcc -DSCO" ./configure
@end example
The @code{-DSCO} is needed to help configure detect some thread
functions properly. If you forget @code{-DSCO}, you will get the following
error message while compiling:
@example
my_pthread.c: In function `my_pthread_mutex_init':
my_pthread.c:374: `pthread_mutexattr_default' undeclared (first use this function)
@end example
@item
If you don't start @code{safe_mysqld} as root, you probably will get only the
default 110 open files per process. @code{mysqld} will write a note about this
in the log file.
@item
With SCO 3.2V5.0.5, you should use FSU Pthreads version 3.5c or newer.
The following @code{configure} command should work:
@example
shell> CC="gcc -belf" ./configure --prefix=/usr/local/mysql --disable-shared
@end example
@item
With SCO 3.2V4.2, you should use FSU Pthreads version 3.5c or newer.
The following @code{configure} command should work:
@example
shell> CFLAGS="-D_XOPEN_XPG4" CXX=gcc CXXFLAGS="-D_XOPEN_XPG4" \
./configure \
--with-debug --prefix=/usr/local/mysql \
--with-named-thread-libs="-lgthreads -lsocket -lgen -lgthreads" \
--with-named-curses-libs="-lcurses"
@end example
You may get some problems with some include files. In this case, you can
find new SCO-specific include files at
@uref{http://www.mysql.com/Downloads/SCO/SCO-3.2v4.2-includes.tar.gz}.
You should unpack this file in the @file{include}
directory of your @strong{MySQL} source tree.
@end enumerate
SCO development notes:
@itemize @bullet
@item
@strong{MySQL} should automatically detect FSU Pthreads and link @code{mysqld}
with @code{-lgthreads -lsocket -lgthreads}.
@item
The SCO development libraries are reentrant in FSU Pthreads. SCO claims
that its libraries' functions are reentrant, so they must be reentrant with
FSU Pthreads. FSU Pthreads on OpenServer tries to use the SCO scheme to
make reentrant library.
@item
FSU Pthreads (at least the version at @uref{http://www.mysql.com/}) comes linked with
GNU @code{malloc}. If you encounter problems with memory usage, make sure that
@file{gmalloc.o}
is included in @file{libgthreads.a} and @file{libgthreads.so}.
@item
In FSU Pthreads, the following system calls are pthreads-aware: @code{read()},
@code{write()}, @code{getmsg()}, @code{connect()}, @code{accept()},
@code{select()} and @code{wait()}.
@end itemize
If you want to install DBI on SCO, you have to edit the @file{Makefiles} in
DBI-xxx and each subdirectory:
@example
OLD: NEW:
CC = cc CC = gcc -belf
CCCDLFLAGS = -KPIC -W1,-Bexport CCCDLFLAGS = -fpic
CCDLFLAGS = -wl,-Bexport CCDLFLAGS =
LD = ld LD = gcc -belf -G -fpic
LDDLFLAGS = -G -L/usr/local/lib LDDLFLAGS = -L/usr/local/lib
LDFLAGS = -belf -L/usr/local/lib LDFLAGS = -L/usr/local/lib
LD = ld LD = gcc -belf -G -fpic
OPTIMISE = -Od OPTIMISE = -O1
OLD:
CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include
NEW:
CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include
@end example
This is because the Perl dynaloader will not load the @code{DBI} modules
if they were compiled with @code{icc} or @code{cc}.
Perl works best when compiled with @code{cc}.
@node SCO Unixware, IBM-AIX, SCO, Source install system issues
@subsection SCO Unixware 7.0 notes
You must use a version of @strong{MySQL} at least as recent as 3.22.13, because
that version fixes some portability problems under Unixware.
We have been able to compile @strong{MySQL} with the following @code{configure}
command on UnixWare 7.0.1:
@example
shell> CC=cc CXX=CC ./configure --prefix=/usr/local/mysql
@end example
If you want to use @code{gcc}, you must use @code{gcc} 2.95.2 or newer.
@node IBM-AIX, HP-UX 10.20, SCO Unixware, Source install system issues
@subsection IBM-AIX notes
Automatic detection of @code{xlC} is missing from Autoconf, so a
@code{configure} command something like this is needed when compiling
@strong{MySQL}: (The example uses the IBM compiler)
@example
shell> CC="xlc_r" CFLAGS="-ma -O3 -qstrict -DHAVE_INT_8_16_32" \
CXX="xlC_r" CXXFLAGS="-ma -O3 -qstrict -DHAVE_INT_8_16_32" \
./configure
@end example
If you change the @code{-O3} to @code{-O2} in the above configure line,
you must also remove the @code{-qstrict} option (this is a limitation in
the IBM C compiler).
If you are using @code{gcc} or @code{egcs} to compile @strong{MySQL}, you
@strong{MUST} use the @code{-fno-exceptions} flag, as the exception
handling in @code{gcc}/@code{egcs} is not thread-safe! (This is tested with
@code{egcs} 1.1.) We recommend the following @code{configure} line with
@code{egcs} and @code{gcc} on AIX:
@example
shell> CC=gcc \
CFLAGS="-DHAVE_INT_8_16_32" \
CXX=gcc \
CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -DHAVE_INT_8_16_32" \" \
./configure --prefix=/usr/local/mysql --with-debug --with-low-memory
@end example
If you have problems with signals (@strong{MySQL} dies unexpectedly
under high load) you may have found an OS bug with threads and
signals. In this case you can tell @strong{MySQL} not to use signals by
configuring with:
@example
shell> 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
@end example
This doesn't affect the performance of @strong{MySQL}, but has the side
effect that you can't kill clients that are ``sleeping'' on a connection with
@code{mysqladmin kill} or @code{mysqladmin shutdown}. Instead, the client
will die when it issues its next command.
On some versions of AIX, linking with @code{libbind.a} makes @code{getservbyname} core
dump. This is an AIX bug and should be reported to IBM.
@node HP-UX 10.20, HP-UX 11.x, IBM-AIX, Source install system issues
@subsection HP-UX 10.20 notes
There are a couple of ``small'' problems when compiling @strong{MySQL} on
HP-UX. We recommend that you use @code{gcc} instead of the HP-UX native
compiler, because @code{gcc} produces better code!
We recommend one to use gcc 2.95 on HP-UX. Don't use high optimization
flags (like -O6) as this may not be safe on HP-UX.
Note that MIT-pthreads can't be compiled with the HP-UX compiler,
because it can't compile @code{.S} (assembler) files.
The following configure line should work:
@example
CFLAGS="-DHPUX -I/opt/dce/include" CXXFLAGS="-DHPUX -I/opt/dce/include -felide-constructors -fno-exceptions -fno-rtti" CXX=gcc ./configure --with-pthread --with-named-thread-libs='-ldce' --prefix=/usr/local/mysql --disable-shared
@end example
If you are compiling @code{gcc} 2.95 yourself, you should NOT link it with
the DCE libraries (@code{libdce.a} or @code{libcma.a}) if you want to compile
@strong{MySQL} with MIT-pthreads. If you mix the DCE and MIT-pthreads
packages you will get a @code{mysqld} to which you cannot connect. Remove
the DCE libraries while you compile @code{gcc} 2.95!
@node HP-UX 11.x, MacOSX, HP-UX 10.20, Source install system issues
@subsection HP-UX 11.x notes
For HPUX 11.x we recommend @strong{MySQL} 3.23.15 or later.
If you are using @code{gcc} 2.95.1 on a unpatched HPUX 11.x system you will
get the error:
@example
In file included from /usr/include/unistd.h:11,
from ../include/global.h:125,
from mysql_priv.h:15,
from item.cc:19:
/usr/include/sys/unistd.h:184: declaration of C function `int pthread_atfork(void (*)(...), void (*)
(...), void (*)(...))' conflicts with
/usr/include/sys/pthread.h:440: previous declaration `int pthread_atfork(void (*)(), void (*)(), voi
d (*)())' here
In file included from item.h:306,
from mysql_priv.h:158,
from item.cc:19:
@end example
The problem is that HP-UX doesn't define @code{pthreads_atfork()} consistently.
It has conflicting prototypes in
@file{/usr/include/sys/unistd.h}:184 and
@file{/usr/include/sys/pthread.h}:440 (I post the details below).
One solution is to copy @file{/usr/include/sys/unistd.h} into
@file{mysql/include} and edit @file{unistd.h} and change it to match
the definition in @file{pthread.h}. Here's the diff:
@example
183,184c183,184
< extern int pthread_atfork(void (*prepare)(), void (*parent)(),
< void (*child)());
---
> extern int pthread_atfork(void (*prepare)(void), void (*parent)(void),
> void (*child)(void));
@end example
After this, the following configure line should work:
@example
CFLAGS="-fomit-frame-pointer -O6 -fpic" CXX=gcc CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti -O6" ./configure --prefix=/usr/local/mysql --disable-shared
@end example
Here is some information that a HPUX 11.x user sent us about compile
@strong{MySQL} with HPUX:x compiler
@itemize @bullet
@item
@example
Environment:
proper compilers.
setenv CC cc
setenv CXX aCC
flags
setenv CFLAGS -D_REENTRANT
setenv CXXFLAGS -D_REENTRANT
setenv CPPFLAGS -D_REENTRANT
% aCC -V
aCC: HP ANSI C++ B3910B X.03.14.06
% cc -V /tmp/empty.c
cpp.ansi: HP92453-01 A.11.02.00 HP C Preprocessor (ANSI)
ccom: HP92453-01 A.11.01.00 HP C Compiler
cc: "/tmp/empty.c", line 1: warning 501: Empty source file.
@end example
@item
@example
configuration:
./configure --with-pthread \
--prefix=/source-control/mysql \
--with-named-thread-libs=-lpthread \
--with-low-memory
@end example
@item
added '#define _CTYPE_INCLUDED' to include/m_ctype.h. This
symbol is the one defined in HP's /usr/include/ctype.h:
@example
/* Don't include std ctype.h when this is included */
#define _CTYPE_H
#define __CTYPE_INCLUDED
#define _CTYPE_INCLUDED
#define _CTYPE_USING /* Don't put names in global namespace. */
@end example
@item
I had to use the compile-time flag @code{-D_REENTRANT} to get the
compiler to recognize the prototype for
@code{localtime_r}. Alternatively I could have supplied the prototype
for @code{localtime_r}. But I wanted to catch other bugs without needing
to run into them. I wasn't sure where I needed it so I added it to all
flags.
@item
The optimization flags used by @strong{MySQL} (-O3) are not recognized
by HP's compilers. I did not change the flags.
@end itemize
@node MacOSX, , HP-UX 11.x, Source install system issues
@subsection MacOS X notes
You can get @strong{MySQL} to work on MacOS X by following the links to
the MacOS X ports. @xref{Useful Links}.
@strong{MySQL} 3.23.7 should include all patches necessary to configure
it on MacOSX. You must however first install the pthread package from
@uref{http://www.prnet.de/RegEx/mysql.html,MySql for MacOSX Server}
before configuring @strong{MySQL}.
You might want to also add aliases to your shell's resource file to
access @code{mysql} and @code{mysqladmin} from the command line.
@example
alias mysql '/usr/local/mysql/bin/mysql'
alias mysqladmin '/usr/local/mysql/libexec/mysqladmin'
@end example
@node Win32, OS/2, Source install system issues, Installing
@section Win32 notes
This section describes installation and use of @strong{MySQL} on Win32. This
is also described in the @file{README} file that comes with the
@strong{MySQL} Win32 distribution.
@menu
* Win32 installation:: Installing @strong{MySQL} on Win32
* Win95 start:: Starting @strong{MySQL} on Win95 / Win98
* NT start:: Starting @strong{MySQL} on NT / Win2000
* Win32 running:: Running @strong{MySQL} on Win32
* Win32 and SSH:: Connecting to a remote @strong{MySQL} from Win32 with SSH
* Win32 symbolic links:: Splitting data across different disks under Win32
* Win32 compiling::
* Win32 vs Unix:: @strong{MySQL}-Win32 compared to Unix @strong{MySQL}
@end menu
@node Win32 installation, Win95 start, Win32, Win32
@subsection Installing MySQL on Win32
If you don't have a registered version of @strong{MySQL}, you should first
download the shareware version from:
@uref{http://www.mysql.com/mysql_w32.htmy,@strong{MySQL} 3.22.x}
If you plan to connect to @strong{MySQL} from some other program, you will
probably also need the @strong{MyODBC} driver. You can find this at the
@uref{http://www.mysql.com/downloads/api-myodbc.html,@strong{MyODBC} download page}.
To install either distribution, unzip it in some empty directory and run the
@code{Setup.exe} program.
By default, @strong{MySQL}-Win32 is configured to be installed in
@file{C:\mysql}. If you want to install @strong{MySQL} elsewhere, install it
in @file{C:\mysql}, then move the installation to where you want it. If you
do move @strong{MySQL}, you must tell @code{mysqld} where everything is by
supplying options to @code{mysqld}. Use @code{C:\mysql\bin\mysqld --help} to
display all options! For example, if you have moved the @strong{MySQL}
distribution to @file{D:\programs\mysql}, you must start @code{mysqld} with:
@code{D:\programs\mysql\bin\mysqld --basedir D:\programs\mysql}
With the registered version of @strong{MySQL}, you can also create a
@file{C:\my.cnf} file that holds any default options for the
@strong{MySQL} server. Copy the file @file{\mysql\my-xxxxx.cnf} to
@file{C:\my.cnf} and edit this to suit your setup. Note that you should
specify all paths with @code{/} instead of @code{\}. If you use
@code{\}, you need to specify this twice, as @code{\} is the escape
character in @strong{MySQL}.
@xref{Option files}.
@node Win95 start, NT start, Win32 installation, Win32
@subsection Starting MySQL on Win95 / Win98
@strong{MySQL} uses TCP/IP to connect a client to a server. (This will
allow any machine on your network to connect to your @strong{MySQL}
server). Because of this, you must install TCP/IP on your machine before
starting @strong{MySQL}. You can find TCP/IP on your Windows CD-ROM.
Note that if you are using an old Win95 release (for example OSR2), it's
likely that you have an old Winsock package! @strong{MySQL} requires
Winsock 2! You can get the newest Winsock from
@uref{http://www.microsoft.com,Microsoft}. Win98 has as default the new
Winsock 2 library, so the above doesn't apply for Win98.
There are 2 different @strong{MySQL} servers you can use:
@multitable @columnfractions .15 .85
@item @code{mysqld} @tab Compiled with full debugging and automatic memory allocation checking
@item @code{mysqld-opt} @tab Optimized for a Pentium processor.
@end multitable
Both of the above should work on any Intel processor >= i386.
To start the @code{mysqld} server, you should start an MS-DOS window and type:
@example
C:\mysql\bin\mysqld
@end example
This will start @code{mysqld} in the background without a window.
You can kill the @strong{MySQL} server by executing:
@example
C:\mysql\bin\mysqladmin -u root shutdown
@end example
Note that Win95/Win98 don't support creation of named pipes. On
Win95/Win98, you can only use named pipes to connect to a remote
@strong{MySQL} running on an NT server.
If @code{mysqld} doesn't start please check whether or not the
@file{\mysql\mysql.err} file contains any reason for this. You can also
try to start it with @code{mysqld --standalone}; In this case you may
get some useful information on the screen that may help solve this.
The last option is to start @code{mysqld} with @code{--debug}. In this
case @code{mysqld} will write a log file in @file{\mysqld.trace}
that should contain the reason why @code{mysqld} doesn't start. If you
make a bug report about this, please only send the lines where something
seams to go wrong to the mailing list!
@node NT start, Win32 running, Win95 start, Win32
@subsection Starting MySQL on NT / Win200
The Win95/Win98 section also applies to @strong{MySQL} on NT / Win2000, with
the following differences:
To get @strong{MySQL} to work with TCP/IP on NT, you must install
service pack 3 (or newer)!
Note that everything in the following that applies for NT, also applies
for Win2000!
For NT / Win2000, the server name is @code{mysqld-nt}. Normally you
should install @strong{MySQL} as a service on NT/Win2000:
@example
C:\mysql\bin\mysqld-nt --install
@end example
(You could use the @code{mysqld} or @code{mysqld-opt} servers on NT,
but those cannot be started as a service or use named pipes.)
You can start and stop the @strong{MySQL} service with:
@example
NET START mysql
NET STOP mysql
@end example
Note that in this case you can't use any other options for @code{mysqld-nt}!
You can also run @code{mysqld-nt} as a standalone program on NT if you need
to start @code{mysqld-nt} with any options! If you start @code{mysqld-nt}
without options on NT, @code{mysqld-nt} tries to starts itself as a service
with the default service options. If you have stopped @code{mysqld-nt}, you
have to start it with @code{NET START mysql}.
The service is installed with the name @code{MySql}. Once installed, it must
be started using Services Control Manager (SCM) Utility (found in Control
Panel) or by using the @code{NET START MySQL} command. If any options are
desired, they must be specified as "Startup parameters" in the SCM utility
before you start the @strong{MySQL} service. Once running, @code{mysqld-nt}
can be stopped using @code{mysqladmin} or from the SCM utility or by using
the command @code{NET STOP MySQL}. If you use SCM to stop @code{mysqld-nt},
there is a strange message from SCM about @code{mysqld shutdown normally}.
When run as a service, @code{mysqld-nt} has no access to a console and so no
messages can be seen.
On NT you can get the following service error messages:
@multitable @columnfractions .3 .7
@item Permission Denied @tab Means that it cannot find @code{mysqld-nt.exe}
@item Cannot Register @tab Means that the path is incorrect
@end multitable
If you have problems installing @code{mysqld-nt} as a service, try starting
it with the full path:
@example
C:\mysql\bin\mysqld-nt --install
@end example
If this doesn't work, you can get @code{mysqld-nt} to start properly by fixing
the path in the registry!
If you don't want to start @code{mysqld-nt} as a service, you can start it as
follows:
@example
C:\mysql\bin\mysqld-nt --standalone
@end example
or
@example
C:\mysql\bin\mysqld --standalone --debug
@end example
The last version gives you a debug trace in @file{C:\mysqld.trace}.
@node Win32 running, Win32 and SSH, NT start, Win32
@subsection Running MySQL on Win32
@strong{MySQL} supports TCP/IP on all Win32 platforms and named pipes on NT.
The default is to use named pipes for local connections on NT and TCP/IP for
all other cases if the client has TCP/IP installed. The host name specifies
which protocol is used:
@multitable @columnfractions .3 .7
@strong{Host name} @tab @strong{protocol}
@item NULL (none) @tab On NT, try named pipes first; if that doesn't work, use TCP/IP. On Win95/Win98, TCP/IP is used.
@item . @tab Named pipes
@item localhost @tab TCP/IP to current host
@item hostname @tab TCP/IP
@end multitable
You can force a @strong{MySQL} client to use named pipes by specifying the
@code{--pipe} option. Use the @code{--socket} option to specify the name of
the pipe.
You can test whether or not @strong{MySQL} is working by executing the
following commands:
@example
C:\mysql\bin\mysqlshow
C:\mysql\bin\mysqlshow -u root mysql
C:\mysql\bin\mysqladmin version status proc
C:\mysql\bin\mysql test
@end example
If @code{mysqld} is slow to answer to connections on Win95/Win98, there is
probably a problem with your DNS. In this case, start @code{mysqld} with
@code{--skip-name-resolve} and use only @code{localhost} and IP numbers in
the @strong{MySQL} grant tables. You can also avoid DNS when connecting to a
@code{mysqld-nt} @strong{MySQL} server running on NT by using the
@code{--pipe} argument to specify use of named pipes. This works for most
@strong{MySQL} clients.
There are two versions of the @strong{MySQL} command line tool:
@multitable @columnfractions .15 .85
@item @code{mysql} @tab Compiled on native Win32, which offers very limited text
editing capabilities.
@item @code{mysqlc} @tab Compiled with the Cygnus GNU compiler and libraries, which offers @code{readline} editing.
@end multitable
If you want to use @code{mysqlc.exe}, you must copy
@file{C:\mysql\lib\cygwinb19.dll} to @file{\windows\system} (or similar
place).
The default privileges on Win32 give all local users full privileges
to all databases. To make @strong{MySQL} more secure, you
should set a password for all users and remove the row in the
@code{mysql.user} table that has @code{Host='localhost'} and
@code{User=''}.
You should also add a password for the @code{root} user:
(The following example starts by removing the anonymous user, that allows
anyone to access the 'test' database)
@example
C:\mysql\bin\mysql mysql
mysql> DELETE FROM user WHERE Host='localhost' AND User='';
mysql> QUIT
C:\mysql\bin\mysqladmin reload
C:\mysql\bin\mysqladmin -u root password your_password
@end example
After you've set the password, if you want to take down the @code{mysqld}
server, you can do so using this command:
@example
mysqladmin --user=root --password=your_password shutdown
@end example
If you are using the old shareware version of @strong{MySQL} 3.21 under
Windows, the above command will fail with an error: @code{parse error
near 'SET OPTION password'}. This is because the old shareware version,
which is based on @strong{MySQL} 3.21, doesn't have the @code{SET PASSWORD}
command. The fix is in this case is to upgrade to the 3.22 shareware
version.
With the newer @strong{MySQL} versions you can easily add new users
and change privileges with @code{GRANT} and @code{REVOKE} commands.
@xref{GRANT}.
@node Win32 and SSH, Win32 symbolic links, Win32 running, Win32
@subsection Connecting to a remote MySQL from Win32 with SSH
Here is a note about how to connect to get a secure connection to remote MySQL
server with SSH (by David Carlson).
@itemize @bullet
@item
Install SSH client on your windows machine - I used a free SSH client
from @uref{http://www.doc.ic.ac.uk/~ci2/ssh/}.
Other useful links:
@uref{http://www.npaci.edu/Security/npaci_security_software.html} and
@uref{http://www.npaci.edu/Security/samples/ssh32_windows/index.html}.
@item
Start SSH. Set Host Name = yourmysqlserver name or IP address. Set
userid=your userid to log in to your server
@item
Click on "local forwards". Set @code{local port: 3306},
@code{host: localhost}, @code{remote port: 3306}
@item
Save everything, otherwise you'll have to redo it the next time.
@item
Log in to your server with SSH.
@item
Start some ODBC application (for example Access)
@item
Create a new file and link to mySQL using the ODBC driver the same way
you normally do except for server, user "localhost".
@end itemize
That's it. It works very well with a direct Internet connection. I'm
having problems with SSH conflicting with my Win95 network and Wingate -
but that'll be the topic of a posting on another software company's
usegroup!
@findex Symbolic links
@findex Using multiple disks to start data
@node Win32 symbolic links, Win32 compiling, Win32 and SSH, Win32
@subsection Splitting data across different disks under Win32
On windows @strong{MySQL} 3.23.16 and above is compiled with the
@code{-DUSE_SYMDIR} option. This allows you to put a database on
different disk by adding a symbolic link to it (in a similar manner that
symbolic links works on Unix).
On windows you make a symbolic link to a database by creating a file
that contains the path to the destination directory and saving this in
the @code{mysql_data} directory under the filename @code{database.sym}.
Note that the symbolic link will only be used if the directory
@code{mysql_data_dir\database} doesn't exist.
For example if you want to have database @code{foo} on @file{D:\data\foo} you
should create the file @file{C:\mysql\data\foo.sym} that should contains the
text @code{D:\data\foo}. After this, all tables created in the database
@code{foo} will be created in @file{D:\data\foo}.
@node Win32 compiling, Win32 vs Unix, Win32 symbolic links, Win32
@subsection Compiling MySQL clients on Windows.
In your source files, you should include @file{windows.h} before you include
@code{mysql.h}:
@example
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
#include <mysql.h>
@end example
You can either link your code with the dynamic @file{libmysql.lib} library,
which is just a wrapper to load in @file{libmysql.dll} on demand, or link
with the static @file{mysqlclient.lib} library.
Note that as the mysqlclient libraries are compiled as threaded libraries,
you should also compile your code to be multi-threaded!
@node Win32 vs Unix, , Win32 compiling, Win32
@subsection MySQL-Win32 compared to Unix MySQL
@strong{MySQL}-Win32 has by now proven itself to be very stable. This version
of @strong{MySQL} has the same features as the corresponding Unix version
with the following exceptions:
@table @strong
@item Win95 and threads
Win95 leaks about 200 bytes of main memory for each thread creation. Because
of this, you shouldn't run @code{mysqld} for an extended time on Win95 if
you do many connections, because each connection in @strong{MySQL} creates
a new thread! WinNT and Win98 don't suffer from this bug.
@item Concurrent reads
@strong{MySQL} depends on the @code{pread()} and @code{pwrite()} calls to be
able to mix @code{INSERT} and @code{SELECT}. As windows doesn't support these
calls, @strong{MySQL} can't currently handle concurrent reads on windows.
We plan to fix this by adding an extra mutex to each open file and simulate
@code{pread()}/@code{pwrite()}.
@item Blocking read
@strong{MySQL} uses a blocking read for each connection.
This means that:
@itemize @bullet
@item
A connection will not be disconnected automatically after 8 hours, as happens
with the Unix version of @strong{MySQL}.
@item
If a connection ``hangs,'' it's impossible to break it without killing
@strong{MySQL}.
@item
@code{mysqladmin kill} will not work on a sleeping connection.
@item
@code{mysqladmin shutdown} can't abort as long as there are sleeping
connections.
@end itemize
We plan to fix this in the near future.
@item UDF functions
For the moment, @strong{MySQL}-Win32 does not support user definable functions.
@item @code{DROP DATABASE}
You can't drop a database that is in use by some thread.
@item Killing @strong{MySQL} from the task manager
You can't kill @strong{MySQL} from the task manager or with the shutdown
utility in Windows95. You must take it down with @code{mysqladmin shutdown}.
@item Case-insensitive names
Filenames are case insensitive on Win32, so database and table names
are also case insensitive in @strong{MySQL} for Win32. The only restriction is
that database and table names must be given in the same case throughout a
given statement. The following query would not work because it refers to
a table both as @code{my_table} and as @code{MY_TABLE}:
@example
SELECT * FROM my_table WHERE MY_TABLE.col=1;
@end example
@item The @samp{\} directory character
Pathname components in Win95 are separated by @samp{\} characters, which is
also the escape character in @strong{MySQL}. If you are using @code{LOAD
DATA INFILE} or @code{SELECT ... INTO OUTFILE}, you must double the @samp{\}
character or use Unix style filenames @samp{/} characters:
@example
LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr;
SELECT * INTO OUTFILE 'C:/tmp/skr.txt' FROM skr;
@end example
@item @code{Can't open named pipe} error
If you use the shareware version of @strong{MySQL}-Win32 on NT with the
newest mysql-clients you will get the following error:
@example
error 2017: can't open named pipe to host: . pipe...
@end example
@tindex .my.cnf file
This is because the release version of @strong{MySQL} uses
named pipes on NT by default. You can avoid this error by using the
@code{--host=localhost} option to the new @strong{MySQL} clients
or create a file @file{C:\my.cnf} that contains the following information:
@example
[client]
host = localhost
@end example
@item @code{Access denied for user} error
If you get the error @code{Access denied for user: 'some-user@@unknown'
to database 'mysql'} when accessing a @strong{MySQL} server on the same
machine, this means that @strong{MySQL} can't resolve your host name
properly.
To fix this, you should create a file @file{\windows\hosts} with the
following information:
@example
127.0.0.1 localhost
@end example
@end table
Here are some open issues for anyone who might want to help us with the Win32
release:
@itemize @bullet
@item
Make a single user @code{MYSQL.DLL} server. This should include everything in
a standard @strong{MySQL} server, except thread creation. This will make
@strong{MySQL} much easier to use in applications that don't need a true
client/server and don't need to access the server from other hosts.
@item
Add some nice ``start'' and ``shutdown'' icons to the @strong{MySQL} installation.
@item
Create a tool to manage registry entries for the @strong{MySQL} startup
options. The registry entry reading is already coded into @code{mysqld.cc},
but it should be recoded to be more ``parameter'' oriented.
The tool should also be able to update the @file{\my.cnf} file if the user
would prefer to use this instead of the registry.
@item
When registering @code{mysqld} as a service with @code{--install} (on NT)
it would be nice if you could also add default options on the command line.
For the moment, the workaround is to update the @file{C:\my.cnf} file
instead.
@item
When you suspend a laptop running Win95, the @code{mysqld}
daemon doesn't accept new connections when the laptop is resumed.
We don't know if this is a problem with Win95, TCP/IP or @strong{MySQL}.
@item
It would be real nice to be able to kill @code{mysqld} from the
task manager. For the moment, you must use @code{mysqladmin shutdown}.
@item
Port @code{readline} to Win32 for use in the @code{mysql} command line tool.
@item
GUI versions of the standard @strong{MySQL} clients (@code{mysql},
@code{mysqlshow}, @code{mysqladmin}, and @code{mysqldump}) would be nice.
@item
It would be nice if the socket ``read'' and ``write'' functions in
@file{net.c} were interruptible. This would make it possible to kill open
threads with @code{mysqladmin kill} on Win32.
@item
Documentation of which Windows programs work with
@strong{MySQL}-Win32/@strong{MyODBC} and what must be done to get them working.
@item
@code{mysqld} always starts in the "C" locale and not in the default locale.
We would like to have @code{mysqld} use the current locale for the sort order.
@item
Port @code{sqlclient} to Win32 (almost done) and add more features to it!
@item
Add more options to MysqlManager.
@item
Change the communication protocol between the server and client to use Windows
internal communication instead of sockets and TCP/IP.
@item
Implement UDF functions with @code{.DLL}s.
@item
Add macros to use the faster thread-safe increment/decrement methods
provided by Win32.
@end itemize
Other Win32-specific issues are described in the @file{README} file that comes
with the @strong{MySQL}-Win32 distribution.
@node OS/2, MySQL binaries, Win32, Installing
@section OS/2 notes
@strong{MySQL} uses quite a few open files. Because of this, you
should add something like the following to your @file{CONFIG.SYS} file:
@example
SET EMXOPT=-c -n -h1024
@end example
If you don't do this, you will probably run into the following error:
@example
File 'xxxx' not found (Errcode: 24)
@end example
When using @strong{MySQL} with OS/2 Warp 3, FixPack 29 or above is
required. With OS/2 Warp 4, FixPack 4 or above is required. This is a
requirement of the Pthreads library. @strong{MySQL} must be installed
in a partition that supports long file names such as HPFS, FAT32, etc.
The @file{INSTALL.CMD} script must be run from OS/2's own @file{CMD.EXE}
and may not work with replacement shells such as @file{4OS2.EXE}.
The @file{scripts/mysql-install-db} script has been renamed: it is now called
@file{install.cmd} and is a REXX script which will set up the default
@strong{MySQL} security settings and create the WorkPlace Shell icons
for @strong{MySQL}.
Dynamic module support is compiled in but not fully tested. Dynamic
modules should be compiled using the Pthreads runtime library.
@example
gcc -Zdll -Zmt -Zcrtdll=pthrdrtl -I../include -I../regex -I.. \
-o example udf_example.cc -L../lib -lmysqlclient udf_example.def
mv example.dll example.udf
@end example
@strong{Note:} Due to limitations in OS/2, UDF module name stems must not
exceed 8 characters. Modules are stored in the @file{/mysql2/udf}
directory; the @code{safe-mysqld.cmd} script will put this directory in
the @code{BEGINLIBPATH} environment variable. When using UDF modules,
specified extensions are ignored --- it is assumed to be @file{.udf}.
For example, in Unix, the shared module might be named @file{example.so}
and you would load a function from it like this:
@example
CREATE FUNCTION metaphon RETURNS STRING SONAME "example.so";
@end example
Is OS/2, the module would be named @file{example.udf}, but you would not
specify the module extension:
@example
CREATE FUNCTION metaphon RETURNS STRING SONAME "example";
@end example
@node MySQL binaries, Post-installation, OS/2, Installing
@section MySQL binaries
As a service, we at MySQL AB provides a set of binary distributions of
@strong{MySQL} that are compiled at our site or at sites where customers
kindly have given us access to their machines.
These distributions are generated with
@code{scripts/make_binary_distribution} and are configured with the
following compilers and options:
@table @asis
@item SunOS 4.1.4 2 sun4c with @code{gcc} 2.7.2.1
@code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --disable-shared --with-extra-charsets=complex}
@item SunOS 5.5.1 sun4u with @code{egcs} 1.0.3a
@code{CC=gcc CFLAGS="-O6 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex}
@item SunOS 5.6 sun4u with @code{egcs} 2.90.27
@code{CC=gcc CFLAGS="-O6 -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex}
@item SunOS 5.6 i86pc with @code{gcc} 2.8.1
@code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex}
@item Linux 2.0.33 i386 with @code{pgcc} 2.90.29 (@code{egcs} 1.0.3a)
@code{CFLAGS="-O6 -mpentium -mstack-align-double -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -mpentium -mstack-align-double -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --with-extra-charsets=complex}
@item Linux 2.2.x with x686 with @code{gcc} 2.95.2
@code{CFLAGS="-O6 -mpentiumpro -fomit-frame-pointer" CXX=gcc CXXFLAGS="-O6 -mpentiumpro -fomit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --enable-assembler --with-mysqld-ldflags=-all-static --disable-shared --with-extra-charset=complex}
@item SCO 3.2v5.0.4 i386 with @code{gcc} 2.7-95q4
@code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex}
@item AIX 2 4 with @code{gcc} 2.7.2.2
@code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex}
@item OSF1 V4.0 564 alpha with @code{gcc} 2.8.1
@code{CC=gcc CFLAGS=-O CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-low-memory --with-extra-charsets=complex}
@item Irix 6.3 IP32 with @code{gcc} 2.8.0
@code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex}
@item BSDI BSD/OS 3.1 i386 with @code{gcc} 2.7.2.1
@code{CC=gcc CXX=gcc CXXFLAGS=-O ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex}
@item BSDI BSD/OS 2.1 i386 with @code{gcc} 2.7.2
@code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex}
@end table
Anyone who has more optimal options for any of the configurations listed
above can always mail them to the developer's mailing list at
@email{developer@@lists.mysql.com}.
RPM distributions prior to @strong{MySQL} 3.22 are user-contributed.
Beginning with 3.22, some RPMs are generated by us at MySQL AB.
If you want to compile a debug version of @strong{MySQL}, you should add
@code{--with-debug} or @code{--with-debug=full} to the above configure lines
and remove any @code{-fomit-frame-pointer} options.
@node Post-installation, Upgrade, MySQL binaries, Installing
@section Post-installation setup and testing
@menu
* mysql_install_db:: Problems running @code{mysql_install_db}
* Starting server:: Problems starting the @strong{MySQL} server
* Automatic start:: Starting and stopping @strong{MySQL} automatically
* Command-line options:: Command-line options
* Option files:: Option files
@end menu
Once you've installed @strong{MySQL} (from either a binary or source
distribution), you need to initialize the grant tables, start the server
and make sure that the server works okay. You may also wish to arrange
for the server to be started and stopped automatically when your system
starts up and shuts down.
Normally you install the grant tables and start the server like this
for installation from a source distribution:
@example
shell> ./scripts/mysql_install_db
shell> cd mysql_installation_directory
* Command-line options:: Command-line options
shell> ./bin/safe_mysqld &
@end example
For a binary distribution, do this:
@example
shell> cd mysql_installation_directory
shell> ./bin/mysql_install_db
shell> ./bin/safe_mysqld &
@end example
Testing is most easily done from the top-level directory of the @strong{MySQL}
distribution. For a binary distribution, this is your installation directory
(typically something like @file{/usr/local/mysql}). For a source
distribution, this is the main directory of your @strong{MySQL} source tree.
In the commands shown below in this section and in the following
subsections, @code{BINDIR} is the path to the location in which programs
like @code{mysqladmin} and @code{safe_mysqld} are installed. For a
binary distribution, this is the @file{bin} directory within the
distribution. For a source distribution, @code{BINDIR} is probably
@file{/usr/local/bin}, unless you specified an installation directory
other than @file{/usr/local} when you ran @code{configure}.
@code{EXECDIR} is the location in which the @code{mysqld} server is
installed. For a binary distribution, this is the same as
@code{BINDIR}. For a source distribution, @code{EXECDIR} is probably
@file{/usr/local/libexec}.
Testing is described in detail below:
@enumerate
@item
If necessary, start the @code{mysqld} server and set up the initial
@strong{MySQL} grant tables containing the privileges that determine how
users are allowed to connect to the server. This is normally done with the
@code{mysql_install_db} script:
@example
shell> scripts/mysql_install_db
@end example
Typically, @code{mysql_install_db} needs to be run only the first time you
install @strong{MySQL}. Therefore, if you are upgrading an existing
installation, you can skip this step. (However, @code{mysql_install_db} is
quite safe to use and will not update any tables that already exist, so if
you are unsure what to do, you can always run @code{mysql_install_db}.)
@code{mysql_install_db} creates six tables (@code{user}, @code{db},
@code{host}, @code{tables_priv}, @code{columns_priv} and @code{func}) in the
@code{mysql} database. A description of the initial privileges is given in
@ref{Default privileges}. Briefly, these privileges allow the @strong{MySQL}
@code{root} user to do anything, and allow anybody to create or use databases
with a name of @code{'test'} or starting with @code{'test_'}.
If you don't set up the grant tables, the following error will appear in the
log file when you start the server:
@tindex host.frm, problems finding
@example
mysqld: Can't find file: 'host.frm'
@end example
The above may also happens with a binary @strong{MySQL} distribution if you
don't start @strong{MySQL} by executing exactly @code{./bin/safe_mysqld}!
You might need to run @code{mysql_install_db} as @code{root}. However,
if you prefer, you can run the @strong{MySQL} server as an unprivileged
(non-@code{root}) user, provided that user can read and write files in
the database directory. Instructions for running @strong{MySQL} as an
unprivileged user are given in @ref{Changing MySQL user, , Changing
@strong{MySQL} user}.
If you have problems with @code{mysql_install_db}, see
@ref{mysql_install_db, , @code{mysql_install_db}}.
There are some alternatives to running the @code{mysql_install_db}
script as it is provided in the @strong{MySQL} distribution:
@itemize @bullet
@item
You may want to edit @code{mysql_install_db} before running it, to
change the initial privileges that are installed into the grant tables.
This is useful if you want to install @strong{MySQL} on a lot of machines
with the same privileges. In this case you probably should need only to add
a few extra @code{INSERT} statements to the @code{mysql.user} and
@code{mysql.db} tables!
@item
If you want to change things in the grant tables after installing them, you
can run @code{mysql_install_db}, then use @code{mysql -u root mysql} to
connect to the grant tables as the @strong{MySQL} @code{root} user and issue
SQL statements to modify the grant tables directly.
@item
It is possible to recreate the grant tables completely after they have
already been created. You might want to do this if you've already installed
the tables but then want to recreate them after editing
@code{mysql_install_db}.
@end itemize
For more information about these alternatives, see @ref{Default privileges}.
@item
Start the @strong{MySQL} server like this:
@example
shell> cd mysql_installation_directory
shell> bin/safe_mysqld &
@end example
If you have problems starting the server, see @ref{Starting server}.
@item
Use @code{mysqladmin} to verify that the server is running. The following
commands provide a simple test to check that the server is up and responding
to connections:
@example
shell> BINDIR/mysqladmin version
shell> BINDIR/mysqladmin variables
@end example
The output from @code{mysqladmin version} varies slightly depending on your
platform and version of @strong{MySQL}, but should be similar to that shown
below:
@example
shell> BINDIR/mysqladmin version
mysqladmin Ver 6.3 Distrib 3.22.9-beta, for pc-linux-gnu on i686
TCX Datakonsult AB, by Monty
Server version 3.22.9-beta
Protocol version 10
Connection Localhost via UNIX socket
TCP port 3306
UNIX socket /tmp/mysql.sock
Uptime: 16 sec
Running threads: 1 Questions: 20 Reloads: 2 Open tables: 3
@end example
To get a feeling for what else you can do with @code{BINDIR/mysqladmin},
invoke it with the @code{--help} option.
@item
Verify that you can shut down the server:
@example
shell> BINDIR/mysqladmin -u root shutdown
@end example
@item
Verify that you can restart the server. Do this using @code{safe_mysqld} or
by invoking @code{mysqld} directly. For example:
@example
shell> BINDIR/safe_mysqld --log &
@end example
If @code{safe_mysqld} fails, try running it from the @strong{MySQL}
installation directory (if you are not already there). If that doesn't work,
see @ref{Starting server}.
@item
Run some simple tests to verify that the server is working.
The output should be similar to what is shown below:
@example
shell> BINDIR/mysqlshow
+-----------+
| Databases |
+-----------+
| mysql |
+-----------+
shell> BINDIR/mysqlshow mysql
Database: mysql
+--------------+
| Tables |
+--------------+
| columns_priv |
| db |
| func |
| host |
| tables_priv |
| user |
+--------------+
shell> BINDIR/mysql -e "select host,db,user from db" mysql
+------+--------+------+
| host | db | user |
+------+--------+------+
| % | test | |
| % | test_% | |
+------+--------+------+
@end example
There is also a benchmark suite in the @file{sql-bench} directory (under the
@strong{MySQL} installation directory) that you can use to compare how
@strong{MySQL} performs on different platforms. The @file{sql-bench/Results}
directory contains the results from many runs against different databases and
platforms. To run all tests, execute these commands:
@example
shell> cd sql-bench
shell> run-all-tests
@end example
If you don't have the @file{sql-bench} directory, you are probably using an
RPM for a binary distribution. (Source distribution RPMs include the
benchmark directory.) In this case, you must first install the benchmark
suite before you can use it. Beginning with @strong{MySQL} 3.22, there are
benchmark RPM files named @file{mysql-bench-VERSION-i386.rpm} that contain
benchmark code and data.
If you have a source distribution, you can also run the tests in the
@file{tests} subdirectory. For example, to run @file{auto_increment.tst}, do
this:
@example
shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst
@end example
The expected results are shown in the @file{./tests/auto_increment.res} file.
@end enumerate
@node mysql_install_db, Starting server, Post-installation, Post-installation
@subsection Problems running @code{mysql_install_db}
This section lists problems you might encounter when you run
@code{mysql_install_db}:
@table @strong
@item @code{mysql_install_db} doesn't install the grant tables
You may find that @code{mysql_install_db} fails to install the grant
tables and terminates after displaying the following messages:
@example
starting mysqld daemon with databases from XXXXXX
mysql daemon ended
@end example
In this case, you should examine the log file very carefully! The log
should be located in the directory @file{XXXXXX} named by the error message,
and should indicate why @code{mysqld} didn't start. If you don't understand
what happened, include the log when you post a bug report using
@code{mysqlbug}!
@xref{Bug reports}.
@item There is already a @code{mysqld} daemon running
In this case, you have probably don't have to run @code{mysql_install_db} at
all. You have to run @code{mysql_install_db} only once, when you install
@strong{MySQL} the first time.
@item Installing a second @code{mysqld} daemon doesn't work when one daemon is running
This can happen when you already have an existing @strong{MySQL}
installation, but want to put a new installation in a different place (e.g.,
for testing, or perhaps you simply want to run two installations at the same
time). Generally the problem that occurs when you try to run the second
server is that it tries to use the same socket and port as the old one. In
this case you will get the error message: @code{Can't start server: Bind on
TCP/IP port: Address already in use} or @code{Can't start server : Bind on
unix socket...} You can start the new server with a different socket and
port as follows:
@tindex MYSQL_UNIX_PORT environment variable
@tindex MYSQL_TCP_PORT environment variable
@tindex Environment variable, MYSQL_UNIX_PORT
@tindex Environment variable, MYSQL_TCP_PORT
@example
shell> MYSQL_UNIX_PORT=/tmp/mysqld-new.sock
shell> MYSQL_TCP_PORT=3307
shell> export MYSQL_UNIX_PORT MYSQL_TCP_PORT
shell> scripts/mysql_install_db
shell> bin/safe_mysqld &
@end example
The environment variables appendix includes a list of other environment
variables you can use to affect @code{mysqld}. @xref{Environment variables}.
After this, you should edit your server boot script to start both daemons
with different sockets and ports. For example, it could invoke
@code{safe_mysqld} twice, but with different @code{--socket}, @code{--port}
and @code{--basedir} options for each invocation.
@item You don't have write access to @file{/tmp}
If you don't have write access to create a socket file at the default place
(in @file{/tmp}) or permission to create temporary files in @file{/tmp,}
you will get an error when running @code{mysql_install_db} or when
starting or using @code{mysqld}.
You can specify a different socket and temporary directory as follows:
@tindex TMPDIR environment variable
@tindex MYSQL_UNIX_PORT environment variable
@tindex Environment variable, TMPDIR
@tindex Environment variable, MYSQL_UNIX_PORT
@example
shell> TMPDIR=/some_tmp_dir/
shell> MYSQL_UNIX_PORT=/some_tmp_dir/mysqld.sock
shell> export TMPDIR MYSQL_UNIX_PORT
@end example
@file{some_tmp_dir} should be the path to some directory for which you
have write permission. @xref{Environment variables}.
After this you should be able to run @code{mysql_install_db} and start
the server with these commands:
@example
shell> scripts/mysql_install_db
shell> BINDIR/safe_mysqld &
@end example
@item @code{mysqld} crashes immediately
If you are running RedHat 5.0 with a version of @code{glibc} older than
2.0.7-5, you should make sure you have installed all @code{glibc} patches!
There is a lot of information about this in the @strong{MySQL} mail
archives. Links to the mail archives are available at the online
@uref{http://www.mysql.com/documentation/, @strong{MySQL} documentation page}.
Also, see @ref{Linux}.
You can also start @code{mysqld} manually using the @code{--skip-grant-tables}
option and add the privilege information yourself using @code{mysql}:
@example
shell> BINDIR/safe_mysqld --skip-grant-tables &
shell> BINDIR/mysql -u root mysql
@end example
From @code{mysql}, manually execute the SQL commands in
@code{mysql_install_db}. Make sure you run @code{mysqladmin
flush-privileges} or @code{mysqladmin reload} afterward to tell the server to
reload the grant tables.
@end table
@node Starting server, Automatic start, mysql_install_db, Post-installation
@subsection Problems starting the MySQL server
Generally, you start the @code{mysqld} server in one of three ways:
@itemize @bullet
@item
By invoking @code{mysql.server}. This script is used primarily at
system startup and shutdown, and is described more fully in
@ref{Automatic start}.
@item
By invoking @code{safe_mysqld}, which tries to determine the proper options
for @code{mysqld} and then runs it with those options.
@item
On NT you should install @code{mysqld} as a service as follows:
@example
bin\mysqld-nt --install # Install MySQL as a service
@end example
You can now start/stop @code{mysqld} as follows:
@example
NET START mysql
NET STOP mysql
@end example
Note that in this case you can't use any other options for @code{mysqld}!
You can remove the service as follows:
@example
bin\mysqld-nt --remove # remove MySQL as a service
@end example
@item
By invoking @code{mysqld} directly.
@end itemize
Whichever method you use to start the server, if it fails to start up
correctly, check the log file to see if you can find out why. Log files
are located in the data directory (typically
@file{/usr/local/mysql/data} for a binary distribution,
@file{/usr/local/var} for a source distribution),
@file{\mysql\mysql.err} on Windows. Look in the data directory for
files with names of the form @file{host_name.err} and
@file{host_name.log} where @code{host_name} is the name of your server
host. Then check the last few lines of these files:
@example
shell> tail host_name.err
shell> tail host_name.log
@end example
If you find in the log file something like: the following:
@example
000729 14:50:10 bdb: Recovery function for LSN 1 27595 failed
000729 14:50:10 bdb: warning: ./test/t1.db: No such file or directory
000729 14:50:10 Can't init databases
@end example
This means that you started mysqld with @code{--bdb-recover} and that
Berkeley DB found something wrong with it's log files when it tried to
recover your databases. To be able to continue, you should move away
the old Berkeley DB log file from the database directory to some other
place, where you can later examine these. The log files are named
@file{log.0000000001}, where the number will increase over time.
When the @code{mysqld} daemon starts up, it changes directory to the
data directory. This is where it expects to write log files and the pid
(process ID) file, and where it expects to find databases.
The data directory location is hardwired in when the distribution is
compiled. However, if @code{mysqld} expects to find the data directory
somewhere other than where it really is on your system, it will not work
properly. If you have problems with incorrect paths, you can find out
what options @code{mysqld} allows and what the default path settings are by
invoking @code{mysqld} with the @code{--help} option. You can override the
defaults by specifying the correct pathnames as command-line arguments to
@code{mysqld}. (These options can be used with @code{safe_mysqld} as well.)
Normally you should need to tell @code{mysqld} only the base directory under
which @strong{MySQL} is installed. You can do this with the @code{--basedir}
option. You can also use @code{--help} to check the effect of changing path
options (note that @code{--help} @emph{must} be the final option of the
@code{mysqld} command). For example:
@example
shell> EXECDIR/mysqld --basedir=/usr/local --help
@end example
Once you determine the path settings you want, start the server without
the @code{--help} option.
If you get the following error, it means that some other program (or another
@code{mysqld} server) is already using the TCP/IP port or socket
@code{mysqld} is trying to use:
@example
Can't start server: Bind on TCP/IP port: Address already in use
or
Can't start server : Bind on unix socket...
@end example
Use @code{ps} to make sure that you don't have another @code{mysqld} server
running. If you can't find another server running, you can try to execute
the command @code{telnet your-host-name tcp-ip-port-number} and press
@code{RETURN} a couple of times. If you don't get an error message like
@code{telnet: Unable to connect to remote host: Connection refused},
something is using the TCP/IP port @code{mysqld} is trying to use.
@xref{mysql_install_db, , @code{mysql_install_db}}, and @ref{Multiple
servers}.
The @code{safe_mysqld} script is written so that it normally is able to start
a server that was installed from either a source or a binary version of
@strong{MySQL}, even if these install the server in slightly different
locations. @code{safe_mysqld} expects one of these conditions to be true:
@itemize @bullet
@item
The server and databases can be found relative to the directory from which
@code{safe_mysqld} is invoked. @code{safe_mysqld} looks under its working
directory for @file{bin} and @file{data} directories (for binary
distributions) or for @file{libexec} and @file{var} directories (for source
distributions). This condition should be met if you execute
@code{safe_mysqld} from your @strong{MySQL} installation directory (for
example, @file{/usr/local/mysql} for a binary distribution).
@item
If the server and databases cannot be found relative to its working directory,
@code{safe_mysqld} attempts to locate them by absolute pathnames. Typical
locations are @file{/usr/local/libexec} and @file{/usr/local/var}.
The actual locations are determined when the distribution was built from which
@code{safe_mysqld} comes. They should be correct if
@strong{MySQL} was installed in a standard location.
@end itemize
Because @code{safe_mysqld} will try to find the server and databases relative
to its own working directory, you can install a binary distribution of
@strong{MySQL} anywhere, as long as you start @code{safe_mysqld} from the
@strong{MySQL} installation directory:
@example
shell> cd mysql_installation_directory
shell> bin/safe_mysqld &
@end example
If @code{safe_mysqld} fails, even when invoked from the @strong{MySQL}
installation directory, you can modify it to use the path to @code{mysqld}
and the pathname options that are correct for your system. Note that if you
upgrade @strong{MySQL} in the future, your modified version of
@code{safe_mysqld} will be overwritten, so you should make a copy of your
edited version that you can reinstall.
If @code{mysqld} is currently running, you can find out what path settings
it is using by executing this command:
@example
shell> mysqladmin variables
or
shell> mysqladmin -h 'your-host-name' variables
@end example
If @code{safe_mysqld} starts the server but you can't connect to it,
you should make sure you have an entry in @file{/etc/hosts} that looks like
this:
@example
127.0.0.1 localhost
@end example
This problem occurs only on systems that don't have a working thread
library and for which @strong{MySQL} must be configured to use MIT-pthreads.
On Windows, you can try to start @code{mysqld} as follows:
@example
C:\mysql\bin\mysqld --standalone --debug
@end example
This will not run in the background and it should also write a trace in
@file{\mysqld.trace}, which may help you determine the source of your
problems. @xref{Win32}.
@node Automatic start, Command-line options, Starting server, Post-installation
@subsection Starting and stopping MySQL automatically
The @code{mysql.server} script can be used to start or stop the server,
by invoking it with @code{start} or @code{stop} arguments:
@example
shell> mysql.server start
shell> mysql.server stop
@end example
@code{mysql.server} can be found in the @file{share/mysql} directory
under the @strong{MySQL} installation directory, or in the @file{support-files}
directory of the @strong{MySQL} source tree.
Before @code{mysql.server} starts the server, it changes directory to
the @strong{MySQL} installation directory, then invokes
@code{safe_mysqld}. You might need to edit @code{mysql.server} if you
have a binary distribution that you've installed in a non-standard
location. Modify it to @code{cd} into the proper directory before it
runs @code{safe_mysqld}. If you want the server to run as some specific
user, you can change the @code{mysql_daemon_user=root} line to use
another user. You can also modify @code{mysql.server} to pass other
options to @code{safe_mysqld}.
@code{mysql.server stop} brings down server by sending a signal to it.
You can take down the server manually by executing @code{mysqladmin shutdown}.
You might want to add these start and stop commands to the appropriate places
in your @file{/etc/rc*} files when you start using @strong{MySQL} for
production applications. Note that if you modify @code{mysql.server}, then
if you upgrade @strong{MySQL} sometime, your modified version will be
overwritten, so you should make a copy of your edited version that you can
reinstall.
If your system uses @file{/etc/rc.local} to start external scripts, you
should append the following to it:
@example
/bin/sh -c 'cd /usr/local/mysql ; ./bin/safe_mysqld &'
@end example
You can also add options for @code{mysql.server} in a global
@file{/etc/my.cnf} file. A typical @file{/etc/my.cnf} file might look like
this:
@example
[mysqld]
datadir=/usr/local/mysql/var
socket=/tmp/mysqld.sock
port=3306
[mysql.server]
user=mysql
basedir=/usr/local/mysql
@end example
The @code{mysql.server} script uses the following variables:
@code{user}, @code{datadir}, @code{basedir}, @code{bindir} and @code{pid-file}.
@xref{Option files}.
@cindex Command-line options
@node Command-line options, Option files, Automatic start, Post-installation
@subsection Command-line options
@code{mysqld} accepts the following command-line options:
@table @code
@item --ansi
Use ANSI SQL syntax instead of MySQL syntax. @xref{Ansi mode}.
@item -b, --basedir=path
Path to installation directory. All paths are
usually resolved relative to this.
@item --big-tables
Allow big result sets by saving all temporary sets on file. It solves
most 'table full' errors, but also slows down the queries where
in-memory tables would suffice. Since version 3.23.2 @strong{MySQL} is
able to solve it automaticaly by using memory for small temporary
tables and switching to disk tables where necessary.
@item --bind-address=IP
IP address to bind to.
@item --character-sets-dir=path
Directory where character sets are. @xref{Character sets}.
@item --chroot=path
Chroot mysqld daemon during startup.
Recommended security measure. It will somewhat limit @code{LOAD DATA INFILE}
and @code{SELECT ... INTO OUTFILE} though.
@item -h, --datadir=path
Path to the database root.
@item --default-character-set=charset
Set the default character set. @xref{Character sets}.
@item --default-table-type=type
Set the default table type for tables. @xref{Table types}.
@item --delay-key-write-for-all-tables
Don't flush key buffers between writes for any @code{MyISAM} table.
@xref{Server parameters}.
@item --enable-locking
Enable system locking.
@item -T, --exit-info
Print some debug info at exit.
@item --flush
Flush all changes to disk after each SQL commands; Normally @strong{MySQL}
only does a write of all changes to disk after each SQL command, and lets
the operating system handle the syncing to disk.
@xref{Crashing}.
@item -?, --help
Display short help and exit.
@item --init-file=file
Read SQL commands from this file at startup.
@item -L, --language=...
Client error messages in given language. May be given as a full path.
@xref{Languages}.
@item -l, --log[=file]
Log connections and queries to file
@item --log-update[=file]
Log updates to @code{file.#} where @code{#} is a unique number if not given.
@xref{Update log}.
@item --log-isam[=file]
Log all isam changes to file.
@item --log-long-format
Log some extra information to update log.
@item --low-priority-updates
Table-modifying operations (@code{INSERT}/@code{DELETE}/@code{UPDATE})
will have lower priority than selects.
It can also be done via @code{@{INSERT | REPLACE | UPDATE | DELETE@}
LOW_PRIORITY ...} to lower the priority of only one query, or by
@code{SET OPTION SQL_LOW_PRIORITY_UPDATES=1} to change the
priority in one thread.
@xref{Table locking}.
@item --pid-file=path
Path to pid file used by @code{safe_mysqld}.
@item -P, --port=...
Port number to listen for TCP/IP connections.
@item -o, --old-protocol
Use the 3.20 protocol for compatibility with some very old clients.
@xref{Upgrading-from-3.20}.
@item --one-thread
Only use one thread (for debugging under Linux). @xref{Debugging server}.
@item -O, --set-variable var=option
Give a variable an value. @code{--help} lists variables.
You can find a full description for all variables in the @code{SHOW VARIABLES}
section in this manual. @xref{SHOW VARIABLES}.
The tuning server parameters section includes information of how to optimize
these. @xref{Server parameters}.
@item -Sg, --skip-grant-tables
This option causes the server not to use the privilege system at all. This
gives everyone @emph{full access} to all databases! (You can tell a running
server to start using the grant tables again by executing @code{mysqladmin
flush-privileges} or @code{mysqladmin reload}.)
@item --safe-mode
Skip some optimize stages.
Implies @code{--skip-delay-key-write}.
@item --secure
IP numbers returned by the @code{gethostbyname()} system call are
checked to make sure they resolve back to the original hostname. This
makes it harder for someone on the outside to get access by pretending
to be another host. This option also adds some sanity checks of
hostnames. The option is turned off by default in @strong{MySQL} 3.21
because sometimes it takes a long time to perform backward resolutions.
@strong{MySQL} 3.22 caches hostnames (unless @code{--skip-host-cache} is
used) and has this option enabled by default.
@item --skip-delay-key-write
Ignore the @code{delay_key_write} option for all tables.
@xref{Server parameters}.
@item --skip-locking
Don't use system locking. To use @code{isamchk} or @code{myisamchk} one has
to shut down the server. @xref{Stability}. Note that in @strong{MySQL} 3.23
one can use @code{REPAIR} and @code{CHECK} to repair/check @code{MyISAM}
tables.
@item --skip-name-resolve
Hostnames are not resolved. All @code{Host} column values in the grant
tables must be IP numbers or @code{localhost}.
@item --skip-networking
Don't listen for TCP/IP connections at all.
All interaction with @code{mysqld} must be made via Unix sockets.
This option is highly recommended for systems where only local requests
are allowed. However, this option is unsuitable for systems that use
MIT-pthreads, because the MIT-pthreads package doesn't support Unix
sockets.
@item --skip-new
Don't use new, possible wrong routines.
Implies @code{--skip-delay-key-write}.
This will also set default table type to @code{ISAM}. @xref{ISAM}.
@item --skip-host-cache
Never use host name cache for faster name-ip resolution, but query
DNS server on every connect instead.
@item --skip-show-database
Don't allow 'SHOW DATABASE' commands, unless the user has
@strong{process} privilege.
@item --skip-thread-priority
Disable using thread priorities for faster responce time.
@item --socket=path
Socket file to use for local connections instead of default
@code{/tmp/mysql.sock}.
@item -t, --tmpdir=path
Path for temporary files. It may be useful if your default @code{/tmp}
directory resides on a partition too small to hold temporary tables.
@item -u, --user=user_name
Run @code{mysqld} daemon as user @code{user_name}. This option is
@emph{mandatory} when starting @code{mysqld} as root.
@item -V, --version
output version information and exit
@end table
@cindex Default options
@cindex Option files
@node Option files, , Command-line options, Post-installation
@subsection Option files
@strong{MySQL} 3.22 can read default startup options for the server and
for clients from option files.
@strong{MySQL} reads default options from the following files on Unix:
@tindex .my.cnf file
@multitable @columnfractions .3 .7
@item @strong{Filename} @tab @strong{Purpose}
@item @code{/etc/my.cnf} @tab Global options
@item @code{DATADIR/my.cnf} @tab Server-specific options
@item @code{~/.my.cnf} @tab User-specific options
@end multitable
@code{DATADIR} is the @strong{MySQL} data directory (typically
@file{/usr/local/mysql/data} for a binary installation, or
@file{/usr/local/var} for a source installation). Note that this is the
directory that was specified at configuration time, not the one specified
with @code{--datadir} when @code{mysqld} starts up! (@code{--datadir} has no
effect on where the server looks for option files, because it looks for them
before it processes any command-line arguments.)
@strong{MySQL} reads default options from the following files on Win32:
@multitable @columnfractions .3 .7
@item @strong{Filename} @tab @strong{Purpose}
@item @code{windows-system-directory\my.ini}
@item @code{C:\my.cnf} @tab Global options
@item @code{C:\mysql\data\my.cnf} @tab Server-specific options
@end multitable
Note that you on Win32 should specify all paths with @code{/} instead of
@code{\}. If you use @code{\}, you need to specify this twice, as
@code{\} is the escape character in @strong{MySQL}.
@cindex Environment variables
@strong{MySQL} tries to read option files in the order listed above. If
multiple option files exist, an option specified in a file read later takes
precedence over the same option specified in a file read earlier. Options
specified on the command line take precedence over options specified in any
option file. Some options can be specified using environment variables.
Options specified on the command line or in option files take precedence over
environment variable values. @xref{Environment variables}.
The following programs support option files: @code{mysql},
@code{mysqladmin}, @code{mysqld}, @code{mysqldump}, @code{mysqlimport},
@code{mysql.server}, @code{myisamchk} and @code{myisampack}.
You can use option files to specify any long option that a program supports!
Run the program with @code{--help} to get a list of available options.
An option file can contain lines of the following forms:
@table @code
@item #comment
Comment lines start with @samp{#} or @samp{;}. Empty lines are ignored.
@item [group]
@code{group} is the name of the program or group for which you want to set
options. After a group line, any @code{option} or @code{set-variable} lines
apply to the named group until the end of the option file or another group
line is given.
@item option
This is equivalent to @code{--option} on the command line.
@item option=value
This is equivalent to @code{--option=value} on the command line.
@item set-variable = variable=value
This is equivalent to @code{--set-variable variable=value} on the command line.
This syntax must be used to set a @code{mysqld} variable.
@end table
The @code{client} group allows you to specify options that apply to all
@strong{MySQL} clients (not @code{mysqld}). This is the perfect group to use
to specify the password you use to connect to the server. (But make
sure the option file is readable and writable only to yourself.)
Note that for options and values, all leading and trailing blanks are
automatically deleted. You may use the escape sequences @samp{\b},
@samp{\t}, @samp{\n}, @samp{\r}, @samp{\\} and @samp{\s} in your value string
(@samp{\s} == blank).
Here is a typical global option file:
@example
[client]
port=3306
socket=/tmp/mysql.sock
[mysqld]
port=3306
socket=/tmp/mysql.sock
set-variable = key_buffer_size=16M
set-variable = max_allowed_packet=1M
[mysqldump]
quick
@end example
Here is typical user option file:
@example
[client]
# The following password will be sent to all standard MySQL clients
password=my_password
[mysql]
no-auto-rehash
@end example
@tindex .my.cnf file
If you have a source distribution, you will find sample configuration
files named @file{my-xxxx.cnf} in the @file{support-files} directory.
If you have a binary distribution, look in the @file{DIR/share/mysql}
directory, where @code{DIR} is the pathname to the @strong{MySQL}
installation directory (typically @file{/usr/local/mysql}). Currently
there is sample configuration files for small, medium, large and very
large systems. You can copy @file{my-xxxx.cnf} to your home directory
(rename the copy to @file{.my.cnf}) to experiment with this.
To tell a @strong{MySQL} program not to read any option files, specify
@code{--no-defaults} as the first option on the command line. This
@strong{MUST} be the first option or it will have no effect!
If you want to check which options are used, you can give the option
@code{--print-defaults} as the first option.
If you want to force the use of a specific config file, you can use the option
@code{--defaults-file=full-path-to-default-file}. If you do this, only the
specified file will be read.
Note for developers: Option file handling is implemented simply by
processing all matching options (i.e., options in the appropriate group)
before any command line arguments. This works nicely for programs that use
the last instance of an option that is specified multiple times. If you have
an old program that handles multiply-specified options this way but doesn't
read option files, you need add only two lines to give it that capability.
Check the source code of any of the standard @strong{MySQL} clients to see
how to do this.
@node Upgrade, , Post-installation, Installing
@section Is there anything special to do when upgrading/downgrading MySQL?
You can always move the @strong{MySQL} form and data files between
different versions on the same architecture as long as you have the same
base version of @strong{MySQL}. The current base version is
3. If you change the character set when running @strong{MySQL} (which may
also change the sort order), you must run @code{myisamchk -r -q} on all
tables. Otherwise your indexes may not be ordered correctly.
If you are paranoid and/or afraid of new versions, you can always rename your
old @code{mysqld} to something like @code{mysqld}-'old-version-number'. If
your new @code{mysqld} then does something unexpected, you can simply shut it
down and restart with your old @code{mysqld}!
When you do an upgrade you should also backup your old databases, of course.
Sometimes it's good to be a little paranoid!
After an upgrade, if you experience problems with recompiled client programs,
like @code{Commands out of sync} or unexpected core dumps, you probably have
used an old header or library file when compiling your programs. In this
case you should check the date for your @file{mysql.h} file and
@file{libmysqlclient.a} library to verify that they are from the new
@strong{MySQL} distribution. If not, please recompile your programs!
If you get some problems that the new @code{mysqld} server doesn't want to
start or that you can't connect without a password, check that you don't
have some old @file{my.cnf} file from your old installation! You can
check this with: @code{program-name --print-defaults}. If this outputs
anything other than the program name, you have an active @code{my.cnf}
file that will may affect things!
It is a good idea to rebuild and reinstall the @code{Msql-Mysql-modules}
distribution whenever you install a new release of @strong{MySQL},
particularly if you notice symptoms such as all your @code{DBI} scripts
dumping core after you upgrade @strong{MySQL}.
@menu
* Upgrading-from-3.22:: Upgrading from a 3.22 version to 3.23
* Upgrading-from-3.21:: Upgrading from a 3.21 version to 3.22
* Upgrading-from-3.20:: Upgrading from a 3.20 version to 3.21
* Upgrading-to-arch:: Upgrading to another architecture
@end menu
@cindex Compatibility, between MySQL versions
@node Upgrading-from-3.22, Upgrading-from-3.21, Upgrade, Upgrade
@subsection Upgrading from a 3.22 version to 3.23
@strong{MySQL} 3.23 supports tables of the new @code{MyISAM} type and
the old @code{ISAM} type. You don't have to convert your old tables to
use these with 3.23. By default, all new tables will be created with
type @code{MyISAM} (unless you start @code{mysqld} with the
@code{--default-table-type=isam} option. You can change an @code{ISAM}
table to a @code{MyISAM} table with @code{ALTER TABLE} or the Perl script
@code{mysql_convert_table_format}.
3.22 and 3.21 clients will work without any problems with a 3.23 server.
The following lists what you have to watch out for when upgrading to 3.23:
@itemize @bullet
@item The default return type of @code{IF} will now depend on both arguments
and not only the first argument.
@item @code{AUTO_INCREMENT} will not work with negative numbers.
@item @code{INNER} and @code{DELAYED} are now reserved words.
@item @code{FLOAT(X)} is now a true floating point types and not a value with
a fixed number of decimals.
@item When declaring @code{DECIMAL(length,dec)} the length argument no
longer includes a place for the sign or the decimal point.
@item A @code{TIME} string must now be of one of the following formats:
@code{[[[DAYS] [H]H:]MM:]SS[.fraction]} or
@code{[[[[[H]H]H]H]MM]SS[.fraction]}
@item @code{LIKE} now compares strings using the same character
comparison rules as @code{'='}. If you require the old behavior, you
can compile @strong{MySQL} with the @code{CXXFLAGS=-DLIKE_CMP_TOUPPER}
flag.
@item @code{REGEXP} is now case insensitive for normal (not binary) strings.
@item When you check/repair tables you should use @code{CHECK TABLE}
or @code{myisamchk} for @code{MyISAM} tables (@code{.MYI}) and
@code{isamchk} for ISAM (@code{.ISM}) tables.
@item If you want your @code{mysqldump}s to be compatible between
@strong{MySQL} 3.22 and 3.23, you should not use the @code{--opt} or
@code{--full} option to @code{mysqldump}.
@item Check all your calls to @code{DATE_FORMAT()} to make sure there is a
@samp{%} before each format character. (Later @strong{MySQL} 3.22
version did allow this syntax.
@item
@code{mysql_fetch_fields_direct} is now a function (it was a macro) and
it returns a pointer to a @code{MYSQL_FIELD} instead of a
@code{MYSQL_FIELD}.
@item
@code{mysql_num_fields()} can no longer be used on a @code{MYSQL*} object (it's
now a function that takes @code{MYSQL_RES*} as an argument. You should now
use @code{mysql_field_count()} instead.
@item
In @code{MySQL} 3.22, the output of @code{SELECT DISTINCT ...} was
almost always sorted. In 3.23, you must use @code{GROUP BY} or
@code{ORDER BY} to obtain sorted output.
@item
@code{SUM()} now returns @code{NULL}, instead of 0, if there is no matching
rows. This is according to ANSI SQL.
@item
New restricted words: @code{CASE, THEN, WHEN, ELSE and END}
@item An @code{AND} or @code{OR} with @code{NULL} values will now return
@code{NULL} instead of 0. This mostly affects queries that uses @code{NOT}
on an @code{AND/OR} expression as @code{NOT NULL} = @code{NULL}.
@end itemize
@cindex Compatibility, between MySQL versions
@node Upgrading-from-3.21, Upgrading-from-3.20, Upgrading-from-3.22, Upgrade
@subsection Upgrading from a 3.21 version to 3.22
Nothing that affects compatibility has changed between 3.21 and 3.22. The
only pitfall is that new tables that are created with @code{DATE} type
columns will use the new way to store the date. You can't access these new
fields from an old version of @code{mysqld}.
After installing @strong{MySQL} 3.22, you should start the new server and
then run the @code{mysql_fix_privilege_tables} script. This will add the new
privileges that you need to use the @code{GRANT} command. If you forget
this, you will get @code{Access denied} when you try to use @code{ALTER
TABLE}, @code{CREATE INDEX} or @code{DROP INDEX}. If your @strong{MySQL} root
user requires a password, you should give this as an argument to
@code{mysql_fix_privilege_tables}.
The C API interface to @code{mysql_real_connect()} has changed. If you have
an old client program that calls this function, you must place a @code{0} for
the new @code{db} argument (or recode the client to send the @code{db}
element for faster connections). You must also call @code{mysql_init()}
before calling @code{mysql_real_connect()}! This change was done to allow
the new @code{mysql_options()} function to save options in the @code{MYSQL}
handler structure.
The @code{mysqld} variable @code{key_buffer} has changed names to
@code{key_buffer_size}, but you can still use the old name in your
startup files.
@node Upgrading-from-3.20, Upgrading-to-arch, Upgrading-from-3.21, Upgrade
@subsection Upgrading from a 3.20 version to 3.21
If you are running a version older than 3.20.28 and want to
switch to 3.21.x, you need to do the following:
You can start the @code{mysqld} 3.21 server with @code{safe_mysqld
--old-protocol} to use it with clients from the 3.20 distribution.
In this case, the new client function @code{mysql_errno()} will not
return any server error, only @code{CR_UNKNOWN_ERROR}, (but it
works for client errors) and the server uses the old password() checking
rather than the new one.
If you are @strong{NOT} using the @code{--old-protocol} option to
@code{mysqld}, you will need to make the following changes:
@itemize @bullet
@item
All client code must be recompiled. If you are using ODBC, you must get
the new @strong{MyODBC} 2.x driver.
@item
The script @code{scripts/add_long_password} must be run to convert the
@code{Password} field in the @code{mysql.user} table to @code{CHAR(16)}.
@item
All passwords must be reassigned in the @code{mysql.user} table (to get 62-bit
rather than 31-bit passwords).
@item
The table format hasn't changed, so you don't have to convert any tables.
@end itemize
@strong{MySQL} 3.20.28 and above can handle the new @code{user} table format
without affecting clients. If you have a @strong{MySQL} version earlier than
3.20.28, passwords will no longer work with it if you convert the @code{user}
table. So to be safe, you should first upgrade to at least 3.20.28 and then
upgrade to 3.21.x.
@cindex Protocol mismatch
The new client code works with a 3.20.x @code{mysqld} server, so
if you experience problems with 3.21.x, you can use the old 3.20.x server
without having to recompile the clients again.
If you are not using the @code{--old-protocol} option to @code{mysqld},
old clients will issue the error message:
@example
ERROR: Protocol mismatch. Server Version = 10 Client Version = 9
@end example
The new Perl @code{DBI}/@code{DBD} interface also supports the old
@code{mysqlperl} interface. The only change you have to make if you use
@code{mysqlperl} is to change the arguments to the @code{connect()} function.
The new arguments are: @code{host}, @code{database}, @code{user},
@code{password} (the @code{user} and @code{password} arguments have changed
places).
@xref{Perl DBI Class, , Perl @code{DBI} Class}.
The following changes may affect queries in old applications:
@itemize @bullet
@item
@code{HAVING} must now be specified before any @code{ORDER BY} clause.
@item
The parameters to @code{LOCATE()} have been swapped.
@item
There are some new reserved words. The most notable are @code{DATE},
@code{TIME} and @code{TIMESTAMP}.
@end itemize
@node Upgrading-to-arch, , Upgrading-from-3.20, Upgrade
@subsection Upgrading to another architecture
If you are using @strong{MySQL} 3.23, you can copy the @code{.frm}, the
@code{.MYI} and the @code{.MYD} files between different architectures
that support the same floating point format. (@strong{MySQL} takes care
of any byte swapping issues).
The @strong{MySQL} @code{ISAM} data @file{*.ISD} and the index files
@file{*.ISM} files) are architecture-dependent and in some case
OS-dependent. If you want to move your applications to another machine
that has a different architecture or OS than your current machine, you
should not try to move a database by simply copying the files to the
other machine. Use @code{mysqldump} instead.
By default, @code{mysqldump} will create a file full of SQL statements.
You can then transfer the file to the other machine and feed it as input
to the @code{mysql} client.
Try @code{mysqldump --help} to see what options are available.
If you are moving the data to a newer version of @strong{MySQL}, you should use
@code{mysqldump --opt} with the newer version to get a fast, compact dump.
The easiest (although not the fastest) way to move a database between two
machines is to run the following commands on the machine on which the
database is located:
@example
shell> mysqladmin -h 'other hostname' create db_name
shell> mysqldump --opt db_name \
| mysql -h 'other hostname' db_name
@end example
If you want to copy a database from a remote machine over a slow network,
you can use:
@example
shell> mysqladmin create db_name
shell> mysqldump -h 'other hostname' --opt --compress db_name \
| mysql db_name
@end example
You can also store the result in a file, then transfer the file to the
target machine and load the file into the database there. For example,
you can dump a database to a file on the source machine like this:
@example
shell> mysqldump --quick db_name | gzip > db_name.contents.gz
@end example
(The file created in this example is compressed.) Transfer the file
containing the database contents to the target machine and run these commands
there:
@example
shell> mysqladmin create db_name
shell> gunzip < db_name.contents.gz | mysql db_name
@end example
@cindex @code{mysqldump}
@cindex @code{mysqlimport}
You can also use @code{mysqldump} and @code{mysqlimport} to accomplish
the database transfer.
For big tables, this is much faster than simply using @code{mysqldump}.
In the commands shown below, @code{DUMPDIR} represents the full pathname
of the directory you use to store the output from @code{mysqldump}.
First, create the directory for the output files and dump the database:
@example
shell> mkdir DUMPDIR
shell> mysqldump --tab=DUMPDIR db_name
@end example
Then transfer the files in the @code{DUMPDIR} directory to some corresponding
directory on the target machine and load the files into @strong{MySQL}
there:
@example
shell> mysqladmin create db_name # create database
shell> cat DUMPDIR/*.sql | mysql db_name # create tables in database
shell> mysqlimport db_name DUMPDIR/*.txt # load data into tables
@end example
Also, don't forget to copy the @code{mysql} database, because that's where the
grant tables (@code{user}, @code{db}, @code{host}) are stored. You may have
to run commands as the @strong{MySQL} @code{root} user on the new machine
until you have the @code{mysql} database in place.
After you import the @code{mysql} database on the new machine, execute
@code{mysqladmin flush-privileges} so that the server reloads the grant table
information.
@cindex Compatibility, with ANSI SQL
@node Compatibility, Privilege system, Installing, Top
@chapter How standards-compatible is MySQL?
@menu
* Extensions to ANSI:: @strong{MySQL} extensions to ANSI SQL92
* Ansi mode:: Runnning @strong{MySQL} in ANSI mode
* Differences from ANSI:: @strong{MySQL} differences compared to ANSI SQL92
* Missing functions:: Functionality missing from @strong{MySQL}
* Standards:: What standards does @strong{MySQL} follow?
* Commit-rollback:: How to cope without @code{COMMIT}-@code{ROLLBACK}
@end menu
@node Extensions to ANSI, Ansi mode, Compatibility, Compatibility
@section MySQL extensions to ANSI SQL92
@strong{MySQL} includes some extensions that you probably will not find in
other SQL databases. Be warned that if you use them, your code will not be
portable to other SQL servers. In some cases, you can write code that
includes @strong{MySQL} extensions, but is still portable, by using comments
of the form @code{/*! ... */}. In this case, @strong{MySQL} will parse and
execute the code within the comment as it would any other @strong{MySQL}
statement, but other SQL servers will ignore the extensions. For example:
@example
SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ...
@end example
If you add a version number after the @code{'!'}, the syntax will only be
executed if the @strong{MySQL} version is equal or newer than the used
version number:
@example
CREATE /*!32302 TEMPORARY */ TABLE (a int);
@end example
The above means that if you have 3.23.02 or newer, then @strong{MySQL} will use
the @code{TEMPORARY} keyword.
@strong{MySQL} extensions are listed below:
@itemize @bullet
@item
The field types @code{MEDIUMINT}, @code{SET}, @code{ENUM} and the
different @code{BLOB} and @code{TEXT} types.
@item
The field attributes @code{AUTO_INCREMENT}, @code{BINARY}, @code{NULL},
@code{UNSIGNED} and @code{ZEROFILL}.
@item
All string comparisons are case insensitive by default, with sort
ordering determined by the current character set (ISO-8859-1 Latin1 by
default). If you don't like this, you should declare your columns with
the @code{BINARY} attribute or use the @code{BINARY} cast, which causes
comparisons to be done according to the ASCII order used on the
@strong{MySQL} server host.
@item
@strong{MySQL} maps each database to a directory under the @strong{MySQL}
data directory, and tables within a database to filenames in the database
directory.
This has two implications:
@itemize @minus
@item
@cindex Database names, case sensitivity
@cindex Table names, case sensitivity
@cindex Case sensitivity, of database names
@cindex Case sensitivity, of table names
Database names and table names are case sensitive in @strong{MySQL} on
operating systems that have case sensitive filenames (like most Unix
systems). If you have a problem remembering table names, adopt a consistent
convention, such as always creating databases and tables using lowercase
names.
@item
Database, table, index, column or alias names may begin with a digit
(but may not consist solely of digits).
@item
You can use standard system commands to backup, rename, move, delete and copy
tables. For example, to rename a table, rename the @file{.MYD}, @file{.MYI}
and @file{.frm} files to which the table corresponds.
@end itemize
@item
In SQL statements, you can access tables from different databases
with the @code{db_name.tbl_name} syntax. Some SQL servers provide
the same functionality but call this @code{User space}.
@strong{MySQL} dosen't support tablespaces like in:
@code{create table ralph.my_table...IN my_tablespace}.
@item
@code{LIKE} is allowed on numeric columns.
@item
Use of @code{INTO OUTFILE} and @code{STRAIGHT_JOIN} in a @code{SELECT}
statement. @xref{SELECT, , @code{SELECT}}.
@item
The @code{SQL_SMALL_RESULT} option in a @code{SELECT} statement.
@item
@code{EXPLAIN SELECT} to get a description on how tables are joined.
@item
Use of index names, indexes on a prefix of a field, and use of
@code{INDEX} or @code{KEY} in a @code{CREATE TABLE}
statement. @xref{CREATE TABLE, , @code{CREATE TABLE}}.
@item
Use of @code{TEMPORARY} or @code{IF NOT EXISTS} with @code{CREATE TABLE}.
@item
Use of @code{COUNT(DISTINCT list)} where 'list' is more than one element.
@item
Use of @code{CHANGE col_name}, @code{DROP col_name} or @code{DROP INDEX}
in an @code{ALTER TABLE} statement. @xref{ALTER TABLE, , @code{ALTER TABLE}}.
@item
Use of @code{IGNORE} in an @code{ALTER TABLE} statement.
@item
Use of multiple @code{ADD}, @code{ALTER}, @code{DROP} or @code{CHANGE}
clauses in an @code{ALTER TABLE} statement.
@item
Use of @code{DROP TABLE} with the keywords @code{IF EXISTS}.
@item
You can drop multiple tables with a single @code{DROP TABLE} statement.
@item
The @code{LIMIT} clause of the @code{DELETE} statement.
@item
The @code{DELAYED} clause of the @code{INSERT} and @code{REPLACE}
statements.
@item
The @code{LOW_PRIORITY} clause of the @code{INSERT}, @code{REPLACE},
@code{DELETE} and @code{UPDATE} statements.
@cindex Oracle compatibility
@cindex Compatibility, with Oracle
@item
Use of @code{LOAD DATA INFILE}. In many cases, this syntax is compatible with
Oracle's @code{LOAD DATA INFILE}. @xref{LOAD DATA, , @code{LOAD DATA}}.
@item
The @code{OPTIMIZE TABLE} statement.
@xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}.
@item
The @code{SHOW} statement.
@xref{SHOW, , @code{SHOW}}.
@item
Strings may be enclosed by either @samp{"} or @samp{'}, not just by @samp{'}.
@item
Use of the escape @samp{\} character.
@item
The @code{SET OPTION} statement. @xref{SET OPTION, , @code{SET OPTION}}.
@item
You don't need to name all selected columns in the @code{GROUP BY} part.
This gives better performance for some very specific, but quite normal
queries.
@xref{Group by functions}.
@item
To make it easier for users that come from other SQL environments,
@strong{MySQL} supports aliases for many functions. For example, all
string functions support both ANSI SQL syntax and ODBC syntax.
@item
@strong{MySQL} understands the @code{||} and @code{&&} operators to mean
logical OR and AND, as in the C programming language. In @strong{MySQL},
@code{||} and @code{OR} are synonyms, as are @code{&&} and @code{AND}.
Because of this nice syntax, @strong{MySQL} doesn't support
the ANSI SQL @code{||} operator for string concatenation; use
@code{CONCAT()} instead. Because @code{CONCAT()} takes any number
of arguments, it's easy to convert use of the @code{||} operator to
@strong{MySQL}.
@item
@code{CREATE DATABASE} or @code{DROP DATABASE}.
@xref{CREATE DATABASE, , @code{CREATE DATABASE}}.
@cindex PostgreSQL compatibility
@cindex Compatibility, with PostgreSQL
@item
The @code{%} operator is a synonym for @code{MOD()}. That is,
@code{N % M} is equivalent to @code{MOD(N,M)}. @code{%} is supported
for C programmers and for compatibility with PostgreSQL.
@item
The @code{=}, @code{<>}, @code{<=} ,@code{<}, @code{>=},@code{>},
@code{<<}, @code{>>}, @code{<=>}, @code{AND}, @code{OR} or @code{LIKE}
operators may be used in column comparisons to the left of the
@code{FROM} in @code{SELECT} statements. For example:
@example
mysql> SELECT col1=1 AND col2=2 FROM tbl_name;
@end example
@item
The @code{LAST_INSERT_ID()} function.
@xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@item
The @code{REGEXP} and @code{NOT REGEXP} extended regular expression
operators.
@item
@code{CONCAT()} or @code{CHAR()} with one argument or more than two
arguments. (In @strong{MySQL}, these functions can take any number of
arguments.)
@item The @code{BIT_COUNT()}, @code{CASE}, @code{ELT()},
@code{FROM_DAYS()}, @code{FORMAT()}, @code{IF()}, @code{PASSWORD()},
@code{ENCRYPT()}, @code{md5()}, @code{ENCODE()}, @code{DECODE()},
@code{PERIOD_ADD()}, @code{PERIOD_DIFF()}, @code{TO_DAYS()}, or
@code{WEEKDAY()} functions.
@item
Use of @code{TRIM()} to trim substrings. ANSI SQL only supports removal
of single characters.
@item
The @code{GROUP BY} functions @code{STD()}, @code{BIT_OR()} and
@code{BIT_AND()}.
@item
Use of @code{REPLACE} instead of @code{DELETE} + @code{INSERT}.
@xref{REPLACE, , @code{REPLACE}}.
@item
The @code{FLUSH flush_option} statement.
@item
The possiblity to set variables in a statement with @code{:=}:
@example
SELECT @@a:=SUM(total),@@b=COUNT(*),@@a/@@b AS avg FROM test_table;
SELECT @@t1:=(@@t2:=1)+@@t3:=4,@@t1,@@t2,@@t3;
@end example
@end itemize
@node Ansi mode, Differences from ANSI, Extensions to ANSI, Compatibility
@section Runnning MySQL in ANSI mode
If you start mysqld with the @code{--ansi} option, the following behaviour
of @strong{MySQL} changes.
@itemize @bullet
@item
@code{||} is string concatenation instead of @code{OR}.
@item
One can have any number of spaces between a function name and the '('. This
makes also all function names reserved words.
@item
@code{"} will be an identifier quote character (like the @strong{MySQL}
@code{`} quote character) and not a string quote character.
@item
@code{REAL} will be a synonym for @code{FLOAT} instead of a synonym of
@code{DOUBLE}.
@end itemize
@node Differences from ANSI, Missing functions, Ansi mode, Compatibility
@section MySQL differences compared to ANSI SQL92
We try to make @strong{MySQL} follow the ANSI SQL standard and the
ODBC SQL standard, but in some cases @strong{MySQL} does some things
differently:
@itemize @bullet
@item
@code{--} is only a comment if followed by a white space. @xref{Missing comments}.
@item
For @code{VARCHAR} columns, trailing spaces are removed when the value is
stored. @xref{Bugs}.
@item
In some cases, @code{CHAR} columns are silently changed to @code{VARCHAR}
columns. @xref{Silent column changes}.
@item
Privileges for a table is not automatically revoked when you delete a
table. You must explicitly issue a @code{REVOKE} to revoke privileges for
a table. @xref{GRANT, , @code{GRANT}}.
@item
@code{NULL AND FALSE} will evaluate to @code{NULL} and not to @code{FALSE}.
This is because we don't think it's good to have to evaluate a lot of
extra conditions in this case.
@end itemize
@node Missing functions, Standards, Differences from ANSI, Compatibility
@section Functionality missing from MySQL
The following functionality is missing in the current version of
@strong{MySQL}. For a prioritized list indicating when new extensions may be
added to @strong{MySQL}, you should consult
@uref{http://www.mysql.com/documentation/manual.php?section=TODO, the online
@strong{MySQL} TODO list}. That is the latest version of the TODO list in
this manual. @xref{TODO}.
@menu
* Missing Sub-selects:: Sub-selects
* Missing SELECT INTO TABLE:: @code{SELECT INTO TABLE}
* Missing Transactions:: Transactions
* Missing Triggers:: Triggers
* Missing Foreign Keys:: Foreign Keys
* Missing Views:: Views
* Missing comments:: @samp{--} as the start of a comment
@end menu
@node Missing Sub-selects, Missing SELECT INTO TABLE, Missing functions, Missing functions
@subsection Sub-selects
The following will not yet work in @strong{MySQL}:
@example
SELECT * FROM table1 WHERE id IN (SELECT id FROM table2);
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2);
@end example
However, in many cases you can rewrite the query without a sub select:
@example
SELECT table1.* FROM table1,table2 WHERE table1.id=table2.id;
SELECT table1.* FROM table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id IS NULL
@end example
For more complicated subqueries you can often create temporary tables
to hold the subquery. In some cases, however this option will not
work. The most frequently encountered of these cases arises with
@code{DELETE} statements, for which standard SQL does not support joins
(except in sub-selects). For this situation there are two options
available until subqueries are supported by @strong{MySQL}.
The first option is to use a procedural programming language (such as
Perl or PHP) to submit a @code{SELECT} query to obtain the primary keys
for the records to be deleted, and then use these values to construct
the @code{DELETE} statement (@code{DELETE FROM ... WHERE ... IN (key1,
key2, ...)}).
The second option is to use interactive SQL to contruct a set of
@code{DELETE} statements automatically, using the @strong{MySQL}
extension @code{CONCAT()} (in lieu of the standard @code{||} operator).
For example:
@example
SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', tab1.pkid, ';')
FROM tab1, tab2
WHERE tab1.col1 = tab2.col2;
@end example
You can place this query in a script file and redirect input from it to
the @code{mysql} command-line interpreter, piping its output back to a
second instance of the interpreter:
@example
prompt> mysql --skip-column-names mydb < myscript.sql | mysql mydb
@end example
@strong{MySQL} only supports @code{INSERT ... SELECT ...} and
@code{REPLACE ... SELECT ...} Independent sub-selects will be probably
be available in 3.24.0. You can now use the function @code{IN()} in
other contexts, however.
@node Missing SELECT INTO TABLE, Missing Transactions, Missing Sub-selects, Missing functions
@subsection @code{SELECT INTO TABLE}
@strong{MySQL} doesn't yet support the Oracle SQL extension:
@code{SELECT ... INTO TABLE ...}. @strong{MySQL} supports instead the
ANSI SQL syntax @code{INSERT INTO ... SELECT ...}, which is basically
the same thing.
Alternatively, you can use @code{SELECT INTO OUTFILE...} or @code{CREATE
TABLE ... SELECT} to solve your problem.
@node Missing Transactions, Missing Triggers, Missing SELECT INTO TABLE, Missing functions
@subsection Transactions
As @strong{MySQL} does nowadays support transactions, the following
discussion is only valid if you are only using the non-transaction-safe
table types. @xref{COMMIT}.
The question is often asked, by the curious and the critical, ``Why is
@strong{MySQL} not a transactional database?'' or ``Why does @strong{MySQL}
not support transactions?''
@strong{MySQL} has made a conscious decision to support another paradigm
for data integrity, ``atomic operations.'' It is our thinking and
experience that atomic operations offer equal or even better integrity
with much better performance. We, nonetheless, appreciate and understand
the transactional database paradigm and plan, within the next few releases,
to introduce transaction safe tables on a per table basis. We will be
giving our users the possibility to decide if they need the speed of
atomic operations or if they need to use transactional features in their
applications.
How does one use the features of @strong{MySQL} to maintain rigorous integrity
and how do these features compare with the transactional paradigm?
First, in the transactional paradigm, if your applications are written
in a way that is dependent on the calling of ``rollback'' instead of
``commit'' in critical situations, then transactions are more
convenient. Moreover, transactions ensure that unfinished updates or
corrupting activities are not commited to the database; the server is
given the opportunity to do an automatic rollback and your database is
saved.
@strong{MySQL}, in almost all cases, allows you to solve for potential
problems by including simple checks before updates and by running simple
scripts that check the databases for inconsistencies and automatically
repair or warn if such occurs. Note that just by using the
@strong{MySQL} log or even adding one extra log, one can normally fix
tables perfectly with no data integrity loss.
Moreover, ``fatal'' transactional updates can be rewritten to be
atomic. In fact,we will go so far as to say that all integrity problems
that transactions solve can be done with @code{LOCK TABLES} or atomic updates,
ensuring that you never will get an automatic abort from the database,
which is a common problem with transactional databases.
Not even transactions can prevent all loss if the server goes down. In
such cases even a transactional system can lose data. The difference
between different systems lies in just how small the time-lap is where
they could lose data. No system is 100% secure, only ``secure
enough.'' Even Oracle, reputed to be the safest of transactional
databases, is reported to sometimes lose data in such situations.
To be safe with @strong{MySQL}, you only need to have backups and have
the update logging turned on. With this you can recover from any
situation that you could with any transactional database. It is, of
course, always good to have backups, independent of which database you
use.
The transactional paradigm has its benefits and its drawbacks. Many
users and application developers depend on the ease with which they can
code around problems where an ``abort'' appears or is necessary, and they
may have to do a little more work with @strong{MySQL} to either think
differently or write more. If you are new to the atomic operations
paradigm, or more familiar or more comfortable with transactions, do not
jump to the conclusion that @strong{MySQL} has not addressed these
issues. Reliability and integrity are foremost in our minds. Recent
estimates are that there are more than 1,000,000 mysqld servers
currently running, many of which are in production environments. We
hear very, very seldom from our users that they have lost any data, and
in almost all of those cases user error is involved. This is in our
opinion the best proof of @strong{MySQL}'s stability and reliability.
Lastly, in situations where integrity is of highest importance,
@strong{MySQL}'s current features allow for transaction-level or better
reliability and integrity. If you lock tables with @code{LOCK TABLES}, all
updates will stall until any integrity checks are made. If you only obtain
a read lock (as opposed to a write lock), then reads and inserts are
still allowed to happen. The new inserted records will not be seen by
any of the clients that have a @code{READ} lock until they relaease their read
locks. With @code{INSERT DELAYED} you can queue inserts into a local queue,
until the locks are released, without having to have the client wait
for the insert to complete.
``Atomic,'' in the sense that we mean it, is nothing magical. It only means
that you can be sure that while each specific update is running no other
user can interfere with it and that there will never be an automatic
rollback (which can happen on transaction based systems if you are not
very careful). @strong{MySQL} also guarantees that there will not be
any dirty reads. You can find some example of how to write atomic updates
in the in the commit-rollback section. @xref{Commit-rollback}.
We have thought quite a bit about integrity and performance and we
believe that our atomic operations paradigm allows for both high
reliability and extremely high performance, on the order of three to
five times the speed of the fastest and most optimally tuned of
transactional databases. We didn't leave out transactions because they
are hard to do; The main reason we went with atomic operations as
opposed to transactions is that by doing this we could apply many speed
optimizations that would not otherwise have been possible.
Many of our users who have speed foremost in their minds are not at all
concerned about transactions. For them transactions are not an
issue. For those of our users who are concerned with or have wondered
about transactions vis a vis @strong{MySQL}, there is a ``@strong{MySQL}
way'' as we have outlined above. For those where safety is more important
than speed, we recommend them to use the @code{BDB} tables for all their
critical data. @xref{BDB}.
One final note: we are currently working on a safe replication schema
that we believe to be better than any commercial replication system we
know of. This system will work most reliably under the atomic
operations, non-transactional, paradigm. Stay tuned.
@node Missing Triggers, Missing Foreign Keys, Missing Transactions, Missing functions
@subsection Stored procedures and triggers
A stored procedure is a set of SQL commands that can be compiled and stored
in the server. Once this has been done, clients don't need to keep reissuing
the entire query but can refer to the stored procedure. This provides better
performance because the query has to be parsed only once and less information
needs to be sent between the server and the client. You can also raise the
conceptual level by having libraries of functions in the server.
A trigger is a stored procedure that is invoked when a particular event
occurs. For example, you can install a stored procedure that is triggered
each time a record is deleted from a transaction table and that automatically
deletes the corresponding customer from a customer table when all his
transactions are deleted.
The planned update language will be able to
handle stored procedures, but without triggers. Triggers usually slow
down everything, even queries for which they are not needed.
To see when @strong{MySQL} might get stored procedures, see @ref{TODO}.
@node Missing Foreign Keys, Missing Views, Missing Triggers, Missing functions
@subsection Foreign Keys
Note that foreign keys in SQL are not used to join tables, but are used
mostly for checking referential integrity. If you want to get results from
multiple tables from a @code{SELECT} statement, you do this by joining
tables!
@example
SELECT * from table1,table2 where table1.id = table2.id;
@end example
@xref{JOIN, , @code{JOIN}}. @xref{example-Foreign keys}.
The @code{FOREIGN KEY} syntax in @strong{MySQL} exists only for compatibility
with other SQL vendors' @code{CREATE TABLE} commands; it doesn't do
anything. The @code{FOREIGN KEY} syntax without @code{ON DELETE ...} is
mostly used for documentation purposes. Some ODBC applications may use this
to produce automatic @code{WHERE} clauses, but this is usually easy to
override. @code{FOREIGN KEY} is sometimes used as a constraint check, but
this check is unnecessary in practice if rows are inserted into the tables in
the right order. @strong{MySQL} only supports these clauses because some
applications require them to exist (regardless of whether or not they
work!).
In @strong{MySQL}, you can work around the problem of @code{ON DELETE
...} not being implemented by adding the appropriate @code{DELETE} statement to
an application when you delete records from a table that has a foreign key.
In practice this is as quick (in some cases quicker) and much more portable
than using foreign keys.
In the near future we will extend the @code{FOREIGN KEY} implementation so
that at least the information will be saved in the table specification file
and may be retrieved by @code{mysqldump} and ODBC.
@menu
* Broken Foreign KEY:: Reasons NOT to use foreign keys
@end menu
@node Broken Foreign KEY, , Missing Foreign Keys, Missing Foreign Keys
@subsubsection Reasons NOT to use foreign keys
There are so many problems with @code{FOREIGN KEY}s that we don't
know where to start:
@itemize @bullet
@item
Foreign keys make life very complicated, because the foreign key definitions
must be stored in a database and implementing them would destroy the whole
``nice approach'' of using files that can be moved, copied and removed.
@item
The speed impact is terrible for @code{INSERT} and @code{UPDATE} statements,
and in this case almost all @code{FOREIGN KEY} checks are useless because you
usually insert records in the right tables in the right order, anyway.
@item
There is also a need to hold locks on many more tables when updating one
table, because the side effects can cascade through the entire database. It's
MUCH faster to delete records from one table first and subsequently delete
them from the other tables.
@item
You can no longer restore a table by doing a full delete from
the table and then restoring all records (from a new source or from a backup).
@item
If you have foreign keys you can't dump and restore tables unless you do so
in a very specific order.
@item
It's very easy to do ``allowed'' circular definitions that make the
tables impossible to recreate each table with a single create statement,
even if the definition works and is usable.
@end itemize
The only nice aspect of @code{FOREIGN KEY} is that it gives ODBC and some
other client programs the ability to see how a table is connected and to use
this to show connection diagrams and to help in building applicatons.
@strong{MySQL} will soon store @code{FOREIGN KEY} definitions so that
a client can ask for and receive an answer how the original connection was
made. The current @file{.frm} file format does not have any place for it.
@node Missing Views, Missing comments, Missing Foreign Keys, Missing functions
@subsection Views
@strong{MySQL} doesn't support views, but this is on the TODO.
@node Missing comments, , Missing Views, Missing functions
@subsection @samp{--} as the start of a comment
Some other SQL databases use @samp{--} to start comments. @strong{MySQL}
has @samp{#} as the start comment character, even if the @code{mysql}
command line tool removes all lines that start with @samp{--}.
You can also use the C comment style @code{/* this is a comment */} with
@strong{MySQL}.
@xref{Comments}.
@strong{MySQL} 3.23.3 and above supports the @samp{--} comment style
only if the comment is followed by a space. This is because this
degenerate comment style has caused many problems with automatically
generated SQL queries that have used something like the following code,
where we automatically insert the value of the payment for
@code{!payment!}:
@example
UPDATE tbl_name SET credit=credit-!payment!
@end example
What do you think will happen when the value of @code{payment} is negative?
Because @code{1--1} is legal in SQL, we think it is terrible that
@samp{--} means start comment.
In @strong{MySQL} 3.23 you can however use: @code{1-- This is a comment}
The following discussing only concerns you if you are running an
@strong{MySQL} version earlier than 3.23:
If you have a SQL program in a text file that contains @samp{--} comments
you should use:
@example
shell> replace " --" " #" < text-file-with-funny-comments.sql \
| mysql database
@end example
instead of the usual:
@example
shell> mysql database < text-file-with-funny-comments.sql
@end example
You can also edit the command file ``in place'' to change the @samp{--}
comments to @samp{#} comments:
@example
shell> replace " --" " #" -- text-file-with-funny-comments.sql
@end example
Change them back with this command:
@example
shell> replace " #" " --" -- text-file-with-funny-comments.sql
@end example
@node Standards, Commit-rollback, Missing functions, Compatibility
@section What standards does MySQL follow?
Entry level SQL92. ODBC level 0-2.
@node Commit-rollback, , Standards, Compatibility
@section How to cope without @code{COMMIT}/@code{ROLLBACK}
The following mostly apply only for @code{ISAM}, @code{MyISAM} and
@code{HEAP} tables; If you only use transaction safe tables (@code{BDB}
tables) in an a update you can do @code{COMMIT} and @code{ROLLBACK} also
with @code{MySQL}. @xref{COMMIT}.
The problem with handling @code{COMMIT}-@code{ROLLBACK} efficiently with
the above table types would require a completely different table layout
than @strong{MySQL} uses today. The table type would also need extra
threads that do automatic cleanups on the tables and the disk usage
would be much higher. This would these table types about 2-4 times
slower than they are today.
For the moment, we are much more for implementing the SQL server
language (something like stored procedures). With this you would very
seldom really need @code{COMMIT}-@code{ROLLBACK.} This would also give much
better performance.
Loops that need transactions normally can be coded with the help of
@code{LOCK TABLES}, and you don't need cursors when you can update records
on the fly.
We at TcX had a greater need for a real fast database than a 100%
general database. Whenever we find a way to implement these features without
any speed loss, we will probably do it. For the moment, there are many more
important things to do. Check the TODO for how we prioritize things at
the moment. (Customers with higher levels of support can alter this, so
things may be reprioritized.)
The current problem is actually @code{ROLLBACK}. Without
@code{ROLLBACK}, you can do any kind of @code{COMMIT} action with
@code{LOCK TABLES}. To support @code{ROLLBACK} with the above table
types, @strong{MySQL} would have to be changed to store all old records
that were updated and revert everything back to the starting point if
@code{ROLLBACK} was issued. For simple cases, this isn't that hard to do
(the current @code{isamlog} could be used for this purpose), but it
would be much more difficult to implement @code{ROLLBACK} for
@code{ALTER/DROP/CREATE TABLE}.
To avoid using @code{ROLLBACK}, you can use the following strategy:
@enumerate
@item
Use @code{LOCK TABLES ...} to lock all the tables you want to access.
@item
Test conditions.
@item
Update if everything is okay.
@item
Use @code{UNLOCK TABLES} to release your locks.
@end enumerate
This is usually a much faster method than using transactions with possible
@code{ROLLBACK}s, although not always. The only situation this solution
doesn't handle is when someone kills the threads in the middle of an
update. In this case, all locks will be released but some of the updates may
not have been executed.
You can also use functions to update records in a single operation.
You can get a very efficient application by using the following techniques:
@itemize @bullet
@item
Modify fields relative to their current value
@item
Update only those fields that actually have changed
@end itemize
For example, when we are doing updates to some customer information, we
update only the customer data that have changed and test only that none of
the changed data, or data that depend on the changed data, have changed
compared to the original row. The test for changed data is done with the
@code{WHERE} clause in the @code{UPDATE} statement. If the record wasn't
updated, we give the client a message: "Some of the data you have changed
have been changed by another user". Then we show the old row versus the new
row in a window, so the user can decide which version of the customer record
he should use.
This gives us something that is similar to ``column locking'' but is actually
even better, because we only update some of the columns, using values that
are relative to their current values. This means that typical @code{UPDATE}
statements look something like these:
@example
UPDATE tablename SET pay_back=pay_back+'relative change';
UPDATE customer
SET
customer_date='current_date',
address='new address',
phone='new phone',
money_he_owes_us=money_he_owes_us+'new_money'
WHERE
customer_id=id AND address='old address' AND phone='old phone';
@end example
As you can see, this is very efficient and works even if another client has
changed the values in the @code{pay_back} or @code{money_he_owes_us} columns.
@findex mysql_insert_id()
@findex LAST_INSERT_ID()
In many cases, users have wanted @code{ROLLBACK} and/or @code{LOCK
TABLES} for the purpose of managing unique identifiers for some tables. This
can be handled much more efficiently by using an @code{AUTO_INCREMENT} column
and either the SQL function @code{LAST_INSERT_ID()} or the C API function
@code{mysql_insert_id()}. @xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@cindex Row-level locking
At MySQL AB, we have never had any need for row-level locking because we have
always been able to code around it. Some cases really need row
locking, but they are very few. If you want row-level locking, you
can use a flag column in the table and do something like this:
@example
UPDATE tbl_name SET row_flag=1 WHERE id=ID;
@end example
@strong{MySQL} returns 1 for the number of affected rows if the row was
found and @code{row_flag} wasn't already 1 in the original row.
You can think of it as @strong{MySQL} changed the above query to:
@example
UPDATE tbl_name SET row_flag=1 WHERE id=ID and row_flag <> 1;
@end example
@node Privilege system, Reference, Compatibility, Top
@chapter The MySQL access privilege system
@strong{MySQL} has an advanced but non-standard security/privilege
system. This section describes how it works.
@menu
* General security:: General security
* Security:: How to make @strong{MySQL} secure against crackers
* What Privileges:: What the privilege system does
* User names:: @strong{MySQL} user names and passwords
* Connecting:: Connecting to the @strong{MySQL} server
* Password security:: Keeping your password secure
* Privileges provided:: Privileges provided by @strong{MySQL}
* Privileges:: How the privilege system works
* Connection access:: Access control, stage 1: Connection verification
* Request access:: Access control, stage 2: Request verification
* Privilege changes:: When privilege changes take effect
* Default privileges:: Setting up the initial @strong{MySQL} privileges
* Adding users:: Adding new user privileges to @strong{MySQL}
* Passwords:: How to set up passwords
* Access denied:: Causes of @code{Access denied} errors
@end menu
@node General security, Security, Privilege system, Privilege system
@section General security
Anyone using @strong{MySQL} on a computer connected to the Internet
should read this section to avoid the most common security mistakes.
In discussing ``security'' we emphasize the necessity of fully protecting the
entire server host (not simply the @strong{MySQL} server) against all types
of applicable attacks: eavesdropping, altering, playback and Denial of
Service. We do not cover all aspects of availability and fault tolerance
here.
@strong{MySQL} uses Access Control Lists (ACLs) security for all
connections, queries, and other operations which a user may attempt to
perform. There is also some support for SSL encrypted connections
between @strong{MySQL} clients and servers. Many of the concepts
discussed here are not specific to @strong{MySQL} at all; the same
general ideas apply to almost all applications.
When running @strong{MySQL}, follow these guidelines whenever possible:
@itemize @bullet
@item
Learn the @strong{MySQL} access privilege system. The @code{GRANT} and
@code{REVOKE} commands are used for restricting access to @strong{MySQL}. Do
not grant any more privileges than necessary. Never grant privileges to all
hosts.
Checklist:
@itemize @bullet
@item
Try @code{mysql -u root}. If you are able to connect successfully to the
server without being asked for a password, you have problems. Any user (not
just root) can connect to your @strong{MySQL} server with full privileges!
Review the @strong{MySQL} installation instructions, paying particular
attention to the item about setting a @code{root} password.
@item
Use the command @code{SHOW GRANTS} and check to see who has access to
what. Remove those privileges which are not necessary using the @code{REVOKE}
command.
@end itemize
@item
Do not keep any plain-text passwords in your database. When your
computer becomes compromised, the intruder can take the full list of
passwords and use them. Instead use @code{MD5()} or another one-way
hashing function.
@item
Do not use passwords from dictionaries. There are special programs to
break them. Even passwords like ``xfish98'' are very bad. Much better is
``duag98'' which contains the same word ``fish'' but typed one key to the
left on a standard QWERTY keyboard. Another method is to use ``Mhall'' which
is taken from first characters of sentence ``Mary had a little lamb''. This
is easy to remember and type, but hard to guess for someone who does not know
it.
@item
Invest in a firewall. This protects from at least 50% of all types of
exploits in any software. Put @strong{MySQL} behind the firewall or in
a demilitarized zone (DMZ).
Checklist:
@itemize @bullet
@item
Try to scan your ports from the Internet using a tool such as
@code{nmap}. @strong{MySQL} uses port 3306 by default. This port should
be inaccessible from untrusted hosts. Another simple way to check whether or not
your @strong{MySQL} port is open is to type @code{telnet
server_host 3306} from some remote machine, where
@code{server_host} is the hostname of your @strong{MySQL}
server. If you get a connection and some garbage characters, the port is
open, and should be closed on your firewall or router, unless you really
have a good reason to keep it open. If @code{telnet} just hangs,
everything is OK, the port is blocked.
@end itemize
@item
Do not trust any data entered by your users. They can try to trick your
code by entering special or escaped character sequences in web forms,
URLs, or whatever application you have built. Be sure that your
application remains secure if user enters something like @code{; DROP
DATABASE mysql;}. This is an extreme example, but large security leaks
and data loss may occur as a result of hackers using similar techniques,
if you do not prepare for them.
Also remember to check numeric data. A common mistake is to protect only
strings. Sometimes people think that if a database contains only publicly
available data that it need not be protected. This is incorrect. At least
Denial-of-Service type attacks can be performed on such
databases. The simplest way to protect from this type of attack is to use
apostrophes around the numeric constants: @code{SELECT * FROM table
WHERE ID='234'} instead of @code{SELECT * FROM table WHERE ID=234}.
@strong{MySQL} automatically converts this string to a number and
meanwhile strips all non-numeric symbols from it.
Checklist:
@itemize @bullet
@item
All WWW applications:
@itemize @bullet
@item
Try to enter @samp{'} and @samp{"} in all your Web forms. If you get any kind
of @strong{MySQL} error, investigate the problem right away.
@item
Try to modify any dynamic URLs by adding @code{%22} (@samp{"}), @code{%23}
(@samp{#}) and @code{%27} (@samp{'}) in the URL.
@item
Try to modify datatypes in dynamic URLs from numeric ones to character
ones containing characters from previous example. Your application
should be safe against this and similar attacks.
@item
Try to enter characters, spaces, special symbols instead of numbers in
numeric fields. Your application should remove them before passing them to
@strong{MySQL} or your application should generate an error. Passing
unchecked values to @strong{MySQL} is very dangerous!
@item
Check data sizes before passing them to @strong{MySQL}.
@item
Consider having your application connect to the database using a
different user name than the one you use for administrative purposes. Do not give
your applications any more access privileges than what they need.
@end itemize
@item
Users of PHP:
@itemize @bullet
@item
Check out the @code{addslashes()} function.
@end itemize
@item
Users of @strong{MySQL} C API:
@itemize @bullet
@item
Check out the @code{mysql_escape()} API call.
@end itemize
@item
Users of @strong{MySQL}++:
@itemize @bullet
@item
Check out the @code{escape} and @code{quote} modifiers for query streams.
@end itemize
@item
Users of Perl DBI
@itemize @bullet
@item
Check out the @code{quote()} method.
@end itemize
@end itemize
@item
Do not transmit plain (unencrypted) data over the Internet. These data are
accessible to everyone who has the time and ability to intercept it and use
it for their own purposes. Instead, use an encrypted protocol such as SSL or
SSH. @strong{MySQL} supports internal SSL connections as of version 3.23.9.
SSH port-forwarding can be used to create an encrypted (and compressed)
tunnel for the communication.
@item
Learn to use the @code{tcpdump} and @code{strings} utilities. For most cases,
you can check whether or not @strong{MySQL} data streams are unencrypted
by issuing a command like the following:
@example
shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings
@end example
(This works under Linux and should work with small modifications under
other systems). Warning: If you do not see data this doesn't always
actually mean that it is encrypted. If you need high security, you should
consult with a security expert.
@end itemize
@node Security, What Privileges, General security, Privilege system
@section How to make MySQL secure against crackers
When you connect to a @strong{MySQL} server, you normally should use a
password. The password is not transmitted in clear text over the
connection.
All other information is transferred as text that can be read by anyone
that is able to watch the connection. If you are concerned about this,
you can use the compressed protocol (in @strong{MySQL} 3.22 and above)
to make things much harder. To make things even more secure you should
use @code{ssh} (see @uref{http://www.cs.hut.fi/ssh}). With this, you
can get an encrypted TCP/IP connection between a @strong{MySQL} server
and a @strong{MySQL} client.
To make a @strong{MySQL} system secure, you should strongly consider the
following suggestions:
@itemize @bullet
@item
Use passwords for all @strong{MySQL} users. Remember that anyone can log in
as any other person as simply as @code{mysql -u other_user db_name} if
@code{other_user} has no password. It is common behavior with client/server
applications that the client may specify any user name. You can change the
password of all users by editing the @code{mysql_install_db} script before
you run it, or only the password for the @strong{MySQL} @code{root} user like
this:
@example
shell> mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('new_password')
WHERE user='root';
mysql> FLUSH PRIVILEGES;
@end example
@item
Don't run the @strong{MySQL} daemon as the Unix @code{root} user.
It is very dangerous as any user with @code{FILE} privileges will be able to
create files
as @code{root} (e.g. @code{~root/.bashrc}). To prevent this
@code{mysqld} will refuse to run as @code{root} unless it is specified
directly via @code{--user=root} option.
@code{mysqld} can be run as any user instead. You can also create a new
Unix user @code{mysql} to make everything even more secure. If you run
@code{mysqld} as another Unix user, you don't need to change the
@code{root} user name in the @code{user} table, because @strong{MySQL}
user names have nothing to do with Unix user names. You can edit the
@code{mysql.server} script to start @code{mysqld} as another Unix user.
Normally this is done with the @code{su} command. For more details, see
@ref{Changing MySQL user, , Changing @strong{MySQL} user}.
@item
If you put a password for the Unix @code{root} user in the @code{mysql.server}
script, make sure this script is readable only by @code{root}.
@item
Check that the Unix user that @code{mysqld} runs as is the only user with
read/write privileges in the database directories.
@item
On Unix platforms, do not run @code{mysqld} as root unless you really
need to. Consider creating a user named @code{mysql} for that purpose.
@item
Don't give the @strong{process} privilege to all users. The output of
@code{mysqladmin processlist} shows the text of the currently executing
queries, so any user who is allowed to execute that command might be able to
see if another user issues an @code{UPDATE user SET
password=PASSWORD('not_secure')} query.
@code{mysqld} reserves an extra connection for users who have the
@strong{process} privilege, so that a @strong{MySQL} @code{root} user can log
in and check things even if all normal connections are in use.
@item
Don't give the @strong{file} privilege to all users. Any user that has this
privilege can write a file anywhere in the file system with the privileges of
the @code{mysqld} daemon! To make this a bit safer, all files generated with
@code{SELECT ... INTO OUTFILE} are readable to everyone, and you can't
overwrite existing files.
@tindex /etc/passwd
The @strong{file} privilege may also be used to read any file accessible
to the Unix user that the server runs as. This could be abused, for example,
by using @code{LOAD DATA} to load @file{/etc/passwd} into a table, which
can then be read with @code{SELECT}.
@item
If you don't trust your DNS, you should use IP numbers instead of hostnames
in the grant tables. In principle, the @code{--secure} option to
@code{mysqld} should make hostnames safe. In any case, you should be very
careful about creating grant table entries using hostname values that
contain wildcards!
@end itemize
The following @code{mysqld} options affect networking security:
@table @code
@item --secure
IP numbers returned by the @code{gethostbyname()} system call are checked to
make sure they resolve back to the original hostname. This makes it harder
for someone on the outside to get access by pretending to be another host. This
option also adds some sanity checks of hostnames. The option is turned off
by default in @strong{MySQL} 3.21 because sometimes it takes a long time to
perform backward resolutions. @strong{MySQL} 3.22 caches hostnames and has
this option enabled by default.
@item --skip-grant-tables
This option causes the server not to use the privilege system at all. This
gives everyone @emph{full access} to all databases! (You can tell a running
server to start using the grant tables again by executing @code{mysqladmin
flush-privileges} or @code{mysqladmin reload}.)
@item --skip-name-resolve
Hostnames are not resolved. All @code{Host} column values in the grant
tables must be IP numbers or @code{localhost}.
@item --skip-networking
Don't allow TCP/IP connections over the network. All connections to
@code{mysqld} must be made via Unix sockets. This option is unsuitable for
systems that use MIT-pthreads, because the MIT-pthreads package doesn't
support Unix sockets.
@end table
@node What Privileges, User names, Security, Privilege system
@section What the privilege system does
The primary function of the @strong{MySQL} privilege system is to
authenticate a user connecting from a given host, and to associate that user
with privileges on a database such as
@strong{select}, @strong{insert}, @strong{update} and @strong{delete}.
Additional functionality includes the ability to have an anonymous user and
to grant privileges for @strong{MySQL}-specific functions such as @code{LOAD
DATA INFILE} and administrative operations.
@node User names, Connecting, What Privileges, Privilege system
@section MySQL user names and passwords
There are several distinctions between the way user names and passwords are
used by @strong{MySQL}, and the way they are used by Unix or Windows:
@itemize @bullet
@item
User names, as used by @strong{MySQL} for authentication purposes, have
nothing to do with Unix user names (login names) or Windows user names. Most
@strong{MySQL} clients by default try to log in using the current Unix user
name as the @strong{MySQL} user name, but that is for convenience only.
Client programs allow a different name to be specified with the @code{-u} or
@code{--user} options. This means that you can't make a database secure in
any way unless all @strong{MySQL} user names have passwords. Anyone may
attempt to connect to the server using any name, and they will succeed if
they specify any name that doesn't have a password.
@item
@strong{MySQL} user names can be up to 16 characters long; Unix user names
typically are limited to 8 characters.
@item
@strong{MySQL} passwords have nothing to do with Unix passwords. There is no
necessary connection between the password you use to log in to a Unix machine
and the password you use to access a database on that machine.
@item
@strong{MySQL} encrypts passwords using a different algorithm than the one
used during the Unix login process. See the descriptions of the
@code{PASSWORD()} and @code{ENCRYPT()} functions in @ref{Miscellaneous
functions}.
@end itemize
@node Connecting, Password security, User names, Privilege system
@section Connecting to the MySQL server
@strong{MySQL} client programs generally require that you specify connection
parameters when you want to access a @strong{MySQL} server: the host you want
to connect to, your user name and your password. For example, the
@code{mysql} client can be started like this (optional arguments are enclosed
between @samp{[} and @samp{]}):
@example
shell> mysql [-h host_name] [-u user_name] [-pyour_pass]
@end example
Alternate forms of the @code{-h}, @code{-u} and @code{-p} options are
@code{--host=host_name}, @code{--user=user_name} and
@code{--password=your_pass}. Note that there is @emph{no space} between
@code{-p} or @code{--password=} and the password following it.
@strong{NOTE:} Specifying a password on the command line is not secure!
Any user on your system may then find out your password by typing a command
like: @code{ps auxww}. @xref{Option files}.
@code{mysql} uses default values for connection parameters that are missing
from the command line:
@itemize @bullet
@item
The default hostname is @code{localhost}.
@item
The default user name is your Unix login name.
@item
No password is supplied if @code{-p} is missing.
@end itemize
Thus, for a Unix user @code{joe}, the following commands are equivalent:
@example
shell> mysql -h localhost -u joe
shell> mysql -h localhost
shell> mysql -u joe
shell> mysql
@end example
Other @strong{MySQL} clients behave similarly.
On Unix systems, you can specify different default values to be used when you
make a connection, so that you need not enter them on the command line each
time you invoke a client program. This can be done in a couple of ways:
@itemize @bullet
@item
@tindex .my.cnf file
You can specify connection parameters in the @code{[client]} section of the
@file{.my.cnf} configuration file in your home directory. The relevant
section of the file might look like this:
@example
[client]
host=host_name
user=user_name
password=your_pass
@end example
@xref{Option files}.
@item
@tindex MYSQL_HOST environment variable
@tindex Environment variable, MYSQL_HOST
@tindex MYSQL_PWD environment variable
@tindex Environment variable, MYSQL_PWD
@tindex USER environment variable
@tindex Environment variable, USER
You can specify connection parameters using environment variables. The
host can be specified for @code{mysql} using @code{MYSQL_HOST}. The
@strong{MySQL} user name can be specified using @code{USER} (this is for
Windows only). The password can be specified using @code{MYSQL_PWD}
(but this is insecure; see next section). @xref{Environment variables}.
@end itemize
@node Password security, Privileges provided, Connecting, Privilege system
@section Keeping your password secure
It is inadvisable to specify your password in a way that exposes it to
discovery by other users. The methods you can use to specify your password
when you run client programs are listed below, along with an assessment of
the risks of each method:
@itemize @bullet
@item
Use a @code{-pyour_pass} or @code{--password=your_pass} option on the command
line. This is convenient but insecure, because your password becomes visible
to system status programs (such as @code{ps}) that may be invoked by other
users to display command lines. (@strong{MySQL} clients typically overwrite
the command line argument with zeroes during their initialization sequence,
but there is still a brief interval during which the value is visible.)
@item
Use a @code{-p} or @code{--password} option (with no @code{your_pass} value
specified). In this case, the client program solicits the password from
the terminal:
@example
shell> mysql -u user_name -p
Enter password: ********
@end example
The client echoes @samp{*} characters to the terminal as you enter your
password so that onlookers cannot see it.
It is more secure to enter your password this way than to specify it on the
command line because it is not visible to other users. However, this method
of entering a password is suitable only for programs that you run
interactively. If you want to invoke a client from a script that runs
non-interactively, there is no opportunity to enter the password from the
terminal. On some systems, you may even find that the first line of your
script is read and interpreted (incorrectly) as your password!
@item
@tindex .my.cnf file
Store your password in a configuration file. For example, you can list your
password in the @code{[client]} section of the @file{.my.cnf} file in your
home directory:
@example
[client]
password=your_pass
@end example
If you store your password in @file{.my.cnf}, the file should not be group or
world readable or writable. Make sure the file's access mode is @code{400}
or @code{600}.
@xref{Option files}.
@item
You can store your password in the @code{MYSQL_PWD} environment variable, but
this method must be considered extremely insecure and should not be used.
Some versions of @code{ps} include an option to display the environment of
running processes; your password will be in plain sight for all to see if
you set @code{MYSQL_PWD}. Even on systems without such a version of
@code{ps}, it is unwise to assume there is no other method to observe process
environments. @xref{Environment variables}.
@end itemize
All in all, the safest methods are to have the client program prompt for the
password or to specify the password in a properly-protected @file{.my.cnf}
file.
@node Privileges provided, Privileges, Password security, Privilege system
@section Privileges provided by MySQL
Privilege information is stored in the @code{user}, @code{db}, @code{host},
@code{tables_priv} and @code{columns_priv} tables in the @code{mysql}
database (that is, in the database named @code{mysql}). The @strong{MySQL}
server reads the contents of these tables when it starts up and under the
circumstances indicated in @ref{Privilege changes}.
The names used in this manual to refer to the privileges provided by
@strong{MySQL} are shown below, along with the table column name associated
with each privilege in the grant tables and the context in which the
privilege applies:
@multitable @columnfractions .15 .25 .6
@item @strong{Privilege} @tab @strong{Column} @tab @strong{Context}
@item @strong{select} @tab @code{Select_priv} @tab tables
@item @strong{insert} @tab @code{Insert_priv} @tab tables
@item @strong{update} @tab @code{Update_priv} @tab tables
@item @strong{delete} @tab @code{Delete_priv} @tab tables
@item @strong{index} @tab @code{Index_priv} @tab tables
@item @strong{alter} @tab @code{Alter_priv} @tab tables
@item @strong{create} @tab @code{Create_priv} @tab databases, tables or indexes
@item @strong{drop} @tab @code{Drop_priv} @tab databases or tables
@item @strong{grant} @tab @code{Grant_priv} @tab databases or tables
@item @strong{references} @tab @code{References_priv} @tab databases or tables
@item @strong{reload} @tab @code{Reload_priv} @tab server administration
@item @strong{shutdown} @tab @code{Shutdown_priv} @tab server administration
@item @strong{process} @tab @code{Process_priv} @tab server administration
@item @strong{file} @tab @code{File_priv} @tab file access on server
@end multitable
The @strong{select}, @strong{insert}, @strong{update} and @strong{delete}
privileges allow you to perform operations on rows in existing tables in
a database.
@code{SELECT} statements require the @strong{select} privilege only if they
actually retrieve rows from a table. You can execute certain @code{SELECT}
statements even without permission to access any of the databases on the
server. For example, you could use the @code{mysql} client as a simple
calculator:
@example
mysql> SELECT 1+1;
mysql> SELECT PI()*2;
@end example
The @strong{index} privilege allows you to create or drop (remove) indexes.
The @strong{alter} privilege allows you to use @code{ALTER TABLE}.
The @strong{create} and @strong{drop} privileges allow you to create new
databases and tables, or to drop (remove) existing databases and tables.
Note that if you grant the @strong{drop} privilege for the @code{mysql}
database to a user, that user can drop the database in which the
@strong{MySQL} access privileges are stored!
The @strong{grant} privilege allows you to give to other users those
privileges you yourself possess.
The @strong{file} privilege gives you permission to read and write files on
the server using the @code{LOAD DATA INFILE} and @code{SELECT ... INTO
OUTFILE} statements. Any user to whom this privilege is granted can read or
write any file that the @strong{MySQL} server can read or write.
The remaining privileges are used for administrative operations, which are
performed using the @code{mysqladmin} program. The table below shows which
@code{mysqladmin} commands each administrative privilege allows you to
execute:
@multitable @columnfractions .15 .85
@item @strong{Privilege} @tab @strong{Commands permitted to privilege holders}
@item @strong{reload} @tab @code{reload}, @code{refresh},
@code{flush-privileges},
@code{flush-hosts}, @code{flush-logs}, @code{flush-tables}
@item @strong{shutdown} @tab @code{shutdown}
@item @strong{process} @tab @code{processlist}, @code{kill}
@end multitable
The @code{reload} command tells the server to reread the grant tables. The
@code{refresh} command flushes all tables and opens and closes the log
files. @code{flush-privileges} is a synonym for @code{reload}. The other
@code{flush-*} commands perform functions similar to @code{refresh} but are
more limited in scope, and may be preferable in some instances. For example,
if you want to flush just the log files, @code{flush-logs} is a better choice
than @code{refresh}.
The @code{shutdown} command shuts down the server.
The @code{processlist} command displays information about the threads
executing within the server. The @code{kill} command kills server threads.
You can always display or kill your own threads, but you need the
@strong{process} privilege to display or kill threads initiated by other
users.
It is a good idea in general to grant privileges only to those users who need
them, but you should exercise particular caution in granting certain
privileges:
@itemize @bullet
@item
The @strong{grant} privilege allows users to give away their privileges to
other users. Two users with different privileges and with the @strong{grant}
privilege are able to combine privileges.
@item
The @strong{alter} privilege may be used to subvert the privilege system
by renaming tables.
@item
The @strong{file} privilege can be abused to read any world-readable file on
the server into a database table, the contents of which can then be
accessed using @code{SELECT}. This includes the contents of all databases
hosted by the server!
@item
The @strong{shutdown} privilege can be abused to deny service to other
users entirely, by terminating the server.
@item
The @strong{process} privilege can be used to view the plain text of
currently executing queries, including queries that set or change passwords.
@item
Privileges on the @code{mysql} database can be used to change passwords and
other access privilege information. (Passwords are stored encrypted, so a
malicious user cannot simply read them. However, with sufficient privileges,
that same user can replace a password with a different one.)
@end itemize
There are some things that you cannot do with the @strong{MySQL}
privilege system:
@itemize @bullet
@item
You cannot explicitly specify that a given user should be denied access.
That is, you cannot explicitly match a user and then refuse the connection.
@item
You cannot specify that a user has privileges to create or drop tables
in a database but not to create or drop the database itself.
@end itemize
@node Privileges, Connection access, Privileges provided, Privilege system
@section How the privilege system works
The @strong{MySQL} privilege system ensures that all users may do exactly the
things that they are supposed to be allowed to do. When you connect to a
@strong{MySQL} server, your identity is determined by @strong{the host from
which you connect} and @strong{the user name you specify}. The system grants
privileges according to your identity and @strong{what you want to do}.
@strong{MySQL} considers both your hostname and user name in identifying you
because there is little reason to assume that a given user name belongs to
the same person everywhere on the Internet. For example, the user
@code{bill} who connects from @code{whitehouse.gov} need not be the same
person as the user @code{bill} who connects from @code{microsoft.com}.
@strong{MySQL} handles this by allowing you to distinguish users on different
hosts that happen to have the same name: you can grant @code{bill} one set
of privileges for connections from @code{whitehouse.gov}, and a different set
of privileges for connections from @code{microsoft.com}.
@strong{MySQL} access control involves two stages:
@itemize @bullet
@item
Stage 1: The server checks whether or not you are even allowed to connect.
@item
Stage 2: Assuming you can connect, the server checks each request you issue
to see whether or not you have sufficient privileges to perform it. For
example, if you try to select rows from a table in a database or drop a table
from the database, the server makes sure you have the @strong{select}
privilege for the table or the @strong{drop} privilege for the database.
@end itemize
The server uses the @code{user}, @code{db} and @code{host} tables in the
@code{mysql} database at both stages of access control. The fields in these
grant tables are shown below:
@multitable @columnfractions .2 .25 .25 .25
@item @strong{Table name} @tab @code{user} @tab @code{db} @tab @code{host}
@item @strong{Scope fields} @tab @code{Host} @tab @code{Host} @tab @code{Host}
@item @tab @code{User} @tab @code{Db} @tab @code{Db}
@item @tab @code{Password} @tab @code{User} @tab
@item @strong{Privilege fields} @tab @code{Select_priv} @tab @code{Select_priv} @tab @code{Select_priv}
@item @tab @code{Insert_priv} @tab @code{Insert_priv} @tab @code{Insert_priv}
@item @tab @code{Update_priv} @tab @code{Update_priv} @tab @code{Update_priv}
@item @tab @code{Delete_priv} @tab @code{Delete_priv} @tab @code{Delete_priv}
@item @tab @code{Index_priv} @tab @code{Index_priv} @tab @code{Index_priv}
@item @tab @code{Alter_priv} @tab @code{Alter_priv} @tab @code{Alter_priv}
@item @tab @code{Create_priv} @tab @code{Create_priv} @tab @code{Create_priv}
@item @tab @code{Drop_priv} @tab @code{Drop_priv} @tab @code{Drop_priv}
@item @tab @code{Grant_priv} @tab @code{Grant_priv} @tab @code{Grant_priv}
@item @tab @code{References_priv} @tab @tab
@item @tab @code{Reload_priv} @tab @tab
@item @tab @code{Shutdown_priv} @tab @tab
@item @tab @code{Process_priv} @tab @tab
@item @tab @code{File_priv} @tab @tab
@end multitable
For the second stage of access control (request verification), the server
may, if the request involves tables, additionally consult the
@code{tables_priv} and @code{columns_priv} tables. The fields in these
tables are shown below:
@multitable @columnfractions .2 .25 .25
@item @strong{Table name} @tab @code{tables_priv} @tab @code{columns_priv}
@item @strong{Scope fields} @tab @code{Host} @tab @code{Host}
@item @tab @code{Db} @tab @code{Db}
@item @tab @code{User} @tab @code{User}
@item @tab @code{Table_name} @tab @code{Table_name}
@item @tab @tab @code{Column_name}
@item @strong{Privilege fields} @tab @code{Table_priv} @tab @code{Column_priv}
@item @tab @code{Column_priv} @tab
@item @strong{Other fields} @tab @code{Timestamp} @tab @code{Timestamp}
@item @tab @code{Grantor} @tab
@end multitable
Each grant table contains scope fields and privilege fields.
Scope fields determine the scope of each entry in the tables, i.e., the
context in which the entry applies. For example, a @code{user} table entry
with @code{Host} and @code{User} values of @code{'thomas.loc.gov'} and
@code{'bob'} would be used for authenticating connections made to the server
by @code{bob} from the host @code{thomas.loc.gov}. Similarly, a @code{db}
table entry with @code{Host}, @code{User} and @code{Db} fields of
@code{'thomas.loc.gov'}, @code{'bob'} and @code{'reports'} would be used when
@code{bob} connects from the host @code{thomas.loc.gov} to access the
@code{reports} database. The @code{tables_priv} and @code{columns_priv}
tables contain scope fields indicating tables or table/column combinations
to which each entry applies.
@cindex Case sensitivity, in access checking
For access-checking purposes, comparisons of @code{Host} values are
case insensitive. @code{User}, @code{Password}, @code{Db} and
@code{Table_name} values are case sensitive.
@code{Column_name} values are case insensitive in @strong{MySQL} 3.22.12
or later.
Privilege fields indicate the privileges granted by a table entry, that is,
what operations can be performed. The server combines the information in the
various grant tables to form a complete description of a user's privileges.
The rules used to do this are described in @ref{Request access}.
Scope fields are strings, declared as shown below; the default value for
each is the empty string:
@multitable @columnfractions .15 .15 .7
@item @strong{Field name} @tab @strong{Type}
@item @code{Host} @tab @code{CHAR(60)}
@item @code{User} @tab @code{CHAR(16)}
@item @code{Password} @tab @code{CHAR(16)}
@item @code{Db} @tab @code{CHAR(64)} @tab (@code{CHAR(60)} for the
@code{tables_priv} and @code{columns_priv} tables)
@item @code{Table_name} @tab @code{CHAR(60)}
@item @code{Column_name} @tab @code{CHAR(60)}
@end multitable
In the @code{user}, @code{db} and @code{host} tables,
all privilege fields are declared as @code{ENUM('N','Y')} --- each can have a
value of @code{'N'} or @code{'Y'}, and the default value is @code{'N'}.
In the @code{tables_priv} and @code{columns_priv} tables, the privilege
fields are declared as @code{SET} fields:
@multitable @columnfractions .2 .2 .6
@item @strong{Table name} @tab @strong{Field name} @tab @strong{Possible set elements}
@item @code{tables_priv} @tab @code{Table_priv} @tab @code{'Select', 'Insert',
'Update', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter'}
@item @code{tables_priv} @tab @code{Column_priv} @tab @code{'Select', 'Insert',
'Update', 'References'}
@item @code{columns_priv} @tab @code{Column_priv} @tab @code{'Select', 'Insert',
'Update', 'References'}
@end multitable
Briefly, the server uses the grant tables like this:
@itemize @bullet
@item
The @code{user} table scope fields determine whether to allow or reject
incoming connections. For allowed connections, any privileges granted in
the @code{user} table indicate the user's global (superuser) privileges.
These privileges apply to @strong{all} databases on the server.
@item
The @code{db} and @code{host} tables are used together:
@itemize @minus
@item
The @code{db} table scope fields determine which users can access which
databases from which hosts. The privilege fields determine which operations
are allowed.
@item
The @code{host} table is used as an extension of the @code{db} table when you
want a given @code{db} table entry to apply to several hosts. For example,
if you want a user to be able to use a database from several hosts in
your network, leave the @code{Host} value empty in the user's @code{db} table
entry, then populate the @code{host} table with an entry for each of those
hosts. This mechanism is described more detail in @ref{Request access}.
@end itemize
@item
The @code{tables_priv} and @code{columns_priv} tables are similar to
the @code{db} table, but are more fine-grained: they apply at the
table and column level rather than at the database level.
@end itemize
Note that administrative privileges (@strong{reload}, @strong{shutdown},
etc.) are specified only in the @code{user} table. This is because
administrative operations are operations on the server itself and are not
database-specific, so there is no reason to list such privileges in the
other grant tables. In fact, only the @code{user} table need
be consulted to determine whether or not you can perform an administrative
operation.
The @strong{file} privilege is specified only in the @code{user} table, too.
It is not an administrative privilege as such, but your ability to read or
write files on the server host is independent of the database you are
accessing.
The @code{mysqld} server reads the contents of the grant tables once, when it
starts up. Changes to the grant tables take effect as indicated in
@ref{Privilege changes}.
When you modify the contents of the grant tables, it is a good idea to make
sure that your changes set up privileges the way you want. For help in
diagnosing problems, see @ref{Access denied}. For advice on security issues,
@ref{Security}.
A useful
diagnostic tool is the @code{mysqlaccess} script, which Yves Carlier has
provided for the @strong{MySQL} distribution. Invoke @code{mysqlaccess} with
the @code{--help} option to find out how it works.
Note that @code{mysqlaccess} checks access using only the @code{user},
@code{db} and @code{host} tables. It does not check table- or column-level
privileges.
@node Connection access, Request access, Privileges, Privilege system
@section Access control, stage 1: Connection verification
When you attempt to connect to a @strong{MySQL} server, the server accepts or
rejects the connection based on your identity and whether or not you can
verify your identity by supplying the correct password. If not, the server
denies access to you completely. Otherwise, the server accepts the
connection, then enters stage 2 and waits for requests.
Your identity is based on two pieces of information:
@itemize @bullet
@item
The host from which you connect
@item
Your @strong{MySQL} user name
@end itemize
Identity checking is performed using the three @code{user} table scope fields
(@code{Host}, @code{User} and @code{Password}). The server accepts the
connection only if a @code{user} table entry matches your hostname and user
name, and you supply the correct password.
Values in the @code{user} table scope fields may be specified as follows:
@itemize @bullet
@item
A @code{Host} value may be a hostname or an IP number, or @code{'localhost'}
to indicate the local host.
@item
@cindex Wildcards, in @code{mysql.user} table
You can use the wildcard characters @samp{%} and @samp{_} in the @code{Host}
field.
@item
A @code{Host} value of @code{'%'} matches any hostname. A blank @code{Host}
value is equivalent to @code{'%'}. Note that these values match @emph{any
host that can create a connection to your server!}
@cindex Netmask notation, in @code{mysql.user} table
@item
As of MySQL 3.23, for @code{Host} values specified as IP numbers, you
can specify a netmask indicating how many address bits to use for the
network number. For example:
@example
GRANT ALL PRIVILEGES on db.* to david@'192.58.197.0/255.255.255.0';
@end example
This will allow everyone to connect from an IP where the following is true:
@example
user_ip & netmask = host_ip.
@end example
In the above example all IP:s in the interval 192.58.197.0 -
192.58.197.255 can connect to the @strong{MySQL} server.
@item
@cindex Anonymous user
Wildcard characters are not allowed in the @code{User} field, but you can
specify a blank value, which matches any name. If the @code{user} table
entry that matches an incoming connection has a blank user name, the user is
considered to be the anonymous user (the user with no name), rather than the
name that the client actually specified. This means that a blank user name
is used for all further access checking for the duration of the connection
(that is, during stage 2).
@item
The @code{Password} field can be blank. This does not mean that any password
matches, it means the user must connect without specifying a password.
@end itemize
@findex PASSWORD()
Non-blank @code{Password} values represent encrypted passwords.
@strong{MySQL} does not store passwords in plaintext form for anyone to see.
Rather, the password supplied by a user who is attempting to connect is
encrypted (using the @code{PASSWORD()} function) and compared to the
already-encrypted version stored in the @code{user} table. If they match,
the password is correct.
The examples below show how various combinations of @code{Host} and
@code{User} values in @code{user} table entries apply to incoming
connections:
@multitable @columnfractions .25 .15 .60
@item @code{Host} @strong{value} @tab @code{User} @strong{value} @tab @strong{Connections matched by entry}
@item @code{'thomas.loc.gov'} @tab @code{'fred'} @tab @code{fred}, connecting from @code{thomas.loc.gov}
@item @code{'thomas.loc.gov'} @tab @code{''} @tab Any user, connecting from @code{thomas.loc.gov}
@item @code{'%'} @tab @code{'fred'} @tab @code{fred}, connecting from any host
@item @code{'%'} @tab @code{''} @tab Any user, connecting from any host
@item @code{'%.loc.gov'} @tab @code{'fred'} @tab @code{fred}, connecting from any host in the @code{loc.gov} domain
@item @code{'x.y.%'} @tab @code{'fred'} @tab @code{fred}, connecting from @code{x.y.net}, @code{x.y.com},@code{x.y.edu}, etc. (this is probably not useful)
@item @code{'144.155.166.177'} @tab @code{'fred'} @tab @code{fred}, connecting from the host with IP address @code{144.155.166.177}
@item @code{'144.155.166.%'} @tab @code{'fred'} @tab @code{fred}, connecting from any host in the @code{144.155.166} class C subnet
@item @code{'144.155.166.0/24'} @tab @code{'fred'} @tab Same as previous example
@end multitable
Because you can use IP wildcard values in the @code{Host} field (e.g.,
@code{'144.155.166.%'} to match every host on a subnet), there is the
possibility that someone might try to exploit this capability by naming a
host @code{144.155.166.somewhere.com}. To foil such attempts, @strong{MySQL}
disallows matching on hostnames that start with digits and a dot. Thus, if
you have a host named something like @code{1.2.foo.com}, its name will never
match the @code{Host} column of the grant tables. Only an IP number can
match an IP wildcard value.
An incoming connection may be matched by more than one entry in the
@code{user} table. For example, a connection from @code{thomas.loc.gov} by
@code{fred} would be matched by several of the entries just shown above. How
does the server choose which entry to use if more than one matches? The
server resolves this question by sorting the @code{user} table after reading
it at startup time, then looking through the entries in sorted order when a
user attempts to connect. The first matching entry is the one that is used.
@code{user} table sorting works as follows. Suppose the @code{user} table
looks like this:
@example
+-----------+----------+-
| Host | User | ...
+-----------+----------+-
| % | root | ...
| % | jeffrey | ...
| localhost | root | ...
| localhost | | ...
+-----------+----------+-
@end example
When the server reads in the table, it orders the entries with the
most-specific @code{Host} values first (@code{'%'} in the @code{Host} column
means ``any host'' and is least specific). Entries with the same @code{Host}
value are ordered with the most-specific @code{User} values first (a blank
@code{User} value means ``any user'' and is least specific). The resulting
sorted @code{user} table looks like this:
@example
+-----------+----------+-
| Host | User | ...
+-----------+----------+-
| localhost | root | ...
| localhost | | ...
| % | jeffrey | ...
| % | root | ...
+-----------+----------+-
@end example
@cindex Grant tables, sorting
@cindex Sorting, grant tables
@cindex @code{user} table, sorting
When a connection is attempted, the server looks through the sorted entries
and uses the first match found. For a connection from @code{localhost} by
@code{jeffrey}, the entries with @code{'localhost'} in the @code{Host} column
match first. Of those, the entry with the blank user name matches both the
connecting hostname and user name. (The @code{'%'/'jeffrey'} entry would
have matched, too, but it is not the first match in the table.)
Here is another example. Suppose the @code{user} table looks like this:
@example
+----------------+----------+-
| Host | User | ...
+----------------+----------+-
| % | jeffrey | ...
| thomas.loc.gov | | ...
+----------------+----------+-
@end example
The sorted table looks like this:
@example
+----------------+----------+-
| Host | User | ...
+----------------+----------+-
| thomas.loc.gov | | ...
| % | jeffrey | ...
+----------------+----------+-
@end example
A connection from @code{thomas.loc.gov} by @code{jeffrey} is matched by the
first entry, whereas a connection from @code{whitehouse.gov} by
@code{jeffrey} is matched by the second.
A common misconception is to think that for a given user name, all entries
that explicitly name that user will be used first when the server attempts to
find a match for the connection. This is simply not true. The previous
example illustrates this, where a connection from @code{thomas.loc.gov} by
@code{jeffrey} is first matched not by the entry containing @code{'jeffrey'}
as the @code{User} field value, but by the entry with no user name!
If you have problems connecting to the server, print out the @code{user}
table and sort it by hand to see where the first match is being made.
@node Request access, Privilege changes, Connection access, Privilege system
@section Access control, stage 2: Request verification
Once you establish a connection, the server enters stage 2. For each request
that comes in on the connection, the server checks whether you have
sufficient privileges to perform it, based on the type of operation you wish
to perform. This is where the privilege fields in the grant tables come into
play. These privileges can come from any of the @code{user}, @code{db},
@code{host}, @code{tables_priv} or @code{columns_priv} tables. The grant
tables are manipulated with @code{GRANT} and @code{REVOKE} commands.
@xref{GRANT, , @code{GRANT}}. (You may find it helpful to refer to
@ref{Privileges}, which lists the fields present in each of the grant
tables.)
The @code{user} table grants privileges that are assigned to you on a global
basis and that apply no matter what the current database is. For example, if
the @code{user} table grants you the @strong{delete} privilege, you can
delete rows from any database on the server host! In other words,
@code{user} table privileges are superuser privileges. It is wise to grant
privileges in the @code{user} table only to superusers such as server or
database administrators. For other users, you should leave the privileges
in the @code{user} table set to @code{'N'} and grant privileges on a
database-specific basis only, using the @code{db} and @code{host} tables.
@cindex Anonymous user
@cindex Wildcards, in @code{mysql.db} table
@cindex Wildcards, in @code{mysql.host} table
The @code{db} and @code{host} tables grant database-specific privileges.
Values in the scope fields may be specified as follows:
@itemize @bullet
@item
The
wildcard characters @samp{%} and @samp{_} can be used in the @code{Host} and
@code{Db} fields of either table.
@item
A @code{'%'} @code{Host} value in the @code{db} table means ``any host.'' A
blank @code{Host} value in the @code{db} table means ``consult the
@code{host} table for further information.''
@item
A @code{'%'} or blank @code{Host} value in the @code{host} table means ``any
host.''
@item
A @code{'%'} or blank @code{Db} value in either table means ``any database.''
@item
A blank @code{User} value in either table matches the anonymous user.
@end itemize
@cindex Grant tables, sorting
@cindex Sorting, grant tables
@cindex @code{db} table, sorting
@cindex @code{host} table, sorting
The @code{db} and @code{host} tables are read in and sorted when the server
starts up (at the same time that it reads the @code{user} table). The
@code{db} table is sorted on the @code{Host}, @code{Db} and @code{User} scope
fields, and the @code{host} table is sorted on the @code{Host} and @code{Db}
scope fields. As with the @code{user} table, sorting puts the most-specific
values first and least-specific values last, and when the server looks for
matching entries, it uses the first match that it finds.
@cindex Wildcards, in @code{mysql.tables_priv} table
@cindex Wildcards, in @code{mysql.columns_priv} table
The @code{tables_priv} and @code{columns_priv} tables grant table- and
column-specific privileges. Values in the scope fields may be specified as
follows:
@itemize @bullet
@item
The wildcard characters @samp{%} and @samp{_}
can be used in the @code{Host} field of either table.
@item
A @code{'%'} or blank @code{Host} value in either table means ``any host.''
@item
The @code{Db}, @code{Table_name} and @code{Column_name} fields cannot contain
wildcards or be blank in either table.
@end itemize
The @code{tables_priv} and @code{columns_priv} tables are sorted on
the @code{Host}, @code{Db} and @code{User} fields. This is similar to
@code{db} table sorting, although the sorting is simpler because
only the @code{Host} field may contain wildcards.
The request verification process is described below. (If you are familiar
with the access-checking source code, you will notice that the description
here differs slightly from the algorithm used in the code. The description
is equivalent to what the code actually does; it differs only to make the
explanation simpler.)
For administrative requests (@strong{shutdown}, @strong{reload}, etc.), the
server checks only the @code{user} table entry, because that is the only table
that specifies administrative privileges. Access is granted if the entry
allows the requested operation and denied otherwise. For example, if you
want to execute @code{mysqladmin shutdown} but your @code{user} table entry
doesn't grant the @strong{shutdown} privilege to you, access is denied
without even checking the @code{db} or @code{host} tables. (They
contain no @code{Shutdown_priv} column, so there is no need to do so.)
For database-related requests (@strong{insert}, @strong{update}, etc.), the
server first checks the user's global (superuser) privileges by looking in
the @code{user} table entry. If the entry allows the requested operation,
access is granted. If the global privileges in the @code{user} table are
insufficient, the server determines the user's database-specific privileges
by checking the @code{db} and @code{host} tables:
@enumerate
@item
The server looks in the @code{db} table for a match on the @code{Host},
@code{Db} and @code{User} fields. The @code{Host} and @code{User} fields are
matched to the connecting user's hostname and @strong{MySQL} user name. The
@code{Db} field is matched to the database the user wants to access. If
there is no entry for the @code{Host} and @code{User}, access is denied.
@item
If there is a matching @code{db} table entry and its @code{Host} field is
not blank, that entry defines the user's database-specific privileges.
@item
If the matching @code{db} table entry's @code{Host} field is blank, it
signifies that the @code{host} table enumerates which hosts should be allowed
access to the database. In this case, a further lookup is done in the
@code{host} table to find a match on the @code{Host} and @code{Db} fields.
If no @code{host} table entry matches, access is denied. If there is a
match, the user's database-specific privileges are computed as the
intersection (@emph{not} the union!) of the privileges in the @code{db} and
@code{host} table entries, i.e., the privileges that are @code{'Y'} in both
entries. (This way you can grant general privileges in the @code{db} table
entry and then selectively restrict them on a host-by-host basis using the
@code{host} table entries.)
@end enumerate
After determining the database-specific privileges granted by the @code{db}
and @code{host} table entries, the server adds them to the global privileges
granted by the @code{user} table. If the result allows the requested
operation, access is granted. Otherwise, the server checks the user's
table and column privileges in the @code{tables_priv} and @code{columns_priv}
tables and adds those to the user's privileges. Access is allowed or denied
based on the result.
Expressed in boolean terms, the preceding description of how a user's
privileges are calculated may be summarized like this:
@example
global privileges
OR (database privileges AND host privileges)
OR table privileges
OR column privileges
@end example
It may not be apparent why, if the global @code{user} entry privileges are
initially found to be insufficient for the requested operation, the server
adds those privileges to the database-, table- and column-specific privileges
later. The reason is that a request might require more than one type of
privilege. For example, if you execute an @code{INSERT ... SELECT}
statement, you need both @strong{insert} and @strong{select} privileges.
Your privileges might be such that the @code{user} table entry grants one
privilege and the @code{db} table entry grants the other. In this case, you
have the necessary privileges to perform the request, but the server cannot
tell that from either table by itself; the privileges granted by the entries
in both tables must be combined.
The @code{host} table can be used to maintain a list of ``secure'' servers.
At TcX, the @code{host} table contains a list of all machines on the local
network. These are granted all privileges.
You can also use the @code{host} table to indicate hosts that are @emph{not}
secure. Suppose you have a machine @code{public.your.domain} that is located
in a public area that you do not consider secure. You can allow access to
all hosts on your network except that machine by using @code{host} table
entries
like this:
@example
+--------------------+----+-
| Host | Db | ...
+--------------------+----+-
| public.your.domain | % | ... (all privileges set to 'N')
| %.your.domain | % | ... (all privileges set to 'Y')
+--------------------+----+-
@end example
Naturally, you should always test your entries in the grant tables (e.g.,
using @code{mysqlaccess}) to make sure your access privileges are actually
set up the way you think they are.
@node Privilege changes, Default privileges, Request access, Privilege system
@section When privilege changes take effect
When @code{mysqld} starts, all grant table contents are read into memory and
become effective at that point.
Modifications to the grant tables that you perform using @code{GRANT},
@code{REVOKE}, or @code{SET PASSWORD} are noticed by the server immediately.
If you modify the grant tables manually (using @code{INSERT}, @code{UPDATE},
etc.), you should execute a @code{FLUSH PRIVILEGES} statement or run
@code{mysqladmin flush-privileges} or @code{mysqladmin reload} to tell the
server to reload the grant tables. Otherwise your changes will have @emph{no
effect} until you restart the server. If you change the grant tables manually
but forget to reload the privileges, you will be wondering why your changes
don't seem to make any difference!
When the server notices that the grant tables have been changed,
existing client connections are affected as follows:
@itemize @bullet
@item
Table and column privilege changes take effect with the client's next
request.
@item
Database privilege changes take effect at the next @code{USE db_name}
command.
@end itemize
Global privilege changes and password changes take effect the next time the
client connects.
@node Default privileges, Adding users, Privilege changes, Privilege system
@section Setting up the initial MySQL privileges
After installing @strong{MySQL}, you set up the initial access privileges by
running @code{scripts/mysql_install_db}.
@xref{Quick install}.
The @code{mysql_install_db} script starts up the @code{mysqld}
server, then initializes the grant tables to contain the following set
of privileges:
@itemize @bullet
@item
The @strong{MySQL} @code{root} user is created as a superuser who can do
anything. Connections must be made from the local host.
@strong{Note:}
The initial @code{root} password is empty, so anyone can connect as @code{root}
@emph{without a password} and be granted all privileges.
@item
@cindex Anonymous user
An anonymous user is created that can do anything with databases that have a
name of @code{'test'} or starting with @code{'test_'}. Connections must be
made from the local host. This means any local user can connect without a
password and be treated as the anonymous user.
@item
Other privileges are denied. For example, normal users can't use
@code{mysqladmin shutdown} or @code{mysqladmin processlist}.
@end itemize
@strong{NOTE:} The default privileges are different for Win32.
@xref{Win32 running}.
Because your installation is initially wide open, one of the first things you
should do is specify a password for the @strong{MySQL}
@code{root} user. You can do this as follows (note that you specify the
password using the @code{PASSWORD()} function):
@example
shell> mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('new_password')
WHERE user='root';
mysql> FLUSH PRIVILEGES;
@end example
You can in @strong{MySQL} 3.22 and above use the @code{SET PASSWORD} statement:
@example
shell> mysql -u root mysql
mysql> SET PASSWORD FOR root=PASSWORD('new_password');
@end example
Another way to set the password is by using the @code{mysqladmin} command:
@example
shell> mysqladmin -u root password new_password
@end example
Note that if you update the password in the @code{user} table directly using
the first method, you must tell the server to reread the grant tables (with
@code{FLUSH PRIVILEGES}), because the change will go unnoticed otherwise.
Once the @code{root} password has been set, thereafter you must supply that
password when you connect to the server as @code{root}.
You may wish to leave the @code{root} password blank so that you don't need
to specify it while you perform additional setup or testing. However, be sure
to set it before using your installation for any real production work.
See the @code{scripts/mysql_install_db} script to see how it sets up
the default privileges. You can use this as a basis to see how to
add other users.
If you want the initial privileges to be different than those just described
above, you can modify @code{mysql_install_db} before you run it.
To recreate the grant tables completely, remove all the @file{*.frm},
@file{*.MYI} and @file{*.MYD} files in the directory containing the
@code{mysql} database. (This is the directory named @file{mysql} under
the database directory, which is listed when you run @code{mysqld
--help}.) Then run the @code{mysql_install_db} script, possibly after
editing it first to have the privileges you want.
@strong{NOTE:} For @strong{MySQL} versions older than 3.22.10, you should NOT
delete the @file{*.frm} files. If you accidentally do this, you should
copy them back from your @strong{MySQL} distribution before running
@code{mysql_install_db}.
@node Adding users, Passwords, Default privileges, Privilege system
@section Adding new user privileges to MySQL
You can add users two different ways: by using @code{GRANT} statements
or by manipulating the @strong{MySQL} grant tables directly. The
preferred method is to use @code{GRANT} statements, because they are
more concise and less error-prone.
The examples below show how to use the @code{mysql} client to set up new
users. These examples assume that privileges are set up according to the
defaults described in the previous section. This means that to make changes,
you must be on the same machine where @code{mysqld} is running, you must
connect as the @strong{MySQL} @code{root} user, and the @code{root} user must
have the @strong{insert} privilege for the @code{mysql} database and the
@strong{reload} administrative privilege. Also, if you have changed the
@code{root} user password, you must specify it for the @code{mysql} commands
below.
You can add new users by issuing @code{GRANT} statements:
@example
shell> mysql --user=root mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO monty@@localhost
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO monty@@"%"
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO admin@@localhost;
mysql> GRANT USAGE ON *.* TO dummy@@localhost;
@end example
These @code{GRANT} statements set up three new users:
@table @code
@item monty
A full superuser who can connect to the server from anywhere, but who must
use a password @code{'some_pass'} to do so. Note that we must issue
@code{GRANT} statements for both @code{monty@@localhost} and
@code{monty@@"%"}. If we don't add the entry with @code{localhost}, the
anonymous user entry for @code{localhost} that is created by
@code{mysql_install_db} will take precedence when we connect from the local
host, because it has a more specific @code{Host} field value and thuse comes
earlier in the @code{user} table sort order.
@item admin
A user who can connect from @code{localhost} without a password and who is
granted the @strong{reload} and @strong{process} administrative privileges.
This allows the user to execute the @code{mysqladmin reload},
@code{mysqladmin refresh} and @code{mysqladmin flush-*} commands, as well as
@code{mysqladmin processlist} . No database-related privileges are granted.
(They can be granted later by issuing additional @code{GRANT} statements.)
@item dummy
A user who can connect without a password, but only from the local host. The
global privileges are all set to @code{'N'} --- the @code{USAGE} privilege
type allows you to create a user with no privileges. It is assumed that you
will grant database-specific privileges later.
@end table
You can also add the same user access information directly by issuing
@code{INSERT} statements and then telling the server to reload the grant
tables:
@example
shell> mysql --user=root mysql
mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('some_pass'),
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y')
mysql> INSERT INTO user VALUES('%','monty',PASSWORD('some_pass'),
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y')
mysql> INSERT INTO user SET Host='localhost',User='admin',
Reload_priv='Y', Process_priv='Y';
mysql> INSERT INTO user (Host,User,Password)
VALUES('localhost','dummy','');
mysql> FLUSH PRIVILEGES;
@end example
Depending on your @strong{MySQL} version, you may have to use a different
number of @code{'Y'} values above (versions prior to 3.22.11 had fewer
privilege columns). For the @code{admin} user, the more readable extended
@code{INSERT} syntax that is available starting with 3.22.11 is used.
Note that to set up a superuser, you need only create a @code{user} table
entry with the privilege fields set to @code{'Y'}. No @code{db} or
@code{host} table entries are necessary.
The privilege columns in the @code{user} table were not set explicitly in the
last @code{INSERT} statement (for the @code{dummy} user), so those columns
are assigned the default value of @code{'N'}. This is the same thing that
@code{GRANT USAGE} does.
The following example adds a user @code{custom} who can connect from hosts
@code{localhost}, @code{server.domain} and @code{whitehouse.gov}. He wants
to access the @code{bankaccount} database only from @code{localhost},
the @code{expenses} database only from @code{whitehouse.gov} and
the @code{customer} database from all three hosts. He wants
to use the password @code{stupid} from all three hosts.
To set up this user's privileges using @code{GRANT} statements, run these
commands:
@example
shell> mysql --user=root mysql
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON bankaccount.*
TO custom@@localhost
IDENTIFIED BY 'stupid';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON expenses.*
TO custom@@whitehouse.gov
IDENTIFIED BY 'stupid';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON customer.*
TO custom@@'%'
IDENTIFIED BY 'stupid';
@end example
To set up the user's privileges by modifying the grant tables directly,
run these commands (note the @code{FLUSH PRIVILEGES} at the end):
@example
shell> mysql --user=root mysql
mysql> INSERT INTO user (Host,User,Password)
VALUES('localhost','custom',PASSWORD('stupid'));
mysql> INSERT INTO user (Host,User,Password)
VALUES('server.domain','custom',PASSWORD('stupid'));
mysql> INSERT INTO user (Host,User,Password)
VALUES('whitehouse.gov','custom',PASSWORD('stupid'));
mysql> INSERT INTO db
(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
Create_priv,Drop_priv)
VALUES
('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db
(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
Create_priv,Drop_priv)
VALUES
('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y');
mysql> INSERT INTO db
(Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,
Create_priv,Drop_priv)
VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y');
mysql> FLUSH PRIVILEGES;
@end example
The first three @code{INSERT} statements add @code{user} table entries that
allow user @code{custom} to connect from the various hosts with the given
password, but grant no permissions to him (all privileges are set to the
default value of @code{'N'}). The next three @code{INSERT} statements add
@code{db} table entries that grant privileges to @code{custom} for the
@code{bankaccount}, @code{expenses} and @code{customer} databases, but only
when accessed from the proper hosts. As usual, when the grant tables are
modified directly, the server must be told to reload them (with
@code{FLUSH PRIVILEGES}) so that the privilege changes take effect.
If you want to give a specific user access from any machine in a given
domain, you can issue a @code{GRANT} statement like the following:
@example
mysql> GRANT ...
ON *.*
TO myusername@@"%.mydomainname.com"
IDENTIFIED BY 'mypassword';
@end example
To do the same thing by modifying the grant tables directly, do this:
@example
mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername',
PASSWORD('mypassword'),...);
mysql> FLUSH PRIVILEGES;
@end example
You can also use @code{xmysqladmin}, @code{mysql_webadmin} and even
@code{xmysql} to insert, change and update values in the grant tables.
You can find these utilities in the
@uref{http://www.mysql.com/Downloads/Contrib/,Contrib directory of the @strong{MySQL}
Website}.
@node Passwords, Access denied, Adding users, Privilege system
@section How to set up passwords
@cindex Passwords, setting
@findex PASSWORD()
The examples in the preceding sections illustrate an important principle:
when you store a non-empty password using @code{INSERT} or @code{UPDATE}
statements, you must use the @code{PASSWORD()} function to encrypt it. This
is because the @code{user} table stores passwords in encrypted form, not as
plaintext. If you forget that fact, you are likely to attempt to set
passwords like this:
@example
shell> mysql -u root mysql
mysql> INSERT INTO user (Host,User,Password)
VALUES('%','jeffrey','biscuit');
mysql> FLUSH PRIVILEGES;
@end example
The result is that the plaintext value @code{'biscuit'} is stored as the
password in the @code{user} table. When the user @code{jeffrey} attempts to
connect to the server using this password, the @code{mysql} client encrypts
it with @code{PASSWORD()} and sends the result to the server. The server
compares the value in the @code{user} table (the encrypted value of
@code{'biscuit'}) to the encrypted password (which is @emph{not}
@code{'biscuit'}). The comparison fails and the server rejects the
connection:
@example
shell> mysql -u jeffrey -pbiscuit test
Access denied
@end example
Passwords must be encrypted when they are inserted in the @code{user}
table, so the @code{INSERT} statement should have been specified like this
instead:
@example
mysql> INSERT INTO user (Host,User,Password)
VALUES('%','jeffrey',PASSWORD('biscuit'));
@end example
You must also use the @code{PASSWORD()} function when you use @code{SET
PASSWORD} statements:
@example
mysql> SET PASSWORD FOR jeffrey@@"%" = PASSWORD('biscuit');
@end example
If you set passwords using the @code{GRANT ... IDENTIFIED BY} statement
or the @code{mysqladmin password} command, the @code{PASSWORD()} function
is unnecessary. They both take care of encrypting the password for you,
so you would specify a password of @code{'biscuit'} like this:
@example
mysql> GRANT USAGE ON *.* TO jeffrey@@"%" IDENTIFIED BY 'biscuit';
@end example
or
@example
shell> mysqladmin -u jeffrey password biscuit
@end example
@strong{NOTE:} @code{PASSWORD()} does not perform password encryption in the
same way that Unix passwords are encrypted. You should not assume that if
your Unix password and your @strong{MySQL} password are the same, that
@code{PASSWORD()} will result in the same encrypted value as is stored in the
Unix password file.
@xref{User names}.
@node Access denied, , Passwords, Privilege system
@section Causes of @code{Access denied} errors
If you encounter @code{Access denied} errors when you try to connect to the
@strong{MySQL} server, the list below indicates some courses of
action you can take to correct the problem:
@itemize @bullet
@item
After installing @strong{MySQL}, did you run the @code{mysql_install_db} script
to set up the initial grant table contents? If not, do
so. @xref{Default privileges}. Test the initial privileges by
executing this command:
@example
shell> mysql -u root test
@end example
The server should let you connect without error. You should also make sure
you have a file @file{user.MYD} in the @strong{MySQL} database directory.
Ordinarily, this is @file{PATH/var/mysql/user.MYD}, where @code{PATH} is the
pathname to the @strong{MySQL} installation root.
@item
After a fresh installation, you should connect to the server and set up
your users and their access permissions:
@example
shell> mysql -u root mysql
@end example
The server should let you connect because the @strong{MySQL} @code{root} user
has no password initially. That is also a security risk, so setting the
@code{root} password is something you should do while you're setting up
your other @strong{MySQL} users.
If you try to connect as @code{root} and get this error:
@example
Access denied for user: '@@unknown' to database mysql
@end example
this means that you don't have an entry in the @code{user} table with a
@code{User} column value of @code{'root'} and that @code{mysqld} cannot
resolve the hostname for your client. In this case, you must restart the
server with the @code{--skip-grant-tables} option and edit your
@file{/etc/hosts} or @file{\windows\hosts} file to add an entry for your
host.
@item
@cindex @code{mysql_fix_privilege_tables}
If you updated an existing @strong{MySQL} installation from a pre-3.22.11
version to 3.22.11 or later, did you run the
@code{mysql_fix_privilege_tables} script? If not, do so. The structure of
the grant tables changed with @strong{MySQL} 3.22.11 when the @code{GRANT}
statement became functional.
@item
If you make changes to the grant tables directly (using @code{INSERT} or
@code{UPDATE} statement) and your changes seem to be ignored, remember that
you must issue a @code{FLUSH PRIVILEGES} statement or execute a
@code{mysqladmin flush-privileges} command to cause the server to reread the
tables. Otherwise your changes have no effect until the next time the server
is restarted. Remember that after you set the @code{root} password, you
won't need to specify it until after you flush the privileges, because the
server still won't know you've changed the password yet!
@item
If your privileges seem to have changed in the middle of a session, it may be
that a superuser has changed them. Reloading the grant tables affects new
client connections, but it also affects existing connections as indicated in
@ref{Privilege changes}.
@item
For testing, start the @code{mysqld} daemon with the
@code{--skip-grant-tables} option. Then you can change the @strong{MySQL}
grant tables and use the @code{mysqlaccess} script to check whether or not
your modifications have the desired effect. When you are satisfied with your
changes, execute @code{mysqladmin flush-privileges} to tell the @code{mysqld}
server to start using the new grant tables. @strong{Note:} Reloading the
grant tables overrides the @code{--skip-grant-tables} option. This allows
you to tell the server to begin using the grant tables again without bringing
it down and restarting it.
@item
If you have access problems with a Perl, PHP, Python or ODBC program, try to
connect to the server with @code{mysql -u user_name db_name} or @code{mysql
-u user_name -pyour_pass db_name}. If you are able to connect using the
@code{mysql} client, there is a problem with your program and not with the
access privileges. (Notice that there is no space between @code{-p} and the
password; you can also use the @code{--password=your_pass} syntax to specify
the password.)
@item
If you can't get your password to work, remember that you must use
the @code{PASSWORD()} function if you set the password with the
@code{INSERT}, @code{UPDATE} or @code{SET PASSWORD} statements. The
@code{PASSWORD()} function is unnecessary if you specify the password using
the @code{GRANT ... INDENTIFIED BY} statement or the @code{mysqladmin
password} command.
@xref{Passwords}.
@item
@code{localhost} is a synonym for your local hostname, and is also the
default host to which clients try to connect if you specify no host
explicitly. However, connections to @code{localhost} do not work if you are
running on a system that uses MIT-pthreads (@code{localhost} connections are
made using Unix sockets, which are not supported by MIT-pthreads). To avoid
this problem on such systems, you should use the @code{--host} option to name
the server host explicitly. This will make a TCP/IP connection to the
@code{mysqld} server. In this case, you must have your real hostname in
@code{user} table entries on the server host. (This is true even if you are
running a client program on the same host as the server.)
@item
If you get an @code{Access denied} error when trying to connect to the
database with @code{mysql -u user_name db_name}, you may have a problem
with the @code{user} table. Check this by executing @code{mysql -u root
mysql} and issuing this SQL statement:
@example
mysql> SELECT * FROM user;
@end example
The result should include an entry with the @code{Host} and @code{User}
columns matching your computer's hostname and your @strong{MySQL} user name.
@item
The @code{Access denied} error message will tell you who you are trying
to log in as, the host from which you are trying to connect, and whether
or not you were using a password. Normally, you should have one entry in
the @code{user} table that exactly matches the hostname and user name
that were given in the error message.
@item
If you get the following error when you try to connect from a different host
than the one on which the @strong{MySQL} server is running, then there is no
row in the @code{user} table that matches that host:
@example
Host ... is not allowed to connect to this MySQL server
@end example
You can fix this by using the command line tool @code{mysql} (on the
server host!) to add a row to the @code{user}, @code{db} or @code{host}
table for the user/hostname combination from which you are trying to
connect and then execute @code{mysqladmin flush-privileges}. If you are
not running @strong{MySQL} 3.22 and you don't know the IP number or
hostname of the machine from which you are connecting, you should put an
entry with @code{'%'} as the @code{Host} column value in the @code{user}
table and restart @code{mysqld} with the @code{--log} option on the
server machine. After trying to connect from the client machine, the
information in the @strong{MySQL} log will indicate how you really did
connect. (Then replace the @code{'%'} in the @code{user} table entry
with the actual hostname that shows up in the log. Otherwise, you'll
have a system that is insecure.)
Another reason for this error on Linux is that you are using a binary
@strong{MySQL} version that is compiled with a different glibc version
than the one you are using. In this case you should either upgrade your
OS/glibc or download the source @strong{MySQL} version and compile this
yourself; A source RPM is normally trivial to compile and install, so
normally this isn't a big problem.
@item
If @code{mysql -u root test} works but @code{mysql -h your_hostname -u root
test} results in @code{Access denied}, then you may not have the correct name
for your host in the @code{user} table. A common problem here is that the
@code{Host} value in the user table entry specifies an unqualified hostname,
but your system's name resolution routines return a fully-qualified domain
name (or vice-versa). For example, if you have an entry with host
@code{'tcx'} in the @code{user} table, but your DNS tells @strong{MySQL} that
your hostname is @code{'tcx.subnet.se'}, the entry will not work. Try adding
an entry to the @code{user} table that contains the IP number of your host as
the @code{Host} column value. (Alternatively, you could add an entry to the
@code{user} table with a @code{Host} value that contains a wildcard---for
example, @code{'tcx.%'}. However, use of hostnames ending with @samp{%} is
@emph{insecure} and is @emph{not} recommended!)
@item
If @code{mysql -u user_name test} works but @code{mysql -u user_name
other_db_name} doesn't work, you don't have an entry for @code{other_db_name}
listed in the @code{db} table.
@item
If @code{mysql -u user_name db_name} works when executed on the server
machine, but @code{mysql -u host_name -u user_name db_name} doesn't work when
executed on another client machine, you don't have the client machine listed
in the @code{user} table or the @code{db} table.
@item
If you can't figure out why you get @code{Access denied}, remove from the
@code{user} table all entries that have @code{Host} values containing
wildcards (entries that contain @samp{%} or @samp{_}). A very common error
is to insert a new entry with @code{Host}=@code{'%'} and
@code{User}=@code{'some user'}, thinking that this will allow you to specify
@code{localhost} to connect from the same machine. The reason that this
doesn't work is that the default privileges include an entry with
@code{Host}=@code{'localhost'} and @code{User}=@code{''}. Because that entry
has a @code{Host} value @code{'localhost'} that is more specific than
@code{'%'}, it is used in preference to the new entry when connecting from
@code{localhost}! The correct procedure is to insert a second entry with
@code{Host}=@code{'localhost'} and @code{User}=@code{'some_user'}, or to
remove the entry with with @code{Host}=@code{'localhost'} and
@code{User}=@code{''}.
@item
If you get the following error, you may have a problem with the @code{db} or
@code{host} table:
@example
Access to database denied
@end example
If the entry selected from the @code{db} table has an empty value in the
@code{Host} column, make sure there are one or more corresponding entries in
the @code{host} table specifying which hosts the @code{db} table entry
applies to.
If you get the error when using the SQL commands @code{SELECT ...
INTO OUTFILE} or @code{LOAD DATA INFILE}, your entry in the @code{user} table
probably doesn't have the @strong{file} privilege enabled.
@item
@cindex Configuration files
@cindex Environment variables
@tindex .my.cnf file
Remember that client programs will use connection parameters specified
in configuration files or environment variables. @xref{Environment
variables}. If a client seems to be sending the wrong default
connection parameters when you don't specify them on the command line,
check your environment and the @file{.my.cnf} file in your home
directory. You might also check the system-wide @strong{MySQL}
configuration files, though it is far less likely that client connection
parameters will be specified there. @xref{Option files}. If you get
@code{Access denied} when you run a client without any options, make
sure you haven't specified an old password in any of your option files!
@xref{Option files}.
@item
If everything else fails, start the @code{mysqld} daemon with a debugging
option (for example, @code{--debug=d,general,query}). This will print host and
user information about attempted connections, as well as information about
each command issued. @xref{Debugging server}.
@item
If you have any other problems with the @strong{MySQL} grant tables and
feel you must post the problem to the mailing list, always provide a
dump of the @strong{MySQL} grant tables. You can dump the tables with
the @code{mysqldump mysql} command. As always, post your problem using
the @code{mysqlbug} script. @xref{Bug reports}. In some cases you may need
to restart @code{mysqld} with @code{--skip-grant-tables} to be able to run
@code{mysqldump}.
@end itemize
@node Reference, Table types, Privilege system, Top
@chapter MySQL language reference
@menu
* Literals:: Literals: how to write strings and numbers
* Variables:: User variables
* Column types:: Column types
* Functions:: Functions
* CREATE DATABASE:: @code{CREATE DATABASE} syntax
* DROP DATABASE:: @code{DROP DATABASE} syntax
* CREATE TABLE:: @code{CREATE TABLE} syntax
* ALTER TABLE:: @code{ALTER TABLE} syntax
* DROP TABLE:: @code{DROP TABLE} syntax
* OPTIMIZE TABLE:: @code{OPTIMIZE TABLE} syntax
* CHECK TABLE:: @code{CHECK TABLE} syntax
* ANALYZE TABLE::
* REPAIR TABLE:: @code{REPAIR TABLE} syntax
* DELETE:: @code{DELETE} syntax
* SELECT:: @code{SELECT} syntax
* JOIN:: @code{JOIN} syntax
* INSERT:: @code{INSERT} syntax
* REPLACE:: @code{REPLACE} syntax
* LOAD DATA:: @code{LOAD DATA INFILE} syntax
* UPDATE:: @code{UPDATE} syntax
* USE:: @code{USE} syntax
* FLUSH:: @code{Flush} syntax (clearing caches)
* KILL:: @code{KILL} syntax
* SHOW:: @code{SHOW} syntax (Get information about tables, columns, ...)
* EXPLAIN:: @code{EXPLAIN} syntax (Get information about a @code{SELECT})
* DESCRIBE:: @code{DESCRIBE} syntax (Get information about names of columns)
* COMMIT:: @code{BEGIN/COMMIT/ROLLBACK} syntax
* LOCK TABLES:: @code{LOCK TABLES/UNLOCK TABLES} syntax
* SET OPTION:: @code{SET OPTION} syntax
* GRANT:: @code{GRANT} and @code{REVOKE} syntax
* CREATE INDEX:: @code{CREATE INDEX} syntax
* DROP INDEX:: @code{DROP INDEX} syntax
* Comments:: Comment syntax
* CREATE FUNCTION:: @code{CREATE FUNCTION} syntax
* Reserved words:: Is @strong{MySQL} picky about reserved words?
@end menu
@cindex Strings
@cindex Strings, escaping characters
@node Literals, Variables, Reference, Reference
@section Literals: how to write strings and numbers
@menu
* String syntax:: Strings
* Number syntax:: Numbers
* Hexadecimal values:: Hexadecimal values
* NULL values:: @code{NULL} values
* Legal names:: Database, table, index, column and alias names
@end menu
@node String syntax, Number syntax, Literals, Literals
@subsection Strings
A string is a sequence of characters, surrounded by either single quote
(@samp{'}) or double quote (@samp{"}) characters (only the single quote
if you run in ANSI mode). Examples:
@example
'a string'
"another string"
@end example
Within a string, certain sequences have special meaning. Each of these
sequences begins with a backslash (@samp{\}), known as the @emph{escape
character}. @strong{MySQL} recognizes the following escape sequences:
@c these aren't really functions, but that's probably the most reasonable index
@table @code
@findex \0 (ASCII 0)
@findex NUL
@item \0
An ASCII 0 (@code{NUL}) character.
@findex \n (newline)
@findex newline (\n)
@item \n
A newline character.
@findex \t (tab)
@findex tab (\t)
@item \t
A tab character.
@findex \r (carriage return)
@findex return (\r)
@findex carriage return (\r)
@item \r
A carriage return character.
@findex \b (backspace)
@findex backspace (\b)
@item \b
A backspace character.
@findex \' (single quote)
@findex single quote (\')
@item \'
A single quote (@samp{'}) character.
@findex \" (double quote)
@findex double quote (\")
@item \"
A double quote (@samp{"}) character.
@findex \\ (escape)
@findex escape (\\)
@item \\
A backslash (@samp{\}) character.
@findex % (wildcard character)
@findex Wildcard character (%)
@item \%
A @samp{%} character. This is used to search for literal instances of
@samp{%} in contexts where @samp{%} would otherwise be interpreted
as a wildcard character. @xref{String comparison functions}.
@findex _ (wildcard character)
@findex Wildcard character (_)
@item \_
A @samp{_} character. This is used to search for literal instances of
@samp{_} in contexts where @samp{_} would otherwise be interpreted
as a wildcard character. @xref{String comparison functions}.
@end table
Note that if you use @samp{\%} or @samp{\_} in some string contexts, these
will return the strings @samp{\%} and @samp{\_} and not @samp{%} and
@samp{_}.
@noindent
There are several ways to include quotes within a string:
@itemize @bullet
@item
A @samp{'} inside a string quoted with @samp{'} may be written as @samp{''}.
@item
A @samp{"} inside a string quoted with @samp{"} may be written as @samp{""}.
@item
You can precede the quote character with an escape character (@samp{\}).
@item
A @samp{'} inside a string quoted with @samp{"} needs no special treatment
and need not be doubled or escaped. In the same way, @samp{"} inside a
string quoted with @samp{'} needs no special treatment.
@end itemize
The @code{SELECT} statements shown below demonstrate how quoting and
escaping work:
@example
mysql> SELECT 'hello', '"hello"', '""hello""', 'hel''lo', '\'hello';
+-------+---------+-----------+--------+--------+
| hello | "hello" | ""hello"" | hel'lo | 'hello |
+-------+---------+-----------+--------+--------+
mysql> SELECT "hello", "'hello'", "''hello''", "hel""lo", "\"hello";
+-------+---------+-----------+--------+--------+
| hello | 'hello' | ''hello'' | hel"lo | "hello |
+-------+---------+-----------+--------+--------+
mysql> SELECT "This\nIs\nFour\nlines";
+--------------------+
| This
Is
Four
lines |
+--------------------+
@end example
@cindex Quoting binary data
If you want to insert binary data into a @code{BLOB} column, the following
characters must be represented by escape sequences:
@table @code
@item NUL
ASCII 0. You should represent this by @samp{\0} (a backslash and an ASCII @samp{0} character).
@item \
ASCII 92, backslash. Represent this by @samp{\\}.
@item '
ASCII 39, single quote. Represent this by @samp{\'}.
@item "
ASCII 34, double quote. Represent this by @samp{\"}.
@end table
@cindex Quoting
@cindex @code{BLOB}, inserting binary data
@findex mysql_escape_string()
@findex DBI->quote
If you write C code, you can use the C API function
@code{mysql_escape_string()} to escape characters for the @code{INSERT}
statement. @xref{C API function overview}. In Perl, you can use the
@code{quote} method of the @code{DBI} package to convert special
characters to the proper escape sequences. @xref{Perl DBI Class, , Perl
@code{DBI} Class}.
You should use an escape function on any string that might contain any of the
special characters listed above!
@node Number syntax, Hexadecimal values, String syntax, Literals
@subsection Numbers
Integers are represented as a sequence of digits. Floats use @samp{.} as a
decimal separator. Either type of number may be preceded by @samp{-} to
indicate a negative value.
Examples of valid integers:
@example
1221
0
-32
@end example
Examples of valid floating-point numbers:
@example
294.42
-32032.6809e+10
148.00
@end example
An integer may be used in a floating-point context; it is interpreted
as the equivalent floating-point number.
@tindex Hexadecimal values
@node Hexadecimal values, NULL values, Number syntax, Literals
@subsection Hexadecimal values
@strong{MySQL} supports hexadecimal values. In number context these acts
like an integer (64 bit precision). In string context these acts like a binary
string where each pair of hex digits is converted to a character.
@example
mysql> SELECT 0xa+0
-> 10
mysql> select 0x5061756c;
-> Paul
@end example
Hexadecimal strings is often used by ODBC to give values for BLOB columns.
@tindex NULL value
@node NULL values, Legal names, Hexadecimal values, Literals
@subsection @code{NULL} values
The @code{NULL} value means ``no data'' and is different from values such
as @code{0} for numeric types or the empty string for string types.
@xref{Problems with NULL, , Problems with @code{NULL}}.
@code{NULL} may be represented by @code{\N} when using the text file import
or export formats (@code{LOAD DATA INFILE}, @code{SELECT ... INTO OUTFILE}).
@xref{LOAD DATA, , @code{LOAD DATA}}.
@node Legal names, , NULL values, Literals
@subsection Database, table, index, column and alias names
@menu
* Name case sensitivity:: Case sensitivity in names
@end menu
Database, table, index, column and alias names all follow the same rules in
@strong{MySQL}:
@tindex Quoting of identifiers
@tindex `
@tindex "
Note that the rules changed starting with @strong{MySQL} 3.23.6 when we
introduced quoting of identifiers (database, table and column names)
with @code{`} (@code{"} will also work to quote identifiers if you run
in ANSI mode).
@multitable @columnfractions .15 .7 .78
@item @strong{Identifier} @tab @strong{max length} @tab @strong{Allowed characters}
@item Database @tab 64 @tab Any character that is allowed in a directory name execpt @code{/}.
@item Table @tab 64 @tab Any character that is allowed in file name, except @code{/} or @code{.}
@item Column @tab 64 @tab All characters
@item Alias @tab 255 @tab All characters
@end multitable
Note that in addition to the above, you can't have ASCII(0) or ASCII(255) in
an identifier.
Note that if the identifer is a restricted word or contains special character
you must always quote it with @code{`} when you use it:
@example
SELECT * from `select` where `select`.id > 100;
@end example
In previous versions of @strong{MySQL}, the name rules are as follows:
@itemize @bullet
@item
A name may consist of alphanumeric characters from the current character set
and also @samp{_} and @samp{$}. The default character set is ISO-8859-1
Latin1; this may be changed with the @code{--default-character-set} option
to @code{mysqld}.
@xref{Character sets}.
@item
A name may start with any character that is legal in a name. In particular,
a name may start with a number (this differs from many other database
systems!). However, a name cannot consist @emph{only} of numbers.
@item
You cannot use the @samp{.} character in names because it is used to extend the
format by which you can refer to columns (see immediately below).
@end itemize
It is recommended that you do not use names like @code{1e}, because
an expression like @code{1e+1} is ambiguous. It may be interpreted as the
expression @code{1e + 1} or as the number @code{1e+1}.
In @strong{MySQL} you can refer to a column using any of the following forms:
@multitable @columnfractions .35 .65
@item @strong{Column reference} @tab @strong{Meaning}
@item @code{col_name} @tab Column @code{col_name}
from whichever table used in the query contains a column of that name
@item @code{tbl_name.col_name} @tab Column @code{col_name} from table
@code{tbl_name} of the current database
@item @code{db_name.tbl_name.col_name} @tab Column @code{col_name} from table
@code{tbl_name} of the database @code{db_name}. This form is available in
@strong{MySQL} 3.22 or later.
@item
@code{`column_name`} @tab A column that is a keyword or contains special characters.
@end multitable
You need not specify a @code{tbl_name} or @code{db_name.tbl_name} prefix for
a column reference in a statement unless the reference would be ambiguous.
For example, suppose tables @code{t1} and @code{t2} each contain a column
@code{c}, and you retrieve @code{c} in a @code{SELECT} statement that uses
both @code{t1} and @code{t2}. In this case, @code{c} is ambiguous because it
is not unique among the tables used in the statement, so you must indicate
which table you mean by writing @code{t1.c} or @code{t2.c}. Similarly, if
you are retrieving from a table @code{t} in database @code{db1} and from a
table @code{t} in database @code{db2}, you must refer to columns in those
tables as @code{db1.t.col_name} and @code{db2.t.col_name}.
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
The syntax @code{.tbl_name} means the table @code{tbl_name} in the current
database. This syntax is accepted for ODBC compatibility, because some ODBC
programs prefix table names with a @samp{.} character.
@node Name case sensitivity, , Legal names, Legal names
@subsubsection Case sensitivity in names
@cindex Database names, case sensitivity
@cindex Table names, case sensitivity
@cindex Column names, case sensitivity
@cindex Alias names, case sensitivity
@cindex Case sensitivity, of database names
@cindex Case sensitivity, of table names
@cindex Case sensitivity, of column names
@cindex Case sensitivity, of alias names
In @strong{MySQL}, databases and tables correspond to directories and files
within those directories. Consequently, the case sensitivity of the
underlying operating system determines the case sensitivity of database and
table names. This means database and table names are case sensitive in Unix
and case insensitive in Win32.
@strong{Note:} Although database and table names are case insensitive for
Win32, you should not refer to a given database or table using different
cases within the same query. The following query would not work because it
refers to a table both as @code{my_table} and as @code{MY_TABLE}:
@example
mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1;
@end example
Column names are case insensitive in all cases.
Aliases on tables are case sensitive. The following query would not work
because it refers to the alias both as @code{a} and as @code{A}:
@example
mysql> SELECT col_name FROM tbl_name AS a
WHERE a.col_name = 1 OR A.col_name = 2;
@end example
Aliases on columns are case insensitive.
@node Variables, Column types, Literals, Reference
@section User variables
@strong{MySQL} supports thread specific variables with the
@code{@@variablename} syntax. A variable name may consist of
alphanumeric characters from the current character set and also
@samp{_}, @samp{$}, and @samp{.} . The default character set is
ISO-8859-1 Latin1; this may be changed with the
@code{--default-character-set} option to @code{mysqld}. @xref{Character
sets}.
Variables don't have to be initialized. They contain @code{NULL} by default
and can store an integer, real or string value. All variables for
a thread are automatically freed when the thread exits.
You can set a variable with the @code{SET} syntax:
@example
SET @@variable= @{ integer expression | real expression | string expression @}
[,@@variable= ...].
@end example
You can also set a variable in an expression with the @code{@@variable:=expr}
syntax:
@example
select @@t1:=(@@t2:=1)+@@t3:=4,@@t1,@@t2,@@t3;
+----------------------+------+------+------+
| @@t1:=(@@t2:=1)+@@t3:=4 | @@t1 | @@t2 | @@t3 |
+----------------------+------+------+------+
| 5 | 5 | 1 | 4 |
+----------------------+------+------+------+
@end example
(We had to use the @code{:=} syntax here, because @code{=} was reserved for
comparisons.)
User variables may be used where expressions are allowed. Note that
this does not currently include use in contexts where a number is explicitly
required, such as in the @code{LIMIT} clause of a @code{SELECT} statement,
or the @code{IGNORE number LINES} clause of a @code{LOAD DATA} statement.
@strong{NOTE:} In a @code{SELECT} statement, each expression is only
evaluated when it's sent to the client. This means that one can't
in the @code{HAVING}, @code{GROUP BY} or @code{ORDER BY} clause refer to an
expression that involves variables that are set in the @code{SELECT} part.
For example, the following statement will NOT work as expected:
@example
SELECT (@@aa:=id) AS a, (@@aa+3) AS b FROM table_name HAVING b=5;
@end example
The reason is that @code{@@aa} will not contain the value of the current
row, but the value of @code{id} for the previous accepted row.
@node Column types, Functions, Variables, Reference
@section Column types
@strong{MySQL} supports a number of column types, which may be grouped into
three categories: numeric types, date and time types, and string (character)
types. This section first gives an overview of the types available and
summarizes the storage requirements for each column type, then provides a
more detailed description of the properties of the types in each category.
The overview is intentionally brief. The more detailed descriptions should
be consulted for additional information about particular column types, such
as the allowable formats in which you can specify values.
The column types supported by @strong{MySQL} are listed below.
The following code letters are used in the descriptions:
@table @code
@item M
Indicates the maximum display size. The maximum legal display size is 255.
@item D
Applies to floating-point types and indicates the number of digits
following the decimal point. The maximum possible value is 30, but
should be no greater than @code{M}-2.
@end table
Square brackets (@samp{[} and @samp{]}) indicate parts of type specifiers
that are optional.
@tindex Types
@c The @w{-number} stuff keeps a linebreak from occurring between
@c the - and number.
Note that if you specify @code{ZEROFILL} for a column, @strong{MySQL} will
automatically add the @code{UNSIGNED} attribute to the column.
@table @code
@tindex TINYINT
@item TINYINT[(M)] [UNSIGNED] [ZEROFILL]
A very small integer. The signed range is @code{-128} to @code{127}. The
unsigned range is @code{0} to @code{255}.
@tindex SMALLINT
@item SMALLINT[(M)] [UNSIGNED] [ZEROFILL]
A small integer. The signed range is @code{-32768} to @code{32767}. The
unsigned range is @code{0} to @code{65535}.
@tindex MEDIUMINT
@item MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL]
A medium-size integer. The signed range is @code{-8388608} to
@code{8388607}. The unsigned range is @code{0} to @code{16777215}.
@tindex INT
@item INT[(M)] [UNSIGNED] [ZEROFILL]
A normal-size integer. The signed range is @code{-2147483648} to
@code{2147483647}. The unsigned range is @code{0} to @code{4294967295}.
@tindex INTEGER
@item INTEGER[(M)] [UNSIGNED] [ZEROFILL]
This is a synonym for @code{INT}.
@tindex BIGINT
@item BIGINT[(M)] [UNSIGNED] [ZEROFILL]
A large integer. The signed range is @code{-9223372036854775808} to
@code{9223372036854775807}. The unsigned range is @code{0} to
@code{18446744073709551615}. Note that all arithmetic is done using
signed @code{BIGINT} or @code{DOUBLE} values, so you shouldn't use
unsigned big integers larger than @code{9223372036854775807} (63 bits)
except with bit functions! Note that @code{-}, @code{+} and @code{*}
will use @code{BIGINT} arithmetic when both arguments are @code{INTEGER}
values! This means that if you multiply two big integers (or results
from functions that return integers) you may get unexpected results if
the result is larger than @code{9223372036854775807}.
@tindex FLOAT
@tindex FLOAT(precision)
@item FLOAT(precision) [ZEROFILL]
A floating-point number. Cannot be unsigned. @code{precision} can be
@code{<=24} for a single precision floating point number and between 25
and 53 for a double precision floating point number.
these types are like the @code{FLOAT} and @code{DOUBLE} types described
immediately below. @code{FLOAT(X)} have the same ranges as the
corresponding @code{FLOAT} and @code{DOUBLE} types, but the display
size and number of decimals is undefined.
In @strong{MySQL} 3.23, this is a true floating point value. In
earlier @strong{MySQL} versions, @code{FLOAT(precision)} always has 2 decimals.
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
This syntax is provided for ODBC compatibility.
@tindex FLOAT
@tindex FLOAT(M,D)
@item FLOAT[(M,D)] [ZEROFILL]
A small (single-precision) floating-point number. Cannot be unsigned.
Allowable values are @code{@w{-3.402823466E+38}} to
@code{@w{-1.175494351E-38}}, @code{0} and @code{@w{1.175494351E-38}} to
@code{3.402823466E+38}. The M is the display width and D is the
number of decimals. @code{FLOAT} without an argument or with an argument of
<= 24 stands for a single-precision floating point number.
@tindex DOUBLE
@tindex FLOAT(precision)
@item DOUBLE[(M,D)] [ZEROFILL]
A normal-size (double-precision) floating-point number. Cannot be
unsigned. Allowable values are @code{@w{-1.7976931348623157E+308}} to
@code{@w{-2.2250738585072014E-308}}, @code{0} and
@code{2.2250738585072014E-308} to @code{1.7976931348623157E+308}. The M
is the display width and D is the number of decimals. @code{DOUBLE}
without an argument or @code{FLOAT(X)} where 25 <= X <= 53 stands for a
double-precision floating point number.
@tindex DOUBLE PRECISION
@tindex REAL
@item DOUBLE PRECISION[(M,D)] [ZEROFILL]
@itemx REAL[(M,D)] [ZEROFILL]
These are synonyms for @code{DOUBLE}.
@tindex DECIMAL
@item DECIMAL[(M[,D])] [ZEROFILL]
An unpacked floating-point number. Cannot be unsigned. Behaves like a
@code{CHAR} column: ``unpacked'' means the number is stored as a string,
using one character for each digit of the value. The decimal point,
and, for negative numbers, the @samp{-} sign is not counted in M. If
@code{D} is 0, values will have no decimal point or fractional part.
The maximum range of @code{DECIMAL} values is the same as for
@code{DOUBLE}, but the actual range for a given @code{DECIMAL} column
may be constrained by the choice of @code{M} and @code{D}.
If @code{D} is left out it's set to 0. If @code{M} is left out it's set to 10.
Note that in @strong{MySQL} 3.22 the @code{M} argument includes the sign
and the decimal point.
@tindex NUMERIC
@item NUMERIC(M,D) [ZEROFILL]
This is a synonym for @code{DECIMAL}.
@tindex DATE
@item DATE
A date. The supported range is @code{'1000-01-01'} to @code{'9999-12-31'}.
@strong{MySQL} displays @code{DATE} values in @code{'YYYY-MM-DD'} format, but
allows you to assign values to @code{DATE} columns using either strings or
numbers.
@tindex DATETIME
@item DATETIME
A date and time combination. The supported range is @code{'1000-01-01
00:00:00'} to @code{'9999-12-31 23:59:59'}. @strong{MySQL} displays
@code{DATETIME} values in @code{'YYYY-MM-DD HH:MM:SS'} format, but allows you
to assign values to @code{DATETIME} columns using either strings or numbers.
@tindex TIMESTAMP
@item TIMESTAMP[(M)]
A timestamp. The range is @code{'1970-01-01 00:00:00'} to sometime in the
year @code{2037}. @strong{MySQL} displays @code{TIMESTAMP} values in
@code{YYYYMMDDHHMMSS}, @code{YYMMDDHHMMSS}, @code{YYYYMMDD} or @code{YYMMDD}
format, depending on whether @code{M} is @code{14} (or missing), @code{12},
@code{8} or @code{6}, but allows you to assign values to @code{TIMESTAMP}
columns using either strings or numbers. A @code{TIMESTAMP} column is useful
for recording the date and time of an @code{INSERT} or @code{UPDATE}
operation because it is automatically set to the date and time of the most
recent operation if you don't give it a value yourself. You can also set it
to the current date and time by assigning it a @code{NULL} value. @xref{Date
and time types}.
@tindex TIME
@item TIME
A time. The range is @code{'-838:59:59'} to @code{'838:59:59'}.
@strong{MySQL} displays @code{TIME} values in @code{'HH:MM:SS'} format, but
allows you to assign values to @code{TIME} columns using either strings or
numbers.
@tindex YEAR
@item YEAR[(2|4)]
A year in 2- or 4- digit formats (default is 4-digit). The allowable values are
@code{1901} to @code{2155}, and @code{0000} in the 4 year format and
1970-2069 if you use the 2 digit format (70-69). @strong{MySQL} displays
@code{YEAR} values in @code{YYYY} format, but allows you to assign
values to @code{YEAR} columns using either strings or numbers.
(The @code{YEAR} type is new in @strong{MySQL} 3.22.)
@tindex NATIONAL CHAR
@tindex NCHAR
@tindex CHAR
@tindex CHARACTER
@item [NATIONAL] CHAR(M) [BINARY]
A fixed-length string that is always right-padded with spaces to the
specified length when stored. The range of @code{M} is 1 to 255 characters.
Trailing spaces are removed when the value is retrieved. @code{CHAR} values
are sorted and compared in case-insensitive fashion according to the
default character set unless the @code{BINARY} keyword is given.
@code{NATIONAL CHAR} (short form @code{NCHAR}) is the ANSI SQL way to
define that a CHAR column should use the default CHARACTER set. This is
default in @code{MySQL}.
@code{CHAR} is a shorthand for @code{CHARACTER}.
@strong{MySQL} allows you to create a column of type
@code{CHAR(0)}. This is mainly useful when you have to be compliant with
some old applications that depend on the existence of a column but that do not
actually use the value. This is also quite nice when you need a
column that only can take 2 values: A @code{CHAR(0)}, that is not defined
as @code{NOT NULL}, will only occupy one bit and can only take 2 values:
@code{NULL} or @code{""}.
@tindex CHARACTER VARYING
@tindex CHAR VARYING
@tindex VARCHAR
@item [NATIONAL] VARCHAR(M) [BINARY]
A variable-length string. Note:
Trailing spaces are removed when the value is stored (this differs from the
ANSI SQL specification). The range of @code{M} is 1 to 255 characters.
@code{VARCHAR} values are sorted and compared in case-insensitive fashion
unless the @code{BINARY} keyword is given. @xref{Silent column changes}.
@code{VARCHAR} is a shorthand for @code{CHARACTER VARYING}.
@tindex TINYBLOB
@tindex TINYTEXT
@item TINYBLOB
@itemx TINYTEXT
A @code{BLOB} or @code{TEXT} column with a maximum length of 255 (2^8 - 1)
characters. @xref{Silent column changes}.
@tindex BLOB
@tindex TEXT
@item BLOB
@itemx TEXT
A @code{BLOB} or @code{TEXT} column with a maximum length of 65535 (2^16 - 1)
characters. @xref{Silent column changes}.
@tindex MEDIUMBLOB
@tindex MEDIUMTEXT
@item MEDIUMBLOB
@itemx MEDIUMTEXT
A @code{BLOB} or @code{TEXT} column with a maximum length of 16777215
(2^24 - 1) characters. @xref{Silent column changes}.
@tindex LONGBLOB
@tindex LONGTEXT
@item LONGBLOB
@itemx LONGTEXT
A @code{BLOB} or @code{TEXT} column with a maximum length of 4294967295
(2^32 - 1) characters. @xref{Silent column changes}.
@tindex ENUM
@item ENUM('value1','value2',...)
An enumeration.
A string object that can have only one value, chosen from the list of values
@code{'value1'}, @code{'value2'}, @code{...}, or @code{NULL}. An @code{ENUM}
can have a maximum of 65535 distinct values.
@tindex SET
@item SET('value1','value2',...)
A set. A string object that can have zero or more values, each of which must
be chosen from the list of values @code{'value1'}, @code{'value2'},
@code{...} A @code{SET} can have a maximum of 64 members.
@end table
@menu
* Storage requirements:: Column type storage requirements
* Numeric types:: Numeric types
* Date and time types:: Date and time types
* String types:: String types
* Choosing types:: Choosing the right type for a column
* Indexes:: Column indexes
* Multiple-column indexes:: Multiple-column indexes
* Other-vendor column types:: Using column types from other database engines
@end menu
@cindex Storage requirements
@node Storage requirements, Numeric types, Column types, Column types
@subsection Column type storage requirements
The storage requirements for each of the column types supported by
@strong{MySQL} are listed below by category.
@subheading Numeric types
@multitable @columnfractions .35 .65
@item @strong{Column type} @tab @strong{Storage required}
@item @code{TINYINT} @tab 1 byte
@item @code{SMALLINT} @tab 2 bytes
@item @code{MEDIUMINT} @tab 3 bytes
@item @code{INT} @tab 4 bytes
@item @code{INTEGER} @tab 4 bytes
@item @code{BIGINT} @tab 8 bytes
@item @code{FLOAT(X)} @tab 4 if X <= 24 or 8 if 25 <= X <= 53
@item @code{FLOAT} @tab 4 bytes
@item @code{DOUBLE} @tab 8 bytes
@item @code{DOUBLE PRECISION} @tab 8 bytes
@item @code{REAL} @tab 8 bytes
@item @code{DECIMAL(M,D)} @tab @code{M} bytes (@code{D}+2, if @code{M < D})
@item @code{NUMERIC(M,D)} @tab @code{M} bytes (@code{D}+2, if @code{M < D})
@end multitable
@subheading Date and time types
@multitable @columnfractions .35 .65
@item @strong{Column type} @tab @strong{Storage required}
@item @code{DATE} @tab 3 bytes
@item @code{DATETIME} @tab 8 bytes
@item @code{TIMESTAMP} @tab 4 bytes
@item @code{TIME} @tab 3 bytes
@item @code{YEAR} @tab 1 byte
@end multitable
@subheading String types
@multitable @columnfractions .35 .65
@item @strong{Column type} @tab @strong{Storage required}
@item @code{CHAR(M)} @tab @code{M} bytes, @code{1 <= M <= 255}
@item @code{VARCHAR(M)} @tab @code{L}+1 bytes, where @code{L <= M} and
@code{1 <= M <= 255}
@item @code{TINYBLOB}, @code{TINYTEXT} @tab @code{L}+1 bytes,
where @code{L} < 2^8
@item @code{BLOB}, @code{TEXT} @tab @code{L}+2 bytes,
where @code{L} < 2^16
@item @code{MEDIUMBLOB}, @code{MEDIUMTEXT} @tab @code{L}+3 bytes,
where @code{L} < 2^24
@item @code{LONGBLOB}, @code{LONGTEXT} @tab @code{L}+4 bytes,
where @code{L} < 2^32
@item @code{ENUM('value1','value2',...)} @tab 1 or 2 bytes, depending on
the number of enumeration values (65535 values maximum)
@item @code{SET('value1','value2',...)} @tab 1, 2, 3, 4 or 8 bytes, depending
on the number of set members (64 members maximum)
@end multitable
@code{VARCHAR} and the @code{BLOB} and @code{TEXT} types are variable-length
types, for which the storage requirements depend on the actual length of
column values (represented by @code{L} in the preceding table), rather than
on the type's maximum possible size. For example, a @code{VARCHAR(10)}
column can hold a string with a maximum length of 10 characters. The actual
storage required is the length of the string (@code{L}), plus 1 byte to
record the length of the string. For the string @code{'abcd'}, @code{L} is 4
and the storage requirement is 5 bytes.
The @code{BLOB} and @code{TEXT} types require 1, 2, 3 or 4 bytes to record
the length of the column value, depending on the maximum possible length of
the type.
If a table includes any variable-length column types, the record format will
also be variable-length. Note that when a table is created, @strong{MySQL}
may under certain conditions change a column from a variable-length type to a
fixed-length type, or vice-versa. @xref{Silent column changes}.
The size of an @code{ENUM} object is determined by the number of different
enumeration values. 1 byte is used for enumerations with up to 255 possible
values. 2 bytes are used for enumerations with up to 65535 values.
The size of a @code{SET} object is determined by the number of different
set members. If the set size is @code{N}, the object occupies @code{(N+7)/8}
bytes, rounded up to 1, 2, 3, 4 or 8 bytes. A @code{SET} can have a maximum
of 64 members.
@node Numeric types, Date and time types, Storage requirements, Column types
@subsection Numeric types
@strong{MySQL} supports all of the ANSI/ISO SQL92 numeric types. These
types include the exact numeric data types (@code{NUMERIC},
@code{DECIMAL}, @code{INTEGER}, and @code{SMALLINT}), as well as the
approximate numeric data types (@code{FLOAT}, @code{REAL}, and
@code{DOUBLE PRECISION}). The keyword @code{INT} is a synonym for
@code{INTEGER}, and the keyword @code{DEC} is a synonym for
@code{DECIMAL}.
The @code{NUMERIC} and @code{DECIMAL} types are implemented as the same
type by @strong{MySQL}, as permitted by the SQL92 standard. They are
used for values for which it is important to preserve exact precision,
for example with monetary data. When declaring a column of one of these
types the precision and scale can be (and usually is) specified; for
example:
@example
salary DECIMAL(9,2)
@end example
In this example, @code{9} (@code{precision}) represents the number of
significant decimal digits which will be stored for values, and
@code{2} (@code{scale}) represents the number of digits which will be
stored following the decimal point. In this case, therefore, the range
of values which can be stored in the @code{salary} column is from
@code{-9999999.99} to @code{9999999.99}. In ANSI/ISO SQL92, the syntax
@code{DECIMAL(p)} is equivalent to @code{DECIMAL(p,0)}. Similarly, the
syntax @code{DECIMAL} is equivalent to @code{DECIMAL(p,0)}, where the
implementation is allowed to decide the value of @code{p}.
@strong{MySQL} does not currently support either of these variant forms
of the @code{DECIMAL}/@code{NUMERIC} data types. This is not generally
a serious problem, as the principal benefits of these types derive from
the ability to control both precision and scale explicitly.
@code{DECIMAL} and @code{NUMERIC} values are stored as strings, rather
than as binary floating point numbers, in order to preserve the decimal
precision of those values. One character is used for each digit of the
value, the decimal point (if @code{scale} > 0) and the @samp{-} sign
(for negative numbers). If @code{scale} is 0, @code{DECIMAL} and
@code{NUMERIC} values contain no decimal point or fractional part.
The maximum range of @code{DECIMAL} and @code{NUMERIC} values is the
same as for @code{DOUBLE}, but the actual range for a given
@code{DECIMAL} or @code{NUMERIC} column can be constrained by the
@code{precision} or @code{scale} for a given column. When such a column
is assigned a value with more digits following the decimal point than
are allowed by the specified @code{scale}, the value is rounded to that
@code{scale}. When a @code{DECIMAL} or @code{NUMERIC} column is
assigned a value whose magnitude exceeds the range implied by the
specified (or defaulted) @code{precision} and @code{scale},
@strong{MySQL} stores the value representing the corresponding end
point of that range.
As an extension to the ANSI/ISO SQL92 standard, @strong{MySQL} also
supports the integral types @code{TINYINT}, @code{MEDIUMINT}, and
@code{BIGINT} as listed in the tables above. Another extension is
supported by @strong{MySQL} for optionally specifying the display width
of an integral value in parentheses following the base keyword for the
type (for example, @code{INT(4)}). This optional width specification is
used to left-pad the display of values whose width is less than the
width specified for the column, but does not constrain the range of
values which can be stored in the column, nor the number of digits which
will be displayed for values whose width exceeds that specified for the
column. When used in conjunction with the optional extension attribute
@code{ZEROFILL} the default padding of spaces is replaced with zeroes.
For example, for a column declared as @code{INT(5) ZEROFILL}, a value
of @code{4} is retrieved as @code{00004}. Note that if you store larger
values than the display width in an integral column, you may experience
problems when @strong{MySQL} generates temporary tables for some
complicated joins as in these case @strong{MySQL} trust that the data
did fit into the original column width.
All integral types can have an optional (non-standard) attribute
@code{UNSIGNED}. Unsigned values can be used when you want to allow
only positive numbers in a column and you need a little bigger numeric
range for the column.
The @code{FLOAT} type is used to represent approximate numeric data
types. The ANSI/ISO SQL92 standard allows an optional specification of
the precision (but not the range of the exponent) in bits following the
keyword @code{FLOAT} in parentheses. The @strong{MySQL} implementation
also supports this optional precision specification. When the keyword
@code{FLOAT} is used for a column type without a precision
specification, @strong{MySQL} uses four bytes to store the values. A
variant syntax is also supported, with two numbers given in parentheses
following the @code{FLOAT} keyword. With this option, the first number
continues to represent the storage requirements for the value in bytes,
and the second number specifies the number of digits to be stored and
displayed following the decimal point (as with @code{DECIMAL} and
@code{NUMERIC}). When @strong{MySQL} is asked to store a number for
such a column with more decimal digits following the decimal point than
specified for the column, the value is rounded to eliminate the extra
digits when the value is stored.
The @code{REAL} and @code{DOUBLE PRECISION} types do not accept
precision specifications. As an extension to the ANSI/ISO SQL92
standard, @strong{MySQL} recognizes @code{DOUBLE} as a synonym for the
@code{DOUBLE PRECISION} type. In contrast with the standard's
requirement that the precision for @code{REAL} be smaller than that used
for @code{DOUBLE PRECISION}, @strong{MySQL} implements both as 8-byte
double-precision floating point values (when running in non-"Ansi mode").
For maximum portability, code requiring storage of approximate numeric
data values should use @code{FLOAT} or @code{DOUBLE PRECISION} with no
specification of precision or number of decimal points.
When asked to store a value in a numeric column that is outside the column
type's allowable range, @strong{MySQL} clips the value to the appropriate
endpoint of the range and stores the resulting value instead.
For example, the range of an @code{INT} column is @code{-2147483648} to
@code{2147483647}. If you try to insert @code{-9999999999} into an
@code{INT} column, the value is clipped to the lower endpoint of the range,
and @code{-2147483648} is stored instead. Similarly, if you try to insert
@code{9999999999}, @code{2147483647} is stored instead.
If the @code{INT} column is @code{UNSIGNED}, the size of the column's
range is the same but its endpoints shift up to @code{0} and @code{4294967295}.
If you try to store @code{-9999999999} and @code{9999999999},
the values stored in the column become @code{0} and @code{4294967296}.
Conversions that occur due to clipping are reported as ``warnings'' for
@code{ALTER TABLE}, @code{LOAD DATA INFILE}, @code{UPDATE} and
multi-row @code{INSERT} statements.
@cindex Types, Date and Time
@cindex Date and Time types
@node Date and time types, String types, Numeric types, Column types
@subsection Date and time types
@menu
* Y2K issues:: Y2K issues and date types
* DATETIME:: The @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} types
* TIME:: The @code{TIME} type
* YEAR:: The @code{YEAR} type
@end menu
The date and time types are @code{DATETIME}, @code{DATE},
@code{TIMESTAMP}, @code{TIME} and @code{YEAR}. Each of these has a
range of legal values, as well as a ``zero'' value that is used when you
specify a really illegal value. Note that @strong{MySQL} allows you to store
certain 'not strictly' legal date values, for example @code{1999-11-31}.
The reason for this is that we think it's the responsibility of the
application to handle date checking, not the SQL servers. To make the
date checking 'fast', @strong{MySQL} only checks that the month is in
the range of 0-12 and the day is in the range of 0-31. The above ranges
are defined this way because @strong{MySQL} allows you to store, in a
@code{DATE} or @code{DATETIME} column, dates where the day or month-day
are zero. This is extremely useful for applications that need to store
a birth-date for which you don't know the exact date. In this case you
simply store the date like @code{1999-00-00} or @code{1999-01-00}. (You
can of course not expect to get a correct value from functions like
@code{DATE_SUB()} or @code{DATE_ADD} for dates like these).
Here are some general considerations to keep in mind when working
with date and time types:
@itemize @bullet
@item
@strong{MySQL} retrieves values for a given date or time type in a standard
format, but it attempts to interpret a variety of formats for values that
you supply (e.g., when you specify a value to be assigned to or compared to a
date or time type). Nevertheless, only the formats described in the
following sections are supported. It is expected that you will supply legal
values, and unpredictable results may occur if you use values in other
formats.
@item
Although @strong{MySQL} tries to interpret values in several formats, it
always expects the year part of date values to be leftmost. Dates must be
given in year-month-day order (e.g., @code{'98-09-04'}), rather than in the
month-day-year or day-month-year orders commonly used elsewhere (e.g.,
@code{'09-04-98'}, @code{'04-09-98'}).
@item
@strong{MySQL} automatically converts a date or time type value to a number
if the value is used in a numeric context, and vice versa.
@item
When @strong{MySQL} encounters a value for a date or time type that is
out of range or otherwise illegal for the type (see start of this
section), it converts the value to the ``zero'' value for that type.
(The exception is that out-of-range @code{TIME} values are clipped to
the appropriate endpoint of the @code{TIME} range.) The table below
shows the format of the ``zero'' value for each type:
@multitable @columnfractions .3 .7
@item @strong{Column type} @tab @strong{``Zero'' value}
@item @code{DATETIME} @tab @code{'0000-00-00 00:00:00'}
@item @code{DATE} @tab @code{'0000-00-00'}
@item @code{TIMESTAMP} @tab @code{00000000000000} (length depends on display size)
@item @code{TIME} @tab @code{'00:00:00'}
@item @code{YEAR} @tab @code{0000}
@end multitable
@item
The ``zero'' values are special, but you can store or refer to them
explicitly using the values shown in the table. You can also do this
using the values @code{'0'} or @code{0}, which are easier to write.
@item
``Zero'' date or time values used through @strong{MyODBC} are converted
automatically to @code{NULL} in @strong{MyODBC} 2.50.12 and above, because
ODBC can't handle such values.
@end itemize
@cindex Year 2000 issues
@node Y2K issues, DATETIME, Date and time types, Date and time types
@subsubsection Y2K issues and date types
@strong{MySQL} itself is Y2K-safe (@pxref{Year 2000 compliance}),
but input values presented to @strong{MySQL} may not be. Any input
containing 2-digit year values is ambiguous, because the century is unknown.
Such values must be interpreted into 4-digit form because @strong{MySQL} stores
years internally using four digits.
For @code{DATETIME}, @code{DATE}, @code{TIMESTAMP} and @code{YEAR} types,
@strong{MySQL} interprets dates with ambiguous year values using the
following rules:
@itemize @bullet
@item
Year values in the range @code{00-69} are converted to @code{2000-2069}.
@item
Year values in the range @code{70-99} are converted to @code{1970-1999}.
@end itemize
Remember that these rules provide only reasonable guesses as to what your
data mean. If the heuristics used by @strong{MySQL} don't produce the
correct values, you should provide unambiguous input containing 4-digit
year values.
@code{ORDER BY} will sort 2 digit @code{YEAR/DATE/DATETIME} types properly.
Note also that some functions like @code{MIN()} and @code{MAX()} will convert a
@code{TIMESTAMP/DATE} to a number. This means that a timestamp with a 2
digit year will not work properly with these functions. The fix in this
case is to convert the @code{TIMESTAMP/DATE} to 4 digit year format or
use something like @code{MIN(DATE_ADD(timestamp,INTERVAL 0 DAYS))}.
@tindex DATETIME
@tindex DATE
@tindex TIMESTAMP
@node DATETIME, TIME, Y2K issues, Date and time types
@subsubsection The @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} types
The @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} types are related.
This section describes their characteristics, how they are similar and how
they differ.
The @code{DATETIME} type is used when you need values that contain both date
and time information. @strong{MySQL} retrieves and displays @code{DATETIME}
values in @code{'YYYY-MM-DD HH:MM:SS'} format. The supported range is
@code{'1000-01-01 00:00:00'} to @code{'9999-12-31 23:59:59'}. (``Supported''
means that although earlier values might work, there is no guarantee that
they will.)
The @code{DATE} type is used when you need only a date value, without a time
part. @strong{MySQL} retrieves and displays @code{DATE} values in
@code{'YYYY-MM-DD'} format. The supported range is @code{'1000-01-01'} to
@code{'9999-12-31'}.
The @code{TIMESTAMP} column type provides a type that you can use to
automatically mark @code{INSERT} or @code{UPDATE} operations with the current
date and time. If you have multiple @code{TIMESTAMP} columns, only the first
one is updated automatically.
Automatic updating of the first @code{TIMESTAMP} column occurs under any of
the following conditions:
@itemize @bullet
@item
The column is not specified explicitly in an @code{INSERT} or
@code{LOAD DATA INFILE} statement.
@item
The column is not specified explicitly in an @code{UPDATE} statement and some
other column changes value. (Note that an @code{UPDATE} that sets a column
to the value it already has will not cause the @code{TIMESTAMP} column to be
updated, because if you set a column to its current value, @strong{MySQL}
ignores the update for efficiency.)
@item
You explicitly set the @code{TIMESTAMP} column to @code{NULL}.
@end itemize
@code{TIMESTAMP} columns other than the first may also be set to the current
date and time. Just set the column to @code{NULL}, or to @code{NOW()}.
You can set any @code{TIMESTAMP} column to a value different than the current
date and time by setting it explicitly to the desired value. This is true
even for the first @code{TIMESTAMP} column. You can use this property if,
for example, you want a @code{TIMESTAMP} to be set to the current date and
time when you create a row, but not to be changed whenever the row is updated
later:
@itemize @bullet
@item
Let @strong{MySQL} set the column when the row is created.
This will initialize it to the current date and time.
@item
When you perform subsequent updates to other columns in the row, set
the @code{TIMESTAMP} column explicitly to its current value.
@end itemize
On the other hand, you may find it just as easy to use a @code{DATETIME}
column that you initialize to @code{NOW()} when the row is created and
leave alone for subsequent updates.
@code{TIMESTAMP} values may range from the beginning of 1970 to sometime in
the year 2037, with a resolution of one second. Values are displayed as
numbers.
The format in which @strong{MySQL} retrieves and displays @code{TIMESTAMP}
values depends on the display size, as illustrated by the table below. The
`full' @code{TIMESTAMP} format is 14 digits, but @code{TIMESTAMP} columns may
be created with shorter display sizes:
@multitable @columnfractions .3 .7
@item @strong{Column type} @tab @strong{Display format}
@item @code{TIMESTAMP(14)} @tab @code{YYYYMMDDHHMMSS}
@item @code{TIMESTAMP(12)} @tab @code{YYMMDDHHMMSS}
@item @code{TIMESTAMP(10)} @tab @code{YYMMDDHHMM}
@item @code{TIMESTAMP(8)} @tab @code{YYYYMMDD}
@item @code{TIMESTAMP(6)} @tab @code{YYMMDD}
@item @code{TIMESTAMP(4)} @tab @code{YYMM}
@item @code{TIMESTAMP(2)} @tab @code{YY}
@end multitable
All @code{TIMESTAMP} columns have the same storage size, regardless of
display size. The most common display sizes are 6, 8, 12, and 14. You can
specify an arbitrary display size at table creation time, but values of 0 or
greater than 14 are coerced to 14. Odd-valued sizes in the range from 1 to
13 are coerced to the next higher even number.
You can specify @code{DATETIME}, @code{DATE} and @code{TIMESTAMP} values using
any of a common set of formats:
@itemize @bullet
@item
As a string in either @code{'YYYY-MM-DD HH:MM:SS'} or @code{'YY-MM-DD
HH:MM:SS'} format. A ``relaxed'' syntax is allowed---any punctuation
character may be used as the delimiter between date parts or time parts.
For example, @code{'98-12-31 11:30:45'}, @code{'98.12.31 11+30+45'},
@code{'98/12/31 11*30*45'} and @code{'98@@12@@31 11^30^45'} are
equivalent.
@item
As a string in either @code{'YYYY-MM-DD'} or @code{'YY-MM-DD'} format.
A ``relaxed'' syntax is allowed here, too. For example, @code{'98-12-31'},
@code{'98.12.31'}, @code{'98/12/31'} and @code{'98@@12@@31'} are
equivalent.
@item
As a string with no delimiters in either @code{'YYYYMMDDHHMMSS'} or
@code{'YYMMDDHHMMSS'} format, provided that the string makes sense as a
date. For example, @code{'19970523091528'} and @code{'970523091528'} are
interpreted as @code{'1997-05-23 09:15:28'}, but @code{'971122129015'} is
illegal (it has a nonsensical minute part) and becomes @code{'0000-00-00
00:00:00'}.
@item
As a string with no delimiters in either @code{'YYYYMMDD'} or @code{'YYMMDD'}
format, provided that the string makes sense as a date. For example,
@code{'19970523'} and @code{'970523'} are interpreted as
@code{'1997-05-23'}, but @code{'971332'} is illegal (it has nonsensical month
and day parts) and becomes @code{'0000-00-00'}.
@item
As a number in either @code{YYYYMMDDHHMMSS} or @code{YYMMDDHHMMSS}
format, provided that the number makes sense as a date. For example,
@code{19830905132800} and @code{830905132800} are interpreted as
@code{'1983-09-05 13:28:00'}.
@item
As a number in either @code{YYYYMMDD} or @code{YYMMDD}
format, provided that the number makes sense as a date. For example,
@code{19830905} and @code{830905} are interpreted as @code{'1983-09-05'}.
@item
As the result of a function that returns a value that is acceptable
in a @code{DATETIME}, @code{DATE} or @code{TIMESTAMP} context, such as
@code{NOW()} or @code{CURRENT_DATE}.
@end itemize
Illegal @code{DATETIME}, @code{DATE} or @code{TIMESTAMP} values are converted
to the ``zero'' value of the appropriate type (@code{'0000-00-00 00:00:00'},
@code{'0000-00-00'} or @code{00000000000000}).
For values specified as strings that include date part delimiters, it is not
necessary to specify two digits for month or day values that are less than
@code{10}. @code{'1979-6-9'} is the same as @code{'1979-06-09'}. Similarly,
for values specified as strings that include time part delimiters, it is not
necessary to specify two digits for hour, month or second values that are
less than @code{10}. @code{'1979-10-30 1:2:3'} is the same as
@code{'1979-10-30 01:02:03'}.
Values specified as numbers should be 6, 8, 12 or 14 digits long. If the
number is 8 or 14 digits long, it is assumed to be in @code{YYYYMMDD} or
@code{YYYYMMDDHHMMSS} format and that the year is given by the first 4
digits. If the number is 6 or 12 digits long, it is assumed to be in
@code{YYMMDD} or @code{YYMMDDHHMMSS} format and that the year is given by the
first 2 digits. Numbers that are not one of these lengths are interpreted
as though padded with leading zeros to the closest length.
Values specified as non-delimited strings are interpreted using their length
as given. If the string is 8 or 14 characters long, the year is assumed to
be given by the first 4 characters. Otherwise the year is assumed to be
given by the first 2 characters. The string is interpreted from left to
right to find year, month, day, hour, minute and second values, for as many
parts as are present in the string. This means you should not use strings
that have fewer than 6 characters. For example, if you specify @code{'9903'},
thinking that will represent March, 1999, you will find that @strong{MySQL}
inserts a ``zero'' date into your table. This is because the year and month
values are @code{99} and @code{03}, but the day part is missing (zero), so
the value is not a legal date.
@code{TIMESTAMP} columns store legal values using the full precision with
which the value was specified, regardless of the display size. This has
several implications:
@itemize @bullet
@item
Always specify year, month, and day, even if your column types are
@code{TIMESTAMP(4)} or @code{TIMESTAMP(2)}. Otherwise, the value will not
be a legal date and @code{0} will be stored.
@item
If you use @code{ALTER TABLE} to widen a narrow @code{TIMESTAMP} column,
information will be displayed that previously was ``hidden''.
@item
Similarly, narrowing a @code{TIMESTAMP} column does not cause information to
be lost, except in the sense that less information is shown when the values
are displayed.
@item
Although @code{TIMESTAMP} values are stored to full precision, the only
function that operates directly on the underlying stored value is
@code{UNIX_TIMESTAMP()}. Other functions operate on the formatted retrieved
value. This means you cannot use functions such as @code{HOUR()} or
@code{SECOND()} unless the relevant part of the @code{TIMESTAMP} value is
included in the formatted value. For example, the @code{HH} part of a
@code{TIMESTAMP} column is not displayed unless the display size is at least
10, so trying to use @code{HOUR()} on shorter @code{TIMESTAMP} values
produces a meaningless result.
@end itemize
You can to some extent assign values of one date type to an object
of a different date type. However, there may be some alteration
of the value or loss of information:
@itemize @bullet
@item
If you assign a @code{DATE} value to a @code{DATETIME} or @code{TIMESTAMP}
object, the time part of the resulting value is set to @code{'00:00:00'},
because the @code{DATE} value contains no time information.
@item
If you assign a @code{DATETIME} or @code{TIMESTAMP} value to a @code{DATE}
object, the time part of the resulting value is deleted, because the
@code{DATE} type stores no time information.
@item
Remember that although @code{DATETIME}, @code{DATE} and @code{TIMESTAMP}
values all can be specified using the same set of formats, the types do not
all have the same range of values. For example, @code{TIMESTAMP} values
cannot be earlier than @code{1970} or later than @code{2037}. This means
that a date such as @code{'1968-01-01'}, while legal as a @code{DATETIME} or
@code{DATE} value, is not a valid @code{TIMESTAMP} value and will be
converted to @code{0} if assigned to such an object.
@end itemize
Be aware of certain pitfalls when specifying date values:
@itemize @bullet
@item
The relaxed format allowed for values specified as strings can be deceiving.
For example, a value such as @code{'10:11:12'} might look like a time value
because of the @samp{:} delimiter, but if used in a date context will be
interpreted as the year @code{'2010-11-12'}. The value @code{'10:45:15'}
will be converted to @code{'0000-00-00'} because @code{'45'} is not a legal
month.
@item
Year values specified as two digits are ambiguous, because the century is
unknown. @strong{MySQL} interprets 2-digit year values using the following
rules:
@itemize @minus
@item
Year values in the range @code{00-69} are converted to @code{2000-2069}.
@item
Year values in the range @code{70-99} are converted to @code{1970-1999}.
@end itemize
@end itemize
@tindex TIME
@node TIME, YEAR, DATETIME, Date and time types
@subsubsection The @code{TIME} type
@strong{MySQL} retrieves and displays @code{TIME} values in @code{'HH:MM:SS'}
format (or @code{'HHH:MM:SS'} format for large hours values). @code{TIME}
values may range from @code{'-838:59:59'} to @code{'838:59:59'}. The reason
the hours part may be so large is that the @code{TIME} type may be used not
only to represent a time of day (which must be less than 24 hours), but also
elapsed time or a time interval between two events (which may be much greater
than 24 hours, or even negative).
You can specify @code{TIME} values in a variety of formats:
@itemize @bullet
@item
As a string in @code{'D HH:MM:SS.fraction'} format. (Note that
@strong{MySQL} doesn't yet store the fraction for the time column). One
can also use one of the following ``relaxed'' syntax:
@code{HH:MM:SS.fraction}, @code{HH:MM:SS}, @code{HH:MM}, @code{D HH:MM:SS},
@code{D HH:MM}, @code{D HH} or @code{SS}. Here @code{D} is days between 0-33.
@item
As a string with no delimiters in @code{'HHMMSS'} format, provided that
it makes sense as a time. For example, @code{'101112'} is understood as
@code{'10:11:12'}, but @code{'109712'} is illegal (it has a nonsensical
minute part) and becomes @code{'00:00:00'}.
@item
As a number in @code{HHMMSS} format, provided that it makes sense as a time.
For example, @code{101112} is understood as @code{'10:11:12'}. The following
alternative formats are also understood: @code{SS}, @code{MMSS},@code{HHMMSS},
@code{HHMMSS.fraction}. Note that @strong{MySQL} doesn't yet store the
fraction part.
@item
As the result of a function that returns a value that is acceptable
in a @code{TIME} context, such as @code{CURRENT_TIME}.
@end itemize
For @code{TIME} values specified as strings that include a time part
delimiter, it is not necessary to specify two digits for hours, minutes or
seconds values that are less than @code{10}. @code{'8:3:2'} is the same as
@code{'08:03:02'}.
Be careful about assigning ``short'' @code{TIME} values to a @code{TIME}
column. @strong{MySQL} interprets values using the assumption that the
rightmost digits represent seconds. (@strong{MySQL} interprets @code{TIME}
values as elapsed time, rather than as time of day.) For example, you might
think of @code{'11:12'}, @code{'1112'} and @code{1112} as meaning
@code{'11:12:00'} (12 minutes after 11 o'clock), but @strong{MySQL}
interprets them as @code{'00:11:12'} (11 minutes, 12 seconds). Similarly,
@code{'12'} and @code{12} are interpreted as @code{'00:00:12'}.
Values that lie outside the @code{TIME} range
but are otherwise legal are clipped to the appropriate
endpoint of the range. For example, @code{'-850:00:00'} and
@code{'850:00:00'} are converted to @code{'-838:59:59'} and
@code{'838:59:59'}.
Illegal @code{TIME} values are converted to @code{'00:00:00'}. Note that
because @code{'00:00:00'} is itself a legal @code{TIME} value, there is no way
to tell, from a value of @code{'00:00:00'} stored in a table, whether the
original value was specified as @code{'00:00:00'} or whether it was illegal.
@tindex YEAR
@node YEAR, , TIME, Date and time types
@subsubsection The @code{YEAR} type
The @code{YEAR} type is a 1-byte type used for representing years.
@strong{MySQL} retrieves and displays @code{YEAR} values in @code{YYYY}
format. The range is @code{1901} to @code{2155}.
You can specify @code{YEAR} values in a variety of formats:
@itemize @bullet
@item
As a four-digit string in the range @code{'1901'} to @code{'2155'}.
@item
As a four-digit number in the range @code{1901} to @code{2155}.
@item
As a two-digit string in the range @code{'00'} to @code{'99'}. Values in the
ranges @code{'00'} to @code{'69'} and @code{'70'} to @code{'99'} are
converted to @code{YEAR} values in the ranges @code{2000} to @code{2069} and
@code{1970} to @code{1999}.
@item
As a two-digit number in the range @code{1} to @code{99}. Values in the
ranges @code{1} to @code{69} and @code{70} to @code{99} are converted to
@code{YEAR} values in the ranges @code{2001} to @code{2069} and @code{1970}
to @code{1999}. Note that the range for two-digit numbers is slightly
different than the range for two-digit strings, because you cannot specify zero
directly as a number and have it be interpreted as @code{2000}. You
@emph{must} specify it as a string @code{'0'} or @code{'00'} or it will be
interpreted as @code{0000}.
@item
As the result of a function that returns a value that is acceptable
in a @code{YEAR} context, such as @code{NOW()}.
@end itemize
Illegal @code{YEAR} values are converted to @code{0000}.
@node String types, Choosing types, Date and time types, Column types
@subsection String types
The string types are @code{CHAR}, @code{VARCHAR}, @code{BLOB}, @code{TEXT},
@code{ENUM} and @code{SET}.
@tindex CHAR
@tindex VARCHAR
@menu
* CHAR:: The @code{CHAR} and @code{VARCHAR} types
* BLOB:: The @code{BLOB} and @code{TEXT} types
* ENUM:: The @code{ENUM} type
* SET:: The @code{SET} type
@end menu
@node CHAR, BLOB, String types, String types
@subsubsection The @code{CHAR} and @code{VARCHAR} types
The @code{CHAR} and @code{VARCHAR} types are similar, but differ in the
way they are stored and retrieved.
The length of a @code{CHAR} column is fixed to the length that you declare
when you create the table. The length can be any value between 1 and 255.
(As of @strong{MySQL} 3.23, the length of @code{CHAR} may be 0 to 255.)
When @code{CHAR} values are stored, they are right-padded with spaces to the
specified length. When @code{CHAR} values are retrieved, trailing spaces are
removed.
Values in @code{VARCHAR} columns are variable-length strings. You can
declare a @code{VARCHAR} column to be any length between 1 and 255, just as
for @code{CHAR} columns. However, in contrast to @code{CHAR}, @code{VARCHAR}
values are stored using only as many characters as are needed, plus one byte
to record the length. Values are not padded; instead, trailing spaces are
removed when values are stored. (This space removal differs from the ANSI
SQL specification.)
If you assign a value to a @code{CHAR} or @code{VARCHAR} column that
exceeds the column's maximum length, the value is truncated to fit.
The table below illustrates the differences between the two types of columns
by showing the result of storing various string values into @code{CHAR(4)}
and @code{VARCHAR(4)} columns:
@c Need to use @(space) to make sure second column values retain spacing
@c in output for table below.
@multitable @columnfractions .2 .15 .2 .2 .25
@item @strong{Value} @tab @code{CHAR(4)} @tab @strong{Storage required} @tab @code{VARCHAR(4)} @tab @strong{Storage required}
@item @code{''} @tab @code{'@ @ @ @ '} @tab 4 bytes @tab @code{''} @tab 1 byte
@item @code{'ab'} @tab @code{'ab@ @ '} @tab 4 bytes @tab @code{'ab'} @tab 3 bytes
@item @code{'abcd'} @tab @code{'abcd'} @tab 4 bytes @tab @code{'abcd'} @tab 5 bytes
@item @code{'abcdefgh'} @tab @code{'abcd'} @tab 4 bytes @tab @code{'abcd'} @tab 5 bytes
@end multitable
The values retrieved from the @code{CHAR(4)} and @code{VARCHAR(4)} columns
will be the same in each case, because trailing spaces are removed from
@code{CHAR} columns upon retrieval.
Values in @code{CHAR} and @code{VARCHAR} columns are sorted and compared in
case-insensitive fashion, unless the @code{BINARY} attribute was specified
when the table was created. The @code{BINARY} attribute means that column
values are sorted and compared in case-sensitive fashion according to the
ASCII order of the machine where the @strong{MySQL} server is running.
The @code{BINARY} attribute is ``sticky''. This means that if a column marked
@code{BINARY} is used in an expression, the whole expression is compared as a
@code{BINARY} value.
@strong{MySQL} may silently change the type of a @code{CHAR} or @code{VARCHAR}
column at table creation time.
@xref{Silent column changes}.
@tindex BLOB
@tindex TEXT
@node BLOB, ENUM, CHAR, String types
@subsubsection The @code{BLOB} and @code{TEXT} types
A @code{BLOB} is a binary large object that can hold a variable amount of
data. The four @code{BLOB} types @code{TINYBLOB}, @code{BLOB},
@code{MEDIUMBLOB} and @code{LONGBLOB} differ only in the maximum length of
the values they can hold.
@xref{Storage requirements}.
The four @code{TEXT} types @code{TINYTEXT}, @code{TEXT}, @code{MEDIUMTEXT}
and @code{LONGTEXT} correspond to the four @code{BLOB} types and have the
same maximum lengths and storage requirements. The only difference between
@code{BLOB} and @code{TEXT} types is that sorting and comparison is performed
in case-sensitive fashion for @code{BLOB} values and case-insensitive fashion
for @code{TEXT} values. In other words, a @code{TEXT} is a case-insensitive
@code{BLOB}.
If you assign a value to a @code{BLOB} or @code{TEXT} column that exceeds
the column type's maximum length, the value is truncated to fit.
In most respects, you can regard a @code{TEXT} column as a @code{VARCHAR}
column that can be as big as you like. Similarly, you can regard a
@code{BLOB} column as a @code{VARCHAR BINARY} column. The differences are:
@itemize @bullet
@item
You can have indexes on @code{BLOB} and @code{TEXT} columns with
@strong{MySQL} versions 3.23.2 and newer. Older versions of
@strong{MySQL} did not support this.
@item
There is no trailing-space removal for @code{BLOB} and @code{TEXT} columns
when values are stored, as there is for @code{VARCHAR} columns.
@item
@cindex Default values, @code{BLOB} and @code{TEXT} columns
@cindex @code{BLOB} columns, default values
@cindex @code{TEXT} columns, default values
@code{BLOB} and @code{TEXT} columns cannot have @code{DEFAULT} values.
@end itemize
@strong{MyODBC} defines @code{BLOB} values as @code{LONGVARBINARY} and
@code{TEXT} values as @code{LONGVARCHAR}.
Because @code{BLOB} and @code{TEXT} values may be extremely long, you
may run up against some constraints when using them:
@itemize @bullet
@item
If you want to use @code{GROUP BY} or @code{ORDER BY} on a @code{BLOB} or
@code{TEXT} column, you must convert the column value into a fixed-length
object. The standard way to do this is with the @code{SUBSTRING}
function. For example:
@example
mysql> select comment from tbl_name,substring(comment,20) as substr
ORDER BY substr;
@end example
If you don't do this, only the first @code{max_sort_length} bytes of the
column are used when sorting. The default value of @code{max_sort_length} is
1024; this value can be changed using the @code{-O} option when starting the
@code{mysqld} server. You can group on an expression involving @code{BLOB} or
@code{TEXT} values by specifying the column position or by using an alias:
@example
mysql> select id,substring(blob_col,1,100) from tbl_name
GROUP BY 2;
mysql> select id,substring(blob_col,1,100) as b from tbl_name
GROUP BY b;
@end example
@item
The maximum size of a @code{BLOB} or @code{TEXT} object is determined by its
type, but the largest value you can actually transmit between the client and
server is determined by the amount of available memory and the size of the
communications buffers. You can change the message buffer size, but you must
do so on both the server and client ends. @xref{Server parameters}.
@end itemize
Note that each @code{BLOB} or @code{TEXT} value is represented internally by
a separately-allocated object. This is in contrast to all other column types,
for which storage is allocated once per column when the table is opened.
@tindex ENUM
@node ENUM, SET, BLOB, String types
@subsubsection The @code{ENUM} type
An @code{ENUM} is a string object whose value normally is chosen from a list
of allowed values that are enumerated explicitly in the column specification
at table creation time.
The value may also be the empty string (@code{""}) or @code{NULL} under
certain circumstances:
@itemize @bullet
@item
If you insert an invalid value into an @code{ENUM} (that is, a string not
present in the list of allowed values), the empty string is inserted
instead as a special error value.
@item
If an @code{ENUM} is declared @code{NULL}, @code{NULL} is also a legal value
for the column, and the default value is @code{NULL}. If an @code{ENUM} is
declared @code{NOT NULL}, the default value is the first element of the
list of allowed values.
@end itemize
Each enumeration value has an index:
@itemize @bullet
@item
Values from the list of allowable elements in the column specification are
numbered beginning with 1.
@item
The index value of the empty string error value is 0. This means that you
can use the following @code{SELECT} statement to find rows into which invalid
@code{ENUM} values were assigned:
@example
mysql> SELECT * FROM tbl_name WHERE enum_col=0;
@end example
@item
The index of the @code{NULL} value is @code{NULL}.
@end itemize
For example, a column specified as @code{ENUM("one", "two", "three")} can
have any of the values shown below. The index of each value is also shown:
@multitable @columnfractions .2 .8
@item @strong{Value} @tab @strong{Index}
@item @code{NULL} @tab @code{NULL}
@item @code{""} @tab 0
@item @code{"one"} @tab 1
@item @code{"two"} @tab 2
@item @code{"three"} @tab 3
@end multitable
An enumeration can have a maximum of 65535 elements.
Lettercase is irrelevant when you assign values to an @code{ENUM} column.
However, values retrieved from the column later have lettercase matching the
values that were used to specify the allowable values at table creation time.
If you retrieve an @code{ENUM} in a numeric context, the column value's index
is returned. If you store a number into an @code{ENUM}, the number is
treated as an index, and the the value stored is the enumeration member with
that index. (However, this will not work with @code{LOAD DATA}, which treats
all input as strings.)
@code{ENUM} values are sorted according to the order in which the enumeration
members were listed in the column specification. (In other words,
@code{ENUM} values are sorted according to their index numbers.) For
example, @code{"a"} sorts before @code{"b"} for @code{ENUM("a", "b")}, but
@code{"b"} sorts before @code{"a"} for @code{ENUM("b", "a")}. The empty
string sorts before non-empty strings, and @code{NULL} values sort before
all other enumeration values.
If you want to get all possible values for an @code{ENUM} column, you should
use: @code{SHOW COLUMNS FROM table_name LIKE enum_column_name} and parse
the @code{ENUM} definition in the second column.
@tindex SET
@node SET, , ENUM, String types
@subsubsection The @code{SET} type
A @code{SET} is a string object that can have zero or more values, each of
which must be chosen from a list of allowed values specified when the table
is created. @code{SET} column values that consist of multiple set members
are specified with members separated by commas (@samp{,}). A consequence of
this is that @code{SET} member values cannot themselves contain commas.
For example, a column specified as @code{SET("one", "two") NOT NULL} can have
any of these values:
@example
""
"one"
"two"
"one,two"
@end example
A @code{SET} can have a maximum of 64 different members.
@strong{MySQL} stores @code{SET} values numerically, with the low-order bit
of the stored value corresponding to the first set member. If you retrieve a
@code{SET} value in a numeric context, the value retrieved has bits set
corresponding to the set members that make up the column value. If a number
is stored into a @code{SET} column, the bits that are set in the binary
representation of the number determine the set members in the column value.
Suppose a column is specified as @code{SET("a","b","c","d")}. Then the
members have the following bit values:
@multitable @columnfractions .2 .2 .6
@item @code{SET} @strong{member} @tab @strong{Decimal value} @tab @strong{Binary value}
@item @code{a} @tab @code{1} @tab @code{0001}
@item @code{b} @tab @code{2} @tab @code{0010}
@item @code{c} @tab @code{4} @tab @code{0100}
@item @code{d} @tab @code{8} @tab @code{1000}
@end multitable
If you assign a value of @code{9} to this column, that is @code{1001} in
binary, so the first and fourth @code{SET} value members @code{"a"} and
@code{"d"} are selected and the resulting value is @code{"a,d"}.
For a value containing more than one @code{SET} element, it does not matter
what order the elements are listed in when you insert the value. It also
does not matter how many times a given element is listed in the value.
When the value is retrieved later, each element in the value will appear
once, with elements listed according to the order in which they were
specified at table creation time. For example, if a column is specified as
@code{SET("a","b","c","d")}, then @code{"a,d"}, @code{"d,a"} and
@code{"d,a,a,d,d"} will all appear as @code{"a,d"} when retrieved.
@code{SET} values are sorted numerically. @code{NULL} values sort before
non-@code{NULL} @code{SET} values.
Normally, you perform a @code{SELECT} on a @code{SET} column using
the @code{LIKE} operator or the @code{FIND_IN_SET()} function:
@example
mysql> SELECT * FROM tbl_name WHERE set_col LIKE '%value%';
mysql> SELECT * FROM tbl_name WHERE FIND_IN_SET('value',set_col)>0;
@end example
But the following will also work:
@example
mysql> SELECT * FROM tbl_name WHERE set_col = 'val1,val2';
mysql> SELECT * FROM tbl_name WHERE set_col & 1;
@end example
The first of these statements looks for an exact match. The second looks
for values containing the first set member.
If you want to get all possible values for a @code{SET} column, you should
use: @code{SHOW COLUMNS FROM table_name LIKE set_column_name} and parse
the @code{SET} definition in the second column.
@cindex Types, choosing
@cindex Choosing types
@node Choosing types, Indexes, String types, Column types
@subsection Choosing the right type for a column
For the most efficient use of storage, try to use the most precise type in
all cases. For example, if an integer column will be used for values in the
range between @code{1} and @code{99999}, @code{MEDIUMINT UNSIGNED} is the
best type.
Accurate representation of monetary values is a common problem. In
@strong{MySQL}, you should use the @code{DECIMAL} type. This is stored as
a string, so no loss of accuracy should occur. If accuracy is not
too important, the @code{DOUBLE} type may also be good enough.
For high precision, you can always convert to a fixed-point type stored
in a @code{BIGINT}. This allows you to do all calculations with integers
and convert results back to floating-point values only when necessary.
@cindex Indexes
@cindex Keys
@node Indexes, Multiple-column indexes, Choosing types, Column types
@subsection Column indexes
All @strong{MySQL} column types can be indexed. Use of indexes on the
relevant columns is the best way to improve the performance of @code{SELECT}
operations.
A table may have up to 16 indexes. The maximum index length is
256 bytes, although this may be changed when compiling @strong{MySQL}.
For @code{CHAR} and @code{VARCHAR} columns, you can index a prefix of a
column. This is much faster and requires less disk space than indexing the
whole column. The syntax to use in the @code{CREATE TABLE} statement to
index a column prefix looks like this:
@example
KEY index_name (col_name(length))
@end example
The example below creates an index for the first 10 characters of the
@code{name} column:
@example
mysql> CREATE TABLE test (
name CHAR(200) NOT NULL,
KEY index_name (name(10)));
@end example
For @code{BLOB} and @code{TEXT} columns, you must index a prefix of the
column, you cannot index the entire thing.
@node Multiple-column indexes, Other-vendor column types, Indexes, Column types
@subsection Multiple-column indexes
@strong{MySQL} can create indexes on multiple columns. An index may
consist of up to 15 columns. (On @code{CHAR} and @code{VARCHAR} columns you
can also use a prefix of the column as a part of an index).
A multiple-column index can be considered a sorted array containing values
that are created by concatenating the values of the indexed columns.
@strong{MySQL} uses multiple-column indexes in such a way that queries are
fast when you specify a known quantity for the first column of the index in a
@code{WHERE} clause, even if you don't specify values for the other columns.
Suppose a table is created using the following specification:
@example
mysql> CREATE TABLE test (
id INT NOT NULL,
last_name CHAR(30) NOT NULL,
first_name CHAR(30) NOT NULL,
PRIMARY KEY (id),
INDEX name (last_name,first_name));
@end example
Then the index @code{name} is an index over @code{last_name} and
@code{first_name}. The index will be used for queries that specify
values in a known range for @code{last_name}, or for both @code{last_name}
and @code{first_name}.
Therefore, the @code{name} index will be used in the following queries:
@example
mysql> SELECT * FROM test WHERE last_name="Widenius";
mysql> SELECT * FROM test WHERE last_name="Widenius"
AND first_name="Michael";
mysql> SELECT * FROM test WHERE last_name="Widenius"
AND (first_name="Michael" OR first_name="Monty");
mysql> SELECT * FROM test WHERE last_name="Widenius"
AND first_name >="M" AND first_name < "N";
@end example
However, the @code{name} index will NOT be used in the following queries:
@example
mysql> SELECT * FROM test WHERE first_name="Michael";
mysql> SELECT * FROM test WHERE last_name="Widenius"
OR first_name="Michael";
@end example
For more information on the manner in which @strong{MySQL} uses indexes to
improve query performance, see @ref{MySQL indexes, , @strong{MySQL}
indexes}.
@cindex Type portability
@node Other-vendor column types, , Multiple-column indexes, Column types
@subsection Using column types from other database engines
To make it easier to use code written for SQL implementations from other
vendors, @strong{MySQL} maps column types as shown in the table below. These
mappings make it easier to move table definitions from other database engines
to @strong{MySQL}:
@multitable @columnfractions .4 .6
@item @strong{Other vendor type} @tab @strong{MySQL type}
@item @code{BINARY(NUM)} @tab @code{CHAR(NUM) BINARY}
@item @code{CHAR VARYING(NUM)} @tab @code{VARCHAR(NUM)}
@item @code{FLOAT4} @tab @code{FLOAT}
@item @code{FLOAT8} @tab @code{DOUBLE}
@item @code{INT1} @tab @code{TINYINT}
@item @code{INT2} @tab @code{SMALLINT}
@item @code{INT3} @tab @code{MEDIUMINT}
@item @code{INT4} @tab @code{INT}
@item @code{INT8} @tab @code{BIGINT}
@item @code{LONG VARBINARY} @tab @code{MEDIUMBLOB}
@item @code{LONG VARCHAR} @tab @code{MEDIUMTEXT}
@item @code{MIDDLEINT} @tab @code{MEDIUMINT}
@item @code{VARBINARY(NUM)} @tab @code{VARCHAR(NUM) BINARY}
@end multitable
Column type mapping occurs at table creation time. If you create a table
with types used by other vendors and then issue a @code{DESCRIBE tbl_name}
statement, @strong{MySQL} reports the table structure using the equivalent
@strong{MySQL} types.
@cindex Functions for @code{SELECT} and @code{WHERE} clauses
@node Functions, CREATE DATABASE, Column types, Reference
@section Functions for use in @code{SELECT} and @code{WHERE} clauses
A @code{select_expression} or @code{where_definition} in a SQL statement
can consist of any expression using the functions described below.
An expression that contains @code{NULL} always produces a @code{NULL} value
unless otherwise indicated in the documentation for the operators and
functions involved in the expression.
@strong{Note:} There must be no whitespace between a function name and the
parenthesis following it. This helps the @strong{MySQL} parser distinguish
between function calls and references to tables or columns that happen to
have the same name as a function. Spaces around arguments are permitted,
though.
@need 2000
For the sake of brevity, examples display the output from the @code{mysql}
program in abbreviated form. So this:
@example
mysql> select MOD(29,9);
1 rows in set (0.00 sec)
+-----------+
| mod(29,9) |
+-----------+
| 2 |
+-----------+
@end example
Is displayed like this:
@example
mysql> select MOD(29,9);
-> 2
@end example
@menu
* Grouping functions:: Grouping functions
* Arithmetic functions:: Normal arithmetic operations
* Bit functions:: Bit functions
* Logical functions:: Logical operations
* Comparison functions:: Comparison operators
* String comparison functions:: String comparison functions
* Casts:: Cast operators
* Control flow functions:: Control flow functions
* Mathematical functions:: Mathematical functions
* String functions:: String functions
* Date and time functions:: Date and time functions
* Miscellaneous functions:: Miscellaneous functions
* Group by functions:: Functions for @code{GROUP BY} clause
@end menu
@node Grouping functions, Arithmetic functions, Functions, Functions
@subsection Grouping functions
@cindex Grouping of expressions
@table @code
@findex () (parentheses)
@findex parentheses ( and )
@item ( ... )
Parentheses. Use these to force the order of evaluation in an expression.
@example
mysql> select 1+2*3;
-> 7
mysql> select (1+2)*3;
-> 9
@end example
@end table
@node Arithmetic functions, Bit functions, Grouping functions, Functions
@subsection Normal arithmetic operations
The usual arithmetic operators are available. Note that in the case of
@code{-}, @code{+} and @code{*}, the result is calculated with @code{BIGINT}
(64-bit) precision if both arguments are integers!
@cindex Arithmetic expressions
@table @code
@findex + (addition)
@findex addition (+)
@item +
Addition
@example
mysql> select 3+5;
-> 8
@end example
@findex - (subtraction)
@findex subtraction (-)
@item -
Subtraction
@example
mysql> select 3-5;
-> -2
@end example
@findex * (multiplication)
@findex multiplication (*)
@item *
Multiplication
@example
mysql> select 3*5;
-> 15
mysql> select 18014398509481984*18014398509481984.0;
-> 324518553658426726783156020576256.0
mysql> select 18014398509481984*18014398509481984;
-> 0
@end example
The result of the last expression is incorrect because the result of the integer
multiplication exceeds the 64-bit range of @code{BIGINT} calculations.
@findex / (division)
@findex division (/)
@item /
Division
@example
mysql> select 3/5;
-> 0.60
@end example
Division by zero produces a @code{NULL} result:
@example
mysql> select 102/(1-1);
-> NULL
@end example
A division will be calculated with @code{BIGINT} arithmetic only if performed
in a context where its result is converted to an integer!
@end table
@findex Arithmetic functions
@findex Bit functions
@findex Functions, arithmetic
@findex Functions, bit
@node Bit functions, Logical functions, Arithmetic functions, Functions
@subsection Bit functions
@strong{MySQL} uses @code{BIGINT} (64-bit) arithmetic for bit operations, so
these operators have a maximum range of 64 bits.
@table @code
@findex | (bitwise OR)
@findex OR, bitwise
@item |
Bitwise OR
@example
mysql> select 29 | 15;
-> 31
@end example
@findex & (bitwise AND)
@findex AND, bitwise
@item &
Bitwise AND
@example
mysql> select 29 & 15;
-> 13
@end example
@findex << (left shift)
@item <<
Shifts a longlong (@code{BIGINT}) number to the left.
@example
mysql> select 1 << 2
-> 4
@end example
@findex >> (right shift)
@item >>
Shifts a longlong (@code{BIGINT}) number to the right.
@example
mysql> select 4 >> 2
-> 1
@end example
@findex ~
@item ~
Invert all bits.
@example
mysql> select 5 & ~1
-> 4
@end example
@findex BIT_COUNT()
@item BIT_COUNT(N)
Returns the number of bits that are set in the argument @code{N}.
@example
mysql> select BIT_COUNT(29);
-> 4
@end example
@end table
@findex Logical functions
@findex Functions, logical
@node Logical functions, Comparison functions, Bit functions, Functions
@subsection Logical operations
All logical functions return @code{1} (TRUE) or @code{0} (FALSE).
@table @code
@findex NOT, logical
@findex ! (logical NOT)
@item NOT
@itemx !
Logical NOT. Returns @code{1} if the argument is @code{0}, otherwise returns
@code{0}.
Exception: @code{NOT NULL} returns @code{NULL}.
@example
mysql> select NOT 1;
-> 0
mysql> select NOT NULL;
-> NULL
mysql> select ! (1+1);
-> 0
mysql> select ! 1+1;
-> 1
@end example
The last example returns @code{1} because the expression evaluates
the same way as @code{(!1)+1}.
@findex OR, logical
@findex || (logical OR)
@item OR
@itemx ||
Logical OR. Returns @code{1} if either argument is not @code{0} and not
@code{NULL}.
@example
mysql> select 1 || 0;
-> 1
mysql> select 0 || 0;
-> 0
mysql> select 1 || NULL;
-> 1
@end example
@findex AND, logical
@findex && (logical AND)
@item AND
@itemx &&
Logical AND. Returns @code{0} if either argument is @code{0} or @code{NULL},
otherwise returns @code{1}.
@example
mysql> select 1 && NULL;
-> 0
mysql> select 1 && 0;
-> 0
@end example
@end table
@cindex Casts
@cindex Type conversions
@findex Comparison operators
@node Comparison functions, String comparison functions, Logical functions, Functions
@subsection Comparison operators
Comparison operations result in a value of @code{1} (TRUE), @code{0} (FALSE)
or @code{NULL}. These functions work for both numbers and strings. Strings
are automatically converted to numbers and numbers to strings as needed (as
in Perl).
@strong{MySQL} performs comparisons using the following
rules:
@itemize @bullet
@item
If one or both arguments are @code{NULL}, the result of the comparison
is @code{NULL}, except for the @code{<=>} operator.
@item
If both arguments in a comparison operation are strings, they are compared as
strings.
@item
If both arguments are integers, they are compared as integers.
@item
Hexadecimal values are treated as binary strings if not compared to a number.
@item
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
If one of the arguments is a @code{TIMESTAMP} or @code{DATETIME} column and
the other argument is a constant, the constant is converted
to a timestamp before the comparison is performed. This is done to be more
ODBC-friendly.
@item
In all other cases, the arguments are compared as floating-point (real)
numbers.
@end itemize
By default, string comparisons are done in case-independent fashion using the
current character set (ISO-8859-1 Latin1 by default, which also works
excellently for English).
The examples below illustrate conversion of strings to numbers for comparison
operations:
@example
mysql> SELECT 1 > '6x';
-> 0
mysql> SELECT 7 > '6x';
-> 1
mysql> SELECT 0 > 'x6';
-> 0
mysql> SELECT 0 = 'x6';
-> 1
@end example
@table @code
@findex = (equal)
@findex equal (=)
@item =
Equal
@example
mysql> select 1 = 0;
-> 0
mysql> select '0' = 0;
-> 1
mysql> select '0.0' = 0;
-> 1
mysql> select '0.01' = 0;
-> 0
mysql> select '.01' = 0.01;
-> 1
@end example
@findex <> (not equal)
@findex not equal (<>)
@findex != (not equal)
@findex not equal (!=)
@item <>
@itemx !=
Not equal
@example
mysql> select '.01' <> '0.01';
-> 1
mysql> select .01 <> '0.01';
-> 0
mysql> select 'zapp' <> 'zappp';
-> 1
@end example
@findex <= (less than or equal)
@findex less than or equal (<=)
@item <=
Less than or equal
@example
mysql> select 0.1 <= 2;
-> 1
@end example
@findex < (less than)
@findex less than (<)
@item <
Less than
@example
mysql> select 2 <= 2;
-> 1
@end example
@findex >= (greater than or equal)
@findex greater than or equal (>=)
@item >=
Greater than or equal
@example
mysql> select 2 >= 2;
-> 1
@end example
@findex > (greater than)
@findex greater than (>)
@item >
Greater than
@example
mysql> select 2 > 2;
-> 0
@end example
@findex <=> (Equal to)
@item <=>
Null safe equal
@example
mysql> select 1 <=> 1, NULL <=> NULL, 1 <=> NULL;
-> 1 1 0
@end example
@findex IS NULL
@findex IS NOT NULL
@item IS NULL
@itemx IS NOT NULL
Test whether or not a value is or is not @code{NULL}
@example
mysql> select 1 IS NULL, 0 IS NULL, NULL IS NULL:
-> 0 0 1
mysql> select 1 IS NOT NULL, 0 IS NOT NULL, NULL IS NOT NULL;
-> 1 1 0
@end example
@findex BETWEEN ... AND
@item expr BETWEEN min AND max
If @code{expr} is greater than or equal to @code{min} and @code{expr} is
less than or equal to @code{max}, @code{BETWEEN} returns @code{1},
otherwise it returns @code{0}. This is equivalent to the expression
@code{(min <= expr AND expr <= max)} if all the arguments are of the
same type. The first argument (@code{expr}) determines how the
comparison is performed as follows:
@itemize @bullet
@item
If @code{expr} is a @code{TIMESTAMP}, @code{DATE} or @code{DATETIME}
column, min and max are formatted to the same format if they
are constants.
@item
If @code{expr} is a case-insensitive string expression, a case-insensitive
string comparison is done.
@item
If @code{expr} is a case-sensitive string expression, a case-sensitive
string comparison is done.
@item
If @code{expr} is an integer expression, an integer comparison is done.
@item
Otherwise, a floating-point (real) comparison is done.
@end itemize
@example
mysql> select 1 BETWEEN 2 AND 3;
-> 0
mysql> select 'b' BETWEEN 'a' AND 'c';
-> 1
mysql> select 2 BETWEEN 2 AND '3';
-> 1
mysql> select 2 BETWEEN 2 AND 'x-3';
-> 0
@end example
@findex IN
@item expr IN (value,...)
Returns @code{1} if @code{expr} is any of the values in the @code{IN} list,
else returns @code{0}. If all values are constants, then all values are
evaluated according to the type of @code{expr} and sorted. The search for the
item is then done using a binary search. This means @code{IN} is very quick
if the @code{IN} value list consists entirely of constants. If @code{expr}
is a case-sensitive string expression, the string comparison is performed in
case-sensitive fashion.
@example
mysql> select 2 IN (0,3,5,'wefwf');
-> 0
mysql> select 'wefwf' IN (0,3,5,'wefwf');
-> 1
@end example
@findex NOT IN
@item expr NOT IN (value,...)
Same as @code{NOT (expr IN (value,...))}.
@findex ISNULL()
@item ISNULL(expr)
If @code{expr} is @code{NULL}, @code{ISNULL()} returns @code{1}, otherwise
it returns @code{0}.
@example
mysql> select ISNULL(1+1);
-> 0
mysql> select ISNULL(1/0);
-> 1
@end example
Note that a comparison of @code{NULL} values using @code{=} will always be
false!
@findex COALESCE()
@item COALESCE(list)
Returns first non-@code{NULL} element in list.
@example
mysql> select COALESCE(NULL,1);
-> 1
mysql> select COALESCE(NULL,NULL,NULL);
-> NULL
@end example
@findex INTERVAL()
@item INTERVAL(N,N1,N2,N3,...)
Returns @code{0} if @code{N} < @code{N1}, @code{1} if @code{N} < @code{N2}
and so on. All arguments are treated as integers. It is required that
@code{N1} < @code{N2} < @code{N3} < @code{...} < @code{Nn} for this function
to work correctly. This is because a binary search is used (very fast).
@example
mysql> select INTERVAL(23, 1, 15, 17, 30, 44, 200);
-> 3
mysql> select INTERVAL(10, 1, 10, 100, 1000);
-> 2
mysql> select INTERVAL(22, 23, 30, 44, 200);
-> 0
@end example
@end table
@findex String comparison functions
@findex Functions, string comparison
@node String comparison functions, Casts, Comparison functions, Functions
@subsection String comparison functions
@cindex Case sensitivity, in string comparisons
@cindex String comparisons, case sensitivity
Normally, if any expression in a string comparison is case sensitive, the
comparison is performed in case-sensitive fashion.
@table @code
@findex LIKE
@item expr LIKE pat [ESCAPE 'escape-char']
Pattern matching using
SQL simple regular expression comparison. Returns @code{1} (TRUE) or @code{0}
(FALSE). With @code{LIKE} you can use the following two wildcard characters
in the pattern:
@multitable @columnfractions .1 .9
@item @code{%} @tab Matches any number of characters, even zero characters
@item @code{_} @tab Matches exactly one character
@end multitable
@example
mysql> select 'David!' LIKE 'David_';
-> 1
mysql> select 'David!' LIKE '%D%v%';
-> 1
@end example
To test for literal instances of a wildcard character, precede the character
with the escape character. If you don't specify the @code{ESCAPE} character,
@samp{\} is assumed:
@multitable @columnfractions .1 .9
@item @code{\%} @tab Matches one @code{%} character
@item @code{\_} @tab Matches one @code{_} character
@end multitable
@example
mysql> select 'David!' LIKE 'David\_';
-> 0
mysql> select 'David_' LIKE 'David\_';
-> 1
@end example
To specify a different escape character, use the @code{ESCAPE} clause:
@example
mysql> select 'David_' LIKE 'David|_' ESCAPE '|';
-> 1
@end example
@code{LIKE} is allowed on numeric expressions! (This is a @strong{MySQL}
extension to the ANSI SQL @code{LIKE}.)
@example
mysql> select 10 LIKE '1%';
-> 1
@end example
Note: Because @strong{MySQL} uses the C escape syntax in strings (e.g.,
@samp{\n}), you must double any @samp{\} that you use in your @code{LIKE}
strings. For example, to search for @samp{\n}, specify it as @samp{\\n}. To
search for @samp{\}, specify it as @samp{\\\\} (the backslashes are stripped
once by the parser, and another time when the pattern match is done, leaving
a single backslash to be matched).
@findex NOT LIKE
@item expr NOT LIKE pat [ESCAPE 'escape-char']
Same as @code{NOT (expr LIKE pat [ESCAPE 'escape-char'])}.
@cindex mSQL compatibility
@cindex Compatibility, with mSQL
@findex REGEXP
@findex RLIKE
@item expr REGEXP pat
@itemx expr RLIKE pat
Performs a pattern match of a string expression @code{expr} against a pattern
@code{pat}. The pattern can be an extended regular expression.
@xref{Regexp}. Returns @code{1} if @code{expr} matches @code{pat}, otherwise
returns @code{0}. @code{RLIKE} is a synonym for @code{REGEXP}, provided for
@code{mSQL} compatibility. Note: Because @strong{MySQL} uses the C escape
syntax in strings (e.g., @samp{\n}), you must double any @samp{\} that you
use in your @code{REGEXP} strings. In @code{MySQL} 3.23.4
@code{REGEXP} is case insensitive for normal (not binary) strings.
@example
mysql> select 'Monty!' REGEXP 'm%y%%';
-> 0
mysql> select 'Monty!' REGEXP '.*';
-> 1
mysql> select 'new*\n*line' REGEXP 'new\\*.\\*line';
-> 1
mysql> select "a" REGEXP "A", "a" REGEXP BINARY "A";
-> 1 0
@end example
@item
@code{REGEXP} and @code{RLIKE} use the current character set (ISO-8859-1
Latin1 by default) when deciding the type of a character.
@findex NOT REGEXP
@item expr NOT REGEXP pat
@itemx expr NOT RLIKE pat
Same as @code{NOT (expr REGEXP pat)}.
@findex STRCMP()
@item STRCMP(expr1,expr2)
@code{STRCMP()}
returns @code{0} if the strings are the same, @code{-1} if the first
argument is smaller than the second according to the current sort order,
and @code{1} otherwise.
@example
mysql> select STRCMP('text', 'text2');
-> -1
mysql> select STRCMP('text2', 'text');
-> 1
mysql> select STRCMP('text', 'text');
-> 0
@end example
@end table
@findex Casts
@node Casts, Control flow functions, String comparison functions, Functions
@subsection Cast operators
@table @code
@findex BINARY
@item @code{BINARY}
The @code{BINARY} operator casts the string following it to a binary string.
This is an easy way to force a column comparison to be case sensitive even
if the column isn't defined as @code{BINARY} or @code{BLOB}.
@example
mysql> select "a" = "A";
-> 1
mysql> select BINARY "a" = "A";
-> 0
@end example
@code{BINARY} was introduced in @strong{MySQL} 3.23.0
@end table
@findex Control flow functions
@findex Functions, control flow
@node Control flow functions, Mathematical functions, Casts, Functions
@subsection Control flow functions
@table @code
@findex IFNULL()
@item IFNULL(expr1,expr2)
If @code{expr1} is not @code{NULL}, @code{IFNULL()} returns @code{expr1},
else it returns @code{expr2}. @code{IFNULL()} returns a numeric or string
value, depending on the context in which it is used.
@example
mysql> select IFNULL(1,0);
-> 1
mysql> select IFNULL(NULL,10);
-> 10
mysql> select IFNULL(1/0,10);
-> 10
mysql> select IFNULL(1/0,'yes');
-> 'yes'
@end example
@findex NULLIF()
@item NULLIF(expr1,expr2)
If @code{expr1 = expr2} is true, return @code{NULL} else return @code{expr1}.
This is the same as @code{CASE WHEN x = y THEN NULL ELSE x END}
@example
mysql> select NULLIF(1,1);
-> NULL
mysql> select NULLIF(1,2);
-> 1
@end example
Note that @code{expr1} is evaluated twice in @strong{MySQL} if the arguments
are equal.
@findex IF()
@item IF(expr1,expr2,expr3)
If @code{expr1} is TRUE (@code{expr1 <> 0} and @code{expr1 <> NULL}) then
@code{IF()} returns @code{expr2}, else it returns @code{expr3}.
@code{IF()} returns a numeric or string value, depending on the context
in which it is used.
@example
mysql> select IF(1>2,2,3);
-> 3
mysql> select IF(1<2,'yes','no');
-> 'yes'
mysql> select IF(strcmp('test','test1'),'no','yes');
-> 'no'
@end example
@code{expr1} is evaluated as an integer value, which means that if you are
testing floating-point or string values, you should do so using a comparison
operation.
@example
mysql> select IF(0.1,1,0);
-> 0
mysql> select IF(0.1<>0,1,0);
-> 1
@end example
In the first case above, @code{IF(0.1)} returns @code{0} because @code{0.1}
is converted to an integer value, resulting in a test of @code{IF(0)}. This
may not be what you expect. In the second case, the comparison tests the
original floating-point value to see whether it is non-zero. The result
of the comparison is used as an integer.
The default return type of @code{IF()} (which may matter when it stored into
a temporary table) is calculated in @strong{MySQL} 3.23 as follows:
@multitable @columnfractions .7 .3
@item expr2 or expr3 returns string @tab string
@item expr2 or expr3 returns a floating point value @tab floating point
@item expr2 or expr3 returns an integer @tab integer
@end multitable
@findex CASE
@item CASE value WHEN [compare-value] THEN result [WHEN [compare-value] THEN result ...] [ELSE result] END
@item CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END
The first version returns the @code{result} where
@code{value=compare-value}. The second version returns the result for
the first condition which is true. If there was no matching result
value, then the result after @code{ELSE} is returned. If there is no
@code{ELSE} part then @code{NULL} is returned.
@example
mysql> SELECT CASE 1 WHEN 1 THEN "one" WHEN 2 THEN "two" ELSE "more" END;
-> "one"
mysql> SELECT CASE WHEN 1>0 THEN "true" ELSE "false" END;
-> "true"
mysql> SELECT CASE BINARY "B" when "a" then 1 when "b" then 2 END;
-> NULL
@end example
@end table
@findex Mathematical functions
@findex Functions, mathematical
@node Mathematical functions, String functions, Control flow functions, Functions
@subsection Mathematical functions
All mathematical functions return @code{NULL} in case of an error.
@table @code
@findex - (unary minus)
@findex minus, unary (-)
@findex unary minus (-)
@item -
Unary minus. Changes the sign of the argument.
@example
mysql> select - 2;
-> -2
@end example
Note that if this operator is used with a @code{BIGINT}, the return value is a
@code{BIGINT}! This means that you should avoid using @code{-} on integers that
may have the value of @code{-2^63}!
@findex ABS()
@item ABS(X)
Returns the absolute value of @code{X}.
@example
mysql> select ABS(2);
-> 2
mysql> select ABS(-32);
-> 32
@end example
This function is safe to use with @code{BIGINT} values.
@findex SIGN()
@item SIGN(X)
Returns the sign of the argument as @code{-1}, @code{0} or @code{1}, depending
on whether @code{X} is negative, zero, or positive.
@example
mysql> select SIGN(-32);
-> -1
mysql> select SIGN(0);
-> 0
mysql> select SIGN(234);
-> 1
@end example
@findex MOD()
@findex % (modulo)
@findex modulo (%)
@item MOD(N,M)
@itemx %
Modulo (like the @code{%} operator in C).
Returns the remainder of @code{N} divided by @code{M}.
@example
mysql> select MOD(234, 10);
-> 4
mysql> select 253 % 7;
-> 1
mysql> select MOD(29,9);
-> 2
@end example
This function is safe to use with @code{BIGINT} values.
@findex FLOOR()
@item FLOOR(X)
Returns the largest integer value not greater than @code{X}.
@example
mysql> select FLOOR(1.23);
-> 1
mysql> select FLOOR(-1.23);
-> -2
@end example
Note that the return value is converted to a @code{BIGINT}!
@findex CEILING()
@item CEILING(X)
Returns the smallest integer value not less than @code{X}.
@example
mysql> select CEILING(1.23);
-> 2
mysql> select CEILING(-1.23);
-> -1
@end example
Note that the return value is converted to a @code{BIGINT}!
@findex ROUND()
@item ROUND(X)
Returns the argument @code{X}, rounded to the nearest integer.
@example
mysql> select ROUND(-1.23);
-> -1
mysql> select ROUND(-1.58);
-> -2
mysql> select ROUND(1.58);
-> 2
@end example
@findex ROUND()
@item ROUND(X,D)
Returns the argument @code{X}, rounded to a number with @code{D} decimals.
If @code{D} is @code{0}, the result will have no decimal point or fractional
part.
@example
mysql> select ROUND(1.298, 1);
-> 1.3
mysql> select ROUND(1.298, 0);
-> 1
@end example
@findex EXP()
@item EXP(X)
Returns the value of @code{e} (the base of natural logarithms) raised to
the power of @code{X}.
@example
mysql> select EXP(2);
-> 7.389056
mysql> select EXP(-2);
-> 0.135335
@end example
@findex LOG()
@item LOG(X)
Returns the natural logarithm of @code{X}.
@example
mysql> select LOG(2);
-> 0.693147
mysql> select LOG(-2);
-> NULL
@end example
If you want the log of a number @code{X} to some arbitary base @code{B}, use
the formula @code{LOG(X)/LOG(B)}.
@findex LOG10()
@item LOG10(X)
Returns the base-10 logarithm of @code{X}.
@example
mysql> select LOG10(2);
-> 0.301030
mysql> select LOG10(100);
-> 2.000000
mysql> select LOG10(-100);
-> NULL
@end example
@findex POW()
@findex POWER()
@item POW(X,Y)
@itemx POWER(X,Y)
Returns the value of @code{X} raised to the power of @code{Y}.
@example
mysql> select POW(2,2);
-> 4.000000
mysql> select POW(2,-2);
-> 0.250000
@end example
@findex SQRT()
@item SQRT(X)
Returns the non-negative square root of @code{X}.
@example
mysql> select SQRT(4);
-> 2.000000
mysql> select SQRT(20);
-> 4.472136
@end example
@findex PI()
@item PI()
Returns the value of PI.
@example
mysql> select PI();
-> 3.141593
@end example
@findex COS()
@item COS(X)
Returns the cosine of @code{X}, where @code{X} is given in radians.
@example
mysql> select COS(PI());
-> -1.000000
@end example
@findex SIN()
@item SIN(X)
Returns the sine of @code{X}, where @code{X} is given in radians.
@example
mysql> select SIN(PI());
-> 0.000000
@end example
@findex TAN()
@item TAN(X)
Returns the tangent of @code{X}, where @code{X} is given in radians.
@example
mysql> select TAN(PI()+1);
-> 1.557408
@end example
@findex ACOS()
@item ACOS(X)
Returns the arc cosine of @code{X}, that is, the value whose cosine is
@code{X}. Returns @code{NULL} if @code{X} is not in the range @code{-1} to
@code{1}.
@example
mysql> select ACOS(1);
-> 0.000000
mysql> select ACOS(1.0001);
-> NULL
mysql> select ACOS(0);
-> 1.570796
@end example
@findex ASIN()
@item ASIN(X)
Returns the arc sine of @code{X}, that is, the value whose sine is
@code{X}. Returns @code{NULL} if @code{X} is not in the range @code{-1} to
@code{1}.
@example
mysql> select ASIN(0.2);
-> 0.201358
mysql> select ASIN('foo');
-> 0.000000
@end example
@findex ATAN()
@item ATAN(X)
Returns the arc tangent of @code{X}, that is, the value whose tangent is
@code{X}.
@example
mysql> select ATAN(2);
-> 1.107149
mysql> select ATAN(-2);
-> -1.107149
@end example
@findex ATAN2()
@item ATAN2(X,Y)
Returns the arc tangent of the two variables @code{X} and @code{Y}. It is
similar to calculating the arc tangent of @code{Y / X}, except that the
signs of both arguments are used to determine the quadrant of the
result.
@example
mysql> select ATAN(-2,2);
-> -0.785398
mysql> select ATAN(PI(),0);
-> 1.570796
@end example
@findex COT()
@item COT(X)
Returns the cotangent of @code{X}.
@example
mysql> select COT(12);
-> -1.57267341
mysql> select COT(0);
-> NULL
@end example
@findex RAND()
@item RAND()
@itemx RAND(N)
Returns a random floating-point value in the range @code{0} to @code{1.0}.
If an integer argument @code{N} is specified, it is used as the seed value.
@example
mysql> select RAND();
-> 0.5925
mysql> select RAND(20);
-> 0.1811
mysql> select RAND(20);
-> 0.1811
mysql> select RAND();
-> 0.2079
mysql> select RAND();
-> 0.7888
@end example
You can't use a column with @code{RAND()} values in an @code{ORDER BY}
clause, because @code{ORDER BY} would evaluate the column multiple times.
In @strong{MySQL} 3.23, you can however do:
@code{SELECT * FROM table_name ORDER BY RAND()}
This is useful to get a random sample of a set @code{SELECT * FROM
table1,table2 WHERE a=b AND c<d ORDER BY RAND() LIMIT 1000}.
Note that a @code{RAND()} in a @code{WHERE} clause will be re-evaluated
every time the @code{WHERE} is executed.
@findex LEAST()
@item LEAST(X,Y,...)
With two or more arguments, returns the smallest (minimum-valued) argument.
The arguments are compared using the following rules:
@itemize @bullet
@item
If the return value is used in an @code{INTEGER} context, or all arguments
are integer-valued, they are compared as integers.
@item
If the return value is used in a @code{REAL} context, or all arguments are
real-valued, they are compared as reals.
@item
If any argument is a case-sensitive string, the arguments are compared
as case-sensitive strings.
@item
In other cases, the arguments are compared as case-insensitive strings.
@end itemize
@example
mysql> select LEAST(2,0);
-> 0
mysql> select LEAST(34.0,3.0,5.0,767.0);
-> 3.0
mysql> select LEAST("B","A","C");
-> "A"
@end example
In @strong{MySQL} versions prior to 3.22.5, you can use @code{MIN()} instead
of @code{LEAST}.
@findex GREATEST()
@item GREATEST(X,Y,...)
Returns the largest (maximum-valued) argument.
The arguments are compared using the same rules as for @code{LEAST}.
@example
mysql> select GREATEST(2,0);
-> 2
mysql> select GREATEST(34.0,3.0,5.0,767.0);
-> 767.0
mysql> select GREATEST("B","A","C");
-> "C"
@end example
In @strong{MySQL} versions prior to 3.22.5, you can use @code{MAX()} instead
of @code{GREATEST}.
@findex DEGREES()
@item DEGREES(X)
Returns the argument @code{X}, converted from radians to degrees.
@example
mysql> select DEGREES(PI());
-> 180.000000
@end example
@findex RADIANS()
@item RADIANS(X)
Returns the argument @code{X}, converted from degrees to radians.
@example
mysql> select RADIANS(90);
-> 1.570796
@end example
@findex TRUNCATE()
@item TRUNCATE(X,D)
Returns the number @code{X}, truncated to @code{D} decimals. If @code{D}
is @code{0}, the result will have no decimal point or fractional part.
@example
mysql> select TRUNCATE(1.223,1);
-> 1.2
mysql> select TRUNCATE(1.999,1);
-> 1.9
mysql> select TRUNCATE(1.999,0);
-> 1
@end example
@end table
@findex String functions
@findex Functions, string
@node String functions, Date and time functions, Mathematical functions, Functions
@subsection String functions
String-valued functions return @code{NULL} if the length of the result would
be greater than the @code{max_allowed_packet} server parameter. @xref{Server
parameters}.
For functions that operate on string positions,
the first position is numbered 1.
@table @code
@findex ASCII()
@item ASCII(str)
Returns the ASCII code value of the leftmost character of the string
@code{str}. Returns @code{0} if @code{str} is the empty string. Returns
@code{NULL} if @code{str} is @code{NULL}.
@example
mysql> select ASCII('2');
-> 50
mysql> select ASCII(2);
-> 50
mysql> select ASCII('dx');
-> 100
@end example
See also the @code{ORD()} function.
@findex ORD()
@item ORD(str)
If the leftmost character of the string str is a multi-byte character,
returns the code of multi-byte character by returning the ASCII code value
of the character in the format of:
@code{((first byte ASCII code)*256+(second byte ASCII code))[*256+third byte ASCII code...]}.
If the leftmost character is not a multi-byte character, returns the same
value as the like @code{ASCII()} function does.
@example
mysql> select ORD('2');
-> 50
@end example
@findex CONV()
@item CONV(N,from_base,to_base)
Converts numbers between different number bases. Returns a string
representation of the number @code{N}, converted from base @code{from_base}
to base @code{to_base}. Returns @code{NULL} if any argument is @code{NULL}.
The argument @code{N} is interpreted as an integer, but may be specified as
an integer or a string. The minimum base is @code{2} and the maximum base is
@code{36}. If @code{to_base} is a negative number, @code{N} is regarded as a
signed number. Otherwise, @code{N} is treated as unsigned. @code{CONV} works
with 64-bit precision.
@example
mysql> select CONV("a",16,2);
-> '1010'
mysql> select CONV("6E",18,8);
-> '172'
mysql> select CONV(-17,10,-18);
-> '-H'
mysql> select CONV(10+"10"+'10'+0xa,10,10);
-> '40'
@end example
@findex BIN()
@item BIN(N)
Returns a string representation of the binary value of @code{N}, where
@code{N} is a longlong (@code{BIGINT}) number. This is equivalent to
@code{CONV(N,10,2)}. Returns @code{NULL} if @code{N} is @code{NULL}.
@example
mysql> select BIN(12);
-> '1100'
@end example
@findex OCT()
@item OCT(N)
Returns a string representation of the octal value of @code{N}, where
@code{N} is a longlong number. This is equivalent to @code{CONV(N,10,8)}.
Returns @code{NULL} if @code{N} is @code{NULL}.
@example
mysql> select OCT(12);
-> '14'
@end example
@findex HEX()
@item HEX(N)
Returns a string representation of the hexadecimal value of @code{N}, where
@code{N} is a longlong (@code{BIGINT}) number. This is equivalent to
@code{CONV(N,10,16)}. Returns @code{NULL} if @code{N} is @code{NULL}.
@example
mysql> select HEX(255);
-> 'FF'
@end example
@findex CHAR()
@item CHAR(N,...)
@code{CHAR()} interprets the arguments as integers and returns a string
consisting of the characters given by the ASCII code values of those
integers. @code{NULL} values are skipped.
@example
mysql> select CHAR(77,121,83,81,'76');
-> 'MySQL'
mysql> select CHAR(77,77.3,'77.3');
-> 'MMM'
@end example
@findex CONCAT()
@item CONCAT(str1,str2,...)
Returns the string that results from concatenating the arguments. Returns
@code{NULL} if any argument is @code{NULL}. May have more than 2 arguments.
A numeric argument is converted to the equivalent string form.
@example
mysql> select CONCAT('My', 'S', 'QL');
-> 'MySQL'
mysql> select CONCAT('My', NULL, 'QL');
-> NULL
mysql> select CONCAT(14.3);
-> '14.3'
@end example
@findex CONCAT_WS()
@item CONCAT_WS(separator, str1, str2,...)
@code{CONCAT_WS()} stands for CONCAT With Separator and is a special form of
@code{CONCAT()}. The irst argument is the separator for the rest of the
arguments. The separator can be a string as well as the rest of the
arguments. If the separator is @code{NULL}, the result will be @code{NULL}.
The function will skip any @code{NULL}s and empty strings, after the
separator argument. The separator will be added between the strings to be
concatenated.
@example
mysql> select CONCAT_WS(",","First name","Second name","Last Name");
-> 'First name,Second name,Last Name'
mysql> select CONCAT_WS(",","First name",NULL,"Last Name");
-> 'First name,Last Name'
@end example
@findex LENGTH()
@findex OCTET_LENGTH()
@findex CHAR_LENGTH()
@findex CHARACTER_LENGTH()
@item LENGTH(str)
@itemx OCTET_LENGTH(str)
@itemx CHAR_LENGTH(str)
@itemx CHARACTER_LENGTH(str)
Returns the length of the string @code{str}.
@example
mysql> select LENGTH('text');
-> 4
mysql> select OCTET_LENGTH('text');
-> 4
@end example
Note that for @code{CHAR_LENGTH()}, multi-byte characters are only counted once.
@findex LOCATE()
@findex POSITION()
@item LOCATE(substr,str)
@itemx POSITION(substr IN str)
Returns the position of the first occurrence of substring @code{substr}
in string @code{str}. Returns @code{0} if @code{substr} is not in @code{str}.
@example
mysql> select LOCATE('bar', 'foobarbar');
-> 4
mysql> select LOCATE('xbar', 'foobar');
-> 0
@end example
This function is multi-byte safe.
@findex LOCATE()
@item LOCATE(substr,str,pos)
Returns the position of the first occurrence of substring @code{substr} in
string @code{str}, starting at position @code{pos}.
Returns @code{0} if @code{substr} is not in @code{str}.
@example
mysql> select LOCATE('bar', 'foobarbar',5);
-> 7
@end example
This function is multi-byte safe.
@findex INSTR()
@item INSTR(str,substr)
Returns the position of the first occurrence of substring @code{substr} in
string @code{str}. This is the same as the two-argument form of
@code{LOCATE()}, except that the arguments are swapped.
@example
mysql> select INSTR('foobarbar', 'bar');
-> 4
mysql> select INSTR('xbar', 'foobar');
-> 0
@end example
This function is multi-byte safe.
@findex LPAD()
@item LPAD(str,len,padstr)
Returns the string @code{str}, left-padded with the string
@code{padstr} until @code{str} is @code{len} characters long.
@example
mysql> select LPAD('hi',4,'??');
-> '??hi'
@end example
@findex RPAD()
@item RPAD(str,len,padstr)
Returns the string @code{str}, right-padded with the string
@code{padstr} until @code{str} is @code{len} characters long.
@example
mysql> select RPAD('hi',5,'?');
-> 'hi???'
@end example
@findex LEFT()
@item LEFT(str,len)
Returns the leftmost @code{len} characters from the string @code{str}.
@example
mysql> select LEFT('foobarbar', 5);
-> 'fooba'
@end example
This function is multi-byte safe.
@findex RIGHT()
@item RIGHT(str,len)
Returns the rightmost @code{len} characters from the string @code{str}.
@example
mysql> select RIGHT('foobarbar', 4);
-> 'rbar'
@end example
This function is multi-byte safe.
@findex SUBSTRING()
@findex MID()
@item SUBSTRING(str,pos,len)
@itemx SUBSTRING(str FROM pos FOR len)
@itemx MID(str,pos,len)
Returns a substring @code{len} characters long from string @code{str},
starting at position @code{pos}.
The variant form that uses @code{FROM} is ANSI SQL92 syntax.
@example
mysql> select SUBSTRING('Quadratically',5,6);
-> 'ratica'
@end example
This function is multi-byte safe.
@findex SUBSTRING()
@item SUBSTRING(str,pos)
@item SUBSTRING(str FROM pos)
Returns a substring from string @code{str} starting at position @code{pos}.
@example
mysql> select SUBSTRING('Quadratically',5);
-> 'ratically'
mysql> select SUBSTRING('foobarbar' FROM 4);
-> 'barbar'
@end example
This function is multi-byte safe.
@findex SUBSTRING_INDEX()
@item SUBSTRING_INDEX(str,delim,count)
Returns the substring from string @code{str} before @code{count}
occurrences of the delimiter @code{delim}.
If @code{count} is positive, everything to the left of the final delimiter
(counting from the left) is returned.
If @code{count} is negative, everything to the right of the final delimiter
(counting from the right) is returned.
@example
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', 2);
-> 'www.mysql'
mysql> select SUBSTRING_INDEX('www.mysql.com', '.', -2);
-> 'mysql.com'
@end example
This function is multi-byte safe.
@findex LTRIM()
@item LTRIM(str)
Returns the string @code{str} with leading space characters removed.
@example
mysql> select LTRIM(' barbar');
-> 'barbar'
@end example
@findex RTRIM()
@item RTRIM(str)
Returns the string @code{str} with trailing space characters removed.
@example
mysql> select RTRIM('barbar ');
-> 'barbar'
@end example
This function is multi-byte safe.
@findex TRIM()
@item TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str)
Returns the string @code{str} with all @code{remstr} prefixes and/or suffixes
removed. If none of the specifiers @code{BOTH}, @code{LEADING} or
@code{TRAILING} are given, @code{BOTH} is assumed. If @code{remstr} is not
specified, spaces are removed.
@example
mysql> select TRIM(' bar ');
-> 'bar'
mysql> select TRIM(LEADING 'x' FROM 'xxxbarxxx');
-> 'barxxx'
mysql> select TRIM(BOTH 'x' FROM 'xxxbarxxx');
-> 'bar'
mysql> select TRIM(TRAILING 'xyz' FROM 'barxxyz');
-> 'barx'
@end example
This function is multi-byte safe.
@findex SOUNDEX()
@item SOUNDEX(str)
Returns a soundex string from @code{str}. Two strings that sound ``about the
same'' should have identical soundex strings. A ``standard'' soundex string
is 4 characters long, but the @code{SOUNDEX()} function returns an
arbitrarily long string. You can use @code{SUBSTRING()} on the result to get
a ``standard'' soundex string. All non-alphanumeric characters are ignored
in the given string. All international alpha characters outside the A-Z range
are treated as vowels.
@example
mysql> select SOUNDEX('Hello');
-> 'H400'
mysql> select SOUNDEX('Quadratically');
-> 'Q36324'
@end example
@findex SPACE()
@item SPACE(N)
Returns a string consisting of @code{N} space characters.
@example
mysql> select SPACE(6);
-> ' '
@end example
@findex REPLACE()
@item REPLACE(str,from_str,to_str)
Returns the string @code{str} with all all occurrences of the string
@code{from_str} replaced by the string @code{to_str}.
@example
mysql> select REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
@end example
This function is multi-byte safe.
@findex REPEAT()
@item REPEAT(str,count)
Returns a string consisting of the string @code{str} repeated @code{count}
times. If @code{count <= 0}, returns an empty string. Returns @code{NULL} if
@code{str} or @code{count} are @code{NULL}.
@example
mysql> select REPEAT('MySQL', 3);
-> 'MySQLMySQLMySQL'
@end example
@findex REVERSE()
@item REVERSE(str)
Returns the string @code{str} with the order of the characters reversed.
@example
mysql> select REVERSE('abc');
-> 'cba'
@end example
This function is multi-byte safe.
@findex INSERT()
@item INSERT(str,pos,len,newstr)
Returns the string @code{str}, with the substring beginning at position
@code{pos} and @code{len} characters long replaced by the string
@code{newstr}.
@example
mysql> select INSERT('Quadratic', 3, 4, 'What');
-> 'QuWhattic'
@end example
This function is multi-byte safe.
@findex ELT()
@item ELT(N,str1,str2,str3,...)
Returns @code{str1} if @code{N} = @code{1}, @code{str2} if @code{N} =
@code{2}, and so on. Returns @code{NULL} if @code{N} is less than @code{1}
or greater than the number of arguments. @code{ELT()} is the complement of
@code{FIELD()}.
@example
mysql> select ELT(1, 'ej', 'Heja', 'hej', 'foo');
-> 'ej'
mysql> select ELT(4, 'ej', 'Heja', 'hej', 'foo');
-> 'foo'
@end example
@findex FIELD()
@item FIELD(str,str1,str2,str3,...)
Returns the index of @code{str} in the @code{str1}, @code{str2},
@code{str3}, @code{...} list.
Returns @code{0} if @code{str} is not found.
@code{FIELD()} is the complement of @code{ELT()}.
@example
mysql> select FIELD('ej', 'Hej', 'ej', 'Heja', 'hej', 'foo');
-> 2
mysql> select FIELD('fo', 'Hej', 'ej', 'Heja', 'hej', 'foo');
-> 0
@end example
@findex FIND_IN_SET()
@item FIND_IN_SET(str,strlist)
Returns a value @code{1} to @code{N} if the string @code{str} is in the list
@code{strlist} consisting of @code{N} substrings. A string list is a string
composed of substrings separated by @samp{,} characters. If the first
argument is a constant string and the second is a column of type @code{SET},
the @code{FIND_IN_SET()} function is optimized to use bit arithmetic!
Returns @code{0} if @code{str} is not in @code{strlist} or if @code{strlist}
is the empty string. Returns @code{NULL} if either argument is @code{NULL}.
This function will not work properly if the first argument contains a
@samp{,}.
@example
mysql> SELECT FIND_IN_SET('b','a,b,c,d');
-> 2
@end example
@findex MAKE_SET()
@item MAKE_SET(bits,str1,str2,...)
Returns a set (a string containing substrings separated by @samp{,}
characters) consisting of the strings that have the corresponding bit in
@code{bits} set. @code{str1} corresponds to bit 0, @code{str2} to bit 1,
etc. @code{NULL} strings in @code{str1}, @code{str2}, @code{...}
are not appended to the result.
@example
mysql> SELECT MAKE_SET(1,'a','b','c');
-> 'a'
mysql> SELECT MAKE_SET(1 | 4,'hello','nice','world');
-> 'hello,world'
mysql> SELECT MAKE_SET(0,'a','b','c');
-> ''
@end example
@findex EXPORT_SET()
@item EXPORT_SET(bits,on,off,[separator,[number_of_bits]])
Returns a string where for every bit set in 'bit', you get a 'on' string and for
every reset bit you get an 'off' string. Each string is separated with 'separator'
(default ',') and only 'number_of_bits' (default 64) of 'bits' is used.
@example
mysql> select EXPORT_SET(5,'Y','N',',',4)
-> Y,N,Y,N
@end example
@findex LCASE()
@findex LOWER()
@item LCASE(str)
@itemx LOWER(str)
Returns the string @code{str} with all characters changed to lowercase
according to the current character set mapping (the default is ISO-8859-1
Latin1).
This function is multi-byte safe.
@example
mysql> select LCASE('QUADRATICALLY');
-> 'quadratically'
@end example
@findex UCASE()
@findex UPPER()
@item UCASE(str)
@itemx UPPER(str)
Returns the string @code{str} with all characters changed to uppercase
according to the current character set mapping (the default is ISO-8859-1
Latin1).
@example
mysql> select UCASE('Hej');
-> 'HEJ'
@end example
This function is multi-byte safe.
@findex FILE
@item LOAD_FILE(file_name)
Reads the file and returns the file contents as a string. The file
must be on the server, you must specify the full pathname to the
file, and you must have the @strong{file} privilege. The file must
be readable by all and be smaller than @code{max_allowed_packet}.
If the file doesn't exist or can't be read due to one of the above reasons,
the function returns @code{NULL}.
@example
mysql> UPDATE table_name
SET blob_column=LOAD_FILE("/tmp/picture")
WHERE id=1;
@end example
@end table
If you are not using @strong{MySQL 3.23}, you have to do the reading of
the file inside your application and create an @code{INSERT} statement
to update the database with the file information. One way to do this, if
you are using the @strong{MySQL}++ library, can be found at
@uref{http://www.mysql.com/documentation/mysql++/mysql++-examples.html}.
@strong{MySQL} automatically converts numbers to strings as necessary, and
vice versa:
@example
mysql> SELECT 1+"1";
-> 2
mysql> SELECT CONCAT(2,' test');
-> '2 test'
@end example
If you want to convert a number to a string explicitly, pass it as the
argument to @code{CONCAT()}.
If a string function is given a binary string as an argument, the resulting
string is also a binary string. A number converted to a string is treated as
a binary string. This only affects comparisons.
@findex Date and time functions
@findex Functions, date and time
@node Date and time functions, Miscellaneous functions, String functions, Functions
@subsection Date and time functions
See @ref{Date and time types} for a description of the range of values
each type has, and the valid formats in which date and time values may be
specified.
Here is an example that uses date functions. The query below selects
all records with a @code{date_col} value from within the last 30 days:
@example
mysql> SELECT something FROM table
WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;
@end example
@table @code
@findex DAYOFWEEK()
@item DAYOFWEEK(date)
Returns the weekday index
for @code{date} (@code{1} = Sunday, @code{2} = Monday, ... @code{7} = Saturday).
These index values correspond to the ODBC standard.
@example
mysql> select DAYOFWEEK('1998-02-03');
-> 3
@end example
@findex WEEKDAY()
@item WEEKDAY(date)
Returns the weekday index for
@code{date} (@code{0} = Monday, @code{1} = Tuesday, ... @code{6} = Sunday).
@example
mysql> select WEEKDAY('1997-10-04 22:23:00');
-> 5
mysql> select WEEKDAY('1997-11-05');
-> 2
@end example
@findex DAYOFMONTH()
@item DAYOFMONTH(date)
Returns the day of the month for @code{date}, in the range @code{1} to
@code{31}.
@example
mysql> select DAYOFMONTH('1998-02-03');
-> 3
@end example
@findex DAYOFYEAR()
@item DAYOFYEAR(date)
Returns the day of the year for @code{date}, in the range @code{1} to
@code{366}.
@example
mysql> select DAYOFYEAR('1998-02-03');
-> 34
@end example
@findex MONTH()
@item MONTH(date)
Returns the month for @code{date}, in the range @code{1} to @code{12}.
@example
mysql> select MONTH('1998-02-03');
-> 2
@end example
@findex DAYNAME()
@item DAYNAME(date)
Returns the name of the weekday for @code{date}.
@example
mysql> select DAYNAME("1998-02-05");
-> 'Thursday'
@end example
@findex MONTHNAME()
@item MONTHNAME(date)
Returns the name of the month for @code{date}.
@example
mysql> select MONTHNAME("1998-02-05");
-> 'February'
@end example
@findex QUARTER()
@item QUARTER(date)
Returns the quarter of the year for @code{date}, in the range @code{1}
to @code{4}.
@example
mysql> select QUARTER('98-04-01');
-> 2
@end example
@findex WEEK()
@item WEEK(date)
@itemx WEEK(date,first)
With a single argument, returns the week for @code{date}, in the range
@code{0} to @code{53} (yes, there may be the beginnings of a week 53),
for locations where Sunday is the first day of the week. The
two-argument form of @code{WEEK()} allows you to specify whether the
week starts on Sunday or Monday. The week starts on Sunday if the
second argument is @code{0}, on Monday if the second argument is
@code{1}.
@example
mysql> select WEEK('1998-02-20');
-> 7
mysql> select WEEK('1998-02-20',0);
-> 7
mysql> select WEEK('1998-02-20',1);
-> 8
mysql> select WEEK('1998-12-31',1);
-> 53
@end example
@findex YEAR()
@item YEAR(date)
Returns the year for @code{date}, in the range @code{1000} to @code{9999}.
@example
mysql> select YEAR('98-02-03');
-> 1998
@end example
@item YEARWEEK(date)
@itemx YEARWEEK(date,first)
Returns year and week for a date. The second arguments works exactly
like the second argument to @code{WEEK()}. Note that the year may be
different from the year in the date argument for the first and the last
week of the year!
@example
mysql> select YEARWEEK('1987-01-01');
-> 198653
@end example
@findex HOUR()
@item HOUR(time)
Returns the hour for @code{time}, in the range @code{0} to @code{23}.
@example
mysql> select HOUR('10:05:03');
-> 10
@end example
@findex MINUTE()
@item MINUTE(time)
Returns the minute for @code{time}, in the range @code{0} to @code{59}.
@example
mysql> select MINUTE('98-02-03 10:05:03');
-> 5
@end example
@findex SECOND()
@item SECOND(time)
Returns the second for @code{time}, in the range @code{0} to @code{59}.
@example
mysql> select SECOND('10:05:03');
-> 3
@end example
@findex PERIOD_ADD()
@item PERIOD_ADD(P,N)
Adds @code{N} months to period @code{P} (in the format @code{YYMM} or
@code{YYYYMM}). Returns a value in the format @code{YYYYMM}.
Note that the period argument @code{P} is @emph{not} a date value.
@example
mysql> select PERIOD_ADD(9801,2);
-> 199803
@end example
@findex PERIOD_DIFF()
@item PERIOD_DIFF(P1,P2)
Returns the number of months between periods @code{P1} and @code{P2}.
@code{P1} and @code{P2} should be in the format @code{YYMM} or @code{YYYYMM}.
Note that the period arguments @code{P1} and @code{P2} are @emph{not}
date values.
@example
mysql> select PERIOD_DIFF(9802,199703);
-> 11
@end example
@findex DATE_ADD()
@findex DATE_SUB()
@findex ADDDATE()
@findex SUBDATE()
@findex EXTRACT(type FROM date)
@item DATE_ADD(date,INTERVAL expr type)
@itemx DATE_SUB(date,INTERVAL expr type)
@itemx ADDDATE(date,INTERVAL expr type)
@itemx SUBDATE(date,INTERVAL expr type)
These functions perform date arithmetic. They are new for @strong{MySQL}
3.22. @code{ADDDATE()} and @code{SUBDATE()} are synonyms for
@code{DATE_ADD()} and @code{DATE_SUB()}.
In @strong{MySQL} 3.23, you can use @code{+} and @code{-} instead of
@code{DATE_ADD()} and @code{DATE_SUB()}. (See example)
@code{date} is a @code{DATETIME} or @code{DATE} value specifying the starting
date. @code{expr} is an expression specifying the interval value to be added
or substracted from the starting date. @code{expr} is a string; it may start
with a @samp{-} for negative intervals. @code{type} is a keyword indicating
how the expression should be interpreted.
The @code{EXTRACT(type FROM date)} function returns the 'type'
interval from the date.
The following table shows how the @code{type} and @code{expr} arguments
are related:
@multitable @columnfractions .18 .3 .42
@item @code{type} @strong{value} @tab @strong{Meaning} @tab @strong{Expected} @code{expr} @strong{format}
@item @code{SECOND} @tab Seconds @tab @code{SECONDS}
@item @code{MINUTE} @tab Minutes @tab @code{MINUTES}
@item @code{HOUR} @tab Hours @tab @code{HOURS}
@item @code{DAY} @tab Days @tab @code{DAYS}
@item @code{MONTH} @tab Months @tab @code{MONTHS}
@item @code{YEAR} @tab Years @tab @code{YEARS}
@item @code{MINUTE_SECOND} @tab Minutes and seconds @tab @code{"MINUTES:SECONDS"}
@item @code{HOUR_MINUTE} @tab Hours and minutes @tab @code{"HOURS:MINUTES"}
@item @code{DAY_HOUR} @tab Days and hours @tab @code{"DAYS HOURS"}
@item @code{YEAR_MONTH} @tab Years and months @tab @code{"YEARS-MONTHS"}
@item @code{HOUR_SECOND} @tab Hours, minutes, @tab @code{"HOURS:MINUTES:SECONDS"}
@item @code{DAY_MINUTE} @tab Days, hours, minutes @tab @code{"DAYS HOURS:MINUTES"}
@item @code{DAY_SECOND} @tab Days, hours, minutes, seconds @tab @code{"DAYS HOURS:MINUTES:SECONDS"}
@end multitable
@strong{MySQL} allows any punctuation delimiter in the @code{expr} format.
The ones shown in the table are the suggested delimiters. If the @code{date}
argument is a @code{DATE} value and your calculations involve only
@code{YEAR}, @code{MONTH} and @code{DAY} parts (that is, no time parts), the
result is a @code{DATE} value. Otherwise the result is a @code{DATETIME}
value.
@example
mysql> SELECT "1997-12-31 23:59:59" + INTERVAL 1 SECOND;
-> 1998-01-01 00:00:00
mysql> SELECT INTERVAL 1 DAY + "1997-12-31";
-> 1998-01-01
mysql> SELECT "1998-01-01" - INTERVAL 1 SECOND;
-> 1997-12-31 23:59:59
mysql> SELECT DATE_ADD("1997-12-31 23:59:59",
INTERVAL 1 SECOND);
-> 1998-01-01 00:00:00
mysql> SELECT DATE_ADD("1997-12-31 23:59:59",
INTERVAL 1 DAY);
-> 1998-01-01 23:59:59
mysql> SELECT DATE_ADD("1997-12-31 23:59:59",
INTERVAL "1:1" MINUTE_SECOND);
-> 1998-01-01 00:01:00
mysql> SELECT DATE_SUB("1998-01-01 00:00:00",
INTERVAL "1 1:1:1" DAY_SECOND);
-> 1997-12-30 22:58:59
mysql> SELECT DATE_ADD("1998-01-01 00:00:00",
INTERVAL "-1 10" DAY_HOUR);
-> 1997-12-30 14:00:00
mysql> SELECT DATE_SUB("1998-01-02", INTERVAL 31 DAY);
-> 1997-12-02
mysql> SELECT EXTRACT(YEAR FROM "1999-07-02");
-> 1999
mysql> SELECT EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03");
-> 199907
mysql> SELECT EXTRACT(DAY_MINUTE FROM "1999-07-02 01:02:03");
-> 20102
@end example
If you specify an interval value that is too short (does not include all the
interval parts that would be expected from the @code{type} keyword),
@strong{MySQL} assumes you have left out the leftmost parts of the interval
value. For example, if you specify a @code{type} of @code{DAY_SECOND}, the
value of @code{expr} is expected to have days, hours, minutes and seconds
parts. If you specify a value like @code{"1:10"}, @strong{MySQL} assumes
that the days and hours parts are missing and the value represents minutes
and seconds. In other words, @code{"1:10" DAY_SECOND} is interpreted in such
a way that it is equivalent to @code{"1:10" MINUTE_SECOND}. This is
analogous to the way that @strong{MySQL} interprets @code{TIME} values
as representing elapsed time rather than as time of day.
If you use really incorrect dates, the result is @code{NULL}. If you add
@code{MONTH}, @code{YEAR_MONTH} or @code{YEAR} and the resulting date
has a day that is larger than the maximum day for the new month, the day is
adjusted to the maximum days in the new month.
@example
mysql> select DATE_ADD('1998-01-30', Interval 1 month);
-> 1998-02-28
@end example
Note from the preceding example that the word @code{INTERVAL} and the
@code{type} keyword are not case sensitive.
@findex TO_DAYS()
@item TO_DAYS(date)
Given a date @code{date}, returns a daynumber (the number of days since year
0).
@example
mysql> select TO_DAYS(950501);
-> 728779
mysql> select TO_DAYS('1997-10-07');
-> 729669
@end example
@code{TO_DAYS()} is not intended for use with values that precede the advent
of the Gregorian calendar (1582), because it doesn't take into account the
days that were lost when the calender was changed.
@findex FROM_DAYS()
@item FROM_DAYS(N)
Given a daynumber @code{N}, returns a @code{DATE} value.
@example
mysql> select FROM_DAYS(729669);
-> '1997-10-07'
@end example
@code{FROM_DAYS()} is not intended for use with values that precede the
advent of the Gregorian calendar (1582), because it doesn't take into account
the days that were lost when the calender was changed.
@findex DATE_FORMAT()
@item DATE_FORMAT(date,format)
Formats the @code{date} value according to the @code{format} string. The
following specifiers may be used in the @code{format} string:
@multitable @columnfractions .1 .9
@item @code{%M} @tab Month name (@code{January}..@code{December})
@item @code{%W} @tab Weekday name (@code{Sunday}..@code{Saturday})
@item @code{%D} @tab Day of the month with english suffix (@code{1st}, @code{2nd}, @code{3rd}, etc.)
@item @code{%Y} @tab Year, numeric, 4 digits
@item @code{%y} @tab Year, numeric, 2 digits
@item @code{%X} @tab Year for the week where Sunday is the first day of the week, numeric, 4 digits, used with '%V'
@item @code{%x} @tab Year for the week, where Monday is the first day of the week, numeric, 4 digits, used with '%v'
@item @code{%a} @tab Abbreviated weekday name (@code{Sun}..@code{Sat})
@item @code{%d} @tab Day of the month, numeric (@code{00}..@code{31})
@item @code{%e} @tab Day of the month, numeric (@code{0}..@code{31})
@item @code{%m} @tab Month, numeric (@code{01}..@code{12})
@item @code{%c} @tab Month, numeric (@code{1}..@code{12})
@item @code{%b} @tab Abbreviated month name (@code{Jan}..@code{Dec})
@item @code{%j} @tab Day of year (@code{001}..@code{366})
@item @code{%H} @tab Hour (@code{00}..@code{23})
@item @code{%k} @tab Hour (@code{0}..@code{23})
@item @code{%h} @tab Hour (@code{01}..@code{12})
@item @code{%I} @tab Hour (@code{01}..@code{12})
@item @code{%l} @tab Hour (@code{1}..@code{12})
@item @code{%i} @tab Minutes, numeric (@code{00}..@code{59})
@item @code{%r} @tab Time, 12-hour (@code{hh:mm:ss [AP]M})
@item @code{%T} @tab Time, 24-hour (@code{hh:mm:ss})
@item @code{%S} @tab Seconds (@code{00}..@code{59})
@item @code{%s} @tab Seconds (@code{00}..@code{59})
@item @code{%p} @tab @code{AM} or @code{PM}
@item @code{%w} @tab Day of the week (@code{0}=Sunday..@code{6}=Saturday)
@item @code{%U} @tab Week (@code{0}..@code{53}), where Sunday is the first day of the week
@item @code{%u} @tab Week (@code{0}..@code{53}), where Monday is the first day of the week
@item @code{%V} @tab Week (@code{1}..@code{53}), where Sunday is the first day of the week. Used with '%X'
@item @code{%v} @tab Week (@code{1}..@code{53}), where Monday is the first day of the week. Used with '%x'
@item @code{%%} @tab A literal @samp{%}.
@end multitable
All other characters are just copied to the result without interpretation.
@example
mysql> select DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y');
-> 'Saturday October 1997'
mysql> select DATE_FORMAT('1997-10-04 22:23:00', '%H:%i:%s');
-> '22:23:00'
mysql> select DATE_FORMAT('1997-10-04 22:23:00',
'%D %y %a %d %m %b %j');
-> '4th 97 Sat 04 10 Oct 277'
mysql> select DATE_FORMAT('1997-10-04 22:23:00',
'%H %k %I %r %T %S %w');
-> '22 22 10 10:23:00 PM 22:23:00 00 6'
mysql> select DATE_FORMAT('1999-01-01', '%X %V');
-> '1998 52'
@end example
As of @strong{MySQL} 3.23, the @code{%} character is required before
format specifier characters. In earlier versions of @strong{MySQL},
@code{%} was optional.
@findex TIME_FORMAT()
@item TIME_FORMAT(time,format)
This is used like the @code{DATE_FORMAT()} function above, but the
@code{format} string may contain only those format specifiers that handle
hours, minutes and seconds. Other specifiers produce a @code{NULL} value or
@code{0}.
@findex CURDATE()
@findex CURRENT_DATE
@item CURDATE()
@itemx CURRENT_DATE
Returns today's date as a value in @code{'YYYY-MM-DD'} or @code{YYYYMMDD}
format, depending on whether the function is used in a string or numeric
context.
@example
mysql> select CURDATE();
-> '1997-12-15'
mysql> select CURDATE() + 0;
-> 19971215
@end example
@findex CURTIME()
@findex CURRENT_TIME
@item CURTIME()
@itemx CURRENT_TIME
Returns the current time as a value in @code{'HH:MM:SS'} or @code{HHMMSS}
format, depending on whether the function is used in a string or numeric
context.
@example
mysql> select CURTIME();
-> '23:50:26'
mysql> select CURTIME() + 0;
-> 235026
@end example
@findex NOW()
@findex SYSDATE()
@findex CURRENT_TIMESTAMP
@item NOW()
@itemx SYSDATE()
@itemx CURRENT_TIMESTAMP
Returns the current date and time as a value in @code{'YYYY-MM-DD HH:MM:SS'}
or @code{YYYYMMDDHHMMSS} format, depending on whether the function is used in
a string or numeric context.
@example
mysql> select NOW();
-> '1997-12-15 23:50:26'
mysql> select NOW() + 0;
-> 19971215235026
@end example
@findex UNIX_TIMESTAMP()
@item UNIX_TIMESTAMP()
@itemx UNIX_TIMESTAMP(date)
If called with no argument, returns a Unix timestamp (seconds since
@code{'1970-01-01 00:00:00'} GMT). If @code{UNIX_TIMESTAMP()} is called with
a @code{date} argument, it returns the value of the argument as seconds since
@code{'1970-01-01 00:00:00'} GMT. @code{date} may be a @code{DATE} string,
a @code{DATETIME} string, a @code{TIMESTAMP}, or a number in the format
@code{YYMMDD} or @code{YYYYMMDD} in local time.
@example
mysql> select UNIX_TIMESTAMP();
-> 882226357
mysql> select UNIX_TIMESTAMP('1997-10-04 22:23:00');
-> 875996580
@end example
When @code{UNIX_TIMESTAMP} is used on a @code{TIMESTAMP} column, the function
will receive the value directly, with no implicit
``string-to-unix-timestamp'' conversion.
If you give @code{UNIX_TIMESTAMP()} a wrong or out-of-range date, it will
return 0.
@findex FROM_UNIXTIME()
@item FROM_UNIXTIME(unix_timestamp)
Returns a representation of the @code{unix_timestamp} argument as a value in
@code{'YYYY-MM-DD HH:MM:SS'} or @code{YYYYMMDDHHMMSS} format, depending on
whether the function is used in a string or numeric context.
@example
mysql> select FROM_UNIXTIME(875996580);
-> '1997-10-04 22:23:00'
mysql> select FROM_UNIXTIME(875996580) + 0;
-> 19971004222300
@end example
@findex FROM_UNIXTIME()
@item FROM_UNIXTIME(unix_timestamp,format)
Returns a string representation of the Unix timestamp, formatted according to
the @code{format} string. @code{format} may contain the same specifiers as
those listed in the entry for the @code{DATE_FORMAT()} function.
@example
mysql> select FROM_UNIXTIME(UNIX_TIMESTAMP(),
'%Y %D %M %h:%i:%s %x');
-> '1997 23rd December 03:43:30 x'
@end example
@findex SEC_TO_TIME()
@item SEC_TO_TIME(seconds)
Returns the @code{seconds} argument, converted to hours, minutes and seconds,
as a value in @code{'HH:MM:SS'} or @code{HHMMSS} format, depending on whether
the function is used in a string or numeric context.
@example
mysql> select SEC_TO_TIME(2378);
-> '00:39:38'
mysql> select SEC_TO_TIME(2378) + 0;
-> 3938
@end example
@findex TIME_TO_SEC()
@item TIME_TO_SEC(time)
Returns the @code{time} argument, converted to seconds.
@example
mysql> select TIME_TO_SEC('22:23:00');
-> 80580
mysql> select TIME_TO_SEC('00:39:38');
-> 2378
@end example
@end table
@findex Miscellaneous functions
@findex Functions, miscellaneous
@node Miscellaneous functions, Group by functions, Date and time functions, Functions
@subsection Miscellaneous functions
@table @code
@findex DATABASE()
@item DATABASE()
Returns the current database name.
@example
mysql> select DATABASE();
-> 'test'
@end example
If there is no current database, @code{DATABASE()} returns the empty string.
@findex USER()
@findex SYSTEM_USER()
@findex SESSION_USER()
@item USER()
@itemx SYSTEM_USER()
@itemx SESSION_USER()
Returns the current @strong{MySQL} user name.
@example
mysql> select USER();
-> 'davida@@localhost'
@end example
In @strong{MySQL} 3.22.11 or later, this includes the client hostname as well as the
user name. You can extract just the user name part like this (which works
whether or not the value includes a hostname part):
@example
mysql> select substring_index(USER(),"@@",1);
-> 'davida'
@end example
@findex PASSWORD()
@item PASSWORD(str)
Calculates a password string from the plaintext password @code{str}. This is
the function that is used for encrypting @strong{MySQL} passwords for storage
in the @code{Password} column of the @code{user} grant table.
@example
mysql> select PASSWORD('badpwd');
-> '7f84554057dd964b'
@end example
@cindex Password encryption, reversibility of
@code{PASSWORD()} encryption is non-reversible.
@code{PASSWORD()} does not perform password encryption in the same way that
Unix passwords are encrypted. You should not assume that if your Unix
password and your @strong{MySQL} password are the same, @code{PASSWORD()}
will result in the same encrypted value as is stored in the Unix password
file. See @code{ENCRYPT()}.
@findex ENCRYPT()
@item ENCRYPT(str[,salt])
Encrypt @code{str} using the Unix @code{crypt()} system call. The
@code{salt} argument should be a string with two characters.
(As of @strong{MySQL} 3.22.16, @code{salt} may be longer than two characters.)
@example
mysql> select ENCRYPT("hello");
-> 'VxuFAJXVARROc'
@end example
If @code{crypt()} is not available on your system, @code{ENCRYPT()} always
returns @code{NULL}.
@code{ENCRYPT()} ignores all but the first 8 characters of @code{str}, at
least on some systems. This will be determined by the behavior of the
underlying @code{crypt()} system call.
@findex ENCODE()
@item ENCODE(str,pass_str)
Encrypt @code{str} using @code{pass_str} as the password.
To decrypt the result, use @code{DECODE()}.
The results is a binary string of the same length as @code{string}.
If you want to save it in a column, use a @code{BLOB} column type.
@findex DECODE()
@item DECODE(crypt_str,pass_str)
Descrypts the encrypted string @code{crypt_str} using @code{pass_str} as the
password. @code{crypt_str} should be a string returned from
@code{ENCODE()}.
@findex MD5()
@item MD5(string)
Calculates a MD5 checksum for the string. Value is returned as a 32 long
hex number that may, for example, be used as a hash key.
@example
mysql> select MD5("testing")
-> 'ae2b1fca515949e5d54fb22b8ed95575'
@end example
This is an "RSA Data Security, Inc. MD5 Message-Digest Algorithm".
@findex LAST_INSERT_ID([expr])
@item LAST_INSERT_ID([expr])
Returns the last automatically generated value that was inserted into an
@code{AUTO_INCREMENT} column.
@xref{mysql_insert_id,, @code{mysql_insert_id()}}.
@example
mysql> select LAST_INSERT_ID();
-> 195
@end example
The last ID that was generated is maintained in the server on a
per-connection basis. It will not be changed by another client. It will not
even be changed if you update another @code{AUTO_INCREMENT} column with a
non-magic value (that is, a value that is not @code{NULL} and not @code{0}).
@cindex Sequence emulation
If @code{expr} is given as an argument to @code{LAST_INSERT_ID()} in an
@code{UPDATE} clause, then the value of the argument is returned as a
@code{LAST_INSERT_ID()} value. This can be used to simulate sequences:
First create the table:
@example
mysql> create table sequence (id int not null);
mysql> insert into sequence values (0);
@end example
Then the table can be used to generate sequence numbers like this:
@example
mysql> update sequence set id=LAST_INSERT_ID(id+1);
@end example
You can generate sequences without calling @code{LAST_INSERT_ID()}, but the
utility of using the function this way is that the ID value is maintained in
the server as the last automatically generated value. You can retrieve the
new ID as you would read any normal @code{AUTO_INCREMENT} value in
@strong{MySQL}. For example, @code{LAST_INSERT_ID()} (without an argument)
will return the new ID. The C API function @code{mysql_insert_id()}
can also be used to get the value.
@findex FORMAT()
@item FORMAT(X,D)
Formats the number @code{X} to a format like @code{'#,###,###.##'}, rounded
to @code{D} decimals. If @code{D} is @code{0}, the result will have no
decimal point or fractional part.
@example
mysql> select FORMAT(12332.123456, 4);
-> '12,332.1235'
mysql> select FORMAT(12332.1,4);
-> '12,332.1000'
mysql> select FORMAT(12332.2,0);
-> '12,332'
@end example
@findex VERSION()
@item VERSION()
Returns a string indicating the @strong{MySQL} server version.
@example
mysql> select VERSION();
-> '3.23.13-log'
@end example
Note that if your version ends with @code{-log} this means that logging is
enabled.
@findex CONNECTION_ID()
@item CONNECTION_ID()
Returns the connection id (@code{thread_id}) for the connection.
Every connection has its own unique id.
@example
mysql> select CONNECTION_ID();
-> 1
@end example
@findex GET_LOCK()
@item GET_LOCK(str,timeout)
Tries to obtain a lock with a name given by the string @code{str}, with a
timeout of @code{timeout} seconds. Returns @code{1} if the lock was obtained
successfully, @code{0} if the attempt timed out, or @code{NULL} if an error
occurred (such as running out of memory or the thread was killed with
@code{mysqladmin kill}). A lock is released when you execute
@code{RELEASE_LOCK()}, execute a new @code{GET_LOCK()} or the thread
terminates. This function can be used to implement application locks or to
simulate record locks. It blocks requests by other clients for locks with
the same name; clients that agree on a given lock string name can use the
string to perform cooperative advisory locking.
@example
mysql> select GET_LOCK("lock1",10);
-> 1
mysql> select GET_LOCK("lock2",10);
-> 1
mysql> select RELEASE_LOCK("lock2");
-> 1
mysql> select RELEASE_LOCK("lock1");
-> NULL
@end example
Note that the second @code{RELEASE_LOCK()} call returns @code{NULL} because
the lock @code{"lock1"} was automatically released by the second
@code{GET_LOCK()} call.
@findex RELEASE_LOCK()
@item RELEASE_LOCK(str)
Releases the lock named by the string @code{str} that was obtained with
@code{GET_LOCK()}. Returns @code{1} if the lock was released, @code{0} if the
lock wasn't locked by this thread (in which case the lock is not released)
and @code{NULL} if the named lock didn't exist. The lock will not exist if
it was never obtained by a call to @code{GET_LOCK()} or if it already has
been released.
@findex BENCHMARK()
@item BENCHMARK(count,expr)
The @code{BENCHMARK()} function executes the expression @code{expr}
repeatedly @code{count} times. It may be used to time how fast @strong{MySQL}
processes the expression. The result value is always @code{0}. The intended
use is in the @code{mysql} client, which reports query execution times.
@example
mysql> select BENCHMARK(1000000,encode("hello","goodbye"));
+----------------------------------------------+
| BENCHMARK(1000000,encode("hello","goodbye")) |
+----------------------------------------------+
| 0 |
+----------------------------------------------+
1 row in set (4.74 sec)
@end example
The time reported is elapsed time on the client end, not CPU time on the
server end. It may be advisable to execute @code{BENCHMARK()} several
times, and interpret the result with regard to how heavily loaded the
server machine is.
@findex INET_NTOA()
@item INET_NTOA(expr)
Returns the network address (4 or 8 byte) for the numeric expression.
@example
mysql> select INET_NTOA(3520061480);
-> "209.207.224.40"
@end example
@findex INET_ATON()
@item INET_ATON(expr)
Returns an integer that represents the numeric value for a network address
Addresses may be 4 or 8 byte addresses.
@example
mysql> select INET_ATON("209.207.224.40");
-> 3520061480
@end example
@end table
@findex GROUP BY functions
@findex Functions, GROUP BY
@node Group by functions, , Miscellaneous functions, Functions
@subsection Functions for use with @code{GROUP BY} clauses
If you use a group function in a statement containing no @code{GROUP BY}
clause, it is equivalent to grouping on all rows.
@table @code
@findex COUNT()
@item COUNT(expr)
Returns a count of the number of non-@code{NULL} values in the rows
retrieved by a @code{SELECT} statement.
@example
mysql> select student.student_name,COUNT(*)
from student,course
where student.student_id=course.student_id
GROUP BY student_name;
@end example
@code{COUNT(*)} is somewhat different in that it returns a count of
the number of rows retrieved, whether or not they contain @code{NULL}
values.
@code{COUNT(*)} is optimized to
return very quickly if the @code{SELECT} retrieves from one table, no
other columns are retrieved and there is no @code{WHERE} clause.
For example:
@example
mysql> select COUNT(*) from student;
@end example
@findex COUNT(DISTINCT)
@findex DISTINCT
@item COUNT(DISTINCT expr,[expr...])
Returns a count of the number of different values.
@example
mysql> select COUNT(DISTINCT results) from student;
@end example
In @strong{MySQL} you can get the number of distinct expressions combinations
by giving a list of expressions. In ANSI SQL you would have to do a
concatenation of all expressions inside @code{CODE(DISTINCT ..)}.
@findex AVG()
@item AVG(expr)
Returns the average value of @code{expr}.
@example
mysql> select student_name, AVG(test_score)
from student
GROUP BY student_name;
@end example
@findex MIN()
@findex MAX()
@item MIN(expr)
@itemx MAX(expr)
Returns the minimum or maximum value of @code{expr}. @code{MIN()} and
@code{MAX()} may take a string argument; in such cases they return the
minimum or maximum string value.
@example
mysql> select student_name, MIN(test_score), MAX(test_score)
from student
GROUP BY student_name;
@end example
@findex SUM()
@item SUM(expr)
Returns the sum of @code{expr}. Note that if the return set has no rows,
it returns NULL!
@findex STD()
@findex STDDEV()
@cindex Oracle compatibility
@cindex Compatibility, with Oracle
@item STD(expr)
@itemx STDDEV(expr)
Returns the standard deviation of @code{expr}. This is an extension to
ANSI SQL.
The @code{STDDEV()} form of this function is provided for Oracle compatability.
@findex BIT_OR()
@item BIT_OR(expr)
Returns the bitwise @code{OR} of all bits in @code{expr}. The calculation is
performed with 64-bit (@code{BIGINT} precision.
@findex BIT_AND()
@item BIT_AND(expr)
Returns the bitwise @code{AND} of all bits in @code{expr}. The calculation is
performed with 64-bit (@code{BIGINT} precision.
@end table
@strong{MySQL} has extended the use of @code{GROUP BY}. You can use columns or
calculations in the @code{SELECT} expressions which don't appear in
the @code{GROUP BY} part. This stands for @emph{any possible value for this
group}. You can use this to get better performance by avoiding sorting and
grouping on unnecessary items. For example, you don't need to group on
@code{customer.name} in the following query:
@example
mysql> select order.custid,customer.name,max(payments)
from order,customer
where order.custid = customer.custid
GROUP BY order.custid;
@end example
In ANSI SQL, you would have to add @code{customer.name} to the @code{GROUP
BY} clause. In @strong{MySQL}, the name is redundant if you don't run in
ANSI mode.
Don't use this feature if the columns you omit from the @code{GROUP BY} part
aren't unique in the group!
In some cases, you can use @code{MIN()} and @code{MAX()} to obtain a specific
column value even if it isn't unique. The following gives the value of
@code{column} from the row containing the smallest value in the @code{sort}
column:
@example
substr(MIN(concat(sort,space(6-length(sort)),column),7,length(column)))
@end example
@cindex @code{ORDER BY}, aliases in
@cindex Aliases, in @code{ORDER BY} clauses
@cindex @code{GROUP BY}, aliases in
@cindex Aliases, in @code{GROUP BY} clauses
@cindex Expressions, aliases for
@cindex Aliases, for expressions
Note that if you are using @strong{MySQL} 3.22 (or earlier) or if you
are trying to follow ANSI SQL, you can't use expressions in @code{GROUP
BY} or @code{ORDER BY} clauses. You can work around this limitation by
using an alias for the expression:
@example
mysql> SELECT id,FLOOR(value/100) AS val FROM tbl_name
GROUP BY id,val ORDER BY val;
@end example
In @code{MySQL} 3.23 you can do:
@example
mysql> SELECT id,FLOOR(value/100) FROM tbl_name ORDER BY RAND();
@end example
@findex CREATE DATABASE
@node CREATE DATABASE, DROP DATABASE, Functions, Reference
@section @code{CREATE DATABASE} syntax
@example
CREATE DATABASE [IF NOT EXISTS] db_name
@end example
@code{CREATE DATABASE} creates a database with the given name. Rules for
allowable database names are given in @ref{Legal names}. An error occurs if
the database already exists and you didn't specify @code{IF NOT EXISTS}.
Databases in @strong{MySQL} are implemented as directories containing files
that correspond to tables in the database. Because there are no tables in a
database when it is initially created, the @code{CREATE DATABASE} statement
only creates a directory under the @strong{MySQL} data directory.
@cindex @code{mysqladmin}
You can also create databases with @code{mysqladmin}.
@xref{Programs}.
@findex DROP DATABASE
@node DROP DATABASE, CREATE TABLE, CREATE DATABASE, Reference
@section @code{DROP DATABASE} syntax
@example
DROP DATABASE [IF EXISTS] db_name
@end example
@code{DROP DATABASE} drops all tables in the database and deletes the
database. @strong{Be VERY careful with this command!}
@code{DROP DATABASE} returns the number of files that were removed from the
database directory. Normally, this is three times the number of tables,
because each table corresponds to a @file{.MYD} file, a @file{.MYI} file and a
@file{.frm} file.
In @strong{MySQL} 3.22 or later, you can use the keywords @code{IF EXISTS} to
prevent an error from occurring if the database doesn't exist.
@cindex @code{mysqladmin}
You can also drop databases with @code{mysqladmin}.
@xref{Programs}.
@findex CREATE TABLE
@node CREATE TABLE, ALTER TABLE, DROP DATABASE, Reference
@section @code{CREATE TABLE} syntax
@menu
* Silent column changes:: Silent column changes
@end menu
@example
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)]
[table_options] [select_statement]
create_definition:
col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT]
[PRIMARY KEY] [reference_definition]
or PRIMARY KEY (index_col_name,...)
or KEY [index_name] (index_col_name,...)
or INDEX [index_name] (index_col_name,...)
or UNIQUE [INDEX] [index_name] (index_col_name,...)
or [CONSTRAINT symbol] FOREIGN KEY index_name (index_col_name,...)
[reference_definition]
or CHECK (expr)
type:
TINYINT[(length)] [UNSIGNED] [ZEROFILL]
or SMALLINT[(length)] [UNSIGNED] [ZEROFILL]
or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL]
or INT[(length)] [UNSIGNED] [ZEROFILL]
or INTEGER[(length)] [UNSIGNED] [ZEROFILL]
or BIGINT[(length)] [UNSIGNED] [ZEROFILL]
or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL]
or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL]
or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL]
or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL]
or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL]
or CHAR(length) [BINARY]
or VARCHAR(length) [BINARY]
or DATE
or TIME
or TIMESTAMP
or DATETIME
or TINYBLOB
or BLOB
or MEDIUMBLOB
or LONGBLOB
or TINYTEXT
or TEXT
or MEDIUMTEXT
or LONGTEXT
or ENUM(value1,value2,value3,...)
or SET(value1,value2,value3,...)
index_col_name:
col_name [(length)]
reference_definition:
REFERENCES tbl_name [(index_col_name,...)]
[MATCH FULL | MATCH PARTIAL]
[ON DELETE reference_option]
[ON UPDATE reference_option]
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT
table_options:
TYPE = @{ISAM | MYISAM | HEAP@}
or AUTO_INCREMENT = #
or AVG_ROW_LENGTH = #
or CHECKSUM = @{0 | 1@}
or COMMENT = "string"
or MAX_ROWS = #
or MIN_ROWS = #
or PACK_KEYS = @{0 | 1@}
or PASSWORD = "string"
or DELAY_KEY_WRITE = @{0 | 1@}
or ROW_FORMAT= @{ default | dynamic | static | compressed @}
or RAID_TYPE= @{1 | STRIPED | RAID0 @} RAID_CHUNKS=# RAID_CHUNKSIZE=#;
select_statement:
[IGNORE | REPLACE] SELECT ... (Some legal select statement)
@end example
@code{CREATE TABLE}
creates a table with the given name in the current database. Rules for
allowable table names are given in @ref{Legal names}. An error occurs if
there is no current database or if the table already exists.
In @strong{MySQL} 3.22 or later, the table name can be specified as
@code{db_name.tbl_name}. This works whether or not there is a current
database.
In @strong{MySQL} 3.23, you can use the @code{TEMPORARY} keyword when you
create a table. A temporary table will automatically be deleted if a
connection dies and the name is per connection. This means that two different
connections can both use the same temporary table name without conflicting
with each other or with an existing table of the same name. (The existing table
is hidden until the temporary table is deleted).
In @strong{MySQL} 3.23 or later, you can use the keywords @code{IF NOT EXISTS}
so that an error does not occur if the table already exists. Note that there
is no verification that the table structures are identical.
Each table @code{tbl_name} is represented by some files in the database
directory. In the case of MyISAM-type tables you will get:
@multitable @columnfractions .2 .8
@item @strong{File} @tab @strong{Purpose}
@item @code{tbl_name.frm} @tab Table definition (form) file
@item @code{tbl_name.MYD} @tab Data file
@item @code{tbl_name.MYI} @tab Index file
@end multitable
For more information on the properties of the various column types, see
@ref{Column types}.
@itemize @bullet
@item
If neither @code{NULL} nor @code{NOT NULL} is specified, the column
is treated as though @code{NULL} had been specified.
@item
An integer column may have the additional attribute @code{AUTO_INCREMENT}.
When you insert a value of @code{NULL} (recommended) or @code{0} into an
@code{AUTO_INCREMENT} column, the column is set to @code{value+1}, where
@code{value} is the largest value for the column currently in the table.
@code{AUTO_INCREMENT} sequences begin with @code{1}.
@xref{mysql_insert_id, , @code{mysql_insert_id()}}.
If you delete the row containing the maximum value for an
@code{AUTO_INCREMENT} column, the value will be reused with an ISAM
table but not with a @code{MyISAM} table. If you delete all rows in the
table with @code{DELETE FROM table_name} (without a @code{WHERE}) in
@code{AUTOCOMMIT} mode, the sequence starts over for both table types.
@strong{Note:} There can be only one @code{AUTO_INCREMENT} column per
table, and it must be indexed. @strong{MySQL} 3.23 will also only work
properly if the auto_increment column only has positive
values. Inserting a negative number is regarded as inserting a very large
positive number. This is done to avoid precision problems when
numbers 'wrap' over from positive to negative and also to ensure that one
doesn't accidently get a auto_increment column that contains 0.
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
To make @strong{MySQL} compatible with some ODBC applications, you can find
the last inserted row with the following query:
@example
SELECT * FROM tbl_name WHERE auto_col IS NULL
@end example
@item
@code{NULL} values are handled differently for @code{TIMESTAMP} columns than
for other column types. You cannot store a literal @code{NULL} in a
@code{TIMESTAMP} column; setting the column to @code{NULL} sets it to the
current date and time. Because @code{TIMESTAMP} columns behave this way, the
@code{NULL} and @code{NOT NULL} attributes do not apply in the normal way and
are ignored if you specify them.
On the other hand, to make it easier for @strong{MySQL} clients to use
@code{TIMESTAMP} columns, the server reports that such columns may be
assigned @code{NULL} values (which is true), even though @code{TIMESTAMP}
never actually will contain a @code{NULL} value. You can see this when you
use @code{DESCRIBE tbl_name} to get a description of your table.
Note that setting a @code{TIMESTAMP} column to @code{0} is not the same
as setting it to @code{NULL}, because @code{0} is a valid @code{TIMESTAMP}
value.
@item
If no @code{DEFAULT} value is specified for a column, @strong{MySQL}
automatically assigns one.
If the column may take @code{NULL} as a value, the default value is
@code{NULL}.
If the column is declared as @code{NOT NULL}, the default value depends on
the column type:
@itemize @minus
@item
For numeric types other than those declared with the @code{AUTO_INCREMENT}
attribute, the default is @code{0}. For an @code{AUTO_INCREMENT} column, the
default value is the next value in the sequence.
@item
For date and time types other than @code{TIMESTAMP}, the default is the
appropriate ``zero'' value for the type. For the first @code{TIMESTAMP}
column in a table, the default value is the current date and time.
@xref{Date and time types}.
@item
For string types other than @code{ENUM}, the default value is the empty string.
For @code{ENUM}, the default is the first enumeration value.
@end itemize
@item
@code{KEY} is a synonym for @code{INDEX}.
@item
In @strong{MySQL}, a @code{UNIQUE} key can have only distinct values. An
error occurs if you try to add a new row with a key that matches an existing
row.
@item
A @code{PRIMARY KEY} is a unique @code{KEY} with the extra constraint
that all key columns must be defined as @code{NOT NULL}. In @strong{MySQL}
the key is named @code{PRIMARY}. A table can have only one @code{PRIMARY KEY}.
If you don't have a @code{PRIMARY KEY} and some applications ask for the
@code{PRIMARY KEY} in your tables, @strong{MySQL} will return the first
@code{UNIQUE} key, which doesn't have any @code{NULL} columns, as the
@code{PRIMARY KEY}.
@item
A @code{PRIMARY KEY} can be a multiple-column index. However, you cannot
create a multiple-column index using the @code{PRIMARY KEY} key attibute in a
column specification. Doing so will mark only that single column as primary.
You must use the @code{PRIMARY KEY(index_col_name, ...)} syntax.
@item
If the @code{PRIMARY} or @code{UNIQUE} key consists of only one column and this
is of type integer, you can also refer to it as @code{_rowid}
(new in 3.23.11).
@item
If you don't assign a name to an index, the index will be assigned the same
name as the first @code{index_col_name}, with an optional suffix (@code{_2},
@code{_3}, @code{...}) to make it unique. You can see index names for a
table using @code{SHOW INDEX FROM tbl_name}.
@xref{SHOW, , @code{SHOW}}.
@item
@cindex @code{NULL} values, and indexes
@cindex Indexes, and @code{NULL} values
Only the @code{MyISAM} table type supports indexes on columns that can have
@code{NULL} values. In other cases you must declare such columns
@code{NOT NULL} or an error results.
@item
With @code{col_name(length)} syntax, you can specify an index which
uses only a part of a @code{CHAR} or @code{VARCHAR} column. This can
make the index file much smaller.
@xref{Indexes}.
@item
@cindex @code{BLOB} columns, indexing
@cindex Indexes, and @code{BLOB} columns
@cindex @code{TEXT} columns, indexing
@cindex Indexes, and @code{TEXT} columns
Only the @code{MyISAM} table type supports indexing on @code{BLOB} and
@code{TEXT} columns. When putting an index on a @code{BLOB} or @code{TEXT}
column you MUST always specify the length of the index:
@example
CREATE TABLE test (blob_col BLOB, index(blob_col(10)));
@end example
@item
When you use @code{ORDER BY} or @code{GROUP BY} with a @code{TEXT} or
@code{BLOB} column, only the first @code{max_sort_length} bytes are used.
@xref{BLOB, , @code{BLOB}}.
@item
The @code{FOREIGN KEY}, @code{CHECK} and @code{REFERENCES} clauses don't
actually do anything. The syntax for them is provided only for compatibility,
to make it easier to port code from other SQL servers and to run applications
that create tables with references.
@xref{Missing functions}.
@item
Each @code{NULL} column takes one bit extra, rounded up to the nearest byte.
@item
The maximum record length in bytes can be calculated as follows:
@example
row length = 1
+ (sum of column lengths)
+ (number of NULL columns + 7)/8
+ (number of variable-length columns)
@end example
@item The @code{table_options} and @code{SELECT} options is only
implemented in @strong{MySQL} 3.23 and above.
The different table types are:
@multitable @columnfractions .20 .80
@item ISAM @tab The original table handler. @xref{ISAM}.
@item MyISAM @tab The new binary portable table handler. @xref{MyISAM}.
@item HEAP @tab The data for this table is only stored in memory. @xref{HEAP}.
@item BDB or Berkeley_db @tab Transaction safe tables @xref{BDB}.
@end multitable
@xref{Table types}.
The other table options are used to optimize the behavior of the
table. In most cases, you don't have to specify any of them.
The options work for all table types, if not otherwise indicated.
@multitable @columnfractions .20 .80
@item @code{AUTO_INCREMENT} @tab The next auto_increment value you want to set for your table (MyISAM)
@item @code{AVG_ROW_LENGTH} @tab An approximation of the average row length for your table. You only need to set this for tables with variable size records.
@item @code{CHECKSUM} @tab Set this to 1 if you want @strong{MySQL} to maintain a checksum for all rows (makes the table a little slower to update but makes it easier to find corrupted tables) (MyISAM)
@item @code{COMMENT} @tab A 60 character comment for your table
@item @code{MAX_ROWS} @tab Max number of rows you plan to store in the table
@item @code{MIN_ROWS} @tab Minimum number of rows you plan to store in the table
@item @code{PACK_KEYS} @tab Set this to 1 if you want to have smaller index. This usually makes updates slower and reads faster (MyISAM, ISAM).
@item @code{PASSWORD} @tab Encrypt the @code{.frm} file with a password. This option doesn't do anything in the standard @strong{MySQL} version.
@item @code{DELAY_KEY_WRITE} @tab Set this to 1 if want to delay key table updates until the table is closed (MyISAM).
@item @code{ROW_FORMAT} @tab Defines how the rows should be stored (for the future).
@end multitable
When you use a @code{MyISAM} table, @strong{MySQL} uses the product of
@code{max_rows * avg_row_length} to decide how big the resulting table
will be. If you don't specify any of the above options, the maximum size
for a table will be 4G (or 2G if your operating systems only supports 2G
tables).
If you don't use @code{PACK_KEYS}, the default is to only pack strings,
not numbers. If you use @code{PACK_KEYS=1}, numbers will be packed as well.
When packing binary number keys, @strong{MySQL} will use prefix compression.
This means that you will only get a big benefit of this if you have
many numbers that are the same. Prefix compression means that every
key needs one extra byte to indicate how many bytes of the previous key are
the same for the next key (note that the pointer to the row is stored
in high-byte-first-order directly after the key, to improve
compression. This means that if you have many equal keys on two rows
in a row, all following 'same' keys will usually only take 2 bytes
(including the pointer to the row). Compare this to the ordinary case
where the following keys will take 'storage_size_for_key' +
pointer_size (usually 4). On the other hand, if all keys are
totally different, you will lose 1 byte per key, if the key isn't a
key that can have @code{NULL} values (In this case the packed key length will
be stored in the same byte that is used to mark if a key is @code{NULL}).
@item
If you specify a @code{SELECT} after the @code{CREATE STATEMENT},
@strong{MySQL} will create new fields for all elements in the
@code{SELECT}. For example:
@example
mysql> CREATE TABLE test (a int not null auto_increment,
primary key (a), key(b))
TYPE=HEAP SELECT b,c from test2;
@end example
This will create a @code{HEAP} table with 3 columns. Note that the table will
automatically be deleted if any errors occur while copying data
into the table.
@item
The @code{RAID_TYPE} option will help you to break the 2G/4G limit on OSes
that don't support big files. You can get also more speed from the I/O
bottleneck by putting @code{RAID} directories on different physical disks.
@code{RAID_TYPE} will work on any OS, as long as you have configured
@strong{MySQL} with @code{--with-raid}. For now the only allowed
@code{RAID_TYPE} is @code{STRIPED} (@code{1} and @code{RAID0} are aliases
for this).
If you specify @code{RAID_TYPE=STRIPED} for a @code{MyISAM} table,
@code{MyISAM} will create @code{RAID_CHUNKS} sub-directories named 00,
01, 02 in the database directory. In each of these directories
@code{MyISAM} will create an @code{table_name.MYD}. When writing data
to the data file, the @code{RAID} handler will map the first
@code{RAID_CHUNKSIZE} *1024 bytes to the first file, the next
@code{RAID_CHUNKSIZE} *1024 bytes to the next file and so on.
@end itemize
@node Silent column changes, , CREATE TABLE, CREATE TABLE
@subsection Silent column specification changes
In some cases, @strong{MySQL} silently changes a column specification from
that given in a @code{CREATE TABLE} statement. (This may also occur with
@code{ALTER TABLE}.)
@itemize @bullet
@item
@code{VARCHAR} columns with a length less than four are changed to
@code{CHAR}.
@item
If any column in a table has a variable length, the entire row is
variable-length as a result. Therefore, if a table contains any
variable-length columns (@code{VARCHAR}, @code{TEXT} or @code{BLOB}),
all @code{CHAR} columns longer than three characters are changed to
@code{VARCHAR} columns. This doesn't affect how you use the columns in
any way; in @strong{MySQL}, @code{VARCHAR} is just a different way to
store characters. @strong{MySQL} performs this conversion because it
saves space and makes table operations faster. @xref{Table types}.
@item
@code{TIMESTAMP} display sizes must be even and in the range from 2 to 14.
If you specify a display size of 0 or greater than 14, the size is coerced
to 14. Odd-valued sizes in the range from 1 to 13 are coerced
to the next higher even number.
@item
You cannot store a literal @code{NULL} in a @code{TIMESTAMP} column; setting
it to @code{NULL} sets it to the current date and time. Because
@code{TIMESTAMP} columns behave this way, the @code{NULL} and @code{NOT NULL}
attributes do not apply in the normal way and are ignored if you specify
them. @code{DESCRIBE tbl_name} always reports that a @code{TIMESTAMP}
column may be assigned @code{NULL} values.
@item
@strong{MySQL} maps certain column types used by other SQL database vendors
to @strong{MySQL} types. @xref{Other-vendor column types}.
@end itemize
If you want to see whether or not @strong{MySQL} used a column type other
than the one you specified, issue a @code{DESCRIBE tbl_name} statement after
creating or altering your table.
@cindex @code{myisampack}
Certain other column type changes may occur if you compress a table
using @code{myisampack}. @xref{Compressed format}.
@findex ALTER TABLE
@node ALTER TABLE, DROP TABLE, CREATE TABLE, Reference
@section @code{ALTER TABLE} syntax
@example
ALTER [IGNORE] TABLE tbl_name alter_spec [, alter_spec ...]
alter_specification:
ADD [COLUMN] create_definition [FIRST | AFTER column_name ]
or ADD [COLUMN] (create_definition, create_definition,...)
or ADD INDEX [index_name] (index_col_name,...)
or ADD PRIMARY KEY (index_col_name,...)
or ADD UNIQUE [index_name] (index_col_name,...)
or ALTER [COLUMN] col_name @{SET DEFAULT literal | DROP DEFAULT@}
or CHANGE [COLUMN] old_col_name create_definition
or MODIFY [COLUMN] create_definition
or DROP [COLUMN] col_name
or DROP PRIMARY KEY
or DROP INDEX index_name
or RENAME [AS] new_tbl_name
or table_options
@end example
@code{ALTER TABLE} allows you to change the structure of an existing table.
For example, you can add or delete columns, create or destroy indexes, change
the type of existing columns, or rename columns or the table itself. You can
also change the comment for the table and type of the table.
@xref{CREATE TABLE, , @code{CREATE TABLE}}.
If you use @code{ALTER TABLE} to change a column specification but
@code{DESCRIBE tbl_name} indicates that your column was not changed, it is
possible that @strong{MySQL} ignored your modification for one of the reasons
described in @ref{Silent column changes}. For example, if you try to change
a @code{VARCHAR} column to @code{CHAR}, @strong{MySQL} will still use
@code{VARCHAR} if the table contains other variable-length columns.
@code{ALTER TABLE} works by making a temporary copy of the original table.
The alteration is performed on the copy, then the original table is
deleted and the new one is renamed. This is done in such a way that
all updates are automatically redirected to the new table without
any failed updates. While @code{ALTER TABLE} is executing, the original
table is readable by other clients. Updates and writes to the table
are stalled until the new table is ready.
@itemize @bullet
@item
To use @code{ALTER TABLE}, you need @strong{select}, @strong{insert},
@strong{delete}, @strong{update}, @strong{create} and @strong{drop}
privileges on the table.
@item
@code{IGNORE} is a @strong{MySQL} extension to ANSI SQL92.
It controls how @code{ALTER TABLE} works if there are duplicates on
unique keys in the new table.
If @code{IGNORE} isn't specified, the copy is aborted and rolled back.
If @code{IGNORE} is specified, then for rows with duplicates on a unique
key, only the first row is used; the others are deleted.
@item
You can issue multiple @code{ADD}, @code{ALTER}, @code{DROP} and
@code{CHANGE} clauses in a single @code{ALTER TABLE} statement. This is a
@strong{MySQL} extension to ANSI SQL92, which allows only one of each clause
per @code{ALTER TABLE} statement.
@item
@code{CHANGE col_name}, @code{DROP col_name} and @code{DROP
INDEX} are @strong{MySQL} extensions to ANSI SQL92.
@item
@code{MODIFY} is an Oracle extension to @code{ALTER TABLE}.
@item
The optional word @code{COLUMN} is a pure noise word and can be omitted.
@item
If you use @code{ALTER TABLE tbl_name RENAME AS new_name} without any other
options, @strong{MySQL} simply renames the files that correspond to the table
@code{tbl_name}. There is no need to create the temporary table.
@item
@code{create_definition} clauses use the same syntax for @code{ADD} and
@code{CHANGE} as for @code{CREATE TABLE}. Note that this syntax includes
the column name, not just the column type.
@xref{CREATE TABLE, , @code{CREATE TABLE}}.
@item
You can rename a column using a @code{CHANGE old_col_name create_definition}
clause. To do so, specify the old and new column names and the type that
the column currently has. For example, to rename an @code{INTEGER} column
from @code{a} to @code{b}, you can do this:
@example
mysql> ALTER TABLE t1 CHANGE a b INTEGER;
@end example
If you want to change a column's type but not the name, @code{CHANGE}
syntax still requires two column names even if they are the same. For
example:
@example
mysql> ALTER TABLE t1 CHANGE b b BIGINT NOT NULL;
@end example
However, as of @strong{MySQL} 3.22.16a, you can also use @code{MODIFY} to
change a column's type without renaming it:
@example
mysql> ALTER TABLE t1 MODIFY b BIGINT NOT NULL;
@end example
@item
If you use @code{CHANGE} or @code{MODIFY} to shorten a column for which
an index exists on part of the column (for instance, if you have an index
on the first 10 characters of a @code{VARCHAR} column), you cannot make
the column shorter than the number of characters that are indexed.
@item
When you change a column type using @code{CHANGE} or @code{MODIFY},
@strong{MySQL} tries to convert data to the new type as well as possible.
@item
In @strong{MySQL} 3.22 or later, you can use @code{FIRST} or @code{ADD ...
AFTER col_name} to add a column at a specific position within a table row.
The default is to add the column last.
@item
@code{ALTER COLUMN} specifies a new default value for a column
or removes the old default value.
If the old default is removed and the column can be @code{NULL}, the new
default is @code{NULL}. If the column cannot be @code{NULL}, @strong{MySQL}
assigns a default value.
Default value assignment is described in
@ref{CREATE TABLE, , @code{CREATE TABLE}}.
@item
@code{DROP INDEX} removes an index. This is a @strong{MySQL} extension to
ANSI SQL92.
@item
If columns are dropped from a table, the columns are also removed from any
index of which they are a part. If all columns that make up an index are
dropped, the index is dropped as well.
@item
@code{DROP PRIMARY KEY} drops the primary index. If no such
index exists, it drops the first @code{UNIQUE} index in the table.
(@strong{MySQL} marks the first @code{UNIQUE} key as the @code{PRIMARY KEY}
if no @code{PRIMARY KEY} was specified explicitly.)
@item
@findex mysql_info()
With the C API function @code{mysql_info()}, you can find out how many
records were copied, and (when @code{IGNORE} is used) how many records were
deleted due to duplication of unique key values.
@item
@cindex Foreign keys
@cindex References
The @code{FOREIGN KEY}, @code{CHECK} and @code{REFERENCES} clauses don't
actually do anything. The syntax for them is provided only for compatibility,
to make it easier to port code from other SQL servers and to run applications
that create tables with references.
@xref{Missing functions}.
@end itemize
Here is an example that shows some of the uses of @code{ALTER TABLE}. We
begin with a table @code{t1} that is created as shown below:
@example
mysql> CREATE TABLE t1 (a INTEGER,b CHAR(10));
@end example
To rename the table from @code{t1} to @code{t2}:
@example
mysql> ALTER TABLE t1 RENAME t2;
@end example
To change column @code{a} from @code{INTEGER} to @code{TINYINT NOT NULL}
(leaving the name the same), and to change column @code{b} from
@code{CHAR(10)} to @code{CHAR(20)} as well as renaming it from @code{b} to
@code{c}:
@example
mysql> ALTER TABLE t2 MODIFY a TINYINT NOT NULL, CHANGE b c CHAR(20);
@end example
To add a new @code{TIMESTAMP} column named @code{d}:
@example
mysql> ALTER TABLE t2 ADD d TIMESTAMP;
@end example
To add an index on column @code{d}, and make column @code{a} the primary key:
@example
mysql> ALTER TABLE t2 ADD INDEX (d), ADD PRIMARY KEY (a);
@end example
To remove column @code{c}:
@example
mysql> ALTER TABLE t2 DROP COLUMN c;
@end example
To add a new @code{AUTO_INCREMENT} integer column named @code{c}:
@example
mysql> ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT,
ADD INDEX (c);
@end example
Note that we indexed @code{c}, because @code{AUTO_INCREMENT} columns must be
indexed, and also that we declare @code{c} as @code{NOT NULL}, because
indexed columns cannot be @code{NULL}.
When you add an @code{AUTO_INCREMENT} column, column values are filled in
with sequence numbers for you automatically.
See also @xref{ALTER TABLE problems, , @code{ALTER TABLE} problems}.
@findex DROP TABLE
@node DROP TABLE, OPTIMIZE TABLE, ALTER TABLE, Reference
@section @code{DROP TABLE} syntax
@example
DROP TABLE [IF EXISTS] tbl_name [, tbl_name,...]
@end example
@code{DROP TABLE} removes one or more tables. All table data and the table
definition are @emph{removed}, so @strong{be careful} with this command!
In @strong{MySQL} 3.22 or later, you can use the keywords @code{IF EXISTS} to
prevent an error from occurring for tables that don't exist.
@findex OPTIMIZE TABLE
@node OPTIMIZE TABLE, CHECK TABLE, DROP TABLE, Reference
@section @code{OPTIMIZE TABLE} syntax
@example
OPTIMIZE TABLE tbl_name
@end example
@code{OPTIMIZE TABLE} should be used if you have deleted a large part of a
table or if you have made many changes to a table with variable-length rows
(tables that have @code{VARCHAR}, @code{BLOB} or @code{TEXT} columns).
Deleted records are maintained in a linked list and subsequent @code{INSERT}
operations reuse old record positions. You can use @code{OPTIMIZE TABLE} to
reclaim the unused space.
@code{OPTIMIZE TABLE} works by making a temporary copy of the original
table; The old table is copied to the new table (without the unused
rows), then the original table is deleted and the new one is
renamed. While @code{OPTIMIZE TABLE} is executing, the original table is
readable by other clients. Updates and writes to the table are stalled
until the new table is ready. This is done in such a way that all updates
are automatically redirected to the new table without any failed updates.
@findex CHECK TABLE
@node CHECK TABLE, ANALYZE TABLE, OPTIMIZE TABLE, Reference
@section @code{CHECK TABLE} syntax
@example
CHECK TABLE tbl_name[,tbl_name...] [TYPE = QUICK]
@end example
Check the table(s) for errors. The command returns a table with the following
columns:
@multitable @columnfractions .35 .65
@item Table @tab Table name
@item Op @tab Always 'check'
@item Msg_type @tab One of @code{status}, @code{error}, @code{info} or @code{warning}.
@item Msg_text @tab The message.
@end multitable
Note that you can get many rows of information for each checked table. The
last one row will be of @code{Msg_type status} and should normally be
@code{OK}. If you don't get @code{OK}, you should normally run a repair of
the table. @xref{Table maintenance}.
If @code{TYPE=QUICK} is given then @strong{MySQL} will not scan the rows
for table with fixed size records.
@code{CHECK TABLE} only works on @code{MyISAM} tables and is the same things
as running @code{myisamchk -m table_name} on the table.
@findex ANALYZE TABLE
@node ANALYZE TABLE, REPAIR TABLE, CHECK TABLE, Reference
@section @code{ANALYZE TABLE} syntax
@example
ANALYZE TABLE tbl_name[,tbl_name...]
@end example
Analyze and store the key distribution for the table. During the
analyze the table is locked with a read lock.
This is equivalent of running @code{myisamchk -a} on the table.
@strong{MySQL} uses the stored key distribution to decide in which order
tables should be joined when one does a join on something else than a
constant.
The command returns a table with the following columns:
@multitable @columnfractions .35 .65
@item Table @tab Table name
@item Op @tab Always 'analyze
@item Msg_type @tab One of @code{status}, @code{error}, @code{info} or @code{warning}.
@item Msg_text @tab The message.
@end multitable
You can check the stored key distribution with the @code{SHOW INDEX} command.
@xref{SHOW DATABASE INFO}.
@findex REPAIR TABLE
@node REPAIR TABLE, DELETE, ANALYZE TABLE, Reference
@section @code{REPAIR TABLE} syntax
@example
REPAIR TABLE tbl_name[,tbl_name...] [TYPE = QUICK]
@end example
@code{REPAIR TABLE} only works on @code{MyISAM} tables and is the same things
as running @code{myisamchk -r table_name} on the table.
Repair the corrupted table. The command returns a table with the following
columns:
@multitable @columnfractions .35 .65
@item Table @tab Table name
@item Op @tab Always 'repair'
@item Msg_type @tab One of @code{status}, @code{error}, @code{info} or @code{warning}.
@item Msg_text @tab The message.
@end multitable
Note that you can get many rows of information for each repaired
table. The last one row will be of @code{Msg_type status} and should
normally be @code{OK}. If you don't get @code{OK}, you should try
repairing the table with @code{myisamchk -o}, as @code{REPAIR TABLE}
does not yet implement all the options of @code{myisamchk}. In the near
future, we will make it more flexible.
If @code{TYPE=QUICK} is given then @strong{MySQL} will try to do a
@code{REPAIR} of only the index tree.
@findex DELETE
@node DELETE, SELECT, REPAIR TABLE, Reference
@section @code{DELETE} syntax
@example
DELETE [LOW_PRIORITY] FROM tbl_name
[WHERE where_definition] [LIMIT rows]
@end example
@code{DELETE} deletes rows from @code{tbl_name} that satisfy the condition
given by @code{where_definition}, and returns the number of records deleted.
If you issue a @code{DELETE} with no @code{WHERE} clause, all rows are
deleted. If you do this in @code{AUTOCOMMIT} mode, @strong{MySQL} does
this by recreating the table as an empty table, which is much faster
than deleting each row. In this case, @code{DELETE} returns zero as the
number of affected records. (@strong{MySQL} can't return the number of
rows that were actually deleted, because the recreate is done without
opening the data files. As long as the table definition file
@file{tbl_name.frm} is valid, the table can be recreated this way, even
if the data or index files have become corrupted.).
If you really want to know how many records are deleted when you are deleting
all rows, and are willing to suffer a speed penalty, you can use a
@code{DELETE} statement of this form:
@example
mysql> DELETE FROM tbl_name WHERE 1>0;
@end example
Note that this is MUCH slower than @code{DELETE FROM tbl_name} with no
@code{WHERE} clause, because it deletes rows one at a time.
If you specify the keyword @code{LOW_PRIORITY}, execution of the
@code{DELETE} is delayed until no other clients are reading from the table.
Deleted records are maintained in a linked list and subsequent @code{INSERT}
operations reuse old record positions. To reclaim unused space and reduce
file sizes, use the @code{OPTIMIZE TABLE} statement or the @code{myisamchk}
utility to reorganize tables. @code{OPTIMIZE TABLE} is easier, but
@code{myisamchk} is faster.
@xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}, and
@ref{Optimization}.
The @strong{MySQL}-specific @code{LIMIT rows} option to @code{DELETE} tells
the server the maximum number of rows to be deleted before control is
returned to the client. This can be used to ensure that a specific
@code{DELETE} command doesn't take too much time. You can simply repeat
the @code{DELETE} command until the number of affected rows is less than
the @code{LIMIT} value.
@findex SELECT
@node SELECT, JOIN, DELETE, Reference
@section @code{SELECT} syntax
@example
SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[HIGH_PRIORITY]
[DISTINCT | DISTINCTROW | ALL]
select_expression,...
[INTO @{OUTFILE | DUMPFILE@} 'file_name' export_options]
[FROM table_references
[WHERE where_definition]
[GROUP BY @{unsigned_integer | col_name | formula@}]
[HAVING where_definition]
[ORDER BY @{unsigned_integer | col_name | formula@} [ASC | DESC] ,...]
[LIMIT [offset,] rows]
[PROCEDURE procedure_name] ]
@end example
@code{SELECT} is used to retrieve rows selected from one or more tables.
@code{select_expression} indicates the columns you want to retrieve.
@code{SELECT} may also be used to retrieve rows computed without reference to
any table. For example:
@example
mysql> SELECT 1 + 1;
-> 2
@end example
All keywords used must be given in exactly the order shown above. For example,
a @code{HAVING} clause must come after any @code{GROUP BY} clause and before
any @code{ORDER BY} clause.
@itemize @bullet
@item
@cindex Aliases, on expressions
@cindex Expression aliases
A @code{SELECT} expression may be given an alias using @code{AS}. The alias
is used as the expression's column name and can be used with
@code{ORDER BY} or @code{HAVING} clauses. For example:
@example
mysql> select concat(last_name,', ',first_name) AS full_name
from mytable ORDER BY full_name;
@end example
@item
The @code{FROM table_references} clause indicates the tables from which to
retrieve rows. If you name more than one table, you are performing a
join. For information on join syntax, see @ref{JOIN, , @code{JOIN}}.
@item
You can refer to a column as @code{col_name}, @code{tbl_name.col_name} or
@code{db_name.tbl_name.col_name}. You need not specify a @code{tbl_name} or
@code{db_name.tbl_name} prefix for a column reference in a @code{SELECT}
statement unless the reference would be ambiguous. See @ref{Legal names},
for examples of ambiguity that require the more explicit column reference
forms.
@item
@cindex Aliases, for tables
@cindex Table aliases
A table reference may be aliased using @code{tbl_name [AS] alias_name}.
@example
mysql> select t1.name, t2.salary from employee AS t1, info AS t2
where t1.name = t2.name;
mysql> select t1.name, t2.salary from employee t1, info t2
where t1.name = t2.name;
@end example
@item
Columns selected for output may be referred to in @code{ORDER BY} and
@code{GROUP BY} clauses using column names, column aliases or column
positions. Column positions begin with 1.
@example
mysql> select college, region, seed from tournament
ORDER BY region, seed;
mysql> select college, region AS r, seed AS s from tournament
ORDER BY r, s;
mysql> select college, region, seed from tournament
ORDER BY 2, 3;
@end example
To sort in reverse order, add the @code{DESC} (descending) keyword to the
name of the column in the @code{ORDER BY} clause that you are sorting by.
The default is ascending order; this may be specified explicitly using
the @code{ASC} keyword.
@item
The @code{HAVING} clause can refer to any column or alias named in the
@code{select_expression}. It is applied last, just before items are sent to
the client, with no optimization. Don't use @code{HAVING} for items that
should be in the @code{WHERE} clause. For example, do not write this:
@example
mysql> select col_name from tbl_name HAVING col_name > 0;
@end example
Write this instead:
@example
mysql> select col_name from tbl_name WHERE col_name > 0;
@end example
In @strong{MySQL} 3.22.5 or later, you can also write queries like this:
@example
mysql> select user,max(salary) from users
group by user HAVING max(salary)>10;
@end example
In older @strong{MySQL} versions, you can write this instead:
@example
mysql> select user,max(salary) AS sum from users
group by user HAVING sum>10;
@end example
@item
@code{SQL_SMALL_RESULT}, @code{SQL_BIG_RESULT}, @code{SQL_BUFFER_RESULT},
@code{STRAIGHT_JOIN} and @code{HIGH_PRIORITY} are @strong{MySQL} extensions
to ANSI SQL92.
@item
@code{HIGH_PRIORITY} will give the @code{SELECT} higher priority than
a statement that updates a table. You should only use this for queries
that are very fast and must be done at once. A @code{SELECT HIGH_PRIORITY}
query will run if the table is locked for read even if there is an update
statement that is waiting for the table to be free.
@item
@code{SQL_BIG_RESULT} can be used with @code{GROUP BY} or @code{DISTINCT}
to tell the optimizer that the result set will have many rows. In this case,
@strong{MySQL} will directly use disk based temporary tables if needed.
@strong{MySQL} will also in this case prefer sorting to doing a
temporary table with a key on the @code{GROUP BY} elements.
@item
@code{SQL_BUFFER_RESULT} will put force the result to be put into a temporary
table. This will help @strong{MySQL} free the table locks early and will help
in cases where it takes a long time to send the result set to the client.
@item
@code{SQL_SMALL_RESULT}, a @strong{MySQL}-specific option, can be used
with @code{GROUP BY} or @code{DISTINCT} to tell the optimizer that the
result set will be small. In this case, @strong{MySQL} will use fast
temporary tables to store the resulting table instead of using sorting. In
@strong{MySQL} 3.23 this shouldn't normally be needed.
@item
@code{STRAIGHT_JOIN} forces the optimizer to join the tables in the order in
which they are listed in the @code{FROM} clause. You can use this to speed up
a query if the optimizer joins the tables in non-optimal order.
@xref{EXPLAIN, , @code{EXPLAIN}}.
@item
The @code{LIMIT} clause can be used to constrain the number of rows returned
by the @code{SELECT} statement. @code{LIMIT} takes one or two numeric
arguments.
If two arguments are given, the first specifies the offset of the first row to
return, the second specifies the maximum number of rows to return.
The offset of the initial row is 0 (not 1).
@example
mysql> select * from table LIMIT 5,10; # Retrieve rows 6-15
@end example
If one argument is given, it indicates the maximum number of rows to return.
@example
mysql> select * from table LIMIT 5; # Retrieve first 5 rows
@end example
In other words, @code{LIMIT n} is equivalent to @code{LIMIT 0,n}.
@item
@tindex /etc/passwd
The @code{SELECT ... INTO OUTFILE 'file_name'} form of @code{SELECT} writes
the selected rows to a file. The file is created on the server host, and
cannot already exist (among other things, this prevents database tables and
files such as @file{/etc/passwd} from being destroyed). You must have the
@strong{file} privilege on the server host to use this form of @code{SELECT}.
@code{SELECT ... INTO OUTFILE} is the complement of @code{LOAD DATA
INFILE}; the syntax for the @code{export_options} part of the statement
consists of the same @code{FIELDS} and @code{LINES} clauses that are used
with the @code{LOAD DATA INFILE} statement.
@xref{LOAD DATA, , @code{LOAD DATA}}.
In the resulting text file, only the following characters are escaped by
the @code{ESCAPED BY} character:
@itemize @bullet
@item The @code{ESCAPED BY} character
@item The first character in @code{FIELDS TERMINATED BY}
@item The first character in @code{LINES TERMINATED BY}
@end itemize
Additionally, @code{ASCII 0} is converted to @code{ESCAPED BY} followed by 0
(@code{ASCII 48}).
The reason for the above is that you MUST escape any @code{FIELDS
TERMINATED BY}, @code{ESCAPED BY} or @code{LINES TERMINATED BY}
characters to reliably be able to read the file
back. @code{ASCII 0} is escaped to make it easier to view with some
pagers.
As the resulting file doesn't have to conform to the SQL syntax, nothing
else need be escaped.
@end itemize
@findex DUMPFILE
If you use @code{INTO DUMPFILE} instead of @code{INTO OUTFILE} @strong{MySQL}
will only write one row into the file, without any column or line
terminations and without any escaping. This is useful if you want to
store a blob in a file.
@findex JOIN
@findex INNER JOIN
@findex CROSS JOIN
@findex LEFT JOIN
@findex LEFT OUTER JOIN
@findex NATURAL LEFT JOIN
@findex NATURAL LEFT OUTER JOIN
@findex STRAIGHT_JOIN
@node JOIN, INSERT, SELECT, Reference
@section @code{JOIN} syntax
@strong{MySQL} supports the following @code{JOIN} syntaxes for use in
@code{SELECT} statements:
@example
table_reference, table_reference
table_reference [CROSS] JOIN table_reference
table_reference INNER JOIN table_reference join_condition
table_reference STRAIGHT_JOIN table_reference
table_reference LEFT [OUTER] JOIN table_reference join_condition
table_reference LEFT [OUTER] JOIN table_reference
table_reference NATURAL [LEFT [OUTER]] JOIN table_reference
@{ oj table_reference LEFT OUTER JOIN table_reference ON conditional_expr @}
@end example
Where @code{table_reference} is defined as
@example
table_name [[AS] alias] [USE INDEX (key_list)] [IGNORE INDEX (key_list)]
@end example
and @code{join_condition} is defined as
@example
ON conditional_expr |
USING (column_list)
@end example
Note that in version before 3.23.16 the @code{INNER JOIN} didn't take
a join condition!
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
The last @code{LEFT OUTER JOIN} syntax shown above exists only for
compatibility with ODBC.
@itemize @bullet
@item
A table reference may be aliased using @code{tbl_name AS alias_name} or
@code{tbl_name alias_name}.
@example
mysql> select t1.name, t2.salary from employee AS t1, info AS t2
where t1.name = t2.name;
@end example
@item
@code{INNER JOIN} and @code{,} (comma) are semantically equivalent.
Both do a full join between the tables used. Normally, you specify how
the tables should be linked in the @code{WHERE} condition.
@item
The @code{ON} conditional is any conditional of the form that may be used in
a @code{WHERE} clause.
@item
If there is no matching record for the right table in the @code{ON} or
@code{USING} part in a @code{LEFT JOIN}, a row with all columns set to
@code{NULL} is used for the right table. You can use this fact to find
records in a table that have no counterpart in another table:
@example
mysql> select table1.* from table1
LEFT JOIN table2 ON table1.id=table2.id
where table2.id is NULL;
@end example
This example finds all rows in @code{table1} with an @code{id} value that is
not present in @code{table2} (i.e., all rows in @code{table1} with no
corresponding row in @code{table2}). This assumes that @code{table2.id} is
declared @code{NOT NULL}, of course.
@item
The @code{USING} @code{(column_list)} clause names a list of columns that must
exist in both tables. A @code{USING} clause such as:
@example
A LEFT JOIN B USING (C1,C2,C3,...)
@end example
is defined to be semantically identical to an @code{ON} expression like
this:
@example
A.C1=B.C1 AND A.C2=B.C2 AND A.C3=B.C3,...
@end example
@item
The @code{NATURAL [LEFT] JOIN} of two tables is defined to be
semantically equivalent to a @code{INNER JOIN} or a @code{LEFT JOIN}
with a @code{USING} clause that names all columns that exist in both
tables.
@item
@code{STRAIGHT_JOIN} is identical to @code{JOIN}, except that the left table
is always read before the right table. This can be used for those (few)
cases where the join optimizer puts the tables in the wrong order.
@item
As of @strong{MySQL} 3.23.12, you can give hints about which
index @strong{MySQL} should use when retrieving information from a
table. This is useful if @code{EXPLAIN} shows that @strong{MySQL} is
using the wrong index. By specifying @code{USE INDEX (key_list)}, you
can tell @strong{MySQL} to use only one of the specified indexes to
find rows in the table. The alternative syntax @code{IGNORE INDEX
(key_list)} can be used to tell @strong{MySQL} to not use some
particular index.
@end itemize
Some examples:
@example
mysql> select * from table1,table2 where table1.id=table2.id;
mysql> select * from table1 LEFT JOIN table2 ON table1.id=table2.id;
mysql> select * from table1 LEFT JOIN table2 USING (id);
mysql> select * from table1 LEFT JOIN table2 ON table1.id=table2.id
LEFT JOIN table3 ON table2.id=table3.id;
mysql> select * from table1 USE INDEX (key1,key2) WHERE key1=1 and key2=2 AND
key3=3;
mysql> select * from table1 IGNORE INDEX (key3) WHERE key1=1 and key2=2 AND
key3=3;
@end example
@xref{LEFT JOIN optimization, , @code{LEFT JOIN} optimization}.
@findex INSERT
@node INSERT, REPLACE, JOIN, Reference
@section @code{INSERT} syntax
@example
INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES (expression,...),(...),...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
SELECT ...
or INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name
SET col_name=expression, col_name=expression, ...
@end example
@code{INSERT} inserts new rows into an existing table. The @code{INSERT ...
VALUES} form of the statement inserts rows based on explicitly-specified
values. The @code{INSERT ... SELECT} form inserts rows selected from another
table or tables. The @code{INSERT ... VALUES} form with multiple value lists
is supported in @strong{MySQL} 3.22.5 or later. The
@code{col_name=expression} syntax is supported in @strong{MySQL} 3.22.10 or
later.
@code{tbl_name} is the table into which rows should be inserted. The column
name list or the @code{SET} clause indicates which columns the statement
specifies values for.
@itemize @bullet
@item
If you specify no column list for @code{INSERT ... VALUES} or @code{INSERT
... SELECT}, values for all columns must be provided in the
@code{VALUES()} list or by the @code{SELECT}. If you don't know the order of
the columns in the table, use @code{DESCRIBE tbl_name} to find out.
@item
Any column not explicitly given a value is set to its default value. For
example, if you specify a column list that doesn't name all the columns in
the table, unnamed columns are set to their default values. Default value
assignment is described in @ref{CREATE TABLE, , @code{CREATE TABLE}}.
@item
An @code{expression} may refer to any column that was set earlier in a value
list. For example, you can say this:
@example
mysql> INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2);
@end example
But not this:
@example
mysql> INSERT INTO tbl_name (col1,col2) VALUES(col2*2,15);
@end example
@item
If you specify the keyword @code{LOW_PRIORITY}, execution of the
@code{INSERT} is delayed until no other clients are reading from the table.
In this case the client has to wait until the insert statement is completed,
which may take a long time if the table is in heavy use. This is in
contrast to @code{INSERT DELAYED} which lets the client continue at once.
@item
If you specify the keyword @code{IGNORE} in an @code{INSERT} with many value
rows, any rows which duplicate an existing @code{PRIMARY} or @code{UNIQUE}
key in the table are ignored and are not inserted. If you do not specify
@code{IGNORE}, the insert is aborted if there is any row that duplicates an
existing key value. You can check with the C API function
@code{mysql_info()} how many rows were inserted into the table.
@item
If @strong{MySQL} was configured using the @code{DONT_USE_DEFAULT_FIELDS}
option, @code{INSERT} statements generate an error unless you explicitly
specify values for all columns that require a non-@code{NULL} value.
@xref{configure options, , @code{configure} options}.
@item
The following conditions hold for a @code{INSERT INTO ... SELECT} statement:
@itemize @minus
@item
The query cannot contain an @code{ORDER BY} clause.
@item
The target table of the @code{INSERT} statement cannot appear in the
@code{FROM} clause of the @code{SELECT} part of the query, because it's
forbidden in ANSI SQL to @code{SELECT} from the same table into which you are
@code{INSERT}ing. (The problem is that the @code{SELECT} possibly would
find records that were inserted earlier during the same run. When using
sub-select clauses, the situation could easily be very confusing!)
@item
@code{AUTO_INCREMENT} columns work as usual.
@end itemize
@end itemize
@findex mysql_info()
If you use @code{INSERT ... SELECT} or a @code{INSERT ... VALUES}
statement with multiple value lists, you can use the C API function
@code{mysql_info()} to get information about the query. The format of the
information string is shown below:
@example
Records: 100 Duplicates: 0 Warnings: 0
@end example
@code{Duplicates} indicates the number of rows that couldn't be inserted
because they would duplicate some existing unique index value.
@code{Warnings} indicates the number of attempts to insert column values that
were problematic in some way. Warnings can occur under any of the following
conditions:
@itemize @bullet
@item
Inserting @code{NULL} into a column that has been declared @code{NOT NULL}.
The column is set to its default value.
@item
Setting a numeric column to a value that lies outside the column's range.
The value is clipped to the appropriate endpoint of the range.
@item
Setting a numeric column to a value such as @code{'10.34 a'}. The trailing
garbage is stripped and the remaining numeric part is inserted. If the value
doesn't make sense as a number at all, the column is set to @code{0}.
@item
Inserting a string into a @code{CHAR}, @code{VARCHAR}, @code{TEXT} or
@code{BLOB} column that exceeds the column's maximum length. The value is
truncated to the column's maximum length.
@item
Inserting a value into a date or time column that is illegal for the column
type. The column is set to the appropriate ``zero'' value for the type.
@end itemize
@findex INSERT DELAYED
@findex DELAYED
The @code{DELAYED} option
for the
@code{INSERT} statement is a @strong{MySQL}-specific option that is very
useful if you have clients that can't wait for the @code{INSERT} to complete.
This is a common problem when you use @strong{MySQL} for logging and you also
periodically run @code{SELECT} statements that take a long time to complete.
@code{DELAYED} was introduced in @strong{MySQL} 3.22.15. It is a
@strong{MySQL} extension to ANSI SQL92.
When you use @code{INSERT DELAYED}, the client will get an ok at once
and the row will be inserted when the table is not in use by any other thread.
Another major benefit of using @code{INSERT DELAYED} is that inserts
from many clients are bundled together and written in one block. This is much
faster than doing many separate inserts.
Note that currently the queued rows are only stored in memory until they are
inserted into the table. This means that if you kill @code{mysqld}
the hard way (@code{kill -9}) or if @code{mysqld} dies unexpectedly, any
queued rows that weren't written to disk are lost!
The following describes in detail what happens when you use the
@code{DELAYED} option to @code{INSERT} or @code{REPLACE}. In this
description, the ``thread'' is the thread that received an @code{INSERT
DELAYED} command and ``handler'' is the thread that handles all
@code{INSERT DELAYED} statements for a particular table.
@itemize @bullet
@item
When a thread executes a @code{DELAYED} statement for a table, a handler
thread is created to process all @code{DELAYED} statements for the table, if
no such handler already exists.
@item
The thread checks whether or not the handler has acquired a @code{DELAYED}
lock already; if not, it tells the handler thread to do so. The
@code{DELAYED} lock can be obtained even if other threads have a @code{READ}
or @code{WRITE} lock on the table. However, the handler will wait for all
@code{ALTER TABLE} locks or @code{FLUSH TABLES} to ensure that the table
structure is up to date.
@item
The thread executes the @code{INSERT} statement but instead of writing
the row to the table it puts a copy of the final row into a queue that
is managed by the handler thread. Any syntax errors are noticed by the
thread and reported to the client program.
@item
The client can't report the number of duplicates or the @code{AUTO_INCREMENT}
value for the resulting row; it can't obtain them from the server, because
the @code{INSERT} returns before the insert operation has been completed. If
you use the C API, the @code{mysql_info()} function doesn't return anything
meaningful, for the same reason.
@item
The update log is updated by the handler thread when the row is inserted into
the table. In case of multiple-row inserts, the update log is updated when
the first row is inserted.
@item
After every @code{delayed_insert_limit} rows are written, the handler checks
whether or not any @code{SELECT} statements are still pending. If so, it
allows these to execute before continuing.
@item
When the handler has no more rows in its queue, the table is unlocked. If no
new @code{INSERT DELAYED} commands are received within
@code{delayed_insert_timeout} seconds, the handler terminates.
@item
If more than @code{delayed_queue_size} rows are pending already in a specific
handler queue, the thread waits until there is room in the queue. This is
useful to ensure that the @code{mysqld} server doesn't use all memory for the
delayed memory queue.
@item
The handler thread will show up in the @strong{MySQL} process list
with @code{delayed_insert} in the @code{Command} column. It will
be killed if you execute a @code{FLUSH TABLES} command or kill it with
@code{KILL thread_id}. However, it will first store all queued rows into the
table before exiting. During this time it will not accept any new
@code{INSERT} commands from another thread. If you execute an @code{INSERT
DELAYED} command after this, a new handler thread will be created.
@item
Note that the above means that @code{INSERT DELAYED} commands have higher
priority than normal @code{INSERT} commands if there is an @code{INSERT
DELAYED} handler already running! Other update commands will have to wait
until the @code{INSERT DELAYED} queue is empty, someone kills the handler
thread (with @code{KILL thread_id}) or someone executes @code{FLUSH TABLES}.
@item
The following status variables provide information about @code{INSERT
DELAYED} commands:
@multitable @columnfractions .35 .65
@item @code{Delayed_insert_threads} @tab Number of handler threads
@item @code{Delayed_writes} @tab Number of rows written with @code{INSERT DELAYED}
@item @code{Not_flushed_delayed_rows} @tab Number of rows waiting to be written
@end multitable
You can view these variables by issuing a @code{SHOW STATUS} statement or
by executing a @code{mysqladmin extended-status} command.
@end itemize
Note that @code{INSERT DELAYED} is slower than a normal INSERT if the
table is not in use. There is also the additional overhead for the
server to handle a separate thread for each table on which you use
@code{INSERT DELAYED}. This means that you should only use @code{INSERT
DELAYED} when you are really sure you need it!
@findex REPLACE
@node REPLACE, LOAD DATA, INSERT, Reference
@section @code{REPLACE} syntax
@example
REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
VALUES (expression,...)
or REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name [(col_name,...)]
SELECT ...
or REPLACE [LOW_PRIORITY | DELAYED]
[INTO] tbl_name
SET col_name=expression, col_name=expression,...
@end example
@code{REPLACE} works exactly like @code{INSERT}, except that if an old
record in the table has the same value as a new record on a unique index,
the old record is deleted before the new record is inserted.
@xref{INSERT, , @code{INSERT}}.
@findex LOAD DATA INFILE
@node LOAD DATA, UPDATE, REPLACE, Reference
@section @code{LOAD DATA INFILE} syntax
@example
LOAD DATA [LOW_PRIORITY] [LOCAL] INFILE 'file_name.txt' [REPLACE | IGNORE]
INTO TABLE tbl_name
[FIELDS
[TERMINATED BY '\t']
[OPTIONALLY] ENCLOSED BY '']
[ESCAPED BY '\\' ]]
[LINES TERMINATED BY '\n']
[IGNORE number LINES]
[(col_name,...)]
@end example
The @code{LOAD DATA INFILE} statement reads rows from a text file into a
table at a very high speed. If the @code{LOCAL} keyword is specified, the
file is read from the client host. If @code{LOCAL} is not specified, the
file must be located on the server. (@code{LOCAL} is available in
@strong{MySQL} 3.22.6 or later.)
For security reasons, when reading text files located on the server, the
files must either reside in the database directory or be readable by all.
Also, to use @code{LOAD DATA INFILE} on server files, you must have the
@strong{file} privilege on the server host.
@xref{Privileges provided}.
If you specify the keyword @code{LOW_PRIORITY}, execution of the
@code{LOAD DATA} statement is delayed until no other clients are reading
from the table.
Using @code{LOCAL} will be a bit slower than letting the server access the
files directly, because the contents of the file must travel from the client
host to the server host. On the other hand, you do not need the
@strong{file} privilege to load local files.
@cindex @code{mysqlimport}
You can also load data files by using the @code{mysqlimport} utility; it
operates by sending a @code{LOAD DATA INFILE} command to the server. The
@code{--local} option causes @code{mysqlimport} to read data files from the
client host. You can specify the @code{--compress} option to get better
performance over slow networks if the client and server support the
compressed protocol.
When locating files on the server host, the server uses the following rules:
@itemize @bullet
@item
If an absolute pathname is given, the server uses the pathname as is.
@item
If a relative pathname with one or more leading components is given,
the server searches for the file relative to the server's data directory.
@item
If a filename with no leading components is given, the server looks for
the file in the database directory of the current database.
@end itemize
Note that these rules mean a file given as @file{./myfile.txt} is read from
the server's data directory, whereas a file given as @file{myfile.txt} is
read from the database directory of the current database. For example,
the following @code{LOAD DATA} statement reads the file @file{data.txt}
from the database directory for @code{db1} because @code{db1} is the current
database, even though the statement explicitly loads the file into a
table in the @code{db2} database:
@example
mysql> USE db1;
mysql> LOAD DATA INFILE "data.txt" INTO TABLE db2.my_table;
@end example
The @code{REPLACE} and @code{IGNORE} keywords control handling of input
records that duplicate existing records on unique key values. If you specify
@code{REPLACE}, new rows replace existing rows that have the same unique key
value. If you specify @code{IGNORE}, input rows that duplicate an existing
row on a unique key value are skipped. If you don't specify either option, an
error occurs when a duplicate key value is found, and the rest of the text
file is ignored.
If you load data from a local file using the @code{LOCAL} keyword, the server
has no way to stop transmission of the file in the middle of the operation,
so the default bahavior is the same as if @code{IGNORE} is specified.
@code{LOAD DATA INFILE} is the complement of @code{SELECT ... INTO OUTFILE}.
@xref{SELECT, , @code{SELECT}}.
To write data from a database to a file, use @code{SELECT ... INTO OUTFILE}.
To read the file back into the database, use @code{LOAD DATA INFILE}.
The syntax of the @code{FIELDS} and @code{LINES} clauses is the same for
both commands. Both clauses are optional, but @code{FIELDS}
must precede @code{LINES} if both are specified.
If you specify a @code{FIELDS} clause,
each of its subclauses (@code{TERMINATED BY}, @code{[OPTIONALLY] ENCLOSED
BY} and @code{ESCAPED BY}) is also optional, except that you must
specify at least one of them.
If you don't specify a @code{FIELDS} clause, the defaults are the
same as if you had written this:
@example
FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'
@end example
If you don't specify a @code{LINES} clause, the default
is the same as if you had written this:
@example
LINES TERMINATED BY '\n'
@end example
In other words, the defaults cause @code{LOAD DATA INFILE} to act as follows
when reading input:
@itemize @bullet
@item
Look for line boundaries at newlines
@item
Break lines into fields at tabs
@item
Do not expect fields to be enclosed within any quoting characters
@item
Interpret occurrences of tab, newline or @samp{\} preceded by
@samp{\} as literal characters that are part of field values
@end itemize
Conversely, the defaults cause @code{SELECT ... INTO OUTFILE} to act as
follows when writing output:
@itemize @bullet
@item
Write tabs between fields
@item
Do not enclose fields within any quoting characters
@item
Use @samp{\} to escape instances of tab, newline or @samp{\} that occur
within field values
@item
Write newlines at the ends of lines
@end itemize
Note that to write @code{FIELDS ESCAPED BY '\\'}, you must specify two
backslashes for the value to be read as a single backslash.
The @code{IGNORE number LINES} option can be used to ignore a header of
column names at the start of the file:
@example
mysql> LOAD DATA INFILE "/tmp/file_name" into table test IGNORE 1 LINES;
@end example
When you use @code{SELECT ... INTO OUTFILE} in tandem with @code{LOAD
DATA INFILE} to write data from a database into a file and then read
the file back into the database later, the field and line handling
options for both commands must match. Otherwise, @code{LOAD DATA
INFILE} will not interpret the contents of the file properly. Suppose
you use @code{SELECT ... INTO OUTFILE} to write a file with
fields delimited by commas:
@example
mysql> SELECT * INTO OUTFILE 'data.txt'
FIELDS TERMINATED BY ','
FROM ...
@end example
To read the comma-delimited file back in, the correct statement would be:
@example
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY ',';
@end example
If instead you tried to read in the file with the statement shown below, it
wouldn't work because it instructs @code{LOAD DATA INFILE} to look for
tabs between fields:
@example
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE table2
FIELDS TERMINATED BY '\t';
@end example
The likely result is that each input line would be interpreted as
a single field.
@code{LOAD DATA INFILE} can be used to read files obtained from
external sources, too. For example, a file in dBASE format will have
fields separated by commas and enclosed in double quotes. If lines in
the file are terminated by newlines, the command shown below
illustrates the field and line handling options you would use to load
the file:
@example
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n';
@end example
Any of the field or line handling options may specify an empty string
(@code{''}). If not empty, the @code{FIELDS [OPTIONALLY] ENCLOSED BY}
and @code{FIELDS ESCAPED BY} values must be a single character. The
@code{FIELDS TERMINATED BY} and @code{LINES TERMINATED BY} values may
be more than one character. For example, to write lines that are
terminated by carriage return-linefeed pairs, or to read a file
containing such lines, specify a @code{LINES TERMINATED BY '\r\n'}
clause.
@code{FIELDS [OPTIONALLY] ENCLOSED BY} controls quoting of fields. For
output (@code{SELECT ... INTO OUTFILE}), if you omit the word
@code{OPTIONALLY}, all fields are enclosed by the @code{ENCLOSED BY}
character. An example of such output (using a comma as the field
delimiter) is shown below:
@example
"1","a string","100.20"
"2","a string containing a , comma","102.20"
"3","a string containing a \" quote","102.20"
"4","a string containing a \", quote and comma","102.20"
@end example
If you specify @code{OPTIONALLY}, the @code{ENCLOSED BY} character is
used only to enclose @code{CHAR} and @code{VARCHAR} fields:
@example
1,"a string",100.20
2,"a string containing a , comma",102.20
3,"a string containing a \" quote",102.20
4,"a string containing a \", quote and comma",102.20
@end example
Note that occurrences of the @code{ENCLOSED BY} character within a
field value are escaped by prefixing them with the @code{ESCAPED BY}
character. Also note that if you specify an empty @code{ESCAPED BY}
value, it is possible to generate output that cannot be read properly by
@code{LOAD DATA INFILE}. For example, the output just shown above would
appear as shown below if the escape character is empty. Observe that the
second field in the fourth line contains a comma following the quote, which
(erroneously) appears to terminate the field:
@example
1,"a string",100.20
2,"a string containing a , comma",102.20
3,"a string containing a " quote",102.20
4,"a string containing a ", quote and comma",102.20
@end example
For input, the @code{ENCLOSED BY} character, if present, is stripped from the
ends of field values. (This is true whether or not @code{OPTIONALLY} is
specified; @code{OPTIONALLY} has no effect on input interpretation.)
Occurrences of the @code{ENCLOSED BY} character preceded by the
@code{ESCAPED BY} character are interpreted as part of the current field
value. In addition, duplicated @code{ENCLOSED BY} characters occurring
within fields are interpreted as single @code{ENCLOSED BY} characters if the
field itself starts with that character. For example, if @code{ENCLOSED BY
'"'} is specified, quotes are handled as shown below:
@example
"The ""BIG"" boss" -> The "BIG" boss
The "BIG" boss -> The "BIG" boss
The ""BIG"" boss -> The ""BIG"" boss
@end example
@code{FIELDS ESCAPED BY} controls how to write or read special characters.
If the @code{FIELDS ESCAPED BY} character is not empty, it is used to prefix
the following characters on output:
@itemize @bullet
@item
The @code{FIELDS ESCAPED BY} character
@item
The @code{FIELDS [OPTIONALLY] ENCLOSED BY} character
@item
The first character of the @code{FIELDS TERMINATED BY} and
@code{LINES TERMINATED BY} values
@item
ASCII @code{0} (what is actually written following the escape character is
ASCII @code{'0'}, not a zero-valued byte)
@end itemize
If the @code{FIELDS ESCAPED BY} character is empty, no characters are escaped.
It is probably not a good idea to specify an empty escape character,
particularly if field values in your data contain any of the characters in
the list just given.
For input, if the @code{FIELDS ESCAPED BY} character is not empty, occurrences
of that character are stripped and the following character is taken literally
as part of a field value. The exceptions are an escaped @samp{0} or
@samp{N} (e.g., @code{\0} or @code{\N} if the escape character is
@samp{\}). These sequences are interpreted as ASCII @code{0} (a zero-valued
byte) and @code{NULL}. See below for the rules on @code{NULL} handling.
For more information about @samp{\}-escape syntax,
see @ref{Literals}.
In certain cases, field and line handling options interact:
@itemize @bullet
@item
If @code{LINES TERMINATED BY} is an empty string and @code{FIELDS
TERMINATED BY} is non-empty, lines are also terminated with
@code{FIELDS TERMINATED BY}.
@item
If the @code{FIELDS TERMINATED BY} and @code{FIELDS ENCLOSED BY} values are
both empty (@code{''}), a fixed-row (non-delimited) format is used. With
fixed-row format, no delimiters are used between fields. Instead, column
values are written and read using the ``display'' widths of the columns. For
example, if a column is declared as @code{INT(7)}, values for the column are
written using 7-character fields. On input, values for the column are
obtained by reading 7 characters. Fixed-row format also affects handling of
@code{NULL} values; see below. Note that fixed size format will not work
if you are using a multi-byte character set.
@end itemize
Handling of @code{NULL} values varies, depending on the @code{FIELDS} and
@code{LINES} options you use:
@itemize @bullet
@item
For the default @code{FIELDS} and @code{LINES} values,
@code{NULL} is written as @code{\N} for output and @code{\N} is read
as @code{NULL} for input (assuming the @code{ESCAPED BY} character
is @samp{\}).
@item
If @code{FIELDS ENCLOSED BY} is not empty, a field containing the literal
word @code{NULL} as its value is read as a @code{NULL} value (this differs
from the word @code{NULL} enclosed within @code{FIELDS ENCLOSED BY}
characters, which is read as the string @code{'NULL'}).
@item
If @code{FIELDS ESCAPED BY} is empty, @code{NULL} is written as the word
@code{NULL}.
@item
With fixed-row format (which happens when @code{FIELDS TERMINATED BY} and
@code{FIELDS ENCLOSED BY} are both empty), @code{NULL} is written as an empty
string. Note that this causes both @code{NULL} values and empty strings in
the table to be indistinguishable when written to the file because they are
both written as empty strings. If you need to be able to tell the two apart
when reading the file back in, you should not use fixed-row format.
@end itemize
Some cases are not supported by @code{LOAD DATA INFILE}:
@itemize @bullet
@item
Fixed-size rows (@code{FIELDS TERMINATED BY} and @code{FIELDS ENCLOSED
BY} both empty) and @code{BLOB} or @code{TEXT} columns.
@item
If you specify one separator that is the same as or a prefix of another,
@code{LOAD DATA INFILE} won't be able to interpret the input properly.
For example, the following @code{FIELDS} clause would cause problems:
@example
FIELDS TERMINATED BY '"' ENCLOSED BY '"'
@end example
@item
If @code{FIELDS ESCAPED BY} is empty, a field value that contains an occurrence
of @code{FIELDS ENCLOSED BY} or @code{LINES TERMINATED BY}
followed by the @code{FIELDS TERMINATED BY} value will cause @code{LOAD
DATA INFILE} to stop reading a field or line too early.
This happens because @code{LOAD DATA INFILE} cannot properly determine
where the field or line value ends.
@end itemize
The following example loads all columns of the @code{persondata} table:
@example
mysql> LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata;
@end example
No field list is specified, so @code{LOAD DATA INFILE} expects input rows
to contain a field for each table column. The default @code{FIELDS} and
@code{LINES} values are used.
If you wish to load only some of a table's columns, specify a field list:
@example
mysql> LOAD DATA INFILE 'persondata.txt'
INTO TABLE persondata (col1,col2,...);
@end example
You must also specify a field list if the order of the fields in the input
file differs from the order of the columns in the table. Otherwise,
@strong{MySQL} cannot tell how to match up input fields with table columns.
If a row has too few fields, the columns for which no input field is present
are set to default values. Default value assignment is described in
@ref{CREATE TABLE, , @code{CREATE TABLE}}.
An empty field value is interpreted differently than if the field value
is missing:
@itemize @bullet
@item
For string types, the column is set to the empty string.
@item
For numeric types, the column is set to @code{0}.
@item
For date and time types, the column is set to the appropriate ``zero''
value for the type.
@xref{Date and time types}.
@end itemize
@code{TIMESTAMP} columns are only set to the current date and time if there
is a @code{NULL} value for the column, or (for the first @code{TIMESTAMP}
column only) if the @code{TIMESTAMP} column is left out from the field list
when a field list is specified.
If an input row has too many fields, the extra fields are ignored and
the number of warnings is incremented.
@code{LOAD DATA INFILE} regards all input as strings, so you can't use
numeric values for @code{ENUM} or @code{SET} columns the way you can with
@code{INSERT} statements. All @code{ENUM} and @code{SET} values must be
specified as strings!
@findex mysql_info()
If you are using the C API, you can get information about the query by
calling the API function @code{mysql_info()} when the @code{LOAD DATA INFILE}
query finishes. The format of the information string is shown below:
@example
Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
@end example
Warnings occur under the same circumstances as when values are inserted
via the @code{INSERT} statement (@pxref{INSERT, , @code{INSERT}}), except
that @code{LOAD DATA INFILE} also generates warnings when there are too few
or too many fields in the input row. The warnings are not stored anywhere;
the number of warnings can only be used as an indication if everything went
well. If you get warnings and want to know exactly why you got them, one way
to do this is to use @code{SELECT ... INTO OUTFILE} into another file and
compare this to your original input file.
If you need @code{LOAD DATA INFILE} to read from a pipe, you can use the
following trick:
@example
mkfifo /mysql/db/x/x
chmod 666 /mysql/db/x/x
cat < /dev/tcp/10.1.1.12/4711 > /nt/mysql/db/x/x
mysql -e "LOAD DATA INFILE 'x' INTO TABLE x" x
@end example
For more information about the efficiency of @code{INSERT} versus
@code{LOAD DATA INFILE} and speeding up @code{LOAD DATA INFILE},
@xref{Insert speed}.
@findex UPDATE
@node UPDATE, USE, LOAD DATA, Reference
@section @code{UPDATE} syntax
@example
UPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1,col_name2=expr2,...
[WHERE where_definition] [LIMIT #]
@end example
@code{UPDATE} updates columns in existing table rows with new values. The
@code{SET} clause indicates which columns to modify and the values they
should be given. The @code{WHERE} clause, if given, specifies which rows
should be updated. Otherwise all rows are updated.
If you specify the keyword @code{LOW_PRIORITY}, execution of the
@code{UPDATE} is delayed until no other clients are reading from the table.
If you specify the keyword @code{IGNORE}, the update statement will not
abort even if we get duplicate key errors during the update. Rows that
would cause conflicts will not be updated.
If you access a column from @code{tbl_name} in an expression,
@code{UPDATE} uses the current value of the column. For example, the
following statement sets the @code{age} column to one more than its
current value:
@example
mysql> UPDATE persondata SET age=age+1;
@end example
@code{UPDATE} assignments are evaluated from left to right. For example, the
following statement doubles the @code{age} column, then increments it:
@example
mysql> UPDATE persondata SET age=age*2, age=age+1;
@end example
If you set a column to the value it currently has, @strong{MySQL} notices
this and doesn't update it.
@findex mysql_info()
@code{UPDATE} returns the number of rows that were actually changed.
In @strong{MySQL} 3.22 or later, the C API function @code{mysql_info()}
returns the number of rows that were matched and updated and the number of
warnings that occurred during the @code{UPDATE}.
In @strong{MySQL} 3.23 you can use @code{LIMIT #} to ensure that only a given
number of rows are changed.
@findex USE
@node USE, FLUSH, UPDATE, Reference
@section @code{USE} syntax
@example
USE db_name
@end example
The @code{USE db_name} statement tells @strong{MySQL} to use the @code{db_name}
database as the default database for subsequent queries. The database remains
current until the end of the session, or until another @code{USE} statement
is issued:
@example
mysql> USE db1;
mysql> SELECT count(*) FROM mytable; # selects from db1.mytable
mysql> USE db2;
mysql> SELECT count(*) FROM mytable; # selects from db2.mytable
@end example
Making a particular database current by means of the @code{USE} statement
does not preclude you from accessing tables in other databases. The example
below accesses the @code{author} table from the @code{db1} database and the
@code{editor} table from the @code{db2} database:
@example
mysql> USE db1;
mysql> SELECT author_name,editor_name FROM author,db2.editor
WHERE author.editor_id = db2.editor.editor_id;
@end example
@cindex Sybase compatibility
@cindex Compatibility, with Sybase
The @code{USE} statement is provided for Sybase compatibility.
@cindex @code{mysqladmin}
@findex FLUSH
@node FLUSH, KILL, USE, Reference
@section @code{FLUSH} syntax (clearing caches)
@example
FLUSH flush_option [,flush_option]
@end example
You should use the @code{FLUSH} command if you want to clear some of the
internal caches @strong{MySQL} uses. To execute @code{FLUSH}, you must have
the @strong{reload} privilege.
@code{flush_option} can be any of the following:
@multitable @columnfractions .15 .85
@item @code{HOSTS} @tab Empties the host cache tables. You should flush the
host tables if some of your hosts change IP number or if you get the
error message @code{Host ... is blocked}. When more than
@code{max_connect_errors} errors occur in a row for a given host while
connection to the @strong{MySQL} server, @strong{MySQL} assumes
something is wrong and blocks the host from further connection requests.
Flushing the host tables allows the host to attempt to connect
again. @xref{Blocked host}.) You can start @code{mysqld} with
@code{-O max_connection_errors=999999999} to avoid this error message.
@item @code{LOGS} @tab Closes and reopens the standard and update log
files. If you have specified the update log file without an extension,
the extension number of the new update log file will be incremented by
one relative to the previous file. If you have used an extension in the
file name, @strong{MySQL} will close and reopen the update log file.
@xref{Update log}.
@item @code{PRIVILEGES} @tab Reloads the privileges from the grant tables in
the @code{mysql} database.
@item @code{TABLES} @tab Closes all open tables.
@item @code{TABLES WITH READ LOCK} @tab Closes all open tables and locks all tables for all databases with a read until one executes @code{UNLOCK TABLES}.
@item @code{STATUS} @tab Resets most status variables to zero.
@end multitable
You can also access each of the commands shown above with the @code{mysqladmin}
utility, using the @code{flush-hosts}, @code{flush-logs}, @code{reload}
or @code{flush-tables} commands.
@cindex @code{mysqladmin}
@findex KILL
@node KILL, SHOW, FLUSH, Reference
@section @code{KILL} syntax
@example
KILL thread_id
@end example
Each connection to @code{mysqld} runs in a separate thread. You can see
which threads are running with the @code{SHOW PROCESSLIST} command, and kill
a thread with the @code{KILL thread_id} command.
If you have the @strong{process} privilege, you can see and kill all threads.
Otherwise, you can see and kill only your own threads.
You can also use the @code{mysqladmin processlist} and @code{mysqladmin kill}
commands to examine and kill threads.
@findex SHOW DATABASES
@findex SHOW TABLES
@findex SHOW COLUMNS
@findex SHOW FIELDS
@findex SHOW INDEX
@findex SHOW KEYS
@findex SHOW STATUS
@findex SHOW VARIABLES
@findex SHOW PROCESSLIST
@findex SHOW TABLE STATUS
@findex SHOW GRANTS
@node SHOW, EXPLAIN, KILL, Reference
@section @code{SHOW} syntax (Get information about tables, columns,...)
@example
SHOW DATABASES [LIKE wild]
or SHOW TABLES [FROM db_name] [LIKE wild]
or SHOW COLUMNS FROM tbl_name [FROM db_name] [LIKE wild]
or SHOW INDEX FROM tbl_name [FROM db_name]
or SHOW TABLE STATUS [FROM db_name] [LIKE wild]
or SHOW STATUS [LIKE wild]
or SHOW VARIABLES [LIKE wild]
or SHOW [FULL] PROCESSLIST
or SHOW GRANTS FOR user
@end example
@code{SHOW} provides information about databases, tables, columns or
status information about the server. If the @code{LIKE wild} part is
used, the @code{wild} string can be a string that uses the SQL @samp{%}
and @samp{_} wildcard characters.
@findex SHOW DATABASES
@findex SHOW TABLES
@findex SHOW COLUMNS
@findex SHOW FIELDS
@findex SHOW INDEX
@findex SHOW KEYS
@menu
* SHOW DATABASE INFO::
* SHOW TABLE STATUS::
* SHOW STATUS::
* SHOW VARIABLES::
* SHOW PROCESSLIST::
* SHOW GRANTS::
@end menu
@node SHOW DATABASE INFO, SHOW TABLE STATUS, SHOW, SHOW
@subsection SHOW information about database, tables, columns and index
You can use @code{db_name.tbl_name} as an alternative to the @code{tbl_name
FROM db_name} syntax. These two statements are equivalent:
@example
mysql> SHOW INDEX FROM mytable FROM mydb;
mysql> SHOW INDEX FROM mydb.mytable;
@end example
@code{SHOW DATABASES} lists the databases on the @strong{MySQL} server
host. You can also get this list using the @code{mysqlshow} command.
@code{SHOW TABLES} lists the tables in a given database. You can also
get this list using the @code{mysqlshow db_name} command.
@strong{Note:} If a user doesn't have any privileges for a table, the table
will not show up in the output from @code{SHOW TABLES} or @code{mysqlshow
db_name}.
@code{SHOW COLUMNS} lists the columns in a given table. If the column
types are different than you expect them to be based on a @code{CREATE
TABLE} statement, note that @strong{MySQL} sometimes changes column
types. @xref{Silent column changes}.
The @code{DESCRIBE} statement provides information similar to
@code{SHOW COLUMNS}.
@xref{DESCRIBE, , @code{DESCRIBE}}.
@code{SHOW FIELDS} is a synonym for @code{SHOW COLUMNS} and
@code{SHOW KEYS} is a synonym for @code{SHOW INDEX}. You can also
list a table's columns or indexes with @code{mysqlshow db_name tbl_name}
or @code{mysqlshow -k db_name tbl_name}.
@code{SHOW INDEX} returns the index information in a format that closely
resembles the @code{SQLStatistics} call in ODBC. The following columns
are returned:
@multitable @columnfractions .35 .65
@item @strong{Column} @tab @strong{Meaning}
@item @code{Table} @tab Name of the table
@item @code{Non_unique} @tab 0 if the index can't contain duplicates.
@item @code{Key_name} @tab Name of the index
@item @code{Seq_in_index} @tab Column sequence number in index, starting with 1.
@item @code{Column_name} @tab Column name.
@item @code{Collation} @tab How the column is sorted in the index. In
@strong{MySQL}, this can have values @code{A} (Ascending) or @code{NULL}
(Not sorted).
@item @code{Cardinality} @tab Number of unique values in the index.
This is updated by running @code{isamchk -a}.
@item @code{Sub_part} @tab Number of indexed characters if the column is
only partly indexed. @code{NULL} if the entire key is indexed.
@end multitable
@node SHOW TABLE STATUS, SHOW STATUS, SHOW DATABASE INFO, SHOW
@subsection SHOW status information about tables
@code{SHOW TABLE STATUS} (new in version 3.23) works likes @code{SHOW
STATUS}, but provides a lot of information about each table. You can
also get this list using the @code{mysqlshow --status db_name} command.
The following columns are returned:
@multitable @columnfractions .30 .70
@item @strong{Column} @tab @strong{Meaning}
@item @code{Name} @tab Name of the table
@item @code{Type} @tab Type of table (BDB, ISAM, MyISAM or HEAP)
@item @code{Row_format} @tab The row storage format (Fixed, Dynamic, or Compressed)
@item @code{Rows} @tab Number of rows
@item @code{Avg_row_length} @tab Average row length
@item @code{Data_length} @tab Length of the data file
@item @code{Max_data_length} @tab Max length of the data file
@item @code{Index_length} @tab Length of the index file
@item @code{Data_free} @tab Number of allocated but not used bytes
@item @code{Auto_increment} @tab Next autoincrement value
@item @code{Create_time} @tab When the table was created
@item @code{Update_time} @tab When the data file was last updated
@item @code{Check_time} @tab When one last run a check on the table
@item @code{Create_options} @tab Extra options used with @code{CREATE TABLE}
@item @code{Comment} @tab The comment used when creating the table (or some information why @strong{MySQL} couldn't access the table information).
@end multitable
@node SHOW STATUS, SHOW VARIABLES, SHOW TABLE STATUS, SHOW
@subsection SHOW status information
@cindex @code{mysqladmin}
@code{SHOW STATUS} provides server status information
(like @code{mysqladmin extended-status}). The output resembles that shown
below, though the format and numbers probably differ:
@example
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_clients | 0 |
| Aborted_connects | 0 |
| Bytes_received | 100 |
| Bytes_sent | 2106 |
| Connections | 4 |
| Created_tmp_tables | 0 |
| Delayed_insert_threads | 0 |
| Delayed_writes | 0 |
| Delayed_errors | 0 |
| Flush_commands | 1 |
| Handler_delete | 0 |
| Handler_read_first | 1 |
| Handler_read_key | 0 |
| Handler_read_next | 2 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_next | 25 |
| Handler_update | 0 |
| Handler_write | 0 |
| Key_blocks_used | 1 |
| Key_read_requests | 2 |
| Key_reads | 1 |
| Key_write_requests | 0 |
| Key_writes | 0 |
| Max_used_connections | 0 |
| Not_flushed_key_blocks | 0 |
| Not_flushed_delayed_rows | 0 |
| Open_tables | 0 |
| Open_files | 0 |
| Open_streams | 0 |
| Opened_tables | 6 |
| Questions | 4 |
| Slow_launch_threads | 0 |
| Slow_queries | 0 |
| Slave_running | OFF |
| Threads_cached | 0 |
| Threads_connected | 1 |
| Threads_running | 1 |
| Uptime | 1256 |
+--------------------------+-------+
@end example
The status variables listed above have the following meaning:
@multitable @columnfractions .35 .65
@item @code{Aborted_clients} @tab Number of connections that has been aborted because the client has died without closing the connection properly.
@item @code{Aborted_connects} @tab Number of tries to connect to the @strong{MySQL} server that has failed.
@item @code{Bytes_received} @tab Number of bytes received from the client
@item @code{Bytes_sent} @tab Number of bytes received from the client
@item @code{Connections} @tab Number of connection attempts to the @strong{MySQL} server.
@item @code{Created_tmp_tables} @tab Number of implicit temporary tables that has been created while executing statements.
@item @code{Delayed_insert_threads} @tab Number of delayed insert handler threads in use.
@item @code{Delayed_writes} @tab Number of rows written with @code{INSERT DELAYED}.
@item @code{Delayed_errors} @tab Number of rows written with @code{INSERT DELAYED} for which some error occurred (probably @code{duplicate key}).
@item @code{Flush_commands} @tab Number of executed @code{FLUSH} commands.
@item @code{Handler_delete} @tab Number of times a row was deleted from a table.
@item @code{Handler_read_first} @tab Number of times the first entry was read from an index.
If this is high, it suggests that the server is doing a lot of full index scans, for example,
@code{SELECT col1 FROM foo}, assuming that col1 is indexed
@item @code{Handler_read_key} @tab Number of requests to read a row based on a key. If this
is high, it is a good indication that your queries and tables are properly indexed.
@item @code{Handler_read_next} @tab Number of requests to read next row in key order. This
will be incremented if you are querying an index column with a range contraint. This also
will be incremented if you are doing an index scan.
@item @code{Handler_read_rnd} @tab Number of requests to read a row based on a fixed position.
This will be high if you are doing a lot of queries that require sorting of the result.
@item @code{Handler_read_rnd_next} @tab Number of requests to read the next row in the datafile.
This will be high if you are doing a lot of table scans - generally this suggests that you tables
are not properly indexed or that you queries are not written to take advantaged of the indeces you
have..
@item @code{Handler_update} @tab Number of requests to update a row in a table.
@item @code{Handler_write} @tab Number of requests to insert a row in a table.
@item @code{Key_blocks_used} @tab The number of used blocks in the key cache.
@item @code{Key_read_requests} @tab The number of requests to read a key block from the cache.
@item @code{Key_reads} @tab The number of physical reads of a key block from disk.
@item @code{Key_write_requests} @tab The number of requests to write a key block to the cache.
@item @code{Key_writes} @tab The number of physical writes of a key block to disk.
@item @code{Max_used_connections} @tab The maximum number of connections that has been in use simultaneously.
@item @code{Not_flushed_key_blocks} @tab Keys blocks in the key cache that has changed but hasn't yet been flushed to disk.
@item @code{Not_flushed_delayed_rows} @tab Number of rows waiting to be written in @code{INSERT DELAY} queues.
@item @code{Open_tables} @tab Number of tables that are open.
@item @code{Open_files} @tab Number of files that are open.
@item @code{Open_streams} @tab Number of streams that are open (used mainly for logging)
@item @code{Opened_tables} @tab Number of tables that has been opened.
@item @code{Questions} @tab Number of queries sent to the server.
@item @code{Slow_launch_threads} @tab Number of threads that has taken more than @code{slow_launch_time} to connect.
@item @code{Slow_queries} @tab Number of queries that has taken more than @code{long_query_time}
@item @code{Threads_cached} @tab Number of threads in the thread cache.
@item @code{Threads_connected} @tab Number of currently open connections.
@item @code{Threads_running} @tab Number of threads that are not sleeping.
@item @code{Uptime} @tab How many seconds the server has been up.
@end multitable
Some comments about the above:
@itemize @bullet
@item
If @code{Opened_tables} is big, then your @code{table_cache}
variable is probably too small.
@item
If @code{key_reads} is big, then your @code{key_cache} is probably too
small. The cache hit rate can be calculated with
@code{key_reads}/@code{key_read_requests}.
@item
If @code{Handler_read_rnd} is big, then you have a probably a lot of queries
that requires @strong{MySQL} to scan whole tables or you have joins that doesn't use
keys properly.
@end itemize
@node SHOW VARIABLES, SHOW PROCESSLIST, SHOW STATUS, SHOW
@subsection SHOW VARIABLES
@code{SHOW VARIABLES} shows the values of the some of @strong{MySQL} system
variables. You can also get this information using the @code{mysqladmin
variables} command. If the default values are unsuitable, you can set most
of these variables using command-line options when @code{mysqld} starts up.
@xref{Command-line options}.
The output resembles that shown below, though the format and numbers may
differ somewhat:
@example
+----------------------------+------------------------------+
| Variable_name | Value |
+----------------------------+------------------------------+
| ansi_mode | OFF |
| back_log | 50 |
| basedir | /usr/local/mysql/ |
| bdb_cache_size | 1048540 |
| bdb_home | /usr/local/mysql/data/ |
| bdb_logdir | |
| bdb_tmpdir | /tmp/ |
| character_set | latin1 |
| character_sets | latin1 |
| connect_timeout | 5 |
| concurrent_insert | ON |
| datadir | /usr/local/mysql/data/ |
| delay_key_write | ON |
| delayed_insert_limit | 100 |
| delayed_insert_timeout | 300 |
| delayed_queue_size | 1000 |
| join_buffer_size | 131072 |
| flush | OFF |
| flush_time | 0 |
| init_file | |
| interactive_timeout | 28800 |
| key_buffer_size | 16776192 |
| language | /usr/local/mysql/share/english/ |
| log | OFF |
| log_update | OFF |
| log_bin | OFF |
| log_slave_updates | OFF |
| long_query_time | 10 |
| low_priority_updates | OFF |
| lower_case_table_names | 0 |
| max_allowed_packet | 1047552 |
| max_connections | 100 |
| max_connect_errors | 10 |
| max_delayed_threads | 20 |
| max_heap_table_size | 16777216 |
| max_join_size | 4294967295 |
| max_sort_length | 1024 |
| max_tmp_tables | 32 |
| max_write_lock_count | 4294967295 |
| myisam_sort_buffer_size | 8388608 |
| net_buffer_length | 16384 |
| net_retry_count | 10 |
| pid_file | /usr/local/mysql/data/tik.pid |
| port | 3306 |
| protocol_version | 10 |
| record_buffer | 131072 |
| skip_locking | ON |
| skip_networking | OFF |
| skip_show_database | OFF |
| slow_launch_time | 2 |
| socket | /tmp/mysql.sock |
| sort_buffer | 2097116 |
| table_cache | 64 |
| table_type | MYISAM |
| thread_stack | 131072 |
| thread_cache_size | 3 |
| tmp_table_size | 1048576 |
| tmpdir | /tmp/ |
| version | 3.23.21-beta-debug |
| wait_timeout | 28800 |
+-----------------------------------+-----------------------+
@end example
Each option is described below. Values for buffer sizes, lengths and stack
sizes are given in bytes. You can specify values with a suffix of @samp{K}
or @samp{M} to indicate kilobytes or megabytes. For example, @code{16M}
indicates 16 megabytes. The case of suffix letters does not matter;
@code{16M} and @code{16m} are equivalent.
@table @code
@item @code{ansi_mode}.
Is @code{ON} if @code{mysqld} was started with @code{--ansi}.
@xref{Ansi mode}.
@item @code{back_log}
The number of outstanding connection requests @strong{MySQL} can have. This
comes into play when the main @strong{MySQL} thread gets @strong{VERY}
many connection requests in a very short time. It then takes some time
(although very little) for the main thread to check the connection and start
a new thread. The @code{back_log} value indicates how many requests can be
stacked during this short time before @strong{MySQL} momentarily stops
answering new requests. You need to increase this only if you expect a large
number of connections in a short period of time.
In other words, this value is the size of the listen queue for incoming
TCP/IP connections. Your operating system has its own limit on the size
of this queue. The manual page for the Unix @code{listen(2)} system
call should have more details. Check your OS documentation for the
maximum value for this variable. Attempting to set @code{back_log}
higher than your operating system limit will be ineffective.
@item @code{bdb_cache_size}
The buffer that is allocated to cache index and rows for @code{BDB} tables.
If you don't use @code{BDB} tables, you should set this to 0 or
start @code{mysqld} with @code{--skip-bdb} o not waste memory for this cache.
@item @code{concurrent_inserts}
If @code{ON} (the default), @code{MySQL} will allow you to use @code{INSERT}
on @code{MyISAM} tables at the same time as you run @code{SELECT} queries
on them. You can turn this option off by starting mysqld with @code{--safe}
or @code{--skip-new}.
@item @code{connect_timeout}
The number of seconds the @code{mysqld} server is waiting for a connect
packet before responding with @code{Bad handshake}.
@item @code{delayed_insert_timeout}
How long a @code{INSERT DELAYED} thread should wait for @code{INSERT}
statements before terminating.
@item @code{delayed_insert_limit}
After inserting @code{delayed_insert_limit} rows, the @code{INSERT
DELAYED} handler will check if there are any @code{SELECT} statements
pending. If so, it allows these to execute before continuing.
@item @code{delay_key_write}
If enabled (is on by default), @strong{MySQL} will honor the
@code{delay_key_write} option @code{CREATE TABLE}. This means that the
key buffer for tables with this option will not get flushed on every
index update, but only when a table is closed. This will speed up
writes on keys a lot but you should add automatic checking of all tables
with @code{myisamchk --fast --force} if you use this. Note that if you
start @code{mysqld} with the @code{--delay-key-write-for-all-tables}
option this means that all tables will be treated as if they were
created with the @code{delay_key_write} option. You can clear this flag
by starting @code{mysqld} with @code{--skip-new} or @code{--safe-mode}.
@item @code{delayed_queue_size}
What size queue (in rows) should be allocated for handling @code{INSERT
DELAYED}. If the queue becomes full, any client that does @code{INSERT
DELAYED} will wait until there is room in the queue again.
@item @code{flush}
This is @code{ON} if you have started @strong{MySQL} with the @code{--flush}
option.
@item @code{flush_time}
If this is set to a non-zero value, then every @code{flush_time} seconds all
tables will be closed (to free up resources and sync things to disk). We
only recommend this option on Win95, Win98 or on system where you have
very little resources.
@item @code{init_file}
The name of the file specified with the @code{--init-file} option when
you start the server. This is a file of SQL statements you want the
server to execute when it starts.
@item @code{interactive_timeout}
The number of seconds the server waits for activity on an interactive
connection before closing it. An interactive client is defined as a
client that uses the @code{CLIENT_INTERACTIVE} option to
@code{mysql_real_connect()}. See also @code{wait_timeout}.
@item @code{join_buffer_size}
The size of the buffer that is used for full joins (joins that do not
use indexes). The buffer is allocated one time for each full join
between two tables. Increase this value to get a faster full join when
adding indexes is not possible. (Normally the best way to get fast joins
is to add indexes.)
@c Make texi2html support index @anchor{Index cache size}. Then change
@c some xrefs to point here
@item @code{key_buffer_size}
Index blocks are buffered and are shared by all threads.
@code{key_buffer_size} is the size of the buffer used for index blocks.
Increase this to get better index handling (for all reads and multiple
writes) to as much as you can afford; 64M on a 256M machine that mainly
runs @strong{MySQL} is quite common. If you however make this too big
(more than 50% of your total memory?) your system may start to page and
become REALLY slow. Remember that because @strong{MySQL} does not cache
data read, that you will have to leave some room for the OS filesystem
cache.
You can check the performance of the key buffer by doing @code{show
status} and examine the variables @code{Key_read_requests},
@code{Key_reads}, @code{Key_write_requests} and @code{Key_writes}. The
@code{Key_reads/Key_read_request} ratio should normally be < 0.01.
The @code{Key_write/Key_write_requests} is usually near 1 if you are
using mostly updates/deletes but may be much smaller if you tend to
do updates that affect many at the same time or if you are
using @code{delay_key_write}. @xref{SHOW}.
To get even more speed when writing many rows at the same time use
@code{LOCK TABLES}. @xref{LOCK TABLES, , @code{LOCK TABLES}}.
@item @code{lower_case_table_names}
Change all table names to lower case on disk.
@item @code{long_query_time}
If a query takes longer than this (in seconds), the @code{Slow_queries} counter
will be incremented.
@item @code{max_allowed_packet}
The maximum size of one packet. The message buffer is initialized to
@code{net_buffer_length} bytes, but can grow up to @code{max_allowed_packet}
bytes when needed. This value by default is small, to catch big (possibly
wrong) packets. You must increase this value if you are using big
@code{BLOB} columns. It should be as big as the biggest @code{BLOB} you want
to use.
@item @code{max_connections}
The number of simultaneous clients allowed. Increasing this value increases
the number of file descriptors that @code{mysqld} requires. See below for
comments on file descriptor limits. @xref{Too many connections}.
@item @code{max_connect_errors}
If there is more than this number of interrupted connections from a host
this host will be blocked from further connections. You can unblock a host
with the command @code{FLUSH HOSTS}.
@item @code{max_delayed_threads}
Don't start more than this number of threads to handle @code{INSERT DELAYED}
statements. If you try to insert data into a new table after all @code{INSERT
DELAYED} threads are in use, the row will be inserted as if the
@code{DELAYED} attribute wasn't specified.
@item @code{max_join_size}
Joins that are probably going to read more than @code{max_join_size}
records return an error. Set this value if your users tend to perform joins
without a @code{WHERE} clause that take a long time and return
millions of rows.
@item @code{max_heap_table_size}
Don't allow creation of heap tables bigger than this.
@item @code{max_sort_length}
The number of bytes to use when sorting @code{BLOB} or @code{TEXT}
values (only the first @code{max_sort_length} bytes of each value
are used; the rest are ignored).
@item @code{max_tmp_tables}
(This option doesn't yet do anything).
Maximum number of temporary tables a client can keep open at the same time.
@item @code{max_write_lock_count}
After this many write locks, allow some read locks to run in between.
@item @code{myisam_sort_buffer_size}
The buffer that is allocated when sorting the index when doing a @code{REPAIR}
table.
@item @code{net_buffer_length}
The communication buffer is reset to this size between queries. This
should not normally be changed, but if you have very little memory, you
can set it to the expected size of a query. (That is, the expected length of
SQL statements sent by clients. If statements exceed this length, the buffer
is automatically enlarged, up to @code{max_allowed_packet} bytes.)
@item @code{net_retry_count}
If a read on a communication port is interrupted, retry this many times
before giving up. This value should be quite high on @code{FreeBSD} as
internal interrupts is sent to all threads.
@item @code{net_read_timeout}
Number of seconds to wait for more data from a connection before aborting
the read. Note that when we don't expect data from a connection, the timeout
is defined by @code{write_timeout}.
@item @code{net_write_timeout}
Number of seconds to wait for a block to be written to a connection before
aborting the write.
@item @code{record_buffer}
Each thread that does a sequential scan allocates a buffer of this
size for each table it scans. If you do many sequential scans, you may
want to increase this value.
@item @code{query_buffer_size}
The initial allocation of the query buffer. If most of your queries are
long (like when inserting blobs), you should increase this!
@item @code{skip_show_databases}
This prevents people from doing @code{SHOW DATABASES}, if they don't
have the @code{PROCESS_PRIV} privilege. This can improve security if
you're concerned about people being able to see what databases and
tables other users have.
@item @code{slow_launch_time}
If the creating of the thread longer than this (in seconds), the
@code{Slow_launch_threads} counter will be incremented.
@item @code{sort_buffer}
Each thread that needs to do a sort allocates a buffer of this
size. Increase this value for faster @code{ORDER BY} or @code{GROUP BY}
operations.
@xref{Temporary files}.
@item @code{table_cache}
The number of open tables for all threads. Increasing this value
increases the number of file descriptors that @code{mysqld} requires.
@strong{MySQL} needs two file descriptors for each unique open table.
See below for comments on file descriptor limits. You can check if you
need to increase the table cache by checking the @code{Opened_tables}
variable. @xref{SHOW}. If this variable is big and you don't do
@code{FLUSH TABLES} a lot (which just forces all tables to be closed and
reopenend), then you should increase the value of this variable.
For information about how the table cache works, see @ref{Table cache}.
@item @code{thread_cache_size}
How many threads we should keep keep in a cache for reuse. When a
client disconnects the clients threads is put in the cache if there
isn't more than @code{thread_cache_size} threads from before. All new
threads are first taken from the cache and only when the cache is empty
a new thread is created. This variable can be increased to improve
performance if you have a lot of new connections (Normally this doesn't
however give a notable performance improvement if you have a good
thread implementation).
@item @code{thread_concurrency}
On Solaris, @code{mysqld} will call @code{thr_setconcurrency()} with
this value. @code{thr_setconcurrency()} permits the application to give
the threads system a hint, for the desired number of threads that should
be run at the same time.
@item @code{thread_stack}
The stack size for each thread. Many of the limits detected by the
@code{crash-me} test are dependent on this value. The default is
large enough for normal operation. @xref{Benchmarks}.
@item @code{tmp_table_size}
If an in-memory temporary table exceeds this size, @strong{MySQL}
will automatically convert it to an on-disk @code{MyISAM} table.
Increase the value of @code{tmp_table_size} if you do many advanced
@code{GROUP BY} queries and you have lots of memory.
@item @code{wait_timeout}
The number of seconds the server waits for activity on a connection before
closing it. See also @code{interactive_timeout}.
@end table
The manual section that describes tuning @strong{MySQL} contains some
information of how to tune the above variables.
@findex Threads
@findex PROCESSLIST
@node SHOW PROCESSLIST, SHOW GRANTS, SHOW VARIABLES, SHOW
@subsection SHOW information about connected threads (processes)
@code{SHOW PROCESSLIST} shows you which threads are running. You can
also get this information using the @code{mysqladmin processlist}
command. If you have the @strong{process} privilege, you can see all
threads. Otherwise, you can see only your own threads. @xref{KILL, ,
@code{KILL}}. If you don't use the the @code{FULL} option, then only
the first 100 characters of each query will be shown.
@node SHOW GRANTS, , SHOW PROCESSLIST, SHOW
@subsection SHOW GRANTS (privileges) for a user
@code{SHOW GRANTS FOR user} lists the grant commands that must be issued to
duplicate the grants for a user.
@example
mysql> SHOW GRANTS FOR root@@localhost;
+---------------------------------------------------------------------+
| Grants for root@@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
@end example
@findex EXPLAIN
@findex SELECT, optimizing
@node EXPLAIN, DESCRIBE, SHOW, Reference
@section @code{EXPLAIN} syntax (Get information about a @code{SELECT})
@example
EXPLAIN tbl_name
or EXPLAIN SELECT select_options
@end example
@code{EXPLAIN tbl_name} is a synonym for @code{DESCRIBE tbl_name} or
@code{SHOW COLUMNS FROM tbl_name}.
When you precede a @code{SELECT} statement with the keyword @code{EXPLAIN},
@strong{MySQL} explains how it would process the @code{SELECT}, providing
information about how tables are joined and in which order.
With the help of @code{EXPLAIN}, you can see when you must add indexes
to tables to get a faster @code{SELECT} that uses indexes to find the
records. You can also see if the optimizer joins the tables in an optimal
order. To force the optimizer to use a specific join order for a
@code{SELECT} statement, add a @code{STRAIGHT_JOIN} clause.
For non-simple joins, @code{EXPLAIN} returns a row of information for each
table used in the @code{SELECT} statement. The tables are listed in the order
they would be read. @strong{MySQL} resolves all joins using a single-sweep
multi-join method. This means that @strong{MySQL} reads a row from the first
table, then finds a matching row in the second table, then in the third table
and so on. When all tables are processed, it outputs the selected columns and
backtracks through the table list until a table is found for which there are
more matching rows. The next row is read from this table and the process
continues with the next table.
Output from @code{EXPLAIN} includes the following columns:
@table @code
@item table
The table to which the row of output refers.
@item type
The join type. Information about the various types is given below.
@item possible_keys
The @code{possible_keys} column indicates which indexes @strong{MySQL}
could use to find the rows in this table. Note that this column is
totally independent of the order of the tables. That means that some of
the keys in possible_keys may not be useable in practice with the
generated table order.
If this column is empty, there are no relevant indexes. In this case,
you may be able to improve the performance of your query by examining
the @code{WHERE} clause to see if it refers to some column or columns
that would be suitable for indexing. If so, create an appropriate index
and check the query with @code{EXPLAIN} again. @xref{ALTER TABLE}.
To see what indexes a table has, use @code{SHOW INDEX FROM tbl_name}.
@item key
The @code{key} column indicates the key that @strong{MySQL} actually
decided to use. The key is @code{NULL} if no index was chosen. If
@strong{MySQL} chooses the wrong index, you can probably force
@strong{MySQL} to use another index by using @code{myisamchk --analyze},
@xref{myisamchk syntax}, or by using @code{USE INDEX/IGNORE INDEX}.
@xref{JOIN}.
@item key_len
The @code{key_len} column indicates the length of the key that
@strong{MySQL} decided to use. The length is @code{NULL} if the
@code{key} is @code{NULL}. Note that this tell us how many parts of a
multi-part key @strong{MySQL} will actually use.
@item ref
The @code{ref} column shows which columns or constants are used with the
@code{key} to select rows from the table.
@item rows
The @code{rows} column indicates the number of rows @strong{MySQL}
believes it must examine to execute the query.
@item Extra
This column contains additional information of how @strong{MySQL} will
resolve the query. Here follows an explanation of the different text
strings that can be found in this column:
@table @code
@item Not exists
@strong{MySQL} was able to do a @code{LEFT JOIN} optimization on the
query and will not examine more rows in this table for a row combination
after it founds one rows that matches the @code{LEFT JOIN} criteria.
@item @code{range checked for each record (index map: #)}
@strong{MySQL} didn't find a real good index to use. It will instead for
each row combination in the preceding tables do a check which index to
use (if any) use this index to retrieve the rows from the table. This
isn't very fast but is of course faster than having to do a join without
an index.
@item Using filesort
@strong{MySQL} will need to do an extra pass to find out how to retrieve
the rows in sorted order. The sort is done by going through all rows
according to the @code{join type} and storing the sort key + pointer to
the row for all rows that match the @code{WHERE}. Then the keys are
sorted. Finally the rows are retrieved in sorted order.
@item Using index
The column information is retrieved from the table using only
information in the index tree without having to do an additional seek to
read the actually row. This can be done when all the used columns for
the table are part of the same index.
@item Using temporary
To be able to resolve the query @strong{MySQL} will need to create a
temporary table to hold the result. This typically happens if you do an
@code{ORDER BY} on a different column set than you did an @code{GROUP
BY} on.
@item Where used
A @code{WHERE} clause will be used to restrict which rows will be
matched against the next table or sent to the client. If you don't have
this information and the the table is of type @code{ALL} or @code{index}
you may have something wrong in your query (if you don't intend to
fetch/examine all rows from the table).
@end table
If you want to get your queries as fast as possible, you should look out for
@code{Using filesort} and @code{Using temporary}.
@end table
The different join types are listed below, ordered from best to worst type:
@cindex System table
@cindex Table, system
@table @code
@item system
The table has only one row (= system table). This is a special case of
the @code{const} join type.
@cindex Constant table
@cindex Table, constant
@item const
The table has at most one matching row, which will be read at the start
of the query. Because there is only one row, values from the column in
this row can be regarded as constants by the rest of the
optimizer. @code{const} tables are very fast as they are read only once!
@item eq_ref
One row will be read from this table for each combination of rows from
the previous tables. This the best possible join type, other than the
@code{const} types. It is used when all parts of an index are used by
the join and the index is @code{UNIQUE} or a @code{PRIMARY KEY}.
@item ref
All rows with matching index values will be read from this table for each
combination of rows from the previous tables. @code{ref} is used if the join
uses only a leftmost prefix of the key, or if the key is not @code{UNIQUE}
or a @code{PRIMARY KEY} (in other words, if the join cannot select a single
row based on the key value). If the key that is used matches only a few rows,
this join type is good.
@item range
Only rows that are in a given range will be retrieved, using an index to
select the rows. The @code{ref} column indicates which index is used.
@item index
This is the same as @code{ALL}, except that only the index tree is
scanned. This is usually faster than @code{ALL}, as the index file is usually
smaller than the data file.
@item ALL
A full table scan will be done for each combination of rows from the
previous tables. This is normally not good if the table is the first
table not marked @code{const}, and usually @strong{very} bad in all other
cases. You normally can avoid @code{ALL} by adding more indexes, so that
the row can be retrieved based on constant values or column values from
earlier tables.
@end table
You can get a good indication of how good a join is by multiplying all values
in the @code{rows} column of the @code{EXPLAIN} output. This should tell you
roughly how many rows @strong{MySQL} must examine to execute the query. This
number is also used when you restrict queries with the @code{max_join_size}
variable.
@xref{Server parameters}.
The following example shows how a @code{JOIN} can be optimized progressively
using the information provided by @code{EXPLAIN}.
Suppose you have the @code{SELECT} statement shown below, that you examine
using @code{EXPLAIN}:
@example
EXPLAIN SELECT tt.TicketNumber, tt.TimeIn,
tt.ProjectReference, tt.EstimatedShipDate,
tt.ActualShipDate, tt.ClientID,
tt.ServiceCodes, tt.RepetitiveID,
tt.CurrentProcess, tt.CurrentDPPerson,
tt.RecordVolume, tt.DPPrinted, et.COUNTRY,
et_1.COUNTRY, do.CUSTNAME
FROM tt, et, et AS et_1, do
WHERE tt.SubmitTime IS NULL
AND tt.ActualPC = et.EMPLOYID
AND tt.AssignedPC = et_1.EMPLOYID
AND tt.ClientID = do.CUSTNMBR;
@end example
For this example, assume that:
@itemize @bullet
@item
The columns being compared have been declared as follows:
@multitable @columnfractions .1 .2 .7
@item @strong{Table} @tab @strong{Column} @tab @strong{Column type}
@item @code{tt} @tab @code{ActualPC} @tab @code{CHAR(10)}
@item @code{tt} @tab @code{AssignedPC} @tab @code{CHAR(10)}
@item @code{tt} @tab @code{ClientID} @tab @code{CHAR(10)}
@item @code{et} @tab @code{EMPLOYID} @tab @code{CHAR(15)}
@item @code{do} @tab @code{CUSTNMBR} @tab @code{CHAR(15)}
@end multitable
@item
The tables have the indexes shown below:
@multitable @columnfractions .1 .9
@item @strong{Table} @tab @strong{Index}
@item @code{tt} @tab @code{ActualPC}
@item @code{tt} @tab @code{AssignedPC}
@item @code{tt} @tab @code{ClientID}
@item @code{et} @tab @code{EMPLOYID} (primary key)
@item @code{do} @tab @code{CUSTNMBR} (primary key)
@end multitable
@item
The @code{tt.ActualPC} values aren't evenly distributed.
@end itemize
Initially, before any optimizations have been performed, the @code{EXPLAIN}
statement produces the following information:
@example
table type possible_keys key key_len ref rows Extra
et ALL PRIMARY NULL NULL NULL 74
do ALL PRIMARY NULL NULL NULL 2135
et_1 ALL PRIMARY NULL NULL NULL 74
tt ALL AssignedPC,ClientID,ActualPC NULL NULL NULL 3872
range checked for each record (key map: 35)
@end example
Because @code{type} is @code{ALL} for each table, this output indicates that
@strong{MySQL} is doing a full join for all tables! This will take quite a
long time, as the product of the number of rows in each table must be
examined! For the case at hand, this is @code{74 * 2135 * 74 * 3872 =
45,268,558,720} rows. If the tables were bigger, you can only imagine how
long it would take...
One problem here is that @strong{MySQL} can't (yet) use indexes on columns
efficiently if they are declared differently. In this context,
@code{VARCHAR} and @code{CHAR} are the same unless they are declared as
different lengths. Because @code{tt.ActualPC} is declared as @code{CHAR(10)}
and @code{et.EMPLOYID} is declared as @code{CHAR(15)}, there is a length
mismatch.
To fix this disparity between column lengths, use @code{ALTER TABLE} to
lengthen @code{ActualPC} from 10 characters to 15 characters:
@example
mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15);
@end example
Now @code{tt.ActualPC} and @code{et.EMPLOYID} are both @code{VARCHAR(15)}.
Executing the @code{EXPLAIN} statement again produces this result:
@example
table type possible_keys key key_len ref rows Extra
tt ALL AssignedPC,ClientID,ActualPC NULL NULL NULL 3872 where used
do ALL PRIMARY NULL NULL NULL 2135
range checked for each record (key map: 1)
et_1 ALL PRIMARY NULL NULL NULL 74
range checked for each record (key map: 1)
et eq_ref PRIMARY PRIMARY 15 tt.ActualPC 1
@end example
This is not perfect, but is much better (the product of the @code{rows}
values is now less by a factor of 74). This version is executed in a couple
of seconds.
A second alteration can be made to eliminate the column length mismatches
for the @code{tt.AssignedPC = et_1.EMPLOYID} and @code{tt.ClientID =
do.CUSTNMBR} comparisons:
@example
mysql> ALTER TABLE tt MODIFY AssignedPC VARCHAR(15),
MODIFY ClientID VARCHAR(15);
@end example
Now @code{EXPLAIN} produces the output shown below:
@example
table type possible_keys key key_len ref rows Extra
et ALL PRIMARY NULL NULL NULL 74
tt ref AssignedPC,ClientID,ActualPC ActualPC 15 et.EMPLOYID 52 where used
et_1 eq_ref PRIMARY PRIMARY 15 tt.AssignedPC 1
do eq_ref PRIMARY PRIMARY 15 tt.ClientID 1
@end example
This is ``almost'' as good as it can get.
The remaining problem is that, by default, @strong{MySQL} assumes that values
in the @code{tt.ActualPC} column are evenly distributed, and that isn't the
case for the @code{tt} table. Fortunately, it is easy to tell @strong{MySQL}
about this:
@example
shell> myisamchk --analyze PATH_TO_MYSQL_DATABASE/tt
shell> mysqladmin refresh
@end example
Now the join is ``perfect'', and @code{EXPLAIN} produces this result:
@example
table type possible_keys key key_len ref rows Extra
tt ALL AssignedPC,ClientID,ActualPC NULL NULL NULL 3872 where used
et eq_ref PRIMARY PRIMARY 15 tt.ActualPC 1
et_1 eq_ref PRIMARY PRIMARY 15 tt.AssignedPC 1
do eq_ref PRIMARY PRIMARY 15 tt.ClientID 1
@end example
Note that the @code{rows} column in the output from @code{EXPLAIN} is an
``educated guess'' from the @strong{MySQL} join optimizer; To optimize a
query, you should check if the numbers are even close to the truth. If not,
you may get better performance by using @code{STRAIGHT_JOIN} in your
@code{SELECT} statement and trying to list the tables in a different order in
the @code{FROM} clause.
@findex DESC
@findex DESCRIBE
@node DESCRIBE, COMMIT, EXPLAIN, Reference
@section @code{DESCRIBE} syntax (Get information about columns)
@example
@{DESCRIBE | DESC@} tbl_name @{col_name | wild@}
@end example
@code{DESCRIBE} provides information about a table's columns. @code{col_name}
may be a column name or a string containing the SQL @samp{%} and @samp{_}
wildcard characters.
If the column types are different than you expect them to be based on a
@code{CREATE TABLE} statement, note that @strong{MySQL} sometimes changes column
types.
@xref{Silent column changes}.
@cindex Oracle compatibility
@cindex Compatibility, with Oracle
This statement is provided for Oracle compatibility.
The @code{SHOW} statement provides similar information.
@xref{SHOW, , @code{SHOW}}.
@findex BEGIN
@findex COMMIT
@findex ROLLBACK
@node COMMIT, LOCK TABLES, DESCRIBE, Reference
@section @code{BEGIN/COMMIT/ROLLBACK} syntax
By default, @strong{MySQL} runs in @code{autocommit} mode. This means that
as soon as you execute an update, @strong{MySQL} will store the update on
disk.
If you are using @code{BDB} tables, you can put @strong{MySQL} into
non-@code{autocommit} mode with the following command:
@example
SET AUTOCOMMIT=0
@end example
After this you must use @code{COMMIT} to store your changes to disk or
@code{ROLLBACK} if you want to ignore the changes you have made since
the beginning of your transaction.
If you want to switch from @code{AUTOCOMMIT} mode for one serie of
statements, you can use the @code{BEGIN} or @code{BEGIN WORK} statement.
@example
BEGIN;
SELECT @@A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summmary=@@A WHERE type=1;
COMMIT;
@end example
Note that if you are using non-transaction-safe tables, the changes will be
stored at once, independent of the status of the @code{autocommit} mode.
@findex LOCK TABLES
@findex UNLOCK TABLES
@node LOCK TABLES, SET OPTION, COMMIT, Reference
@section @code{LOCK TABLES/UNLOCK TABLES} syntax
@example
LOCK TABLES tbl_name [AS alias] @{READ | [READ LOCAL] | [LOW_PRIORITY] WRITE@}
[, tbl_name @{READ | [LOW_PRIORITY] WRITE@} ...]
...
UNLOCK TABLES
@end example
@code{LOCK TABLES} locks tables for the current thread. @code{UNLOCK TABLES}
releases any locks held by the current thread. All tables that are locked by
the current thread are automatically unlocked when the thread issues another
@code{LOCK TABLES}, or when the connection to the server is closed.
If a thread obtains a @code{READ} lock on a table, that thread (and all other
threads) can only read from the table. If a thread obtains a @code{WRITE}
lock on a table, then only the thread holding the lock can @code{READ} from
or @code{WRITE} to the table. Other threads are blocked.
The difference between @code{READ LOCAL} and @code{READ} is that
@code{READ LOCAL} allows non-conflicting @code{INSERT} statements to
execute while the lock is held. This can't however be used if you are
going to manipulate the database files outside @strong{MySQL} while you
hold the lock.
Each thread waits (without timing out) until it obtains all the locks it has
requested.
@code{WRITE} locks normally have higher priority than @code{READ} locks, to
ensure that updates are processed as soon as possible. This means that if one
thread obtains a @code{READ} lock and then another thread requests a
@code{WRITE} lock, subsequent @code{READ} lock requests will wait until the
@code{WRITE} thread has gotten the lock and released it. You can use
@code{LOW_PRIORITY WRITE} locks to allow other threads to obtain @code{READ}
locks while the thread is waiting for the @code{WRITE} lock. You should only
use @code{LOW_PRIORITY WRITE} locks if you are sure that there will
eventually be a time when no threads will have a @code{READ} lock.
When you use @code{LOCK TABLES}, you must lock all tables that you are
going to use and you must use the same alias that you are going to use in
your queries! If you are using a table multiple times in a query (with
aliases), you must get a lock for each alias! This policy ensures that
table locking is deadlock free.
Note that you should @strong{NOT} lock any tables that you are using with
@code{INSERT DELAYED}. This is because that in this case the @code{INSERT}
is done by a separate thread.
Normally, you don't have to lock tables, as all single @code{UPDATE} statements
are atomic; no other thread can interfere with any other currently executing
SQL statement. There are a few cases when you would like to lock tables
anyway:
@itemize @bullet
@item
If you are going to run many operations on a bunch of tables, it's much
faster to lock the tables you are going to use. The downside is, of course,
that no other thread can update a @code{READ}-locked table and no other
thread can read a @code{WRITE}-locked table.
@item
@strong{MySQL} doesn't support a transaction environment, so you must use
@code{LOCK TABES} if you want to ensure that no other thread comes between a
@code{SELECT} and an @code{UPDATE}. The example shown below
requires @code{LOCK TABLES} in order to execute safely:
@example
mysql> LOCK TABLES trans READ, customer WRITE;
mysql> select sum(value) from trans where customer_id= some_id;
mysql> update customer set total_value=sum_from_previous_statement
where customer_id=some_id;
mysql> UNLOCK TABLES;
@end example
Without @code{LOCK TABLES}, there is a chance that another thread might
insert a new row in the @code{trans} table between execution of the
@code{SELECT} and @code{UPDATE} statements.
@end itemize
By using incremental updates (@code{UPDATE customer SET
value=value+new_value}) or the @code{LAST_INSERT_ID()} function, you can
avoid using @code{LOCK TABLES} in many cases.
You can also solve some cases by using the user-level lock functions
@code{GET_LOCK()} and @code{RELEASE_LOCK()}. These locks are saved in a hash
table in the server and implemented with @code{pthread_mutex_lock()} and
@code{pthread_mutex_unlock()} for high speed.
@xref{Miscellaneous functions}.
See @ref{Internal locking}, for more information on locking policy.
You can also lock all tables in all databases with read locks with the
@code{FLUSH TABLES WITH READ LOCK} command. @xref{FLUSH}.
@findex SET OPTION
@node SET OPTION, GRANT, LOCK TABLES, Reference
@section @code{SET} syntax
@example
SET [OPTION] SQL_VALUE_OPTION= value, ...
@end example
@code{SET OPTION} sets various options that affect the operation of the
server or your client. Any option you set remains in effect until the
current session ends, or until you set the option to a different value.
@table @code
@item CHARACTER SET character_set_name | DEFAULT
This maps all strings from and to the client with the given mapping.
Currently the only option for @code{character_set_name} is
@code{cp1251_koi8}, but you can easily add new mappings by editing the
@file{sql/convert.cc} file in the @strong{MySQL} source distribution. The
default mapping can be restored by using a @code{character_set_name} value of
@code{DEFAULT}.
Note that the syntax for setting the @code{CHARACTER SET} option differs
from the syntax for setting the other options.
@item PASSWORD = PASSWORD('some password')
@cindex Passwords, setting
Set the password for the current user. Any non-anonymous user can change his
own password!
@item PASSWORD FOR user = PASSWORD('some password')
@cindex Passwords, setting
Set the password for a specific user on the current server host. Only a user
with access to the @code{mysql} database can do this. The user should be
given in @code{user@@hostname} format, where @code{user} and @code{hostname}
are exactly as they are listed in the @code{User} and @code{Host} columns of
the @code{mysql.user} table entry. For example, if you had an entry with
@code{User} and @code{Host} fields of @code{'bob'} and @code{'%.loc.gov'},
you would write:
@example
mysql> SET PASSWORD FOR bob@@"%.loc.gov" = PASSWORD("newpass");
or
mysql> UPDATE mysql.user SET password=PASSWORD("newpass") where user="bob' and host="%.loc.gov";
@end example
@item SQL_AUTO_IS_NULL = 0 | 1
If set to @code{1} (default) then one can find the last inserted row
for a table with an auto_increment row with the following construct:
@code{WHERE auto_increment_column IS NULL}. This is used by some
ODBC programs like Access.
@item SET AUTOCOMMIT= 0 | 1
If set to @code{1} all changes to a table will be done at once. To start
an multi command transaction you have to use the @code{BEGIN}
statement. @xref{COMMIT}. If set to @code{0} you have to use @code{COMMIT} /
@code{ROLLBACK} to accept/revoke that transaction. @xref{COMMIT}. Note
that when you change from not @code{AUTOCOMMIT} mode to
@code{AUTOCOMMIT} mode, @strong{MySQL} will do an automatic
@code{COMMIT} on any open transactions.
@item SQL_BIG_TABLES = 0 | 1
@cindex The table is full
If set to @code{1}, all temporary tables are stored on disk rather than in
memory. This will be a little slower, but you will not get the error
@code{The table tbl_name is full} for big @code{SELECT} operations that
require a large temporary table. The default value for a new connection is
@code{0} (i.e., use in-memory temporary tables).
@item SQL_BIG_SELECTS = 0 | 1
If set to @code{0}, @strong{MySQL} will abort if a @code{SELECT} is attempted
that probably will take a very long time. This is useful when an inadvisable
@code{WHERE} statement has been issued. A big query is defined as a
@code{SELECT} that probably will have to examine more than
@code{max_join_size} rows. The default value for a new connection is
@code{1} (which will allow all @code{SELECT} statements).
@item SQL_BUFFER_RESULT = 0 | 1
@code{SQL_BUFFER_RESULT} will force the result from @code{SELECT}'s
to be put into a temporary table. This will help @strong{MySQL} free the
table locks early and will help in cases where it takes a long time to
send the result set to the client.
@item SQL_LOW_PRIORITY_UPDATES = 0 | 1
If set to @code{1}, all @code{INSERT}, @code{UPDATE}, @code{DELETE} and
and @code{LOCK TABLE WRITE} statements wait until there is no pending
@code{SELECT} or @code{LOCK TABLE READ} on the affected table.
@item SQL_MAX_JOIN_SIZE = value | DEFAULT
Don't allow @code{SELECT}'s that will probably need to examine more than
@code{value} row combinations. By setting this value, you can catch
@code{SELECT}'s where keys are not used properly and that would probably
take a long time. Setting this to a value other than @code{DEFAULT} will reset
the @code{SQL_BIG_SELECTS} flag. If you set the @code{SQL_BIG_SELECTS}
flag again, the @code{SQL_MAX_JOIN_SIZE} variable will be ignored.
You can set a default value for this variable by starting @code{mysqld} with
@code{-O max_join_size=#}.
@item SQL_SAFE_MODE = 0 | 1
If set to @code{1}, @strong{MySQL} will abort if a @code{UPDATE} or
@code{DELETE} is attempted that doesn't use a key or @code{LIMIT} in the
@code{WHERE} clause. This makes it possible to catch wrong updates
when creating SQL commands by hand.
@item SQL_SELECT_LIMIT = value | DEFAULT
The maximum number of records to return from @code{SELECT} statements. If
a @code{SELECT} has a @code{LIMIT} clause, the @code{LIMIT} takes precedence
over the value of @code{SQL_SELECT_LIMIT}. The default value for a new
connection is ``unlimited''. If you have changed the limit, the default value
can be restored by using a @code{SQL_SELECT_LIMIT} value of @code{DEFAULT}.
@item SQL_LOG_OFF = 0 | 1
If set to @code{1}, no logging will be done to the standard log for this
client, if the client has the @strong{process} privilege. This does not
affect the update log!
@item SQL_LOG_UPDATE = 0 | 1
If set to @code{0}, no logging will be done to the update log for the client,
if the client has the @strong{process} privilege. This does not affect the
standard log!
@item TIMESTAMP = timestamp_value | DEFAULT
Set the time for this client. This is used to get the original timestamp if
you use the update log to restore rows.
@item LAST_INSERT_ID = #
Set the value to be returned from @code{LAST_INSERT_ID()}. This is stored in
the update log when you use @code{LAST_INSERT_ID()} in a command that updates
a table.
@item INSERT_ID = #
Set the value to be used by the following @code{INSERT} command when inserting
an @code{AUTO_INCREMENT} value. This is mainly used with the update log.
@end table
@findex GRANT
@findex REVOKE
@node GRANT, CREATE INDEX, SET OPTION, Reference
@section @code{GRANT} and @code{REVOKE} syntax
@example
GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON @{tbl_name | * | *.* | db_name.*@}
TO user_name [IDENTIFIED BY 'password']
[, user_name [IDENTIFIED BY 'password'] ...]
[WITH GRANT OPTION]
REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON @{tbl_name | * | *.* | db_name.*@}
FROM user_name [, user_name ...]
@end example
@code{GRANT} is implemented in @strong{MySQL} 3.22.11 or later. For
earlier @strong{MySQL} versions, the @code{GRANT} statement does nothing.
The @code{GRANT} and @code{REVOKE} commands allow system administrators to
grant and revoke rights to @strong{MySQL} users at four privilege levels:
@table @strong
@item Global level
Global privileges apply to all databases on a given server. These privileges
are stored in the @code{mysql.user} table.
@item Database level
Database privileges apply to all tables in a given database. These privileges
are stored in the @code{mysql.db} and @code{mysql.host} tables.
@item Table level
Table privileges apply to all columns in a given table. These privileges are
stored in the @code{mysql.tables_priv} table.
@item Column level
Column privileges apply to single columns in a given table. These privileges are
stored in the @code{mysql.columns_priv} table.
@end table
For examples of how @code{GRANT} works, see @ref{Adding users}.
For the @code{GRANT} and @code{REVOKE} statements, @code{priv_type} may be
specified as any of the following:
@example
ALL PRIVILEGES FILE RELOAD
ALTER INDEX SELECT
CREATE INSERT SHUTDOWN
DELETE PROCESS UPDATE
DROP REFERENCES USAGE
@end example
@code{ALL} is a synonym for @code{ALL PRIVILEGES}. @code{REFERENCES} is not
yet implemented. @code{USAGE} is currently a synonym for ``no privileges''.
It can be used when you want to create a user that has no privileges.
To revoke the @strong{grant} privilege from a user, use a @code{priv_type}
value of @code{GRANT OPTION}:
@example
REVOKE GRANT OPTION ON ... FROM ...;
@end example
The only @code{priv_type} values you can specify for a table are @code{SELECT},
@code{INSERT}, @code{UPDATE}, @code{DELETE}, @code{CREATE}, @code{DROP},
@code{GRANT}, @code{INDEX} and @code{ALTER}.
The only @code{priv_type} values you can specify for a column (that is, when
you use a @code{column_list} clause) are @code{SELECT}, @code{INSERT} and
@code{UPDATE}.
You can set global privileges by using @code{ON *.*} syntax. You can set
database privileges by using @code{ON db_name.*} syntax. If you specify
@code{ON *} and you have a current database, you will set the privileges for
that database. (@strong{Warning:} If you specify @code{ON *} and you
@emph{don't} have a current database, you will affect the global privileges!)
In order to accommodate granting rights to users from arbitrary hosts,
@strong{MySQL} supports specifying the @code{user_name} value in the form
@code{user@@host}. If you want to specify a @code{user} string
containing special characters (such as @samp{-}), or a @code{host} string
containing special characters or wildcard characters (such as @samp{%}), you
can quote the user or host name (e.g., @code{'test-user'@@'test-hostname'}).
You can specify wildcards in the hostname. For example,
@code{user@@"%.loc.gov"} applies to @code{user} for any host in the
@code{loc.gov} domain, and @code{user@@"144.155.166.%"} applies to @code{user}
for any host in the @code{144.155.166} class C subnet.
The simple form @code{user} is a synonym for @code{user@@"%"}.
@strong{Note:} If you allow anonymous users to connect to the @strong{MySQL}
server (which is the default), you should also add all local users as
@code{user@@localhost} because otherwise the anonymous user entry for the
local host in the @code{mysql.user} table will be used when the user tries to
log into the @strong{MySQL} server from the local machine! Anonymous users
are defined by inserting entries with @code{User=''} into the
@code{mysql.user} table. You can verify if this applies to you by executing
this query:
@example
mysql> SELECT Host,User FROM mysql.user WHERE User='';
@end example
For the moment, @code{GRANT} only supports host, table, database and
column names up to 60 characters long. A user name can be up to 16
characters.
The privileges for a table or column are formed from the
logical OR of the privileges at each of the four privilege
levels. For example, if the @code{mysql.user} table specifies that a
user has a global @strong{select} privilege, this can't be denied by an
entry at the database, table or column level.
The privileges for a column can be calculated as follows:
@example
global privileges
OR (database privileges AND host privileges)
OR table privileges
OR column privileges
@end example
In most cases, you grant rights to a user at only one of the privilege
levels, so life isn't normally as complicated as above. :) The details of the
privilege-checking procedure are presented in
@ref{Privilege system}.
If you grant privileges for a user/hostname combination that does not exist
in the @code{mysql.user} table, an entry is added and remains there until
deleted with a @code{DELETE} command. In other words, @code{GRANT} may
create @code{user} table entries, but @code{REVOKE} will not remove them;
you must do that explicitly using @code{DELETE}.
@cindex Passwords, setting
In @strong{MySQL} 3.22.12 or later,
if a new user is created or if you have global grant privileges, the user's
password will be set to the password specified by the @code{IDENTIFIED BY}
clause, if one is given. If the user already had a password, it is replaced
by the new one.
@strong{Warning:} If you create a new user but do not specify an
@code{IDENTIFIED BY} clause, the user has no password. This is insecure.
Passwords can also be set with the @code{SET PASSWORD} command.
@xref{SET OPTION, , @code{SET OPTION}}.
If you grant privileges for a database, an entry in the @code{mysql.db}
table is created if needed. When all privileges for the database have been
removed with @code{REVOKE}, this entry is deleted.
If a user doesn't have any privileges on a table, the table is not displayed
when the user requests a list of tables (e.g., with a @code{SHOW TABLES}
statement).
The @code{WITH GRANT OPTION} clause gives the user the ability to give
to other users any privileges the user has at the specified privilege level.
You should be careful to whom you give the @strong{grant} privilege, as two
users with different privileges may be able to join privileges!
You cannot grant another user a privilege you don't have yourself;
the @strong{grant} privilege allows you to give away only those privileges
you possess.
Be aware that when you grant a user the @strong{grant} privilege at a
particular privilege level, any privileges the user already possesses (or
is given in the future!) at that level are also grantable by that user.
Suppose you grant a user the @strong{insert} privilege on a database. If
you then grant the @strong{select} privilege on the database and specify
@code{WITH GRANT OPTION}, the user can give away not only the @strong{select}
privilege, but also @strong{insert}. If you then grant the @strong{update}
privilege to the user on the database, the user can give away the
@strong{insert}, @strong{select} and @strong{update}.
You should not grant @strong{alter} privileges to a normal user. If you
do that, the user can try to subvert the privilege system by renaming
tables!
Note that if you are using table or column privileges for even one user, the
server examines table and column privileges for all users and this will slow
down @strong{MySQL} a bit.
When @code{mysqld} starts, all privileges are read into memory.
Database, table and column privileges take effect at once and
user-level privileges take effect the next time the user connects.
Modifications to the grant tables that you perform using @code{GRANT} or
@code{REVOKE} are noticed by the server immediately.
If you modify the grant tables manually (using @code{INSERT}, @code{UPDATE},
etc.), you should execute a @code{FLUSH PRIVILEGES} statement or run
@code{mysqladmin flush-privileges} to tell the server to reload the grant
tables.
@xref{Privilege changes}.
@cindex ANSI SQL, differences from
The biggest differences between the ANSI SQL and @strong{MySQL} versions of
@code{GRANT} are:
@itemize @bullet
@item
ANSI SQL doesn't have global or database-level privileges and ANSI SQL
doesn't support all privilege types that @strong{MySQL} supports.
@item
When you drop a table in ANSI SQL, all privileges for the table are revoked.
If you revoke a privilege in ANSI SQL, all privileges that were granted based
on this privilege are also revoked. In @strong{MySQL}, privileges can be
dropped only with explicit @code{REVOKE} commands or by manipulating the
@strong{MySQL} grant tables.
@end itemize
@cindex Indexes
@cindex Indexes, multi-part
@cindex Multi-part index
@findex CREATE INDEX
@node CREATE INDEX, DROP INDEX, GRANT, Reference
@section @code{CREATE INDEX} syntax
@example
CREATE [UNIQUE] INDEX index_name ON tbl_name (col_name[(length)],... )
@end example
The @code{CREATE INDEX} statement doesn't do anything in @strong{MySQL} prior
to version 3.22. In 3.22 or later, @code{CREATE INDEX} is mapped to an
@code{ALTER TABLE} statement to create indexes.
@xref{ALTER TABLE, , @code{ALTER TABLE}}.
Normally, you create all indexes on a table at the time the table itself
is created with @code{CREATE TABLE}.
@xref{CREATE TABLE, , @code{CREATE TABLE}}.
@code{CREATE INDEX} allows you to add indexes to existing tables.
A column list of the form @code{(col1,col2,...)} creates a multiple-column
index. Index values are formed by concatenating the values of the given
columns.
For @code{CHAR} and @code{VARCHAR} columns, indexes can be created that
use only part of a column, using @code{col_name(length)} syntax. (On
@code{BLOB} and @code{TEXT} columns the length is required). The
statement shown below creates an index using the first 10 characters of
the @code{name} column:
@example
mysql> CREATE INDEX part_of_name ON customer (name(10));
@end example
Because most names usually differ in the first 10 characters, this index should
not be much slower than an index created from the entire @code{name} column.
Also, using partial columns for indexes can make the index file much smaller,
which could save a lot of disk space and might also speed up @code{INSERT}
operations!
Note that you can only add an index on a column that can have @code{NULL}
values or on a @code{BLOB}/@code{TEXT} column if you are useing
@strong{MySQL} version 3.23.2 or newer and are using the @code{MyISAM}
table type.
For more information about how @strong{MySQL} uses indexes, see
@ref{MySQL indexes, , @strong{MySQL} indexes}.
@findex DROP INDEX
@node DROP INDEX, Comments, CREATE INDEX, Reference
@section @code{DROP INDEX} syntax
@example
DROP INDEX index_name ON tbl_name
@end example
@code{DROP INDEX} drops the index named @code{index_name} from the table
@code{tbl_name}. @code{DROP INDEX} doesn't do anything in @strong{MySQL}
prior to version 3.22. In 3.22 or later, @code{DROP INDEX} is mapped to an
@code{ALTER TABLE} statement to drop the index.
@xref{ALTER TABLE, , @code{ALTER TABLE}}.
@findex Comment syntax
@node Comments, CREATE FUNCTION, DROP INDEX, Reference
@section Comment syntax
The @strong{MySQL} server supports the @code{# to end of line}, @code{--
to end of line} and @code{/* in-line or multiple-line */} comment
styles:
@example
mysql> select 1+1; # This comment continues to the end of line
mysql> select 1+1; -- This comment continues to the end of line
mysql> select 1 /* this is an in-line comment */ + 1;
mysql> select 1+
/*
this is a
multiple-line comment
*/
1;
@end example
Note that the @code{--} comment style requires you to have at least one space
after the @code{--}!
Although the server understands the comment syntax just described,
there are some limitations on the way that the @code{mysql} client
parses @code{/* ... */} comments:
@itemize @bullet
@item
Single-quote and double-quote characters are taken to indicate the beginning
of a quoted string, even within a comment. If the quote is not matched by a
second quote within the comment, the parser doesn't realize the comment has
ended. If you are running @code{mysql} interactively, you can tell that it
has gotten confused like this because the prompt changes from @code{mysql>}
to @code{'>} or @code{">}.
@item
A semicolon is taken to indicate the end of the current SQL statement
and anything following it to indicate the beginning of the next statement.
@end itemize
These limitations apply both when you run @code{mysql} interactively
and when you put commands in a file and tell @code{mysql} to read its
input from that file with @code{mysql < some-file}.
@strong{MySQL} doesn't support the @samp{--} ANSI SQL comment style.
@xref{Missing comments}.
@findex CREATE FUNCTION
@findex DROP FUNCTION
@findex UDF functions
@findex User-defined functions
@findex Functions, user-defined
@node CREATE FUNCTION, Reserved words, Comments, Reference
@section @code{CREATE FUNCTION/DROP FUNCTION} syntax
@example
CREATE [AGGREGATE] FUNCTION function_name RETURNS @{STRING|REAL|INTEGER@}
SONAME shared_library_name
DROP FUNCTION function_name
@end example
A user-definable function (UDF) is a way to extend @strong{MySQL} with a new
function that works like native (built in) @strong{MySQL} functions such as
@code{ABS()} and @code{CONCAT()}.
@code{AGGREGATE} is a new option for @strong{MySQL} 3.23. An
@code{AGGREGATE} function works exactly like a native @strong{MySQL}
@code{GROUP} function like @code{SUM} or @code{COUNT()}.
@code{CREATE FUNCTION} saves the function's name, type and shared library
name in the @code{mysql.func} system table. You must have the
@strong{insert} and @strong{delete} privileges for the @code{mysql} database
to create and drop functions.
All active functions are reloaded each time the server starts, unless
you start @code{mysqld} with the @code{--skip-grant-tables} option. In
this case, UDF initialization is skipped and UDFs are unavailable.
(An active function is one that has been loaded with @code{CREATE FUNCTION}
and not removed with @code{DROP FUNCTION}.)
For instructions on writing user-definable functions, see @ref{Adding
functions}. For the UDF mechanism to work, functions must be written in C or
C++, your operating system must support dynamic loading and you must have
compiled @code{mysqld} dynamically (not statically).
@cindex Keywords
@cindex Reserved words
@cindex Reserved words, exceptions
@node Reserved words, , CREATE FUNCTION, Reference
@section Is MySQL picky about reserved words?
A common problem stems from trying to create a table with column names that
use the names of datatypes or functions built into @strong{MySQL}, such as
@code{TIMESTAMP} or @code{GROUP}. You're allowed to do it (for example,
@code{ABS} is an allowed column name), but whitespace is not allowed between
a function name and the @samp{(} when using functions whose names are also
column names.
The following words are explicitly reserved in @strong{MySQL}. Most of
them are forbidden by ANSI SQL92 as column and/or table names
(for example, @code{group}).
A few are reserved because @strong{MySQL} needs them and is
(currently) using a @code{yacc} parser:
@c This is fixed by including the symbols table from lex.h here and then running
@c fix-mysql-reserved-words in emacs (or let David do it):
@c (defun fix-mysql-reserved-words ()
@c (interactive)
@c (let ((cnt 0))
@c (insert "\n@item ")
@c (while (looking-at "[ \t]*{ +\"\\([^\"]+\\)\"[ \t]*,.*\n")
@c (replace-match "@code{\\1}")
@c (incf cnt)
@c (if (> cnt 3)
@c (progn
@c (setf cnt 0)
@c (insert "\n@item "))
@c (insert " @tab ")))))
@c But remove the non alphanumeric entries by hand first.
@c Updated after 3.23.4 990928 by David
@multitable @columnfractions .25 .25 .25 .25
@item @code{action} @tab @code{add} @tab @code{aggregate} @tab @code{all}
@item @code{alter} @tab @code{after} @tab @code{and} @tab @code{as}
@item @code{asc} @tab @code{avg} @tab @code{avg_row_length} @tab @code{auto_increment}
@item @code{between} @tab @code{bigint} @tab @code{bit} @tab @code{binary}
@item @code{blob} @tab @code{bool} @tab @code{both} @tab @code{by}
@item @code{cascade} @tab @code{case} @tab @code{char} @tab @code{character}
@item @code{change} @tab @code{check} @tab @code{checksum} @tab @code{column}
@item @code{columns} @tab @code{comment} @tab @code{constraint} @tab @code{create}
@item @code{cross} @tab @code{current_date} @tab @code{current_time} @tab @code{current_timestamp}
@item @code{data} @tab @code{database} @tab @code{databases} @tab @code{date}
@item @code{datetime} @tab @code{day} @tab @code{day_hour} @tab @code{day_minute}
@item @code{day_second} @tab @code{dayofmonth} @tab @code{dayofweek} @tab @code{dayofyear}
@item @code{dec} @tab @code{decimal} @tab @code{default} @tab @code{delayed}
@item @code{delay_key_write} @tab @code{delete} @tab @code{desc} @tab @code{describe}
@item @code{distinct} @tab @code{distinctrow} @tab @code{double} @tab @code{drop}
@item @code{end} @tab @code{else} @tab @code{escape} @tab @code{escaped}
@item @code{enclosed} @tab @code{enum} @tab @code{explain} @tab @code{exists}
@item @code{fields} @tab @code{file} @tab @code{first} @tab @code{float}
@item @code{float4} @tab @code{float8} @tab @code{flush} @tab @code{foreign}
@item @code{from} @tab @code{for} @tab @code{full} @tab @code{function}
@item @code{global} @tab @code{grant} @tab @code{grants} @tab @code{group}
@item @code{having} @tab @code{heap} @tab @code{high_priority} @tab @code{hour}
@item @code{hour_minute} @tab @code{hour_second} @tab @code{hosts} @tab @code{identified}
@item @code{ignore} @tab @code{in} @tab @code{index} @tab @code{infile}
@item @code{inner} @tab @code{insert} @tab @code{insert_id} @tab @code{int}
@item @code{integer} @tab @code{interval} @tab @code{int1} @tab @code{int2}
@item @code{int3} @tab @code{int4} @tab @code{int8} @tab @code{into}
@item @code{if} @tab @code{is} @tab @code{isam} @tab @code{join}
@item @code{key} @tab @code{keys} @tab @code{kill} @tab @code{last_insert_id}
@item @code{leading} @tab @code{left} @tab @code{length} @tab @code{like}
@item @code{lines} @tab @code{limit} @tab @code{load} @tab @code{local}
@item @code{lock} @tab @code{logs} @tab @code{long} @tab @code{longblob}
@item @code{longtext} @tab @code{low_priority} @tab @code{max} @tab @code{max_rows}
@item @code{match} @tab @code{mediumblob} @tab @code{mediumtext} @tab @code{mediumint}
@item @code{middleint} @tab @code{min_rows} @tab @code{minute} @tab @code{minute_second}
@item @code{modify} @tab @code{month} @tab @code{monthname} @tab @code{myisam}
@item @code{natural} @tab @code{numeric} @tab @code{no} @tab @code{not}
@item @code{null} @tab @code{on} @tab @code{optimize} @tab @code{option}
@item @code{optionally} @tab @code{or} @tab @code{order} @tab @code{outer}
@item @code{outfile} @tab @code{pack_keys} @tab @code{partial} @tab @code{password}
@item @code{precision} @tab @code{primary} @tab @code{procedure} @tab @code{process}
@item @code{processlist} @tab @code{privileges} @tab @code{read} @tab @code{real}
@item @code{references} @tab @code{reload} @tab @code{regexp} @tab @code{rename}
@item @code{replace} @tab @code{restrict} @tab @code{returns} @tab @code{revoke}
@item @code{rlike} @tab @code{row} @tab @code{rows} @tab @code{second}
@item @code{select} @tab @code{set} @tab @code{show} @tab @code{shutdown}
@item @code{smallint} @tab @code{soname} @tab @code{sql_big_tables} @tab @code{sql_big_selects}
@item @code{sql_low_priority_updates} @tab @code{sql_log_off} @tab @code{sql_log_update} @tab @code{sql_select_limit}
@item @code{sql_small_result} @tab @code{sql_big_result} @tab @code{sql_warnings} @tab @code{straight_join}
@item @code{starting} @tab @code{status} @tab @code{string} @tab @code{table}
@item @code{tables} @tab @code{temporary} @tab @code{terminated} @tab @code{text}
@item @code{then} @tab @code{time} @tab @code{timestamp} @tab @code{tinyblob}
@item @code{tinytext} @tab @code{tinyint} @tab @code{trailing} @tab @code{to}
@item @code{type} @tab @code{use} @tab @code{using} @tab @code{unique}
@item @code{unlock} @tab @code{unsigned} @tab @code{update} @tab @code{usage}
@item @code{values} @tab @code{varchar} @tab @code{variables} @tab @code{varying}
@item @code{varbinary} @tab @code{with} @tab @code{write} @tab @code{when}
@item @code{where} @tab @code{year} @tab @code{year_month} @tab @code{zerofill}
@end multitable
The following symbols (from the table above) are disallowed by ANSI SQL
but allowed by @strong{MySQL} as column/table names. This is because some
of these names are very natural names and a lot of people have already
used them.
@itemize @bullet
@item @code{ACTION}
@item @code{BIT}
@item @code{DATE}
@item @code{ENUM}
@item @code{NO}
@item @code{TEXT}
@item @code{TIME}
@item @code{TIMESTAMP}
@end itemize
@cindex Table types, Choosing
@cindex BDB table type
@cindex Berkeley_db table type
@cindex ISAM table type
@cindex HEAP table type
@cindex MySQL table types
@cindex MyISAM table type
@node Table types, Tutorial, Reference, Top
@chapter MySQL table types
As of @strong{MySQL} 3.23.6, you can choose between three basic
table formats. When you create a new table, you can tell @strong{MySQL}
which table type it should use for the table. @strong{MySQL} will
always create a @code{.frm} file to hold the table and column
definitions. Depending on the table type the index and data will be
stored in other files.
The default table type in @strong{MySQL} is @code{MyISAM}. If you are
trying to use a table type that is not incompiled or activated,
@strong{MySQL} will instead create a table of type @code{MyISAM}.
You can convert tables between different types with the @code{ALTER
TABLE} statement. @xref{ALTER TABLE, , @code{ALTER TABLE}}.
Note that @strong{MySQL} supports two different kind of
tables. Transactions safe tables (@code{BDB}) and not transaction safe
tables (@code{ISAM},@code{MyISAM} and @code{HEAP}.
Advantages of transaction safe tables (TST)
@itemize @bullet
@item
Safer; Even if @code{MySQL} crashes or you get hardware problems, you
can get your data back; Either by automatic recovery or from a backup
+ the transaction log.
@item
You can combine many statements and accept these all in one go with
the @code{COMMIT} command.
@item
You can execute @code{ROLLBACK} to ignore your changes (if you are not
running in auto commit mode).
@item
If an update fails, all your changes will be restored. (With NTST tables all
changes that has taken place are permanent)
@end itemize
Advantages of not transaction safe tables (NTST):
@itemize @bullet
@item
Much faster as there is no transcation overhead.
@item
Will use less disk space as there is no overhead of transactions.
@item
Will use less memory to do updates.
@end itemize
You can combine TST and NTST tables in the same statements to get the best
of both worlds.
@menu
* MyISAM:: MyISAM tables
* ISAM:: ISAM tables
* HEAP:: HEAP tables
* BDB:: BDB or Berkeley_db tables
@end menu
@node MyISAM, ISAM, Table types, Table types
@section MyISAM tables
@code{MyISAM} is the default table type in @strong{MySQL} 3.23. It's
based on the @code{ISAM} code and has a lot of useful extensions.
The index is stored in a file with the @code{.MYI} (MYIndex) extension
and the data is stored in file with the @code{.MYD} (MYData) extension.
You can check/repair @code{MyISAM} tables with the @code{myisamchk}
utility. @xref{Crash recovery}.
The following is new in @code{MyISAM}:
@itemize @bullet
@item
You can @code{INSERT} new rows in a table without deleted rows,
while other threads are reading from the table.
@item
Support for big files (63-bit) on filesystems/operating systems that
support big files.
@item
All data is stored with the low byte first. This makes the data machine and
OS independent. The only requirement is that the machine uses two's-complement
signed integers (as every machine for the last 20 years has)
and IEEE floating point format (also totally dominant among mainstream
machines). The only area of machines that may not support binary
compatibility are embedded systems (because they sometimes have peculiar
processors).
@item
All number keys are stored with high byte first to give better index
compression.
@item
Internal handling of one @code{AUTO_INCREMENT} column. @code{MyISAM}
will automatically update this on @code{INSERT/UPDATE}. The
@code{AUTO_INCREMENT} value can be reset with @code{myisamchk}. This
will make @code{AUTO_INCREMENT} columns faster (at least 10 %) and old
numbers will not be reused as with the old ISAM. Note that when a
@code{AUTO_INCREMENT} is defined on the end of a multi-part-key the old
behavior is still present.
@item
When inserted in sorted order (as when you are using an @code{AUTO_INCREMENT}
column) the key tree will be split so that the high node only contains one
key. This will improve the space utilization in the key tree.
@item
@code{BLOB} and @code{TEXT} columns can be indexed.
@item
@code{NULL} values are allowed in indexed columns. This takes 0-1
bytes/key.
@item
Maximum key length is now 500 bytes by default. In cases of keys longer
than 250 bytes, a bigger key block size than the default of 1024 bytes
is used for this key.
@item
Maximum number of keys/table enlarged to 32 as default. This can be
enlarged to 64 without having to recompile @code{myisamchk}.
@item
There is a flag in the @code{MyISAM} file that indicates whether or not the
table was closed correctly. This will soon be used for automatic repair
in the @strong{MySQL} server.
@item
@code{myisamchk} will mark tables as checked if one runs it with
@code{--update-state}. @code{myisamchk --fast} will only check those
tables that don't have this mark.
@item
@code{myisamchk -a} stores statistics for key parts (and not only for
whole keys as in @code{ISAM}).
@item
Dynamic size rows will now be much less fragmented when mixing deletes
with updates and inserts. This is done by automatically combining adjacent
deleted blocks and by extending blocks if the next block is deleted.
@item
@code{myisampack} can pack @code{BLOB} and @code{VARCHAR} columns.
@end itemize
@code{MyISAM} also supports the following things, which @strong{MySQL}
will be able to use in the near future.
@itemize @bullet
@item
Support for a true @code{VARCHAR} type; A @code{VARCHAR} column starts
with a length stored in 2 bytes.
@item
Tables with @code{VARCHAR} may have fixed or dynamic record length.
@item
@code{VARCHAR} and @code{CHAR} may be up to 64K.
All key segments have their own language definition. This will enable
@strong{MySQL} to have different language definitions per column.
@item
A hashed computed index can be used for @code{UNIQUE}; This will allow
you to have @code{UNIQUE} on any combination of columns in a table. (You
can't search on a @code{UNIQUE} computed index, however.)
@end itemize
Note that index files are usually much smaller with @code{MyISAM} than with
@code{ISAM}. This means that @code{MyISAM} will normally use less
system resources than @code{ISAM}, but will need more CPU when inserting
data into compressed index.
@menu
* Key space:: Space needed for keys
* MyISAM table formats:: MyISAM table formats
@end menu
@node Key space, MyISAM table formats, MyISAM, MyISAM
@subsection Space needed for keys
@strong{MySQL} can support different index types, but the normal type is
ISAM or MyISAM. These use a B-tree index and you can roughly calculate
the size for the index file as @code{(key_length+4)/0.67}, summed over
all keys. (This is for the worst case when all keys are inserted in
sorted order and we don't have any compressed keys.)
String indexes are space compressed. If the first index part is a
string, it will also be prefix compressed. Space compression makes the
index file smaller than the above figures if the string column has a lot
of trailing space or is a @code{VARCHAR} column that is not always used
to the full length. Prefix compression is used on keys that start
with a string. Prefix compression helps if there are many strings
with an identical prefix.
In @code{MyISAM} tables, you can also prefix compress numbers by specifying
@code{PACK_KEYS=1} when you create the table. This helps when you have
many integer keys which have an identical prefix when the numbers are stored
high-byte first.
@node MyISAM table formats, , Key space, MyISAM
@subsection MyISAM table formats
@strong{MyISAM} supports 3 different table types. 2 of them are chosen
automatically depending on the type of columns you are using. The third,
compressed tables, can only be created with the @code{myisampack} tool.
@menu
* Static format:: Static (Fixed-length) table characteristics
* Dynamic format:: Dynamic table characteristics
* Compressed format:: Compressed table characteristics
@end menu
@node Static format, Dynamic format, MyISAM table formats, MyISAM table formats
@subsubsection Static (Fixed-length) table characteristics
This is the default format. It's used when the table contains no
@code{VARCHAR}, @code{BLOB} or @code{TEXT} columns.
This format is the simplest and most secure format. It is also the
fastest of the on-disk formats. The speed comes from the easy way data
can be found on disk. When looking up something with an index and static
format it is very simple, just multiply the row number by the row length.
Also when scanning a table it is very easy to read a constant number of
records with each disk read.
The security comes from if your computer crashes when writing to a
fixed size MyISAM file, @code{myisamchk} can easily figure out where each
row starts and ends. So it can usually reclaim all records except the
partially written one. Note that in @strong{MySQL} all indexes can always be
reconstructed.
@itemize @bullet
@item
All @code{CHAR}, @code{NUMERIC} and @code{DECIMAL} columns are space-padded
to the column width.
@item
Very quick.
@item
Easy to cache.
@item
Easy to reconstruct after a crash, because records are located in fixed
positions.
@item
Doesn't have to be reorganized (with @code{myisamchk}) unless a huge number of
records are deleted and you want to return free disk space to the operating
system.
@item
Usually requires more disk space than dynamic tables.
@end itemize
@node Dynamic format, Compressed format, Static format, MyISAM table formats
@subsubsection Dynamic table characteristics
This format is used if the table contains any @code{VARCHAR}, @code{BLOB}
or @code{TEXT} columns or if the table was created with
@code{ROW_FORMAT=dynamic}.
This format is a litte more complex because each row has to have a header
that says how long it is. One record can also end up at more than one
location when it is made longer at an update.
You can use @code{OPTIMIZE table} or @code{myisamchk} to defragment a
table. If you have static data that you access/change a lot in the same
table as some @code{VARCHAR} or @code{BLOB} columns, it might be a good
idea to move the dynamic columns to other tables just to avoid
fragmentation.
@itemize @bullet
@item
All string columns are dynamic (except those with a length less than 4).
@item
Each record is preceded by a bitmap indicating which columns are empty
(@code{''}) for string columns, or zero for numeric columns (this isn't
the same as columns containing @code{NULL} values). If a string column
has a length of zero after removal of trailing spaces, or a numeric
column has a value of zero, it is marked in the bit map and not saved to
disk. Non-empty strings are saved as a length byte plus the string
contents.
@item
Usually takes much less disk space than fixed-length tables.
@item
Each record uses only as much space as is required. If a record becomes
larger, it is split into as many pieces as required. This results in record
fragmentation.
@item
If you update a row with information that extends the row length, the
row will be fragmented. In this case, you may have to run @code{myisamchk
-r} from time to time to get better performance. Use @code{myisamchk -ei
tbl_name} for some statistics.
@item
Not as easy to reconstruct after a crash, because a record may be fragmented
into many pieces and a link (fragment) may be missing.
@item
The expected row length for dynamic sized records is:
@example
3
+ (number of columns + 7) / 8
+ (number of char columns)
+ packed size of numeric columns
+ length of strings
+ (number of NULL columns + 7) / 8
@end example
There is a penalty of 6 bytes for each link. A dynamic record is linked
whenever an update causes an enlargement of the record. Each new link will be
at least 20 bytes, so the next enlargement will probably go in the same link.
If not, there will be another link. You may check how many links there are
with @code{myisamchk -ed}. All links may be removed with @code{myisamchk -r}.
@end itemize
@node Compressed format, , Dynamic format, MyISAM table formats
@subsubsection Compressed table characteristics
This is a read only type that is generated with the optional
@code{myisampack} tool (@code{pack_isam} for @code{ISAM} tables).
@itemize @bullet
@item
All MySQL distributions, even those that existed before @strong{MySQL}
went GPL, can read tables that were compressed with @code{myisampack}.
@item
Compressed tables takes very little disk space. This minimizes disk usage which
is very nice when using slow disks (like CD-ROMs).
@item
Each record is compressed separately (very little access overhead). The
header for a record is fixed (1-3 bytes) depending on the biggest record in the
table. Each column is compressed differently. Some of the compression types
are:
@itemize @minus
@item
There is usually a different Huffman table for each column.
@item
Suffix space compression.
@item
Prefix space compression.
@item
Numbers with value @code{0} are stored using 1 bit.
@item
If values in an integer column have a small range, the column is stored using
the smallest possible type. For example, a @code{BIGINT} column (8 bytes) may
be stored as a @code{TINYINT} column (1 byte) if all values are in the range
@code{0} to @code{255}.
@item
If a column has only a small set of possible values, the column type is
converted to @code{ENUM}.
@item
A column may use a combination of the above compressions.
@end itemize
@item
Can handle fixed or dynamic length records, but not @code{BLOB} or @code{TEXT}
columns.
@item
Can be uncompressed with @code{myisamchk}.
@end itemize
@node ISAM, HEAP, MyISAM, Table types
@section ISAM tables
You can also use the deprecated ISAM table type. This will disappear
rather soon because @code{MyISAM} is a better implementation of the same
thing. ISAM uses a @code{B-tree} index. The index is stored in a file
with the @code{.ISM} extension and the data is stored in file with the
@code{.ISD} extension. You can check/repair ISAM tables with the
@code{isamchk} utility. @xref{Crash recovery}.
@code{ISAM} has the following features/properties:
@itemize @bullet
@item Compressed and fixed length keys
@item Fixed and dynamic record length
@item 16 keys with 16 key parts / key
@item Max key length 256 (default)
@item Data is stored in machine format; this is fast, but is machine/OS dependent.
@end itemize
Most of the things for @code{MyISAM} tables are also true for @code{ISAM}
tables. @xref{MyISAM}. The major differences compared to @code{MyISAM}
tables are:
@itemize @bullet
@item ISAM tables are not binary portable across OS/Platforms.
@item Can't handle tables > 4G.
@item Only support prefix compression on strings
@item Smaller key limits.
@item Dynamic tables gets more fragmented.
@item Tables are compressed with @code{pack_isam} rather than with @code{myisampack}.
@end itemize
@node HEAP, BDB, ISAM, Table types
@section HEAP tables
@code{HEAP} tables use a hashed index and are stored in memory. This
makes them very fast, but if @strong{MySQL} crashes you will lose all
data stored in them. @code{HEAP} is very useful for temporary tables!
The @strong{MySQL} internal HEAP tables uses 100% dynamic hashing
without overflow areas. There is no extra space needed for free lists.
@code{HEAP} tables also don't have problems with delete + inserts, which
normally is common with hashed tables..
@example
mysql> CREATE TABLE test TYPE=HEAP SELECT ip,SUM(downloads) as down
FROM log_table GROUP BY ip;
mysql> SELECT COUNT(ip),AVG(down) FROM test;
mysql> DROP TABLE test;
@end example
Here are some things you should consider when you use @code{HEAP} tables:
@itemize @bullet
@item
You should always use specify @code{MAX_ROWS} in the @code{CREATE} statement
to ensure that you accidently do not use all memory.
@item
Indexes will only be used with @code{=} and @code{<=>} (but are VERY fast).
@item
@code{HEAP} tables can only use whole keys to search for a row; compare this
to @code{MyISAM} tables where any prefix of the key can be used to find rows.
@item
@code{HEAP} tables use a fixed record length format.
@item
@code{HEAP} doesn't support @code{BLOB}/@code{TEXT} columns.
@item
@code{HEAP} doesn't support @code{AUTO_INCREMENT} columns.
@item
@code{HEAP} doesn't support an index on a @code{NULL} column.
@item
You can have non-unique keys in a @code{HEAP} table (this isn't common for
hashed tables).
@item
@code{HEAP} tables are shared between all clients (just like any other
table).
@item
You can't search for the next entry in order (that is to use the index
to do a @code{ORDER BY}).
@item
Data for @code{HEAP} tables are allocated in small blocks. The tables
are 100% dynamic (on inserting). No overflow areas and no extra key
space is needed. Deleted rows are put in a linked list and are
reused when you insert new data into the table.
@item
You need enough extra memory for all HEAP tables that you want to use at
the same time.
@item
To free memory, you should execute @code{DELETE FROM heap_table} or
@code{DROP TABLE heap_table}.
@item
@strong{MySQL} cannot find out how approximately many rows there
are between two values (this is used by the range optimizer to decide which
index to use). This may affect some queries if you change a @code{MyISAM}
table to a @code{HEAP} table.
@item
To ensure that you accidentally don't do anything stupid, you can't create
@code{HEAP} tables bigger than @code{max_heap_table_size}.
@end itemize
Memory needed for one row in a @code{HEAP} table is:
SUM_OVER_ALL_KEYS(max_length_of_key + sizeof(char*)*2) +
ALIGN(length_of_row+1,sizeof(char*))
@code{sizeof(char*)} is 4 on 32 bit machines and 8 on 64 bit machines.
@node BDB, , HEAP, Table types
@section BDB or Berkeley_db tables
Berkeley DB (@uref{http://www.sleepycat.com}) has provided
@strong{MySQL} with a transaction safe table handler. This will survive
crashes and also provides @code{COMMIT} and @code{ROLLBACK} on
transactions. In order to build MySQL 3.23.x (BDB support first appeared
in 3.23.15) with support for @code{BDB} tables, you will need Berkeley
DB 3.1.14 or newer which can be downloaded from
@uref{http://www.mysql.com/downloads/mysql-3.23.html}; or also from
Sleepycat's download page at
@uref{http://www.sleepycat.com/download.html}.
To install Berkeley DB first uncompress the @code{BDB} distribution
and follow the instructions in the README provided in the distiribution
directory. Basicly what you need to do is:
@itemize @bullet
@item
cd build_[your_os]
@item
../dist/configure
@item
make
@item
make install
@end itemize
Please refer to the manual provided by @code{BDB} distribution for
more/updated information.
After this you need to configure your @strong{MySQL} with
--with-berkeley-db=DIR The directory is the one where you installed
@code{BDB} binaries with make install. (Usually it is
/usr/local/BerkeleyDB.3.1/) You can give additional options to
@strong{MySQL} configure, --with-berkeley-db-includes=DIR and
--with-berkeley-db-libs=DIR, if the @code{BDB} includes and/or libs
directory is not under the first directory. By default they are.
Then complete the @strong{MySQL} installation as normal.
Even if Berkeley DB is in itself very tested and reliably, the
@strong{MySQL} interface is still very alpha, but we are actively
improving and optimizing it to get it this stable real soon.
If you are running with @code{AUTOCOMMIT=0} then your changes in @code{BDB}
tables will not be updated until you execute @code{COMMIT}. Instead of commit
you can execute @code{ROLLBACK} to forget your changes. @xref{COMMIT}.
The following options to @code{mysqld} can be used to change the behavour of
BDB tables:
@multitable @columnfractions .30 .70
@item --bdb-home= directory @tab Berkeley home direcory
@item --bdb-lock-detect=# @tab Berkeley lock detect. One of (DEFAULT, OLDEST, RANDOM or YOUNGEST)
@item --bdb-logdir=directory @tab Berkeley DB log file directory
@item --bdb-nosync @tab Don't synchronously flush logs
@item --bdb-recover @tab Start Berkeley DB in recover mode
@item --bdb-tmpdir=directory @tab Berkeley DB tempfile name
@item --skip-bdb @tab Don't use berkeley db.
@end multitable
If you use @code{--skip-bdb}, @strong{MySQL} will not initialize the
Berkeley DB library and this will save a lot of memory. You can of course
not use @code{BDB} tables if you are using this option.
Normally you should start mysqld with @code{--bdb-recover} if you intend
to use BDB tables. This may however give you problems when you try to
start mysqld if the BDB log files are corrupted. @xref{Starting server}.
Some characteristic of @code{BDB} tables:
@itemize @bullet
@item
All @code{BDB} tables must have a primary key.
@item
If all columns you access in a @code{BDB} tables is part of the same index or
part of the the primary key then @strong{MySQL} can execute the query
without having to access the actual row. In a @code{MyISAM} table the
above holds only if the columns are part of the same index.
@item
@code{LOCK TABLES} works on @code{BDB} tables as with other tables. If
you don't use @code{LOCK TABLE}, @strong{MYSQL} will issue an internal
multiple write lock on the table to ensure that the table will be
properly locked if one another thread issues a table lock.
@item
@code{ALTER TABLE} doesn't yet work on @code{BDB} tables.
@item
Internal locking in @code{BDB} tables are done on page level.
@item
Scanning is slower than with @code{MyISAM} tables as one has data in BDB
tables is stored in B-trees and not in a separate data file.
@item
One must in the application always be prepared to handle the case that
any change of a @code{BDB} table may make an automatic rollback and any
read may fail with a deadlock error.
@item
Keys are not compressed to previous keys as with ISAM or MyISAM
tables. In other words, the key information will take a little more
space in @code{BDB} tables compared to MyISAM tables with don't use
@code{PACK_KEYS=0}.
@item
One must do a @code{FLUSH LOGS} from time to time to sync to get checkpoints
for the @code{BDB} tables.
@item
As transaction logs take more place than ordinary logs it's more important
to rotate and remove old logs when using @code{BDB} tables than using other table
types.
@end itemize
Some things that we have to fix in the near future:
@itemize @bullet
@item
Remove the requirement that @code{BDB} tables must have a primary key. This
will be fixed by having an automatic hidden auto_increment column for
the tables without a primary key.
@item
@code{LOCK TABLES} should work as for other @strong{MySQL} tables.
@item
@code{ALTER TABLE} doesn't yet work.
@item
@code{SHOW TABLE STATUS} doesn't yet provide that much information for BDB
tables.
@end itemize
@node Tutorial, Server, Table types, Top
@chapter MySQL Tutorial
@menu
* Connecting-disconnecting:: Connecting to and disconnecting from the server
* Entering queries:: Entering queries
* Examples:: Examples
* Searching on two keys:: Searching on two keys
* Database use:: Creating and using a database
* Getting information:: Getting information about databases and tables
* Batch mode:: Using @code{mysql} in batch mode
* Twin:: Queries from twin project
@end menu
This chapter provides a tutorial introduction to @strong{MySQL} by showing
how to use the @code{mysql} client program to create and use a simple
database. @code{mysql} (sometimes referred to as the ``terminal monitor'' or
just ``monitor'') is an interactive program that allows you to connect to a
@strong{MySQL} server, run queries and view the results. @code{mysql} may
also be used in batch mode: you place your queries in a file beforehand, then
tell @code{mysql} to execute the contents of the file. Both ways of using
@code{mysql} are covered here.
To see a list of options provided by @code{mysql}, invoke it with
the @code{--help} option:
@example
shell> mysql --help
@end example
This chapter assumes that @code{mysql} is installed on your machine, and that
a @strong{MySQL} server is available to which you can connect. If this is
not true, contact your @strong{MySQL} administrator. (If @emph{you} are the
administrator, you will need to consult other sections of this manual.)
The chapter describes the entire process of setting up and using a
database. If you are interested only in accessing an already-existing
database, you may want to skip over the sections that describe how to
create the database and the tables it contains.
Because this chapter is tutorial in nature, many details are necessarily left
out. Consult the relevant sections of the manual for more
information on the topics covered here.
@node Connecting-disconnecting, Entering queries, Tutorial, Tutorial
@section Connecting to and disconnecting from the server
To connect to the server, you'll usually need to provide a @strong{MySQL}
user name when you invoke @code{mysql} and, most likely, a password. If the
server runs on a machine other than the one where you log in, you'll also
need to specify a hostname. Contact your administrator to find out what
connection parameters you should use to connect (i.e., what host, user name
and password to use). Once you know the proper parameters, you should be
able to connect like this:
@example
shell> mysql -h host -u user -p
Enter password: ********
@end example
The @code{********} represents your password; enter it when @code{mysql}
displays the @code{Enter password:} prompt.
If that works, you should see some introductory information followed by a
@code{mysql>} prompt:
@example
shell> mysql -h host -u user -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 459 to server version: 3.22.20a-log
Type 'help' for help.
mysql>
@end example
The prompt tells you that @code{mysql} is ready for you to enter commands.
Some @strong{MySQL} installations allow users to connect as the ``anonymous''
(unnamed) user to the server running on the local host. If this is the case
on your machine, you should be able to connect to that server by invoking
@code{mysql} without any options:
@example
shell> mysql
@end example
After you have connected successfully, you can disconnect any time by typing
@code{QUIT} at the @code{mysql>} prompt:
@example
mysql> QUIT
Bye
@end example
You can also disconnect by typing control-D.
Most examples in the following sections assume you are connected to the
server. They indicate this by the @code{mysql>} prompt.
@node Entering queries, Examples, Connecting-disconnecting, Tutorial
@section Entering queries
Make sure you are connected to the server, as discussed in the previous
section. Doing so will not in itself select any database to work with, but
that's okay. At this point, it's more important to find out a little about
how to issue queries than to jump right in creating tables, loading data
into them and retrieving data from them. This section describes the basic
principles of entering commands, using several queries you can try out to
familiarize yourself with how @code{mysql} works.
Here's a simple command that asks the server to tell you its version number
and the current date. Type it in as shown below following the @code{mysql>}
prompt and hit the RETURN key:
@example
mysql> SELECT VERSION(), CURRENT_DATE;
+--------------+--------------+
| version() | CURRENT_DATE |
+--------------+--------------+
| 3.22.20a-log | 1999-03-19 |
+--------------+--------------+
1 row in set (0.01 sec)
mysql>
@end example
This query illustrates several things about @code{mysql}:
@itemize @bullet
@item
A command normally consists of a SQL statement followed by a semicolon.
(There are some exceptions where a semicolon is not needed. @code{QUIT},
mentioned earlier, is one of them. We'll get to others later.)
@item
When you issue a command, @code{mysql} sends it to the server for execution
and displays the results, then prints another @code{mysql>} to indicate
that it is ready for another command.
@item
@code{mysql} displays query output as a table (rows and columns). The first
row contains labels for the columns. The rows following are the query
results. Normally, column labels are the names of the columns you fetch from
database tables. If you're retrieving the value of an expression rather than
a table column (as in the example just shown), @code{mysql} labels the column
using the expression itself.
@item
@code{mysql} shows how many rows were returned, and how long the query took
to execute, which gives you a rough idea of server performance. These values
are imprecise because they represent wall clock time (not CPU or machine
time), and because they are affected by factors such as server load and
network latency. (For brevity, the ``rows in set'' line is not shown in
the remaining examples in this chapter.)
@end itemize
Keywords may be entered in any lettercase. The following queries are
equivalent:
@example
mysql> SELECT VERSION(), CURRENT_DATE;
mysql> select version(), current_date;
mysql> SeLeCt vErSiOn(), current_DATE;
@end example
Here's another query. It demonstrates that you can use @code{mysql} as a
simple calculator:
@example
mysql> SELECT SIN(PI()/4), (4+1)*5;
+-------------+---------+
| SIN(PI()/4) | (4+1)*5 |
+-------------+---------+
| 0.707107 | 25 |
+-------------+---------+
@end example
The commands shown thus far have been relatively short, single-line
statements. You can even enter multiple statements on a single line.
Just end each one with a semicolon:
@example
mysql> SELECT VERSION(); SELECT NOW();
+--------------+
| version() |
+--------------+
| 3.22.20a-log |
+--------------+
+---------------------+
| NOW() |
+---------------------+
| 1999-03-19 00:15:33 |
+---------------------+
@end example
A command need not be given all on a single line, so lengthy commands that
require several lines are not a problem. @code{mysql} determines where your
statement ends by looking for the terminating semicolon, not by looking for
the end of the input line. (In other words, @code{mysql}
accepts free-format input: it collects input lines but does not execute them
until it sees the semicolon.)
Here's a simple multiple-line statement:
@example
mysql> SELECT
-> USER()
-> ,
-> CURRENT_DATE;
+--------------------+--------------+
| USER() | CURRENT_DATE |
+--------------------+--------------+
| joesmith@@localhost | 1999-03-18 |
+--------------------+--------------+
@end example
In this example, notice how the prompt changes from @code{mysql>} to
@code{->} after you enter the first line of a multiple-line query. This is
how @code{mysql} indicates that it hasn't seen a complete statement and is
waiting for the rest. The prompt is your friend, because it provides
valuable feedback. If you use that feedback, you will always be aware of
what @code{mysql} is waiting for.
If you decide you don't want to execute a command that you are in the
process of entering, cancel it by typing @code{\c}:
@example
mysql> SELECT
-> USER()
-> \c
mysql>
@end example
Here, too, notice the prompt. It switches back to @code{mysql>} after you
type @code{\c}, providing feedback to indicate that @code{mysql} is ready
for a new command.
The following table shows each of the prompts you may see and summarizes what
they mean about the state that @code{mysql} is in:
@multitable @columnfractions .10 .9
@item @strong{Prompt} @tab @strong{Meaning}
@item @code{mysql>} @tab Ready for new command
@item @code{@ @ @ @ ->} @tab Waiting for next line of multiple-line command
@item @code{@ @ @ @ '>} @tab Waiting for next line, collecting a string that begins
with a single quote (@samp{'})
@item @code{@ @ @ @ ">} @tab Waiting for next line, collecting a string that begins
with a double quote (@samp{"})
@end multitable
Multiple-line statements commonly occur ``by accident'' when you intend to
issue a command on a single line, but forget the terminating semicolon. In
this case, @code{mysql} waits for more input:
@example
mysql> SELECT USER()
->
@end example
If this happens to you (you think you've entered a statement but the only
response is a @code{->} prompt), most likely @code{mysql} is waiting for the
semicolon. If you don't notice what the prompt is telling you, you might sit
there for a while before realizing what you need to do. Enter a semicolon to
complete the statement, and @code{mysql} will execute it:
@example
mysql> SELECT USER()
-> ;
+--------------------+
| USER() |
+--------------------+
| joesmith@@localhost |
+--------------------+
@end example
The @code{'>} and @code{">} prompts occur during string collection.
In @strong{MySQL}, you can write strings surrounded by either @samp{'}
or @samp{"} characters (for example, @code{'hello'} or @code{"goodbye"}),
and @code{mysql} lets you enter strings that span multiple lines. When you
see a @code{'>} or @code{">} prompt, it means that you've entered a line
containing a string that begins with a @samp{'} or @samp{"} quote character,
but have not yet entered the matching quote that terminates the string.
That's fine if you really are entering a multiple-line string, but how likely
is that? Not very. More often, the @code{'>} and @code{">} prompts indicate
that you've inadvertantly left out a quote character. For example:
@example
mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
">
@end example
If you enter this @code{SELECT} statement, then hit RETURN and wait for the
result, nothing will happen. Instead of wondering, ``why does this
query take so long?,'' notice the clue provided by the @code{">} prompt. It
tells you that @code{mysql} expects to see the rest of an unterminated
string. (Do you see the error in the statement? The string @code{"Smith} is
missing the second quote.)
At this point, what do you do? The simplest thing is to cancel the command.
However, you cannot just type @code{\c} in this case, because @code{mysql}
interprets it as part of the string that it is collecting! Instead, enter
the closing quote character (so @code{mysql} knows you've finished the
string), then type @code{\c}:
@example
mysql> SELECT * FROM my_table WHERE name = "Smith AND age < 30;
"> "\c
mysql>
@end example
The prompt changes back to @code{mysql>}, indicating that @code{mysql}
is ready for a new command.
It's important to know what the @code{'>} and @code{">} prompts signify,
because if you mistakenly enter an unterminated string, any further lines you
type will appear to be ignored by @code{mysql} --- including a line
containing @code{QUIT}! This can be quite confusing, especially if you
don't know that you need to supply the terminating quote before you can
cancel the current command.
@node Examples, Searching on two keys, Entering queries, Tutorial
@section Examples of common queries
Here follows examples of how to solve some common problems with
@strong{MySQL}.
Some of the examples use the table @code{shop} to hold the price of each
article (item number) for certain traders (dealers). Supposing that each
trader has a single fixed price per article, then (@code{item},
@code{trader}) is a primary key for the records.
You can create the example table as:
@example
CREATE TABLE shop (
article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
dealer CHAR(20) DEFAULT '' NOT NULL,
price DOUBLE(16,2) DEFAULT '0.00' NOT NULL,
PRIMARY KEY(article, dealer));
INSERT INTO shop VALUES
(1,'A',3.45),(1,'B',3.99),(2,'A',10.99),(3,'B',1.45),(3,'C',1.69),
(3,'D',1.25),(4,'D',19.95);
@end example
Okay, so the example data is:
@example
SELECT * FROM shop
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0001 | A | 3.45 |
| 0001 | B | 3.99 |
| 0002 | A | 10.99 |
| 0003 | B | 1.45 |
| 0003 | C | 1.69 |
| 0003 | D | 1.25 |
| 0004 | D | 19.95 |
+---------+--------+-------+
@end example
@menu
* example-Maximum-column:: The maximum value for a column
* example-Maximum-row:: The row holding the maximum of a certain column
* example-Maximum-column-group:: Maximum of column: per group: only the values
* example-Maximum-column-group-row:: The rows holding the group-wise maximum of a certain field
* example-Foreign keys:: Using foreign keys
@end menu
@node example-Maximum-column, example-Maximum-row, Examples, Examples
@subsection The maximum value for a column
``What's the highest item number?''
@example
SELECT MAX(article) AS article FROM shop
+---------+
| article |
+---------+
| 4 |
+---------+
@end example
@node example-Maximum-row, example-Maximum-column-group, example-Maximum-column, Examples
@subsection The row holding the maximum of a certain column
``Find number, dealer, and price of the most expensive article.''
In ANSI SQL this is easily done with a sub-query:
@example
SELECT article, dealer, price
FROM shop
WHERE price=(SELECT MAX(price) FROM shop)
@end example
In @strong{MySQL} (which does not yet have sub-selects), just do it in
two steps:
@enumerate
@item
Get the maximum price value from the table with a @code{SELECT} statement.
@item
Using this value compile the actual query:
@example
SELECT article, dealer, price
FROM shop
WHERE price=19.95
@end example
@end enumerate
Another solution is to sort all rows descending by price and only
get the first row using the @strong{MySQL} specific @code{LIMIT} clause:
@example
SELECT article, dealer, price
FROM shop
ORDER BY price DESC
LIMIT 1
@end example
@strong{Note}: If there are several most expensive articles (e.g. each 19.95)
the @code{LIMIT} solution shows only one of them!
@node example-Maximum-column-group, example-Maximum-column-group-row, example-Maximum-row, Examples
@subsection Maximum of column: per group: only the values
``What's the highest price per article?''
@example
SELECT article, MAX(price) AS price
FROM shop
GROUP BY article
+---------+-------+
| article | price |
+---------+-------+
| 0001 | 3.99 |
| 0002 | 10.99 |
| 0003 | 1.69 |
| 0004 | 19.95 |
+---------+-------+
@end example
@node example-Maximum-column-group-row, example-Foreign keys, example-Maximum-column-group, Examples
@subsection The rows holding the group-wise maximum of a certain field
``For each article, find the dealer(s) with the most expensive price.''
In ANSI SQL, I'd do it with a sub-query like this:
@example
SELECT article, dealer, price
FROM shop s1
WHERE price=(SELECT MAX(s2.price)
FROM shop s2
WHERE s1.article = s2.article)
@end example
In @strong{MySQL} it's best do it in several steps:
@enumerate
@item
Get the list of (article,maxprice). @xref{example-Maximum-column-group-row}.
@item
For each article get the corresponding rows which have the stored maximum
price.
@end enumerate
This can easily be done with a temporary table:
@example
CREATE TEMPORARY TABLE tmp (
article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL,
price DOUBLE(16,2) DEFAULT '0.00' NOT NULL);
LOCK TABLES article read;
INSERT INTO tmp SELECT article, MAX(price) FROM shop GROUP BY article;
SELECT article, dealer, price FROM shop, tmp
WHERE shop.article=tmp.article AND shop.price=tmp.price;
UNLOCK TABLES;
DROP TABLE tmp;
@end example
If you don't use a @code{TEMPORARY} table, you must also lock the 'tmp' table.
``Can it be done with a single query?''
Yes, but only by using a quite inefficient trick that I call the
``MAX-CONCAT trick'':
@example
SELECT article,
SUBSTRING( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 7) AS dealer,
0.00+LEFT( MAX( CONCAT(LPAD(price,6,'0'),dealer) ), 6) AS price
FROM shop
GROUP BY article;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0001 | B | 3.99 |
| 0002 | A | 10.99 |
| 0003 | C | 1.69 |
| 0004 | D | 19.95 |
+---------+--------+-------+
@end example
The last example can of course be made a bit more efficient by doing the
splitting of the concatenated column in the client.
@node example-Foreign keys, , example-Maximum-column-group-row, Examples
@subsection Using foreign keys
You don't need foreign keys to join 2 tables.
The only thing @strong{MySQL} doesn't do is @code{CHECK} to make sure that
the keys you use really exist in the table(s) you're referencing and it
doesn't automatically delete rows from table with a foreign key
definition. If you use your keys like normal, it'll work just fine!
@example
CREATE TABLE persons (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
name CHAR(60) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE shirts (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
owner SMALLINT UNSIGNED NOT NULL REFERENCES persons,
PRIMARY KEY (id)
);
INSERT INTO persons VALUES (NULL, 'Antonio Paz');
INSERT INTO shirts VALUES
(NULL, 'polo', 'blue', LAST_INSERT_ID()),
(NULL, 'dress', 'white', LAST_INSERT_ID()),
(NULL, 't-shirt', 'blue', LAST_INSERT_ID());
INSERT INTO persons VALUES (NULL, 'Lilliana Angelovska');
INSERT INTO shirts VALUES
(NULL, 'dress', 'orange', LAST_INSERT_ID()),
(NULL, 'polo', 'red', LAST_INSERT_ID()),
(NULL, 'dress', 'blue', LAST_INSERT_ID()),
(NULL, 't-shirt', 'white', LAST_INSERT_ID());
SELECT * FROM persons;
+----+---------------------+
| id | name |
+----+---------------------+
| 1 | Antonio Paz |
| 2 | Lilliana Angelovska |
+----+---------------------+
SELECT * FROM shirts;
+----+---------+--------+-------+
| id | style | color | owner |
+----+---------+--------+-------+
| 1 | polo | blue | 1 |
| 2 | dress | white | 1 |
| 3 | t-shirt | blue | 1 |
| 4 | dress | orange | 2 |
| 5 | polo | red | 2 |
| 6 | dress | blue | 2 |
| 7 | t-shirt | white | 2 |
+----+---------+--------+-------+
SELECT s.* FROM persons p, shirts s
WHERE p.name LIKE 'Lilliana%'
AND s.owner = p.id
AND s.color <> 'white';
+----+-------+--------+-------+
| id | style | color | owner |
+----+-------+--------+-------+
| 4 | dress | orange | 2 |
| 5 | polo | red | 2 |
| 6 | dress | blue | 2 |
+----+-------+--------+-------+
@end example
@findex UNION
@node Searching on two keys, Database use, Examples, Tutorial
@section Searching on two keys
@strong{MySQL} doesn't yet optimize when you search on two different
keys combined with @code{OR} (Searching on one key with different @code{OR}
parts is optimized quite good):
@example
SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1'
OR field2_index = '1'
@end example
The reason is that we haven't yet had time to come up with an efficient
way to handle this in the general case. (The @code{AND} handling is
in comparison now completely general and works very well).
For the moment you can solve this very efficently by using a
@code{TEMPORARY} table; This type of optimization is also very good if
you are using very complicated queries where the SQL server does the
optimizations in the wrong order.
@example
CREATE TEMPORARY TABLE tmp
SELECT field1_index, field2_index FROM test_table WHERE field1_index = '1';
INSERT INTO tmp
SELECT field1_index, field2_index FROM test_table WHERE field2_index = '1';
SELECT * from tmp;
DROP TABLE tmp;
@end example
The above way to solve this query is in effect an @code{UNION} of two queries.
@node Database use, Getting information, Searching on two keys, Tutorial
@section Creating and using a database
@menu
* Creating database:: Creating a database
* Creating tables:: Creating a table
* Loading tables:: Loading data into a table
* Retrieving data:: Retrieving information from a table
* Multiple tables:: Using more than one table
@end menu
Now that you know how to enter commands, it's time to access a database.
Suppose you have several pets in your home (your ``menagerie'') and you'd
like to keep track of various types of information about them. You can do so
by creating tables to hold your data and loading them with the desired
information. Then you can answer different sorts of questions about your
animals by retrieving data from the tables. This section shows how to do
all that:
@itemize @bullet
@item
How to create a database
@item
How to create a table
@item
How to load data into the table
@item
How to retrieve data from the table in various ways
@item
How to use multiple tables
@end itemize
The menagerie database will be simple (deliberately), but it is not difficult
to think of real-world situations in which a similar type of database might
be used. For example, a database like this could be used by a farmer to keep
track of livestock, or by a veterinarian to keep track of patient records.
Use the @code{SHOW} statement to find out what databases currently exist
on the server:
@example
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| mysql |
| test |
| tmp |
+----------+
@end example
The list of databases is probably different on your machine, but the
@code{mysql} and @code{test} databases are likely to be among them. The
@code{mysql} database is required because it describes user access
privileges. The @code{test} database is often provided as a workspace for
users to try things out.
If the @code{test} database exists, try to access it:
@example
mysql> USE test
Database changed
@end example
Note that @code{USE}, like @code{QUIT}, does not require a semicolon. (You
can terminate such statements with a semicolon if you like; it does no harm.)
The @code{USE} statement is special in another way, too: it must be given on
a single line.
You can use the @code{test} database (if you have access to it) for the
examples that follow, but anything you create in that database can be
removed by anyone else with access to it. For this reason, you should
probably ask your @strong{MySQL} administrator for permission to use a
database of your own. Suppose you want to call yours @code{menagerie}. The
administrator needs to execute a command like this:
@example
mysql> GRANT ALL ON menagerie.* TO your_mysql_name;
@end example
where @code{your_mysql_name} is the @strong{MySQL} user name assigned to
you.
@node Creating database, Creating tables, Database use, Database use
@subsection Creating and selecting a database
If the administrator creates your database for you when setting up your
permissions, you can begin using it. Otherwise, you need to create it
yourself:
@example
mysql> CREATE DATABASE menagerie;
@end example
Under Unix, database names are case sensitive (unlike SQL keywords), so you
must always refer to your database as @code{menagerie}, not as
@code{Menagerie}, @code{MENAGERIE} or some other variant. This is also true
for table names. (Under Windows, this restriction does not apply, although
you must refer to databases and tables using the same lettercase throughout a
given query.)
Creating a database does not select it for use, you must do that explicitly.
To make @code{menagerie} the current database, use this command:
@example
mysql> USE menagerie
Database changed
@end example
Your database needs to be created only once, but you must select it for use
each time you begin a @code{mysql} session. You can do this by issuing a
@code{USE} statement as shown above. Alternatively, you can select the
database on the command line when you invoke @code{mysql}. Just specify its
name after any connection parameters that you might need to provide. For
example:
@example
shell> mysql -h host -u user -p menagerie
Enter password: ********
@end example
Note that @code{menagerie} is not your password on the command just shown.
If you want to supply your password on the command line after the @code{-p}
option, you must do so with no intervening space (e.g., as
@code{-pmypassword}, not as @code{-p mypassword}). However, putting your
password on the command line is not recommended, because doing so exposes it
to snooping by other users logged in on your machine.
@node Creating tables, Loading tables, Creating database, Database use
@subsection Creating a table
Creating the database is the easy part, but at this point it's empty, as
@code{SHOW TABLES} will tell you:
@example
mysql> SHOW TABLES;
Empty set (0.00 sec)
@end example
The harder part is deciding what the structure of your database should be:
what tables you will need, and what columns will be in each of them.
You'll want a table that contains a record for each of your pets. This can
be called the @code{pet} table, and it should contain, as a bare minimum,
each animal's name. Because the name by itself is not very interesting, the
table should contain other information. For example, if more than one person
in your family keeps pets, you might want to list each animal's owner. You
might also want to record some basic descriptive information such as species
and sex.
How about age? That might be of interest, but it's not a good thing to store
in a database. Age changes as time passes, which means you'd have to update
your records often. Instead, it's better to store a fixed value such as
date of birth. Then, whenever you need age, you can calculate it as the
difference between the current date and the birth date. @strong{MySQL}
provides functions for doing date arithmetic, so this is not difficult.
Storing birth date rather than age has other advantages, too:
@itemize @bullet
@item
You can use the database for tasks such as generating reminders for upcoming
pet birthdays. (If you think this type of query is somewhat silly, note that
it is the same question you might ask in the context of a business database
to identify clients to whom you'll soon need to send out birthday greetings,
for that computer-assisted personal touch.)
@item
You can calculate age in relation to dates other than the current date. For
example, if you store death date in the database, you can easily calculate
how old a pet was when it died.
@end itemize
You can probably think of other types of information that would be useful in
the @code{pet} table, but the ones identified so far are sufficient for now:
name, owner, species, sex, birth and death.
Use a @code{CREATE TABLE} statement to specify the layout of your table:
@example
mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);
@end example
@code{VARCHAR} is a good choice for the @code{name}, @code{owner} and
@code{species} columns because the column values will vary in length. The
lengths of those columns need not all be the same, and need not be
@code{20}. You can pick any length from @code{1} to @code{255}, whatever
seems most reasonable to you. (If you make a poor choice and it turns
out later that you need a longer field, @strong{MySQL} provides an
@code{ALTER TABLE} statement.)
Animal sex can be represented in a variety of ways, for example, @code{"m"}
and @code{"f"}, or perhaps @code{"male"} and @code{"female"}. It's simplest
to use the single characters @code{"m"} and @code{"f"}.
The use of the @code{DATE} data type for the @code{birth} and @code{death}
columns is a fairly obvious choice.
Now that you have created a table, @code{SHOW TABLES} should produce some
output:
@example
mysql> SHOW TABLES;
+---------------------+
| Tables in menagerie |
+---------------------+
| pet |
+---------------------+
@end example
To verify that your table was created the way you expected, use
a @code{DESCRIBE} statement:
@example
mysql> DESCRIBE pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
@end example
You can use @code{DESCRIBE} any time, for example, if you forget the names of
the columns in your table or what types they are.
@node Loading tables, Retrieving data, Creating tables, Database use
@subsection Loading data into a table
After creating your table, you need to populate it. The @code{LOAD DATA} and
@code{INSERT} statements are useful for this.
Suppose your pet records can be described as shown below.
(Observe that @strong{MySQL} expects dates in @code{YYYY-MM-DD} format;
this may be different than what you are used to.)
@multitable @columnfractions .16 .16 .16 .16 .16 .16
@item @strong{name} @tab @strong{owner} @tab @strong{species} @tab @strong{sex} @tab @strong{birth} @tab @strong{death}
@item Fluffy @tab Harold @tab cat @tab f @tab 1993-02-04 @tab
@item Claws @tab Gwen @tab cat @tab m @tab 1994-03-17 @tab
@item Buffy @tab Harold @tab dog @tab f @tab 1989-05-13 @tab
@item Fang @tab Benny @tab dog @tab m @tab 1990-08-27 @tab
@item Bowser @tab Diane @tab dog @tab m @tab 1998-08-31 @tab 1995-07-29
@item Chirpy @tab Gwen @tab bird @tab f @tab 1998-09-11 @tab
@item Whistler @tab Gwen @tab bird @tab @tab 1997-12-09 @tab
@item Slim @tab Benny @tab snake @tab m @tab 1996-04-29 @tab
@end multitable
Because you are beginning with an empty table, an easy way to populate it is to
create a text file containing a row for each of your animals, then load the
contents of the file into the table with a single statement.
You could create a text file @file{pet.txt} containing one record per line,
with values separated by tabs, and given in the order in which the columns
were listed in the @code{CREATE TABLE} statement. For missing values (such
as unknown sexes, or death dates for animals that are still living), you can
use @code{NULL} values. To represent these in your text file, use
@code{\N}. For example, the record for Whistler the bird would look like
this (where the whitespace between values is a single tab character):
@multitable @columnfractions .15 .15 .15 .15 .25 .15
@item @code{Whistler} @tab @code{Gwen} @tab @code{bird} @tab @code{\N} @tab @code{1997-12-09} @tab @code{\N}
@end multitable
To load the text file @file{pet.txt} into the @code{pet} table, use this
command:
@example
mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
@end example
You can specify the column value separator and end of line marker explicitly
in the @code{LOAD DATA} statement if you wish, but the defaults are tab and
linefeed. These are sufficient for the statement to read the file
@file{pet.txt} properly.
When you want to add new records one at a time, the @code{INSERT} statement
is useful. In its simplest form, you supply values for each column, in the
order in which the columns were listed in the @code{CREATE TABLE} statement.
Suppose Diane gets a new hamster named Puffball. You could add a new record
using an @code{INSERT} statement like this:
@example
mysql> INSERT INTO pet
-> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
@end example
Note that string and date values are specified as quoted strings here. Also,
with @code{INSERT}, you can insert @code{NULL} directly to represent a
missing value. You do not use @code{\N} like you do with @code{LOAD DATA}.
From this example, you should be able to see that there would be a lot more
typing involved to load
your records initially using several @code{INSERT} statements rather
than a single @code{LOAD DATA} statement.
@node Retrieving data, Multiple tables, Loading tables, Database use
@subsection Retrieving information from a table
@menu
* Selecting all:: Selecting all data
* Selecting rows:: Selecting particular rows
* Selecting columns:: Selecting particular columns
* Sorting rows:: Sorting rows
* Date calculations:: Date calculations
* Working with NULL:: Working with @code{NULL} values
* Pattern matching:: Pattern matching
* Counting rows:: Counting rows
@end menu
The @code{SELECT} statement is used to pull information from a table.
The general form of the statement is:
@example
SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy
@end example
@code{what_to_select} indicates what you want to see. This can be a list of
columns, or @code{*} to indicate ``all columns.'' @code{which_table}
indicates the table from which you want to retrieve data. The @code{WHERE}
clause is optional. If it's present, @code{conditions_to_satisfy} specifies
conditions that rows must satisfy to qualify for retrieval.
@node Selecting all, Selecting rows, Retrieving data, Retrieving data
@subsubsection Selecting all data
The simplest form of @code{SELECT} retrieves everything from a table:
@example
mysql> SELECT * FROM pet;
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1998-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+--------+---------+------+------------+------------+
@end example
This form of @code{SELECT} is useful if you want to review your entire table,
for instance, after you've just loaded it with your initial dataset. As it
happens, the output just shown reveals an error in your data file: Bowser
appears to have been born after he died! Consulting your original pedigree
papers, you find that the correct birth year is 1989, not 1998.
There are are least a couple of ways to fix this:
@itemize @bullet
@item
Edit the file @file{pet.txt} to correct the error, then empty the table
and reload it using @code{DELETE} and @code{LOAD DATA}:
@example
mysql> SET AUTOCOMMIT=1; # Used for quick recreate of the table
mysql> DELETE FROM pet;
mysql> LOAD DATA LOCAL INFILE "pet.txt" INTO TABLE pet;
@end example
However, if you do this, you must also re-enter the record for Puffball.
@item
Fix only the erroneous record with an @code{UPDATE} statement:
@example
mysql> UPDATE pet SET birth = "1989-08-31" WHERE name = "Bowser";
@end example
@end itemize
As shown above, it is easy to retrieve an entire table. But typically you
don't want to do that, particularly when the table becomes large. Instead,
you're usually more interested in answering a particular question, in which
case you specify some constraints on the information you want. Let's look at
some selection queries in terms of questions about your pets that they
answer.
@node Selecting rows, Selecting columns, Selecting all, Retrieving data
@subsubsection Selecting particular rows
You can select only particular rows from your table. For example, if you want
to verify the change that you made to Bowser's birth date, select Bowser's
record like this:
@example
mysql> SELECT * FROM pet WHERE name = "Bowser";
+--------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+-------+---------+------+------------+------------+
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
+--------+-------+---------+------+------------+------------+
@end example
The output confirms that the year is correctly recorded now as 1989, not 1998.
String comparisons are normally case-insensitive, so you can specify the
name as @code{"bowser"}, @code{"BOWSER"}, etc. The query result will be
the same.
You can specify conditions on any column, not just @code{name}. For example,
if you want to know which animals were born after 1998, test the @code{birth}
column:
@example
mysql> SELECT * FROM pet WHERE birth >= "1998-1-1";
+----------+-------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+----------+-------+---------+------+------------+-------+
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+-------+---------+------+------------+-------+
@end example
You can combine conditions, for example, to locate female dogs:
@example
mysql> SELECT * FROM pet WHERE species = "dog" AND sex = "f";
+-------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+-------+--------+---------+------+------------+-------+
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+-------+--------+---------+------+------------+-------+
@end example
The preceding query uses the @code{AND} logical operator. There is also an
@code{OR} operator:
@example
mysql> SELECT * FROM pet WHERE species = "snake" OR species = "bird";
+----------+-------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+----------+-------+---------+------+------------+-------+
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
+----------+-------+---------+------+------------+-------+
@end example
@code{AND} and @code{OR} may be intermixed. If you do that, it's a good idea
to use parentheses to indicate how conditions should be grouped:
@example
mysql> SELECT * FROM pet WHERE (species = "cat" AND sex = "m")
-> OR (species = "dog" AND sex = "f");
+-------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+-------+--------+---------+------+------------+-------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+-------+--------+---------+------+------------+-------+
@end example
@node Selecting columns, Sorting rows, Selecting rows, Retrieving data
@subsubsection Selecting particular columns
If you don't want to see entire rows from your table, just name the columns
in which you're interested, separated by commas. For example, if you want to
know when your animals were born, select the @code{name} and @code{birth}
columns:
@example
mysql> SELECT name, birth FROM pet;
+----------+------------+
| name | birth |
+----------+------------+
| Fluffy | 1993-02-04 |
| Claws | 1994-03-17 |
| Buffy | 1989-05-13 |
| Fang | 1990-08-27 |
| Bowser | 1989-08-31 |
| Chirpy | 1998-09-11 |
| Whistler | 1997-12-09 |
| Slim | 1996-04-29 |
| Puffball | 1999-03-30 |
+----------+------------+
@end example
To find out who owns pets, use this query:
@example
mysql> SELECT owner FROM pet;
+--------+
| owner |
+--------+
| Harold |
| Gwen |
| Harold |
| Benny |
| Diane |
| Gwen |
| Gwen |
| Benny |
| Diane |
+--------+
@end example
@findex DISTINCT
However, notice that the query simply retrieves the @code{owner} field from
each record, and some of them appear more than once. To minimize the output,
retrieve each unique output record just once by adding the keyword
@code{DISTINCT}:
@example
mysql> SELECT DISTINCT owner FROM pet;
+--------+
| owner |
+--------+
| Benny |
| Diane |
| Gwen |
| Harold |
+--------+
@end example
You can use a @code{WHERE} clause to combine row selection with column
selection. For example, to get birth dates for dogs and cats only,
use this query:
@example
mysql> SELECT name, species, birth FROM pet
-> WHERE species = "dog" OR species = "cat";
+--------+---------+------------+
| name | species | birth |
+--------+---------+------------+
| Fluffy | cat | 1993-02-04 |
| Claws | cat | 1994-03-17 |
| Buffy | dog | 1989-05-13 |
| Fang | dog | 1990-08-27 |
| Bowser | dog | 1989-08-31 |
+--------+---------+------------+
@end example
@node Sorting rows, Date calculations, Selecting columns, Retrieving data
@subsubsection Sorting rows
You may have noticed in the preceding examples that the result rows are
displayed in no particular order. However, it's often easier to examine
query output when the rows are sorted in some meaningful way. To sort a
result, use an @code{ORDER BY} clause.
Here are animal birthdays, sorted by date:
@example
mysql> SELECT name, birth FROM pet ORDER BY birth;
+----------+------------+
| name | birth |
+----------+------------+
| Buffy | 1989-05-13 |
| Bowser | 1989-08-31 |
| Fang | 1990-08-27 |
| Fluffy | 1993-02-04 |
| Claws | 1994-03-17 |
| Slim | 1996-04-29 |
| Whistler | 1997-12-09 |
| Chirpy | 1998-09-11 |
| Puffball | 1999-03-30 |
+----------+------------+
@end example
To sort in reverse order, add the @code{DESC} (descending) keyword to the
name of the column you are sorting by:
@example
mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
+----------+------------+
| name | birth |
+----------+------------+
| Puffball | 1999-03-30 |
| Chirpy | 1998-09-11 |
| Whistler | 1997-12-09 |
| Slim | 1996-04-29 |
| Claws | 1994-03-17 |
| Fluffy | 1993-02-04 |
| Fang | 1990-08-27 |
| Bowser | 1989-08-31 |
| Buffy | 1989-05-13 |
+----------+------------+
@end example
You can sort on multiple columns. For example, to sort by type of
animal, then by birth date within animal type with youngest animals first,
use the following query:
@example
mysql> SELECT name, species, birth FROM pet ORDER BY species, birth DESC;
+----------+---------+------------+
| name | species | birth |
+----------+---------+------------+
| Chirpy | bird | 1998-09-11 |
| Whistler | bird | 1997-12-09 |
| Claws | cat | 1994-03-17 |
| Fluffy | cat | 1993-02-04 |
| Fang | dog | 1990-08-27 |
| Bowser | dog | 1989-08-31 |
| Buffy | dog | 1989-05-13 |
| Puffball | hamster | 1999-03-30 |
| Slim | snake | 1996-04-29 |
+----------+---------+------------+
@end example
Note that the @code{DESC} keyword applies only to the column name immediately
preceding it (@code{birth}); @code{species} values are still sorted in
ascending order.
@node Date calculations, Working with NULL, Sorting rows, Retrieving data
@subsubsection Date calculations
@strong{MySQL} provides several functions that you can use to perform
calculations on dates, for example, to calculate ages or extract
parts of dates.
To determine how many years old each of your pets is, compute age as the
difference between the birth date and the current date. Do this by
converting the two dates to days, take the difference, and divide by 365 (the
number of days in a year):
@example
mysql> SELECT name, (TO_DAYS(NOW())-TO_DAYS(birth))/365 FROM pet;
+----------+-------------------------------------+
| name | (TO_DAYS(NOW())-TO_DAYS(birth))/365 |
+----------+-------------------------------------+
| Fluffy | 6.15 |
| Claws | 5.04 |
| Buffy | 9.88 |
| Fang | 8.59 |
| Bowser | 9.58 |
| Chirpy | 0.55 |
| Whistler | 1.30 |
| Slim | 2.92 |
| Puffball | 0.00 |
+----------+-------------------------------------+
@end example
Although the query works, there are some things about it that could be
improved. First, the result could be scanned more easily if the rows were
presented in some order. Second, the heading for the age column isn't very
meaningful.
The first problem can be handled by adding an @code{ORDER BY name} clause to
sort the output by name. To deal with the column heading, provide a name for
the column so that a different label appears in the output (this is called a
column alias):
@example
mysql> SELECT name, (TO_DAYS(NOW())-TO_DAYS(birth))/365 AS age
-> FROM pet ORDER BY name;
+----------+------+
| name | age |
+----------+------+
| Bowser | 9.58 |
| Buffy | 9.88 |
| Chirpy | 0.55 |
| Claws | 5.04 |
| Fang | 8.59 |
| Fluffy | 6.15 |
| Puffball | 0.00 |
| Slim | 2.92 |
| Whistler | 1.30 |
+----------+------+
@end example
To sort the output by @code{age} rather than @code{name}, just use a
different @code{ORDER BY} clause:
@example
mysql> SELECT name, (TO_DAYS(NOW())-TO_DAYS(birth))/365 AS age
-> FROM pet ORDER BY age;
+----------+------+
| name | age |
+----------+------+
| Puffball | 0.00 |
| Chirpy | 0.55 |
| Whistler | 1.30 |
| Slim | 2.92 |
| Claws | 5.04 |
| Fluffy | 6.15 |
| Fang | 8.59 |
| Bowser | 9.58 |
| Buffy | 9.88 |
+----------+------+
@end example
A similar query can be used to determine age at death for animals that have
died. You determine which animals these are by checking whether or not the
@code{death} value is @code{NULL}. Then, for those with non-@code{NULL}
values, compute the difference between the @code{death} and @code{birth}
values:
@example
mysql> SELECT name, birth, death, (TO_DAYS(death)-TO_DAYS(birth))/365 AS age
-> FROM pet WHERE death IS NOT NULL ORDER BY age;
+--------+------------+------------+------+
| name | birth | death | age |
+--------+------------+------------+------+
| Bowser | 1989-08-31 | 1995-07-29 | 5.91 |
+--------+------------+------------+------+
@end example
The query uses @code{death IS NOT NULL} rather than @code{death != NULL}
because @code{NULL} is a special value. This is explained later.
@xref{Working with NULL, , Working with @code{NULL}}.
What if you want to know which animals have birthdays next month? For this
type of calculation, year and day are irrelevant, you simply want to extract
the month part of the @code{birth} column. @strong{MySQL} provides several
date-part extraction functions, such as @code{YEAR()}, @code{MONTH()} and
@code{DAYOFMONTH()}. @code{MONTH()} is the appropriate function here. To
see how it works, run a simple query that displays the value of both
@code{birth} and @code{MONTH(birth)}:
@example
mysql> SELECT name, birth, MONTH(birth) FROM pet;
+----------+------------+--------------+
| name | birth | MONTH(birth) |
+----------+------------+--------------+
| Fluffy | 1993-02-04 | 2 |
| Claws | 1994-03-17 | 3 |
| Buffy | 1989-05-13 | 5 |
| Fang | 1990-08-27 | 8 |
| Bowser | 1989-08-31 | 8 |
| Chirpy | 1998-09-11 | 9 |
| Whistler | 1997-12-09 | 12 |
| Slim | 1996-04-29 | 4 |
| Puffball | 1999-03-30 | 3 |
+----------+------------+--------------+
@end example
Finding animals with birthdays in the upcoming month is easy, too. Suppose
the current month is April. Then the month value is @code{4} and you look
for animals born in May (month 5) like this:
@example
mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5;
+-------+------------+
| name | birth |
+-------+------------+
| Buffy | 1989-05-13 |
+-------+------------+
@end example
There is a small complication if the current month is December, of course.
You don't just add one to the month number (@code{12}) and look for animals
born in month 13, because there is no such month. Instead, you look for
animals born in January (month 1).
You can even write the query so that it works no matter what the current
month is. That way you don't have to use a particular month number
in the query. @code{DATE_ADD()} allows you to add a time interval to a
given date. If you add a month to the value of @code{NOW()}, then extract
the month part with @code{MONTH()}, the result produces the month in which to
look for birthdays:
@example
mysql> SELECT name, birth FROM pet
-> WHERE MONTH(birth) = MONTH(DATE_ADD(NOW(), INTERVAL 1 MONTH));
@end example
A different way to accomplish the same task is to add @code{1} to get the
next month after the current one (after using the modulo function (@code{MOD})
to ``wrap around'' the month value to @code{0} if it is currently
@code{12}):
@example
mysql> SELECT name, birth FROM pet
-> WHERE MONTH(birth) = MOD(MONTH(NOW()), 12) + 1;
@end example
Note that @code{MONTH} return a number between 1 and 12. And
@code{MOD(something,12)} returns a number between 0 and 11. So the
addition has to be after the @code{MOD()} oterwise we would go from
November (11) to January (1).
@node Working with NULL, Pattern matching, Date calculations, Retrieving data
@subsubsection Working with @code{NULL} values
The @code{NULL} value can be surprising until you get used to it.
Conceptually, @code{NULL} means ``missing value'' or ``unknown value'' and it
is treated somewhat differently than other values. To test for @code{NULL},
you cannot use the arithmetic comparison operators such as @code{=}, @code{<}
or @code{!=}. To demonstrate this for yourself, try the following query:
@example
mysql> SELECT 1 = NULL, 1 != NULL, 1 < NULL, 1 > NULL;
+----------+-----------+----------+----------+
| 1 = NULL | 1 != NULL | 1 < NULL | 1 > NULL |
+----------+-----------+----------+----------+
| NULL | NULL | NULL | NULL |
+----------+-----------+----------+----------+
@end example
Clearly you get no meaningful results from these comparisons. Use
the @code{IS NULL} and @code{IS NOT NULL} operators instead:
@example
mysql> SELECT 1 IS NULL, 1 IS NOT NULL;
+-----------+---------------+
| 1 IS NULL | 1 IS NOT NULL |
+-----------+---------------+
| 0 | 1 |
+-----------+---------------+
@end example
In @strong{MySQL}, 0 means false and 1 means true.
This special treatment of @code{NULL} is why, in the previous section, it
was necessary to determine which animals are no longer alive using
@code{death IS NOT NULL} instead of @code{death != NULL}.
@node Pattern matching, Counting rows, Working with NULL, Retrieving data
@subsubsection Pattern matching
@strong{MySQL} provides standard SQL pattern matching as well as a form of
pattern matching based on extended regular expressions similar to those used
by Unix utilities such as @code{vi}, @code{grep} and @code{sed}.
SQL pattern matching allows you to use @samp{_} to match any single
character, and @samp{%} to match an arbitrary number of characters (including
zero characters). In @strong{MySQL}, SQL patterns are case insensitive by
default. Some examples are shown below. Note that you do not use @code{=}
or @code{!=} when you use SQL patterns; use the @code{LIKE} or @code{NOT
LIKE} comparison operators instead.
To find names beginning with @samp{b}:
@example
mysql> SELECT * FROM pet WHERE name LIKE "b%";
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
+--------+--------+---------+------+------------+------------+
@end example
To find names ending with @samp{fy}:
@example
mysql> SELECT * FROM pet WHERE name LIKE "%fy";
+--------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+-------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+--------+--------+---------+------+------------+-------+
@end example
To find names containing a @samp{w}:
@example
mysql> SELECT * FROM pet WHERE name LIKE "%w%";
+----------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+-------+---------+------+------------+------------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
+----------+-------+---------+------+------------+------------+
@end example
To find names containing exactly five characters, use the @samp{_} pattern
character:
@example
mysql> SELECT * FROM pet WHERE name LIKE "_____";
+-------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+-------+--------+---------+------+------------+-------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+-------+--------+---------+------+------------+-------+
@end example
The other type of pattern matching provided by @strong{MySQL} uses extended
regular expressions. When you test for a match for this type of pattern, use
the @code{REGEXP} and @code{NOT REGEXP} operators (or @code{RLIKE} and
@code{NOT RLIKE}, which are synonyms).
Some characteristics of extended regular expressions are:
@itemize @bullet
@item
@samp{.} matches any single character.
@item
A character class @samp{[...]} matches any character within the brackets.
For example, @samp{[abc]} matches @samp{a}, @samp{b} or @samp{c}. To name a
range of characters, use a dash. @samp{[a-z]} matches any lowercase letter,
whereas @samp{[0-9]} matches any digit.
@item
@samp{*} matches zero or more instances of the thing preceding it. For
example, @samp{x*} matches any number of @samp{x} characters,
@samp{[0-9]*} matches any number of digits, and @samp{.*} matches any
number of anything.
@item
Regular expressions are case sensitive, but you can use a character class to
match both lettercases if you wish. For example, @samp{[aA]} matches
lowercase or uppercase @samp{a} and @samp{[a-zA-Z]} matches any letter in
either case.
@item
The pattern matches if it occurs anywhere in the value being tested
(SQL patterns match only if they match the entire value).
@item
To anchor a pattern so that it must match the beginning or end of the value
being tested, use @samp{^} at the beginning or @samp{$} at the end of the
pattern.
@end itemize
To demonstrate how extended regular expressions work, the @code{LIKE} queries
shown above are rewritten below to use @code{REGEXP}:
To find names beginning with @samp{b}, use @samp{^} to match the beginning of
the name and @samp{[bB]} to match either lowercase or uppercase @samp{b}:
@example
mysql> SELECT * FROM pet WHERE name REGEXP "^[bB]";
+--------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+------------+
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
+--------+--------+---------+------+------------+------------+
@end example
To find names ending with @samp{fy}, use @samp{$} to match the end of the
name:
@example
mysql> SELECT * FROM pet WHERE name REGEXP "fy$";
+--------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+--------+--------+---------+------+------------+-------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+--------+--------+---------+------+------------+-------+
@end example
To find names containing a @samp{w}, use
@samp{[wW]} to match either lowercase or uppercase @samp{w}:
@example
mysql> SELECT * FROM pet WHERE name REGEXP "[wW]";
+----------+-------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+-------+---------+------+------------+------------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Bowser | Diane | dog | m | 1989-08-31 | 1995-07-29 |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
+----------+-------+---------+------+------------+------------+
@end example
Because a regular expression pattern matches if it occurs anywhere in the
value, it is not necessary in the previous query to put a wildcard on either
side of the pattern to get it to match the entire value like it would be if
you used a SQL pattern.
To find names containing exactly five characters, use @samp{^} and @samp{$}
to match the beginning and end of the name, and five instances of @samp{.}
in between:
@example
mysql> SELECT * FROM pet WHERE name REGEXP "^.....$";
+-------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+-------+--------+---------+------+------------+-------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+-------+--------+---------+------+------------+-------+
@end example
You could also write the previous query using the @samp{@{n@}}
``repeat-@code{n}-times'' operator:
@example
mysql> SELECT * FROM pet WHERE name REGEXP "^.@{5@}$";
+-------+--------+---------+------+------------+-------+
| name | owner | species | sex | birth | death |
+-------+--------+---------+------+------------+-------+
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
+-------+--------+---------+------+------------+-------+
@end example
@node Counting rows, , Pattern matching, Retrieving data
@subsubsection Counting rows
Databases are often used to answer the question, ``How often does a certain
type of data occur in a table?'' For example, you might want to know how
many pets you have, or how many pets each owner has, or you might want to
perform various kinds of censuses on your animals.
Counting the total number of animals you have is the same question as ``How
many rows are in the @code{pet} table?,'' because there is one record per pet.
The @code{COUNT()} function counts the number of non-@code{NULL} results, so
the query to count your animals looks like this:
@example
mysql> SELECT COUNT(*) FROM pet;
+----------+
| COUNT(*) |
+----------+
| 9 |
+----------+
@end example
Earlier, you retrieved the names of the people who owned pets. You can
use @code{COUNT()} if you want to find out how many pets each owner has:
@example
mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
+--------+----------+
| owner | COUNT(*) |
+--------+----------+
| Benny | 2 |
| Diane | 2 |
| Gwen | 3 |
| Harold | 2 |
+--------+----------+
@end example
Note the use of @code{GROUP BY} to group together all records for each
@code{owner}. Without it, all you get is an error message:
@example
mysql> SELECT owner, COUNT(owner) FROM pet;
ERROR 1140 at line 1: Mixing of GROUP columns (MIN(),MAX(),COUNT()...)
with no GROUP columns is illegal if there is no GROUP BY clause
@end example
@code{COUNT()} and @code{GROUP BY} are useful for characterizing your
data in various ways. The following examples show different ways to
perform animal census operations.
Number of animals per species:
@example
mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
+---------+----------+
| species | COUNT(*) |
+---------+----------+
| bird | 2 |
| cat | 2 |
| dog | 3 |
| hamster | 1 |
| snake | 1 |
+---------+----------+
@end example
Number of animals per sex:
@example
mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
+------+----------+
| sex | COUNT(*) |
+------+----------+
| NULL | 1 |
| f | 4 |
| m | 4 |
+------+----------+
@end example
(In this output, @code{NULL} indicates ``sex unknown.'')
Number of animals per combination of species and sex:
@example
mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
+---------+------+----------+
| species | sex | COUNT(*) |
+---------+------+----------+
| bird | NULL | 1 |
| bird | f | 1 |
| cat | f | 1 |
| cat | m | 1 |
| dog | f | 1 |
| dog | m | 2 |
| hamster | f | 1 |
| snake | m | 1 |
+---------+------+----------+
@end example
You need not retrieve an entire table when you use @code{COUNT()}. For
example, the previous query, when performed just on dogs and cats, looks like
this:
@example
mysql> SELECT species, sex, COUNT(*) FROM pet
-> WHERE species = "dog" OR species = "cat"
-> GROUP BY species, sex;
+---------+------+----------+
| species | sex | COUNT(*) |
+---------+------+----------+
| cat | f | 1 |
| cat | m | 1 |
| dog | f | 1 |
| dog | m | 2 |
+---------+------+----------+
@end example
Or, if you wanted the number of animals per sex only for known-sex animals:
@example
mysql> SELECT species, sex, COUNT(*) FROM pet
-> WHERE sex IS NOT NULL
-> GROUP BY species, sex;
+---------+------+----------+
| species | sex | COUNT(*) |
+---------+------+----------+
| bird | f | 1 |
| cat | f | 1 |
| cat | m | 1 |
| dog | f | 1 |
| dog | m | 2 |
| hamster | f | 1 |
| snake | m | 1 |
+---------+------+----------+
@end example
@node Multiple tables, , Retrieving data, Database use
@subsection Using more than one table
The @code{pet} table keeps track of which pets you have. If you want to
record other information about them, such as events in their lives like
visits to the vet or when litters are born, you need another table. What
should this table look like?
@itemize @bullet
@item
It needs to contain the pet name so you know which animal each event pertains
to.
@item
It needs a date so you know when the event occurred.
@item
It needs a field to describe the event.
@item
If you want to be able to categorize events, it would be useful to have an
event type field.
@end itemize
Given these considerations, the @code{CREATE TABLE} statement for the
@code{event} table might look like this:
@example
mysql> CREATE TABLE event (name VARCHAR(20), date DATE,
-> type VARCHAR(15), remark VARCHAR(255));
@end example
As with the @code{pet} table, it's easiest to load the initial records
by creating a tab-delimited text file containing the information:
@multitable @columnfractions .15 .15 .15 .55
@item Fluffy @tab 1995-05-15 @tab litter @tab 4 kittens, 3 female, 1 male
@item Buffy @tab 1993-06-23 @tab litter @tab 5 puppies, 2 female, 3 male
@item Buffy @tab 1994-06-19 @tab litter @tab 3 puppies, 3 female
@item Chirpy @tab 1999-03-21 @tab vet @tab needed beak straightened
@item Slim @tab 1997-08-03 @tab vet @tab broken rib
@item Bowser @tab 1991-10-12 @tab kennel
@item Fang @tab 1991-10-12 @tab kennel
@item Fang @tab 1998-08-28 @tab birthday @tab Gave him a new chew toy
@item Claws @tab 1998-03-17 @tab birthday @tab Gave him a new flea collar
@item Whistler @tab 1998-12-09 @tab birthday @tab First birthday
@end multitable
Load the records like this:
@example
mysql> LOAD DATA LOCAL INFILE "event.txt" INTO TABLE event;
@end example
Based on what you've learned from the queries you've run on the @code{pet}
table, you should be able to perform retrievals on the records in the
@code{event} table; the principles are the same. But when is the
@code{event} table by itself insufficient to answer questions you might ask?
Suppose you want to find out the ages of each pet when they had their
litters. The @code{event} table indicates when this occurred, but to
calculate age of the mother, you need her birth date. Because that is
stored in the @code{pet} table, you need both tables for the query:
@example
mysql> SELECT pet.name, (TO_DAYS(date) - TO_DAYS(birth))/365 AS age, remark
-> FROM pet, event
-> WHERE pet.name = event.name AND type = "litter";
+--------+------+-----------------------------+
| name | age | remark |
+--------+------+-----------------------------+
| Fluffy | 2.27 | 4 kittens, 3 female, 1 male |
| Buffy | 4.12 | 5 puppies, 2 female, 3 male |
| Buffy | 5.10 | 3 puppies, 3 female |
+--------+------+-----------------------------+
@end example
There are several things to note about this query:
@itemize @bullet
@item
The @code{FROM} clause lists two tables because the query needs to pull
information from both of them.
@item
When combining (joining) information from multiple tables, you need to
specify how records in one table can be matched to records in the other.
This is easy because they both have a @code{name} column. The query uses
@code{WHERE} clause to match up records in the two tables based on the
@code{name} values.
@item
Because the @code{name} column occurs in both tables, you must be specific
about which table you mean when referring to the column. This is done
by prepending the table name to the column name.
@end itemize
You need not have two different tables to perform a join. Sometimes it is
useful to join a table to itself, if you want to compare records in a table
to other records in that same table. For example, to find breeding pairs
among your pets, you can join the @code{pet} table with itself to pair up
males and females of like species:
@example
mysql> SELECT p1.name, p1.sex, p2.name, p2.sex, p1.species
-> FROM pet AS p1, pet AS p2
-> WHERE p1.species = p2.species AND p1.sex = "f" AND p2.sex = "m";
+--------+------+--------+------+---------+
| name | sex | name | sex | species |
+--------+------+--------+------+---------+
| Fluffy | f | Claws | m | cat |
| Buffy | f | Fang | m | dog |
| Buffy | f | Bowser | m | dog |
+--------+------+--------+------+---------+
@end example
In this query, we specify aliases for the table name in order to be able
to refer to the columns and keep straight which instance of the table
each column reference is associated with.
@node Getting information, Batch mode, Database use, Tutorial
@section Getting information about databases and tables
What if you forget the name of a database or table, or what the structure of
a given table is (e.g., what its columns are called)? @strong{MySQL}
addresses this problem through several statements that provide information
about the databases and tables it supports.
You have already seen @code{SHOW DATABASES}, which lists the databases
managed by the server. To find out which database is currently selected,
use the @code{DATABASE()} function:
@example
mysql> SELECT DATABASE();
+------------+
| DATABASE() |
+------------+
| menagerie |
+------------+
@end example
If you haven't selected any database yet, the result is blank.
To find out what tables the current database contains (for example, when
you're not sure about the name of a table), use this command:
@example
mysql> SHOW TABLES;
+---------------------+
| Tables in menagerie |
+---------------------+
| event |
| pet |
+---------------------+
@end example
If you want to find out about the structure of a table, the @code{DESCRIBE}
command is useful; it displays information about each of a table's columns:
@example
mysql> DESCRIBE pet;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
@end example
@code{Field} indicates the column name, @code{Type} is the data type for
the column, @code{Null} indicates whether or not the column can contain
@code{NULL} values, @code{Key} indicates whether or not the column is
indexed and @code{Default} specifies the column's default value.
If you have indexes on a table,
@code{SHOW INDEX FROM tbl_name} produces information about them.
@node Batch mode, Twin, Getting information, Tutorial
@section Using @code{mysql} in batch mode
In the previous sections, you used @code{mysql} interactively to enter
queries and view the results. You can also run @code{mysql} in batch
mode. To do this, put the commands you want to run in a file, then
tell @code{mysql} to read its input from the file:
@example
shell> mysql < batch-file
@end example
If you need to specify connection parameters on the command line, the
command might look like this:
@example
shell> mysql -h host -u user -p < batch-file
Enter password: ********
@end example
When you use @code{mysql} this way, you are creating a script file, then
executing the script.
Why use a script? Here are a few reasons:
@itemize @bullet
@item
If you run a query repeatedly (say, every day or every week), making it a
script allows you to avoid retyping it each time you execute it.
@item
You can generate new queries from existing ones that are similar by copying
and editing script files.
@item
Batch mode can also be useful while you're developing a query, particularly
for multiple-line commands or multiple-statement sequences of commands. If
you make a mistake, you don't have to retype everything. Just edit your
script to correct the error, then tell @code{mysql} to execute it again.
@item
If you have a query that produces a lot of output, you can run the output
through a pager rather than watching it scroll off the top of your screen:
@example
shell> mysql < batch-file | more
@end example
@item
You can catch the output in a file for further processing:
@example
shell> mysql < batch-file > mysql.out
@end example
@item
You can distribute your script to other people so they can run the commands,
too.
@item
Some situations do not allow for interactive use, for example, when you run
a query from a @code{cron} job. In this case, you must use batch mode.
@end itemize
The default output format is different (more concise) when you run
@code{mysql} in batch mode than when you use it interactively. For
example, the output of @code{SELECT DISTINCT species FROM pet} looks like
this when run interactively:
@example
+---------+
| species |
+---------+
| bird |
| cat |
| dog |
| hamster |
| snake |
+---------+
@end example
But like this when run in batch mode:
@example
species
bird
cat
dog
hamster
snake
@end example
If you want to get the interactive output format in batch mode, use
@code{mysql -t}. To echo to the output the commands that are executed, use
@code{mysql -vvv}.
@node Twin, , Batch mode, Tutorial
@section Queries from twin project
At Analytikerna and Lentus, we have been doing the systems and field work
for a big research project. This project is a collaboration between the
Institute of Environmental Medicine at Karolinska Institutet Stockholm
and the Section on Clinical Research in Aging and Psychology at the
University of Southern California.
The project involves a screening part where all twins in Sweden older
than 65 years are interviewed by telephone. Twins who meet certain
criteria are passed on to the next stage. In this latter stage, twins who
want to participate are visited by a doctor/nurse team. Some of the
examinations include physical and neuropsychological examination,
laboratory testing, neuroimaging, psychological status assessment, and family
history collection. In addition, data are collected on medical and
environmental risk factors.
More information about Twin studies can be found at:
@example
@url{http://www.imm.ki.se/TWIN/TWINUKW.HTM}
@end example
The latter part of the project is administered with a web interface
written using Perl and @strong{MySQL}.
Each night all data from the interviews are moved into a @strong{MySQL}
database.
@menu
* Twin pool:: Find all non-distributed twins
* Twin event:: Show a table on twin pair status
@end menu
@node Twin pool, Twin event, Twin, Twin
@subsection Find all non-distributed twins
The following query is used to determine who goes into the second part of the
project:
@example
select
concat(p1.id, p1.tvab) + 0 as tvid,
concat(p1.christian_name, " ", p1.surname) as Name,
p1.postal_code as Code,
p1.city as City,
pg.abrev as Area,
if(td.participation = "Aborted", "A", " ") as A,
p1.dead as dead1,
l.event as event1,
td.suspect as tsuspect1,
id.suspect as isuspect1,
td.severe as tsevere1,
id.severe as isevere1,
p2.dead as dead2,
l2.event as event2,
h2.nurse as nurse2,
h2.doctor as doctor2,
td2.suspect as tsuspect2,
id2.suspect as isuspect2,
td2.severe as tsevere2,
id2.severe as isevere2,
l.finish_date
from
twin_project as tp
/* For Twin 1 */
left join twin_data as td on tp.id = td.id and tp.tvab = td.tvab
left join informant_data as id on tp.id = id.id and tp.tvab = id.tvab
left join harmony as h on tp.id = h.id and tp.tvab = h.tvab
left join lentus as l on tp.id = l.id and tp.tvab = l.tvab
/* For Twin 2 */
left join twin_data as td2 on p2.id = td2.id and p2.tvab = td2.tvab
left join informant_data as id2 on p2.id = id2.id and p2.tvab = id2.tvab
left join harmony as h2 on p2.id = h2.id and p2.tvab = h2.tvab
left join lentus as l2 on p2.id = l2.id and p2.tvab = l2.tvab,
person_data as p1,
person_data as p2,
postal_groups as pg
where
/* p1 gets main twin and p2 gets his/her twin. */
/* ptvab is a field inverted from tvab */
p1.id = tp.id and p1.tvab = tp.tvab and
p2.id = p1.id and p2.ptvab = p1.tvab and
/* Just the sceening survey */
tp.survey_no = 5 and
/* Skip if partner died before 65 but allow emigration (dead=9) */
(p2.dead = 0 or p2.dead = 9 or
(p2.dead = 1 and
(p2.death_date = 0 or
(((to_days(p2.death_date) - to_days(p2.birthday)) / 365)
>= 65))))
and
(
/* Twin is suspect */
(td.future_contact = 'Yes' and td.suspect = 2) or
/* Twin is suspect - Informant is Blessed */
(td.future_contact = 'Yes' and td.suspect = 1 and id.suspect = 1) or
/* No twin - Informant is Blessed */
(ISNULL(td.suspect) and id.suspect = 1 and id.future_contact = 'Yes') or
/* Twin broken off - Informant is Blessed */
(td.participation = 'Aborted'
and id.suspect = 1 and id.future_contact = 'Yes') or
/* Twin broken off - No inform - Have partner */
(td.participation = 'Aborted' and ISNULL(id.suspect) and p2.dead = 0))
and
l.event = 'Finished'
/* Get at area code */
and substring(p1.postal_code, 1, 2) = pg.code
/* Not already distributed */
and (h.nurse is NULL or h.nurse=00 or h.doctor=00)
/* Has not refused or been aborted */
and not (h.status = 'Refused' or h.status = 'Aborted'
or h.status = 'Died' or h.status = 'Other')
order by
tvid;
@end example
Some explanations:
@table @asis
@item @code{concat(p1.id, p1.tvab) + 0 as tvid}
We want to sort on the concatenated @code{id} and @code{tvab} in
numerical order. Adding @code{0} to the result causes @strong{MySQL} to
treat the result as a number.
@item column @code{id}
This identifies a pair of twins. It is a key in all tables.
@item column @code{tvab}
This identifies a twin in a pair. It has a value of @code{1} or @code{2}.
@item column @code{ptvab}
This is an inverse of @code{tvab}. When @code{tvab} is @code{1} this is
@code{2}, and vice versa. It exists to save typing and to make it easier for
@strong{MySQL} to optimize the query.
@end table
This query demonstrates, among other things, how to do lookups on a
table from the same table with a join (@code{p1} and @code{p2}). In the example, this
is used to check whether a twin's partner died before the age of 65. If so,
the row is not returned.
All of the above exist in all tables with twin-related information. We
have a key on both @code{id,tvab} (all tables) and @code{id,ptvab}
(@code{person_data}) to make queries faster.
On our production machine (A 200MHz UltraSPARC), this query returns
about 150-200 rows and takes less than one second.
The current number of records in the tables used above:
@multitable @columnfractions .3 .5
@item @strong{Table} @tab @strong{Rows}
@item @code{person_data} @tab 71074
@item @code{lentus} @tab 5291
@item @code{twin_project} @tab 5286
@item @code{twin_data} @tab 2012
@item @code{informant_data} @tab 663
@item @code{harmony} @tab 381
@item @code{postal_groups} @tab 100
@end multitable
@node Twin event, , Twin pool, Twin
@subsection Show a table on twin pair status
Each interview ends with a status code called @code{event}. The query
shown below is used to display a table over all twin pairs combined by
event. This indicates in how many pairs both twins are finished, in how many
pairs one twin is finished and the other refused, and so on.
@example
select
t1.event,
t2.event,
count(*)
from
lentus as t1,
lentus as t2,
twin_project as tp
where
/* We are looking at one pair at a time */
t1.id = tp.id
and t1.tvab=tp.tvab
and t1.id = t2.id
/* Just the sceening survey */
and tp.survey_no = 5
/* This makes each pair only appear once */
and t1.tvab='1' and t2.tvab='2'
group by
t1.event, t2.event;
@end example
@cindex Server functions
@node Server, Replication, Tutorial, Top
@chapter MySQL server functions
@menu
* Languages:: What languages are supported by @strong{MySQL}?
* Table size:: How big @strong{MySQL} tables can be
@end menu
@cindex Which languages @strong{MySQL} supports
@cindex Language support
@node Languages, Table size, Server, Server
@section What languages are supported by MySQL?
@code{mysqld} can issue error messages in the following languages: Czech,
Dutch, English (the default), Estonia, French, German, Hungarian, Italian,
Norwegian, Norwegian-ny, Polish, Portuguese, Spanish and Swedish.
To start @code{mysqld} with a particular language, use either the
@code{--language=lang} or @code{-L lang} options. For example:
@example
shell> mysqld --language=swedish
@end example
or:
@example
shell> mysqld --language=/usr/local/share/swedish
@end example
Note that all language names are specified in lowercase.
The language files are located (by default) in
@file{@var{mysql_base_dir}/share/@var{LANGUAGE}/}.
To update the error message file, you should edit the @file{errmsg.txt} file
and execute the following command to generate the @file{errmsg.sys} file:
@example
shell> comp_err errmsg.txt errmsg.sys
@end example
If you upgrade to a newer version of @strong{MySQL}, remember to repeat
your changes with the new @file{errmsg.txt} file.
@menu
* Character sets:: The character set used for data and sorting
* Adding character set:: Adding a new character set
* String collating:: String collating support
* Multi-byte characters:: Multi-byte character support
@end menu
@node Character sets, Adding character set, Languages, Languages
@subsection The character set used for data and sorting
By default, @strong{MySQL} uses the ISO-8859-1 (Latin1) character
set. This is the character set used in the USA and western Europe.
The character set determines what characters are allowed in names and how
things are sorted by the @code{ORDER BY} and @code{GROUP BY} clauses of
the @code{SELECT} statement.
You can change the character set with the
@code{--default-character-set} option when you start the server.
The character sets available depend on the @code{--with-charset=charset}
option to @code{configure}, and the character set configuration files
listed in @file{SHAREDIR/charsets/Index}.
@xref{Quick install}.
When a client connects to a @strong{MySQL} server, the server sends the
default character set in use to the client. The client will switch to
use this character set for this connection.
One should use @code{mysql_real_escape_string()} when escaping strings
for a SQL query. @code{mysql_real_escape_string()} is identical to the
old @code{mysql_escape_string()} function, except that it takes the MYSQL
connection handle as the first parameter.
If the client is compiled with different paths than where the server is
installed and the user that configured @strong{MySQL} didn't included all
character sets in the @strong{MySQL} binary one must specify for
the client where it can find the additional character sets it will need
if the server runs with a different character set than the client.
On can specify this by putting in a @strong{MySQL} option file:
@example
[client]
default-set-dir=/usr/local/mysql/share/mysql/charsets
@end example
where the path points to where the dynamic @strong{MySQL} character sets
are stored.
One can force the client to use specific character set by specifying:
@example
[client]
default-character-set=character-set-name
@end example
but normally this is never needed.
To add another character set to @strong{MySQL}, use the following procedure:
@node Adding character set, String collating, Character sets, Languages
@subsection Adding a new character set
@enumerate
@item
Choose a name for the character set, denoted @code{MYSET} below.
@item
Decide if the set is simple or complex. If the character set
does not need to use special string collating routines for
sorting, and does not need mulit-byte character support, it is
simple. If it needs either of those features, it is complex.
@item
If the character set is simple, then create the file
@file{sql/share/charsets/MYSET.conf}, and add MYSET the
@file{sql/share/charsets/Index} file. Read the
@file{sql/share/charsets/README} for more instructions.
@item
Add the character set name to the @code{CHARSETS_AVAILABLE} and
@code{COMPILED_CHARSETS} lists in @code{configure.in}.
@item
Reconfigure, recompile and test.
@item
If the character set is complex, create the file
@file{strings/ctype-MYSET.c} in the @strong{MySQL} source distribution.
@item
Add MYSET to the end of the @file{sql/share/charsets/Index} file. Take
note of its position in the file - this is its character set number,
denoted @code{MYNUMBER} below.
@item
Look at one of the existing @file{ctype-*.c} files to see what needs to be
defined. Note that the arrays in your file must have names like
@code{ctype_MYSET}, @code{to_lower_MYSET} and so on.
Near the top of the file, place a special comment like this:
@example
/*
* This comment is parsed by configure to create ctype.c,
* so don't change it unless you know what you are doing.
*
* .configure. number_MYSET=MYNUMBER
* .configure. strxfrm_multiply_MYSET=N
* .configure. mbmaxlen_MYSET=N
*/
@end example
The @code{configure} program uses this comment to include
the character set into the @strong{MySQL} library automatically.
The strxfrm_multiply and mbmaxlen lines will be explained in
the following sections. Only include them if you the string
collating functions or the multi-byte character set functions,
respectively.
@code{to_lower[]} and @code{to_upper[]} are simple arrays that hold the
lowercase and uppercase characters corresponding to each member of the
character set. For example:
@example
to_lower['A'] should contain 'a'
to_upper['a'] should contain 'A'
@end example
@code{sort_order[]} is a map indicating how characters should be ordered for
comparison and sorting purposes. For many character sets, this is the same as
@code{to_upper[]} (which means sorting will be case insensitive).
@strong{MySQL} will sort characters based on the value of
@code{sort_order[character]}. For more complicated sorting rules, see
the discussion of string collating below.
@code{ctype[]} is an array of bit values, with one element for one character.
(Note that @code{to_lower[]}, @code{to_upper[]} and @code{sort_order[]}
are indexed by character value, but @code{ctype[]} is indexed by character
value + 1. This is an old legacy to be able to handle EOF.)
You can find the following bitmask definitions in @file{m_ctype.h}:
@example
#define _U 01 /* Upper case */
#define _L 02 /* Lower case */
#define _N 04 /* Numeral (digit) */
#define _S 010 /* Spacing character */
#define _P 020 /* Punctuation */
#define _C 040 /* Control character */
#define _B 0100 /* Blank */
#define _X 0200 /* heXadecimal digit */
@end example
The @code{ctype[]} entry for each character should be the union of the
applicable bitmask values that describe the character.
For example, @code{'A'} is an uppercase character (@code{_U}) as well as a
hexadecimal digit (@code{_X}), so @code{ctype['A'+1]} should contain the value:
@example
_U + _X = 01 + 0200 = 0201
@end example
@item
Add support for the string collating or multi-byte features needed, as
described in the following sections.
@item
Add the character set name to the @code{CHARSETS_AVAILABLE} and
@code{COMPILED_CHARSETS} lists in @code{configure.in}.
@item
Reconfigure, recompile and test.
@end enumerate
@cindex String collating
@node String collating, Multi-byte characters, Adding character set, Languages
@subsection String collating support
If the sorting rules for your language are too complex to be handled
with the simple @code{sort_order[]} table, you need to use the string
collating functions.
Right now the best documentation on this is the character sets that are
already implemented. Look at the big5, czech, gbk, sjis and tis160
character sets for examples.
You must specify the @code{strxfrm_multiply_MYSET=N} value in the
special comment at the top of the file. @code{N} should be set to
the maximum ratio the strings may grow during my_strxfrm_MYSET (it
must be a positive integer).
@cindex Multi-byte characters
@node Multi-byte characters, , String collating, Languages
@subsection Multi-byte character support
If your character set includes multi-byte characters, you need to use
the multi-byte character functions.
Right now the best documentation on this is the character sets that are
already implemented. Look at the euc_kr, gb2312, gbk, sjis and ujis
character sets for examples.
You must specify the @code{mbmaxlen_MYSET=N} value in the
special comment at the top of the file. @code{N} should be set to
the size in bytes of the largest character in the set.
@cindex Table size
@cindex Size of tables
@node Table size, , Languages, Server
@section How big MySQL tables can be
@strong{MySQL} 3.22 has a 4G limit on table size. With the new
@code{MyISAM} in @strong{MySQL} 3.23 the maximum table size is pushed up
to 8 million terabytes (2 ^ 63 bytes).
Note however that operating systems have their own file size
limits. Here are some examples:
@multitable @columnfractions .6 .4
@item Linux-Intel @tab 2G (or 4G with reiserfs)
@item Linux-Alpha @tab 8T (?)
@item Solaris 2.5.1 @tab 2G (possible 4G with patch)
@item Solaris 2.6 @tab 4G
@item Solaris 2.7 Intel @tab 4G
@item Solaris 2.7 ULTRA-SPARC @tab 8T (?)
@end multitable
This means that the table size for @strong{MySQL} is normally limited by
the operating system.
By default, @strong{MySQL} tables have a maximum size of about 4G. You can
check the maximum table size for a table with the @code{SHOW TABLE STATUS}
command or with the @code{myisamchk -dv table_name}.
@xref{SHOW}.
If you need bigger tables than 4G (and your operating system supports
this), you should set the @code{AVG_ROW_LENGTH} and @code{MAX_ROWS}
parameter when you create your table. @xref{CREATE TABLE}. You can
also set these later with @code{ALTER TABLE}. @xref{ALTER TABLE}.
If you need to have bigger tables than 2G / 4G
If your big table is going to be read-only, you could use
@code{myisampack} to merge and compress many tables to one.
@code{myisampack} usually compresses a table by at least 50%, so you can
have, in effect, much bigger tables. @xref{myisampack, ,
@code{myisampack}}.
Another solution can be the included MERGE library, which allows you to
handle a collection of identical tables as one. (Identical in this case
means that all tables are created with identical column information.)
Currently MERGE can only be used to scan a collection of tables because it
doesn't support indexes. We will add indexes to this in the near future.
@cindex Replication
@node Replication, Performance, Server, Top
@chapter Replication in MySQL
@menu
* Replication Intro:: Introduction
* Replication Implementation:: Replication Implementation Overview
* Replication HOWTO:: HOWTO
* Replication Features:: Replication Features
* Replication Options:: Replication Options in my.cnf
* Replication SQL:: SQL Commands related to replication
@end menu
@node Replication Intro, Replication Implementation, Replication, Replication
@section Introduction
One way replication can be used both to increase robustness and
speed. For robustness you have two systems and switch to the backup if
you have problems with the master. The extra speed is achieved by
sending a part of the non-updating queries to the replica server. Of
course this only works if non-updating queries dominate, but that is the
normal case.
Starting in 3.23.15, @strong{MySQL} supports one-way replication
internally. One server acts as the master, while the other acts as the
slave. Note that one server could play the roles of master in one pair
and slave in the other. The master server keeps a binary log of updates
and an index file to binary logs to keep track of log rotation. The
slave upon connecting informs the master where it left off sinse the
last successfully propogated update, catches up on the updates, and then
blocks and waits for the master to notify it of the new updates.
@node Replication Implementation, Replication HOWTO, Replication Intro, Replication
@section Replication Implementation Overview
@strong{MySQL} internal replication uses the master-slave approach. One
server is designated as the master, while the other ( or others) as
slave(s). The master keeps a binary log of updates. The slave connects
to the master, catches up on the missed updates, and then starts
receiving updates immediately as they come to the master. If the
connection is lost, the slave will reconnect. If the master goes down,
the slave will keep trying to connect every @code{master-connect-retry}
seconds until the master comes back up and the connection can be
established. The slave keeps track of where it left off in the
replication process, so it can use the info in the case it goes down and
gets restarted later.
@node Replication HOWTO, Replication Features, Replication Implementation, Replication
@section HOWTO
Below is a quick HOWTO on how to set up replication on your current system:
@itemize @bullet
@item
Upgrade both slave and master to 3.23.15 or higher. We recommend that
you use the latest 3.23 version on both the slave and the master. While
3.23 is in beta, the versions may be not backwards compatible. In
addition, the newer version will fix some bugs and add new features.
@item
Set up special replication user(s) on the master with the @code{FILE}
privilege and permission to connect from all the slaves. If the user is
only doing replication, you don't need to grant him other privileges.
@item
Take a snapshot of all the tables/databases on the master that could
possibly be involved in the update queries before taking the next step
@item
In @code{my.cnf} on the master add @code{log-bin} and restart it. Make
sure there are no important updates to the master between the time you
have taken the snapshot and the time master is restarted with
@code{log-bin} option
@item
Load the snapshot of the master to all the slaves
@item
Add the following to @code{my.cnf} on the slave(s):
@example
master-host=<hostname of the master>
master-user=<replication user name>
master-password=<replication user password>
@end example
replacting the values in <> with what is relevant to your system.
@item Restart the slave(s)
@end itemize
After you have done the above, the master and the slave(s) should be in
sync.
@node Replication Features, Replication Options, Replication HOWTO, Replication
@section Replication Features
Below is an explanation of what is supported and what is not:
@itemize @bullet
@item
Replication will be done correctly with @code{AUTO_INCREMENT},
@code{LAST_INSERT_ID}, and @code{TIMESTAMP} values
@item
@code{LOAD DATA INFILE} will be handled properly as long as the file
still resides on the master server at the time of update
propogation. @code{LOAD LOCAL DATA INFILE} will be skipped.
@item
Update queries that use user variables are not replication-safe (yet)
@item
If the query on the slave gets an error, the slave thread will
terminate, and a message will appear in @code{.err} file. You should
then connect to the slave manually, fix the cause of the error
(eg. non-existent table), and then run @code{SLAVE START} sql command (
available starting in 3.23.16, in 3.23.15 you will have to restart the
server).
@item
If connection to the master is lost, the slave will retry immediately,
and then in case of failure every @code{master-connect-retry} (default
60) seconds. Because of this, it is safe to shut down the master, and
then restart it after a while. The slave will also be able to deal with
network connectivity outages.
@item
Shutting down the slave (cleanly) is also safe, as it keeps track of
where it left off. Unclean shutdowns might produce problems, especially
if disk cache was not synced before the system died. Your system fault
tolerance will be greatly increased if you have a good UPS.
@item
If the master is listening on a non-standard port, you will also need to
specify this with @code{master-port} parameter in @code{my.cnf} .
@item
In 3.23.15,all of the tables and databases will be replicated. Starting
in 3.23.16, you can restrict replication to a set of databases with
@code{replicate-do-db} directives in @code{my.cnf} or just excluse a set
of databases with @code{replicate-ignore-db}.
@item
Starting in 3.23.16, @code{SET SQL_LOG_BIN = 0} will turn off
replication (binary) logging on the master, and @code{SET SQL_LOG_BIN =
1} will turn in back on - you must have the process privilege to do
this.
@item
The slave thread does not log updates to the binary log of the slave,
so it is possible to couple two servers in a mutual master-slave
relationship. You can actually set up a load balancing scheme and do
queries safely on either of the servers. Just do not expect to do LOCK
TABLES on one server, then connect to the other and still have that
lock :-) .
@item
Starting in 3.23.19 you can clean up stale replication leftovers when
something goes wrong and you want a clean start with @code{FLUSH MASTER}
and @code{FLUSH SLAVE} commands
@item
Starting in 3.23.21 you can use LOAD TABLE FROM MASTER for network
backup and to set up replication initially.
@end itemize
@node Replication Options, Replication SQL, Replication Features, Replication
@section Replication Options in my.cnf
The table below explains the replications options in @code{my.cnf} . All
of the are available starting in 3.23.15 unless indicated otherwise.
@multitable @columnfractions .25 .25 .25 .25
@item @strong{Option} @tab @strong{Description} @tab @strong{Where to set} @tab @strong{Example}
@item @code{log-bin} @tab Should be set on the master. Tells it to keep a binary update
log. If a parameter is specified, the log will be written to the specified location. @tab Master @tab
@code{log-bin}
@item @code{log-bin-index} @tab Because the user could issue @code{FLUSH LOGS} command, we need to
know which log is currently active and which ones have been rotated out and it what sequence. This info
is stored in the binary log index file. The default is `hostname`.index . You can use this option
if you want to be a rebel. @tab Master @tab @code{log-bin-index=db.index}
@item @code{master-host} @tab Master hostname or IP address for replication. If not set,
the slave thread will not be started @tab Slave @tab @code{master-host=db-master.mycompany.com}
@item @code{master-user} @tab The user the slave thread will authenticate as when connecting to
the master. The user must have @code{FILE} privilige. If the master user is not set, user @code{test}
is assumed. @tab Slave @tab @code{master-user=scott}
@item @code{master-password} @tab The password the slave thread will authenticate with when
connecting to the master. If not set, empty password is assumed @tab Slave @tab
@code{master-password=tiger}
@item @code{master-port} @tab The port the master is listening on. If not set, the compiled setting of
@code{MYSQL_PORT} is assumed. If you have not tinkered with @code{configure} options, this should be
3306. @tab Slave @tab @code{master-port=3306}
@item @code{master-connect-retry} @tab The number of seconds the slave thread will sleep before retrying
to connect to the master in case the master goes down or the connection is lost.
Default is 60. @tab Slave @tab @code{master-connect-retry=60}
@item @code{master-info-file} @tab
The location of the file that remembers where we left off on the master
during the replication process. The default is master.info in the data
directory. Sasha: The only reason I see for ever changing the default
is the desire to be rebelious.
@tab Slave @tab @code{master-info-file=master.info}
@item @code{replicate-do-db} @tab Tells the slave thread to restrict replication to the specified database. To specify more than one database, use the directive multiple times, once for each database.
Note that this will only work if you do not use cross-database queries such as
@code{UPDATE some_db.some_table SET foo='bar'} while having selected a different or
no database. @tab Slave @tab @code{replicate-do-db=some_db}
@item @code{replicate-ignore-db} @tab Tells the slave thread to not replicate to the specified
database. To specify more than one database to ignore, use the directive multiple times,
once for each database. You must not use cross database updates for this option. @tab Slave @tab @code{replicate-ignore-db=some_db}
@item @code{sql-bin-update-same} @tab If set, setting @code{SQL_LOG_BIN} to a value will
automatically set @code{SQL_LOG_UPDATE} to the same value and vice
versa. @tab Master @tab @code{sql-bin-update-same}
@item @code{log-slave-updates} @tab Tells the slave to log the updates from the slave thread to the binary log. Off by default. You will need to turn it on if you plan to daisy-chain the slaves @tab Slave @tab @code{log-slave-updates}
@end multitable
@node Replication SQL, , Replication Options, Replication
@section SQL commands related to replication
Replication can be controlled through the SQL interface. Below is the
summary of commands:
@multitable @columnfractions .30 .40 .30
@item @strong{Command} @tab @strong{Description} @tab @strong{Where to run}
@item @code{SLAVE START} @tab Starts the slave thread. @tab Slave
@item @code{SLAVE STOP} @tab Stops the slave thread. @tab Slave
@item @code{SET SQL_LOG_BIN=0} @tab Disables update logging @tab Master
@item @code{SET SQL_LOG_BIN=1} @tab Re-enable update logging @tab Master
@item @code{FLUSH MASTER} @tab Deletes all binary logs listed in the inded file, resetting the binlog index file to be empty. @tab Master
@item @code{FLUSH SLAVE} @tab Makes the slave forget its replication position in the master logs @tab Slave
@item @code{LOAD TABLE tblname FROM MASTER} @tab Downloads a copy of the table from master to the slave @tab Slave
@end multitable
@cindex Performance
@cindex Optimization
@node Performance, MySQL Benchmarks, Replication, Top
@chapter Getting maximum performance from MySQL
Optimization is a complicated task because it ultimately requires
understanding of the whole system. While it may be possible to do some
local optimizations with small knowledge of your system/application, the
more optimal you want your system to become the more you will have to
know about it.
So this chapter will try to explain and give some examples of different
ways to optimize @strong{MySQL}. But remember that there are always some
(increasingly harder) ways to make the system even faster left to do.
@menu
* Optimize Basics:: Optimization overview
* System:: System/Compile time and startup parameter tuning
* Data size:: Get your data as small as possible
* MySQL indexes:: How @strong{MySQL} uses indexes
* Query Speed:: Speed of queries that access or update data
* Tips:: Other optimization tips
* Benchmarks:: Using your own benchmarks
* Design:: Design choices
* Design Limitations:: MySQL design limitations/tradeoffs
* Portability:: Portability
* Internal use:: What have we used MySQL for?
@end menu
@node Optimize Basics, System, Performance, Performance
@section Optimization overview
The most important part for getting a system fast is of course the basic
design. You also need to know what kinds of things your system will be
doing, and what your bottlenecks are.
The most common bottlenecks are:
@itemize @bullet
@item Disk seeks
It takes time for the disk to find a piece of data. With modern disks in
1999 the mean time for this is usually lower than 10ms, so we can in
theory do about 1000 seeks a second. This time improves slowly with new
disks and is very hard to optimize for a single table. The way to
optimize this is to spread the data on more than one disk.
@item Disk reading/writing
When the disk is at the correct position we need to read the data. With
modern disks in 1999 one disk delivers something like 10-20Mb/s. This
is easier to optimize than seeks because you can read in parallel from
multiple disks.
@item CPU cycles
When we have got the data into main memory (or if it already were
there) we need to process it to get to our result. When we have small
tables compared to the memory this is the most common limiting
factor. But then with small tables speed is usually not the problem.
@item Memory bandwidth
When the CPU needs more data than can fit in the CPU cache the main
memory bandwidth becomes a bottleneck. This is an uncommon bottleneck
for most systems but one should be aware of it.
@end itemize
@node System, Data size, Optimize Basics, Performance
@section System/Compile time and startup parameter tuning
We start with the system level things since some of these decisions have
to be made very early. In other cases a fast look at this part may
suffice because it not that important for the big gains. However, it is always
nice to have a feeling about how much one could gain by changing things
at this level.
The default OS to use is really important! To get the most use of
multiple CPU machines one should use Solaris (because the threads works
really nice) or Linux (because the 2.2 kernel has really good SMP
support). Also on 32bit machines Linux has a 2G file size limit by
default. Hopefully this will be fixed soon when new filesystems is
released (XFS/Reiserfs).
Because we have not run @strong{MySQL} in production on that many platforms we
advice you to test your intended platform before choosing it, if possible.
Other tips:
@itemize @bullet
@item
If you have enough RAM, you could remove all swap devices. Some
operating systems will use a swap device in some contexts even if you
have free memory.
@item
Use the @code{--skip-locking} @strong{MySQL} option to avoid external
locking. Note that this will not impact @strong{MySQL}'s functionality as
long as you only run one server. Just remember to take down the server (or
lock relevant parts) before you run @code{myisamchk}. On some system
this switch is mandatory because the external locking does not work in any
case.
The @code{--skip-locking} option is on by default when compiling with
MIT-pthreads, because @code{flock()} isn't fully supported by
MIT-pthreads on all platforms.
The only case when you can't use @code{--skip-locking} is if you run
multiple @strong{MySQL} @emph{servers} (not clients) on the same data, or run
@code{myisamchk} on the table without first flushing and locking the
@code{mysqld} server tables first.
You can still use @code{LOCK TABLES} / @code{UNLOCK TABLES} even if you
are using @code{--skip-locking}
@end itemize
@menu
* Compile and link options:: How compiling and linking affects the speed of MySQL
* Disk issues:: Disk issues
* Server parameters:: Tuning server parameters
* Table cache:: How MySQL opens and closes tables
* Creating many tables:: Drawbacks of creating large numbers of tables in the same database
* Open tables:: Why so many open tables?
* Memory use:: How MySQL uses memory
* Internal locking:: How MySQL locks tables
* Table locking:: Table locking issues
@end menu
@node Compile and link options, Disk issues, System, System
@subsection How compiling and linking affects the speed of MySQL
Most of the following tests are done on Linux with the
@strong{MySQL} benchmarks, but they should give some indication for
other operating systems and workloads.
You get the fastest executable when you link with @code{-static}.
On Linux, you will get the fastest code when compiling with @code{pgcc}
and @code{-O6}. To compile @file{sql_yacc.cc} with these options, you
need about 200M memory because @code{gcc/pgcc} needs a lot of memory to
make all functions inline. You should also set @code{CXX=gcc} when
configuring @strong{MySQL} to avoid inclusion of the @code{libstdc++}
library (it is not needed). Note that with some versions of @code{pgcc},
the resulting code will only run on true Pentium processors, even if you
use the compiler option that you want the resulting code to be working on
all x586 type processors (Like AMD).
By just using a better compiler and/or better compiler options you can
get a 10-30 % speed increase in your application. This is particularly
important if you compile the SQL server yourself!
We have tested the both Cygnus CodeFusion and the Fujitsu compiler but
when we tested them, neither was enough bug free enough to compile
@strong{MySQL} with optimizations on.
When you compile @strong{MySQL} you should only include support for the
character sets that you are going to use. (Option @code{--with-charset=xxx}).
The standard @strong{MySQL} binary distributions are compiled with support
for all character sets.
Here is a list of some mesurements that we have done:
@itemize @bullet
@item
If you use @code{pgcc} and compile everything with @code{-O6}, the
@code{mysqld} server is 11% faster than with @code{gcc} versions
older than @code{gcc} 2.95.2.
@item
If you link dynamically (without @code{-static}), the result is 13%
slower. Note that you still can use a dynamic linked @strong{MySQL}
library. It is only the server that is critical for performance.
@item
If you connect using TCP/IP rather than Unix sockets, the result is 7.5%
slower on the same computer. (If you are connection to @code{localhost},
@strong{MySQL} will by default use sockets).
@item
On a Sun SPARCstation 10, @code{gcc} 2.7.3 is 13% faster than Sun Pro C++ 4.2.
@item
On Solaris 2.5.1, MIT-pthreads is 8-12% slower than Solaris native
threads on a single processor. With more load/CPUs the difference should
get bigger.
@end itemize
The @strong{MySQL}-Linux distribution provided by MySQL AB used to be
compiled with @code{pgcc}, but we had to go back to regular gcc because
of a bug in @code{pgcc} that would generate the code that does not run
on AMD. We will continue using gcc until that bug is resolved. In the
meantime, if you have a non-AMD machine, you can get a faster binary by
compiling with @code{pgcc}. The standard MySqL Linux binary is linked
statically to get it faster and more portable.
@node Disk issues, Server parameters, Compile and link options, System
@subsection Disk issues
@itemize @bullet
@item
As mentioned before disks seeks are a big performance bottleneck. This
problems gets more and more apparent when the data starts to grow so
large that effective caching becomes impossible. For large databases,
where you access data more or less randomly, you can be sure that you
will need at least one disk seek to read and a couple of disk seeks to
write things. To minimize this problem, use disks with low seek times.
@item
Increase the number of available disk spindles (and thereby reduce
the seek overhead) by either symlink files to different disks or stripe
the disks.
@table @strong
@item Using symbolic links
This means that you symlink the index and/or data file(s) from the
normal data directory to another disk (that may also be striped). This
makes both the seek and read times better (if the disks are not used for
other things). @xref{Symbolic links}.
@item Striping
Striping means that you have many disks and put the first block on the
first disk, the second block on the second disk, and the Nth on the (Nth
mod number_of_disks) disk, and so on. This means if your normal data
size is less than the stripe size (or perfectly aligned) you will get
much better performance. Note that striping if very dependent on the OS
and stripe-size. So benchmark your application with different
stripe-sizes. @xref{Benchmarks}.
Note that the speed difference for striping is @strong{very} dependent
on the parameters. Depending on how you set the striping parameters and
number of disks you may get difference in orders of magnitude. Note that
you have to choose to optimize for random or sequential access.
@end table
@item
For reliability you may want to use RAID 0+1 (striping + mirroring), but
in this case you will need 2*N drives to hold N drives of data. This is
probably the best option if you have the money for it! You may however
also have to invest in some volume management software to handle it
efficiently.
@item
A good option is to have semi-important data (that can be re-generated)
on RAID 0 disk while store really important data (like host information
and logs) on a RAID 0+1 or RAID N disks. RAID N can be a problem if you
have many writes because of the time to update the parity bits.
@item
You may also set the parameters for the file system that the database
uses. One easy change is to mount the file system with the noatime
option. That makes it skip the updating of the last access time in the
inode and by this will avoid some disk seeks.
@item
On Linux, you can get much more performance (up to 100 % under load is
not uncommon) by using hdpram to configure your disks interface! The
following should be quite good hdparm options for @code{MySQL} (and
probably many other applications):
@example
hdparm -m 16 -d 1
@end example
Note that the performance/reliability when using the above depends on
your hardware, so we strongly suggest that you test your system
throughly after using @code{hdparm}! Please consult the @code{hdparm}
man page for more information! If @code{hdparm} is not used wisely,
filesystem corruption may result. Backup everything before experimenting!
@item
On many OS system you can mount the disks with the 'async' flag to set the file
system to be updated asynchronously. If your computer is reasonable stable,
this should give you more performance without sacrificing too much reliability.
(This flag is on by default on Linux).
@item
If you don't need to know when a file was last accessed (which is not
really useful on a databasa server), you can mount your file systems
with the noatime flag.
@end itemize
@menu
* Symbolic links:: Using symbolic links for databases and tables
@end menu
@node Symbolic links, , Disk issues, Disk issues
@subsubsection Using symbolic links for databases and tables
You can move tables and databases from the database directory to other
locations and replace them with symbolic links to the new locations.
You might want to do this, for example, to move a database to a file
system with more free space.
If @strong{MySQL} notices that a table is a symbolically-linked, it will
resolve the symlink and use the table it points to instead. This works
on all systems that support the @code{realpath()} call (at least Linux
and Solaris support @code{realpath()})! On systems that don't support
@code{realpath()}, you should not access the table through the real path
and through the symlink at the same time! If you do, the table will be
inconsistent after any update.
@strong{MySQL} doesn't that you link one directory to multiple
databases. Replacing a database directory with a symbolic link will
work fine as long as you don't make a symbolic link between databases.
Suppose you have a database @code{db1} under the @strong{MySQL} data
directory, and then make a symlink @code{db2} that points to @code{db1}:
@example
shell> cd /path/to/datadir
shell> ln -s db1 db2
@end example
Now, for any table @code{tbl_a} in @code{db1}, there also appears to be
a table @code{tbl_a} in @code{db2}. If one thread updates @code{db1.tbl_a}
and another thread updates @code{db2.tbl_a}, there will be problems.
If you really need this, you must change the following code in
@file{mysys/mf_format.c}:
@example
if (flag & 32 || (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode)))
@end example
to
@example
if (1)
@end example
On windows you can use internal symbolic links to directories by compiling
@strong{MySQL} with @code{-DUSE_SYMDIR}. This allows you to put different
databases on different disks. @xref{Win32 symbolic links}.
@cindex Startup parameters
@node Server parameters, Table cache, Disk issues, System
@subsection Tuning server parameters
You can get the default buffer sizes used by the @code{mysqld} server
with this command:
@example
shell> mysqld --help
@end example
This command produces a list of all @code{mysqld} options and configurable
variables. The output includes the default values and looks something
like this:
@example
Possible variables for option --set-variable (-O) are:
back_log current value: 5
bdb_cache_size current value: 1048540
connect_timeout current value: 5
delayed_insert_timeout current value: 300
delayed_insert_limit current value: 100
delayed_queue_size current value: 1000
flush_time current value: 0
interactive_timeout current value: 28800
join_buffer_size current value: 131072
key_buffer_size current value: 1048540
lower_case_table_names current value: 0
long_query_time current value: 10
max_allowed_packet current value: 1048576
max_connections current value: 100
max_connect_errors current value: 10
max_delayed_threads current value: 20
max_heap_table_size current value: 16777216
max_join_size current value: 4294967295
max_sort_length current value: 1024
max_tmp_tables current value: 32
max_write_lock_count current value: 4294967295
myisam_sort_buffer_size current value: 8388608
net_buffer_length current value: 16384
net_retry_count current value: 10
net_read_timeout current value: 30
net_write_timeout current value: 60
query_buffer_size current value: 0
record_buffer current value: 131072
slow_launch_time current value: 2
sort_buffer current value: 2097116
table_cache current value: 64
thread_concurrency current value: 10
tmp_table_size current value: 1048576
thread_stack current value: 131072
wait_timeout current value: 28800
@end example
If there is a @code{mysqld} server currently running, you can see what
values it actually is using for the variables by executing this command:
@example
shell> mysqladmin variables
@end example
<<<<<<< manual.texi
Each option is described below. Values for buffer sizes, lengths and stack
sizes are given in bytes. You can specify values with a suffix of @samp{K}
or @samp{M} to indicate kilobytes or megabytes. For example, @code{16M}
indicates 16 megabytes. The case of suffix letters does not matter;
@code{16M} and @code{16m} are equivalent.
You can also see some statistics from a running server by issuing the command
@code{SHOW STATUS}. @xref{SHOW}.
@table @code
@item @code{ansi_mode}.
Is @code{ON} if @code{mysqld} was started with @code{--ansi}.
@xref{Ansi mode}.
@item @code{back_log}
The number of outstanding connection requests @strong{MySQL} can have. This
comes into play when the main @strong{MySQL} thread gets @strong{VERY}
many connection requests in a very short time. It then takes some time
(although very little) for the main thread to check the connection and start
a new thread. The @code{back_log} value indicates how many requests can be
stacked during this short time before @strong{MySQL} momentarily stops
answering new requests. You need to increase this only if you expect a large
number of connections in a short period of time.
In other words, this value is the size of the listen queue for incoming
TCP/IP connections. Your operating system has its own limit on the size
of this queue. The manual page for the Unix @code{listen(2)} system
call should have more details. Check your OS documentation for the
maximum value for this variable. Attempting to set @code{back_log}
higher than your operating system limit will be ineffective.
@item @code{bdb_cache_size}
The buffer that is allocated to cache index and rows for @code{BDB} tables.
If you don't use @code{BDB} tables, you should set this to 0 or
start @code{mysqld} with @code{--skip-bdb} o not waste memory for this cache.
@item @code{concurrent_inserts}
If @code{ON} (the default), @code{MySQL} will allow you to use @code{INSERT}
on @code{MyISAM} tables at the same time as you run @code{SELECT} queries
on them. You can turn this option off by starting mysqld with @code{--safe}
or @code{--skip-new}.
@item @code{connect_timeout}
The number of seconds the @code{mysqld} server is waiting for a connect
packet before responding with @code{Bad handshake}.
@item @code{delayed_insert_timeout}
How long a @code{INSERT DELAYED} thread should wait for @code{INSERT}
statements before terminating.
@item @code{delayed_insert_limit}
After inserting @code{delayed_insert_limit} rows, the @code{INSERT
DELAYED} handler will check if there are any @code{SELECT} statements
pending. If so, it allows these to execute before continuing.
@item @code{delay_key_write}
If enabled (is on by default), @strong{MySQL} will honor the
@code{delay_key_write} option @code{CREATE TABLE}. This means that the
key buffer for tables with this option will not get flushed on every
index update, but only when a table is closed. This will speed up
writes on keys a lot but you should add automatic checking of all tables
with @code{myisamchk --fast --force} if you use this. Note that if you
start @code{mysqld} with the @code{--delay-key-write-for-all-tables}
option this means that all tables will be treated as if they were
created with the @code{delay_key_write} option. You can clear this flag
by starting @code{mysqld} with @code{--skip-new} or @code{--safe-mode}.
@item @code{delayed_queue_size}
What size queue (in rows) should be allocated for handling @code{INSERT
DELAYED}. If the queue becomes full, any client that does @code{INSERT
DELAYED} will wait until there is room in the queue again.
@item @code{flush_time}
If this is set to a non-zero value, then every @code{flush_time} seconds all
tables will be closed (to free up resources and sync things to disk).
@item @code{init_file}
The name of the file specified with the @code{--init-file} option when
you start the server. This is a file of SQL statements you want the
server to execute when it starts.
@item @code{interactive_timeout}
The number of seconds the server waits for activity on an interactive
connection before closing it. An interactive client is defined as a
client that uses the @code{CLIENT_INTERACTIVE} option to
@code{mysql_real_connect()}. See also @code{wait_timeout}.
@item @code{join_buffer_size}
The size of the buffer that is used for full joins (joins that do not
use indexes). The buffer is allocated one time for each full join
between two tables. Increase this value to get a faster full join when
adding indexes is not possible. (Normally the best way to get fast joins
is to add indexes.)
@c Make texi2html support index @anchor{Index cache size}. Then change
@c some xrefs to point here
@item @code{key_buffer_size}
Index blocks are buffered and are shared by all threads.
@code{key_buffer_size} is the size of the buffer used for index blocks.
Increase this to get better index handling (for all reads and multiple
writes) to as much as you can afford; 64M on a 256M machine that mainly
runs @strong{MySQL} is quite common. If you however make this too big
(more than 50% of your total memory?) your system may start to page
and become REALLY slow. Remember that because @strong{MySQL} does not cache data
read, that you will have to leave some room for the OS filesystem cache.
You can check the performance of the key buffer by doing @code{show
status} and examine the variables @code{Key_read_requests},
@code{Key_reads}, @code{Key_write_requests} and @code{Key_writes}. The
@code{Key_reads/Key_read_request} ratio should normally be < 0.01.
The @code{Key_write/Key_write_requests} is usually near 1 if you are
using mostly updates/deletes but may be much smaller if you tend to
do updates that affect many at the same time or if you are
using @code{delay_key_write}. @xref{SHOW}.
To get even more speed when writing many rows at the same time use
@code{LOCK TABLES}. @xref{LOCK TABLES, , @code{LOCK TABLES}}.
@item @code{lower_case_table_names}
Change all table names to lower case on disk.
@item @code{long_query_time}
If a query takes longer than this (in seconds), the @code{Slow_queries} counter
will be incremented.
@item @code{max_allowed_packet}
The maximum size of one packet. The message buffer is initialized to
@code{net_buffer_length} bytes, but can grow up to @code{max_allowed_packet}
bytes when needed. This value by default is small, to catch big (possibly
wrong) packets. You must increase this value if you are using big
@code{BLOB} columns. It should be as big as the biggest @code{BLOB} you want
to use.
@item @code{max_connections}
The number of simultaneous clients allowed. Increasing this value increases
the number of file descriptors that @code{mysqld} requires. See below for
comments on file descriptor limits. @xref{Too many connections}.
@item @code{max_connect_errors}
If there is more than this number of interrupted connections from a host
this host will be blocked from further connections. You can unblock a host
with the command @code{FLUSH HOSTS}.
@item @code{max_delayed_threads}
Don't start more than this number of threads to handle @code{INSERT DELAYED}
statements. If you try to insert data into a new table after all @code{INSERT
DELAYED} threads are in use, the row will be inserted as if the
@code{DELAYED} attribute wasn't specified.
@item @code{max_join_size}
Joins that are probably going to read more than @code{max_join_size}
records return an error. Set this value if your users tend to perform joins
without a @code{WHERE} clause that take a long time and return
millions of rows.
@item @code{max_heap_table_size}
Don't allow creation of heap tables bigger than this.
@item @code{max_sort_length}
The number of bytes to use when sorting @code{BLOB} or @code{TEXT}
values (only the first @code{max_sort_length} bytes of each value
are used; the rest are ignored).
@item @code{max_tmp_tables}
(This option doesn't yet do anything).
Maximum number of temporary tables a client can keep open at the same time.
@item @code{max_write_lock_count}
After this many write locks, allow some read locks to run in between.
@item @code{myisam_sort_buffer_size}
The buffer that is allocated when sorting the index when doing a @code{REPAIR}
table.
@item @code{net_buffer_length}
The communication buffer is reset to this size between queries. This
should not normally be changed, but if you have very little memory, you
can set it to the expected size of a query. (That is, the expected length of
SQL statements sent by clients. If statements exceed this length, the buffer
is automatically enlarged, up to @code{max_allowed_packet} bytes.)
@item @code{net_retry_count}
If a read on a communication port is interrupted, retry this many times
before giving up. This value should be quite high on @code{FreeBSD} as
internal interrupts is sent to all threads.
@item @code{net_read_timeout}
Number of seconds to wait for more data from a connection before aborting
the read. Note that when we don't expect data from a connection, the timeout
is defined by @code{write_timeout}.
@item @code{net_write_timeout}
Number of seconds to wait for a block to be written to a connection before
aborting the write.
=======
>>>>>>> 1.148
<<<<<<< manual.texi
@item @code{record_buffer}
Each thread that does a sequential scan allocates a buffer of this
size for each table it scans. If you do many sequential scans, you may
want to increase this value.
=======
or the @code{SHOW VARIABLES} in the @code{mysql} command client.
>>>>>>> 1.148
<<<<<<< manual.texi
@item @code{query_buffer_size}
The initial allocation of the query buffer. If most of your queries are
long (like when inserting blobs), you should increase this!
=======
You can find a full description for all variables in the @code{SHOW VARIABLES}
section in this manual. @xref{SHOW VARIABLES}.
>>>>>>> 1.148
<<<<<<< manual.texi
@item @code{skip_show_databases}
This prevents people from doing @code{SHOW DATABASES}, if they don't
have the @code{PROCESS_PRIV} privilege. This can improve security if
you're concerned about people being able to see what databases and
tables other users have.
@item @code{slow_launch_time}
If the creating of the thread longer than this (in seconds), the
@code{Slow_launch_threads} counter will be incremented.
@item @code{sort_buffer}
Each thread that needs to do a sort allocates a buffer of this
size. Increase this value for faster @code{ORDER BY} or @code{GROUP BY}
operations.
@xref{Temporary files}.
@item @code{table_cache}
The number of open tables for all threads. Increasing this value
increases the number of file descriptors that @code{mysqld} requires.
@strong{MySQL} needs two file descriptors for each unique open table.
See below for comments on file descriptor limits. You can check if you
need to increase the table cache by checking the @code{Opened_tables}
variable. @xref{SHOW}. If this variable is big and you don't do
@code{FLUSH TABLES} a lot (which just forces all tables to be closed and
reopenend), then you should increase the value of this variable.
For information about how the table cache works, see @ref{Table cache}.
@item @code{thread_cache_size}
How many threads we should keep keep in a cache for reuse. When a
client disconnects the clients threads is put in the cache if there
isn't more than @code{thread_cache_size} threads from before. All new
threads are first taken from the cache and only when the cache is empty
a new thread is created. This variable can be increased to improve
performance if you have a lot of new connections (Normally this doesn't
however give a notable performance improvement if you have a good
thread implementation).
@item @code{thread_concurrency}
On Solaris, @code{mysqld} will call @code{thr_setconcurrency()} with
this value. @code{thr_setconcurrency()} permits the application to give
the threads system a hint, for the desired number of threads that should
be run at the same time.
@item @code{thread_stack}
The stack size for each thread. Many of the limits detected by the
@code{crash-me} test are dependent on this value. The default is
large enough for normal operation. @xref{Benchmarks}.
@item @code{tmp_table_size}
If an in-memory temporary table exceeds this size, @strong{MySQL}
will automatically convert it to an on-disk @code{MyISAM} table.
Increase the value of @code{tmp_table_size} if you do many advanced
@code{GROUP BY} queries and you have lots of memory.
@item @code{wait_timeout}
The number of seconds the server waits for activity on a connection before
closing it. See also @code{interactive_timeout}.
@end table
=======
You can also see some statistics from a running server by issuing the command
@code{SHOW STATUS}. @xref{SHOW STATUS}.
>>>>>>> 1.148
@strong{MySQL} uses algorithms that are very scalable, so you can usually
run with very little memory. If you however give @strong{MySQL} more
memory you will normally also get better performance.
When tuning a @strong{MySQL} server, the two most important variables to use
are @code{key_buffer_size} and @code{table_cache}. You should first feel
confident that you have these right before trying to change any of the
other variables.
If you have much memory (>=256M) and many tables and want maximum performance
with a moderate number of clients, you should use something like this:
@example
shell> safe_mysqld -O key_buffer=64M -O table_cache=256 \
-O sort_buffer=4M -O record_buffer=1M &
@end example
If you have only 128M and only a few tables, but you still do a lot of
sorting, you can use something like:
@example
shell> safe_mysqld -O key_buffer=16M -O sort_buffer=1M
@end example
If you have little memory and lots of connections, use something like this:
@example
shell> safe_mysqld -O key_buffer=512k -O sort_buffer=100k \
-O record_buffer=100k &
@end example
or even:
@example
shell> safe_mysqld -O key_buffer=512k -O sort_buffer=16k \
-O table_cache=32 -O record_buffer=8k -O net_buffer=1K &
@end example
When you have installed @strong{MySQL}, the @file{Docs} directory will
contain some different @code{my.cnf} example files, @file{my-huge.cnf},
@file{my-large.cnf},@file{my-medium.cnf} and@file{my-small.cnf}, you can
use as a base to optimize your system.
If there are very many connections, ``swapping problems'' may occur unless
@code{mysqld} has been configured to use very little memory for each
connection. @code{mysqld} performs better if you have enough memory for all
connections, of course.
Note that if you change an option to @code{mysqld}, it remains in effect only
for that instance of the server.
To see the effects of a parameter change, do something like this:
@example
shell> mysqld -O key_buffer=32m --help
@end example
Make sure that the @code{--help} option is last; otherwise, the effect of any
options listed after it on the command line will not be reflected in the
output.
@cindex Table cache
@findex table_cache
@node Table cache, Creating many tables, Server parameters, System
@subsection How MySQL opens and closes tables
@code{table_cache}, @code{max_connections} and @code{max_tmp_tables}
affect the maximum number of files the server keeps open. If you
increase one or both of these values, you may run up against a limit
imposed by your operating system on the per-process number of open file
descriptors. However, you can increase the limit on many systems.
Consult your OS documentation to find out how to do this, because the
method for changing the limit varies widely from system to system.
@code{table_cache} is related to @code{max_connections}. For example,
for 200 concurrent running connections, you should have a table cache of
at least @code{200 * n}, where @code{n} is the maximum number of tables
in a join.
The cache of open tables can grow to a maximum of @code{table_cache}
(default 64; this can be changed with with the @code{-O table_cache=#}
option to @code{mysqld}). A table is never closed, except when the
cache is full and another thread tries to open a table or if you use
@code{mysqladmin refresh} or @code{mysqladmin flush-tables}.
When the table cache fills up, the server uses the following procedure
to locate a cache entry to use:
@itemize @bullet
@item
Tables that are not currently in use are released, in least-recently-used
order.
@item
If the cache is full and no tables can be released, but a new table needs to
be opened, the cache is temporarily extended as necessary.
@item
If the cache is in a temporarily-extended state and a table goes from in-use
to not-in-use state, the table is closed and released from the cache.
@end itemize
A table is opened for each concurrent access. This means that
if you have two threads accessing the same table or access the table
twice in the same query (with @code{AS}) the table needs to be opened twice.
The first open of any table takes two file descriptors; each additional
use of the table takes only one file descriptor. The extra descriptor
for the first open is used for the index file; this descriptor is shared
among all threads.
You can check if your table cache is too small by checking the mysqld
variable @code{opened_tables}. If this is quite big, even if you
haven't done alot of @code{flush tables}, you should increase your table
cache. @xref{SHOW STATUS}.
@node Creating many tables, Open tables, Table cache, System
@subsection Drawbacks of creating large numbers of tables in the same database
If you have many files in a directory, open, close and create operations will
be slow. If you execute @code{SELECT} statements on many different tables,
there will be a little overhead when the table cache is full, because for
every table that has to be opened, another must be closed. You can reduce
this overhead by making the table cache larger.
@node Open tables, Memory use, Creating many tables, System
@subsection Why so many open tables?
When you run @code{mysqladmin status}, you'll see something like this:
@example
Uptime: 426 Running threads: 1 Questions: 11082 Reloads: 1 Open tables: 12
@end example
This can be somewhat perplexing if you only have 6 tables.
@strong{MySQL} is multithreaded, so it may have many queries on the same
table simultaneously. To minimize the problem with two threads having
different states on the same file, the table is opened independently by
each concurrent thread. This takes some memory and one extra file
descriptor for the data file. The index file descriptor is shared
between all threads.
@cindex Memory use
@node Memory use, Internal locking, Open tables, System
@subsection How MySQL uses memory
The list below indicates some of the ways that the @code{mysqld} server
uses memory. Where applicable, the name of the server variable relevant
to the memory use is given.
@itemize @bullet
@item
The key buffer (variable @code{key_buffer_size}) is shared by all
threads; Other buffers used by the server are allocated as
needed. @xref{Server parameters}.
@item
Each connection uses some thread specific space; A stack (default 64K,
variable @code{thread_stack}) a connection buffer (variable
@code{net_buffer_length}), and a result buffer (variable
@code{net_buffer_length}). The connection buffer and result buffer are
dynamically enlarged up to @code{max_allowed_packet} when needed. When
a query is running, a copy of the current query string is also allocated.
@item
All threads share the same base memory.
@item
Only the compressed ISAM / MyISAM tables are memory mapped. This is
because the 32-bit memory space of 4GB is not large enough for most
big tables. When systems with a 64-bit address-space become more
common we may add general support for memory-mapping.
@item
Each request doing a sequential scan over a table allocates a read buffer
(variable @code{record_buffer}).
@item
All joins are done in one pass and most joins can be done without even
using a temporary table. Most temporary tables are memory-based (HEAP)
tables. Temporary tables with a big record length (calculated as the
sum of all column lengths) or that contain @code{BLOB} columns are
stored on disk.
One problem in @strong{MySQL} versions before 3.23.2 is that if a HEAP table
exceeds the size of @code{tmp_table_size}, you get the error @code{The
table tbl_name is full}. In newer versions this is handled by
automatically changing the in-memory (HEAP) table to a disk-based
(MyISAM) table as necessary. To work around this problem, you can
increase the temporary table size by setting the @code{tmp_table_size}
option to @code{mysqld}, or by setting the SQL option
@code{SQL_BIG_TABLES} in the client program. @xref{SET OPTION, ,
@code{SET OPTION}}. In @strong{MySQL} 3.20, the maximum size of the
temporary table was @code{record_buffer*16}, so if you are using this
version, you have to increase the value of @code{record_buffer}. You can
also start @code{mysqld} with the @code{--big-tables} option to always
store temporary tables on disk, however, this will affect the speed of
many complicated queries.
@item
Most requests doing a sort allocates a sort buffer and 0-2 temporary
files depending on the result set size. @xref{Temporary files}.
@item
Almost all parsing and calculating is done in a local memory store. No
memory overhead is needed for small items and the normal slow memory
allocation and freeing is avoided. Memory is allocated only for
unexpectedly large strings (this is done with @code{malloc()} and
@code{free()}).
@item
Each index file is opened once and the data file is opened once for each
concurrently-running thread. For each concurrent thread, a table structure,
column structures for each column, and a buffer of size @code{3 * n} is
allocated (where @code{n} is the maximum row length, not counting @code{BLOB}
columns). A @code{BLOB} uses 5 to 8 bytes plus the length of the @code{BLOB}
data.
@item
For each table having @code{BLOB} columns, a buffer is enlarged dynamically
to read in larger @code{BLOB} values. If you scan a table, a buffer as large
as the largest @code{BLOB} value is allocated.
@item
Table handlers for all in-use tables are saved in a cache and managed as a
FIFO. Normally the cache has 64 entries. If a table has been used by two
running threads at the same time, the cache contains two entries for the
table. @xref{Table cache}.
@item
A @code{mysqladmin flush-tables} command closes all tables that are not in
use and marks all in-use tables to be closed when the currently executing
thread finishes. This will effectively free most in-use memory.
@end itemize
@code{ps} and other system status programs may report that @code{mysqld}
uses a lot of memory. This may be caused by thread-stacks on different
memory addresses. For example, the Solaris version of @code{ps} counts
the unused memory between stacks as used memory. You can verify this by
checking available swap with @code{swap -s}. We have tested
@code{mysqld} with commercial memory-leakage detectors, so there should
be no memory leaks.
@node Internal locking, Table locking, Memory use, System
@subsection How MySQL locks tables
You can find a discussion about different locking methods in the appendix.
@xref{Locking methods}.
All locking in @strong{MySQL} is deadlock-free. This is managed by always
requesting all needed locks at once at the beginning of a query and always
locking the tables in the same order.
The locking method @strong{MySQL} uses for @code{WRITE} locks works as follows:
@itemize @bullet
@item
If there are no locks on the table, put a write lock on it.
@item
Otherwise, put the lock request in the write lock queue.
@end itemize
The locking method @strong{MySQL} uses for @code{READ} locks works as follows:
@itemize @bullet
@item
If there are no write locks on the table, put a read lock on it.
@item
Otherwise, put the lock request in the read lock queue.
@end itemize
When a lock is released, the lock is made available to the threads
in the write lock queue, then to the threads in the read lock queue.
This means that if you have many updates on a table, @code{SELECT}
statements will wait until there are no more updates.
To work around this for the case where you want to do many @code{INSERT} and
@code{SELECT} operations on a table, you can insert rows in a temporary
table and update the real table with the records from the temporary table
once in a while.
This can be done with the following code:
@example
mysql> LOCK TABLES real_table WRITE, insert_table WRITE;
mysql> insert into real_table select * from insert_table;
mysql> delete from insert_table;
mysql> UNLOCK TABLES;
@end example
You can use the @code{LOW_PRIORITY} options with @code{INSERT} if you
want to prioritize retrieval in some specific cases. @xref{INSERT, ,
@code{INSERT}}.
You could also change the locking code in @file{mysys/thr_lock.c} to use a
single queue. In this case, write locks and read locks would have the same
priority, which might help some applications.
@node Table locking, , Internal locking, System
@subsection Table locking issues
The table locking code in @strong{MySQL} is deadlock free.
@strong{MySQL} uses table locking (instead of row locking or column
locking) on all table types, except @code{BDB} tables, to achieve a very
high lock speed. For large tables, table locking is MUCH better than
row locking for most applications, but there are of course some
pitfalls.
For @code{BDB} tables, @strong{MySQL} only uses table locking of you
explicitely lock the table with @code{LOCK TABLES} or execute an command that
will modify every row in the table, like @code{ALTER TABLE}.
In @strong{MySQL} 3.23.7 and above, you can insert rows into
@code{MyISAM} tables at the same time as other threads are reading from
the table. Note that currently this only works if there are no holes after
deleted rows in the table at the time the insert is made.
Table locking enables many threads to read from a table at the same
time, but if a thread wants to write to a table, it must first get
exclusive access. During the update all other threads that want to
access this particular table will wait until the update is ready.
As updates on tables normally are considered to be more important than
@code{SELECT}, all statements that update a table have higher priority
than statements that retrieve information from a table. This should
ensure that updates are not 'starved' because one issues a lot of heavy
queries against a specific table. (You can change this by using
LOW_PRIORITY with the statement that does the update or
@code{HIGH_PRIORITY} with the @code{SELECT} statement.
Starting from @strong{MySQL 3.23.7} one can use the
@code{max_write_lock_count} variable to force @strong{MySQL} to
temporary give all @code{SELECT} statements, that waits for a table, a
higher priority after a specific number of inserts on a table.
Table locking is however not very good under the following senario:
@itemize @bullet
@item
A client issues a @code{SELECT} that takes a long time to run.
@item
Another client then issues an @code{UPDATE} on a used table; This client
will wait until the @code{SELECT} is finished
@item
Another client issues another @code{SELECT} statement on the same table; As
@code{UPDATE} has higher priority than @code{SELECT}, this @code{SELECT}
will wait for the @code{UPDATE} to finish. It will also wait for the first
@code{SELECT} to finish!
@end itemize
Some possible solutions to this problem are:
@itemize @bullet
@item
Try to get the @code{SELECT} statements to run faster; You may have to create
some summary tables to do this.
@item
Start @code{mysqld} with @code{--low-priority-updates}. This will give
all statements that update (modify) a table lower priority than a @code{SELECT}
statement. In this case the last @code{SELECT} statement in the previous
scenario would execute before the @code{INSERT} statement.
@item
You can give a specific @code{INSERT},@code{UPDATE} or @code{DELETE} statement
lower priority with the @code{LOW_PRIORITY} attribute.
@item
Start @code{mysqld} with a low value for @strong{max_write_lock_count} to give
@code{READ} locks after a certain number of @code{WRITE} locks.
@item
You can specify that all updates from a specific thread should be done with
low priority by using the SQL command: @code{SET SQL_LOW_PRIORITY_UPDATES=1}.
@xref{SET OPTION, , @code{SET OPTION}}.
@item
You can specify that a specific @code{SELECT} is very important with the
@code{HIGH_PRIORITY} attribute. @xref{SELECT, , @code{SELECT}}.
@item
If you have problems with @code{INSERT} combined with @code{SELECT},
switch to use the new @code{MyISAM} tables as these supports concurrent
@code{SELECT}s and @code{INSERT}s.
@item
If you mainly mix @code{INSERT} and @code{SELECT} statements, the
@code{DELAYED} attribute to @code{INSERT} will probably solve your problems.
@xref{INSERT, , @code{INSERT}}.
@item
If you have problems with @code{SELECT} and @code{DELETE}, the @code{LIMIT}
option to @code{DELETE} may help. @xref{DELETE, , @code{DELETE}}.
@end itemize
@node Data size, MySQL indexes, System, Performance
@section Get your data as small as possible
One of the most basic optimization is to get your data (and indexes) to
take as little space on the disk (and in memory) as possible. This can
give huge improvements because disk reads are faster and normally less
main memory will be used. Indexing also takes less resources if
done on smaller columns.
@strong{MySQL} supports a lot of different table types and row formats.
Choosing the right table format may give you a big performance gain.
@xref{Table types}.
You can get better performance on a table and minimize storage space
using the techniques listed below:
@itemize @bullet
@item
Use the most efficient (smallest) types possible. @strong{MySQL} has a
many specialized types that save disk space and memory.
@item
Use the smaller integer types if possible to get smaller tables. For
example, @code{MEDIUMINT} is often better than @code{INT}.
@item
Declare columns to be @code{NOT NULL} if possible. It makes everything
faster and you save one bit per column. Note that if you really need
@code{NULL} in your application you should definitely use it, just avoid
having it on all columns by default.
@item
If you don't have any variable-length columns (@code{VARCHAR},
@code{TEXT} or @code{BLOB} columns), a fixed-size record format is
used. This is faster but unfortunately may waste some space.
@xref{MyISAM table formats}.
@item
Each table should have as short as possible primary index. This makes
identification of one row easy and efficient.
@item
For each table you have to decide which storage/index method to
use. @xref{Table types}.
@item
Only create the indexes that you really need. Indexes are good for
retrieval but bad when you need to store things fast. If you mostly
access a table by searching on a combination of columns, make an index
on them. The first index part should be the most used column. If you are
ALWAYS using many columns you should use the column with more duplicates
first to get better compression of the index.
@item
If it's very likely that a column has a unique prefix on the first number
of characters, it's better to only index this prefix. @strong{MySQL}
supports an index on a part of a character column. Shorter indexes is
faster not only because they take less disk space but also because they
will give you more hits in the index cache and thus fewer disk
seeks. @xref{Server parameters}.
@item
In some circumstances it can be beneficial to split a table that is
scanned very often into two. This is especially true if it is a dynamic
format table and it is possible to use a smaller static format table that
can be used to find the relevant rows when scanning the table.
@end itemize
@node MySQL indexes, Query Speed, Data size, Performance
@section How @strong{MySQL} uses indexes
Indexes are used to find rows with a specific value of one column
fast. Without an index @strong{MySQL} has to start with the first record
and then read through the whole table until it finds the relevent
rows. The bigger the table, the more this costs. If the table has an index
for the colums in question, @strong{MySQL} can get fast a position to
seek to in the middle of the data file without having to look at all the
data. If a table has 1000 rows this is at least 100 times faster than
reading sequentially. Note that if you need to access almost all 1000
rows it is faster to read sequentially because we then avoid disk seeks.
All @strong{MySQL} indexes (@code{PRIMARY}, @code{UNIQUE} and
@code{INDEX}) are stored in B-trees. Strings are automatically prefix-
and end-space compressed. @xref{CREATE INDEX, , @code{CREATE INDEX}}.
Indexes are used to:
@itemize @bullet
@item
Quickly find the rows that match a @code{WHERE} clause.
@item
Retrieve rows from other tables when performing joins.
@item
Find the @code{MAX()} or @code{MIN()} value for a specific indexed
column.
@example
SELECT MIN(key_part2),MAX(key_part2) FROM table_name where key_part1=10
@end example
@item
Sort or group a table if the sorting or grouping is done on a leftmost
prefix of a usable key (e.g., @code{ORDER BY key_part_1,key_part_2 }). The
key is read in reverse order if all key parts are followed by @code{DESC}.
The index can also be used even if the @code{ORDER BY} doesn't match gthe index
exactly, as long as all the not used index parts and all the extra
are @code{ORDER BY} columns are constants in the @code{WHERE} clause. The
following queries will use the index to resolve the @code{ORDER BY} part.
@example
SELECT * FROM foo ORDER BY key_part1,key_part2,key_part3;
SELECT * FROM foo WHERE column=constant ORDER BY column, key_part1;
SELECT * FROM foo WHERE key_part1=const GROUP BY key_part2;
@end example
@item
In some cases a query can be optimized to retrieve values without
consulting the data file. If all used columns for some table are numeric
and form a leftmost prefix for some key, the values may be retrieved
from the index tree for greater speed.
@example
SELECT key_part3 FROM table_name WHERE key_part1=1
@end example
@end itemize
Suppose you issue the following @code{SELECT} statement:
@example
mysql> SELECT * FROM tbl_name WHERE col1=val1 AND col2=val2;
@end example
If a multiple-column index exists on @code{col1} and @code{col2}, the
appropriate rows can be fetched directly. If separate single-column
indexes exist on @code{col1} and @code{col2}, the optimizer tries to
find the most restrictive index by deciding which index will find fewer
rows and using that index to fetch the rows.
@cindex Indexes, leftmost prefix of
@cindex Leftmost prefix of indexes
If the table has a multiple-column index, any leftmost prefix of the
index can be used by the optimizer to find rows. For example, if you
have a three-column index on @code{(col1,col2,col3)}, you have indexed
search capabilities on @code{(col1)}, @code{(col1,col2)} and
@code{(col1,col2,col3)}.
@strong{MySQL} can't use a partial index if the columns don't form a
leftmost prefix of the index. Suppose you have the @code{SELECT}
statements shown below:
@example
mysql> SELECT * FROM tbl_name WHERE col1=val1;
mysql> SELECT * FROM tbl_name WHERE col2=val2;
mysql> SELECT * FROM tbl_name WHERE col2=val2 AND col3=val3;
@end example
If an index exists on @code{(col1,col2,col3)}, only the first query
shown above uses the index. The second and third queries do involve
indexed columns, but @code{(col2)} and @code{(col2,col3)} are not
leftmost prefixes of @code{(col1,col2,col3)}.
@findex LIKE, and indexes
@findex LIKE, and wildcards
@cindex Indexes, and @code{LIKE}
@cindex Wildcards, and @code{LIKE}
@strong{MySQL} also uses indexes for @code{LIKE} comparisons if the argument
to @code{LIKE} is a constant string that doesn't start with a wildcard
character. For example, the following @code{SELECT} statements use indexes:
@example
mysql> select * from tbl_name where key_col LIKE "Patrick%";
mysql> select * from tbl_name where key_col LIKE "Pat%_ck%";
@end example
In the first statement, only rows with @code{"Patrick" <= key_col <
"Patricl"} are considered. In the second statement, only rows with
@code{"Pat" <= key_col < "Pau"} are considered.
The following @code{SELECT} statements will not use indexes:
@example
mysql> select * from tbl_name where key_col LIKE "%Patrick%";
mysql> select * from tbl_name where key_col LIKE other_col;
@end example
In the first statement, the @code{LIKE} value begins with a wildcard character.
In the second statement, the @code{LIKE} value is not a constant.
@findex IS NULL, and indexes
@cindex Indexes, and @code{IS NULL}
Searching using @code{column_name IS NULL} will use indexes if column_name
is an index.
@strong{MySQL} normally uses the index that finds least number of rows. An
index is used for columns that you compare with the following operators:
@code{=}, @code{>}, @code{>=}, @code{<}, @code{<=}, @code{BETWEEN} and a
@code{LIKE} with a non-wildcard prefix like @code{'something%'}.
Any index that doesn't span all @code{AND} levels in the @code{WHERE} clause
is not used to optimize the query. In other words: To be able to use an
index, a prefix of the index must be used in every @code{AND} group.
The following @code{WHERE} clauses use indexes:
@example
... WHERE index_part1=1 AND index_part2=2 AND other_column=3
... WHERE index=1 OR A=10 AND index=2 /* index = 1 OR index = 2 */
... WHERE index_part1='hello' AND index_part_3=5
/* optimized like "index_part1='hello'" */
... WHERE index1=1 and index2=2 or index1=3 and index3=3;
/* Can use index on index1 but not on index2 or index 3 */
@end example
These @code{WHERE} clauses do @strong{NOT} use indexes:
@example
... WHERE index_part2=1 AND index_part3=2 /* index_part_1 is not used */
... WHERE index=1 OR A=10 /* Index is not used in both AND parts */
... WHERE index_part1=1 OR index_part2=10 /* No index spans all rows */
@end example
Note that in some cases @code{MySQL} will not use an index, even if one
would be available. Some of the cases where this happens are:
@itemize @bullet
@item
If the use of the index, would require @strong{MySQL} to access more
than 30 % of the rows in the table. (In this case a table scan is
probably much faster as this will require us to do much fewer seeks).
Note that if you with such a query use @code{LIMIT} to only retrieve
part of the rows, @strong{MySQL} will use an index anyway as it can this
way much more quickly find the few rows to return in the result.
@end itemize
@node Query Speed, Tips, MySQL indexes, Performance
@section Speed of queries that access or update data
First, one thing that affects all queries: The more complex permission
system setup you have, the more overhead you get.
If you do not have any @code{GRANT} statements done @strong{MySQL} will
optimize the permission checking somewhat. So if you have a very high
volume it may be worth the time to avoid grants. Otherwise more
permission check results in a larger overhead.
If your problem is with some explicit @strong{MySQL} function, you can
always time this in the @strong{MySQL} client:
@example
mysql> select benchmark(1000000,1+1);
+------------------------+
| benchmark(1000000,1+1) |
+------------------------+
| 0 |
+------------------------+
1 row in set (0.32 sec)
@end example
The above shows that @strong{MySQL} can execute 1,000,000 @code{+}
expressions in 0.32 seconds on a @code{PentiumII 400MHz}.
All @strong{MySQL} functions should be very optimized, but there may be
some exceptions and the @code{benchmark(loop_count,expression)} is a
great tool to find out if this is a problem with your query.
@menu
* Estimating performance:: Estimating query performance
* SELECT speed:: Speed of @code{SELECT} queries
* Where optimizations:: How MySQL optimizes @code{WHERE} clauses
* LEFT JOIN optimization:: How MySQL optimizes @code{LEFT JOIN}
* LIMIT optimization:: How MySQL optimizes @code{LIMIT}
* Insert speed:: Speed of @code{INSERT} queries
* Update speed:: Speed of @code{UPDATE} queries
* Delete speed:: Speed of @code{DELETE} queries
@end menu
@node Estimating performance, SELECT speed, Query Speed, Query Speed
@subsection Estimating query performance
In most cases you can estimate the performance by counting disk seeks.
For small tables you can usually find the row in 1 disk seek (as the
index is probably cached). For bigger tables, you can estimate that,
(using B++ tree indexes), you will need: @code{log(row_count) /
log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) +
1} seeks to find a row.
In @strong{MySQL} an index block is usually 1024 bytes and the data
pointer is usually 4 bytes, which gives for a 500,000 row table with a
index length of 3 (medium integer) gives you:
@code{log(500,000)/log(1024/3*2/(3+4)) + 1} = 4 seeks.
As the above index would require about 500,000 * 7 * 3/2 = 5.2M,
(assuming that the index buffers are filled to 2/3 (which is typical)
you will probably have much of the index in memory and you will probably
only need 1-2 calls to read data from the OS to find the row.
For writes you will however need 4 seek requests (as above) to find
where to place the new index and normally 2 seeks to update the index
and write the row.
Note that the above doesn't mean that your application will slowly
degenerate by N log N! As long as everything is cached by the OS or SQL
server things will only go marginally slower while the table gets
bigger. After the data gets too big to be cached, things will start to
go much slower until your applications is only bound by disk-seeks
(which increase by N log N). To avoid this, increase the index cache as
the data grows. @xref{Server parameters}.
@node SELECT speed, Where optimizations, Estimating performance, Query Speed
@subsection Speed of @code{SELECT} queries
In general, when you want to make a slow @code{SELECT ... WHERE} faster, the
first thing to check is whether or not you can add an index. @xref{MySQL
indexes, , @strong{MySQL} indexes}. All references between different tables
should usually be done with indexes. You can use the @code{EXPLAIN} command
to determine which indexes are used for a @code{SELECT}.
@xref{EXPLAIN, , @code{EXPLAIN}}.
Some general tips:
@itemize @bullet
@item
To help @strong{MySQL} optimize queries better, run @code{myisamchk
--analyze} on a table after it has been loaded with relevant data. This
updates a value for each index part that indicates the average number of
rows that have the same value. (For unique indexes, this is always 1,
of course.). @strong{MySQL} will use this to decide which index to
choose when you connect two tables with 'a non-constant expression'.
You can check the result from the @code{analyze} run by doing @code{SHOW
INDEX FROM table_name} and examining the @code{Cardinality} column.
@item
To sort an index and data according to an index, use @code{myisamchk
--sort-index --sort-records=1} (if you want to sort on index 1). If you
have a unique index from which you want to read all records in order
according to that index, this is a good way to make that faster. Note
however that this sorting isn't written optimally and will take a long
time for a large table!
@end itemize
@cindex Optimizations
@node Where optimizations, LEFT JOIN optimization, SELECT speed, Query Speed
@subsection How MySQL optimizes @code{WHERE} clauses
The @code{WHERE} optimizations are put in the @code{SELECT} part here because
they are mostly used with @code{SELECT}, but the same optimizations apply for
@code{WHERE} in @code{DELETE} and @code{UPDATE} statements.
Also note that this section is incomplete. @strong{MySQL} does many
optimizations and we have not had time to document them all.
Some of the optimizations performed by @strong{MySQL} are listed below:
@itemize @bullet
@item
Removal of unnecessary parentheses:
@example
((a AND b) AND c OR (((a AND b) AND (c AND d))))
-> (a AND b AND c) OR (a AND b AND c AND d)
@end example
@item
Constant folding:
@example
(a<b AND b=c) AND a=5
-> b>5 AND b=c AND a=5
@end example
@item
Constant condition removal (needed because of constant folding):
@example
(B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
-> B=5 OR B=6
@end example
@item
Constant expressions used by indexes are evaluated only once.
@item
@code{COUNT(*)} on a single table without a @code{WHERE} is retrieved
directly from the table information. This is also done for any @code{NOT NULL}
expression when used with only one table.
@item
Early detection of invalid constant expressions. @strong{MySQL} quickly
detects that some @code{SELECT} statements are impossible and returns no rows.
@item
@code{HAVING} is merged with @code{WHERE} if you don't use @code{GROUP BY}
or group functions (@code{COUNT()}, @code{MIN()}...)
@item
For each sub-join, a simpler @code{WHERE} is constructed to get a fast
@code{WHERE} evaluation for each sub-join and also to skip records as
soon as possible.
@cindex Constant table
@cindex Table, constant
@item
All constant tables are read first, before any other tables in the query.
A constant table is:
@itemize @minus
@item
An empty table or a table with 1 row.
@item
A table that is used with a @code{WHERE} clause on a @code{UNIQUE}
index, or a @code{PRIMARY KEY}, where all index parts are used with constant
expressions and the index parts are defined as @code{NOT NULL}.
@end itemize
All the following tables are used as constant tables:
@example
mysql> SELECT * FROM t WHERE primary_key=1;
mysql> SELECT * FROM t1,t2
WHERE t1.primary_key=1 AND t2.primary_key=t1.id;
@end example
@item
The best join combination to join the tables is found by trying all
possibilities. If all columns in @code{ORDER BY} and in @code{GROUP
BY} come from the same table, then this table is preferred first when
joining.
@item
If there is an @code{ORDER BY} clause and a different @code{GROUP BY} clause,
or if the @code{ORDER BY} or @code{GROUP BY}
contains columns from tables other than the first table in the join
queue, a temporary table is created.
@item
If you use @code{SQL_SMALL_RESULT}, @strong{MySQL} will use an in-memory
temporary table.
@item
As @code{DISTINCT} is converted to a @code{GROUP BY} on all columns,
@code{DISTINCT} combined with @code{ORDER BY} will in many cases also need
a temporary table.
@item
Each table index is queried and the best index that spans fewer than 30% of
the rows is used. If no such index can be found, a quick table scan is used.
@item
In some cases, @strong{MySQL} can read rows from the index without even
consulting the data file. If all columns used from the index are numeric,
then only the index tree is used to resolve the query.
@item
Before each record is output, those that do not match the @code{HAVING} clause
are skipped.
@end itemize
Some examples of queries that are very fast:
@example
mysql> SELECT COUNT(*) FROM tbl_name;
mysql> SELECT MIN(key_part1),MAX(key_part1) FROM tbl_name;
mysql> SELECT MAX(key_part2) FROM tbl_name
WHERE key_part_1=constant;
mysql> SELECT ... FROM tbl_name
ORDER BY key_part1,key_part2,... LIMIT 10;
mysql> SELECT ... FROM tbl_name
ORDER BY key_part1 DESC,key_part2 DESC,... LIMIT 10;
@end example
The following queries are resolved using only the index tree (assuming
the indexed columns are numeric):
@example
mysql> SELECT key_part1,key_part2 FROM tbl_name WHERE key_part1=val;
mysql> SELECT COUNT(*) FROM tbl_name
WHERE key_part1=val1 AND key_part2=val2;
mysql> SELECT key_part2 FROM tbl_name GROUP BY key_part1;
@end example
The following queries use indexing to retrieve the rows in sorted
order without a separate sorting pass:
@example
mysql> SELECT ... FROM tbl_name ORDER BY key_part1,key_part2,...
mysql> SELECT ... FROM tbl_name ORDER BY key_part1 DESC,key_part2 DESC,...
@end example
@node LEFT JOIN optimization, LIMIT optimization, Where optimizations, Query Speed
@subsection How MySQL optimizes @code{LEFT JOIN}
@code{A LEFT JOIN B} is in @strong{MySQL} implemented as follows:
@itemize @bullet
@item
The table @code{B} is set to be dependent on table @code{A} and all tables
that @code{A} is dependent on.
@item
The table @code{A} is set to be dependent on all tables (except @code{B})
that are used in the @code{LEFT JOIN} condition.
@item
All @code{LEFT JOIN} conditions are moved to the @code{WHERE} clause.
@item
All standard join optimizations are done, with the exception that a table is
always read after all tables it is dependent on. If there is a circular
dependence then @strong{MySQL} will issue an error.
@item
All standard @code{WHERE} optimizations are done.
@item
If there is a row in @code{A} that matches the @code{WHERE} clause, but there
wasn't any row in @code{B} that matched the @code{LEFT JOIN} condition,
then an extra @code{B} row is generated with all columns set to @code{NULL}.
@item
If you use @code{LEFT JOIN} to find rows that doesn't exist in some
table and you have the following test: @code{column_name IS NULL} in the
@code{WHERE} part, where column_name is a column that is declared as
@code{NOT NULL}, then @code{MySQL} will stop searching after more rows
(for a particular key combination) after it has found one row that
matches the @code{LEFT JOIN} condition.
@end itemize
The table read order forced by @code{LEFT JOIN} and @code{STRAIGHT JOIN} will help
the join optimizer (which calculates in which order tables should be joined) to do
its work much more quickly as there are fewer table permutations to check.
Note that the above means that if you do a query of type:
@example
SELECT * FROM a,b LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key) WHERE b.key=d.key
@end example
Then @strong{MySQL} will do a full scan on @code{b} as the @code{LEFT JOIN} will
force it to be read before @code{d}.
The fix in this case is to change the query to:
@example
SELECT * FROM b,a LEFT JOIN c ON (c.key=a.key) LEFT JOIN d (d.key=a.key) WHERE b.key=d.key
@end example
@node LIMIT optimization, Insert speed, LEFT JOIN optimization, Query Speed
@subsection How MySQL optimizes @code{LIMIT}
In some cases @strong{MySQL} will handle the query differently when you are
using @code{LIMIT #} and not using @code{HAVING}:
@itemize @bullet
@item
If you are selecting only a few rows with @code{LIMIT}, @strong{MySQL}
will use indexes in some cases when it normally would prefer to do a
full table scan.
@item
If you use @code{LIMIT #} with @code{ORDER BY}, @strong{MySQL} will end the
sorting as soon as it has found the first @code{#} lines instead of sorting
the whole table.
@item
When combining @code{LIMIT #} with @code{DISTINCT}, @strong{MySQL} will stop
as soon as it finds @code{#} unique rows.
@item
In some cases a @code{GROUP BY} can be resolved by reading the key in order
(or do a sort on the key) and then calculate summaries until the
key value changes. In this case @code{LIMIT #} will not calculate any
unnecessary @code{GROUP BY}'s.
@item
As soon as @strong{MySQL} has sent the first @code{#} rows to the client, it
will abort the query.
@item
@code{LIMIT 0} will always quickly return an empty set. This is useful
to check the query and to get the column types of the result columns.
@item
The size of temporary tables uses the @code{LIMIT #} to calculate how much
space is needed to resolve the query.
@end itemize
@node Insert speed, Update speed, LIMIT optimization, Query Speed
@subsection Speed of @code{INSERT} queries
The time to insert a record consists approximately of:
@itemize @bullet
@item
Connect: (3)
@item
Sending query to server: (2)
@item
Parsing query: (2)
@item
Inserting record: (1 x size of record)
@item
Inserting indexes: (1 x number of indexes)
@item
Close: (1)
@end itemize
Where the numbers are somewhat proportional to the overall time. This
does not take into consideration the initial overhead to open tables
(which is done once for each concurrently-running query).
The size of the table slows down the insertion of indexes by N log N
(B-trees).
Some ways to speed up inserts:
@itemize @bullet
@item
If you are inserting many rows from the same client at the same time use
multiple value lists @code{INSERT} statements. This is much faster (many
times in some cases) than using separate @code{INSERT} statements.
@item
If you are inserting a lot of rows from different clients, you can get
higher speed by using the @code{INSERT DELAYED} statement. @xref{INSERT,
, @code{INSERT}}.
@item
Note that with @code{MyISAM} you can insert rows at the same time
@code{SELECT}s are running if there are no deleted rows in the tables.
@item
When loading a table from a text file, use @code{LOAD DATA INFILE}. This
is usually 20 times faster than using a lot of @code{INSERT} statements.
@xref{LOAD DATA, , @code{LOAD DATA}}.
@item
It is possible with some extra work to make @code{LOAD DATA INFILE} run even
faster when the table has many indexes. Use the following procedure:
@enumerate
@item
Optionally create the table with @code{CREATE TABLE}. For example using
@code{mysql} or Perl-DBI.
@item
Execute a @code{FLUSH TABLES} statement or the shell command @code{mysqladmin
flush-tables}.
@item
Use @code{myisamchk --keys-used=0 -rq /path/to/db/tbl_name}. This will
remove all usage of all indexes from the table.
@item
Insert data into the table with @code{LOAD DATA INFILE}. This will not
update any indexes and will therefore be very fast.
@item
If you are going to only read the table in the future, run @code{myisampack}
on it to make it smaller. @xref{Compressed format}.
@item
Recreate the indexes with @code{myisamchk -r -q
/path/to/db/tbl_name}. This will create the index tree in memory before
writing it to disk, which is much faster because it avoid lots of disk
seeks. The resulting index tree is also perfectly balanced.
@item
Execute a @code{FLUSH TABLES} statement or the shell command @code{mysqladmin
flush-tables}.
@end enumerate
This procedure will be built into @code{LOAD DATA INFILE} in some future
version of MySQL.
@item
You can speed up insertions by locking your tables:
@example
mysql> LOCK TABLES a WRITE;
mysql> INSERT INTO a VALUES (1,23),(2,34),(4,33);
mysql> INSERT INTO a VALUES (8,26),(6,29);
mysql> UNLOCK TABLES;
@end example
The main speed difference is that the index buffer is flushed to disk only
once, after all @code{INSERT} statements have completed. Normally there would
be as many index buffer flushes as there are different @code{INSERT}
statements. Locking is not needed if you can insert all rows with a single
statement.
Locking will also lower the total time of multi-connection tests, but the
maximum wait time for some threads will go up (because they wait for
locks). For example:
@example
thread 1 does 1000 inserts
thread 2, 3, and 4 does 1 insert
thread 5 does 1000 inserts
@end example
If you don't use locking, 2, 3 and 4 will finish before 1 and 5. If you
use locking, 2, 3 and 4 probably will not finish before 1 or 5, but the
total time should be about 40% faster.
As @code{INSERT}, @code{UPDATE} and @code{DELETE} operations are very
fast in @strong{MySQL}, you will obtain better overall performance by
adding locks around everything that does more than about 5 inserts or
updates in a row. If you do very many inserts in a row, you could do a
@code{LOCK TABLES} followed by a @code{UNLOCK TABLES} once in a while
(about each 1000 rows) to allow other threads access to the table. This
would still result in a nice performance gain.
Of course, @code{LOAD DATA INFILE} is much faster still for loading data.
@end itemize
To get some more speed for both @code{LOAD DATA INFILE} and
@code{INSERT}, enlarge the key buffer. @xref{Server parameters}.
@node Update speed, Delete speed, Insert speed, Query Speed
@subsection Speed of @code{UPDATE} queries
Update queries are optimized as a @code{SELECT} query with the additional
overhead of a write. The speed of the write is dependent on the size of
the data that is being updated and the number of indexes that are
updated. Indexes that are not changed will not be updated.
Also another way to get fast updates is to delay updates and then do
many updates in a row later. Doing many updates in a row is much quicker
than doing one at a time if you lock the table.
Note that, with dynamic record format, updating a record to
a longer total length may split the record. So if you do this often
it is very important to @code{OPTIMIZE TABLE} sometimes.
@xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}.
@node Delete speed, , Update speed, Query Speed
@subsection Speed of @code{DELETE} queries
The time to delete a record is exactly proportional to the number of
indexes. To delete records more quickly, you can increase the size of
the index cache. @xref{Server parameters}.
It's also much faster to remove all rows than to remove a big part of the
rows from a table.
@node Tips, Benchmarks, Query Speed, Performance
@section Other optimization tips
Unsorted tips for faster systems:
@itemize @bullet
@item
Use persistent connections to the database to avoid the connection
overhead. If you can't use persistent connections and you are doing a
lot of new connections to the database, you may want to change the value
of the @code{thread_cache_size} variable. @xref{Server parameters}.
@item
Always check that all your queries really use the indexes you have created
in the tables. In @strong{MySQL} you can do this with the @code{EXPLAIN}
command. @xref{EXPLAIN, Explain, Explain, manual}.
@item
Try to avoid complex @code{SELECT} queries on tables that are updated a
lot. This is to avoid problems with table locking.
@item
The new @code{MyISAM} tables can insert rows in a table without deleted
rows at the same time another table is reading from it. If this is important
for you, you should consider methods where you don't have to delete rows
or run @code{OPTIMIZE TABLE} after you have deleted a lot of rows.
@item
In some cases it may make sense to introduce a column that is 'hashed'
based on information from other columns. If this column is short and
reasonably unique it may be much faster than a big index on many
columns. In @strong{MySQL} its very easy to use this extra column:
@code{SELECT * FROM table_name WHERE hash=MP5(concat(col1,col2))
AND col_1='constant' AND col_2='constant'}
@item
For tables that changes a lot you should try to avoid all @code{VARCHAR}
or @code{BLOB} columns. You will get dynamic row length as soon as you
are using a single @code{VARCHAR} or @code{BLOB} columns. @xref{Table
types}.
@item
It's not normally useful to split a table into different tables just
because the rows gets 'big'. To access a row, the biggest performance
hit is the disk seek to find the first byte of the row. After finding
the data most new disks can read the whole row fast enough for most
applications. The only cases it really matters to split up a table is if
its a dynamic row size table (see above) that you can change to a fixed
row size. Or if you very often need to scan the table and don't need
most of the columns. @xref{Table types}.
@item
If you very often need to calculate things based on information from a
lot of rows (like counts of things) it's probably much better to
introduce a new table and update the counter in real time. An update of
type @code{UPDATE table set count=count+1 where index_column=constant}
is very fast!
This is really important when you use databases like @strong{MySQL} that
only has table locking (multiple readers / single writers). This will
also give better performance with most databases as the row locking
manager in this case will have less to do.
@item
If you need to collect statistics from big log tables, use summary tables
instead of scanning the whole table. Maintaining the summaries should be
much faster than trying to do statistics 'live'. It's much faster to
re-generate new summary tables from the logs when things change
(depending on business decisions) than to have to change the running
application!
@item
If possible one should classify reports as 'live' or 'statistical',
where data needed for statistical reports are only generated based on
summary tables that are generated from the actual data.
@item
Take advantage of the fact that columns have default values. Insert
values explicitly only when the value to be inserted differs from the
default. This reduces the parsing that @strong{MySQL} need to do and
improves the insert speed.
@item
In some cases it's convenient to pack and store data into a blob. In this
case you have to add some extra code in your appliction to pack/unpack
things in the blob but this may save a lot of accesses at some stage.
This is practical when you have data that doesn't conform to a static
table structure.
@item
Normally you should try to keep all data non-redundant (what
is called 3rd normal form in database theory), but you should not be
afraid of duplicating things or creating summary tables if you need these
to gain more speed.
@item
Stored procedures or UDF (user defined functions) may be a good way to
get more performance. In this case you should however always have a way
to do this some other (slower) way if you use some database that doesn't
support this.
@item
You can always gain something by caching queries/answers in your
application and trying to do many inserts/updates at the same time. If
your database supports lock tables (like @strong{MySQL} and Oracle),
this should help to ensure that the index cache is only flushed once
after all updates.
@item
Use @code{INSERT /*! DELAYED */} when you do not need to know when your
data is written. This speeds things up because many records can be written
with a single disk write.
@item
Use @code{INSERT /*! LOW_PRIORITY */} when you want your selects to be
more important.
@item
Use @code{SELECT /*! HIGH_PRIORITY */} to get selects that jump the
queue. That is the select is done even if there is somebody waiting to
do a write.
@item
Use the multi-line @code{INSERT} statement to store many rows with one
SQL command (many SQL servers supports this).
@item
Use @code{LOAD DATA INFILE} to load bigger amounts of data. This is
faster than normal inserts and will be even faster when @code{myisamchk}
is integrated in @code{mysqld}.
@item
Use @code{AUTO_INCREMENT} columns to make unique values.
@item
Use @code{OPTIMIZE TABLE} once in a while to avoid fragmentation when
using dynamic table format. @xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}.
@item
Use @code{HEAP} tables to get more speed when possible. @xref{Table
types}.
@item
When using a normal web server setup, images should be stored as
files. That is, store only a file reference in the database. The main
reason for this is that a normal web server is much better at caching
files than database contents. So it it's much easier to get a fast
system if you are using files.
@item
Use in memory tables for non-critical data that are accessed often (like
information about the last shown banner for users that doesn't have
cookies).
@item
Columns with identical information in different tables should be
declared identical and have identical names. Before version 3.23 you
got slow joins otherwise.
Try to keep the names simple (use @code{name} instead of
@code{customer_name} in the customer table). To make your names portable
to other SQL servers you should keep them shorter than 18 characters.
@item
If you need REALLY high speed you should take a look at the low level
interfaces for data storage that the different SQL servers support! For
example by accessing the @strong{MySQL} @code{MyISAM} directly you could
get a speed increase of 2-5 times compared to using the SQL interface.
To be able to do this the data must however be on the same server as
the application and usually it should only be accessed by one process
(because external file locking is really slow). One could eliminate the
above problems by introducing low-level @code{MyISAM} commands in the
@strong{MySQL} server (this could be one easy way to get more
performance if needed). By carefully designing the database interface
it should be quite easy to support this types of optimization.
@item
In many cases it's faster to access data from a database (using a live
connection) than accessing a text file, just because the database is
likely to be more compact than the text file (if you are using numerical
data) and this will involve fewer disk accesses. You will also save
code because you don't have to parse your text files to find line and
column boundaries.
@item
You can also use replication to speed things up. @xref{Replication}.
@item
Declaring a table with @code{DELAY_KEY_WRITE=1} will make the updating of
indexes faster as these are not logged to disk until the file is closed.
The downside is that you should run @code{myisamchk} on these tables before
you start @code{mysqld} to ensure that they are okay if something killed
@code{mysqld} in the middle. As the key information can always be generated
from the data you should not lose anything by using @code{DELAY_KEY_WRITE}.
@end itemize
@node Benchmarks, Design, Tips, Performance
@section Using your own benchmarks
You should definately benchmark your application and database to find
out where the bottlenecks are. By fixing it (or by replacing the
bottleneck with a 'dummy module') you can then easily identify the next
bottleneck (and so on). Even if the overall performance for your
application is sufficient you should at least make a plan for each
bottleneck, and decide how to solve it if someday you really need the
extra performance.
For an example of portable benchmark programs look at the @strong{MySQL}
benchmark suite. @xref{MySQL Benchmarks, , @strong{MySQL} Benchmarks}. You
can take any program from this suite and modify it for your needs. By doing this,
you can try different solutions to your problem and test which is really the
fastest solution for you.
It is very common that some problems only occur when the system is very
heavily loaded. We have had many customers who contact us when they
have a (tested) system in production and have encountered load problems. In
every one of these cases so far it has been problems with basic design
(table scans are NOT good at high load) or OS/Library issues. Most of
this would be a @strong{LOT} easier to fix if the systems were not
already in production.
To avoid problems like this you should put some effort into benchmarking
your whole application under the worst possible load! You can use Sasha's
recent hack for this -
@uref{http://www.mysql.com/Downloads/Contrib/mysql-bench-0.6.tar.gz, mysql-super-smack}.
As the name suggests, it can bring your system down to its knees if you ask it,
so make sure to use it only on your developement systems.
@node Design, Design Limitations, Benchmarks, Performance
@section Design choices
@strong{MySQL} keeps row data and index data in separate files. Many (almost
all) other databases mix row and index data in the same file. We believe that
the @strong{MySQL} choice is better for a very wide range of modern systems.
Another way to store the row data is to keep the information for each
column in a separate area (examples are SDBM and Focus). This will cause a
performance hit for every query that accesses more than one column. Because
this degenerates so quickly when more than one column is accessed,
we believe that this model is not good for general purpose databases.
The more common case is that the index and data are stored together
(like in Oracle/Sybase et al). In this case you will find the row
information at the leaf page of the index. The good thing with this
layout is that it, in many cases, depending on how well the index is
cached, saves a disk read. The bad things with this layout is:
@table @bullet
@item
Table scanning is much slower because you have to read through the indexes
to get at the data.
@item
You can't use only the index table to retrieve data for a query.
@item
You lose a lot of space as you must duplicate indexes from the nodes
(as you can't store the row in the nodes).
@item
Deletes will degenerate the table over time (as indexes in nodes are
usually not updated on delete).
@item
It's harder to cache ONLY the index data.
@end table
@node Design Limitations, Portability, Design, Performance
@section MySQL design limitations/tradeoffs
Because @strong{MySQL} uses extremely fast table locking (multiple readers /
single writers) the biggest remaining problem is a mix of a steady stream of
inserts and slow selects on the same table.
We believe that for a huge number of systems the extremely fast
performance in other cases make this choice a win. This case is usually
also possible to solve by having multiple copies of the table, but it
takes more effort and hardware.
We are also working on some extensions to solve this problem for some
common application niches.
@node Portability, Internal use, Design Limitations, Performance
@section Portability
Because all SQL servers implement different parts of SQL, it takes work to
write portable SQL applications. For very simple selects/inserts it is
very easy but the more you need the harder it gets. If you want an
application that is fast with many databases it becomes even harder!
To make a complex application portable you need to choose a number of
SQL servers that it should work with.
You can use the @strong{MySQL} crash-me program/web-page
@uref{http://www.mysql.com/information/crashme/choose.php} to find functions,
types and limits you can use with a selection of database
servers. Crash-me now tests far from everything possible but it
is still comprehensive with about 450 things tested.
For example, you shouldn't have column names longer than 18 characters
if you want to be able to use Informix or DB2.
Both the @strong{MySQL} benchmarks and crash-me programs are very
database-independent. By taking a look at how we have handled this, you
can get a feeling of what you have to do to write your application
database-independent. The benchmarks themselves can be found in the
@file{sql-bench} directory in the @strong{MySQL} source
distribution. They are written in Perl with DBI database interface
(which solves the access part of the problem).
See @uref{http://www.mysql.com/information/benchmarks.html} the results
from this benchmark.
As you can see in these results all databases have some weak points. That
is, they have different design compromises that lead to different
behavior.
If you strive for database independence you need to get a good feeling
of each SQL server's bottlenecks. @strong{MySQL} is VERY fast in
retrieving and updating things, but will have a problem in mixing slow
readers/writers on the same table. Oracle on the other hand has a big
problem when you try to access rows that you have recently updated
(until they are flushed to disk). Transaction databases in general are
not very good at generating summary tables from log tables as in this
case row locking is almost useless.
To get your application @emph{really} database-independent you need to define
an easy extendable interface through which you manipulate your data. As
C++ is available on most systems, it makes sense to use a C++ classes
interface to the databases.
If you use some specific feature for some database (like the
@code{REPLACE} command in @strong{MySQL}), you should code a method for
the other SQL servers to implement the same feature (but slower). With
@strong{MySQL} you can use the @code{/*! */} syntax to add
@strong{MySQL} specific keywords to a query. The code inside
@code{/**/} will be treated as a comment (ignored) by most other SQL
servers.
If REAL high performance is more important than exactness, like in some
web applications, a possibility is to create an application layer that
caches all results to give you even higher performance. By letting
old results 'expire' after a while you can keep the cache reasonably
fresh. This is quite nice in case of extremely high load, in which case
you can dynamically increase the cache and set the expire timeout higher
until things get back to normal.
In this case the table creation information should contain information
of the initial size of the cache and how often the table should normally
be refreshed.
@node Internal use, , Portability, Performance
@section What have we used MySQL for?
During @strong{MySQL} initial development, the features of @strong{MySQL} were made to fit
our largest customer. They handle data warehousing for a couple of the
biggest retailers in Sweden.
From all stores, we get weekly summaries of all bonus card transactions
and we are expected to provide useful information for the store owners
to help them find how their advertisement campaigns are affecting their
customers.
The data is quite huge (about 7 million summary transactions per month)
and we have data for 4-10 years that we need to present to the users.
We got weekly requests from the customers that they want to get
'instant' access to new reports from this data.
We solved this by storing all information per month in compressed
'transaction' tables. We have a set of simple macros (script) that
generates summary tables grouped by different criteria (product group,
customer id, store ...) from the transaction tables. The reports are
web pages that are dynamically generated by a small Perl script that
parses a web page, executes the SQL statements in it and inserts the
results. We would have used PHP or mod_perl instead but they were
not available at that time.
For graphical data we wrote a simple tool in @code{C} that can produce
GIFs based on the result of a SQL query (with some processing of the
result). This is also dynamically executed from the Perl script that
parses the @code{HTML} files.
In most cases a new report can simply be done by copying an existing
script and modifying the SQL query in it. In some cases we will need to
add more fields to an existing summary table or generate a new one, but
this is also quite simple as we keep all transactions tables on disk.
(Currently we have at least 50G of transactions tables and 200G of other
customer data).
We also let our customers access the summary tables directly with ODBC
so that the advanced users can themselves experiment with the data.
We haven't had any problems handling this with quite modest Sun Ultra
SPARCstation (2x200 Mhz). We recently upgraded one of our servers to a 2
CPU 400 Mhz UltraSPARC and we are now planning to start handling
transactions on the product level, which would mean a ten-fold increase
of data. We think we can keep up with this by just adding more disk to
our systems.
We are also experimenting with Intel-Linux to be able to get more CPU
power cheaper. Now that we have the binary portable database format (new
in 3.32) we will start to use this for some parts of the application.
Our initial feelings are that Linux will perform much better on low to
medium load but Solaris will perform better when you start to get a
high load because of extreme disk IO, but we don't yet have anything
conclusive about this. After some discussion with a Linux Kernel
developer this might be a side effect of Linux giving so much resources
to the batch job that the interactive performance gets very low. This
makes the machine feel very slow and unresponsive while big batches are
going. Hopefully this will be better handled in future Linux Kernels.
@node MySQL Benchmarks, Tools, Performance, Top
@chapter The MySQL benchmark suite
This should contain a technical description of the @strong{MySQL}
benchmark suite (and @code{crash-me}) but that description is not
written yet. Currently, you should look at the code and results in the
@file{sql-bench} directory in the distribution (and of course on the Web page
at @uref{http://www.mysql.com/crashme/choose.php} and (normally found in
the @file{sql-bench} directory in the @strong{MySQL} distribution)).
It is meant to be a benchmark that will tell any user what things a
given SQL implementation performs well or poorly at.
Note that this benchmark is single threaded so it measures the minimum
time for the operations.
For example (run on the same NT 4.0 machine):
@multitable @columnfractions .6 .2 .2
@strong{Reading 2000000 rows by index} @tab @strong{Seconds} @tab @strong{Seconds}
@item mysql @tab 367 @tab 249
@item mysql_odbc @tab 464
@item db2_odbc @tab 1206
@item informix_odbc @tab 121126
@item ms-sql_odbc @tab 1634
@item oracle_odbc @tab 20800
@item solid_odbc @tab 877
@item sybase_odbc @tab 17614
@end multitable
@multitable @columnfractions .6 .2 .2
@strong{Inserting (350768) rows} @tab @strong{Seconds} @tab @strong{Seconds}
@item mysql @tab 381 @tab 206
@item mysql_odbc @tab 619
@item db2_odbc @tab 3460
@item informix_odbc @tab 2692
@item ms-sql_odbc @tab 4012
@item oracle_odbc @tab 11291
@item solid_odbc @tab 1801
@item sybase_odbc @tab 4802
@end multitable
In the above test @strong{MySQL} was run with a 8M index cache.
Note that Oracle is not included because they asked to be removed. All
Oracle benchmarks has to be passed by Oracle! We believe that makes
Oracle benchmarks @strong{VERY} biased because the above benchmarks are
supposed to show what a standard installation can do for a single
client.
@code{crash-me} tries to determine what features a database supports and
what it's capabilities and limitations are by actually running
queries. For example, it determines:
@itemize @bullet
@item
What column types are supported
@item
How many indexes are supported
@item
What functions are supported
@item
How big a query can be
@item
How big a @code{VARCHAR} column can be
@end itemize
@node Tools, Maintenance, MySQL Benchmarks, Top
@chapter MySQL Utilites
@menu
* Programs:: What do the executables do?
* mysql:: The command line tool
* mysqladmin:: Administering a @strong{MySQL} server
* mysqldump:: Dumping the structure and data from @strong{MySQL} databases and tables
* mysqlimport:: Importing data from text files
* mysqlshow:: Showing databases, tables and columns
* myisampack:: The @strong{MySQL} compressed read-only table generator
@end menu
@cindex Environment variables
@node Programs, mysql, Tools, Tools
@section Overview of the different MySQL programs
All @strong{MySQL} clients that communicate with the server using the
@code{mysqlclient} library use the following environment variables:
@tindex MYSQL_UNIX_PORT environment variable
@tindex Environment variable, MYSQL_UNIX_PORT
@tindex MYSQL_TCP_PORT environment variable
@tindex Environment variable, MYSQL_TCP_PORT
@tindex MYSQL_PWD environment variable
@tindex Environment variable, MYSQL_PWD
@tindex MYSQL_DEBUG environment variable
@tindex Environment variable, MYSQL_DEBUG
@multitable @columnfractions .25 .75
@item @strong{Name} @tab @strong{Description}
@item @code{MYSQL_UNIX_PORT} @tab The default socket; used for connections to @code{localhost}
@item @code{MYSQL_TCP_PORT} @tab The default TCP/IP port
@item @code{MYSQL_PWD} @tab The default password
@item @code{MYSQL_DEBUG} @tab Debug-trace options when debugging
@item @code{TMPDIR} @tab The directory where temporary tables/files are created
@end multitable
Use of @code{MYSQL_PWD} is insecure.
@xref{Connecting}.
@tindex MYSQL_HISTFILE environment variable
@tindex Environment variable, MYSQL_HISTFILE
@tindex HOME environment variable
@tindex Environment variable, HOME
@cindex History file
@cindex Command line history
@tindex .mysql_history file
The @file{mysql} client uses the file named in the @code{MYSQL_HISTFILE}
environment variable to save the command line history. The default value for
the history file is @file{$HOME/.mysql_history}, where @code{$HOME} is the
value of the @code{HOME} environment variable. @xref{Environment variables}.
All @strong{MySQL} programs take many different options. However, every
@strong{MySQL} program provides a @code{--help} option that you can use
to get a full description of the program's different options. For example, try
@code{mysql --help}.
You can override default options for all standard client programs with an
option file. @ref{Option files}.
The list below briefly describes the @strong{MySQL} programs:
@table @code
@cindex @code{myisamchk}
@item myisamchk
Utility to describe, check, optimize and repair @strong{MySQL} tables.
Because @code{myisamchk} has many functions, it is described in its own
chapter. @xref{Maintenance}.
@cindex @code{make_binary_distribution}
@item make_binary_distribution
Makes a binary release of a compiled @strong{MySQL}. This could be sent
by FTP to @file{/pub/mysql/Incoming} on @code{support.mysql.com} for the
convenience of other @strong{MySQL} users.
@cindex @code{msql2mysql}
@item msql2mysql
A shell script that converts @code{mSQL} programs to @strong{MySQL}. It doesn't
handle all cases, but it gives a good start when converting.
@cindex @code{mysqlaccess}
@item mysqlaccess
A script that checks the access privileges for a host, user and database
combination.
@cindex @code{mysqladmin}
@item mysqladmin
Utility for performing administrative operations, such as creating or
dropping databases, reloading the grant tables, flushing tables to disk and
reopening log files. @code{mysqladmin} can also be used to retrieve version,
process and status information from the server.
@xref{mysqladmin, , @code{mysqladmin}}.
@cindex @code{mysqlbug}
@item mysqlbug
The @strong{MySQL} bug report script. This script should always be used when
filing a bug report to the @strong{MySQL} list.
@cindex @code{mysqld}
@item mysqld
The SQL daemon. This should always be running.
@cindex @code{mysqldump}
@item mysqldump
Dumps a @strong{MySQL} database into a file as SQL statements or
as tab-separated text files. Enhanced freeware originally by Igor Romanenko.
@xref{mysqldump, , @code{mysqldump}}.
@cindex @code{mysqlimport}
@item mysqlimport
Imports text files into their respective tables using @code{LOAD DATA
INFILE}. @xref{mysqlimport, , @code{mysqlimport}}.
@cindex @code{mysqlshow}
@item mysqlshow
Displays information about databases, tables, columns and indexes.
@cindex @code{mysql_install_db}
@item mysql_install_db
Creates the @strong{MySQL} grant tables with default privileges. This is
usually executed only once, when first installing @strong{MySQL}
on a system.
@cindex @code{replace}
@item replace
A utility program that is used by @code{msql2mysql}, but that has more
general applicability as well. @code{replace} changes strings in place in
files or on the standard input. Uses a finite state machine to match longer
strings first. Can be used to swap strings. For example, this command
swaps @code{a} and @code{b} in the given files:
@example
shell> replace a b b a -- file1 file2 ...
@end example
@cindex @code{safe_mysqld}
@item safe_mysqld
A script that starts the @code{mysqld} daemon with some safety features, such
as restarting the server when an error occurs and logging runtime information
to a log file.
@end table
@cindex Scripts
@cindex @code{mysql}
@node mysql, mysqladmin, Programs, Tools
@section The command line tool
@code{mysql} is a simple SQL shell (with GNU @code{readline} capabilities).
It supports interactive and non-interactive use. When used interactively,
query results are presented in an ASCII-table format. When used
non-interactively (e.g., as a filter), the result is presented in
tab-separated format. (The output format can be changed using command-line
options.) You can run scripts simply like this:
@example
shell> mysql database < script.sql > output.tab
@end example
If you have problems due to insufficient memory in the client, use the
@code{--quick} option! This forces @code{mysql} to use
@code{mysql_use_result()} rather than @code{mysql_store_result()} to
retrieve the result set.
Using @code{mysql} is very easy; Just start it as follows
@code{mysql database} or @code{mysql --user=user_name --password=your_password database}. Type a SQL statement, end it with @samp{;}, @samp{\g} or @samp{\G}
and press return/enter.
@code{mysql} supports the following options:
@table @code
@item -?, --help
Display this help and exit
@item -A, --no-auto-rehash
No automatic rehashing. One has to use 'rehash' to get table and field
completion. This gives a quicker start of mysql.
@item -B, --batch
Print results with a tab as separator, each row on a new line. Doesn't use
history file.
@item -C, --compress
Use compression in server/client protocol.
@item -#, --debug[=...]
Debug log. Default is 'd:t:o,/tmp/mysql.trace'
@item -D, --database=..
Database to use; This is mainly useful in the @code{my.cnf} file.
@item -e, --execute=...
Execute command and quit. (Output like with --batch)
@item -E, --vertical
Print the output of a query (rows) vertically. Without this option you
can also force this output by ending your statements with @code{\G}.
@item -f, --force
Continue even if we get a SQL error.
@item -i, --ignore-space
Ignore space after function names.
@item -h, --host=...
Connect to the given host.
@item -H, --html
Produce HTML output.
@item -L, --skip-line-numbers
Don't write line number for errors. Useful when one want's to compare result
files that includes error messages.
@item -n, --unbuffered
Flush buffer after each query.
@item -N, --skip-column-names
Don't write column names in results.
@item -O, --set-variable var=option
Give a variable a value. @code{--help} lists variables.
@item -o, --one-database
Only update the default database. This is useful for skipping updates to
other database in the update log.
@item
@item -p[password], --password[=...]
Password to use when connecting to server. If password is not given on
the command line, you will be prompted for it. Note that if you use the
short form @code{-p} you can't have a space between the option and the
password.
@item -P --port=...
TCP/IP port number to use for connection.
@item -q, --quick
Don't cache result, print it row-by-row. This may slow down the server
if the output is suspended. Doesn't use history file.
@item -r, --raw
Write column values without escape conversion. Used with @code{--batch}
@item -s, --silent
Be more silent.
@item -S --socket=...
Socket file to use for connection.
@item -t --table
Output in table format. This is default in non-batch mode.
@item -T, --exit-info
Only used when debugging. --exit-info=0 will print some usage information
on exit.
@item -u, --user=#
User for login if not current user.
@item -U, --safe-updates[=#], --i-am-a-dummy[=#]
Only allow @code{UPDATE} and @code{DELETE} that uses keys. See below for
more information about this option. You can reset this option if you have
it in your @code{my.cnf} file by using @code{--safe-updates=0}.
@item -v, --verbose
More verbose output (-v -v -v gives the table output format).
@item -V, --version
Output version information and exit.
@item -w, --wait
Wait and retry if connection is down instead of aborting.
@end table
If you type 'help' on the command line, @code{mysql} will print out the
commands that it supports:
@example
mysql> help
MySQL commands:
help (\h) Display this text
? (\h) Synonym for `help'
clear (\c) Clear command
connect (\r) Reconnect to the server. Optional arguments are db and host
edit (\e) Edit command with $EDITOR
exit (\q) Exit mysql. Same as quit
go (\g) Send command to mysql server
ego (\G) Send command to mysql server; Display result vertically
print (\p) Print current command
quit (\q) Quit mysql
rehash (\#) Rebuild completion hash
source (\.) Execute a SQL script file. Takes a file name as an argument
status (\s) Get status information from the server
use (\u) Use another database. Takes database name as argument
@end example
The @code{status} command gives you some information about the
connection and the server you are using. If you are running in the
@code{--safe-updates} mode, @code{status} will also print the values for
the @code{mysql} variables that affects your queries.
A useful startup option for beginners (introduced in @strong{MySQL} 3.23.11) is
@code{--safe-mode} (or @code{--i-am-a-dummy} for users that has at some
time done a @code{DELETE FROM table_name} but forgot the @code{WHERE}
clause. When using this option, @code{mysql} sends the following
command to the @strong{MySQL} server when opening the connection:
@example
SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#,
SQL_MAX_JOIN_SIZE=#max_join_size#"
@end example
where @code{#select_limit#} and @code{#max_join_size#} are variables that
can be set from the @code{mysql} command line. @xref{SET OPTION, @code{SET}}.
The effect of the above is:
@itemize @bullet
@item
You are not allowed to do an @code{UPDATE} or @code{DELETE} statements
if you don't have a key constraint in the @code{WHERE} part. One can
however force an @code{UPDATE/DELETE} by using @code{LIMIT}:
@example
UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1;
@end example
@item
All big results are automatically limited to @code{#select_limit#} rows.
@item
@code{SELECT}'s that will probably need to examine more than
@code{#max_join_size} row combinations will be aborted.
@end itemize
@node mysqladmin, mysqldump, mysql, Tools
@section Administering a MySQL server
Utility for performing administrative operations. The syntax is:
@example
shell> mysqladmin [OPTIONS] command [command-option] command ...
@end example
You can get a list of the options your version of @code{mysqladmin} supports
by executing @code{mysqladmin --help}.
The current @code{mysqladmin} supports the following commands:
@multitable @columnfractions .3 .7
@item create databasename @tab Create a new database.
@item drop databasename @tab Delete a database and all its tables.
@item extended-status @tab Gives an extended status message from the server.
@item flush-hosts @tab Flush all cached hosts.
@item flush-logs @tab Flush all logs.
@item flush-tables @tab Flush all tables.
@item flush-privileges @tab Reload grant tables (same as reload).
@item kill id,id,... @tab Kill mysql threads.
@item password @tab new-password Change old password to new-password.
@item ping @tab Check if mysqld is alive.
@item processlist @tab Show list of active threads in server.
@item reload @tab Reload grant tables.
@item refresh @tab Flush all tables and close and open logfiles.
@item shutdown @tab Take server down.
@item slave-start @tab Start slave replication thread.
@item slave-stop @tab Stop slave replication thread.
@item status @tab Gives a short status message from the server.
@item variables @tab Prints variables available.
@item version @tab Get version info from server.
@end multitable
All commands can be shortened to their unique prefix. For example:
@example
shell> mysqladmin proc stat
+----+-------+-----------+----+-------------+------+-------+------+
| Id | User | Host | db | Command | Time | State | Info |
+----+-------+-----------+----+-------------+------+-------+------+
| 6 | monty | localhost | | 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
@end example
The @code{mysqladmin status} command result has the following columns:
@multitable @columnfractions .3 .7
@item Uptime @tab Number of seconds the @strong{MySQL} server has been up.
@item Threads @tab Number of active threads (clients).
@item Questions @tab Number of questions from clients since @code{mysqld} was started.
@item Slow queries @tab Queries that have taken more than @code{long_query_time} seconds.
@item Opens @tab How many tables @code{mysqld} has opened.
@item Flush tables @tab Number of @code{flush ...}, @code{refresh} and @code{reload} commands.
@item Open tables @tab Number of tables that are open now.
@item Memory in use @tab Memory allocated directly by the mysqld code (only available when @strong{MySQL} is compiled with --with-debug).
@item Max memory used @tab Maximum memory allocated directly by the mysqld code (only available when @strong{MySQL} is compiled with --with-debug).
@end multitable
If you do @code{myslqadmin shutdown} on a socket (in other words, on a
the computer where @code{mysqld} is running), @code{mysqladmin} will
wait until the @code{MySQL} @code{pid-file} is removed to ensure that
the @code{mysqld server} has stopped properly.
@node mysqldump, mysqlimport, mysqladmin, Tools
@section Dumping the structure and data from MySQL databases and tables
Utility to dump a database or a collection of database for backup or
for transferring the data to another SQL server. The dump will contain SQL
statements to create the table and/or populate the table.
@example
shell> mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
@end example
If you don't give any tables or use the @code{--databases} or
@code{--all-databases}, the whole database(s) will be dumped.
You can get a list of the options your version of @code{mysqldump} supports
by executing @code{mysqldump --help}.
Note that if you run @code{mysqldump} without @code{--quick} or
@code{--opt}, @code{mysqldump} will load the whole result set into
memory before dumping the result. This will probably be a problem if
you are dumping a big database.
@code{mysqldump} supports the following options:
@table @code
@item --add-locks
Add @code{LOCK TABLES} before and @code{UNLOCK TABLE} after each table dump.
(To get faster inserts into @strong{MySQL}).
@item --add-drop-table
Add a @code{drop table} before each create statement.
@item -A, --all-databases
Dump all the databases. This will be same as @code{--databases} with all
databases selected.
@item -a, --all
Include all @strong{MySQL} specific create options.
@item --allow-keywords
Allow creation of column names that are keywords. This works by
prefixing each column name with the table name.
@item -c, --complete-insert
Use complete insert statements (with column names).
@item -C, --compress
Compress all information between the client and the server if both support
compression.
@item -B, --databases
To dump several databases. Note the difference in usage; In this case
no tables are given. All name arguments are regarded as databasenames.
@code{USE db_name;} will be included in the output before each new database.
@item --delayed
Insert rows with the @code{INSERT DELAYED} command.
@item -e, --extended-insert
Use the new multiline @code{INSERT} syntax. (Gives more compact and
faster inserts statements.)
@item -#, --debug[=option_string]
Trace usage of the program (for debugging).
@item --help
Display a help message and exit.
@item --fields-terminated-by=...
@itemx --fields-enclosed-by=...
@itemx --fields-optionally-enclosed-by=...
@itemx --fields-escaped-by=...
@itemx --lines-terminated-by=...
These options are used with the @code{-T} option and have the same
meaning as the corresponding clauses for @code{LOAD DATA INFILE}.
@xref{LOAD DATA, , @code{LOAD DATA}}.
@item -F, --flush-logs
Flush log file in the @strong{MySQL} server before starting the dump.
@item -f, --force,
Continue even if we get a SQL error during a table dump.
@item -h, --host=..
Dump data from the @strong{MySQL} server on the named host. The default host
is @code{localhost}.
@item -l, --lock-tables.
Lock all tables before starting the dump. The tables are locked with
@code{READ LOCAL} to allow concurrent inserts in the case of @code{MyISAM}
tables.
@item -n, --no-create-db
'CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name;' will not be put in the
output. The above line will be added otherwise, if --databases or
--all-databases option was given.
@item -t, --no-create-info
Don't write table creation info (The @code{CREATE TABLE} statement.)
@item -d, --no-data
Don't write any row information for the table. This is very useful if you
just want to get a dump of the structure for a table!
@item --opt
Same as @code{--quick --add-drop-table --add-locks --extended-insert
--lock-tables}. Should give you the fastest possible dump for reading
into a @strong{MySQL} server.
@item -pyour_pass, --password[=your_pass]
The password to use when connecting to the server. If you specify
no @samp{=your_pass} part,
@code{mysqldump} you will be prompted for a password.
@item -P port_num, --port=port_num
The TCP/IP port number to use for connecting to a host. (This is used for
connections to hosts other than @code{localhost}, for which Unix sockets are
used.)
@item -q, --quick
Don't buffer query, dump directly to stdout; Uses @code{mysql_use_result()}
to do this.
@item -S /path/to/socket, --socket=/path/to/socket
The socket file to use when connecting to @code{localhost} (which is the
default host).
@item --tables
Overrides option --databases (-B).
@item -T, --tab=path-to-some-directory
Creates a @code{table_name.sql} file, that contains the SQL CREATE commands,
and a @code{table_name.txt} file, that contains the data, for each give table.
@strong{NOTE}: This only works if @code{mysqldump} is run on the same
machine as the @code{mysqld} daemon. The format of the @code{.txt} file
is made according to the @code{--fields-xxx} and @code{--lines--xxx} options.
@item -u user_name, --user=user_name
The @strong{MySQL} user name to use when connecting to the server. The
default value is your Unix login name.
@item -O var=option, --set-variable var=option
Set the value of a variable. The possible variables are listed below.
@item -v, --verbose
Verbose mode. Print out more information what the program does.
@item -V, --version
Print version information and exit.
@item -w, --where='where-condition'
Dump only selected records; Note that QUOTES are mandatory!
@example
"--where=user='jimf'" "-wuserid>1" "-wuserid<1"
@end example
@item -O net_buffer_length=#, where # < 24M
When creating multi-row-insert statements (as with option
@code{--extended-insert} or @code{--opt}), @code{mysqldump} will create
rows up to @code{net_buffer_length} length. If you increase this
variable, you should also ensure that the @code{max_allowed_packet}
variable in the @strong{MySQL} server is bigger than the
@code{net_buffer_length}.
@end table
The most normal use of @code{mysqldump} is probably for making a backup of
whole databases. @xref{Backup}.
@example
mysqldump --opt database > backup-file.sql
@end example
However, it's also very useful to populate another @strong{MySQL} server with
information from a database:
@example
mysqldump --opt database | mysql ---host=remote-host -C database
@end example
It is possible to dump several databases with one command:
@example
mysqldump --databases database1 [database2 database3...] > my_databases.sql
@end example
If all the databases are wanted, one can use:
@example
mysqldump --all-databases > all_databases.sql
@end example
@node mysqlimport, mysqlshow, mysqldump, Tools
@section Importing data from text files
@code{mysqlimport} provides a command line interface to the @code{LOAD DATA
INFILE} SQL statement. Most options to @code{mysqlimport} correspond
directly to the same options to @code{LOAD DATA INFILE}.
@xref{LOAD DATA, , @code{LOAD DATA}}.
@code{mysqlimport} is invoked like this:
@example
shell> mysqlimport [options] database textfile1 [textfile2....]
@end example
For each text file named on the command line,
@code{mysqlimport} strips any extension from the filename and uses the result
to determine which table to import the file's contents into. For example,
files named @file{patient.txt}, @file{patient.text} and @file{patient} would
all be imported into a table named @code{patient}.
@code{mysqlimport} supports the following options:
@table @code
@item -c, --columns=...
This option takes a comma separated list of field names as an argument.
The field list is passed to LOAD DATA INFILE MySQL sql command, which
mysqlimport calls MySQL to execute. For more information, please see
@code{LOAD DATA INFILE}. @xref{LOAD DATA, , @code{LOAD DATA}}.
@item -C, --compress
Compress all information between the client and the server if both support
compression.
@item -#, --debug[=option_string]
Trace usage of the program (for debugging).
@item -d, --delete
Empty the table before importing the text file.
@item --fields-terminated-by=...
@itemx --fields-enclosed-by=...
@itemx --fields-optionally-enclosed-by=...
@itemx --fields-escaped-by=...
@itemx --lines-terminated-by=...
These options have the same meaning as the corresponding clauses for
@code{LOAD DATA INFILE}. @xref{LOAD DATA, , @code{LOAD DATA}}.
@item -f, --force
Ignore errors. For example, if a table for a text file doesn't exist,
continue processing any remaining files. Without @code{--force},
@code{mysqlimport} exits if a table doesn't exist.
@item --help
Display a help message and exit.
@item -h host_name, --host=host_name
Import data to the @strong{MySQL} server on the named host. The default host
is @code{localhost}.
@item -i, --ignore
See the description for the @code{--replace} option.
@item -l, --lock-tables
Lock @strong{ALL} tables for writing before processing any text files. This
ensures that all tables are synchronized on the server.
@item -L, --local
Read input files from the client. By default, text files are assumed to be on
the server if you connect to @code{localhost} (which is the default host).
@item -pyour_pass, --password[=your_pass]
The password to use when connecting to the server. If you specify
no @samp{=your_pass} part,
@code{mysqlimport} you will be prompted for a password.
@item -P port_num, --port=port_num
The TCP/IP port number to use for connecting to a host. (This is used for
connections to hosts other than @code{localhost}, for which Unix sockets are
used.)
@item -r, --replace
The @code{--replace} and @code{--ignore} options control handling of input
records that duplicate existing records on unique key values. If you specify
@code{--replace}, new rows replace existing rows that have the same unique key
value. If you specify @code{--ignore}, input rows that duplicate an existing
row on a unique key value are skipped. If you don't specify either option, an
error occurs when a duplicate key value is found, and the rest of the text
file is ignored.
@item -s, --silent
Silent mode. Write output only when errors occur.
@item -S /path/to/socket, --socket=/path/to/socket
The socket file to use when connecting to @code{localhost} (which is the
default host).
@item -u user_name, --user=user_name
The @strong{MySQL} user name to use when connecting to the server. The
default value is your Unix login name.
@item -v, --verbose
Verbose mode. Print out more information what the program does.
@item -V, --version
Print version information and exit.
@end table
Here follows a sample run of using @code{mysqlimport}:
@example
$ mysql --version
mysql Ver 9.33 Distrib 3.22.25, for pc-linux-gnu (i686)
$ uname -a
Linux xxx.com 2.2.5-15 #1 Mon Apr 19 22:21:09 EDT 1999 i586 unknown
$ mysql -e 'CREATE TABLE imptest(id INT, n VARCHAR(30))' test
$ ed
a
100 Max Sydow
101 Count Dracula
.
w imptest.txt
32
q
$ od -c imptest.txt
0000000 1 0 0 \t M a x S y d o w \n 1 0
0000020 1 \t C o u n t D r a c u l a \n
0000040
$ mysqlimport --local test imptest.txt
test.imptest: Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
$ mysql -e 'SELECT * FROM imptest' test
+------+---------------+
| id | n |
+------+---------------+
| 100 | Max Sydow |
| 101 | Count Dracula |
+------+---------------+
@end example
@node mysqlshow, myisampack, mysqlimport, Tools
@section Showing databases, tables and columns
@code{mysqlshow} can be used to quickly look at which databases exist,
their tables, and the table's columns.
With the @code{mysql} program you can get the same information with the
@code{SHOW} commands. @xref{SHOW}.
@code{mysqlshow} is invoked like this:
@example
shell> mysqlshow [OPTIONS] [database [table [column]]]
@end example
@itemize @bullet
@item
If no database is given, all matching databases are shown.
@item
If no table is given, all matching tables in database are shown.
@item
If no column is given, all matching columns and column types in table
are shown.
@end itemize
Note that in newer @strong{MySQL} versions you only see those
database/tables/columns for which you have some privileges.
If the last argument contains a shell or SQL wildcard (@code{*}, @code{?},
@code{%} or @code{_}) then only what's matched by the wildcard is shown.
This may cause some confusion when you try to display the columns for a
table with a @code{_} as in this case @code{mysqlshow} only shows you
the table names that matches the pattern. This is easily fixed by
adding an extra @code{%} last on the command line (as a separate
argument).
@cindex @code{myisampack}
@cindex @code{pack_isam}
@node myisampack, , mysqlshow, Tools
@section The MySQL compressed read-only table generator.
@code{myisampack} is used to compress MyISAM tables and @code{pack_isam}
is used to compress ISAM tables. Because ISAM tables are deprecated, we
will only discuss @code{myisampack} here, but everything said about
@code{myisampack} should also be true for @code{pack_isam}.
@code{myisampack} works by compressing each column in the table separately.
The information needed to decompress columns is read into memory when the
table is opened. This results in much better performance when accessing
individual records, because you only have to uncompress exactly one record, not
a much larger disk block like when using Stacker on MS-DOS.
Usually, @code{myisampack} packs the data file 40%-70%.
@strong{MySQL} uses memory mapping (@code{mmap()}) on compressed tables and
falls back to normal read/write file usage if @code{mmap()} doesn't work.
There are currently two limitations with @code{myisampack}:
@itemize @bullet
@item
After packing, the table is read only.
@item
@code{myisampack} can also pack @code{BLOB} or @code{TEXT} columns. The
older @code{pack_isam} could not do this.
@end itemize
Fixing these limitations is on our TODO list but with low priority.
@code{myisampack} is invoked like this:
@example
shell> myisampack [options] filename ...
@end example
Each filename should be the name of an index (@file{.MYI}) file. If you
are not in the database directory, you should specify the pathname to the
file. It is permissible to omit the @file{.MYI} extension.
@code{myisampack} supports the following options:
@table @code
@item -b, --backup
Make a backup of the table as @code{tbl_name.OLD}.
@item -#, --debug=debug_options
Output debug log. The @code{debug_options} string often is
@code{'d:t:o,filename'}.
@item -f, --force
Force packing of the table even if it becomes bigger or if the temporary file
exists. (@code{myisampack} creates a temporary file named @file{tbl_name.TMD}
while it compresses the table. If you kill @code{myisampack}, the @file{.TMD}
file may not be deleted. Normally, @code{myisampack} exits with an error if
it finds that @file{tbl_name.TMD} exists. With @code{--force},
@code{myisampack} packs the table anyway.
@item -?, --help
Display a help message and exit.
@item -j big_tbl_name, --join=big_tbl_name
Join all tables named on the command line into a single table
@code{big_tbl_name}. All tables that are to be combined
MUST be identical (same column names and types, same indexes, etc.).
@item -p #, --packlength=#
Specify the record length storage size, in bytes. The value should be 1, 2
or 3. (@code{myisampack} stores all rows with length pointers of 1, 2 or 3
bytes. In most normal cases, @code{myisampack} can determine the right length
value before it begins packing the file, but it may notice during the packing
process that it could have used a shorter length. In this case,
@code{myisampack} will print a note that the next time you pack the same file,
you could use a shorter record length.)
@item -s, --silent
Silent mode. Write output only when errors occur.
@item -t, --test
Don't pack table, only test packing it.
@item -T dir_name, --tmp_dir=dir_name
Use the named directory as the location in which to write the temporary table.
@item -v, --verbose
Verbose mode. Write info about progress and packing result.
@item -V, --version
Display version information and exit.
@item -w, --wait
Wait and retry if table is in use. If the @code{mysqld} server was
invoked with the @code{--skip-locking} option, it is not a good idea to
invoke @code{myisampack} if the table might be updated during the
packing process.
@end table
The sequence of commands shown below illustrates a typical table compression
session:
@example
shell> ls -l station.*
-rw-rw-r-- 1 monty my 994128 Apr 17 19:00 station.MYD
-rw-rw-r-- 1 monty my 53248 Apr 17 19:00 station.MYI
-rw-rw-r-- 1 monty my 5767 Apr 17 19:00 station.frm
shell> myisamchk -dvv station
MyISAM 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 Root Blocksize Rec/key
1 2 4 unique unsigned long 1024 1024 1
2 32 30 multip. text 10240 1024 1
Field Start Length Type
1 1 1
2 2 4
3 6 4
4 10 1
5 11 20
6 31 1
7 32 30
8 62 35
9 97 35
10 132 35
11 167 4
12 171 16
13 187 35
14 222 4
15 226 16
16 242 20
17 262 20
18 282 20
19 302 30
20 332 4
21 336 4
22 340 1
23 341 8
24 349 8
25 357 8
26 365 2
27 367 2
28 369 4
29 373 4
30 377 1
31 378 2
32 380 8
33 388 4
34 392 4
35 396 4
36 400 4
37 404 1
38 405 4
39 409 4
40 413 4
41 417 4
42 421 4
43 425 4
44 429 20
45 449 30
46 479 1
47 480 1
48 481 79
49 560 79
50 639 79
51 718 79
52 797 8
53 805 1
54 806 1
55 807 20
56 827 4
57 831 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
87.14%
shell> ls -l 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 -dvv station
MyISAM 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
Datafilepointer (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
2 32 30 multip. text 54272 1024 1
Field Start Length Type Huff tree Bits
1 1 1 constant 1 0
2 2 4 zerofill(1) 2 9
3 6 4 no zeros, zerofill(1) 2 9
4 10 1 3 9
5 11 20 table-lookup 4 0
6 31 1 3 9
7 32 30 no endspace, not_always 5 9
8 62 35 no endspace, not_always, no empty 6 9
9 97 35 no empty 7 9
10 132 35 no endspace, not_always, no empty 6 9
11 167 4 zerofill(1) 2 9
12 171 16 no endspace, not_always, no empty 5 9
13 187 35 no endspace, not_always, no empty 6 9
14 222 4 zerofill(1) 2 9
15 226 16 no endspace, not_always, no empty 5 9
16 242 20 no endspace, not_always 8 9
17 262 20 no endspace, no empty 8 9
18 282 20 no endspace, no empty 5 9
19 302 30 no endspace, no empty 6 9
20 332 4 always zero 2 9
21 336 4 always zero 2 9
22 340 1 3 9
23 341 8 table-lookup 9 0
24 349 8 table-lookup 10 0
25 357 8 always zero 2 9
26 365 2 2 9
27 367 2 no zeros, zerofill(1) 2 9
28 369 4 no zeros, zerofill(1) 2 9
29 373 4 table-lookup 11 0
30 377 1 3 9
31 378 2 no zeros, zerofill(1) 2 9
32 380 8 no zeros 2 9
33 388 4 always zero 2 9
34 392 4 table-lookup 12 0
35 396 4 no zeros, zerofill(1) 13 9
36 400 4 no zeros, zerofill(1) 2 9
37 404 1 2 9
38 405 4 no zeros 2 9
39 409 4 always zero 2 9
40 413 4 no zeros 2 9
41 417 4 always zero 2 9
42 421 4 no zeros 2 9
43 425 4 always zero 2 9
44 429 20 no empty 3 9
45 449 30 no empty 3 9
46 479 1 14 4
47 480 1 14 4
48 481 79 no endspace, no empty 15 9
49 560 79 no empty 2 9
50 639 79 no empty 2 9
51 718 79 no endspace 16 9
52 797 8 no empty 2 9
53 805 1 17 1
54 806 1 3 9
55 807 20 no empty 3 9
56 827 4 no zeros, zerofill(2) 2 9
57 831 4 no zeros, zerofill(1) 2 9
@end example
The information printed by @code{myisampack} is described below:
@table @code
@item normal
The number of columns for which no extra packing is used.
@item empty-space
The number of columns containing
values that are only spaces; these will occupy 1 bit.
@item empty-zero
The number of columns containing
values that are only binary 0's; these will occupy 1 bit.
@item empty-fill
The number of integer columns that don't occupy the full byte range of their
type; these are changed to a smaller type (for example, an @code{INTEGER}
column may be changed to @code{MEDIUMINT}).
@item pre-space
The number of decimal columns that are stored with leading space. In this
case, each value will contain a count for the number of leading spaces.
@item end-space
The number of columns that have a lot of trailing space. In this case, each
value will contain a count for the number of trailing spaces.
@item table-lookup
The column had only a small number of different values, and that were
converted to an @code{ENUM} before Huffman compression.
@item zero
The number of columns for which all values are zero.
@item Original trees
The initial number of Huffman trees.
@item After join
The number of distinct Huffman trees left after joining
trees to save some header space.
@end table
After a table has been compressed, @code{myisamchk -dvv} prints additional
information about each field:
@table @code
@item Type
The field type may contain the following descriptors:
@table @code
@item constant
All rows have the same value.
@item no endspace
Don't store endspace.
@item no endspace, not_always
Don't store endspace and don't do end space compression for all values.
@item no endspace, no empty
Don't store endspace. Don't store empty values.
@item table-lookup
The column was converted to an @code{ENUM}.
@item zerofill(n)
The most significant @code{n} bytes in the value are always 0 and are not
stored.
@item no zeros
Don't store zeros.
@item always zero
0 values are stored in 1 bit.
@end table
@item Huff tree
The Huffman tree associated with the field.
@item Bits
The number of bits used in the Huffman tree.
@end table
After you have run @code{pack_isam}/@code{myisampack} you must run
@code{isamchk}/@code{myisamchk} to recreate the index. At this time you
can also sort the index blocks and create statistics that is needed for
the @strong{MySQL} optimizer to work more efficiently.
@example
myisamchk -rq --analyze --sort-index table_name.MYI
isamchk -rq --analyze --sort-index table_name.ISM
@end example
After you have installed the packed table into the @strong{MySQL} database
directory you should do @code{mysqladmin flush-tables} to force @code{mysqld}
to start using the new table.
@node Maintenance, Adding functions, Tools, Top
@chapter Maintaining a MySQL installation
@menu
* Table maintenance:: Table maintenance and crash recovery
* Maintenance regimen:: Setting up a table maintenance regimen
* Table-info:: Getting information about a table
* Crash recovery:: Using @code{myisamchk} for crash recovery
* Log files:: Log file maintenance
@end menu
@node Table maintenance, Maintenance regimen, Maintenance, Maintenance
@section Using @code{myisamchk} for table maintenance and crash recovery
Starting with @strong{MySQL} 3.23.13, you can check tables MyISAM with the
@code{CHECK TABLE} command. @xref{CHECK TABLE}. You can repair tables
with the @code{REPAIR TABLE} command. @xref{REPAIR TABLE}.
To check/repair MyISAM tables (@code{.MYI} and @code{.MYD}) you should
use the @code{myisamchk} utility. To check/repair ISAM tables
(@code{.ISM} and @code{.ISD}) you should use the @code{isamchk}
utility. @xref{Table types}.
In the following text we will talk about @code{myisamchk}, but everything
also applies to the old @code{isamchk}.
You can use the @code{myisamchk} utility to get information about your database
tables, check and repair them or optimize them. The following sections
describe how to invoke @code{myisamchk} (including a description of its
options), how to set up a table maintenance schedule, and how to use
@code{myisamchk} to perform its various functions.
You can, in most cases, also use the command @code{OPTIMIZE TABLES} to
optimize and repair tables, but this is not as fast or reliable (in case
of real fatal errors) as @code{myisamchk}. On the other hand,
@code{OPTIMIZE TABLE} is easier to use and you don't have to worry about
flushing tables.
@xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}.
@menu
* myisamchk syntax:: @code{myisamchk} invocation syntax
* myisamchk memory:: @code{myisamchk} memory usage
@end menu
@node myisamchk syntax, myisamchk memory, Table maintenance, Table maintenance
@subsection @code{myisamchk} invocation syntax
@code{myisamchk} is invoked like this:
@example
shell> myisamchk [options] tbl_name
@end example
The @code{options} specify what you want @code{myisamchk} to do. They are
described below. (You can also get a list of options by invoking
@code{myisamchk --help}.) With no options, @code{myisamchk} simply checks your
table. To get more information or to tell @code{myisamchk} to take corrective
action, specify options as described below and in the following sections.
@code{tbl_name} is the database table you want to check. If you run
@code{myisamchk} somewhere other than in the database directory, you must
specify the path to the file, because @code{myisamchk} has no idea where your
database is located. Actually, @code{myisamchk} doesn't care whether or not
the files you are working on are located in a database directory; you can
copy the files that correspond to a database table into another location and
perform recovery operations on them there.
You can name several tables on the @code{myisamchk} command line if you
wish. You can also specify a name as an index file
name (with the @file{.MYI} suffix), which allows you to specify all
tables in a directory by using the pattern @file{*.MYI}.
For example, if you are in a database directory, you can check all the
tables in the directory like this:
@example
shell> myisamchk *.MYI
@end example
If you are not in the database directory, you can check all the tables there
by specifying the path to the directory:
@example
shell> myisamchk /path/to/database_dir/*.MYI
@end example
You can even check all tables in all databases by specifying a wildcard
with the path to the @strong{MySQL} data directory:
@example
shell> myisamchk /path/to/datadir/*/*.MYI
@end example
@code{myisamchk} supports the following options:
@menu
* myisamchk general options::
* myisamchk check options::
* myisamchk repair options::
* myisamchk other options::
@end menu
@node myisamchk general options, myisamchk check options, myisamchk syntax, myisamchk syntax
@subsubsection General options for myisamchk
@table @code
@item -# or --debug=debug_options
Output debug log. The @code{debug_options} string often is
@code{'d:t:o,filename'}.
@item -? or --help
Display a help message and exit.
@item -O var=option, --set-variable var=option
Set the value of a variable. The possible variables and their default values
for myisamchk can be examined with @code{myisamchk --help}.
@multitable @columnfractions .3 .7
@item key_buffer_size @tab 523264
@item read_buffer_size @tab 262136
@item write_buffer_size @tab 262136
@item sort_buffer_size @tab 2097144
@item sort_key_blocks @tab 16
@item decode_bits @tab 9
@end multitable
@code{key_buffer_size} is only used when you check the table with @code{-e} or
repair it with @code{-o}.
@code{sort_buffer_size} is used when you repair the table with @code{-r}.
If you want a faster repair, set the above variables to about 1/4 of your
available memory. You can set both variables to big values as only one
of the above buffers will be used at a time.
@item -s or --silent
Silent mode. Write output only when errors occur. You can use @code{-s}
twice (@code{-ss}) to make @code{myisamchk} very silent.
@item -v or --verbose
Verbose mode. Print more information. This can be used with @code{-d} and
@code{-e}. Use @code{-v} multiple times (@code{-vv}, @code{-vvv}) for more
verbosity!
@item -V or --version
Print the @code{myisamchk} version and exit.
@item -w or, --wait
Instead of giving an error if the table is locked, wait until the table
is unlocked before continuing. Note that if you are running @code{mysqld}
on the table with @code{--skip-locking}, the table is can only be locked
by another @code{myisamchk} command.
@end table
@node myisamchk check options, myisamchk repair options, myisamchk general options, myisamchk syntax
@subsubsection Check options for myisamchk
@table @code
@item -c or --check
Check table for errors. This is the default operation if you are not
giving @code{myisamchk} any options that overrides this.
@item -e or --extend-check
Check the table VERY thoroughly (which is quite slow if you have many
indexes). This options should only be used extreme cases. Normally,
@code{myisamchk} or @code{myisamchk --medium-check} should in most
cases be able to find out if there is any errors in the table.
If you are using @code{--extended-check} and have much memory, you should
increase the value of @code{key_buffer_size} a lot!
@item -F or --fast
Check only tables that hasn't been closed properly.
@item -C or --check-only-changed
Check only tables that has changed since last check.
@item -f or --force
Restart @code{myisamchk} with @code{-r} (repair) on the table, if
@code{myisamchk} finds any errors in the table.
@item -i or --information
Print informational statistics about the table that is checked.
@item -m or --medium-check
Faster than extended-check, but only finds 99.99% of all errors.
Should however be good enough for most cases.
@item -U or --update-state
Store in the @file{.MYI} file when the table was checked and if the
table was crashed. This should be used to get full benefit of the
@code{--check-only-changed} option, but you shouldn't use this if
option if the @code{mysqld} server is using the table and you are
running @code{mysqld} with @code{--skip-locking}.
@item -T or --read-only
Don't mark table as checked. This is useful if you use @code{myisamchk}
to check a table that is in use by some other application that doesn't
use locking (like @code{mysqld --skip-locking})
@end table
@node myisamchk repair options, myisamchk other options, myisamchk check options, myisamchk syntax
@subsubsection Repair options for myisamchk
The following options are used if you start @code{myisamchk} with
@code{-r} or @code{-o}:
@table @code
@item -D # or --data-file-length=#
Max length of data file (when recreating data file when it's 'full')
@item -e or --extend-check
Try to recover every possible row from the data file.
Normally this will also find a lot of garbage rows; Don't use this option
if you are not totally desperate.
@item -f or --force
Overwrite old temporary files (@code{table_name.TMD}) instead of aborting.
@item -k # or keys-used=#
If you are using ISAM, tells the ISAM table handler to update only the
first @code{#} indexes. If you are using @code{MyISAM} tells which keys
to use, where each binary bit stands for one key (First key is bit 0).
This can be used to get faster inserts! Deactivated indexes can be
reactivated by using @code{myisamchk -r}. keys.
@item -l or --no-symlinks
Do not follow symbolic links. Normally @code{myisamchk} repairs the
table a symlink points at.
@item -r or --recover
Can fix almost anything except unique keys that aren't unique.
(which is a extremely unlikely error with ISAM/MyISAM tables).
If you want to recover a table, this is the option to try first. Only if
myisamchk reports that the table can't be recovered by @code{-r}, you
should then try @code{-o}. (Note that in the unlikely case that @code{-r}
fails, the data file is still intact).
If you have lot's of memory, you should increase the size of
@code{sort_buffer_size}!
@item -o or --safe-recover
Uses an old recovery method (reads through all rows in order and updates
all index trees based on the found rows); this is a magnitude slower
than @code{-r}, but can handle a couple of very unlikely cases that
@code{-r} cannot handle. This recovery method also uses much less disk
space than @code{-r}. Normally one should always first repair with
@code{-r} and only if this fails use @code{-o}.
If you have lot's of memory, you should increase the size of
@code{key_buffer_size}!
@item --character-sets-dir=...
Directory where character sets are stored.
@item --set-character-set=name
Change the character set used by the index
@item .t or --tmpdir=path
Path where to store temporary files. If this is not set, @code{myisamchk} will
use the environment variable @code{TMPDIR} for this.
@item -q or --quick
Faster repair by not modifying the data file. One can give a second
@code{-q} to force @code{myisamchk} to modify the original datafile in case
of duplicate keys
@item -u or --unpack
Unpack file packed with myisampack.
@end table
@node myisamchk other options, , myisamchk repair options, myisamchk syntax
@subsubsection Other options for myisamchk
Other actions that @code{myisamchk} can do, besides repair and check tables:
@table @code
@item -a or --analyze
Analyze the distribution of keys. This improves join performance by
enabling the join optimizer to better choose in which order it should
join the tables and which keys it should use.
@code{myisamchk --describe --verbose table_name'} or using @code{SHOW KEYS} in
@strong{MySQL}
@item -d or --description
Prints some information about table.
@item -A or --set-auto-increment[=value]
Force auto_increment to start at this or higher value. If no value is
given, then sets the next auto_increment value to the highest used value
for the auto key + 1.
@item -S or --sort-index
Sort the index tree blocks in high-low order.
This will optimize seeks and will make table scanning by key faster.
@item -R or --sort-records=#
Sorts records according to an index. This makes your data much more localized
and may speed up ranged @code{SELECT} and @code{ORDER BY} operations on
this index. (It may be VERY slow to do a sort the first time!)
To find out a table's index numbers, use @code{SHOW INDEX}, which shows a
table's indexes in the same order that @code{myisamchk} sees them. Indexes are
numbered beginning with 1.
@end table
@node myisamchk memory, , myisamchk syntax, Table maintenance
@subsection @code{myisamchk} memory usage
Memory allocation is important when you run @code{myisamchk}.
@code{myisamchk} uses no more memory than you specify with the @code{-O}
options. If you are going to use @code{myisamchk} on very large files,
you should first decide how much memory you want it to use. The default
is to use only about 3M to fix things. By using larger values, you can
get @code{myisamchk} to operate faster. For example, if you have more
than 32M RAM, you could use options such as these (in addition to any
other options you might specify):
@example
shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ...
@end example
Using @code{-O sort=16M} should probably be enough for most cases.
Be aware that @code{myisamchk} uses temporary files in @code{TMPDIR}. If
@code{TMPDIR} points to a memory file system, you may easily get out of
memory errors. If this happens, set @code{TMPDIR} to point at some directory
with more space and restart @code{myisamchk}
When repairing, @code{myisamchk} will also nead a lot of diskspace:
@itemize @bullet
@item
Double the size of the record file (The original one and a copy). This
space is not needed if one does a repair with @code{--quick}, as in this
case only the index file will be recreated. This space is needed on the
same disk as the original record file!
@item
Space for the new index file (that replaces the old one; The old
index file is truncated at start, so one usually ignore this space).
This space is needed on the same disk as the original index file!
@item
When using @code{--repair} (but not when using @code{--safe-repair}, you
will need space for a sort buffer for:
@code{(largest_key + row_pointer_length)*number_of_rows * 2}.
You can check the length of the keys and the row_pointer_length with
@code{myisamchk -dv table}.
This space is allocated on the temporary disk (specified by @code{TMPDIR} or
@code{--tmpdir=#}).
@end itemize
If you have a problem with disk space during repair, you can try to use
@code{--safe-repair} instead of @code{--repair}.
@node Maintenance regimen, Table-info, Table maintenance, Maintenance
@section Setting up a table maintenance regimen
It is a good idea to perform table checks on a regular basis rather than
waiting for problems to occur. For maintenance purposes, you can use
@code{myisamchk -s} to check tables. The @code{-s} option causes
@code{myisamchk} to run in silent mode, printing messages only when errors
occur.
@tindex .pid (process ID) file
It's a good idea to check tables when the server starts up.
For example, whenever the machine has done a reboot in the middle of an
update, you usually need to check all the tables that could have been
affected. (This is an ``expected crashed table''.) You could add a test to
@code{safe_mysqld} that runs @code{myisamchk} to check all tables that have
been modified during the last 24 hours if there is an old @file{.pid}
(process ID) file left after a reboot. (The @file{.pid} file is created by
@code{mysqld} when it starts up and removed when it terminates normally. The
presence of a @file{.pid} file at system startup time indicates that
@code{mysqld} terminated abnormally.)
An even better test would be to check any table whose last-modified time
is more recent than that of the @file{.pid} file.
You should also check your tables regularly during normal system
operation. At MySQL AB, we run a @code{cron} job to check all our important
tables once a week, using a line like this in a @file{crontab} file:
@example
35 0 * * 0 /path/to/myisamchk -s /path/to/datadir/*/*.MYI
@end example
This prints out information about crashed tables so we can examine and repair
them when needed.
As we haven't had any unexpectedly crashed tables (tables that become
corrupted for reasons other than hardware trouble)
for a couple of years now (this is really true), once a week is
more than enough for us.
We recommend that to start with, you execute @code{myisamchk -s} each
night on all tables that have been updated during the last 24 hours,
until you come to trust @strong{MySQL} as much as we do.
@node Table-info, Crash recovery, Maintenance regimen, Maintenance
@section Getting information about a table
To get a description of a table or statistics about it, use the commands shown
below. We explain some of the information in more detail later.
@table @code
@item myisamchk -d tbl_name
Runs @code{myisamchk} in ``describe mode'' to produce a description of your
table. If you start the @strong{MySQL} server using the @code{--skip-locking}
option, @code{myisamchk} may report an error for a table that is updated while
it runs. However, because @code{myisamchk} doesn't change the table in describe
mode, there isn't any risk of destroying data.
@item myisamchk -d -v tbl_name
To produce more information about what @code{myisamchk} is doing, add @code{-v}
to tell it to run in verbose mode.
@item myisamchk -eis tbl_name
Shows only the most important information from a table. It is slow because it
must read the whole table.
@item myisamchk -eiv tbl_name
This is like @code{-eis}, but tells you what is being done.
@end table
Example of @code{myisamchk -d} output:
@example
MyISAM 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
@end example
Example of @code{myisamchk -d -v} output:
@example
MyISAM file: company
Record format: Fixed length
File-version: 1
Creation time: 1999-10-30 12:12:51
Recover time: 1999-10-31 19:13:01
Status: checked
Data records: 1403698 Deleted blocks: 0
Datafile parts: 1403698 Deleted data: 0
Datafilepointer (bytes): 3 Keyfile pointer (bytes): 3
Max datafile length: 3791650815 Max keyfile length: 4294967294
Recordlength: 226
table description:
Key Start Len Index Type Rec/key Root Blocksize
1 2 8 unique double 1 15845376 1024
2 15 10 multip. text packed stripped 2 25062400 1024
3 219 8 multip. double 73 40907776 1024
4 63 10 multip. text packed stripped 5 48097280 1024
5 167 2 multip. unsigned short 4840 55200768 1024
6 177 4 multip. unsigned long 1346 65145856 1024
7 155 4 multip. text 4995 75090944 1024
8 138 4 multip. unsigned long 87 85036032 1024
9 177 4 multip. unsigned long 178 96481280 1024
193 1 text
@end example
Example of @code{myisamchk -eis} output:
@example
Checking MyISAM 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
@end example
Example of @code{myisamchk -eiv} output:
@example
Checking MyISAM file: company
Data records: 1403698 Deleted blocks: 0
- check file-size
- check delete-chain
block_size 1024:
index 1:
index 2:
index 3:
index 4:
index 5:
index 6:
index 7:
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
@end example
Here are the sizes of the data and index files for the table used in the
preceding examples:
@example
-rw-rw-r-- 1 monty tcx 317235748 Jan 12 17:30 company.MYD
-rw-rw-r-- 1 davida tcx 96482304 Jan 12 18:35 company.MYM
@end example
Explanations for the types of information @code{myisamchk} produces are
given below. The ``keyfile'' is the index file. ``Record'' and ``row''
are synonymous.
@table @code
@item ISAM file
Name of the ISAM (index) file.
@item Isam-version
Version of ISAM format. Currently always 2.
@item Creation time
When the data file was created.
@item Recover time
When the index/data file was last reconstructed.
@item Data records
How many records are in the table.
@item Deleted blocks
How many deleted blocks still have reserved space.
You can optimize your table to minimize this space.
@xref{Optimization}.
@item Datafile: Parts
For dynamic record format, this indicates how many data blocks there are. For
an optimized table without fragmented records, this is the same as @code{Data
records}.
@item Deleted data
How many bytes of non-reclaimed deleted data there are.
You can optimize your table to minimize this space.
@xref{Optimization}.
@item Datafile pointer
The size of the data file pointer, in bytes. It is usually 2, 3, 4 or 5
bytes. Most tables manage with 2 bytes, but this cannot be controlled
from @strong{MySQL} yet. For fixed tables, this is a record address. For
dynamic tables, this is a byte address.
@item Keyfile pointer
The size of the index file pointer, in bytes. It is usually 1, 2 or 3
bytes. Most tables manage with 2 bytes, but this is calculated
automatically by @strong{MySQL}. It is always a block address.
@item Max datafile length
How long the table's data file (@code{.MYD} file) can become, in bytes.
@item Max keyfile length
How long the table's key file (@code{.MYI} file) can become, in bytes.
@item Recordlength
How much space each record takes, in bytes.
@item Record format
The format used to store table rows.
The examples shown above use @code{Fixed length}.
Other possible values are @code{Compressed} and @code{Packed}.
@item table description
A list of all keys in the table. For each key, some low-level information
is presented:
@table @code
@item Key
This key's number.
@item Start
Where in the record this index part starts.
@item Len
How long this index part is. For packed numbers, this should always be
the full length of the column. For strings, it may be shorter than the full
length of the indexed column, because you can index a prefix of a string
column.
@item Index
@code{unique} or @code{multip.} (multiple). Indicates whether or not one value
can exist multiple times in this index.
@item Type
What data-type this index part has. This is an ISAM data-type
with the options @code{packed}, @code{stripped} or @code{empty}.
@item Root
Address of the root index block.
@item Blocksize
The size of each index block. By default this is 1024, but the value may be
changed at compile time.
@item Rec/key
This is a statistical value used by the optimizer. It tells how many
records there are per value for this key. A unique key always has a
value of 1. This may be updated after a table is loaded (or greatly
changed) with @code{myisamchk -a}. If this is not updated at all, a default
value of 30 is given.
@end table
@item
In the first example above, the 9th key is a multi-part key with two parts.
@item Keyblocks used
What percentage of the keyblocks are used. Because the table used in the
examples had just been reorganized with @code{myisamchk}, the values are very
high (very near the theoretical maximum).
@item Packed
@strong{MySQL} tries to pack keys with a common suffix. This can only be used
for @code{CHAR}/@code{VARCHAR}/@code{DECIMAL} keys. For long strings like
names, this can significantly reduce the space used. In the third example
above, the 4th key is 10 characters long and a 60% reduction in space is
achieved.
@item Max levels
How deep the B-tree for this key is. Large tables with long keys get high
values.
@item Records
How many rows are in the table.
@item M.recordlength
The average record length. For tables with fixed-length records, this is the
exact record length.
@item Packed
@strong{MySQL} strips spaces from the end of strings. The @code{Packed}
value indicates the percentage savings achieved by doing this.
@item Recordspace used
What percentage of the data file is used.
@item Empty space
What percentage of the data file is unused.
@item Blocks/Record
Average number of blocks per record (i.e., how many links a fragmented
record is composed of). This is always 1 for fixed-format tables. This value
should stay as close to 1.0 as possible. If it gets too big, you can
reorganize the table with @code{myisamchk}.
@xref{Optimization}.
@item Recordblocks
How many blocks (links) are used. For fixed format, this is the same as the number
of records.
@item Deleteblocks
How many blocks (links) are deleted.
@item Recorddata
How many bytes in the data file are used.
@item Deleted data
How many bytes in the data file are deleted (unused).
@item Lost space
If a record is updated to a shorter length, some space is lost. This is
the sum of all such losses, in bytes.
@item Linkdata
When the dynamic table format is used, record fragments are linked with
pointers (4 to 7 bytes each). @code{Linkdata} is the sum of the amount of
storage used by all such pointers.
@end table
If a table has been compressed with @code{myisampack}, @code{myisamchk
-d} prints additional information about each table column. See
@ref{myisampack, , @code{myisampack}}, for an example of this
information and a description of what it means.
@node Crash recovery, Log files, Table-info, Maintenance
@section Using @code{myisamchk} for crash recovery
If you run @code{mysqld} with @code{--skip-locking} (which is the default on
some systems, like Linux), you can't reliably use @code{myisamchk} to
check a table when @code{mysqld} is using the same table. If you
can be sure that no one is accessing the tables through @code{mysqld}
while you run @code{myisamchk}, you only have to do @code{mysqladmin
flush-tables} before you start checking the tables. If you can't
guarantee the above, then you must take down @code{mysqld} while you
check the tables. If you run @code{myisamchk} while @code{mysqld} is updating
the tables, you may get a warning that a table is corrupt even if it
isn't.
If you are not using @code{--skip-locking}, you can use @code{myisamchk}
to check tables at any time. While you do this, all clients that try
to update the table will wait until @code{myisamchk} is ready before
continuing.
If you use @code{myisamchk} to repair or optimize tables, you
@strong{MUST} always ensure that the @code{mysqld} server is not using
the table (this also applies if you are using @code{--skip-locking}).
If you don't take down @code{mysqld} you should at least do a
@code{mysqladmin flush-tables} before you run @code{myisamchk}.
The file format that @strong{MySQL} uses to store data has been extensively
tested, but there are always external circumstances that may cause database
tables to become corrupted:
@itemize @bullet
@item
The @code{mysqld} process being killed in the middle of a write.
@item
Unexpected shutdown of the computer (for example, if the computer is turned
off).
@item
A hardware error.
@end itemize
This chapter describes how to check for and deal with data corruption
in @strong{MySQL} databases. If your tables get corrupted a lot you should
try to find the reason for this! @xref{Debugging server}.
When performing crash recovery, it is important to understand that each table
@code{tbl_name} in a database corresponds to three files in the database
directory:
@multitable @columnfractions .2 .8
@item @strong{File} @tab @strong{Purpose}
@item @file{tbl_name.frm} @tab Table definition (form) file
@item @file{tbl_name.MYD} @tab Data file
@item @file{tbl_name.MYI} @tab Index file
@end multitable
Each of these three file types is subject to corruption in various ways, but
problems occur most often in data files and index files.
@code{myisamchk} works by creating a copy of the @file{.MYD} (data) file
row by row. It ends the repair stage by removing the old @file{.MYD}
file and renaming the new file to the original file name. If you use
@code{--quick}, @code{myisamchk} does not create a temporary @file{.MYD}
file, but instead assumes that the @file{.MYD} file is correct and only
generates a new index file without touching the @file{.MYD} file. This
is safe, because @code{myisamchk} automatically detects if the
@file{.MYD} file is corrupt and aborts the repair in this case. You can
also give two @code{--quick} options to @code{myisamchk}. In this case,
@code{myisamchk} does not abort on some errors (like duplicate key) but
instead tries to resolve them by modifying the @file{.MYD}
file. Normally the use of two @code{--quick} options is useful only if
you have too little free disk space to perform a normal repair. In this
case you should at least make a backup before running @code{myisamchk}.
@menu
* Check:: How to check tables for errors
* Repair:: How to repair tables
* Optimization:: Table optimization
@end menu
@cindex Checking tables for errors
@node Check, Repair, Crash recovery, Crash recovery
@subsection How to check tables for errors
To check a table, use the following commands:
@table @code
@item myisamchk tbl_name
This finds 99.99% of all errors. What it can't find is corruption that
involves @strong{ONLY} the data file (which is very unusual). If you want
to check a table, you should normally run @code{myisamchk} without options or
with either the @code{-s} or @code{--silent} option.
@item myisamchk -m tbl_name
This finds 99.999% of all errors. It checks first all index for errors and
then it reads through all rows. It calculates a checksum for all keys in
the rows and verifies that they checksum matches the checksum for the keys
in the index tree.
@item myisamchk -e tbl_name
This does a complete and thorough check of all data (@code{-e} means
``extended check''). It does a check-read of every key for each row to verify
that they indeed point to the correct row. This may take a LONG time on a
big table with many keys. @code{myisamchk} will normally stop after the first
error it finds. If you want to obtain more information, you can add the
@code{--verbose} (@code{-v}) option. This causes @code{myisamchk} to keep
going, up through a maximum of 20 errors. In normal usage, a simple
@code{myisamchk} (with no arguments other than the table name) is sufficient.
@item myisamchk -e -i tbl_name
Like the previous command, but the @code{-i} option tells @code{myisamchk} to
print some informational statistics, too.
@end table
@node Repair, Optimization, Check, Crash recovery
@subsection How to repair tables
In the following we only talk about using @code{myisamchk} on @code{MyISAM}
tables (extensions @code{.MYI} and @code{.MYD}). If you are using
@code{ISAM} tables (extensions @code{.ISM} and @code{.ISD}), you should use
@code{isamchk} instead.
The symptoms of a corrupted table are usually that queries abort unexpectedly
and you observe errors such as these:
@itemize @bullet
@item
@file{tbl_name.frm} is locked against change
@item
Can't find file @file{tbl_name.MYI} (Errcode: ###)
@item
Got error ### from table handler (Error 135 is an exception in this case)
@item
Unexpected end of file
@item
Record file is crashed
@end itemize
In these cases, you must repair your tables. @code{myisamchk}
can usually detect and fix most things that go wrong.
The repair process involves up to four stages, described below. Before you
begin, you should @code{cd} to the database directory and check the
permissions of the table files. Make sure they are readable by the Unix user
that @code{mysqld} runs as (and to you, because you need to access the files
you are checking). If it turns out you need to modify files, they must also
be writable by you.
If you are using @strong{MySQL} 3.23.16 and above you can (and should) use the
@code{CHECK} and @code{REPAIR} commands to check and repair @code{MyISAM}
tables. @xref{CHECK TABLE}. @xref{REPAIR TABLE}.
The manual section about table maintenence includes the options to
@code{isamchk}/@code{myisamchk}. @xref{Table maintenance}.
The following section is for the cases where the above command fails or
if you want to use the extended features that isamchk/myisamchk provides.
If you are going to repair a table from the command line, you must first
take down the @code{mysqld} server. Note that when you do
@code{mysqladmin shutdown} on a remote server, the @code{mysqld} server
will still be alive for a while after @code{mysqladmin} returns until
all queries are stopped and all keys have been flushed to disk.
@noindent
@strong{Stage 1: Checking your tables}
Run @code{myisamchk *.MYI} or (@code{myisamchk -e *.MYI} if you have
more time). Use the @code{-s} (silent) option to suppress unnecessary
information.
If the mysqld server is done you should use the --update option to tell
@code{myisamchk} to mark the table as 'checked'.
You have to repair only those tables for which @code{myisamchk} announces an
error. For such tables, proceed to Stage 2.
If you get weird errors when checking (such as @code{out of
memory} errors), or if @code{myisamchk} crashes, go to Stage 3.
@noindent
@strong{Stage 2: Easy safe repair}
Note: If you want repairing to go much faster, you should add: @code{-O
sort_buffer=# -O key_buffer=#} (where # is about 1/4 of the available
memory) to all @code{isamchk/myisamchk} commands.
First, try @code{myisamchk -r -q tbl_name} (@code{-r -q} means ``quick
recovery mode''). This will attempt to repair the index file without
touching the data file. If the data file contains everything that it
should and the delete links point at the correct locations within the
data file, this should work, and the table is fixed. Start repairing the
next table. Otherwise, use the following procedure:
@enumerate
@item
Make a backup of the data file before continuing.
@item
Use @code{myisamchk -r tbl_name} (@code{-r} means ``recovery mode''). This will
remove incorrect records and deleted records from the data file and
reconstruct the index file.
@item
If the preceding step fails, use @code{myisamchk --safe-recover tbl_name}.
Safe recovery mode uses an old recovery method that handles a few cases that
regular recovery mode doesn't (but is slower).
@end enumerate
If you get weird errors when repairing (such as @code{out of
memory} errors), or if @code{myisamchk} crashes, go to Stage 3.
@noindent
@strong{Stage 3: Difficult repair}
You should only reach this stage if the first 16K block in the index file is
destroyed or contains incorrect information, or if the index file is
missing. In this case, it's necessary to create a new index file. Do so as
follows:
@enumerate
@item
Move the data file to some safe place.
@item
Use the table description file to create new (empty) data and index files:
@example
shell> mysql db_name
mysql> SET AUTOCOMMIT=1;
mysql> DELETE FROM tbl_name;
mysql> quit
@end example
@item
Copy the old data file back onto the newly created data file.
(Don't just move the old file back onto the new file; you want to retain
a copy in case something goes wrong.)
@end enumerate
Go back to Stage 2. @code{myisamchk -r -q} should work now. (This shouldn't
be an endless loop).
@noindent
@strong{Stage 4: Very difficult repair}
You should reach this stage only if the description file has also
crashed. That should never happen, because the description file isn't changed
after the table is created.
@enumerate
@item
Restore the description file from a backup and go back to Stage 3. You can
also restore the index file and go back to Stage 2. In the latter case, you
should start with @code{myisamchk -r}.
@item
If you don't have a backup but know exactly how the table was created, create
a copy of the table in another database. Remove the new data file, then move
the description and index files from the other database to your crashed
database. This gives you new description and index files, but leaves
the data file alone. Go back to Stage 2 and attempt to reconstruct
the index file.
@end enumerate
@node Optimization, , Repair, Crash recovery
@subsection Table optimization
To coalesce fragmented records and eliminate wasted space resulting from
deleting or updating records, run @code{myisamchk} in recovery mode:
@example
shell> myisamchk -r tbl_name
@end example
You can optimize a table in the same way using the SQL @code{OPTIMIZE TABLE}
statement. @code{OPTIMIZE TABLE} is easier, but @code{myisamchk} is faster.
There is also no possibility of unwanted interaction between a utility
and the server, because the server does all the work when you use
@code{OPTIMIZE TABLE}.
@code{myisamchk} also has a number of other options you can use to improve
the performance of a table:
@table @code
@item -S, --sort-index
@item -R index_num, --sort-records=index_num
@item -a, --analyze
@end table
For a full description of the option see @xref{myisamchk syntax}.
@node Log files, , Crash recovery, Maintenance
@section Log file maintenance
When using @strong{MySQL} with log files, you will from time to time
want to remove/backup old log files and tell @strong{MySQL} to start
logging on new files. @xref{Update log}.
On a Linux (@code{Redhat}) installation, you can use the
@code{mysql-log-rotate} script for this. If you installed @strong{MySQL}
from an RPM distribution, the script should have been installed
automatically.
On other systems you must install a short script yourself that you
start from @code{cron} to handle log files.
You can force @strong{MySQL} to start using new log files by using
@code{mysqladmin flush-logs} or by using the SQL command @code{FLUSH LOGS}.
If you are using @strong{MySQL} 3.21 you must use @code{mysqladmin refresh}.
The above command does the following:
@itemize @bullet
@item
If standard logging (@code{--log}) is used, closes and reopens the log file.
(@file{mysql.log} as default).
@item
If update logging (@code{--log-update}) is used, closes the update log and
opens a new log file with a higher sequence number.
@end itemize
If you are using only an update log, you only have to flush the logs and then
move away the old update log files to a backup.
If you are using the normal logging, you can do something like:
@example
shell> cd mysql-data-directory
shell> mv mysql.log mysql.old
shell> mysqladmin flush-logs
@end example
and then take a backup and remove @file{mysql.old}.
@node Adding functions, Adding procedures, Maintenance, Top
@chapter Adding new functions to MySQL
There are two ways to add new functions to @strong{MySQL}:
@itemize @bullet
@item You can add the function through the user-definable function (UDF)
interface. User-definable functions are added and removed dynamically using
the @code{CREATE FUNCTION} and @code{DROP FUNCTION} statements.
@xref{CREATE FUNCTION, , @code{CREATE FUNCTION}}.
@item You can add the function as a native (built in) @strong{MySQL} function.
Native functions are compiled into the @code{mysqld} server and become
available on a permanent basis.
@end itemize
Each method has advantages and disadvantages:
@itemize @bullet
@item
If you write a user-definable function, you must install the object file
in addition to the server itself. If you compile your function into the
server, you don't need to do that.
@item
You can add UDFs to a binary @strong{MySQL} distribution. Native functions
require you to modify a source distribution.
@item
If you upgrade your @strong{MySQL} distribution, you can continue to use your
previously-installed UDFs. For native functions, you must repeat your
modifications each time you upgrade.
@end itemize
Whichever method you use to add new functions, they may be used just like
native functions such as @code{ABS()} or @code{SOUNDEX()}.
@menu
* Adding UDF:: Adding a new user-definable function
* Adding native function:: Adding a new native function
@end menu
@cindex Adding user-definable functions
@cindex User-definable functions, adding
@cindex Functions, user-definable, adding
@node Adding UDF, Adding native function, Adding functions, Adding functions
@section Adding a new user-definable function
@menu
* UDF calling sequences:: UDF calling sequences
* UDF arguments:: Argument processing
* UDF return values:: Return values and error handling
* UDF compiling:: Compiling and installing user-definable functions
@end menu
For the UDF mechanism to work, functions must be written in C or C++ and your
operating system must support dynamic loading. The @strong{MySQL} source
distribution includes a file @file{sql/udf_example.cc} that defines 5 new
functions. Consult this file to see how UDF calling conventions work.
For each function that you want to use in SQL statements, you should define
corresponding C (or C++) functions. In the discussion below, the name
``xxx'' is used for an example function name. To distinquish between SQL and
C/C++ usage, @code{XXX()} (uppercase) indicates a SQL function call, and
@code{xxx()} (lowercase) indicates a C/C++ function call.
The C/C++ functions that you write to implement the inferface for
@code{XXX()} are:
@table @asis
@item @code{xxx()} (required)
The main function. This is where the function result is computed.
The correspondence between the SQL type and return type of your C/C++
function is shown below:
@multitable @columnfractions .2 .8
@item @strong{SQL type} @tab @strong{C/C++ type}
@item @code{STRING} @tab @code{char *}
@item @code{INTEGER} @tab @code{long long}
@item @code{REAL} @tab @code{double}
@end multitable
@item @code{xxx_init()} (optional)
The initialization function for @code{xxx()}. It can be used to:
@itemize @bullet
@item
Check the number of arguments to @code{XXX()}.
@item
Check that the arguments are of a required type, or, alternatively,
tell @strong{MySQL} to coerce arguments to the types you want when
the main function is called.
@item
Allocate any memory required by the main function.
@item
Specify the maximum length of the result.
@item
Specify (for @code{REAL} functions) the maximum number of decimals.
@item
Specify whether or not the result can be @code{NULL}.
@end itemize
@item @code{xxx_deinit()} (optional)
The deinitialization function for @code{xxx()}. It should deallocate any
memory allocated by the initialization function.
@end table
When a SQL statement invokes @code{XXX()}, @strong{MySQL} calls the
initialization function @code{xxx_init()} to let it perform any required
setup, such as argument checking or memory allocation. If @code{xxx_init()}
returns an error, the SQL statement is aborted with an error message and the
main and deinitialization functions are not called. Otherwise, the main
function @code{xxx()} is called once for each row. After all rows have been
processed, the deinitialization function @code{xxx_deinit()} is called so it
can perform any required cleanup.
All functions must be thread-safe (not just the main function,
but the initialization and deinitialization functions as well). This means
that you are not allowed to allocate any global or static variables that
change! If you need memory, you should allocate it in @code{xxx_init()}
and free it in @code{xxx_deinit()}.
@node UDF calling sequences, UDF arguments, Adding UDF, Adding UDF
@subsection UDF calling sequences
The main function should be declared as shown below. Note that the return
type and parameters differ, depending on whether you will declare the SQL
function @code{XXX()} to return @code{STRING}, @code{INTEGER} or @code{REAL}
in the @code{CREATE FUNCTION} statement:
@noindent
For @code{STRING} functions:
@example
char *xxx(UDF_INIT *initid, UDF_ARGS *args,
char *result, unsigned long *length,
char *is_null, char *error);
@end example
@noindent
For @code{INTEGER} functions:
@example
long long xxx(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error);
@end example
@noindent
For @code{REAL} functions:
@example
double xxx(UDF_INIT *initid, UDF_ARGS *args,
char *is_null, char *error);
@end example
The initialization and deinitialization functions are declared like this:
@example
my_bool xxx_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void xxx_deinit(UDF_INIT *initid);
@end example
The @code{initid} parameter is passed to all three functions. It points to a
@code{UDF_INIT} structure that is used to communicate information between
functions. The @code{UDF_INIT} structure members are listed below. The
initialization function should fill in any members that it wishes to change.
(To use the default for a member, leave it unchanged.)
@table @code
@item my_bool maybe_null
@code{xxx_init()} should set @code{maybe_null} to @code{1} if @code{xxx()}
can return @code{NULL}. The default value is @code{1} if any of the
arguments are declared @code{maybe_null}.
@item unsigned int decimals
Number of decimals. The default value is the maximum number of decimals in
the arguments passed to the main function. (For example, if the function is
passed @code{1.34}, @code{1.345} and @code{1.3}, the default would be 3,
because @code{1.345} has 3 decimals.
@item unsigned int max_length
The maximum length of the string result. The default value differs depending
on the result type of the function. For string functions, the default is the
length of the longest argument. For integer functions, the default is 21
digits. For real functions, the default is 13 plus the number of decimals
indicated by @code{initid->decimals}. (For numeric functions, the length
includes any sign or decimal point characters.)
@item char *ptr
A pointer that the function can use for its own purposes. For example,
functions can use @code{initid->ptr} to communicate allocated memory
between functions. In @code{xxx_init()}, allocate the memory and assign it
to this pointer:
@example
initid->ptr = allocated_memory;
@end example
In @code{xxx()} and @code{xxx_deinit()}, refer to @code{initid->ptr} to use
or deallocate the memory.
@end table
@node UDF arguments, UDF return values, UDF calling sequences, Adding UDF
@subsection Argument processing
The @code{args} parameter points to a @code{UDF_ARGS} structure which has the
members listed below:
@table @code
@item unsigned int arg_count
The number of arguments. Check this value in the initialization function
if you want your function to be called with a particular number of arguments.
For example:
@example
if (args->arg_count != 2)
@{
strcpy(message,"XXX() requires two arguments");
return 1;
@}
@end example
@item enum Item_result *arg_type
The types for each argument. The possible type values are
@code{STRING_RESULT}, @code{INT_RESULT} and @code{REAL_RESULT}.
To make sure that arguments are of a given type and return an
error if they are not, check the @code{arg_type} array in the initialization
function. For example:
@example
if (args->arg_type[0] != STRING_RESULT ||
args->arg_type[1] != INT_RESULT)
@{
strcpy(message,"XXX() requires a string and an integer");
return 1;
@}
@end example
As an alternative to requiring your function's arguments to be of particular
types, you can use the initialization function to set the @code{arg_type}
elements to the types you want. This causes @strong{MySQL} to coerce
arguments to those types for each call to @code{xxx()}. For example, to
specify coercion of the first two arguments to string and integer, do this in
@code{xxx_init()}:
@example
args->arg_type[0] = STRING_RESULT;
args->arg_type[1] = INT_RESULT;
@end example
@item char **args
@code{args->args} communicates information to the initialization function
about the general nature of the arguments your function was called with. For a
constant argument @code{i}, @code{args->args[i]} points to the argument
value. (See below for instructions on how to access the value properly.)
For a non-constant argument, @code{args->args[i]} is @code{0}.
A constant argument is an expression that uses only constants, such as
@code{3} or @code{4*7-2} or @code{SIN(3.14)}. A non-constant argument is an
expression that refers to values that may change from row to row, such as
column names or functions that are called with non-constant arguments.
For each invocation of the main function, @code{args->args} contains the
actual arguments that are passed for the row currently being processed.
Functions can refer to an argument @code{i} as follows:
@itemize @bullet
@item
An argument of type @code{STRING_RESULT} is given as a string pointer plus a
length, to allow handling of binary data or data of arbitrary length. The
string contents are available as @code{args->args[i]} and the string length
is @code{args->lengths[i]}. You should not assume that strings are
null-terminated.
@item
For an argument of type @code{INT_RESULT}, you must cast
@code{args->args[i]} to a @code{long long} value:
@example
long long int_val;
int_val = *((long long*) args->args[i]);
@end example
@item
For an argument of type @code{REAL_RESULT}, you must cast
@code{args->args[i]} to a @code{double} value:
@example
double real_val;
real_val = *((double*) args->args[i]);
@end example
@end itemize
@item unsigned long *lengths
For the initialization function, the @code{lengths} array indicates the
maximum string length for each argument. For each invocation of the main
function, @code{lengths} contains the actual lengths of any string arguments
that are passed for the row currently being processed. For arguments of
types @code{INT_RESULT} or @code{REAL_RESULT}, @code{lengths} still contains
the maximum length of the argument (as for the initialization function).
@end table
@node UDF return values, UDF compiling, UDF arguments, Adding UDF
@subsection Return values and error handling
The initialization function should return @code{0} if no error occurred and
@code{1} otherwise. If an error occurs, @code{xxx_init()} should store a
null-terminated error message in the @code{message} parameter. The message
will be returned to the client. The message buffer is
@code{MYSQL_ERRMSG_SIZE} characters long, but you should try to keep the
message to less than 80 characters so that it fits the width of a standard
terminal screen.
The return value of the main function @code{xxx()} is the function value, for
@code{long long} and @code{double} functions. For string functions, the
string is returned in the @code{result} and @code{length} arguments.
@code{result} is a buffer at least 255 bytes long. Set these to the contents
and length of the return value. For example:
@example
memcpy(result, "result string", 13);
*length = 13;
@end example
The string function return value normally also points to the result.
To indicate a return value of @code{NULL} in the main function, set
@code{is_null} to @code{1}:
@example
*is_null = 1;
@end example
To indicate an error return in the main function, set the @code{error}
parameter to @code{1}:
@example
*error = 1;
@end example
If @code{xxx()} sets @code{*error} to @code{1} for any row, the function
value is @code{NULL} for the current row and for any subsequent rows
processed by the statement in which @code{XXX()} was invoked. (@code{xxx()}
will not even be called for subsequent rows.) @strong{Note:} In
@strong{MySQL} versions prior to 3.22.10, you should set both @code{*error}
and @code{*is_null}:
@example
*error = 1;
*is_null = 1;
@end example
@node UDF compiling, , UDF return values, Adding UDF
@subsection Compiling and installing user-definable functions
Files implementing UDFs must be compiled and installed on the host where the
server runs. This process is described below for the example UDF file
@file{udf_example.cc} that is included in the @strong{MySQL} source
distribution. This file contains the following functions:
@itemize @bullet
@item
@code{metaphon()} returns a metaphon string of the string argument.
This is something like a soundex string, but it's more tuned for English.
@item
@code{myfunc_double()} returns the sum of the ASCII values of the
characters in its arguments, divided by the sum of the length of its arguments.
@item
@code{myfunc_int()} returns the sum of the length of its arguments.
@item
@code{lookup()} returns the IP number for a hostname.
@item
@code{reverse_lookup()} returns the hostname for an IP number.
The function may be called with a string @code{"xxx.xxx.xxx.xxx"} or
four numbers.
@end itemize
A dynamically-loadable file should be compiled as a sharable object file,
using a command something like this:
@example
shell> gcc -shared -o udf_example.so myfunc.cc
@end example
You can easily find out the correct compiler options for your system by
running this command in the @file{sql} directory of your @strong{MySQL}
source tree:
@example
shell> make udf_example.o
@end example
You should run a compile command similar to the one that @code{make} displays,
except that you should remove the @code{-c} option near the end of the line
and add @code{-o udf_example.so} to the end of the line. (On some systems,
you may need to leave the @code{-c} on the command.)
Once you compile a shared object containing UDFs, you must install it
and tell @strong{MySQL} about it. Compiling a shared object from
@file{udf_example.cc} produces a file named something like
@file{udf_example.so} (the exact name may vary from platform to platform).
Copy this file to some directory searched by @code{ld}, such as
@file{/usr/lib}. On many systems, you can set the @code{LD_LIBRARY} or
@code{LD_LIBRARY_PATH} environment variable to point at the directory where
you have your UDF function files. The @code{dlopen} manual page tells you
which variable you should use on your system. You should set this in
@code{mysql.server} or @code{safe_mysqld} and restart @code{mysqld}.
After the library is installed, notify @code{mysqld} about the new
functions with these commands:
@example
mysql> CREATE FUNCTION metaphon RETURNS STRING SONAME "udf_example.so";
mysql> CREATE FUNCTION myfunc_double RETURNS REAL SONAME "udf_example.so";
mysql> CREATE FUNCTION myfunc_int RETURNS INTEGER SONAME "udf_example.so";
mysql> CREATE FUNCTION lookup RETURNS STRING SONAME "udf_example.so";
mysql> CREATE FUNCTION reverse_lookup RETURNS STRING SONAME "udf_example.so";
@end example
Functions can be deleted using @code{DROP FUNCTION}:
@example
mysql> DROP FUNCTION metaphon;
mysql> DROP FUNCTION myfunc_double;
mysql> DROP FUNCTION myfunc_int;
mysql> DROP FUNCTION lookup;
mysql> DROP FUNCTION reverse_lookup;
@end example
The @code{CREATE FUNCTION} and @code{DROP FUNCTION} statements update the
system table @code{func} in the @code{mysql} database. The function's name,
type and shared library name are saved in the table. You must have the
@strong{insert} and @strong{delete} privileges for the @code{mysql} database
to create and drop functions.
You should not use @code{CREATE FUNCTION} to add a function that has already
been created. If you need to reinstall a function, you should remove it with
@code{DROP FUNCTION} and then reinstall it with @code{CREATE FUNCTION}. You
would need to do this, for example, if you recompile a new version of your
function, so that @code{mysqld} gets the new version. Otherwise the server
will continue to use the old version.
Active functions are reloaded each time the server starts, unless you start
@code{mysqld} with the @code{--skip-grant-tables} option. In this case, UDF
initialization is skipped and UDFs are unavailable. (An active function is
one that has been loaded with @code{CREATE FUNCTION} and not removed with
@code{DROP FUNCTION}.)
@cindex Adding native functions
@cindex Native functions, adding
@cindex Functions, native, adding
@node Adding native function, , Adding UDF, Adding functions
@section Adding a new native function
The procedure for adding a new native function is described below. Note that
you cannot add native functions to a binary distribution because the procedure
involves modifying @strong{MySQL} source code. You must compile
@strong{MySQL} yourself from a source distribution. Also note that if you
migrate to another version of @strong{MySQL} (e.g., when a new version is
released), you will need to repeat the procedure with the new version.
To add a new native @strong{MySQL} function, follow these steps:
@enumerate
@item
Add one line to @file{lex.h} that defines the function name in the
@code{sql_functions[]} array.
@item
Add two lines to @file{sql_yacc.yy}. One indicates the preprocessor
symbol that @code{yacc} should define (this should be added at the
beginning of the file). Then define the function parameters and add an
``item'' with these parameters to the @code{simple_expr} parsing rule.
For an example, check all occurrences of @code{SOUNDEX} in
@file{sql_yacc.yy} to see how this is done.
@item
In @file{item_func.h}, declare a class inheriting from @code{Item_num_func} or
@code{Item_str_func}, depending on whether your function returns a number or a
string.
@item
In @file{item_func.cc}, add one of the following declarations, depending
on whether you are defining a numeric or string function:
@example
double Item_func_newname::val()
longlong Item_func_newname::val_int()
String *Item_func_newname::Str(String *str)
@end example
@item
You should probably also define the following function:
@example
void Item_func_newname::fix_length_and_dec()
@end example
This function should at least calculate @code{max_length} based on the
given arguments. @code{max_length} is the maximum number of characters
the function may return. This function should also set @code{maybe_null = 0}
if the main function can't return a @code{NULL} value. The function can check
if any of the function arguments can return @code{NULL} by checking the
arguments @code{maybe_null} variable.
@end enumerate
All functions must be thread-safe.
For string functions, there are some additional considerations to be aware of:
@itemize @bullet
@item
The @code{String *str} argument provides a string
buffer that may be used to hold the result.
@item
The function should return the string that holds the result.
@item
All current string functions try to avoid allocating any memory unless
absolutely necessary!
@end itemize
@node Adding procedures, ODBC, Adding functions, Top
@chapter Adding new procedures to MySQL
In @strong{MySQL}, you can define a procedure in C++ that can access and
modify the data in a query before it is sent to the client. The modification
can be done on row by row or @code{GROUP BY} level.
We have created an example procedure in @strong{MySQL} 3.23 to
show you what can be done.
@menu
* procedure analyse:: Procedure analyse
* Writing a procedure:: Writing a procedure.
@end menu
@node procedure analyse, Writing a procedure, Adding procedures, Adding procedures
@section Procedure analyse
@code{analyse([max elements,[max memory]])}
This procedure is defined in the @file{sql/sql_analyse.cc}. This
examines the result from your query and returns an analysis of the
results.
@itemize @bullet
@item
@code{max elements} (default 256) is the maximum number of distinct values
@code{analyse} will notice per column. This is used by @code{analyse} to check if
the optimal column type should be of type @code{ENUM}.
@item
@code{max memory} (default 8192) is the maximum memory @code{analyse} should
allocate per column while trying to find all distinct values.
@end itemize
@example
SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max elements,[max memory]])
@end example
@node Writing a procedure, , procedure analyse, Adding procedures
@section Writing a procedure.
For the moment, the only documentation for this is the source. :(
You can find all information about procedures by examining the following files:
@itemize @bullet
@item @file{sql/sql_analyse.cc}
@item @file{sql/procedure.h}
@item @file{sql/procedure.cc}
@item @file{sql/sql_select.cc}
@end itemize
@cindex ODBC
@cindex Windows
@cindex MyODBC
@node ODBC, Common programs, Adding procedures, Top
@chapter MySQL ODBC Support
@menu
* Which ODBC OS:: Operating systems supported by @strong{MyODBC}
* ODBC administrator:: How to fill in the various fields in the ODBC administrator program
* ODBC Problems:: How to report problems with @strong{MySQL} ODBC
* MyODBC clients:: Programs known to work with @strong{MyODBC}
* ODBC and last_insert_id:: How to get the value of an @code{AUTO_INCREMENT} column in ODBC
* MyODBC bug report:: Reporting problems with MyODBC
@end menu
@strong{MySQL} provides support for ODBC by means of the @strong{MyODBC}
program.
@node Which ODBC OS, ODBC administrator, ODBC, ODBC
@section Operating systems supported by MyODBC
@strong{MyODBC} is a 32-bit ODBC (2.50) level 0 driver for connecting
an ODBC-aware application to @strong{MySQL}. @strong{MyODBC} works on
Windows95, Windows98, NT and on most Unix platforms.
Normally you only need to install @strong{MyODBC} on Windows machines.
You only need @strong{MyODBC} for Unix if you have a program like
ColdFusion that is running on the Unix machine and uses ODBC to connect
to the databases.
@strong{MyODBC} is in public domain and you can find the newest version
at @uref{http://www.mysql.com/downloads/api-myodbc.html}.
If you want to install @strong{MyODBC} on a Unix box, you will also need
an @strong{ODBC} manager. @strong{MyODBC} is known to work with
most of the Unix ODBC managers. You can find a list at these in the
@strong{ODBC}-related links section on the @strong{MySQL} useful links page.
@xref{Useful Links}.
On Windows/NT you may get the following error when trying to install
@strong{MyODBC}:
@example
An error occurred while copying C:\WINDOWS\SYSTEM\MFC30.DLL. Restart Windows
and try installing again (before running any applications which use ODBC)
@end example
The problem in this case is that some other program is using ODBC and
because of how windows is designed, you cannot in this case install new
ODBC drivers with Microsoft's ODBC setup program. :( The solution to this
is to reboot your computer in ``safe mode`` (You can choose this by
pressing F8 just before your machine starts Windows during rebooting),
install @strong{MyODBC} and reboot to normal mode.
@itemize @bullet
@item
To make a connection to an Unix box from a Windows box, with an ODBC
application (one that doesn't support @strong{MySQL} natively), you must
first install @strong{MyODBC} on the Windows machine.
@item
The user and Windows machine must have the access privileges to the
@strong{MySQL} server the Unix machine. This is set up with the @code{GRANT}
command. @xref{GRANT,,@code{GRANT}}.
@item
You must create an ODBC DSN entry as follows:
@itemize @bullet
@item
Open the Control Panel on the Windows machine.
@item
Double click the ODBC Data Sources 32 bits icon.
@item
Click the tab User DSN.
@item
Click the button Add.
@item
Select @strong{MySQL} in the screen Create New Data Source and click
the Finish button.
@item
The @strong{MySQL} Driver default configuration screen is shown.
@xref{ODBC administrator}.
@end itemize
@item
Now start your application and select the ODBC driver with the DSN you
specified in the ODBC administrator.
@end itemize
Notice that there are other configuration options in the screen of
@strong{MySQL} (trace, don't prompt on connect, etc) that you can try if
you run into problems.
@node ODBC administrator, ODBC Problems, Which ODBC OS, ODBC
@section How to fill in the various fields in the ODBC administrator program
There are three possibilities for specifying the server name on
Windows95:
@itemize @bullet
@item
Use the IP address of the server.
@item
Add a file @file{\windows\lmhosts} with the following information:
@example
ip hostname
@end example
For example:
@example
194.216.84.21 my_hostname
@end example
@item
Configure the PC to use DNS.
@end itemize
Example of how to fill in the @code{ODBC setup}
@example
Windows DSN name: test
Description: This is my test database
MySql Database: test
Server: 194.216.84.21
User: monty
Password: my_password
Port:
@end example
The value for the @code{Windows DSN name} field is any name that is unique
in your Windows ODBC setup.
You don't have to specify values for the @code{Server}, @code{User},
@code{Password} or @code{Port} fields in the ODBC setup screen.
However, if you do, the values will be used as the defaults later when
you attempt to make a connection. You have the option of changing the
values at that time.
If the port number is not given, the default port (@value{default_port})
is used.
If you specify the option @code{Read options from C:\my.cnf}, the groups
@code{client} and @code{odbc} will be read from the @file{C:\my.cnf} file.
You can use all options that are usable by @code{mysql_options()}.
@xref{mysql_options, , @code{mysql_options}}.
@node ODBC Problems, MyODBC clients, ODBC administrator, ODBC
@section How to report problems with MyODBC
@strong{MyODBC} has been tested with Access, Admndemo.exe, C++-Builder,
Borland Builder 4, Centura Team Developer (formerly Gupta SQL/Windows),
ColdFusion (on Solaris and NT with svc pack 5), Crystal Reports,
DataJunction, Delphi, ERwin, Excel, iHTML, FileMaker Pro, FoxPro, Notes
4.5/4.6, SBSS, Perl DBD-ODBC, Paradox, Powerbuilder, Powerdesigner 32
bit, VC++ and Visual Basic.
If you know of any other applications that work with @strong{MyODBC}, please
mail @email{myodbc@@lists.mysql.com} about this!
With some programs you may get an error like:
@code{Another user has modifies the record that you have modified}. In most
cases this can be solved by doing one of the following things:
@itemize @bullet
@item
Add a primary key for the table if there isn't one already.
@item
Add a timestamp column if there isn't one already.
@item
Only use double float fields. Some programs may fails when they comparing
single floats.
@end itemize
If the above doesn't help, you should do a @code{MyODBC} trace file and
from this try to figure out why things goes wrong.
@node MyODBC clients, ODBC and last_insert_id, ODBC Problems, ODBC
@section Programs known to work with MyODBC
Most programs should work with @strong{MyODBC}, but for each of those
listed below, we have tested it ourselves or gotten confirmation from
some user that it works:
@table @asis
@item @strong{Program}
@strong{Comment}
@item Access
To make Access work:
@itemize @bullet
@item
You should have a primary key in the table.
@item
You should have a timestamp in all tables you want to be able to update.
@item
Only use double float fields. Access fails when comparing with single floats.
@item
Set the `Return matching rows' option field when connecting to @strong{MySQL}.
@item
Access on NT will report @code{BLOB} columns as @code{OLE OBJECTS}. If
you want to have @code{MEMO} columns instead, you should change the
column to @code{TEXT} with @code{ALTER TABLE}.
@item
Access can't always handle @code{DATE} columns properly. If you have a problem
with these, change the columns to @code{DATETIME}.
@item
In some cases, Access may generate illegal SQL queries that
@strong{MySQL} can't understand. You can fix this by selecting
@code{"Query|SQLSpecific|Pass-Through"} from the Access menu.
@end itemize
@item Borland Builder 4
When you start a query you can use the property @code{Active} or use the
method @code{Open}. Note that @code{Active} will start by automatically issue
a @code{SELECT * FROM ...} query that may not be a good thing if your tables
are big!
@item ColdFusion (On Unix)
The following information is taken from the ColdFusion documentation:
Use the following information to configure ColdFusion Server for Linux
to use the unixODBC driver with @strong{MyODBC} for @strong{MySQL} data
sources. Allaire has verified that @strong{MyODBC} version 2.50.26
works with @strong{MySQL} version 3.22.27 and ColdFusion for Linux. (Any
newer version should also work). You can download @strong{MyODBC} at
@uref{http://www.mysql.com/downloads/api-myodbc.html}
ColdFusion 4.5.1 allows you to us the ColdFusion Administrator to add
the @strong{MySQL} data source. However, the driver is not included with
ColdFusion 4.5.1. Before the @strong{MySQL} driver will appear in the ODBC
datasources drop-down list, you must build and copy the @strong{MyODBC} driver
to @file{/opt/coldfusion/lib/libmyodbc.so}.
@item DataJunction
You have to change it to output @code{VARCHAR} rather than @code{ENUM}, as
it exports the latter in a manner that causes @strong{MySQL} grief.
@item Excel
Works. Some tips:
@itemize @bullet
@item
If you have problems with dates, try to select them as strings using the
@code{CONCAT()} function. For example:
@example
select CONCAT(rise_time), CONCAT(set_time)
from sunrise_sunset;
@end example
Values retrieved as strings this way should be correctly recognized
as time values by Excel97.
The purpose of @code{CONCAT()} in this example is to fool ODBC into thinking
the column is of ``string type''. Without the @code{CONCAT()}, ODBC knows the
column is of time type, and Excel does not understand that.
Note that this is a bug in Excel, because it automatically converts a
string to a time. This would be great if the source was a text file, but
is plain stupid when the source is an ODBC connection that reports
exact types for each column.
@end itemize
@item odbcadmin
Test program for ODBC.
@item Delphi
You must use DBE 3.2 or newer. Set the `Don't optimize column width'
option field when connecting to @strong{MySQL}.
Also, here is some potentially useful Delphi code that sets up both an
ODBC entry and a BDE entry for @strong{MyODBC} (the BDE entry requires a BDE
Alias Editor which may be had for free at a Delphi Super Page near
you.): (Thanks to Bryan Brunton @email{bryan@@flesherfab.com} for this)
@example
fReg:= TRegistry.Create;
fReg.OpenKey('\Software\ODBC\ODBC.INI\DocumentsFab', True);
fReg.WriteString('Database', 'Documents');
fReg.WriteString('Description', ' ');
fReg.WriteString('Driver', 'C:\WINNT\System32\myodbc.dll');
fReg.WriteString('Flag', '1');
fReg.WriteString('Password', '');
fReg.WriteString('Port', ' ');
fReg.WriteString('Server', 'xmark');
fReg.WriteString('User', 'winuser');
fReg.OpenKey('\Software\ODBC\ODBC.INI\ODBC Data Sources', True);
fReg.WriteString('DocumentsFab', 'MySQL');
fReg.CloseKey;
fReg.Free;
Memo1.Lines.Add('DATABASE NAME=');
Memo1.Lines.Add('USER NAME=');
Memo1.Lines.Add('ODBC DSN=DocumentsFab');
Memo1.Lines.Add('OPEN MODE=READ/WRITE');
Memo1.Lines.Add('BATCH COUNT=200');
Memo1.Lines.Add('LANGDRIVER=');
Memo1.Lines.Add('MAX ROWS=-1');
Memo1.Lines.Add('SCHEMA CACHE DIR=');
Memo1.Lines.Add('SCHEMA CACHE SIZE=8');
Memo1.Lines.Add('SCHEMA CACHE TIME=-1');
Memo1.Lines.Add('SQLPASSTHRU MODE=SHARED AUTOCOMMIT');
Memo1.Lines.Add('SQLQRYMODE=');
Memo1.Lines.Add('ENABLE SCHEMA CACHE=FALSE');
Memo1.Lines.Add('ENABLE BCD=FALSE');
Memo1.Lines.Add('ROWSET SIZE=20');
Memo1.Lines.Add('BLOBS TO CACHE=64');
Memo1.Lines.Add('BLOB SIZE=32');
AliasEditor.Add('DocumentsFab','MySQL',Memo1.Lines);
@end example
@item C++Builder
Tested with BDE 3.0. The only known problem is that when the table
schema changes, query fields are not updated. BDE however does not seem
to recognize primary keys, only the index PRIMARY, though this has not
been a problem.
@item Visual Basic
To be able to update a table, you must define a primary key for the table.
Visual Basic with ADO can't handle big integers; This means that some queries
like @code{SHOW PROCESSLIST} will not work properly. The fix is to set
add the option @code{OPTION=16834} in the ODBC connect string or set
the @code{Change BIGINT columns to INT} option in the MyODBC connect screen.
@end table
@node ODBC and last_insert_id, MyODBC bug report, MyODBC clients, ODBC
@section How to get the value of an @code{AUTO_INCREMENT} column in ODBC
A common problem is how to get the value of an automatically generated ID
from an @code{INSERT}. With ODBC, you can do something like this (assuming
that @code{auto} is an @code{AUTO_INCREMENT} field):
@example
INSERT INTO foo (auto,text) VALUES(NULL,'text');
SELECT LAST_INSERT_ID();
@end example
Or, if you are just going to insert the ID into another table, you can do this:
@example
INSERT INTO foo (auto,text) VALUES(NULL,'text');
INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text');
@end example
For the benefit of some ODBC applications (at least Delphi and Access),
the following query can be used to find a newly-inserted row:
@example
SELECT * FROM tbl_name WHERE auto IS NULL;
@end example
@node MyODBC bug report, , ODBC and last_insert_id, ODBC
@section Reporting problems with MyODBC
If you encounter difficulties with @strong{MyODBC}, you should start by
making a log file from the ODBC manager (the log you get when requesting
logs from ODBCADMIN) and a @strong{MyODBC} log. To get a @strong{MyODBC}
log, tag the `Trace MyODBC' option flag in the @strong{MyODBC}
connect/configure screen. The log will be written to file
@file{C:\myodbc.log}. Note that you must use @code{MYSQL.DLL} and not
@code{MYSQL2.DLL} for this option to work!
Check the queries that MyODBC sends to the @strong{MySQL} server; You
should be able to find this by searching after the string
@code{>mysql_real_query} in the @file{myodbc.log} file.
You should also try duplicating the queries in the @code{mysql} monitor
or @code{admndemo} to find out if the error is MyODBC or @strong{MySQL}.
If you find out something is wrong, please only send the relevant rows
(max 40 rows) to the @email{myodbc@@lists.mysql.com}. Please never
send the whole MyODBC or ODBC log file!
If you are unable to find out what's wrong, the last option is to to
make an archive (tar or zip) that contains a MyODBC log file, the ODBC
log file and a README file that explains the problem. You can send this
to @uref{ftp://support.mysql.com/pub/mysql/secret}. Only we at MySQL AB
will have access to the files you upload and we will be very discrete
with the data!
If you can create a program that also shows this problem, please
upload this too!
If the program works with some other SQL server, you should make an ODBC log
file where you do exactly the same thing in the other SQL server.
Remember that the more information you can supply to us, the more
likely it is that we can fix the problem!
@node Common programs, Problems, ODBC, Top
@chapter Using @code{MySQL} with some common programs
@menu
* Apache:: Using @strong{MySQL} with Apache
@end menu
@node Apache, , Common programs, Common programs
@section Using MySQL with Apache
The contrib section includes programs that let you authenticate your
users from a @strong{MySQL} database and also let you log your log files
into a @strong{MySQL} table. @xref{Contrib}.
You can change the Apache logging format to be easily readable by
@code{MySQL} by putting the following into the Apache configuration file:
@example
LogFormat \
"\"%h\",%@{%Y%m%d%H%M%S@}t,%>s,\"%b\",\"%@{Content-Type@}o\", \
\"%U\",\"%@{Referer@}i\",\"%@{User-Agent@}i\""
@end example
In @strong{MySQL} you can do something like this:
@example
LOAD DATA INFILE '/local/access_log' INTO TABLE table_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'
@end example
@node Problems, Common problems, Common programs, Top
@chapter Problems and common errors
@menu
* What is crashing:: How to determinate what is causing problems
* Crashing:: What to do if @strong{MySQL} keeps crashing
* Link errors:: Problems when linking with the @strong{MySQL} client library
* Common errors:: Some common errors when using @strong{MySQL}
* Full disk:: How @strong{MySQL} handles a full disk
* Multiple sql commands:: How to run SQL commands from a text file
* Temporary files:: Where @strong{MySQL} stores temporary files
* Problems with mysql.sock:: How to protect @file{/tmp/mysql.sock}
* Error Access denied:: @code{Access denied} error
* Changing MySQL user :: How to run @strong{MySQL} as a normal user
* Resetting permissions:: How to reset a forgotten password.
* File permissions :: Problems with file permissions
* Not enough file handles:: File not found
* Using DATE:: Problems using @code{DATE} columns
* Timezone problems:: Timezone problems
* Case sensitivity:: Case sensitivity in searches
* Problems with NULL:: Problems with @code{NULL} values
* Problems with alias:: Problems with @code{alias}
* Deleting from related tables:: Deleting rows from related tables
* No matching rows:: Solving problems with no matching rows
* ALTER TABLE problems:: Problems with @code{ALTER TABLE}.
* Change column order:: How to change the order of columns in a table
@end menu
@node What is crashing, Crashing, Problems, Problems
@section How to determinate what is causing problems
When you run into problems, the first thing you should do is to find out
which program / piece of equipment is causing problems.
@itemize @bullet
@item
If you have one of the following symptoms, then it is probably a hardware
(like memory, motherboard, CPU, or harddisk) or kernel problem:
@itemize @bullet
@item
The keyboard doesn't work. This can normally be checked by pressing
Caps Lock; If the Caps Lock light doesn't change you have to replace
your keyboard. (Before doing this, you should however try to reboot
your computer and check all cables to the keyboard :)
@item
The mouse pointer doesn't move.
@item
The machine doesn't answer to a remote machine's pings.
@item
Different, unrelated programs don't behave correctly.
@item
If your system rebooted unexpectedly (a faulty user level program should
NEVER be able to take down your system).
@end itemize
In this case you should start by checking all your cables and run some
diagnostic tool to check your hardware!
You should also check if there are any patches, updates or service
packs for your operating system that could likely solve your problems.
Check also that all your libraries (like glibc) are up to date.
It's always good to use a machine with ECC memory to discover
memory problems early!
@item
If your keyboard is locked up, you may be able to fix this by
logging into your machine from another machine and execute
@code{kbd_mode -a} on it.
@item
Please examine your system log file, (/var/log/messages or similar) for
reasons for your problems. If you think the problem is in @strong{MySQL}
then you should also examine @strong{MySQL}'s log files. @xref{Update log}.
@item
If you don't think you have hardware problems, you should try to find
out which program is causing problems.
Try using @code{top}, @code{ps}, @code{taskmanager} or some similar program,
to check which program is taking all CPU, or is locking the machine.
@item
Check with @code{top}, @code{df} or a similar programs if you are out of
memory, disk space, open files or some other critical resource.
@item
If the problem is some runaway process, you can always try to kill if. If it
doesn't want to die, this is probably a bug in the operating system.
@end itemize
If after you have examined all other possibilities and you have
concluded that its the @strong{MySQL} server or a @strong{MySQL} client
that is causing the problem, it's time to do a bug report for our
mailing list or our support team. In the bug report, try to describe
very detailed how the system is behaving and what you think is
happening. You should also state why you think it's @strong{MySQL} that
is causing the problems. Take in consideration all the situations in
this chapter. State any problems exactly how they appear when you
examine your system.. Use the 'cut and paste' method for any output
and/or error messages from programs and/or log files!
Try to describe very detailed which program is not working and all
symptoms you see! We have in the past got many bug reports that just
states "the system doesn't work". This doesn't provide us with any
information of what could be the problem.
If a program fails, it's always useful to know:
@itemize @bullet
@item
Has the program in question made a segmentation fault (core dumped)?
@item
Is the program taking the whole CPU? Check with @code{top}. Let the
program run for a while, it may be evaluating something heavy.
@item
If it's the @code{mysqld} server that is causing problems; Can you
do @code{mysqladmin -u root ping}, or @code{mysqladmin -u root processlist}?
@item
What does a client program say (try with @code{mysql} for example)
when you try to connect to the @strong{MySQL} server?
Does the client jam? Do you get any output from the program?
@end itemize
When send a bug report, you should of course follow the outlines
described in this manual. @xref{Asking questions}.
@node Crashing, Link errors, What is crashing, Problems
@section What to do if MySQL keeps crashing
All @strong{MySQL} versions are tested on many platforms before they are
released. This doesn't mean that there isn't any bugs in
@strong{MySQL}, but that if there are bugs they are very few and can be
hard to find. If you have a problem, it will always help if you try to
find out exactly what crashes your system as you will have a much better
chance of getting this fixed quickly.
First you should try to find out whether the problem is that the
@code{mysqld} daemon dies or whether your problem has to do with your
client. You can check how long your @code{mysqld} server has been up by
executing @code{mysqladmin version}. If @code{mysqld} has died, you may
find the reason for this in the file
@file{mysql-data-directory/'hostname'.err}.
Many crashes of @strong{MySQL} is caused by corrupted index / data
files. @strong{MySQL} will update the data on disk, with the
@code{write()} system call, after every SQL statement and before the
client is notified about the result (this is not true if you are running
with @code{delayed_key_writes}, in which case only the data is written).
This means that the data is safe even if mysqld crashes as the OS will
ensure that the not flushed data is written to disk. You can force
@strong{MySQL} to sync everything to disk after every SQL command by
starting @code{mysqld} with @code{--flush}.
The above means that normally you shouldn't get corrupted tables unless:
@itemize @bullet
@item
Someone/something killed @code{mysqld} or the machine in the middle
of an update.
@item
You have found a bug in @code{mysqld} that caused it to die in the
middle of an update.
@item
Someone is manipulating the data/index files outside of @strong{mysqld}
without locking the table properly.
@item
If you are running many @code{mysqld} servers on the same data on a
system that doesn't support good file system locks (normally handled by
the @code{lockd} deamon.) or if you are running
multiple servers with @code{--skip-locking}
@item
You have a crashed index/data file that contains very wrong data that
got mysqld confused.
@item
You have found a bug in the data storage code. This isn't that likely,
but it's at least possible. In this case you can try to change the file
type to another database handler by using @code{ALTER TABLE} on a
repaired copy of the table!
@end itemize
Because it is very difficult to know why something is crashing, first try to
check whether or not things that work for others crash for you. Please try
the following things:
@itemize @bullet
@item
Take down the @code{mysqld} daemon with @code{mysqladmin shutdown}, run
@code{myisamchk --silent --force */*.MYI} on all tables and restart the
@code{mysqld} daemon. This will ensure that you are running from a clean
state. @xref{Maintenance}.
@item
Use @code{mysqld --log} and try to determine from the information in the log
whether or not some specific query kills the server. 95% of all bugs are
related to a particular query! Normally this is one of the last queries in
the log file just before @strong{MySQL} restarted.
You may be able to verify this using the following procedure:
@itemize @bullet
@item
Take down the @strong{MySQL} daemon (with @code{mysqladmin shutdown})
@item
Make a backup of files in the @strong{MySQL} database directory.
(As the server is stopped, you can just copy the files to some other
directory)
@item
Check the tables with @code{myisamchk -s */*.MYI} to verify that all
tables are correct. If any table is corrupted, repair it with
@code{myisamchk -r path-to-table.MYI}. You should take the backup
before checking the tables as the problem could be related to corrupted
tables.
@item
Remove (or move away) any old log files from the @strong{MySQL} data directory.
@item
Start the server with @code{safe_mysqld --log-update} or
@code{safe_mysqld --log --log-update}.
@item
If @code{mysqld} now dies, you have two options:
@itemize @bullet
@item
First take a backup of your backup database. (Just copy the file(s)
somewhere again). This is because we want to keep the original start
situation untouched. Start a mysqld process on the other backup database
(you can do this with option @code{--datadir=/path/to/backup/}).
@item
Just restore the backup on your original database and restart @code{mysqld}.
You will not any lose information, because you have the @code{log-update} file.
@end itemize
@item
Now you can test if the problem is a specific update statement by executing
@code{mysql database_name < path-to-log-update-file}.
You can also use the script @code{mysql_find_rows} to just execute some of the
update statements if you want to narrow down the problem.
If mysqld now crashes, then you have something repeatable
available. Please mail @email{bugs@@lists.mysql.com}, or
@email{developers@@mysql.com}, or (if you are a support customer) to
@email{support@@mysql.com} about the problem and the @strong{MySQL} team
will fix it as soon as possible.
@end itemize
@item
Have you tried the benchmarks? They should test @strong{MySQL} rather well.
You can also add code that simulates your application! The benchmarks can be
found in the @file{bench} directory in the source distribution, or, for a
binary distribution, in the @file{sql-bench} directory under your
@strong{MySQL} installation directory.
@item
Try @code{fork_test.pl} and @code{fork2_test.pl}.
@item
Check the file @file{mysql-data-directory/'hostname'.err} for any errors.
@item
If you configure @strong{MySQL} for debugging, it will be much easier to
gather information about possible errors if something goes wrong.
Reconfigure @strong{MySQL} with the @code{--with-debug} option to
@code{configure} and then recompile. @xref{Debugging server}.
@item
Configuring @strong{MySQL} for debugging causes a safe memory allocator to be
included that can find some errors. It also provides a lot of output about
what is happening.
@item
Have you applied the latest patches for your operating system?
@item
Use the @code{--skip-locking} option to @code{mysqld}. On some systems, the
@code{lockd} lock manager does not work properly; the @code{--skip-locking}
option tells @code{mysqld} not to use external locking. (This means that you
cannot run 2 @code{mysqld} servers on the same data and that you must be
careful if you use @code{myisamchk}, but it may be instructive to try the
option as a test.)
@item
Have you tried @code{mysqladmin -u root processlist} when @code{mysqld}
appears to be running but not responding? Sometimes @code{mysqld} is not
comatose even though you might think so. The problem may be that all
connections are in use, or there may be some internal lock problem.
@code{mysqladmin processlist} will usually be able to make a connection even
in these cases, and can provide useful information about the current number
of connections and their status.
@item
Run the command @code{mysqladmin -i 5 status}
in a separate window to produce statistics while you run your other queries.
@item
Try the following:
@enumerate
@item
Start @code{mysqld} from @code{gdb} (or in another debugger).
@item
Run your test scripts.
@item
Print the backtrace and the local variables at the 3 lowest levels. In gdb you
can do this with the following commands when @code{mysqld} has crashed inside
gdb:
@example
backtrace
info local
up
info local
up
info local
@end example
With gdb you can also examine which threads there exists with @code{info
threads} and switch to a specific thread with @code{thread #}, where
@code{#} is the thread id.
@end enumerate
@item
Try to simulate your application with a Perl script to force
@strong{MySQL} to crash or misbehave.
@item
Send a normal bug report. @xref{Bug reports}. Be even more detailed
than usual. Because @strong{MySQL} works for many people, it may be that the
crash results from something that exists only on your computer (for example,
an error that is related to your particular system libraries).
@item
If you have a problem with table with dynamic length rows and you are
not using @code{BLOB/TEXT} columns (but only @code{VARCHAR} columns) you
can try to change all @code{VARCHAR} to @code{CHAR} with @code{ALTER
TABLE}. This will force @strong{MySQL} to use fixed size rows. Fixed
size rows take a little extra space, but are much more tolerant to
corruption!
The current dynamic row code has been in use at MySQL AB for at least 3
years without any problems, but by nature dynamic length rows are more
prone to errors, so it may be a good idea to try the above to see if it helps!
@end itemize
@node Link errors, Common errors, Crashing, Problems
@section Problems when linking with the MySQL client library
If you are linking your program and you get errors for unreferenced
symbols that starts with @code{mysql_}, like the following:
@example
/tmp/ccFKsdPa.o: In function `main':
/tmp/ccFKsdPa.o(.text+0xb): undefined reference to `mysql_init'
/tmp/ccFKsdPa.o(.text+0x31): undefined reference to `mysql_real_connect'
/tmp/ccFKsdPa.o(.text+0x57): undefined reference to `mysql_real_connect'
/tmp/ccFKsdPa.o(.text+0x69): undefined reference to `mysql_error'
/tmp/ccFKsdPa.o(.text+0x9a): undefined reference to `mysql_close'
@end example
you should be able to solve this by adding @code{-Lpath-to-the-mysql-library
-lmysqlclient} @strong{LAST} on your link line.
If you get @code{undefined reference} errors for the @code{compress} function,
add @code{-lgz} @strong{LAST} on your link line and try again!
If you get @code{undefined reference} errors for functions that should
exist on your system, like @code{connect}, check the man page, for the
function in question, for which libraries you should add to the link
line!
If you get @code{undefined reference} errors for functions that doesn't
exist on your system, like the following:
@example
mf_format.o(.text+0x201): undefined reference to `__lxstat'
@end example
It usually means that your library is compiled on a system that is not
100 % compatible with yours. In this case you should download the
latest @strong{MySQL} source distribution and compile this yourself.
@xref{Installing source}.
If you are trying to run a program and you then get errors for
unreferenced symbols that starts with @code{mysql_} or that the
@code{mysqlclient} library can't be found, this means that your system
can't find the share @code{libmysqlclient.so} library.
The fix for this is to either tell your system to search after shared
libraries where the library is located by one of the following methods:
@itemize @bullet
@item
Add the path to directory where you have @code{libmysqlclient.so} the
@code{LD_LIBRARY_PATH} environment variable.
@item
Add the path to directory where you have @code{libmysqlclient.so} the
@code{LD_LIBRARY} environment variable.
@item
Copy @code{libmysqlclient.so} to some place that is searched by your system,
like @file{/lib} and update the shared library information by executing
@code{ldconfig}.
@end itemize
Another way to solve this problem is to link your program staticly, with
@code{-static}, or by removing the dynamic @strong{MySQL} libraries
before linking your code. In the second case you should of course be
sure that no other programs is using the dynamic libraries!
@node Common errors, Full disk, Link errors, Problems
@section Some common errors when using MySQL
@menu
* Gone away:: @code{MySQL server has gone away} error
* Can not connect to server:: @code{Can't connect to [local] MySQL server} error
* Blocked host:: @code{Host '...' is blocked} error
* Too many connections:: @code{Too many connections} error
* Out of memory:: @code{Out of memory} error
* Packet too large:: @code{Packet too large} error
* Communication errors::
* Full table:: @code{The table is full} error
* Commands out of sync:: @code{Commands out of sync} error in client
* Ignoring user:: @code{Ignoring user} error
* Cannot find table:: @code{Table 'xxx' doesn't exist} error
@end menu
@node Gone away, Can not connect to server, Common errors, Common errors
@subsection @code{MySQL server has gone away} error
This section also covers the related @code{Lost connection to server
during query} error.
The most common reason for the @code{MySQL server has gone away} error
is that the server timed out and closed the connection. By default, the
server closes the connection after 8 hours if nothing has happened. You
can change the time limit with by setting the @code{wait_timeout} variable when
you start mysqld.
You can check that the @strong{MySQL} hasn't died by executing
@code{mysqladmin version} and examining the uptime.
If you have a script, you just have to issue the query again for the client
to do an automatic reconnection.
You normally can get the following error codes in this case
(which one you get is OS-dependent):
@multitable @columnfractions .3 .7
@item @code{CR_SERVER_GONE_ERROR} @tab The client couldn't send a question to the
server.
@item @code{CR_SERVER_LOST} @tab The client didn't get an error when writing
to the server, but it didn't get a full answer (or any answer) to the question.
@end multitable
You can also get these errors if you send a query to the server that is
incorrect or too large. If @code{mysqld} gets a packet that is too large
or out of order, it assumes that something has gone wrong with the client and
closes the connection. If you need big queries (for example, if you are
working with big @code{BLOB} columns), you can increase the query limit by
starting @code{mysqld} with the @code{-O max_allowed_packet=#} option
(default 1M). The extra memory is allocated on demand, so @code{mysqld} will
use more memory only when you issue a big query or when @code{mysqld} must
return a big result row!
@node Can not connect to server, Blocked host, Gone away, Common errors
@subsection @code{Can't connect to [local] MySQL server} error
A @strong{MySQL} client on Unix can connect to the @code{mysqld} server in two
different ways: Unix sockets, which connect through a file in the file
system (default @file{/tmp/mysqld.sock}), or TCP/IP, which connects
through a port number. Unix sockets are faster than TCP/IP but can only
be used when connecting to a server on the same computer. Unix sockets
are used if you don't specify a hostname or if you specify the special
hostname @code{localhost}.
On Windows you can connect only with TCP/IP if the @code{mysqld} server
is running on Win95/Win98. If it's running on NT, you can also connect
with named pipes. The name of the named pipe is @code{MySQL}. If you
don't give a hostname when connecting to @code{mysqld}, a @strong{MySQL} client
will first try to connect to the named pipe and if this doesn't work it
will connect to the TCP/IP port. You can force the use of named pipes
on Windows by using @code{.} as the hostname.
The error (2002) @code{Can't connect to ...} normally means that there
isn't a @strong{MySQL} server running on the system or that you are
using a wrong socket file or TCP/IP port when trying to connect to the
@code{mysqld} server.
Start by checking (using @code{ps} or the task manager on Windows) that
there is a process running named @code{mysqld} on your server! If there
isn't any @code{mysqld} process, you should start one. @xref{Starting
server}.
If a @code{mysqld} process is running, you can check the server by
trying these different connections (the port number and socket pathname
might be different in your setup, of course):
@example
shell> mysqladmin version
shell> mysqladmin variables
shell> mysqladmin -h `hostname` version variables
shell> mysqladmin -h `hostname` --port=3306 version
shell> mysqladmin -h 'ip for your host' version
shell> mysqladmin --socket=/tmp/mysql.sock version
@end example
Note the use of backquotes rather than forward quotes with the @code{hostname}
command; these cause the output of @code{hostname} (i.e., the current
hostname) to be substituted into the @code{mysqladmin} command.
Here are some reasons the @code{Can't connect to local MySQL server}
error might occur:
@itemize @bullet
@item @code{mysqld} is not running.
@item You are running on a system that uses MIT-pthreads.
If you are running on a system that doesn't have native threads, @code{mysqld}
uses the MIT-pthreads package.
@xref{Which OS}.
However, MIT-pthreads doesn't support Unix sockets, so on such a system you
must always specify the hostname explicitly when connecting to the server.
Try using this command to check the connection to the server:
@example
shell> mysqladmin -h `hostname` version
@end example
@item Someone has removed the Unix socket that @code{mysqld} uses (default
@file{/tmp/mysqld.sock}). You might have a @code{cron} job that removes the
@strong{MySQL} socket (e.g., a job that removes old files from the @file{/tmp}
directory). You can always run @code{mysqladmin version} and
check that the socket @code{mysqladmin} is trying to use really exists.
The fix in this case is to change the @code{cron} job to not remove
@file{mysqld.sock} or to place the socket somewhere else. You can specify
a different socket location at @strong{MySQL} configuration time with this
command:
@example
shell> ./configure --with-unix-socket-path=/path/to/socket
@end example
You can also start @code{safe_mysqld} with the
@code{--socket=/path/to/socket} option and set the environment variable
@code{MYSQL_UNIX_PORT} to the socket pathname before starting your
@strong{MySQL} clients. @item You have started the @code{mysqld} server with
the @code{--socket=/path/to/socket} option. If you change the socket
pathname for the server, you must also notify the @strong{MySQL} clients
about the new path. You can do this by setting the environment variable
@code{MYSQL_UNIX_PORT} to the socket pathname or by providing the socket path
as an argument to the clients. You can test the socket with this command:
@example
shell> mysqladmin --socket=/path/to/socket version
@end example
@item
You are using Linux and one thread has died (core dumped). In this case
you must kill the other @code{mysqld} threads (for example with the
@code{mysql_zap} script before you can start a new @strong{MySQL}
server. @xref{Crashing}.
@end itemize
If you get the error message @code{Can't connect to MySQL server on
some_hostname}, you can try the following things to find out what is the
problem:
@itemize @bullet
@item
Check if the server up by doing @code{telnet your-host-name
tcp-ip-port-number} and press @code{RETURN} a couple of times. If there
is a @strong{MySQL} server running on this port you should get a
responses that includes the version number of the running @strong{MySQL}
server. If you get an error like @code{telnet: Unable to connect to
remote host: Connection refused}, then there is no server running on the
given port.
@item
Try connecting to the @code{mysqld} daemon on the local machine and check
the TCP/IP port that mysqld it's configured to use (variable @code{port}) with
@code{mysqladmin variables}.
@item
Check that your @code{mysqld} server is not started with the
@code{--skip-networking} option.
@end itemize
@node Blocked host, Too many connections, Can not connect to server, Common errors
@subsection @code{Host '...' is blocked} error
If you get an error like this:
@example
Host 'hostname' is blocked because of many connection errors.
Unblock with 'mysqladmin flush-hosts'
@end example
This means that @code{mysqld} has gotten a lot (@code{max_connect_errors})
of connect requests from the host @code{'hostname'} that have been interrupted
in the middle. After @code{max_connect_errors} failed requests, @code{mysqld}
assumes that something is wrong (like an attack from a cracker), and
blocks the site from further connections until someone executes the command
@code{mysqladmin flush-hosts}.
By default, @code{mysqld} blocks a host after 10 connection errors.
You can easily adjust this by starting the server like this:
@example
shell> safe_mysqld -O max_connect_errors=10000 &
@end example
Note that if you get this error message for a given host, you should first
check that there isn't anything wrong with TCP/IP connections from that
host. If your TCP/IP connections aren't working, it won't do you any good to
increase the value of the @code{max_connect_errors} variable!
@node Too many connections, Out of memory, Blocked host, Common errors
@subsection @code{Too many connections} error
If you get the error @code{Too many connections} when you try to connect
to @strong{MySQL}, this means that there is already @code{max_connections}
clients connected to the @code{mysqld} server.
If you need more connections than the default (100), then you should restart
@code{mysqld} with a bigger value for the @code{max_connections} variable.
Note that @code{mysqld} actually allows (@code{max_connections}+1) clients to connect.
The last connection is reserved for a user with the @strong{process} privilege.
By not giving this privilege to normal users (they shouldn't need this), an
administrator with this privilege can login and use @code{SHOW PROCESSLIST}
to find out what could be wrong. @xref{SHOW}.
@node Out of memory, Packet too large, Too many connections, Common errors
@subsection @code{Out of memory} error
If you issue a query and get something like the following error:
@example
mysql: Out of memory at line 42, 'malloc.c'
mysql: needed 8136 byte (8k), memory in use: 12481367 bytes (12189k)
ERROR 2008: MySQL client ran out of memory
@end example
Note that the error refers to the @strong{MySQL} client @code{mysql}. The
reason for this error is simply that the client does not have enough memory to
store the whole result.
To remedy the problem, first check that your query is correct. Is it
reasonable that it should return so many rows? If so,
you can use @code{mysql --quick}, which uses @code{mysql_use_result()}
to retrieve the result set. This places less of a load on the client (but
more on the server).
@node Packet too large, Communication errors, Out of memory, Common errors
@subsection @code{Packet too large} error
When a @strong{MySQL} client or the @code{mysqld} server gets a packet bigger
than @code{max_allowed_packet} bytes, it issues a @code{Packet too large}
error and closes the connection.
If you are using the @code{mysql} client, you may specify a bigger buffer by
starting the client with @code{mysql --set-variable=max_allowed_packet=8M}.
If you are using other clients that do not allow you to specify the maximum
packet size (such as @code{DBI}), you need to set the packet size when you
start the server. You cau use a command-line option to @code{mysqld} to set
@code{max_allowed_packet} to a larger size. For example, if you are
expecting to store the full length of a @code{BLOB} into a table, you'll need
to start the server with the @code{--set-variable=max_allowed_packet=24M}
option.
@cindex Aborted connection
@node Communication errors, Full table, Packet too large, Common errors
@subsection Communication errors / Aborted connection
If you find the error @code{Aborted connection} in the @code{hostname.err}
log file this could be because on of the following reasons:
@itemize @bullet
@item
The client had been sleeping more than @code{wait_timeout} without doing
any requests. @xref{SHOW VARIABLES}.
@item
The client program ended abruptly in the middle of the transfer
@item
The client program did not call @code{mysql_close()} before exit
@item
Usage of duplex Ethernet protocol, both half and full with
Linux. Many Linux Ethernet drivers have this bug. You should test
for this bug by transferring a huge file via ftp between these tow
machines. If a transfer goes in burst-pause-burst-pause .. mode then
you are experiencing a Linux duplex syndrome. The only solution to
this problem is switching of both half and full duplexing on hubs
and switches
@item
Some problem with the thread library that causes interrupts on reads.
@item
Badly configured TCP/IP
@item
Faulty Ethernets or hubs or switches, cables .. This can be diagnosed
properly only by replacing hardware
@end itemize
@cindex The table is full
@node Full table, Commands out of sync, Communication errors, Common errors
@subsection @code{The table is full} error
This error occurs in older @strong{MySQL} versions when an in-memory temporary
table becomes larger than @code{tmp_table_size} bytes. To avoid this
problem, you can use the @code{-O tmp_table_size=#} option to
@code{mysqld} to increase the temporary table size, or use the SQL
option @code{SQL_BIG_TABLES} before you issue the problematic
query. @xref{SET OPTION, , @code{SET OPTION}}.
You can also start @code{mysqld} with the @code{--big-tables} option.
This is exactly the same as using @code{SQL_BIG_TABLES} for all queries.
In @strong{MySQL} 3.23 in-memory temporary tables will automaticly be
converted to a disk based @code{MyISAM} table after the table size gets
bigger than @code{tmp_table_size}.
@cindex Commands out of sync
@node Commands out of sync, Ignoring user, Full table, Common errors
@subsection @code{Commands out of sync} error in client
If you get @code{Commands out of sync; You can't run this command now}
in your client code, you are calling client functions in the wrong order!
This can happen, for example, if you are using @code{mysql_use_result()} and
try to execute a new query before you have called @code{mysql_free_result()}.
It can also happen if you try to execute two queries that return data without
a @code{mysql_use_result()} or @code{mysql_store_result()} in between.
@node Ignoring user, Cannot find table, Commands out of sync, Common errors
@subsection @code{Ignoring user} error
If you get the following error:
@code{Found wrong password for user: 'some_user@@some_host'; Ignoring user}
This means that when @code{mysqld} was started or when it reloaded the
permissions tables, it found an entry in the @code{user} table with
an invalid password. As a result, the entry is simply ignored by the
permission system.
Possible causes of and fixes for this problem:
@itemize @bullet
@item
You may be running a new version of @code{mysqld} with an old
@code{user} table.
You can check this by executing @code{mysqlshow mysql user} to see if
the password field is shorter than 16 characters. If so, you can correct this
condition by running the @code{scripts/add_long_password} script.
@item
The user has an old password (8 chararacters long) and you didn't start
@code{mysqld} with the @code{--old-protocol} option.
Update the user in the @code{user} table with a new password or
restart @code{mysqld} with @code{--old-protocol}.
@item
@findex PASSWORD()
You have specified a password in the @code{user} table without using the
@code{PASSWORD()} function. Use @code{mysql} to update the user in the
@code{user} table with a new password. Make sure to use the @code{PASSWORD()}
function:
@example
mysql> update user set password=PASSWORD('your password')
where user='XXX';
@end example
@end itemize
@node Cannot find table, , Ignoring user, Common errors
@subsection @code{Table 'xxx' doesn't exist} error
If you get the error @code{Table 'xxx' doesn't exist} or @code{Can't
find file: 'xxx' (errno: 2)}, this means that no table exists
in the current database with the name @code{xxx}.
Note that as @strong{MySQL} uses directories and files to store databases and
tables, the database and table names are @strong{case sensitive}!
(On Win32 the databases and tables names are not case sensitive, but all
references to a given table within a query must use the same case!)
You can check which tables you have in the current database with
@code{SHOW TABLES}. @xref{SHOW, , @code{SHOW}}.
@cindex Full disk
@cindex Disk full
@node Full disk, Multiple sql commands, Common errors, Problems
@section How MySQL handles a full disk
@noindent
When a disk full condition occurs, @strong{MySQL} does the following:
@itemize @bullet
@item
It checks once every minute to see whether or not there is enough space to
write the current row. If there is enough space, it continues as if nothing had
happened.
@item
Every 6 minutes it writes an entry to the log file warning about the disk
full condition.
@end itemize
@noindent
To alleviate the problem, you can take the following actions:
@itemize @bullet
@item
To continue, you only have to free enough disk space to insert all records.
@item
To abort the thread, you must send a @code{mysqladmin kill} to the thread.
The thread will be aborted the next time it checks the disk (in 1 minute).
@item
Note that other threads may be waiting for the table that caused the ``disk
full'' condition. If you have several ``locked'' threads, killing the one
thread that is waiting on the disk full condition will allow the other
threads to continue.
@end itemize
@node Multiple sql commands, Temporary files, Full disk, Problems
@section How to run SQL commands from a text file
The @code{mysql} client typically is used interactively, like this:
@example
shell> mysql database
@end example
However, it's also possible to put your SQL commands in a file and tell
@code{mysql} to read its input from that file. To do so, create a text
file @file{text_file} that contains the commands you wish to execute.
Then invoke @code{mysql} as shown below:
@example
shell> mysql database < text_file
@end example
You can also start your text file with a @code{USE db_name} statement. In
this case, it is unnecessary to specify the database name on the command
line:
@example
shell> mysql < text_file
@end example
@xref{Programs}.
@node Temporary files, Problems with mysql.sock, Multiple sql commands, Problems
@section Where MySQL stores temporary files
@strong{MySQL} uses the value of the @code{TMPDIR} environment variable as
the pathname of the directory in which to store temporary files. If you don't
have @code{TMPDIR} set, @strong{MySQL} uses the system default, which is
normally @file{/tmp} or @file{/usr/tmp}. If the file system containing your
temporary file directory is too small, you should edit @code{safe_mysqld} to
set @code{TMPDIR} to point to a directory in a file system where you have
enough space! You can also set the temporary directory using the
@code{--tmpdir} option to @code{mysqld}.
@strong{MySQL} creates all temporary files as ``hidden files''. This ensures
that the temporary files will be removed if @code{mysqld} is terminated. The
disadvantage of using hidden files is that you will not see a big temporary
file that fills up the file system in which the temporary file directory is
located.
When sorting (@code{ORDER BY} or @code{GROUP BY}), @strong{MySQL} normally
uses one or two temporary files. The maximum disk-space needed is:
@example
(length of what is sorted + sizeof(database pointer))
* number of matched rows
* 2
@end example
@code{sizeof(database pointer)} is usually 4, but may grow in the future for
really big tables.
For some @code{SELECT} queries, @strong{MySQL} also creates temporary SQL
tables. These are not hidden and have names of the form @file{SQL_*}.
@code{ALTER TABLE} and @code{OPTIMIZE TABLE} create a temporary table in the
same directory as the original table.
@node Problems with mysql.sock, Error Access denied, Temporary files, Problems
@section How to protect @file{/tmp/mysql.sock} from being deleted
If you have problems with the fact that anyone can delete the
@strong{MySQL} communication socket @file{/tmp/mysql.sock}, you can,
on most versions of Unix, protect your @file{/tmp} file system by setting
the @code{sticky} bit on it. Log in as @code{root} and do the following:
@example
shell> chmod +t /tmp
@end example
This will protect your @file{/tmp} file system so that files can be deleted
only by their owners or the superuser (@code{root}).
You can check if the @code{sticky} bit is set by executing @code{ls -ld /tmp}.
If the last permission bit is @code{t}, the bit is set.
@node Error Access denied, Changing MySQL user , Problems with mysql.sock, Problems
@section @code{Access denied} error
@xref{Privileges}. And especially see @ref{Access denied}.
@node Changing MySQL user , Resetting permissions, Error Access denied, Problems
@section How to run MySQL as a normal user
The @strong{MySQL} server @code{mysqld} can be started and run by any user.
In order to change @code{mysqld} to run as Unix user @code{user_name}, you must
do the following:
@enumerate
@item
Stop the server if it's running (use @code{mysqladmin shutdown}).
@item
Change the database directories and files so that @code{user_name} has
privileges to read and write files in them (you may need to do this as
the Unix @code{root} user):
@example
shell> chown -R user_name /path/to/mysql/datadir
@end example
If directories or files within the @strong{MySQL} data directory are
symlinks, you'll also need to follow those links and change the directories
and files they point to. @code{chown -R} may not follow symlinks for
you.
@item
Start the server as user @code{user_name}, or, if you are using
@strong{MySQL} 3.22 or later, start @code{mysqld} as the Unix @code{root}
user and use the @code{--user=user_name} option. @code{mysqld} will switch
to run as Unix user @code{user_name} before accepting any connections.
@item
If you are using the @code{mysql.server} script to start @code{mysqld} when
the system is rebooted, you should edit @code{mysql.server} to use @code{su}
to run @code{mysqld} as user @code{user_name}, or to invoke @code{mysqld}
with the @code{--user} option. (No changes to @code{safe_mysqld} are
necessary.)
@end enumerate
At this point, your @code{mysqld} process should be running fine and dandy as
the Unix user @code{user_name}. One thing hasn't changed, though: the
contents of the permissions tables. By default (right after running the
permissions table install script @code{mysql_install_db}), the @strong{MySQL}
user @code{root} is the only user with permission to access the @code{mysql}
database or to create or drop databases. Unless you have changed those
permissions, they still hold. This shouldn't stop you from accessing
@strong{MySQL} as the @strong{MySQL} @code{root} user when you're logged in
as a Unix user other than @code{root}; just specify the @code{-u root} option
to the client program.
Note that accessing @strong{MySQL} as @code{root}, by supplying @code{-u
root} on the command line, has @emph{nothing} to do with @strong{MySQL} running
as the Unix @code{root} user, or, indeed, as other Unix user. The access
permissions and user names of @strong{MySQL} are completely separate from
Unix user names. The only connection with Unix user names is that if you
don't provide a @code{-u} option when you invoke a client program, the client
will try to connect using your Unix login name as your @strong{MySQL} user
name.
If your Unix box itself isn't secured, you should probably at least put a
password on the @strong{MySQL} @code{root} users in the access tables.
Otherwise, any user with an account on that machine can run @code{mysql -u
root db_name} and do whatever he likes.
@node Resetting permissions, File permissions , Changing MySQL user , Problems
@section How to reset a forgotten password.
If you have forgotten the @code{root} user password for @strong{MySQL}, you
can restore it with the following procedure.
@enumerate
@item
Take down the mysqld server by sending a @code{kill} (not @code{kill
-9}) to the @code{mysqld} server. The pid is stored in a @code{.pid}
file which is normally in the @strong{MySQL} database directory:
@example
kill `cat /mysql-data-directory/hostname.pid`
@end example
You must be either the Unix @code{root} user or the same user the server
runs as to do this.
@item
Restart @code{mysqld} with the @code{--skip-grant-tables} option.
@item
Connect to the mysqld server with @code{mysql -h hostname mysql} and change
the password with a @code{GRANT} command. @xref{GRANT,,@code{GRANT}}.
You can also do this with
@code{mysqladmin -h hostname -u user password 'new password'}
@item
Load the privilege tables with: @code{mysqladmin -h hostname
flush-privileges} or with the SQL command @code{FLUSH PRIVILEGES}.
@end enumerate
@node File permissions , Not enough file handles, Resetting permissions, Problems
@section Problems with file permissions
If you have problems with file permissions, for example, if @code{mysql}
issues the following error message when you create a table:
@example
ERROR: Can't find file: 'path/with/filename.frm' (Errcode: 13)
@end example
@tindex UMASK environment variable
@tindex Environment variable, UMASK
Then the environment variable @code{UMASK} might be set incorrectly when
@code{mysqld} starts up. The default umask value is @code{0660}. You can
change this behavior by starting @code{safe_mysqld} as follows:
@example
shell> UMASK=384 # = 600 in octal
shell> export UMASK
shell> /path/to/safe_mysqld &
@end example
@tindex UMASK_DIR environment variable
@tindex Environment variable, UMASK_DIR
By default @strong{MySQL} will create database and @code{RAID}
directories with permission type 0700. You can modify this behaviour by
setting the the @code{UMASK_DIR} variable. If you set this, new
directories are created with the combined @code{UMASK} and
@code{UMASK_DIR}. For example, if you want to give group access to
all new directories, you can do:
@example
shell> UMASK_DIR=504 # = 770 in octal
shell> export UMASK_DIR
shell> /path/to/safe_mysqld &
@end example
@xref{Environment variables}.
@node Not enough file handles, Using DATE, File permissions , Problems
@section File not found
If you get @code{ERROR '...' not found (errno: 23)}, @code{Can't open
file: ... (errno: 24)} or any other error with @code{errno 23} or
@code{errno 24} from @strong{MySQL}, it means that you haven't allocated
enough file descriptors for @strong{MySQL}. You can use the
@code{perror} utility to get a description of what the error number
means:
@example
shell> perror 23
File table overflow
shell> perror 24
Too many open files
@end example
The problem here is that @code{mysqld} is trying to keep open too many
files simultaneously. You can either tell @code{mysqld} not to open so
many files at once, or increase the number of file descriptors
available to @code{mysqld}.
To tell @code{mysqld} to keep open fewer files at a time, you can make the
table cache smaller by using the @code{-O table_cache=32} option
to @code{safe_mysqld} (the default value is 64). Reducing the value of
@code{max_connections} will also reduce the number of open files (the default
value is 90).
@tindex ulimit
To change the number of file descriptors available to @code{mysqld}, modify
the @code{safe_mysqld} script. There is a commented-out line
@code{ulimit -n 256} in the script. You can remove the @code{'#'} character
to uncomment this line, and change the number 256 to change the number of
file descriptors available to @code{mysqld}.
@code{ulimit} can increase the number of file descriptors, but only up to the
limit imposed by the operating system. If you need to increase the OS limit
on the number of file descriptors available to each process, consult the
documentation for your operating system.
Note that if you run the @code{tcsh} shell, @code{ulimit} will not work!
@code{tcsh} will also report incorrect values when you ask for the current
limits! In this case you should start @code{safe_mysqld} with @code{sh}!
@node Using DATE, Timezone problems, Not enough file handles, Problems
@section Problems using @code{DATE} columns
The format of a @code{DATE} value is @code{'YYYY-MM-DD'}. According to ANSI
SQL, no other format is allowed. You should use this format in @code{UPDATE}
expressions and in the WHERE clause of @code{SELECT} statements. For
example:
@example
mysql> SELECT * FROM tbl_name WHERE date >= '1997-05-05';
@end example
As a convenience, @strong{MySQL} automatically converts a date to a number if
the date is used in a numeric context (and vice versa). It is also smart
enough to allow a ``relaxed'' string form when updating and in a @code{WHERE}
clause that compares a date to a @code{TIMESTAMP}, @code{DATE} or a
@code{DATETIME} column. (Relaxed form means that any punctuation character
may be used as the separator between parts. For example, @code{'1998-08-15'}
and @code{'1998#08#15'} are equivalent.) @strong{MySQL} can also convert a
string containing no separators (such as @code{'19980815'}), provided it
makes sense as a date.
The special date @code{'0000-00-00'} can be stored and retrieved as
@code{'0000-00-00'.} When using a @code{'0000-00-00'} date through
@strong{MyODBC}, it will automatically be converted to @code{NULL} in
@strong{MyODBC} 2.50.12 and above, because ODBC can't handle this kind of
date.
Because @strong{MySQL} performs the conversions described above, the following
statements work:
@example
mysql> INSERT INTO tbl_name (idate) VALUES (19970505);
mysql> INSERT INTO tbl_name (idate) VALUES ('19970505');
mysql> INSERT INTO tbl_name (idate) VALUES ('97-05-05');
mysql> INSERT INTO tbl_name (idate) VALUES ('1997.05.05');
mysql> INSERT INTO tbl_name (idate) VALUES ('1997 05 05');
mysql> INSERT INTO tbl_name (idate) VALUES ('0000-00-00');
mysql> SELECT idate FROM tbl_name WHERE idate >= '1997-05-05';
mysql> SELECT idate FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT mod(idate,100) FROM tbl_name WHERE idate >= 19970505;
mysql> SELECT idate FROM tbl_name WHERE idate >= '19970505';
@end example
@noindent
However, the following will not work:
@example
mysql> SELECT idate FROM tbl_name WHERE STRCMP(idate,'19970505')=0;
@end example
@code{STRCMP()} is a string function, so it converts @code{idate} to
a string and performs a string comparison. It does not convert
@code{'19970505'} to a date and perform a date comparison.
Note that @strong{MySQL} does no checking whether or not the date is
correct. If you store an incorrect date, such as @code{'1998-2-31'}, the
wrong date will be stored. If the date cannot be converted to any reasonable
value, a @code{0} is stored in the @code{DATE} field. This is mainly a speed
issue and we think it is up to the application to check the dates, and not
the server.
@cindex Timezone problems
@tindex TZ environment variable
@tindex Environment variable, TZ
@node Timezone problems, Case sensitivity, Using DATE, Problems
@section Timezone problems
If you have a problem with @code{SELECT NOW()} returning values in GMT and
not your local time, you have to set the @code{TZ} environment variable to
your current timezone. This should be done for the environment in which
the server runs, for example in @code{safe_mysqld} or @code{mysql.server}.
@xref{Environment variables}.
@cindex Case sensitivity, in searches
@cindex Chinese
@cindex Big5 Chinese character encoding
@node Case sensitivity, Problems with NULL, Timezone problems, Problems
@section Case sensitivity in searches
By default, @strong{MySQL} searches are case-insensitive (although there are
some character sets that are never case insensitive, such as @code{czech}).
That means that if you search with @code{col_name LIKE 'a%'}, you will get all
column values that start with @code{A} or @code{a}. If you want to make this
search case-sensitive, use something like @code{INDEX(col_name, "A")=0} to
check a prefix. Or use @code{STRCMP(col_name, "A") = 0} if the column value
must be exactly @code{"A"}.
Simple comparison operations (@code{>=, >, = , < , <=}, sorting and
grouping) are based on each character's ``sort value''. Characters with
the same sort value (like E, e and é) are treated as the same character!
In older @strong{MySQL} versions @code{LIKE} comparisons where done on
the uppercase value of each character (E == e but E <> é). In newer
@strong{MySQL} versions @code{LIKE} works just like the other comparison
operators.
If you want a column always to be treated in case-sensitive fashion,
declare it as @code{BINARY}. @xref{CREATE TABLE, , @code{CREATE TABLE}}.
If you are using Chinese data in the so-called big5 encoding, you want to
make all character columns @code{BINARY}. This works because the sorting
order of big5 encoding characters is based on the order of ASCII codes.
@cindex @code{NULL} values vs. empty values
@tindex NULL
@node Problems with NULL, Problems with alias, Case sensitivity, Problems
@section Problems with @code{NULL} values
The concept of the @code{NULL} value is a common source of confusion for
newcomers to SQL, who often think that @code{NULL} is the same thing as an
empty string @code{''}. This is not the case! For example, the following
statements are completely different:
@example
mysql> INSERT INTO my_table (phone) VALUES (NULL);
mysql> INSERT INTO my_table (phone) VALUES ("");
@end example
Both statements insert a value into the @code{phone} column, but the first
inserts a @code{NULL} value and the second inserts an empty string. The
meaning of the first can be regarded as ``phone number is not known'' and the
meaning of the second can be regarded as ``she has no phone''.
In SQL, the @code{NULL} value is always false in comparison to any
other value, even @code{NULL}. An expression that contains @code{NULL}
always produces a @code{NULL} value unless otherwise indicated in
the documentation for the operators and functions involved in the
expression. All columns in the following example return @code{NULL}:
@example
mysql> SELECT NULL,1+NULL,CONCAT('Invisible',NULL);
@end example
If you want to search for column values that are @code{NULL}, you
cannot use the @code{=NULL} test. The following statement returns no
rows, because @code{expr = NULL} is FALSE, for any expression:
@example
mysql> SELECT * FROM my_table WHERE phone = NULL;
@end example
To look for @code{NULL} values, you must use the @code{IS NULL} test.
The following shows how to find the @code{NULL} phone number and the
empty phone number:
@example
mysql> SELECT * FROM my_table WHERE phone IS NULL;
mysql> SELECT * FROM my_table WHERE phone = "";
@end example
In @strong{MySQL}, as in many other SQL servers, you can't index
columns that can have @code{NULL} values. You must declare such columns
@code{NOT NULL}. Conversely, you cannot insert @code{NULL} into an indexed
column.
@findex LOAD DATA INFILE
When reading data with @code{LOAD DATA INFILE}, empty columns are updated
with @code{''}. If you want a @code{NULL} value in a column, you should use
@code{\N} in the text file. The literal word @code{'NULL'} may also be used
under some circumstances.
@xref{LOAD DATA, , @code{LOAD DATA}}.
When using @code{ORDER BY}, @code{NULL} values are presented first. If you
sort in descending order using @code{DESC}, @code{NULL} values are presented
last. When using @code{GROUP BY}, all @code{NULL} values are regarded as
equal.
To help with @code{NULL} handling, you can use the @code{IS NULL} and
@code{IS NOT NULL} operators and the @code{IFNULL()} function.
@cindex @code{TIMESTAMP}, and @code{NULL} values
@cindex @code{AUTO_INCREMENT}, and @code{NULL} values
@cindex @code{NULL} values, and @code{TIMESTAMP} columns
@cindex @code{NULL} values, and @code{AUTO_INCREMENT} columns
For some column types, @code{NULL} values are handled specially. If you
insert @code{NULL} into the first @code{TIMESTAMP} column of a table, the
current date and time is inserted. If you insert @code{NULL} into an
@code{AUTO_INCREMENT} column, the next number in the sequence is inserted.
@tindex alias
@node Problems with alias, Deleting from related tables, Problems with NULL, Problems
@section Problems with @code{alias}
You can use an alias to refer to a column in the @code{GROUP BY},
@code{ORDER BY} or in the @code{HAVING} part. Aliases can also be used
to give columns more better names:
@example
SELECT SQRT(a*b) as rt FROM table_name GROUP BY rt HAVING rt > 0;
SELECT id,COUNT(*) AS cnt FROM table_name GROUP BY id HAVING cnt > 0;
SELECT id AS "Customer identity" FROM table_name;
@end example
Note that you ANSI SQL doesn't allow you to refer to an alias in a
@code{WHERE} clause. This is because when the @code{WHERE} code is
executed the column value may not yet be determinated. For example the
following query is @strong{illegal}:
@example
SELECT id,COUNT(*) AS cnt FROM table_name WHERE cnt > 0 GROUP BY id;
@end example
The @code{WHERE} statement is executed to determinate which rows should
be included in the @code{GROUP BY} part while @code{HAVING} is used to
decide which rows from the result set should be used.
@node Deleting from related tables, No matching rows, Problems with alias, Problems
@section Deleting rows from related tables
As @strong{MySQL} doesn't support sub-selects or use of more than one table
in the @code{DELETE} statement, you should use the following approach to
delete rows from 2 related tables:
@enumerate
@item
@code{SELECT} the rows based on some @code{WHERE} condition in the main table.
@item
@code{DELETE} the rows in the main table based on the same condition.
@item
@code{DELETE FROM related_table WHERE related_column IN (selected_rows)}
@end enumerate
If the total number of characters in the query with
@code{related_column} is more than 1,048,576 (the default value of
@code{max_allowed_packet}, you should split it into smaller parts and
execute multiple @code{DELETE} statements. You will probably get the
fastest @code{DELETE} by only deleting 100-1000 @code{related_column}
id's per query if the @code{related_column} is an index. If the
@code{related_column} isn't an index, the speed is independent of the
number of arguments in the @code{IN} clause.
@node No matching rows, ALTER TABLE problems, Deleting from related tables, Problems
@section Solving problems with no matching rows
If you have a complicated query with many tables that doesn't return any
rows, you should use the following procedure to find out what is wrong
with your query:
@enumerate
@item
Test the query with @code{EXPLAIN} and check if you can find something that is
obviously wrong. @xref{EXPLAIN, , @code{EXPLAIN}}.
@item
Select only those fields that are used in the @code{WHERE} clause.
@item
Remove one table at a time from the query until it returns some rows.
If the tables are big, it's a good idea to use @code{LIMIT 10} with the query.
@item
Do a @code{SELECT} for the column that should have matched a row,
against the table that was last removed from the query.
@item
If you are comparing @code{FLOAT} or @code{DOUBLE} columns with numbers that
have decimals, you can't use @code{=}! This problem is common in most
computer languages because floating point values are not exact values.
@example
mysql> SELECT * FROM table_name WHERE float_column=3.5;
->
mysql> SELECT * FROM table_name WHERE float_column between 3.45 and 3.55;
@end example
In most cases, changing the @code{FLOAT} to a @code{DOUBLE} will fix this!
@item
If you still can't figure out what's wrong, create a minimal test that can
be run with @code{mysql test < query.sql} that shows your problems.
You can create a test file with @code{mysqldump --quick database tables > query.sql}. Open the file in an editor, remove some insert lines (if there are
too many of these) and add your select statement at the end of the file.
Test that you still have your problem by doing:
@example
shell> mysqladmin create test2
shell> mysql test2 < query.sql
@end example
Post the test file using @code{mysqlbug} to @email{mysql@@lists.mysql.com}.
@end enumerate
@node ALTER TABLE problems, Change column order, No matching rows, Problems
@section Problems with @code{ALTER TABLE}.
If @code{ALTER TABLE} dies with an error like this:
@example
Error on rename of './database/name.frm' to './database/B-a.frm' (Errcode: 17)
@end example
The problem may be that @strong{MySQL} has crashed in a previous @code{ALTER
TABLE} and there is an old table named @file{A-something} or
@file{B-something} lying around. In this case, go to the @strong{MySQL} data
directory and delete all files that have names starting with @code{A-} or
@code{B-}. (You may want to move them elsewhere instead of deleting them).
@code{ALTER TABLE} works the following way:
@itemize @bullet
@item Create a new table named @file{A-xxx} with the requested changes.
@item All rows from the old table are copied to @file{A-xxx}.
@item The old table is renamed @file{B-xxx}.
@item @file{A-xxx} is renamed to your old table name.
@item @file{B-xxx} is deleted.
@end itemize
If something goes wrong with the renaming operation, @strong{MySQL} tries to
undo the changes. If something goes seriously wrong (this shouldn't happen,
of course), @strong{MySQL} may leave the old table as @file{B-xxx} but a
simple rename should get your data back.
@node Change column order, , ALTER TABLE problems, Problems
@section How to change the order of columns in a table
The whole point of SQL is to abstract the application from the data
storage format. You should always specify the order in wish you wish to
retrieve your data. For example:
@example
SELECT col_name1, col_name2, col_name3 FROM tbl_name;
@end example
will return columns in the order @code{col_name1}, @code{col_name2}, @code{col_name3}, whereas:
@example
SELECT col_name1, col_name3, col_name2 FROM tbl_name;
@end example
will return columns in the order @code{col_name1}, @code{col_name3}, @code{col_name2}.
You should @strong{NEVER}, in an application, use @code{SELECT *} and
retrieve the columns based on their position, because the order in which columns are
returned @strong{CANNOT} be guaranteed over time; A simple change to
your database may cause your application to fail rather dramatically.
If you want to change the order of columns anyway, you can do it as follows:
@enumerate
@item
Create a new table with the columns in the right order.
@item
Execute
@code{INSERT INTO new_table SELECT fields-in-new_table-order FROM old_table}.
@item
Drop or rename @code{old_table}
@item
@code{ALTER TABLE new_table RENAME old_table}
@end enumerate
@node Common problems, Clients, Problems, Top
@chapter Solving some common problems with MySQL
@cindex Replication
@menu
* Log Replication:: Database replication with update log
* Backup:: Database backups
* Update log:: The update log
* Multiple servers:: Running multiple @strong{MySQL} servers on the same machine
@end menu
@cindex Database replication
@cindex Replication, database
@node Log Replication, Backup, Common problems, Common problems
@section Database replication with update log
Now that master-slave internal replication is available starting in 3.23.15,
this is the recommended way. However, it is still possible to replicate a database by
using the update
log. @xref{Update log}. This requires one database that acts as a master
(to which data changes are made) and one or more other databases that act
as slaves. To update a slave, just run @code{mysql < update_log}.
Supply host, user and password options that are appropriate for the slave
database, and use the update log from the master database as input.
If you never delete anything from a table, you can use a @code{TIMESTAMP}
column to find out which rows have been inserted or changed in the table
since the last replication (by comparing to the time when you did the
replication last time) and only copy these rows to the mirror.
It is possible to make a two-way updating system using both the update
log (for deletes) and timestamps (on both sides). But in that case you
must be able to handle conflicts when the same data have been changed in
both ends. You probably want to keep the old version to help with
deciding what has been updated.
Because replication in this case is done with SQL statements, you should not
use the following functions in statements that update the database; they may
not return the same value as in the original database:
@itemize @bullet
@item @code{DATABASE()}
@item @code{GET_LOCK()} and @code{RELEASE_LOCK()}
@item @code{RAND()}
@item @code{USER()}, @code{SYSTEM_USER()} or @code{SESSION_USER()}
@item @code{VERSION()}, @code{CONNECT_ID()}
@end itemize
All time functions are safe to use, as the timestamp is sent to the
mirror if needed. @code{LAST_INSERT_ID()} is also safe to use.
@cindex Backups
@node Backup, Update log, Log Replication, Common problems
@section Database backups
Because @strong{MySQL} tables are stored as files, it is easy to do a
backup. To get a consistent backup, do a @code{LOCK TABLES} on the
relevant tables. @xref{LOCK TABLES, , @code{LOCK TABLES}}. You only need a
read lock; this allows other threads to continue to query the tables while
you are making a copy of the files in the database directory. If you want to
make a SQL level backup of a table, you can use @code{SELECT INTO OUTFILE}.
Another way to backup a database is to use the @code{mysqldump} program:
@xref{mysqldump}.
@enumerate
@item
Do a full backup of your databases:
@example
shell> mysqldump --tab=/path/to/some/dir --opt --full
@end example
You can also simply copy all table files (@file{*.frm}, @file{*.MYD} and
@file{*.MYI} files), as long as the server isn't updating anything.
The script @code{mysqlhotcopy} does use this method.
@item
@cindex Log file, names
Stop @code{mysqld} if it's running, then start it with the
@code{--log-update[=file_name]} option. @xref{Update log}. The update
log file(s) provide you with the information you need to replicate
changes to the database that are made subsequent to the point at which
you executed @code{mysqldump}.
@end enumerate
If you have to restore something, try to recover your tables using
@code{myisamchk -r} first. That should work in 99.9% of all cases. If
@code{myisamchk} fails, try the following procedure:
(This will only work if you have started @strong{MySQL} with
@code{--log-update}. @xref{Update log}.)
@enumerate
@item
Restore the original @code{mysqldump} backup.
@item
Execute the following command to re-run the updates in the update logs:
@example
shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql
@end example
@end enumerate
@code{ls} is used to get all the update log files in the right order.
You can also do selective backups with @code{SELECT * INTO OUTFILE 'file_name'
FROM tbl_name} and restore with @code{LOAD DATA INFILE 'file_name' REPLACE
...} To avoid duplicate records, you need a @code{PRIMARY KEY} or a
@code{UNIQUE} key in the table. The @code{REPLACE} keyword causes old records
to be replaced with new ones when a new record duplicates an old record on
a unique key value.
@cindex Update log
@node Update log, Multiple servers, Backup, Common problems
@section The update log
When started with the @code{--log-update[=file_name]} option,
@code{mysqld} writes a log file containing all SQL commands that update
data. If no file name is given, it defaults to the name of the host
machine, If file name is given, but it doesn't contain a path the file
is written in the data directory. If file_name doesn't have an
extension, @code{mysqld} will create log file names of type
@code{file_name.#}, where @code{#} is a number that is incremented each
time you execute @code{mysqladmin refresh} or @code{mysqladmin
flush-logs}, the @code{FLUSH LOGS} statement, or restart the server.
@strong{Note:} For the above scheme to work, you should NOT create
own files with the same file name as the update log + some extensions
that may be regarded as a number, in the directory used by the update log!
If you use the @code{--log} or @code{-l} options, @code{mysqld} writes a
general log with a filename of @file{hostname.log}, and restarts and
refreshes do not cause a new log file to be generated (although it is closed
and reopened). In this case you can copy it (on Unix) by doing:
@example
mv hostname.log hostname-old.log
mysqladmin flush-logs
cp hostname-old.log to-backup-directory
rm hostname-old.log
@end example
By default, the @code{mysql.server} script starts the @strong{MySQL}
server with the @code{-l} option. If you need better performance when
you start using @strong{MySQL} in a production environment, you can
remove the @code{-l} option from @code{mysql.server} or change it to
@code{--log-update}.
Update logging is smart because it logs only statements that really update
data. So an @code{UPDATE} or a @code{DELETE} with a @code{WHERE} that finds no
rows is not written to the log. It even skips @code{UPDATE} statements that
set a column to the value it already has.
If you want to update a database from update log files, you could do the
following (assuming your update logs have names of the form
@file{file_name.###}):
@example
shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
@end example
@code{ls} is used to get all the log files in the right order.
This can be useful if you have to revert to backup files after a crash
and you want to redo the updates that occurred between the time of the backup
and the crash.
@cindex Database replication
@cindex Replication, database
@cindex Database mirroring
@cindex Mirroring, database
You can also use the update logs when you have a mirrored database on
another host and you want to replicate the changes that have been made
to the master database. @xref{Log Replication}.
@cindex Multiple servers
@node Multiple servers, , Update log, Common problems
@section Running multiple MySQL servers on the same machine
There are circumstances when you might want to run multiple servers on the same
machine. For example, you might want to test a new @strong{MySQL} release
while leaving your existing production setup undisturbed. Or you might
be an Internet service provider that wants to provide independent
@strong{MySQL} installations for different customers.
If you want to run multiple servers, the easiest way is to compile the servers
with different TCP/IP ports and socket files so they are not
both listening to the same TCP/IP port or socket file.
Assume an existing server is configured for the default port number and
socket file. Then configure the new server with a @code{configure} command
something like this:
@example
shell> ./configure --with-tcp-port=port_number \
--with-unix-socket=file_name \
--prefix=/usr/local/mysql-3.22.9
@end example
Here @code{port_number} and @code{file_name} should be different than the
default port number and socket file pathname, and the @code{--prefix} value
should specify an installation directory different than the one under which
the existing @strong{MySQL} installation is located.
You can check the socket and port used by any currently-executing
@strong{MySQL} server with this command:
@example
shell> mysqladmin -h hostname --port=port_number variables
@end example
If you have a @strong{MySQL} server running on the port you used, you will
get a list of some of the most important configurable variables in
@strong{MySQL}, including the socket name.
You should also edit the initialization script for your machine (probably
@file{mysql.server}) to start and kill multiple @code{mysqld} servers.
You don't have to recompile a new @strong{MySQL} server just to start with
a different port and socket. You can change the port and socket to be used
by specifying them at runtime as options to @code{safe_mysqld}:
@example
shell> /path/to/safe_mysqld --socket=file_name --port=port_number
@end example
If you run the new server on the same database directory as another server
with logging enabled, you should also specify the name of the log files
to @code{safe_mysqld} with @code{--log} and @code{--log-update}. Otherwise,
both servers may be trying to write to the same log file.
@strong{Warning}: Normally you should never have two servers that update
data in the same database! If your OS doesn't support fault-free system
locking, this may lead to unpleasant surprises!
If you want to use another database directory for the second server, you
can use the @code{--datadir=path} option to @code{safe_mysqld}.
When you want to connect to a @strong{MySQL} server that is running with
a different port than the port that is compiled into your client, you
can use one of the following methods:
@itemize @bullet
@item
Start the client with @code{--host 'hostname' --port=port_numer} or
@code{[--host localhost] --socket=file_name}.
@item
In your C or Perl programs, you can give the port and socket arguments
when connecting to the @strong{MySQL} server.
@item
@tindex MYSQL_UNIX_PORT environment variable
@tindex MYSQL_TCP_PORT environment variable
@tindex Environment variable, MYSQL_UNIX_PORT
@tindex Environment variable, MYSQL_TCP_PORT
Set the @code{MYSQL_UNIX_PORT} and @code{MYSQL_TCP_PORT} environment variables
to point to the Unix socket and TCP/IP port before you start your clients.
If you normally use a specific socket or port, you should place commands
to set these environment variables in your @file{.login} file.
@xref{Environment variables}. @xref{Programs}.
@item
@tindex .my.cnf file
Specify the default socket and TCP/IP port in the @file{.my.cnf} file in your
home directory. @xref{Option files}.
@end itemize
@node Clients, Comparisons, Common problems, Top
@chapter MySQL client tools and APIs
@menu
* C:: @strong{MySQL} C API
* C API datatypes:: C API datatypes
* C API function overview:: C API function Overview
* C API functions:: C API function descriptions
* Perl:: @strong{MySQL} Perl API
* Eiffel:: @strong{MySQL} Eiffel wrapper
* Java:: @strong{MySQL} Java connectivity (JDBC)
* PHP:: @strong{MySQL} PHP API
* Cplusplus:: @strong{MySQL} C++ APIs
* Python:: @strong{MySQL} Python APIs
* Tcl:: @strong{MySQL} Tcl APIs
@end menu
@node C, C API datatypes, Clients, Clients
@section MySQL C API
The C API code is distributed with @strong{MySQL}. It is included in the
@code{mysqlclient} library and allows C programs to access a database.
Many of the clients in the @strong{MySQL} source distribution are
written in C. If you are looking for examples that demonstrate how to
use the C API, take a look at these clients. You can find these in the
@code{clients} directory in the @strong{MySQL} source distribution.
Most of the other client APIs (all except Java) use the @code{mysqlclient}
library to communicate with the @strong{MySQL} server. This means that, for
example, you can take advantage of many of the same environment variables
that are used by other client programs, because they are referenced from the
library. See @ref{Programs}, for a list of these variables.
The client has a maximum communication buffer size. The size of the buffer
that is allocated initially (16K bytes) is automatically increased up to the
maximum size (the default maximum is 24M). Because buffer sizes are increased
only as demand warrants, simply increasing the default maximum limit does not
in itself cause more resources to be used. This size check is mostly a check
for erroneous queries and communication packets.
The communication buffer must be large enough to contain a single SQL
statement (for client-to-server traffic) and one row of returned data (for
server-to-client traffic). Each thread's communication buffer is dynamically
enlarged to handle any query or row up to the maximum limit. For example, if
you have @code{BLOB} values that contain up to 16M of data, you must have a
communication buffer limit of at least 16M (in both server and client). The
client's default maximum is 24M, but the default maximum in the server is
1M. You can increase this by changing the value of the
@code{max_allowed_packet} parameter when the server is started. @xref{Server
parameters}.
The @strong{MySQL} server shrinks each communication buffer to
@code{net_buffer_length} bytes after each query. For clients, the size of
the buffer associated with a connection is not decreased until the connection
is closed, at which time client memory is reclaimed.
If you are programming with threads, you should compile the
@strong{MySQL} C API with @code{--with-thread-safe-client}. This will make
the C API thread safe per connection. You can let two threads share the same
connection as long as you do the following:
@table @asis
@item
Two threads can't send a query to the @strong{MySQL} at the same time on
the same connection. In particular you have to ensure that between a
@code{mysql_query()} and @code{mysql_store_result()} no other thread is using
the same connection.
@item
Many threads can access different result sets that are retrieved with
@code{mysql_store_result()}.
@item
If you use @code{mysql_use_result}, you have to ensure that no other thread
is asking anything on the same connection until the result set is closed.
@end table
@node C API datatypes, C API function overview, C, Clients
@section C API datatypes
@table @code
@tindex MYSQL C type
@item MYSQL
This structure represents a handle to one database connection. It is
used for almost all @strong{MySQL} functions.
@tindex MYSQL_RES C type
@item MYSQL_RES
This structure represents the result of a query that returns rows
(@code{SELECT}, @code{SHOW}, @code{DESCRIBE}, @code{EXPLAIN}). The
information returned from a query is called the @emph{result set} in the
remainder of this section.
@tindex MYSQL_ROW C type
@item MYSQL_ROW
This is a type-safe representation of one row of data. It is currently
implemented as an array of counted byte strings. (You cannot treat these as
null-terminated strings if field values may contain binary data, because such
values may contain null bytes internally.) Rows are obtained by calling
@code{mysql_fetch_row()}.
@tindex MYSQL_FIELD C type
@item MYSQL_FIELD
This structure contains information about a field, such as the field's
name, type and size. Its members are described in more detail below.
You may obtain the @code{MYSQL_FIELD} structures for each field by
calling @code{mysql_fetch_field()} repeatedly. Field values are not part of
this structure; they are contained in a @code{MYSQL_ROW} structure.
@tindex MYSQL_FIELD_OFFSET C type
@item MYSQL_FIELD_OFFSET
This is a type-safe representation of an offset into a @strong{MySQL} field
list. (Used by @code{mysql_field_seek()}.) Offsets are field numbers
within a row, beginning at zero.
@tindex my_ulonglong C type
@tindex my_ulonglong values, printing
@item my_ulonglong
The type used for the number of rows and for @code{mysql_affected_rows()},
@code{mysql_num_rows()} and @code{mysql_insert_id()}. This type provides a
range of @code{0} to @code{1.84e19}.
On some systems, attempting to print a value of type @code{my_ulonglong}
will not work. To print such a value, convert it to @code{unsigned long}
and use a @code{%lu} print format. Example:
@example
printf (Number of rows: %lu\n", (unsigned long) mysql_num_rows(result));
@end example
@end table
@noindent
The @code{MYSQL_FIELD} structure contains the members listed below:
@table @code
@item char * name
The name of the field, as a null-terminated string.
@item char * table
The name of the table containing this field, if it isn't a calculated field.
For calculated fields, the @code{table} value is an empty string.
@item char * def
The default value of this field, as a null-terminated string. This is set
only if you use @code{mysql_list_fields()}.
@item enum enum_field_types type
The type of the field.
The @code{type} value may be one of the following:
@multitable @columnfractions .3 .55
@item @strong{Type value} @tab @strong{Type meaning}
@item @code{FIELD_TYPE_TINY} @tab @code{TINYINT} field
@item @code{FIELD_TYPE_SHORT} @tab @code{SMALLINT} field
@item @code{FIELD_TYPE_LONG} @tab @code{INTEGER} field
@item @code{FIELD_TYPE_INT24} @tab @code{MEDIUMINT} field
@item @code{FIELD_TYPE_LONGLONG} @tab @code{BIGINT} field
@item @code{FIELD_TYPE_DECIMAL} @tab @code{DECIMAL} or @code{NUMERIC} field
@item @code{FIELD_TYPE_FLOAT} @tab @code{FLOAT} field
@item @code{FIELD_TYPE_DOUBLE} @tab @code{DOUBLE} or @code{REAL} field
@item @code{FIELD_TYPE_TIMESTAMP} @tab @code{TIMESTAMP} field
@item @code{FIELD_TYPE_DATE} @tab @code{DATE} field
@item @code{FIELD_TYPE_TIME} @tab @code{TIME} field
@item @code{FIELD_TYPE_DATETIME} @tab @code{DATETIME} field
@item @code{FIELD_TYPE_YEAR} @tab @code{YEAR} field
@item @code{FIELD_TYPE_STRING} @tab String (@code{CHAR} or @code{VARCHAR}) field
@item @code{FIELD_TYPE_BLOB} @tab @code{BLOB} or @code{TEXT} field (use @code{max_length} to determine the maximum length)
@item @code{FIELD_TYPE_SET} @tab @code{SET} field
@item @code{FIELD_TYPE_ENUM} @tab @code{ENUM} field
@item @code{FIELD_TYPE_NULL} @tab @code{NULL}-type field
@item @code{FIELD_TYPE_CHAR} @tab Deprecated; use @code{FIELD_TYPE_TINY} instead
@end multitable
You can use the @code{IS_NUM()} macro to test whether or not a field has a
numeric type. Pass the @code{type} value to @code{IS_NUM()} and it
will evaluate to TRUE if the field is numeric:
@example
if (IS_NUM(field->type))
printf("Field is numeric\n");
@end example
@item unsigned int length
The width of the field, as specified in the table definition.
@item unsigned int max_length
The maximum width of the field for the result set (the length of the longest
field value for the rows actually in the result set). If you use
@code{mysql_store_result()} or @code{mysql_list_fields()}, this contains the
maximum length for the field. If you use @code{mysql_use_result()}, the
value of this variable is zero.
@item unsigned int flags
Different bit-flags for the field. The @code{flags} value may have zero
or more of the following bits set:
@multitable @columnfractions .3 .55
@item @strong{Flag value} @tab @strong{Flag meaning}
@item @code{NOT_NULL_FLAG} @tab Field can't be @code{NULL}
@item @code{PRI_KEY_FLAG} @tab Field is part of a primary key
@item @code{UNIQUE_KEY_FLAG} @tab Field is part of a unique key
@item @code{MULTIPLE_KEY_FLAG} @tab Field is part of a non-unique key.
@item @code{UNSIGNED_FLAG} @tab Field has the @code{UNSIGNED} attribute
@item @code{ZEROFILL_FLAG} @tab Field has the @code{ZEROFILL} attribute
@item @code{BINARY_FLAG} @tab Field has the @code{BINARY} attribute
@item @code{AUTO_INCREMENT_FLAG} @tab Field has the @code{AUTO_INCREMENT} attribute
@item @code{ENUM_FLAG} @tab Field is an @code{ENUM} (deprecated)
@item @code{BLOB_FLAG} @tab Field is a @code{BLOB} or @code{TEXT} (deprecated)
@item @code{TIMESTAMP_FLAG} @tab Field is a @code{TIMESTAMP} (deprecated)
@end multitable
Use of the @code{BLOB_FLAG}, @code{ENUM_FLAG} and @code{TIMESTAMP_FLAG} flags
is deprecated because they indicate the type of a field rather than an
attribute of its type. It is preferable to test @code{field->type} against
@code{FIELD_TYPE_BLOB}, @code{FIELD_TYPE_ENUM} or @code{FIELD_TYPE_TIMESTAMP}
instead.
@noindent
The example below illustrates a typical use of the @code{flags} value:
@example
if (field->flags & NOT_NULL_FLAG)
printf("Field can't be null\n");
@end example
You may use the following convenience macros to determine the boolean
status of the @code{flags} value:
@multitable @columnfractions .3 .5
@item @code{IS_NOT_NULL(flags)} @tab True if this field is defined as @code{NOT NULL}
@item @code{IS_PRI_KEY(flags)} @tab True if this field is a primary key
@item @code{IS_BLOB(flags)} @tab True if this field is a @code{BLOB} or @code{TEXT} (deprecated; test @code{field->type} instead)
@end multitable
@item unsigned int decimals
The number of decimals for numeric fields.
@end table
@node C API function overview, C API functions, C API datatypes, Clients
@section C API function overview
The functions available in the C API are listed below and are described in
greater detail in the next section.
@xref{C API functions}.
@multitable @columnfractions .3 .7
@item @strong{mysql_affected_rows()} @tab
Returns the number of rows affected by the last @code{UPDATE}, @code{DELETE} or
@code{INSERT} query.
@item @strong{mysql_close()} @tab
Closes a server connection.
@item @strong{mysql_connect()} @tab
Connects to a @strong{MySQL} server. This function is deprecated; use
@code{mysql_real_connect()} instead.
@item @strong{mysql_change_user()} @tab
Change user and database on an open connection.
@item @code{mysql_character_set_name()} @tab
Returns the name of the default character set for the connection.
@item @strong{mysql_create_db()} @tab
Creates a database. This function is deprecated; use the SQL command
@code{CREATE DATABASE} instead.
@item @strong{mysql_data_seek()} @tab
Seeks to an arbitrary row in a query result set.
@item @strong{mysql_debug()} @tab
Does a @code{DBUG_PUSH} with the given string.
@item @strong{mysql_drop_db()} @tab
Drops a database. This function is deprecated; use the SQL command
@code{DROP DATABASE} instead.
@item @strong{mysql_dump_debug_info()} @tab
Makes the server write debug information to the log.
@item @strong{mysql_eof()} @tab
Determines whether or not the last row of a result set has been read.
This function is deprecated; @code{mysql_errno()} or @code{mysql_error()}
may be used instead.
@item @strong{mysql_errno()} @tab
Returns the error number for the most recently invoked @strong{MySQL} function.
@item @strong{mysql_error()} @tab
Returns the error message for the most recently invoked @strong{MySQL} function.
@item @strong{mysql_real_escape_string()} @tab
Escapes special characters in a string for use in a SQL statement taking
into account the current charset of the connection.
@item @strong{mysql_escape_string()} @tab
Escapes special characters in a string for use in a SQL statement.
@item @strong{mysql_fetch_field()} @tab
Returns the type of the next table field.
@item @strong{mysql_fetch_field_direct()} @tab
Returns the type of a table field, given a field number.
@item @strong{mysql_fetch_fields()} @tab
Returns an array of all field structures.
@item @strong{mysql_fetch_lengths()} @tab
Returns the lengths of all columns in the current row.
@item @strong{mysql_fetch_row()} @tab
Fetches the next row from the result set.
@item @strong{mysql_field_seek()} @tab
Puts the column cursor on a specified column.
@item @strong{mysql_field_count()} @tab
Returns the number of result columns for the most recent query.
@item @strong{mysql_field_tell()} @tab
Returns the position of the field cursor used for the last
@code{mysql_fetch_field()}.
@item @strong{mysql_free_result()} @tab
Frees memory used by a result set.
@item @strong{mysql_get_client_info()} @tab
Returns client version information.
@item @strong{mysql_get_host_info()} @tab
Returns a string describing the connection.
@item @strong{mysql_get_proto_info()} @tab
Returns the protocol version used by the connection.
@item @strong{mysql_get_server_info()} @tab
Returns the server version number.
@item @strong{mysql_info()} @tab
Returns information about the most recently executed query.
@item @strong{mysql_init()} @tab
Gets or initializes a @code{MYSQL} structure.
@item @strong{mysql_insert_id()} @tab
Returns the ID generated for an @code{AUTO_INCREMENT} column by the previous
query.
@item @strong{mysql_kill()} @tab
Kill a given thread.
@item @strong{mysql_list_dbs()} @tab
Returns database names matching a simple regular expression.
@item @strong{mysql_list_fields()} @tab
Returns field names matching a simple regular expression.
@item @strong{mysql_list_processes()} @tab
Returns a list of the current server threads.
@item @strong{mysql_list_tables()} @tab
Returns table names matching a simple regular expression.
@item @strong{mysql_num_fields()} @tab
Returns the number of columns in a result set.
@item @strong{mysql_num_rows()} @tab
Returns the number of rows in a result set.
@item @strong{mysql_options()} @tab
Set connect options for @code{mysql_connect()}.
@item @strong{mysql_ping()} @tab
Checks whether or not the connection to the server is working, reconnecting
as necessary.
@item @strong{mysql_query()} @tab
Executes a SQL query specified as a null-terminated string.
@item @strong{mysql_real_connect()} @tab
Connects to a @strong{MySQL} server.
@item @strong{mysql_real_query()} @tab
Executes a SQL query specified as a counted string.
@item @strong{mysql_reload()} @tab
Tells the server to reload the grant tables.
@item @strong{mysql_row_seek()} @tab
Seeks to a row in a result set, using value returned from
@code{mysql_row_tell()}.
@item @strong{mysql_row_tell()} @tab
Returns the row cursor position.
@item @strong{mysql_select_db()} @tab
Selects a database.
@item @strong{mysql_shutdown()} @tab
Shuts down the database server.
@item @strong{mysql_start_slave()} @tab
Starts slave replication thread
@item @strong{mysql_stat()} @tab
Returns the server status as a string.
@item @strong{mysql_store_result()} @tab
Retrieves a complete result set to the client.
@item @strong{mysql_stop_slave()} @tab
Stops slave replication thread
@item @strong{mysql_thread_id()} @tab
Returns the current thread ID.
@item @strong{mysql_thread_save()} @tab
Returns 1 if the clients are compiled as threadsafe.
@item @strong{mysql_use_result()} @tab
Initiates a row-by-row result set retrieval.
@end multitable
To connect to the server, call @code{mysql_init()} to initialize a
connection handler, then call @code{mysql_real_connect()} with that
handler (along with other information such as the hostname, user name
and password). Upon connection, @code{mysql_real_connect()} sets the
@code{reconnect} flag (part of the MYSQL structure) to a value of
@code{1}. This flag indicates, in the event that a query cannot be
performed because of a lost connection, to try reconnecting to the
server before giving up. When you are done with the connection, call
@code{mysql_close()} to terminate it.
While a connection is active, the client may send SQL queries to the server
using @code{mysql_query()} or @code{mysql_real_query()}. The difference
between the two is that @code{mysql_query()} expects the query to be
specified as a null-terminated string whereas @code{mysql_real_query()}
expects a counted string. If the string contains binary data (which may
include null bytes), you must use @code{mysql_real_query()}.
For each non-@code{SELECT} query (e.g., @code{INSERT}, @code{UPDATE},
@code{DELETE}), you can found out how many rows were affected (changed)
by calling @code{mysql_affected_rows()}.
For @code{SELECT} queries, you retrieve the selected rows as a result set.
(Note that some statements are @code{SELECT}-like in that they return rows.
These include @code{SHOW}, @code{DESCRIBE} and @code{EXPLAIN}. They should
be treated the same way as @code{SELECT} statements.)
There are two ways for a client to process result sets. One way is to
retrieve the entire result set all at once by calling
@code{mysql_store_result()}. This function acquires from the server all the
rows returned by the query and stores them in the client. The second way is
for the client to initiate a row-by-row result set retrieval by calling
@code{mysql_use_result()}. This function initializes the retrieval, but does
not actually get any rows from the server.
In both cases, you access rows by calling @code{mysql_fetch_row()}. With
@code{mysql_store_result()}, @code{mysql_fetch_row()} accesses rows that have
already been fetched from the server. With @code{mysql_use_result()},
@code{mysql_fetch_row()} actually retrieves the row from the server.
Information about the size of the data in each row is available by
calling @code{mysql_fetch_lengths()}.
After you are done with a result set, call @code{mysql_free_result()}
to free the memory used for it.
The two retrieval mechanisms are complementary. Client programs should
choose the approach that is most appropriate for their requirements.
In practice, clients tend to use @code{mysql_store_result()} more
commonly.
An advantage of @code{mysql_store_result()} is that because the rows have all
been fetched to the client, you not only can access rows sequentially, you
can move back and forth in the result set using @code{mysql_data_seek()} or
@code{mysql_row_seek()} to change the current row position within the result
set. You can also find out how many rows there are by calling
@code{mysql_num_rows()}. On the other hand, the memory requirements for
@code{mysql_store_result()} may be very high for large result sets and you
are more likely to encounter out-of-memory conditions.
An advantage of @code{mysql_use_result()} is that the client requires less
memory for the result set because it maintains only one row at a time (and
because there is less allocation overhead, @code{mysql_use_result()} can be
faster). Disadvantages are that you must process each row quickly to avoid
tying up the server, you don't have random access to rows within the result
set (you can only access rows sequentially), and you don't know how many rows
are in the result set until you have retrieved them all. Furthermore, you
@emph{must} retrieve all the rows even if you determine in mid-retrieval that
you've found the information you were looking for.
The API makes it possible for clients to respond appropriately to
queries (retrieving rows only as necessary) without knowing whether or
not the query is a @code{SELECT}. You can do this by calling
@code{mysql_store_result()} after each @code{mysql_query()} (or
@code{mysql_real_query()}). If the result set call succeeds, the query
was a @code{SELECT} and you can read the rows. If the result set call
fails, call @code{mysql_field_count()} to determine whether or not a
result was actually to be expected. If @code{mysql_field_count()}
returns zero, the query returned no data (indicating that it was an
@code{INSERT}, @code{UPDATE}, @code{DELETE}, etc.), and thus not
expected to return rows. If @code{mysql_field_count()} is non-zero, the
query should have returned rows, but didn't. This indicates that the
query was a @code{SELECT} that failed. See the description for
@code{mysql_field_count()} for an example of how this can be done.
Both @code{mysql_store_result()} and @code{mysql_use_result()} allow you to
obtain information about the fields that make up the result set (the number
of fields, their names and types, etc.). You can access field information
sequentially within the row by calling @code{mysql_fetch_field()} repeatedly,
or by field number within the row by calling
@code{mysql_fetch_field_direct()}. The current field cursor position may be
changed by calling @code{mysql_field_seek()}. Setting the field cursor
affects subsequent calls to @code{mysql_fetch_field()}. You can also get
information for fields all at once by calling @code{mysql_fetch_fields()}.
For detecting and reporting errors, @strong{MySQL} provides access to error
information by means of the @code{mysql_errno()} and @code{mysql_error()}
functions. These return the error code or error message for the most
recently invoked function that can succeed or fail, allowing you to determine
when an error occurred and what it was.
@node C API functions, Perl, C API function overview, Clients
@section C API function descriptions
@menu
* mysql_affected_rows:: @code{mysql_affected_rows()}
* mysql_close:: @code{mysql_close()}
* mysql_connect:: @code{mysql_connect()}
* mysql_change_user:: @code{mysql_change_user()}
* mysql_character_set_name:: @code{mysql_character_set_name()}
* mysql_create_db:: @code{mysql_create_db()}
* mysql_data_seek:: @code{mysql_data_seek()}
* mysql_debug:: @code{mysql_debug()}
* mysql_drop_db:: @code{mysql_drop_db()}
* mysql_dump_debug_info:: @code{mysql_dump_debug_info()}
* mysql_eof:: @code{mysql_eof()}
* mysql_errno:: @code{mysql_errno()}
* mysql_error:: @code{mysql_error()}
* mysql_escape_string:: @code{mysql_escape_string()}
* mysql_fetch_field:: @code{mysql_fetch_field()}
* mysql_fetch_fields:: @code{mysql_fetch_fields()}
* mysql_fetch_field_direct:: @code{mysql_fetch_field_direct()}
* mysql_fetch_lengths:: @code{mysql_fetch_lengths()}
* mysql_fetch_row:: @code{mysql_fetch_row()}
* mysql_field_count:: @code{mysql_field_count()}
* mysql_field_seek:: @code{mysql_field_seek()}
* mysql_field_tell:: @code{mysql_field_tell()}
* mysql_free_result:: @code{mysql_free_result()}
* mysql_get_client_info:: @code{mysql_get_client_info()}
* mysql_get_host_info:: @code{mysql_get_host_info()}
* mysql_get_proto_info:: @code{mysql_get_proto_info()}
* mysql_get_server_info:: @code{mysql_get_server_info()}
* mysql_info:: @code{mysql_info()}
* mysql_init:: @code{mysql_init()}
* mysql_insert_id:: @code{mysql_insert_id()}
* mysql_kill:: @code{mysql_kill()}
* mysql_list_dbs:: @code{mysql_list_dbs()}
* mysql_list_fields:: @code{mysql_list_fields()}
* mysql_list_processes:: @code{mysql_list_processes()}
* mysql_list_tables:: @code{mysql_list_tables()}
* mysql_num_fields:: @code{mysql_num_fields()}
* mysql_num_rows:: @code{mysql_num_rows()}
* mysql_options:: @code{mysql_options()}
* mysql_ping:: @code{mysql_ping()}
* mysql_query:: @code{mysql_query()}
* mysql_real_connect:: @code{mysql_real_connect()}
* mysql_real_escape_string:: @code{mysql_real_escape_string()}
* mysql_real_query:: @code{mysql_real_query()}
* mysql_reload:: @code{mysql_reload()}
* mysql_row_seek:: @code{mysql_row_seek()}
* mysql_row_tell:: @code{mysql_row_tell()}
* mysql_select_db:: @code{mysql_select_db()}
* mysql_shutdown:: @code{mysql_shutdown()}
* mysql_stat:: @code{mysql_stat()}
* mysql_store_result:: @code{mysql_store_result()}
* mysql_thread_id:: @code{mysql_thread_id()}
* mysql_use_result:: @code{mysql_use_result()}
* NULL mysql_store_result:: Why is it that after @code{mysql_query()} returns success, @code{mysql_store_result()} sometimes returns @code{NULL?}
* Query results:: What results can I get from a query?
* Getting unique ID:: How can I get the unique ID for the last inserted row?
* C API linking problems:: Problems linking with the C API
* Thread-safe clients:: How to make a thread-safe client
@end menu
In the descriptions below, a parameter or return value of @code{NULL} means
@code{NULL} in the sense of the C programming language, not a
@strong{MySQL} @code{NULL} value.
Functions that return a value generally return a pointer or an integer.
Unless specified otherwise, functions returning a pointer return a
non-@code{NULL} value to indicate success or a @code{NULL} value to indicate
an error, and functions returning an integer return zero to indicate success
or non-zero to indicate an error. Note that ``non-zero'' means just that.
Unless the function description says otherwise, do not test against a value
other than zero:
@example
if (result) /* correct */
... error ...
if (result < 0) /* incorrect */
... error ...
if (result == -1) /* incorrect */
... error ...
@end example
When a function returns an error, the @strong{Errors} subsection of the
function description lists the possible types of errors. You can
find out which of these occurred by calling @code{mysql_errno()}.
A string representation of the error may be obtained by calling
@code{mysql_error()}.
@findex @code{mysql_affected_rows()}
@node mysql_affected_rows, mysql_close, C API functions, C API functions
@subsection @code{mysql_affected_rows()}
@code{my_ulonglong mysql_affected_rows(MYSQL *mysql)}
@subsubheading Description
Returns the number of rows affected (changed) by the last @code{UPDATE},
@code{DELETE} or @code{INSERT} query. May be called immediately after
@code{mysql_query()} for @code{UPDATE}, @code{DELETE} or @code{INSERT}
statements. For @code{SELECT} statements, @code{mysql_affected_rows()}
works like @code{mysql_num_rows()}.
@code{mysql_affected_rows()} is currently implemented as a macro.
@subsubheading Return values
An integer greater than zero indicates the number of rows affected or
retrieved. Zero indicates that no records matched the @code{WHERE} clause in
the query or that no query has yet been executed. -1 indicates that the
query returned an error or that, for a @code{SELECT} query,
@code{mysql_affected_rows()} was called prior to calling
@code{mysql_store_result()}.
@subsubheading Errors
None.
@subsubheading Example
@example
mysql_query(&mysql,"UPDATE products SET cost=cost*1.25 WHERE group=10");
printf("%d products updated",mysql_affected_rows(&mysql));
@end example
@findex @code{mysql_close()}
@node mysql_close, mysql_connect, mysql_affected_rows, C API functions
@subsection @code{mysql_close()}
@code{void mysql_close(MYSQL *mysql)}
@subsubheading Description
Closes a previously opened connection. @code{mysql_close()} also deallocates
the connection handle pointed to by @code{mysql} if the handle was allocated
automatically by @code{mysql_init()} or @code{mysql_connect()}.
@subsubheading Return values
None.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_connect()}
@node mysql_connect, mysql_change_user, mysql_close, C API functions
@subsection @code{mysql_connect()}
@code{MYSQL *mysql_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd)}
@subsubheading Description
This function is deprecated. It is preferable to use
@code{mysql_real_connect()} instead.
@code{mysql_connect()} attempts to establish a connection to a @strong{MySQL}
database engine running on @code{host}. @code{mysql_connect()} must complete
successfully before you can execute any of the other API functions, with the
exception of @code{mysql_get_client_info()}.
The meanings of the parameters are the same as for the corresponding
parameters for @code{mysql_real_connect()} with the difference that the
connection parameter may be @code{NULL}. In this case the C API
allocates memory for the connection structure automatically and frees it
when you call @code{mysql_close()}. The disadvantage of this approach is
that you can't retrieve an error message if the connection fails. (To
get error information from @code{mysql_errno()} or @code{mysql_error()},
you must provide a valid @code{MYSQL} pointer.)
@subsubheading Return values
Same as for @code{mysql_real_connect()}.
@subsubheading Errors
Same as for @code{mysql_real_connect()}.
@findex @code{mysql_change_user()}
@node mysql_change_user, mysql_character_set_name, mysql_connect, C API functions
@subsection @code{mysql_change_user()}
@code{my_bool mysql_change_user(MYSQL *mysql, const char *user, const
char *password, const char *db)}
@subsubheading Description
Changes the user and causes the database specified by @code{db} to
become the default (current) database on the connection specified by
@code{mysql}. In subsequent queries, this database is the default for
table references that do not include an explicit database specifier.
This function was introduced in @strong{MySQL} 3.23.3.
@code{mysql_change_user()} fails unless the connected user can be
authenticated or if he doesn't have permission to use the database. In
this case the user and database are not changed
The @code{db} parameter may be set to @code{NULL} if you don't want to have a
default database.
@subsubheading Return values
Zero for success. Non-zero if an error occurred.
@subsubheading Errors
The same that you can get from @code{mysql_real_connect()}.
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@item ER_UNKNOWN_COM_ERROR
The @strong{MySQL} server doesn't implement this command (probably an old server)
@item ER_ACCESS_DENIED_ERROR
The user or password was wrong.
@item ER_BAD_DB_ERROR
The database didn't exists.
@item ER_DBACCESS_DENIED_ERROR
The user did not have access rights to the database.
@item ER_WRONG_DB_NAME
The database name was too long.
@end table
@subsubheading Example
@example
if (mysql_change_user(&mysql, "user", "password", "new_database"))
@{
fprintf(stderr, "Failed to change user. Error: %s\n",
mysql_error(&mysql));
@}
@end example
@findex @code{mysql_character_set_name()}
@node mysql_character_set_name, mysql_create_db, mysql_change_user, C API functions
@subsection @code{mysql_character_set_name()}
@code{const char *mysql_character_set_name(MYSQL *mysql)}
@subsubheading Description
Returns the default character set for the current connection.
@subsubheading Return values
The default character set
@subsubheading Errors
None.
@findex @code{mysql_create_db()}
@node mysql_create_db, mysql_data_seek, mysql_character_set_name, C API functions
@subsection @code{mysql_create_db()}
@code{int mysql_create_db(MYSQL *mysql, const char *db)}
@subsubheading Description
Creates the database named by the @code{db} parameter.
This function is deprecated. It is preferable to use @code{mysql_query()}
to issue a SQL @code{CREATE DATABASE} statement instead.
@subsubheading Return values
Zero if the database was created successfully. Non-zero if an error
occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@subsubheading Example
@example
if(mysql_create_db(&mysql, "my_database"))
@{
fprintf(stderr, "Failed to create new database. Error: %s\n",
mysql_error(&mysql));
@}
@end example
@findex @code{mysql_data_seek()}
@node mysql_data_seek, mysql_debug, mysql_create_db, C API functions
@subsection @code{mysql_data_seek()}
@code{void mysql_data_seek(MYSQL_RES *result, unsigned long long offset)}
@subsubheading Description
Seeks to an arbitrary row in a query result set. This requires that the
result set structure contains the entire result of the query, so
@code{mysql_data_seek()} may be used in conjunction only with
@code{mysql_store_result()}, not with @code{mysql_use_result()}.
The offset should be a value in the range from 0 to
@code{mysql_num_rows(result)-1}.
@subsubheading Return values
None.
@subsubheading Errors
None.
@findex @code{mysql_debug()}
@node mysql_debug, mysql_drop_db, mysql_data_seek, C API functions
@subsection @code{mysql_debug()}
@code{void mysql_debug(char *debug)}
@subsubheading Description
Does a @code{DBUG_PUSH} with the given string. @code{mysql_debug()} uses the
Fred Fish debug library. To use this function, you must compile the client
library to support debugging.
@xref{Debugging server}. @xref{Debugging client}.
@subsubheading Return values
None.
@subsubheading Errors
None.
@subsubheading Example
The call shown below causes the client library to generate a trace file in
@file{/tmp/client.trace} on the client machine:
@example
mysql_debug("d:t:O,/tmp/client.trace");
@end example
@findex @code{mysql_drop_db()}
@node mysql_drop_db, mysql_dump_debug_info, mysql_debug, C API functions
@subsection @code{mysql_drop_db()}
@code{int mysql_drop_db(MYSQL *mysql, const char *db)}
@subsubheading Description
Drops the database named by the @code{db} parameter.
This function is deprecated. It is preferable to use @code{mysql_query()}
to issue a SQL @code{DROP DATABASE} statement instead.
@subsubheading Return values
Zero if the database was dropped successfully. Non-zero if an error
occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@subsubheading Example
@example
if(mysql_drop_db(&mysql, "my_database"))
fprintf(stderr, "Failed to drop the database: Error: %s\n",
mysql_error(&mysql));
@end example
@findex @code{mysql_dump_debug_info()}
@node mysql_dump_debug_info, mysql_eof, mysql_drop_db, C API functions
@subsection @code{mysql_dump_debug_info()}
@code{int mysql_dump_debug_info(MYSQL *mysql)}
@subsubheading Description
Instructs the server to write some debug information to the log. The
connected user must have the @strong{process} privilege for this to work.
@subsubheading Return values
Zero if the command was successful. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_eof()}
@node mysql_eof, mysql_errno, mysql_dump_debug_info, C API functions
@subsection @code{mysql_eof()}
@code{my_bool mysql_eof(MYSQL_RES *result)}
@subsubheading Description
This function is deprecated. @code{mysql_errno()} or @code{mysql_error()}
may be used instead.
@code{mysql_eof()} determines whether or not the last row of a result
set has been read.
If you acquire a result set from a successful call to
@code{mysql_store_result()}, the client receives the entire set in one
operation. In this case, a @code{NULL} return from @code{mysql_fetch_row()}
always means the end of the result set has been reached and it is
unnecessary to call @code{mysql_eof()}.
On the other hand, if you use @code{mysql_use_result()} to initiate a result
set retrieval, the rows of the set are obtained from the server one by one as
you call @code{mysql_fetch_row()} repeatedly. Because an error may occur on
the connection during this process, a @code{NULL} return value from
@code{mysql_fetch_row()} does not necessarily mean the end of the result set
was reached normally. In this case, you can use @code{mysql_eof()} to
determine what happened. @code{mysql_eof()} returns a non-zero value if the
end of the result set was reached and zero if an error occurred.
Historically, @code{mysql_eof()} predates the standard @strong{MySQL} error
functions @code{mysql_errno()} and @code{mysql_error()}. Because those error
functions provide the same information, their use is preferred over
@code{mysql_eof()}, which is now deprecated. (In fact, they provide more
information, because @code{mysql_eof()} returns only a boolean value whereas
the error functions indicate a reason for the error when one occurs.)
@subsubheading Return values
Zero if no error occurred. Non-zero if the end of the result set has been
reached.
@subsubheading Errors
None.
@subsubheading Example
The following example shows how you might use @code{mysql_eof()}:
@example
mysql_query(&mysql,"SELECT * FROM some_table");
result = mysql_use_result(&mysql);
while((row = mysql_fetch_row(result)))
@{
// do something with data
@}
if(!mysql_eof(result)) // mysql_fetch_row() failed due to an error
@{
fprintf(stderr, "Error: %s\n", mysql_error(&mysql));
@}
@end example
However, you can achieve the same effect with the standard @strong{MySQL}
error functions:
@example
mysql_query(&mysql,"SELECT * FROM some_table");
result = mysql_use_result(&mysql);
while((row = mysql_fetch_row(result)))
@{
// do something with data
@}
if(mysql_errno(&mysql)) // mysql_fetch_row() failed due to an error
@{
fprintf(stderr, "Error: %s\n", mysql_error(&mysql));
@}
@end example
@findex @code{mysql_errno()}
@node mysql_errno, mysql_error, mysql_eof, C API functions
@subsection @code{mysql_errno()}
@code{unsigned int mysql_errno(MYSQL *mysql)}
@subsubheading Description
For the connection specified by @code{mysql}, @code{mysql_errno()} returns
the error code for the most recently invoked API function that can succeed
or fail. A return value of zero means that no error occurred. Client error
message numbers are listed in the @strong{MySQL} @file{errmsg.h} header file.
Server error message numbers are listed in @file{mysqld_error.h}
@subsubheading Return values:
An error code value. Zero if no error occurred.
@subsubheading Errors
None.
@findex @code{mysql_error()}
@node mysql_error, mysql_escape_string, mysql_errno, C API functions
@subsection @code{mysql_error()}
@code{char *mysql_error(MYSQL *mysql)}
@subsubheading Description
For the connection specified by @code{mysql}, @code{mysql_error()} returns
the error message for the most recently invoked API function that can succeed
or fail. An empty string (@code{""}) is returned if no error occurred.
This means the following two tests are equivalent:
@example
if(mysql_errno(&mysql))
@{
// an error occurred
@}
if(mysql_error(&mysql)[0] != '\0')
@{
// an error occurred
@}
@end example
The language of the client error messages may be changed by
recompiling the @strong{MySQL} client library. Currently you can choose
error messages in several different languages.
@xref{Languages}.
@subsubheading Return values
A character string that describes the error. An empty string if no error
occurred.
@subsubheading Errors
None.
@findex @code{mysql_escape_string()}
@node mysql_escape_string, mysql_fetch_field, mysql_error, C API functions
@subsection @code{mysql_escape_string()}
You should use @code{mysql_real_escape_string()} instead!
This is identical to @code{mysql_real_escape_string()} except that it takes
the connection as the first argument. @code{mysql_real_escape_string()}
will escape the string according to the current character set while @code{mysql_escape_string()}
does not respect the current charset setting.
@findex @code{mysql_fetch_field()}
@node mysql_fetch_field, mysql_fetch_fields, mysql_escape_string, C API functions
@subsection @code{mysql_fetch_field()}
@code{MYSQL_FIELD *mysql_fetch_field(MYSQL_RES *result)}
@subsubheading Description
Returns the definition of one column of a result set as a @code{MYSQL_FIELD}
structure. Call this function repeatedly to retrieve information about all
columns in the result set. @code{mysql_fetch_field()} returns @code{NULL}
when no more fields are left.
@code{mysql_fetch_field()} is reset to return information about the first
field each time you execute a new @code{SELECT} query. The field returned by
@code{mysql_fetch_field()} is also affected by calls to
@code{mysql_field_seek()}.
If you've called @code{mysql_query()} to perform a @code{SELECT} on a table
but have not called @code{mysql_store_result()}, @strong{MySQL} returns the
default blob length (8K bytes) if you call @code{mysql_fetch_field()} to ask
for the length of a @code{BLOB} field. (The 8K size is chosen because
@strong{MySQL} doesn't know the maximum length for the @code{BLOB}. This
should be made configurable sometime.) Once you've retrieved the result set,
@code{field->max_length} contains the length of the largest value for this
column in the specific query.
@subsubheading Return values
The @code{MYSQL_FIELD} structure for the current column. @code{NULL}
if no columns are left.
@subsubheading Errors
None.
@subsubheading Example
@example
MYSQL_FIELD *field;
while((field = mysql_fetch_field(result)))
@{
printf("field name %s\n", field->name);
@}
@end example
@findex @code{mysql_fetch_fields()}
@node mysql_fetch_fields, mysql_fetch_field_direct, mysql_fetch_field, C API functions
@subsection @code{mysql_fetch_fields()}
@code{MYSQL_FIELD *mysql_fetch_fields(MYSQL_RES *result)}
@subsubheading Description
Returns an array of all @code{MYSQL_FIELD} structures for a result set.
Each structure provides the field definition for one column of the result
set.
@subsubheading Return values
An array of @code{MYSQL_FIELD} structures for all columns of a result set.
@subsubheading Errors
None.
@subsubheading Example
@example
unsigned int num_fields;
unsigned int i;
MYSQL_FIELD *fields;
num_fields = mysql_num_fields(result);
fields = mysql_fetch_fields(result);
for(i = 0; i < num_fields; i++)
@{
printf("Field %u is %s\n", i, fields[i].name);
@}
@end example
@findex @code{mysql_fetch_field_direct()}
@node mysql_fetch_field_direct, mysql_fetch_lengths, mysql_fetch_fields, C API functions
@subsection @code{mysql_fetch_field_direct()}
@code{MYSQL_FIELD *mysql_fetch_field_direct(MYSQL_RES *result, unsigned int fieldnr)}
@subsubheading Description
Given a field number @code{fieldnr} for a column within a result set, returns
that column's field definition as a @code{MYSQL_FIELD} structure. You may use
this function to retrieve the definition for an arbitrary column. The value
of @code{fieldnr} should be in the range from 0 to
@code{mysql_num_fields(result)-1}.
@subsubheading Return values
The @code{MYSQL_FIELD} structure for the specified column.
@subsubheading Errors
None.
@subsubheading Example
@example
unsigned int num_fields;
unsigned int i;
MYSQL_FIELD *field;
num_fields = mysql_num_fields(result);
for(i = 0; i < num_fields; i++)
@{
field = mysql_fetch_field_direct(result, i);
printf("Field %u is %s\n", i, field->name);
@}
@end example
@findex @code{mysql_fetch_lengths()}
@node mysql_fetch_lengths, mysql_fetch_row, mysql_fetch_field_direct, C API functions
@subsection @code{mysql_fetch_lengths()}
@code{unsigned long *mysql_fetch_lengths(MYSQL_RES *result)}
@subsubheading Description
Returns the lengths of the columns of the current row within a result set.
If you plan to copy field values, this length information is also useful for
optimization, because you can avoid calling @code{strlen()}. In addition, if
the result set contains binary data, you @emph{must} use this function to
determine the size of the data, because @code{strlen()} returns incorrect
results for any field containing null characters.
The length for empty columns and for columns containing @code{NULL} values is
zero. To see how to distinguish these two cases, see the description for
@code{mysql_fetch_row()}.
@subsubheading Return values
An array of unsigned long integers representing the size of each column (not
including any terminating null characters).
@code{NULL} if an error occurred.
@subsubheading Errors
@code{mysql_fetch_lengths()} is valid only for the current row of the result
set. It returns @code{NULL} if you call it before calling
@code{mysql_fetch_row()} or after retrieving all rows in the result.
@subsubheading Example
@example
MYSQL_ROW row;
unsigned long *lengths;
unsigned int num_fields;
unsigned int i;
row = mysql_fetch_row(result);
if (row)
@{
num_fields = mysql_num_fields(result);
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
@{
printf("Column %u is %lu bytes in length.\n", i, lengths[i]);
@}
@}
@end example
@findex @code{mysql_fetch_row()}
@node mysql_fetch_row, mysql_field_count, mysql_fetch_lengths, C API functions
@subsection @code{mysql_fetch_row()}
@code{MYSQL_ROW mysql_fetch_row(MYSQL_RES *result)}
@subsubheading Description
Retrieves the next row of a result set. When used after
@code{mysql_store_result()}, @code{mysql_fetch_row()} returns @code{NULL}
when there are no more rows to retrieve. When used after
@code{mysql_use_result()}, @code{mysql_fetch_row()} returns @code{NULL} when
there are no more rows to retrieve or if an error occurred.
The number of values in the row is given by @code{mysql_num_fields(result)}.
If @code{row} holds the return value from a call to @code{mysql_fetch_row()},
pointers to the values are accessed as @code{row[0]} to
@code{row[mysql_num_fields(result)-1]}. @code{NULL} values in the row are
indicated by @code{NULL} pointers.
The lengths of the field values in the row may be obtained by calling
@code{mysql_fetch_lengths()}. Empty fields and fields containing
@code{NULL} both have length 0; you can distinguish these by checking
the pointer for the field value. If the pointer is @code{NULL}, the field
is @code{NULL}; otherwise the field is empty.
@subsubheading Return values
A @code{MYSQL_ROW} structure for the next row. @code{NULL} if
there are no more rows to retrieve or if an error occurred.
@subsubheading Errors
@table @code
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@subsubheading Example
@example
MYSQL_ROW row;
unsigned int num_fields;
unsigned int i;
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
@{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
@{
printf("[%.*s] ", (int) lengths[i], row[i] ? row[i] : "NULL");
@}
printf("\n");
@}
@end example
@findex @code{mysql_field_count()}
@node mysql_field_count, mysql_field_seek, mysql_fetch_row, C API functions
@subsection @code{mysql_field_count()}
@code{unsigned int mysql_field_count(MYSQL *mysql)}
If you are using a version of @strong{MySQL} earlier than 3.22.24, you
should use @code{unsigned int mysql_num_fields(MYSQL *mysql)} instead.
@subsubheading Description
Returns the number of columns for the most recent query on the connection.
The normal use of this function is when @code{mysql_store_result()}
returned @code{NULL} (and thus you have no result set pointer).
In this case, you can call @code{mysql_field_count()} to
determine whether or not @code{mysql_store_result()} should have produced a
non-empty result. This allows the client program to take proper action
without knowing whether or not the query was a @code{SELECT} (or
@code{SELECT}-like) statement. The example shown below illustrates how this
may be done.
@xref{NULL mysql_store_result, , @code{NULL mysql_store_result()}}.
@subsubheading Return values
An unsigned integer representing the number of fields in a result set.
@subsubheading Errors
None.
@subsubheading Example
@example
MYSQL_RES *result;
unsigned int num_fields;
unsigned int num_rows;
if (mysql_query(&mysql,query_string))
@{
// error
@}
else // query succeeded, process any data returned by it
@{
result = mysql_store_result(&mysql);
if (result) // there are rows
@{
num_fields = mysql_num_fields(result);
// retrieve rows, then call mysql_free_result(result)
@}
else // mysql_store_result() returned nothing; should it have?
@{
if(mysql_field_count(&mysql) == 0)
@{
// query does not return data
// (it was not a SELECT)
num_rows = mysql_affected_rows(&mysql);
@}
else // mysql_store_result() should have returned data
@{
fprintf(stderr, "Error: %s\n", mysql_error(&mysql));
@}
@}
@}
@end example
An alternative is to replace the @code{mysql_field_count(&mysql)} call with
@code{mysql_errno(&mysql)}. In this case, you are checking directly for an
error from @code{mysql_store_result()} rather than inferring from the value
of @code{mysql_field_count()} whether or not the statement was a
@code{SELECT}.
@findex @code{mysql_field_seek()}
@node mysql_field_seek, mysql_field_tell, mysql_field_count, C API functions
@subsection @code{mysql_field_seek()}
@code{MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset)}
@subsubheading Description
Sets the field cursor to the given offset. The next call to
@code{mysql_fetch_field()} will retrieve the field definition of the column
associated with that offset.
To seek to the beginning of a row, pass an @code{offset} value of zero.
@subsubheading Return values
The previous value of the field cursor.
@subsubheading Errors
None.
@findex @code{mysql_field_tell()}
@node mysql_field_tell, mysql_free_result, mysql_field_seek, C API functions
@subsection @code{mysql_field_tell()}
@code{MYSQL_FIELD_OFFSET mysql_field_tell(MYSQL_RES *result)}
@subsubheading Description
Returns the position of the field cursor used for the last
@code{mysql_fetch_field()}. This value can be used as an argument to
@code{mysql_field_seek()}.
@subsubheading Return values
The current offset of the field cursor.
@subsubheading Errors
None.
@findex @code{mysql_free_result()}
@node mysql_free_result, mysql_get_client_info, mysql_field_tell, C API functions
@subsection @code{mysql_free_result()}
@code{void mysql_free_result(MYSQL_RES *result)}
@subsubheading Description
Frees the memory allocated for a result set by @code{mysql_store_result()},
@code{mysql_use_result()}, @code{mysql_list_dbs()}, etc. When you are done
with a result set, you must free the memory it uses by calling
@code{mysql_free_result()}.
@subsubheading Return values
None.
@subsubheading Errors
None.
@findex @code{mysql_get_client_info()}
@node mysql_get_client_info, mysql_get_host_info, mysql_free_result, C API functions
@subsection @code{mysql_get_client_info()}
@code{char *mysql_get_client_info(void)}
@subsubheading Description
Returns a string that represents the client library version.
@subsubheading Return values
A character string that represents the @strong{MySQL} client library version.
@subsubheading Errors
None.
@findex @code{mysql_get_host_info()}
@node mysql_get_host_info, mysql_get_proto_info, mysql_get_client_info, C API functions
@subsection @code{mysql_get_host_info()}
@code{char *mysql_get_host_info(MYSQL *mysql)}
@subsubheading Description
Returns a string describing the type of connection in use, including the
server host name.
@subsubheading Return values
A character string representing the server host name and the connection type.
@subsubheading Errors
None.
@findex @code{mysql_get_proto_info()}
@node mysql_get_proto_info, mysql_get_server_info, mysql_get_host_info, C API functions
@subsection @code{mysql_get_proto_info()}
@code{unsigned int mysql_get_proto_info(MYSQL *mysql)}
@subsubheading Description
Returns the protocol version used by current connection.
@subsubheading Return values
An unsigned integer representing the protocol version used by the current
connection.
@subsubheading Errors
None.
@findex @code{mysql_get_server_info()}
@node mysql_get_server_info, mysql_info, mysql_get_proto_info, C API functions
@subsection @code{mysql_get_server_info()}
@code{char *mysql_get_server_info(MYSQL *mysql)}
@subsubheading Description
Returns a string that represents the server version number.
@subsubheading Return values
A character string that represents the server version number.
@subsubheading Errors
None.
@findex @code{mysql_info()}
@node mysql_info, mysql_init, mysql_get_server_info, C API functions
@subsection @code{mysql_info()}
@code{char *mysql_info(MYSQL *mysql)}
@subsubheading Description
Retrieves a string providing information about the most recently executed
query, but only for the statements listed below. For other statements,
@code{mysql_info()} returns @code{NULL}. The format of the string varies
depending on the type of query, as described below. The numbers are
illustrative only; the string will contain values appropriate for the query.
@table @code
@item INSERT INTO ... SELECT ...
String format: @code{Records: 100 Duplicates: 0 Warnings: 0}
@item INSERT INTO ... VALUES (...),(...),(...)...
String format: @code{Records: 3 Duplicates: 0 Warnings: 0}
@item LOAD DATA INFILE ...
String format: @code{Records: 1 Deleted: 0 Skipped: 0 Warnings: 0}
@item ALTER TABLE
String format: @code{Records: 3 Duplicates: 0 Warnings: 0}
@item UPDATE
String format: @code{Rows matched: 40 Changed: 40 Warnings: 0}
@end table
Note that @code{mysql_info()} returns a non-@code{NULL} value for the
@code{INSERT ... VALUES} statement only if multiple value lists are
specified in the statement.
@subsubheading Return values
A character string representing additional information about the most
recently executed query. @code{NULL} if no information is available for the
query.
@subsubheading Errors
None.
@findex @code{mysql_init()}
@node mysql_init, mysql_insert_id, mysql_info, C API functions
@subsection @code{mysql_init()}
@code{MYSQL *mysql_init(MYSQL *mysql)}
@subsubheading Description
Allocates or initializes a @code{MYSQL} object suitable for
@code{mysql_real_connect()}. If @code{mysql} is a @code{NULL} pointer, the
function allocates, initializes and returns a new object. Otherwise the
object is initialized and the address of the object is returned. If
@code{mysql_init()} allocates a new object, it will be freed when
@code{mysql_close()} is called to close the connection.
@subsubheading Return values
An initialized @code{MYSQL*} handle. @code{NULL} if there was
insufficient memory to allocate a new object.
@subsubheading Errors
In case of insufficient memory, @code{NULL} is returned.
@findex @code{mysql_insert_id()}
@node mysql_insert_id, mysql_kill, mysql_init, C API functions
@subsection @code{mysql_insert_id()}
@code{my_ulonglong mysql_insert_id(MYSQL *mysql)}
@subsubheading Description
Returns the ID generated for an @code{AUTO_INCREMENT} column by the previous
query. Use this function after you have performed an @code{INSERT} query
into a table that contains an @code{AUTO_INCREMENT} field.
Note that @code{mysql_insert_id()} returns @code{0} if the previous query
does not generate an @code{AUTO_INCREMENT} value. If you need to save
the value for later, be sure to call @code{mysql_insert_id()} immediately
after the query that generates the value.
Also note that the value of the SQL @code{LAST_INSERT_ID()} function always
contains the most recently generated @code{AUTO_INCREMENT} value, and is
not reset between queries because the value of that function is maintained
in the server.
@subsubheading Return values
The value of the @code{AUTO_INCREMENT} field that was updated by the previous
query. Returns zero if there was no previous query on the connection or if
the query did not update an @code{AUTO_INCREMENT} value.
@subsubheading Errors
None.
@findex @code{mysql_kill()}
@node mysql_kill, mysql_list_dbs, mysql_insert_id, C API functions
@subsection @code{mysql_kill()}
@code{int mysql_kill(MYSQL *mysql, unsigned long pid)}
@subsubheading Description
Asks the server to kill the thread specified by @code{pid}.
@subsubheading Return values
Zero for success. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_list_dbs()}
@node mysql_list_dbs, mysql_list_fields, mysql_kill, C API functions
@subsection @code{mysql_list_dbs()}
@code{MYSQL_RES *mysql_list_dbs(MYSQL *mysql, const char *wild)}
@subsubheading Description
Returns a result set consisting of database names on the server that match
the simple regular expression specified by the @code{wild} parameter.
@code{wild} may contain the wildcard characters @samp{%} or @samp{_}, or may
be a @code{NULL} pointer to match all databases. Calling
@code{mysql_list_dbs()} is similar to executing the query @code{SHOW
databases [LIKE wild]}.
You must free the result set with @code{mysql_free_result()}.
@subsubheading Return values
A @code{MYSQL_RES} result set for success. @code{NULL} if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_OUT_OF_MEMORY
Out of memory.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_list_fields()}
@node mysql_list_fields, mysql_list_processes, mysql_list_dbs, C API functions
@subsection @code{mysql_list_fields()}
@code{MYSQL_RES *mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)}
@subsubheading Description
Returns a result set consisting of field names in the given table that match
the simple regular expression specified by the @code{wild} parameter.
@code{wild} may contain the wildcard characters @samp{%} or @samp{_}, or may
be a @code{NULL} pointer to match all fields. Calling
@code{mysql_list_fields()} is similar to executing the query @code{SHOW
COLUMNS FROM tbl_name [LIKE wild]}.
Note that it's recommended that you use @code{SHOW COLUMNS FROM tbl_name}
instead of @code{mysql_list_fields()}.
You must free the result set with @code{mysql_free_result()}.
@subsubheading Return values
A @code{MYSQL_RES} result set for success. @code{NULL} if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_list_processes()}
@node mysql_list_processes, mysql_list_tables, mysql_list_fields, C API functions
@subsection @code{mysql_list_processes()}
@code{MYSQL_RES *mysql_list_processes(MYSQL *mysql)}
@subsubheading Description
Returns a result set describing the current server threads. This is the same
kind of information as that reported by @code{mysqladmin processlist} or
a @code{SHOW PROCESSLIST} query.
You must free the result set with @code{mysql_free_result()}.
@subsubheading Return values
A @code{MYSQL_RES} result set for success. @code{NULL} if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_list_tables()}
@node mysql_list_tables, mysql_num_fields, mysql_list_processes, C API functions
@subsection @code{mysql_list_tables()}
@code{MYSQL_RES *mysql_list_tables(MYSQL *mysql, const char *wild)}
@subsubheading Description
Returns a result set consisting of table names in the current database that
match the simple regular expression specified by the @code{wild} parameter.
@code{wild} may contain the wildcard characters @samp{%} or @samp{_}, or may
be a @code{NULL} pointer to match all tables. Calling
@code{mysql_list_tables()} is similar to executing the query @code{SHOW
tables [LIKE wild]}.
You must free the result set with @code{mysql_free_result()}.
@subsubheading Return values
A @code{MYSQL_RES} result set for success. @code{NULL} if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_num_fields()}
@findex @code{mysql_field_count()}
@node mysql_num_fields, mysql_num_rows, mysql_list_tables, C API functions
@subsection @code{mysql_num_fields()}
@code{unsigned int mysql_num_fields(MYSQL_RES *result)}
or
@code{unsigned int mysql_num_fields(MYSQL *mysql)}
The second form doesn't work on @strong{MySQL} 3.22.24 or newer. To pass a
@code{MYSQL*} argument, you must use
@code{unsigned int mysql_field_count(MYSQL *mysql)} instead.
@subsubheading Description
Returns the number of columns in a result set.
Note that you can get the number of columns either from a pointer to a result
set or to a connection handle. You would use the connection handle if
@code{mysql_store_result()} or @code{mysql_use_result()} returned
@code{NULL} (and thus you have no result set pointer). In this case, you can
call @code{mysql_field_count()} to determine whether or not
@code{mysql_store_result()} should have produced a non-empty result. This
allows the client program to take proper action without knowing whether or
not the query was a @code{SELECT} (or @code{SELECT}-like) statement. The
example shown below illustrates how this may be done.
@xref{NULL mysql_store_result, , @code{NULL mysql_store_result()}}.
@subsubheading Return values
An unsigned integer representing the number of fields in a result set.
@subsubheading Errors
None.
@subsubheading Example
@example
MYSQL_RES *result;
unsigned int num_fields;
unsigned int num_rows;
if (mysql_query(&mysql,query_string))
@{
// error
@}
else // query succeeded, process any data returned by it
@{
result = mysql_store_result(&mysql);
if (result) // there are rows
@{
num_fields = mysql_num_fields(result);
// retrieve rows, then call mysql_free_result(result)
@}
else // mysql_store_result() returned nothing; should it have?
@{
if (mysql_errno(&mysql))
@{
fprintf(stderr, "Error: %s\n", mysql_error(&mysql));
@}
else if (mysql_field_count(&mysql) == 0)
@{
// query does not return data
// (it was not a SELECT)
num_rows = mysql_affected_rows(&mysql);
@}
@}
@}
@end example
An alternative (if you KNOW that your query should have returned a result set)
is to replace the @code{mysql_errno(&mysql)} call with a check if
@code{mysql_field_count(&mysql)} is = 0. This will only happen if something
went wrong.
@findex @code{mysql_num_rows()}
@node mysql_num_rows, mysql_options, mysql_num_fields, C API functions
@subsection @code{mysql_num_rows()}
@code{my_ulonglong mysql_num_rows(MYSQL_RES *result)}
@subsubheading Description
Returns the number of rows in the result set.
The use of @code{mysql_num_rows()} depends on whether you use
@code{mysql_store_result()} or @code{mysql_use_result()} to return the result
set. If you use @code{mysql_store_result()}, @code{mysql_num_rows()} may be
called immediately. If you use @code{mysql_use_result()},
@code{mysql_num_rows()} will not return the correct value until all the rows
in the result set have been retrieved.
@subsubheading Return values
The number of rows in the result set.
@subsubheading Errors
None.
@findex @code{mysql_options()}
@node mysql_options, mysql_ping, mysql_num_rows, C API functions
@subsection @code{mysql_options()}
@code{int mysql_options(MYSQL *mysql, enum mysql_option option, const char *arg)}
@subsubheading Description
Can be used to set extra connect options and affect behavior for a connection.
This function may be called multiple times to set several options.
@code{mysql_options()} should be called after @code{mysql_init()} and before
@code{mysql_connect()} or @code{mysql_real_connect()}.
The @code{option} argument is the option that you want to set; the @code{arg}
argument is the value for the option. If the option is an integer, then
@code{arg} should point to the value of the integer.
Possible options values:
@multitable @columnfractions .25 .25 .5
@item @strong{Option} @tab @strong{Argument type} @tab @strong{Function}
@item @code{MYSQL_OPT_CONNECT_TIMEOUT} @tab @code{unsigned int *} @tab Connect timeout in seconds.
@item @code{MYSQL_OPT_COMPRESS} @tab Not used @tab Use the compressed client/server protocol.
@item @code{MYSQL_OPT_NAMED_PIPE} @tab Not used @tab Use named pipes to connect to a @strong{MySQL} server on NT.
@item @code{MYSQL_INIT_COMMAND} @tab @code{char *} @tab Command to execute when connecting to the @strong{MySQL} server. Will automatically be re-executed when reconnecting.
@item @code{MYSQL_READ_DEFAULT_FILE} @tab @code{char *} @tab Read options from the named option file instead of from @file{my.cnf}.
@item @code{MYSQL_READ_DEFAULT_GROUP} @tab @code{char *} @tab Read options from the named group from @file{my.cnf} or the file specified with @code{MYSQL_READ_DEFAULT_FILE}.
@end multitable
Note that the group @code{client} is always read if you use
@code{MYSQL_READ_DEFAULT_FILE} or @code{MYSQL_READ_DEFAULT_GROUP}.
The specified group in the option file may contain the following options:
@multitable @columnfractions .3 .7
@item @code{compress} @tab Use the compressed client/server protocol.
@item @code{database} @tab Connect to this database if no database was specified in the connect command.
@item @code{debug} @tab Debug options.
@item @code{host} @tab Default host name.
@item @code{init-command} @tab Command to execute when connecting to @strong{MySQL} server. Will automatically be re-executed when reconnecting.
@item @code{password} @tab Default password.
@item @code{pipe} @tab Use named pipes to connect to a @strong{MySQL} server on NT.
@item @code{port} @tab Default port number.
@item @code{return-found-rows} @tab Tell @code{mysql_info()} to return found rows instead of updated rows when using @code{UPDATE}.
@item @code{socket} @tab Default socket number.
@item @code{timeout} @tab Connect timeout in seconds.
@item @code{user} @tab Default user.
@end multitable
For more information about option files, see @ref{Option files}.
@subsubheading Return values
Zero for success. Non-zero if you used an unknown option.
@subsubheading Example
@example
MYSQL mysql;
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_OPT_COMPRESS,0);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"odbc");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
@{
fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error(&mysql));
@}
@end example
The above requests the client to use the compressed client/server protocol and
read the additional options from the @code{odbc} section in the @code{my.cnf}
file.
@findex @code{mysql_ping()}
@node mysql_ping, mysql_query, mysql_options, C API functions
@subsection @code{mysql_ping()}
@code{int mysql_ping(MYSQL *mysql)}
@subsubheading Description
Checks whether or not the connection to the server is working. If it has gone
down, an automatic reconnection is attempted.
This function can be used by clients that remain idle for a long while,
to check whether or not the server has closed the connection and reconnect
if necessary.
@subsubheading Return values
Zero if the server is alive. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_query()}
@node mysql_query, mysql_real_connect, mysql_ping, C API functions
@subsection @code{mysql_query()}
@code{int mysql_query(MYSQL *mysql, const char *query)}
@subsubheading Description
Executes the SQL query pointed to by the null-terminated string @code{query}.
The query must consist of a single SQL statement. You should not add
a terminating semicolon (@samp{;}) or @code{\g} to the statement.
@code{mysql_query()} cannot be used for queries that contain binary data; you
should use @code{mysql_real_query()} instead. (Binary data may contain the
@samp{\0} character, which @code{mysql_query()} interprets as the end of the
query string.)
If you want to know if the query should return a result set or not, you can
use @code{mysql_field_count()} to check for this.
@xref{mysql_field_count, @code{mysql_field_count}}.
@subsubheading Return values
Zero if the query was successful. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_real_connect()}
@node mysql_real_connect, mysql_real_escape_string, mysql_query, C API functions
@subsection @code{mysql_real_connect()}
@code{MYSQL *mysql_real_connect(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db,
unsigned int port, const char *unix_socket,
unsigned int client_flag)}
@subsubheading Description
@code{mysql_real_connect()} attempts to establish a connection to a
@strong{MySQL} database engine running on @code{host}.
@code{mysql_real_connect()} must complete successfully before you can execute
any of the other API functions, with the exception of
@code{mysql_get_client_info()}.
The parameters are specified as follows:
@itemize @bullet
@item
The first parameter should be the address of an existing @code{MYSQL}
structure. Before calling @code{mysql_real_connect()} you must call
@code{mysql_init()} to initialize the @code{MYSQL} structure. See the
example below.
@item
The value of @code{host} may be either a hostname or an IP address. If
@code{host} is @code{NULL} or the string @code{"localhost"}, a connection to
the local host is assumed. If the OS supports sockets (Unix) or named pipes
(Win32), they are used instead of TCP/IP to connect to the server.
@item
The @code{user} parameter contains the user's @strong{MySQL} login ID. If
@code{user} is @code{NULL}, the current user is assumed. Under Unix, this is
the current login name. Under Windows ODBC, the current user name must be
specified explicitly.
@xref{ODBC administrator}.
@item
The @code{passwd} parameter contains the password for @code{user}. If
@code{passwd} is @code{NULL}, only entries in the @code{user} table for the
user that have a blank password field will be checked for a match. This
allows the database administrator to set up the @strong{MySQL} privilege
system in such a way that users get different privileges depending on whether
or not they have specified a password.
Note: Do not attempt to encrypt the password before calling
@code{mysql_real_connect()}; password encryption is handled automatically by
the client API.
@item
@code{db} is the database name.
If @code{db} is not @code{NULL}, the connection will set the default
database to this value.
@item
If @code{port} is not 0, the value will be used as the port number
for the TCP/IP connection. Note that the @code{host} parameter
determines the type of the connection.
@item
If @code{unix_socket} is not @code{NULL}, the string specifies the
socket or named pipe that should be used. Note that the @code{host}
parameter determines the type of the connection.
@item
The value of @code{client_flag} is usually 0, but can be set to a combination
of the following flags in very special circumstances:
@multitable @columnfractions .25 .7
@item @strong{Flag name} @tab @strong{Flag meaning}
@item @code{CLIENT_FOUND_ROWS} @tab Return the number of found (matched) rows, not the number of affected rows.
@item @code{CLIENT_NO_SCHEMA} @tab Don't allow the @code{db_name.tbl_name.col_name} syntax. This is for ODBC; It causes the parser to generate an error if you use that syntax, which is useful for trapping bugs in some ODBC programs.
@item @code{CLIENT_COMPRESS} @tab Use compression protocol.
@item @code{CLIENT_ODBC} @tab The client is an ODBC client. This changes
@code{mysqld} to be more ODBC-friendly.
@end multitable
@end itemize
@subsubheading Return values
A @code{MYSQL*} connection handle if the connection was successful,
@code{NULL} if the connection was unsuccessful. For a successful connection,
the return value is the same as the value of the first parameter, unless you
pass @code{NULL} for that parameter.
@subsubheading Errors
@table @code
@item CR_CONN_HOST_ERROR
Failed to connect to the @strong{MySQL} server.
@item CR_CONNECTION_ERROR
Failed to connect to the local @strong{MySQL} server.
@item CR_IPSOCK_ERROR
Failed to create an IP socket.
@item CR_OUT_OF_MEMORY
Out of memory.
@item CR_SOCKET_CREATE_ERROR
Failed to create a Unix socket.
@item CR_UNKNOWN_HOST
Failed to find the IP address for the hostname.
@item CR_VERSION_ERROR
A protocol mismatch resulted from attempting to connect to a server with a
client library that uses a different protocol version. This can happen if you
use a very old client library to connect to a new server that wasn't started
with the @code{--old-protocol} option.
@item CR_NAMEDPIPEOPEN_ERROR;
Failed to create a named pipe on Win32.
@item CR_NAMEDPIPEWAIT_ERROR;
Failed to wait for a named pipe on Win32.
@item CR_NAMEDPIPESETSTATE_ERROR;
Failed to get a pipe handler on Win32.
@end table
@subsubheading Example
@example
MYSQL mysql;
mysql_init(&mysql);
mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"your_prog_name");
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
@{
fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error(&mysql));
@}
@end example
By using @code{mysql_options()} the @strong{MySQL} library will read the
@code{[client]} and @code{your_prog_name} sections in the @code{my.cnf}
file which will ensure that your program will work, even if someone has
set up @strong{MySQL} in some non-standard way.
Note that upon connection, @code{mysql_real_connect()} sets the @code{reconnect}
flag (part of the MYSQL structure) to a value of @code{1}. This flag indicates,
in the event that a query cannot be performed because of a lost connection, to
try reconnecting to the server before giving up.
@findex @code{mysql_real_escape_string()}
@node mysql_real_escape_string, mysql_real_query, mysql_real_connect, C API functions
@subsection @code{mysql_real_escape_string()}
@code{unsigned int mysql_real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned int length)}
@subsubheading Description
Encodes the string in @code{from} to an escaped SQL string, taking into
account the current charset of the connection, that can be sent to the
server in a SQL statement, places the result in @code{to}, and adds a
terminating null byte. Characters encoded are @code{NUL} (ASCII 0),
@samp{\n}, @samp{\r}, @samp{\}, @samp{'}, @samp{"} and Control-Z
(@pxref{Literals}).
The string pointed to by @code{from} must be @code{length} bytes long. You
must allocate the @code{to} buffer to be at least @code{length*2+1} bytes
long. (In the worse case, each character may need to be encoded as using two
bytes, and you need room for the terminating null byte.) When
@code{mysql_escape_string()} returns, the contents of @code{to} will be a
null-terminated string. The return value is the length of the encoded
string, not including the terminating null character.
@subsubheading Example
@example
char query[1000],*end;
end = strmov(query,"INSERT INTO test_table values(");
*end++ = '\'';
end += mysql_real_escape_string(&mysql, end,"What's this",11);
*end++ = '\'';
*end++ = ',';
*end++ = '\'';
end += mysql_real_escape_string(&mysql, end,"binary data: \0\r\n",16);
*end++ = '\'';
*end++ = ')';
if (mysql_real_query(&mysql,query,(unsigned int) (end - query)))
@{
fprintf(stderr, "Failed to insert row, Error: %s\n",
mysql_error(&mysql));
@}
@end example
The @code{strmov()} function used in the example is included in the
@code{mysqlclient} library and works like @code{strcpy()} but returns a
pointer to the terminating null of the first parameter.
@subsubheading Return values
The length of the value placed into @code{to}, not including the
terminating null character.
@subsubheading Errors
None.
@findex @code{mysql_real_query()}
@node mysql_real_query, mysql_reload, mysql_real_escape_string, C API functions
@subsection @code{mysql_real_query()}
@code{int mysql_real_query(MYSQL *mysql, const char *query, unsigned int length)}
@subsubheading Description
Executes the SQL query pointed to by @code{query}, which should be a string
@code{length} bytes long. The query must consist of a single SQL statement.
You should not add a terminating semicolon (@samp{;}) or @code{\g} to the
statement.
You @emph{must} use @code{mysql_real_query()} rather than
@code{mysql_query()} for queries that contain binary data, because binary data
may contain the @samp{\0} character. In addition, @code{mysql_real_query()}
is faster than @code{mysql_query()} because it does not call @code{strlen()} on
the query string.
If you want to know if the query should return a result set or not, you can
use @code{mysql_field_count()} to check for this.
@xref{mysql_field_count, @code{mysql_field_count}}.
@subsubheading Return values
Zero if the query was successful. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_reload()}
@node mysql_reload, mysql_row_seek, mysql_real_query, C API functions
@subsection @code{mysql_reload()}
@code{int mysql_reload(MYSQL *mysql)}
@subsubheading Description
Asks the @strong{MySQL} server to reload the grant tables. The
connected user must have the @strong{reload} privilege.
This function is deprecated. It is preferable to use @code{mysql_query()}
to issue a SQL @code{FLUSH PRIVILEGES} statement instead.
@subsubheading Return values
Zero for success. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_row_seek()}
@node mysql_row_seek, mysql_row_tell, mysql_reload, C API functions
@subsection @code{mysql_row_seek()}
@code{MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET offset)}
@subsubheading Description
Sets the row cursor to an arbitrary row in a query result set. This requires
that the result set structure contains the entire result of the query, so
@code{mysql_row_seek()} may be used in conjunction only with
@code{mysql_store_result()}, not with @code{mysql_use_result()}.
The offset should be a value returned from a call to @code{mysql_row_tell()}
or to @code{mysql_row_seek()}. This value is not simply a row number; if you
want to seek to a row within a result set using a row number, use
@code{mysql_data_seek()} instead.
@subsubheading Return values
The previous value of the row cursor. This value may be passed to a
subsequent call to @code{mysql_row_seek()}.
@subsubheading Errors
None.
@findex @code{mysql_row_tell()}
@node mysql_row_tell, mysql_select_db, mysql_row_seek, C API functions
@subsection @code{mysql_row_tell()}
@code{MYSQL_ROW_OFFSET mysql_row_tell(MYSQL_RES *result)}
@subsubheading Description
Returns the current position of the row cursor for the last
@code{mysql_fetch_row()}. This value can be used as an argument to
@code{mysql_row_seek()}.
You should use @code{mysql_row_tell()} only after @code{mysql_store_result()},
not after @code{mysql_use_result()}.
@subsubheading Return values
The current offset of the row cursor.
@subsubheading Errors
None.
@findex @code{mysql_select_db()}
@node mysql_select_db, mysql_shutdown, mysql_row_tell, C API functions
@subsection @code{mysql_select_db()}
@code{int mysql_select_db(MYSQL *mysql, const char *db)}
@subsubheading Description
Causes the database specified by @code{db} to become the default (current)
database on the connection specified by @code{mysql}. In subsequent queries,
this database is the default for table references that do not include an
explicit database specifier.
@code{mysql_select_db()} fails unless the connected user can be authenticated
as having permission to use the database.
@subsubheading Return values
Zero for success. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_shutdown()}
@node mysql_shutdown, mysql_stat, mysql_select_db, C API functions
@subsection @code{mysql_shutdown()}
@code{int mysql_shutdown(MYSQL *mysql)}
@subsubheading Description
Asks the database server to shutdown. The connected user must have
@strong{shutdown} privileges.
@subsubheading Return values
Zero for success. Non-zero if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_stat()}
@node mysql_stat, mysql_store_result, mysql_shutdown, C API functions
@subsection @code{mysql_stat()}
@code{char *mysql_stat(MYSQL *mysql)}
@subsubheading Description
Returns a character string containing information similar to that provided by
the @code{mysqladmin status} command. This includes uptime in seconds and
the number of running threads, questions, reloads and open tables.
@subsubheading Return values
A character string describing the server status. @code{NULL} if an
error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_store_result()}
@node mysql_store_result, mysql_thread_id, mysql_stat, C API functions
@subsection @code{mysql_store_result()}
@code{MYSQL_RES *mysql_store_result(MYSQL *mysql)}
@subsubheading Description
You must call @code{mysql_store_result()} or @code{mysql_use_result()}
for every query which successfully retrieves data (@code{SELECT},
@code{SHOW}, @code{DESCRIBE}, @code{EXPLAIN}).
If you want to know if the query should return a result set or not, you can
use @code{mysql_field_count()} to check for this.
@xref{mysql_field_count, @code{mysql_field_count}}.
@code{mysql_store_result()} reads the entire result of a query to the client,
allocates a @code{MYSQL_RES} structure, and places the result into this
structure.
@code{mysql_store_results()} returns a null pointer if the query didn't return
a result sets (If the query was for example an @code{INSERT} statement).
@code{mysql_store_results()} returns also null pointer if reading of the
result set failed. You can check if you got an error by checking if
@code{mysql_error()} doesn't return a null pointer, if
@code{mysql_errno()} returns <> 0 or if @code{mysql_field_count()}
returns <> 0.
An empty result set is returned if there are no rows returned. (An empty
result set differs from a null pointer as a return value.)
Once you have called @code{mysql_store_result()} and got a result back
which isn't a null pointer, you may call @code{mysql_num_rows()} to find
out how many rows are in the result set.
You can call @code{mysql_fetch_row()} to fetch rows from the result set,
or @code{mysql_row_seek()} and @code{mysql_row_tell()} to obtain or
set the current row position within the result set.
You must call @code{mysql_free_result()} once you are done with the result
set.
@xref{NULL mysql_store_result, , @code{NULL mysql_store_result()}}.
@subsubheading Return values
A @code{MYSQL_RES} result structure with the results. @code{NULL} if
an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_OUT_OF_MEMORY
Out of memory.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@findex @code{mysql_thread_id()}
@node mysql_thread_id, mysql_use_result, mysql_store_result, C API functions
@subsection @code{mysql_thread_id()}
@code{unsigned long mysql_thread_id(MYSQL *mysql)}
@subsubheading Description
Returns the thread ID of the current connection. This value can be used as
an argument to @code{mysql_kill()} to kill the thread.
If the connection is lost and you reconnect with @code{mysql_ping()}, the
thread ID will change. This means you should not get the thread ID and store
it for later, you should get it when you need it.
@subsubheading Return values
The thread ID of the current connection.
@subsubheading Errors
None.
@findex @code{mysql_use_result()}
@node mysql_use_result, NULL mysql_store_result, mysql_thread_id, C API functions
@subsection @code{mysql_use_result()}
@code{MYSQL_RES *mysql_use_result(MYSQL *mysql)}
@subsubheading Description
You must call @code{mysql_store_result()} or @code{mysql_use_result()} for
every query which successfully retrieves data (@code{SELECT}, @code{SHOW},
@code{DESCRIBE}, @code{EXPLAIN}).
@code{mysql_use_result()} initiates a result set retrieval but does not
actually read the result set into the client like @code{mysql_store_result()}
does. Instead, each row must be retrieved individually by making calls to
@code{mysql_fetch_row()}. This reads the result of a query directly from the
server without storing it in a temporary table or local buffer, which is
somewhat faster and uses much less memory than @code{mysql_store_result()}.
The client will only allocate memory for the current row and a communication
buffer that may grow up to @code{max_allowed_packet} bytes.
On the other hand, you shouldn't use @code{mysql_use_result()} if you are
doing a lot of processing for each row on the client side, or if the output
is sent to a screen on which the user may type a @code{^S} (stop scroll).
This will tie up the server and prevent other threads from updating any
tables from which the data is being fetched.
When using @code{mysql_use_result()}, you must execute
@code{mysql_fetch_row()} until a @code{NULL} value is returned, otherwise the
unfetched rows will be returned as part of the result set for your next
query. The C API will give the error @code{Commands out of sync; You can't
run this command now} if you forget to do this!
You may not use @code{mysql_data_seek()}, @code{mysql_row_seek()},
@code{mysql_row_tell()}, @code{mysql_num_rows()} or
@code{mysql_affected_rows()} with a result returned from
@code{mysql_use_result()}, nor may you issue other queries until the
@code{mysql_use_result()} has finished. (However, after you have fetched all
the rows, @code{mysql_num_rows()} will accurately return the number of rows
fetched.)
You must call @code{mysql_free_result()} once you are done with the result
set.
@subsubheading Return values
A @code{MYSQL_RES} result structure. @code{NULL} if an error occurred.
@subsubheading Errors
@table @code
@item CR_COMMANDS_OUT_OF_SYNC
Commands were executed in an improper order.
@item CR_OUT_OF_MEMORY
Out of memory.
@item CR_SERVER_GONE_ERROR
The @strong{MySQL} server has gone away.
@item CR_SERVER_LOST
The connection to the server was lost during the query.
@item CR_UNKNOWN_ERROR
An unknown error occurred.
@end table
@node NULL mysql_store_result, Query results, mysql_use_result, C API functions
@subsection Why is it that after @code{mysql_query()} returns success, @code{mysql_store_result()} sometimes returns @code{NULL?}
It is possible for @code{mysql_store_result()} to return @code{NULL}
following a successful call to @code{mysql_query()}. When this happens, it
means one of the following conditions occurred:
@itemize @bullet
@item
There was a @code{malloc()} failure (for example, if the result set was too
large).
@item
The data couldn't be read (an error occurred on the connection).
@item
The query returned no data (e.g., it was an @code{INSERT}, @code{UPDATE}
or @code{DELETE}).
@end itemize
You can always check whether or not the statement should have produced a
non-empty result by calling @code{mysql_field_count()}. If
@code{mysql_field_count()} returns zero, the result is empty and the last
query was a statement that does not return values (for example, an
@code{INSERT} or a @code{DELETE}). If @code{mysql_field_count()} returns a
non-zero value, the statement should have produced a non-empty result.
See the description of the @code{mysql_field_count()} function for an
example.
You can test for an error by calling @code{mysql_error()} or
@code{mysql_errno()}.
@node Query results, Getting unique ID, NULL mysql_store_result, C API functions
@subsection What results can I get from a query?
In addition to the result set returned by a query, you can also get the
following information:
@itemize @bullet
@item
@code{mysql_affected_rows()} returns the number of rows affected by the last
query when doing an @code{INSERT}, @code{UPDATE} or @code{DELETE}. An
exception is that if @code{DELETE} is used without a @code{WHERE} clause, the
table is recreated empty, which is much faster! In this case,
@code{mysql_affected_rows()} returns zero for the number of records
affected.
@item
@code{mysql_num_rows()} returns the number of rows in a result set. With
@code{mysql_store_result()}, @code{mysql_num_rows()} may be called as soon as
@code{mysql_store_result()} returns. With @code{mysql_use_result()},
@code{mysql_num_rows()} may be called only after you have fetched all the
rows with @code{mysql_fetch_row()}.
@item
@code{mysql_insert_id()} returns the ID generated by the last
query that inserted a row into a table with an @code{AUTO_INCREMENT} index.
@xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@item
Some queries (@code{LOAD DATA INFILE ...}, @code{INSERT INTO
... SELECT ...}, @code{UPDATE}) return additional info. The result is
returned by @code{mysql_info()}. See the description for @code{mysql_info()}
for the format of the string that it returns. @code{mysql_info()} returns a
@code{NULL} pointer if there is no additional information.
@end itemize
@node Getting unique ID, C API linking problems, Query results, C API functions
@subsection How can I get the unique ID for the last inserted row?
If you insert a record in a table containing a column that has the
@code{AUTO_INCREMENT} attribute, you can get the most recently generated
ID by calling the @code{mysql_insert_id()} function.
You can also retrieve the ID by using the @code{LAST_INSERT_ID()} function in
a query string that you pass to @code{mysql_query()}.
You can check if an @code{AUTO_INCREMENT} index is used by executing
the following code. This also checks if the query was an @code{INSERT} with
an @code{AUTO_INCREMENT} index:
@example
if (mysql_error(&mysql)[0] == 0 &&
mysql_num_fields(result) == 0 &&
mysql_insert_id(&mysql) != 0)
@{
used_id = mysql_insert_id(&mysql);
@}
@end example
The most recently generated ID is maintained in the server on a
per-connection basis. It will not be changed by another client. It will not
even be changed if you update another @code{AUTO_INCREMENT} column with a
non-magic value (that is, a value that is not @code{NULL} and not @code{0}).
If you want to use the ID that was generated for one table and insert
it into a second table, you can use SQL statements like this:
@example
INSERT INTO foo (auto,text)
VALUES(NULL,'text'); # generate ID by inserting NULL
INSERT INTO foo2 (id,text)
VALUES(LAST_INSERT_ID(),'text'); # use ID in second table
@end example
@node C API linking problems, Thread-safe clients, Getting unique ID, C API functions
@subsection Problems linking with the C API
When linking with the C API, the following errors may occur on some systems:
@example
gcc -g -o client test.o -L/usr/local/lib/mysql -lmysqlclient -lsocket -lnsl
Undefined first referenced
symbol in file
floor /usr/local/lib/mysql/libmysqlclient.a(password.o)
ld: fatal: Symbol referencing errors. No output written to client
@end example
If this happens on your system, you must include the math library by
adding @code{-lm} to the end of the compile/link line.
@node Thread-safe clients, , C API linking problems, C API functions
@subsection How to make a thread-safe client
The client library is ``almost'' thread-safe. The biggest problem is
that the subroutines in @file{net.c} that read from sockets are not
interrupt-safe. This was done with the thought that you might want to
have your own alarm that can break a long read to a server. If you
install an interrupt handlers for the @code{SIGPIPE} interrupt,
the socket handling should be thread safe.
In the standard binaries we distribute on our web site, the client libraries
are not normally compiled with the thread safe option.
To get a really thread-safe client where you can interrupt the client
from other threads and set timeouts when talking with the MySQL server,
you should use the @code{-lmysys}, @code{-lstring} and @code{-ldbug}
libraries and the @code{net_serv.o} code that the server uses.
If you don't need interrupts or timeouts you can just compile the client
library @code{(mysqlclient)} to be thread safe and use this. In this
case you don't have to worry about the @code{net_serv.o} object file or
the other @strong{MySQL} libraries.
When using a threaded client and you want to use timeouts and interrupts,
you can make great use of the routines in the @file{thr_alarm.c} file.
If you are using routines from the @code{mysys} library, the only thing
you must remember is to call @code{my_init()} first!
All functions except @code{mysql_real_connect()} are by default
thread-safe. The following notes describe how to compile a thread-safe
client library and use it in a thread-safe manner. (The notes below for
@code{mysql_real_connect()} actually apply to @code{mysql_connect()} as
well, but because @code{mysql_connect()} is deprecated, you should be
using @code{mysql_real_connect()} anyway.)
To make @code{mysql_real_connect()} thread-safe, you must recompile the
client library with this command:
@example
shell> ./configure --enable-thread-safe-client
@end example
This will ensure that the client library will use the header files required
for thread safe programs and also that @code{mysql_real_connect()} will use
a thread safe version of the @code{gethostbyname()} call.
You may get some errors because of undefined symbols when linking the
standard client, because the pthread libraries are not included by
default.
The resulting @file{libmysqlclient.a} library is now thread-safe. What this
means is that client code is thread-safe as long as two threads don't query
the same connection handle returned by @code{mysql_real_connect()} at the
same time; the client/server protocol allows only one request at a time on a
given connection. If you want to use multiple threads on the same
connection, you must have a mutex lock around your @code{mysql_query()} and
@code{mysql_store_result()} call combination. Once
@code{mysql_store_result()} is ready, the lock can be released and other
threads may query the same connection. (In other words, different threads
can use different @code{MYSQL_RES} pointers that were created with
@code{mysql_store_result()}, as long as they use the proper locking
protocol.) If you program with POSIX threads, you can use
@code{pthread_mutex_lock()} and @code{pthread_mutex_unlock()} to establish
and release a mutex lock.
If you used @code{mysql_use_result()} rather than @code{mysql_store_result()},
the lock would need to surround @code{mysql_use_result()} and the calls
to @code{mysql_fetch_row()}. However, it really is best for threaded
clients not to use @code{mysql_use_result()}.
@node Perl, Eiffel, C API functions, Clients
@section MySQL Perl API
This section documents the Perl @code{DBI} interface. The former interface
was called @code{mysqlperl}. @code{DBI}/@code{DBD} now is the
recommended Perl interface, so @code{mysqlperl} is obsolete and is not
documented here.
@menu
* DBI with DBD:: @code{DBI} with @code{DBD::mysql}
* Perl DBI Class:: The @code{DBI} interface
* DBI-info:: More @code{DBI}/@code{DBD} information
@end menu
@node DBI with DBD, Perl DBI Class, Perl, Perl
@subsection @code{DBI} with @code{DBD::mysql}
@code{DBI} is a generic interface for many databases. That means that
you can write a script that works with many different database engines
without change. You need a DataBase Driver (DBD) defined for each
database type. For @strong{MySQL}, this driver is called
@code{DBD::mysql}.
For more information on the Perl5 DBI, please visit the @code{DBI} web
page and read the documentation:
@example
@uref{http://www.symbolstone.org/technology/perl/DBI/index.html}
@end example
For more information on Object Oriented Programming
(OOP) as defined in Perl5, see the Perl OOP page:
@example
@uref{http://language.perl.com/info/documentation.html}
@end example
Installation instructions for @strong{MySQL} Perl support are given in
@ref{Perl support}.
@cindex @code{DBI} Perl module
@node Perl DBI Class, DBI-info, DBI with DBD, Perl
@subsection The @code{DBI} interface
@noindent
@strong{Portable DBI methods}
@multitable @columnfractions .3 .7
@item @code{connect} @tab Establishes a connection to a database server.
@item @code{disconnect} @tab Disconnects from the database server.
@item @code{prepare} @tab Prepares a SQL statement for execution.
@item @code{execute} @tab Executes prepared statements.
@item @code{do} @tab Prepares and executes a SQL statement.
@item @code{quote} @tab Quotes string or @code{BLOB} values to be inserted.
@item @code{fetchrow_array} @tab Fetches the next row as an array of fields.
@item @code{fetchrow_arrayref} @tab Fetches next row as a reference array of fields.
@item @code{fetchrow_hashref} @tab Fetches next row as a reference to a hashtable.
@item @code{fetchall_arrayref} @tab Fetches all data as an array of arrays.
@item @code{finish} @tab Finishes a statement and lets the system free resources.
@item @code{rows} @tab Returns the number of rows affected.
@item @code{data_sources} @tab Returns an array of databases available on localhost.
@item @code{ChopBlanks} @tab Controls whether @code{fetchrow_*} methods trim spaces.
@item @code{NUM_OF_PARAMS} @tab The number of placeholders in the prepared statement.
@item @code{NULLABLE} @tab Which columns can be @code{NULL}.
@item @code{trace} @tab Perform tracing for debugging.
@end multitable
@noindent
@strong{MySQL-specific methods}
@multitable @columnfractions .3 .7
@item @code{insertid} @tab The latest @code{AUTO_INCREMENT} value.
@item @code{is_blob} @tab Which column are @code{BLOB} values.
@item @code{is_key} @tab Which columns are keys.
@item @code{is_num} @tab Which columns are numeric.
@item @code{is_pri_key} @tab Which columns are primary keys.
@item @code{is_not_null} @tab Which columns CANNOT be @code{NULL}. See @code{NULLABLE}.
@item @code{length} @tab Maximum possible column sizes.
@item @code{max_length} @tab Maximum column sizes actually present in result.
@item @code{NAME} @tab Column names.
@item @code{NUM_OF_FIELDS} @tab Number of fields returned.
@item @code{table} @tab Table names in returned set.
@item @code{type} @tab All column types.
@end multitable
The Perl methods are described in more detail in the following sections.
Variables used for method return values have these meanings:
@table @code
@item $dbh
Database handle
@item $sth
Statement handle
@item $rc
Return code (often a status)
@item $rv
Return value (often a row count)
@end table
@noindent
@strong{Portable DBI methods}
@table @code
@findex DBI->connect()
@findex connect() DBI method
@item connect($data_source, $username, $password)
Use the @code{connect} method to make a database connection to the data
source. The @code{$data_source} value should begin with
@code{DBI:driver_name:}.
Example uses of @code{connect} with the @code{DBD::mysql} driver:
@example
$dbh = DBI->connect("DBI:mysql:$database", $user, $password);
$dbh = DBI->connect("DBI:mysql:$database:$hostname",
$user, $password);
$dbh = DBI->connect("DBI:mysql:$database:$hostname:$port",
$user, $password);
@end example
If the user name and/or password are undefined, @code{DBI} uses the
values of the @code{DBI_USER} and @code{DBI_PASS} environment variables,
respectively. If you don't specify a hostname, it defaults to
@code{'localhost'}. If you don't specify a port number, it defaults to the
default @strong{MySQL} port (@value{default_port}).
As of @code{Msql-Mysql-modules} version 1.2009,
the @code{$data_source} value allows certain modifiers:
@table @code
@item mysql_read_default_file=file_name
Read @file{filename} as an option file. For information on option files,
see @ref{Option files}.
@item mysql_read_default_group=group_name
The default group when reading an option file is normally the
@code{[client]} group. By specifying the @code{mysql_read_default_group}
option, the default group becomes the @code{[group_name]} group.
@item mysql_compression=1
Use compressed communication between the client and server (@strong{MySQL}
3.22.3 or later).
@item mysql_socket=/path/to/socket
Specify the pathname of the Unix socket that is used to connect
to the server (@strong{MySQL} 3.21.15 or later).
@end table
Multiple modifiers may be given; each must be preceded by a semicolon.
For example, if you want to avoid hardcoding the user name and password into
a @code{DBI} script, you can take them from the user's @file{~/.my.cnf}
option file instead by writing your @code{connect} call like this:
@example
$dbh = DBI->connect("DBI:mysql:$database"
. ";mysql_read_default_file=$ENV@{HOME@}/.my.cnf",
$user, $password);
@end example
This call will read options defined for the @code{[client]} group in the
option file. If you wanted to do the same thing, but use options specified
for the @code{[perl]} group as well, you could use this:
@example
$dbh = DBI->connect("DBI:mysql:$database"
. ";mysql_read_default_file=$ENV@{HOME@}/.my.cnf"
. ";mysql_read_default_group=perl",
$user, $password);
@end example
@findex DBI->disconnect
@findex disconnect DBI method
@item disconnect
The @code{disconnect} method disconnects the database handle from the database.
This is typically called right before you exit from the program.
Example:
@example
$rc = $dbh->disconnect;
@end example
@findex DBI->prepare()
@findex prepare() DBI method
@item prepare($statement)
Prepares a SQL statement for execution by the database engine
and returns a statement handle @code{($sth)} which you can use to invoke
the @code{execute} method.
Typically you handle @code{SELECT} statements (and @code{SELECT}-like statements
such as @code{SHOW}, @code{DESCRIBE} and @code{EXPLAIN}) by means of
@code{prepare} and @code{execute}.
Example:
@example
$sth = $dbh->prepare($statement)
or die "Can't prepare $statement: $dbh->errstr\n";
@end example
@findex DBI->execute
@findex execute DBI method
@item execute
The @code{execute} method executes a prepared statement. For
non-@code{SELECT} statements, @code{execute} returns the number of rows
affected. If no rows are affected, @code{execute} returns @code{"0E0"},
which Perl treats as zero but regards as true. If an error occurs,
@code{execute} returns @code{undef}. For @code{SELECT} statements,
@code{execute} only starts the SQL query in the database; you need to use one
of the @code{fetch_*} methods described below to retrieve the data.
Example:
@example
$rv = $sth->execute
or die "can't execute the query: $sth->errstr;
@end example
@findex DBI->do()
@findex do() DBI method
@item do($statement)
The @code{do} method prepares and executes a SQL statement and returns the
number of rows affected. If no rows are affected, @code{do} returns
@code{"0E0"}, which Perl treats as zero but regards as true. This method is
generally used for non-@code{SELECT} statements which cannot be prepared in
advance (due to driver limitations) or which do not need to executed more
than once (inserts, deletes, etc.). Example:
@example
$rv = $dbh->do($statement)
or die "Can't execute $statement: $dbh- >errstr\n";
@end example
Generally the 'do' statement is MUCH faster (and is preferable)
than prepare/execute for statements that doesn't contain parameters.
@findex DBI->quote()
@findex quote() DBI method
@cindex Quoting strings
@cindex Strings, quoting
@item quote($string)
The @code{quote} method is used to "escape" any special characters contained in
the string and to add the required outer quotation marks.
Example:
@example
$sql = $dbh->quote($string)
@end example
@findex DBI->fetchrow_array
@findex fetchrow_array DBI method
@item fetchrow_array
This method fetches the next row of data and returns it as an array of
field values. Example:
@example
while(@@row = $sth->fetchrow_array) @{
print qw($row[0]\t$row[1]\t$row[2]\n);
@}
@end example
@findex DBI->fetchrow_arrayref
@findex fetchrow_arrayref DBI method
@item fetchrow_arrayref
This method fetches the next row of data and returns it as a reference
to an array of field values. Example:
@example
while($row_ref = $sth->fetchrow_arrayref) @{
print qw($row_ref->[0]\t$row_ref->[1]\t$row_ref->[2]\n);
@}
@end example
@findex DBI->fetchrow_hashref
@findex fetchrow_hashref DBI method
@item fetchrow_hashref
This method fetches a row of data and returns a reference to a hash
table containing field name/value pairs. This method is not nearly as
efficient as using array references as demonstrated above. Example:
@example
while($hash_ref = $sth->fetchrow_hashref) @{
print qw($hash_ref->@{firstname@}\t$hash_ref->@{lastname@}\t\
$hash_ref- > title@}\n);
@}
@end example
@findex DBI->fetchall_arrayref
@findex fetchall_arrayref DBI method
@item fetchall_arrayref
This method is used to get all the data (rows) to be returned from the
SQL statement. It returns a reference to an array of references to arrays
for each row. You access or print the data by using a nested
loop. Example:
@example
my $table = $sth->fetchall_arrayref
or die "$sth->errstr\n";
my($i, $j);
for $i ( 0 .. $#@{$table@} ) @{
for $j ( 0 .. $#@{$table->[$i]@} ) @{
print "$table->[$i][$j]\t";
@}
print "\n";
@}
@end example
@findex DBI->finish
@findex finish DBI method
@item finish
Indicates that no more data will be fetched from this statement
handle. You call this method to free up the statement handle and any
system resources associated with it. Example:
@example
$rc = $sth->finish;
@end example
@findex DBI->rows
@findex rows DBI method
@item rows
Returns the number of rows changed (updated, deleted, etc.) by the last
command. This is usually used after a non-@code{SELECT} @code{execute}
statement. Example:
@example
$rv = $sth->rows;
@end example
@findex DBI->@{NULLABLE@}
@findex NULLABLE DBI method
@item NULLABLE
Returns a reference to an array of boolean values; for each element of
the array, a value of TRUE indicates that this
column may contain @code{NULL} values.
Example:
@example
$null_possible = $sth->@{NULLABLE@};
@end example
@findex DBI->@{NUM_OF_FIELDS@}
@findex NUM_OF_FIELDS DBI method
@item NUM_OF_FIELDS
This attribute indicates
the number of fields returned by a @code{SELECT} or @code{SHOW FIELDS}
statement. You may use this for checking whether a statement returned a
result: A zero value indicates a non-@code{SELECT} statement like
@code{INSERT}, @code{DELETE} or @code{UPDATE}.
Example:
@example
$nr_of_fields = $sth->@{NUM_OF_FIELDS@};
@end example
@findex DBI->data_sources()
@findex data_sources() DBI method
@item data_sources($driver_name)
This method returns an array containing names of databases available to the
@strong{MySQL} server on the host @code{'localhost'}.
Example:
@example
@@dbs = DBI->data_sources("mysql");
@end example
@findex DBI->@{ChopBlanks@}
@findex ChopBlanks DBI method
@item ChopBlanks
This attribute determines whether the @code{fetchrow_*} methods will chop
leading and trailing blanks from the returned values.
Example:
@example
$sth->@{'ChopBlanks'@} =1;
@end example
@findex DBI->trace
@findex trace DBI method
@item trace($trace_level)
@itemx trace($trace_level, $trace_filename)
The @code{trace} method enables or disables tracing. When invoked as a
@code{DBI} class method, it affects tracing for all handles. When invoked as
a database or statement handle method, it affects tracing for the given
handle (and any future children of the handle). Setting @code{$trace_level}
to 2 provides detailed trace information. Setting @code{$trace_level} to 0
disables tracing. Trace output goes to the standard error output by
default. If @code{$trace_filename} is specified, the file is opened in
append mode and output for @emph{all} traced handles is written to that
file. Example:
@example
DBI->trace(2); # trace everything
DBI->trace(2,"/tmp/dbi.out"); # trace everything to /tmp/dbi.out
$dth->trace(2); # trace this database handle
$sth->trace(2); # trace this statement handle
@end example
@tindex DBI_TRACE environment variable
@tindex Environment variable, DBI_TRACE
You can also enable @code{DBI} tracing by setting the @code{DBI_TRACE}
environment variable. Setting it to a numeric value is equivalent to calling
@code{DBI->(value)}. Setting it to a pathname is equivalent to calling
@code{DBI->(2,value)}.
@end table
@noindent
@strong{MySQL-specific methods}
The methods shown below are @strong{MySQL}-specific and not part of the
@code{DBI} standard. Several of them are now deprecated:
@code{is_blob}, @code{is_key}, @code{is_num}, @code{is_pri_key},
@code{is_not_null}, @code{length}, @code{max_length}, and @code{table}.
Where @code{DBI}-standard alternatives exist, they are noted below.
@table @code
@findex DBI->@{insertid@}
@findex insertid DBI method
@tindex AUTO_INCREMENT, using with DBI
@item insertid
If you use the @code{AUTO_INCREMENT} feature of @strong{MySQL}, the new
auto-incremented values will be stored here.
Example:
@example
$new_id = $sth->@{insertid@};
@end example
As an alternative, you can use @code{$dbh->@{'mysql_insertid'@}}.
@findex DBI->@{is_blob@}
@findex is_blob DBI method
@item is_blob
Returns a reference to an array of boolean values; for each element of the
array, a value of TRUE indicates that the
respective column is a @code{BLOB}.
Example:
@example
$keys = $sth->@{is_blob@};
@end example
@findex DBI->@{is_key@}
@findex is_key DBI method
@item is_key
Returns a reference to an array of boolean values; for each element of the
array, a value of TRUE indicates that the
respective column is a key.
Example:
@example
$keys = $sth->@{is_key@};
@end example
@findex DBI->@{is_num@}
@findex is_num DBI method
@item is_num
Returns a reference to an array of boolean values; for each element of the
array, a value of TRUE indicates that the
respective column contains numeric values.
Example:
@example
$nums = $sth->@{is_num@};
@end example
@findex DBI->@{is_pri_key@}
@findex is_pri_key DBI method
@item is_pri_key
Returns a reference to an array of boolean values; for each element of the
array, a value of TRUE indicates that the respective column is a primary key.
Example:
@example
$pri_keys = $sth->@{is_pri_key@};
@end example
@findex DBI->@{is_not_null@}
@findex is_not_null DBI method
@item is_not_null
Returns a reference to an array of boolean values; for each element of the
array, a value of FALSE indicates that this column may contain @code{NULL}
values.
Example:
@example
$not_nulls = $sth->@{is_not_null@};
@end example
@code{is_not_null} is deprecated; it is preferable to use the
@code{NULLABLE} attribute (described above), because that is a DBI standard.
@findex DBI->@{length@}
@findex length DBI method
@findex DBI->@{max_length@}
@findex max_length DBI method
@item length
@itemx max_length
Each of these methods returns a reference to an array of column sizes. The
@code{length} array indicates the maximum possible sizes that each column may
be (as declared in the table description). The @code{max_length} array
indicates the maximum sizes actually present in the result table. Example:
@example
$lengths = $sth->@{length@};
$max_lengths = $sth->@{max_length@};
@end example
@findex DBI->@{NAME@}
@findex NAME DBI method
@item NAME
Returns a reference to an array of column names.
Example:
@example
$names = $sth->@{NAME@};
@end example
@findex DBI->@{table@}
@findex table DBI method
@item table
Returns a reference to an array of table names.
Example:
@example
$tables = $sth->@{table@};
@end example
@findex DBI->@{type@}
@findex type DBI method
@item type
Returns a reference to an array of column types.
Example:
@example
$types = $sth->@{type@};
@end example
@end table
@node DBI-info, , Perl DBI Class, Perl
@subsection More @code{DBI}/@code{DBD} information
You can use the @code{perldoc} command to get more information about
@code{DBI}.
@example
perldoc DBI
perldoc DBI::FAQ
perldoc DBD::mysql
@end example
You can also use the @code{pod2man}, @code{pod2html}, etc., tools to
translate to other formats.
And of course you can find the latest @code{DBI} information at
the @code{DBI} web page:
@example
@uref{http://www.symbolstone.org/technology/perl/DBI/index.html}
@end example
@node Eiffel, Java, Perl, Clients
@section MySQL Eiffel wrapper
The @strong{MySQL} @uref{http://www.mysql.com/Downloads/Contrib/,Contrib directory}
contains an Eiffel wrapper written by Michael Ravits.
You can also find this at:
@url{http://www.netpedia.net/hosting/newplayer/}
@node Java, PHP, Eiffel, Clients
@section MySQL Java connectivity (JDBC)
There are 2 supported JDBC drivers for @strong{MySQL} (the twz and mm driver).
You can find a copy of these at @uref{http://www.mysql.com/Downloads/Contrib/}.
For documentation consult any JDBC documentation and the
drivers own documentation for @strong{MySQL} specific features.
@node PHP, Cplusplus, Java, Clients
@section MySQL PHP API
PHP is a server-side, HTML embedded scripting language that may be used to
create dynamic web pages. It contains support for accessing several
databases, including @strong{MySQL}. PHP may be run as a separate program,
or compiled as a module for use with the Apache web server.
The distribution and documentation are available at the
@uref{http://www.php.net/, PHP website}.
@menu
* PHP problems:: Common problems with MySQL and PHP
@end menu
@node PHP problems, , PHP, PHP
@subsection Common problems with MySQL and PHP
@itemize @bullet
@item Error: "Maximum Execution Time Exeeded"
This is a PHP limit; Go into the @file{php3.ini} file and set the maximum
execution time up from 30 seconds to something higher, as needed.
It is also not a bad idea to double the ram allowed per script to 16 instead of
8 MB.
@item Error: "Fatal error: Call to unsupported or undefined function mysql_connect() in .."
This means that your PHP version isn't compiled with @strong{MySQL} support.
You can either compile a dynamic @strong{MySQL} module and load it into PHP or
recompile PHP with built-in @code{MySQL} support. This is described in
detail in the PHP manual.
@end itemize
@node Cplusplus, Python, PHP, Clients
@section MySQL C++ APIs
Two API's are available in the @strong{MySQL}
@uref{http://www.mysql.com/Contrib/,Contrib directory}.
@node Python, Tcl, Cplusplus, Clients
@section MySQL Python APIs
The @strong{MySQL} @uref{http://www.mysql.com/Contrib/,Contrib directory}
contains a Python
interface written by Joseph Skinner.
You can also use the Python interface to iODBC to access a
@strong{MySQL} server.
@uref{http://starship.skyport.net/~lemburg/,mxODBC}
@node Tcl, , Python, Clients
@section MySQL Tcl APIs
@uref{http://www.binevolve.com/~tdarugar/tcl-sql/, Tcl at binevolve}.
The
@uref{http://www.mysql.com/Contrib,Contrib directory} contains a Tcl
interface that is based on msqltcl 1.50.
@node Comparisons, MySQL internals, Clients, Top
@chapter How MySQL compares to other databases
@menu
* Compare mSQL:: How @strong{MySQL} compares to @code{mSQL}
* Compare PostgreSQL:: How @strong{MySQL} compares with PostgreSQL
@end menu
@node Compare mSQL, Compare PostgreSQL, Comparisons, Comparisons
@section How MySQL compares to @code{mSQL}
This section has been written by the @strong{MySQL} developers, so it
should be read with that in mind. But there are NO factual errors that
we know of.
For a list of all supported limits, functions and types, see the
@uref{http://www.mysql.com/information/crash-me.php, @code{crash-me} web page}.
@table @strong
@item Performance
For a true comparison of speed, consult the growing @strong{MySQL} benchmark
suite. @xref{Benchmarks}.
Because there is no thread creation overhead, a small parser, few features and
simple security, @code{mSQL} should be quicker at:
@itemize @bullet
@item
Tests that perform repeated connects and disconnects, running a very simple
query during each connection.
@item
@code{INSERT} operations into very simple tables with few columns and keys.
@item
@code{CREATE TABLE} and @code{DROP TABLE}.
@item
@code{SELECT} on something that isn't an index. (A table scan is very
easy.)
@end itemize
Because these operations are so simple, it is hard to be better at them when
you have a higher startup overhead. After the connection is established,
@strong{MySQL} should perform much better.
On the other hand, @strong{MySQL} is much faster than @code{mSQL} (and
most other SQL implementions) on the following:
@itemize @bullet
@item
Complex @code{SELECT} operations.
@item
Retrieving large results (@strong{MySQL} has a better, faster and safer
protocol).
@item
Tables with variable-length strings, because @strong{MySQL} has more efficent
handling and can have indexes on @code{VARCHAR} columns.
@item
Handling tables with many columns.
@item
Handling tables with large record lengths.
@item
@code{SELECT} with many expressions.
@item
@code{SELECT} on large tables.
@item
Handling many connections at the same time. @strong{MySQL} is fully
multi-threaded. Each connection has its own thread, which means that
no thread has to wait for another (unless a thread is modifying
a table another thread wants to access.) In @code{mSQL}, once one connection
is established, all others must wait until the first has finished, regardless
of whether the connection is running a query that is short or long. When the
first connection terminates, the next can be served, while all the others wait
again, etc.
@item
Joins.
@code{mSQL} can become pathologically slow if you change the order of tables
in a @code{SELECT}. In the benchmark suite, a time more than 15000 times
slower than @strong{MySQL} was seen. This is due to @code{mSQL}'s lack of a
join optimizer to order tables in the optimal order. However, if you put the
tables in exactly the right order in @code{mSQL}2 and the @code{WHERE} is
simple and uses index columns, the join will be relatively fast!
@xref{Benchmarks}.
@item
@code{ORDER BY} and @code{GROUP BY}.
@item
@code{DISTINCT}.
@item
Using @code{TEXT} or @code{BLOB} columns.
@end itemize
@item SQL Features
@itemize @bullet
@item @code{GROUP BY} and @code{HAVING}.
@code{mSQL} does not support @code{GROUP BY} at all.
@strong{MySQL} supports a full @code{GROUP BY} with both @code{HAVING} and
the following functions: @code{COUNT()}, @code{AVG()}, @code{MIN()},
@code{MAX()}, @code{SUM()} and @code{STD()}. @code{COUNT(*)} is optimized to
return very quickly if the @code{SELECT} retrieves from one table, no other
columns are retrieved and there is no @code{WHERE} clause. @code{MIN()} and
@code{MAX()} may take string arguments.
@item @code{INSERT} and @code{UPDATE} with calculations.
@strong{MySQL} can do calculations in an @code{INSERT} or @code{UPDATE}.
For example:
@example
mysql> UPDATE SET x=x*10+y WHERE x<20;
@end example
@item Aliasing.
@strong{MySQL} has column aliasing.
@item Qualifying column names.
In @strong{MySQL}, if a column name is unique among the tables used in a
query, you do not have to use the full qualifier.
@item @code{SELECT} with functions.
@strong{MySQL} has many functions (too many to list here; see @ref{Functions}).
@end itemize
@item Disk space efficiency
That is, how small can you make your tables?
@strong{MySQL} has very precise types, so you can create tables that take
very little space. An example of a useful @strong{MySQL} datatype is the
@code{MEDIUMINT} that is 3 bytes long. If you have 100,000,000 records,
saving even one byte per record is very important.
@code{mSQL2} has a more limited set of column types, so it is
more difficult to get small tables.
@item Stability
This is harder to judge objectively. For a discussion of @strong{MySQL}
stability, see @ref{Stability}.
We have no experience with @code{mSQL} stability, so we cannot say
anything about that.
@item Price
Another important issue is the license. @strong{MySQL} has a
more flexible license than @code{mSQL}, and is also less expensive than
@code{mSQL}. Whichever product you choose to use, remember to at least
consider paying for a license or email support. (You are required to get
a license if you include @strong{MySQL} with a product that you sell,
of course.)
@item Perl interfaces
@strong{MySQL} has basically the same interfaces to Perl as @code{mSQL} with
some added features.
@item JDBC (Java)
@strong{MySQL} currently has 4 JDBC drivers:
@itemize @bullet
@item
The gwe driver: A Java interface by GWE technologies (not supported anymore).
@item
The jms driver: An improved gwe driver by Xiaokun Kelvin ZHU
@email{X.Zhu@@brad.ac.uk}.
@item
The twz driver: A type 4 JDBC driver by Terrence W. Zellers
@email{zellert@@voicenet.com}. This is commercial but is free for private
and educational use.
@item
The mm driver: A type 4 JDBC driver by Mark Matthews
@email{mmatthew@@ecn.purdue.edu}. This is released under the GPL.
@end itemize
The recommended drivers are the twz or mm driver. Both are reported to work
excellently.
We know that @code{mSQL} has a JDBC driver, but we have too little experience
with it to compare.
@item Rate of development
@strong{MySQL} has a very small team of developers, but we are quite
used to coding C and C++ very rapidly. Because threads, functions,
@code{GROUP BY} and so on are still not implemented in @code{mSQL}, it
has a lot of catching up to do. To get some perspective on this, you
can view the @code{mSQL} @file{HISTORY} file for the last year and
compare it with the News section of the @strong{MySQL} Reference Manual
(@pxref{News}). It should be pretty obvious which one has developed
most rapidly.
@item Utility programs
Both @code{mSQL} and @strong{MySQL} have many interesting third-party
tools. Because it is very easy to port upward (from @code{mSQL} to
@strong{MySQL}), almost all the interesting applications that are available for
@code{mSQL} are also available for @strong{MySQL}.
@strong{MySQL} comes with a simple @code{msql2mysql} program that fixes
differences in spelling between @code{mSQL} and @strong{MySQL} for the
most-used C API functions.
For example, it changes instances of @code{msqlConnect()} to
@code{mysql_connect()}. Converting a client program from @code{mSQL} to
@strong{MySQL} usually takes a couple of minutes.
@end table
@menu
* Using mSQL tools:: How to convert @code{mSQL} tools for @strong{MySQL}
* Protocol differences:: How @code{mSQL} and @strong{MySQL} client/server communications protocols differ
* Syntax differences:: How @code{mSQL} 2.0 SQL syntax differs from @strong{MySQL}
@end menu
@node Using mSQL tools, Protocol differences, Compare mSQL, Compare mSQL
@subsection How to convert @code{mSQL} tools for MySQL
According to our experience, it would just take a few hours to convert tools
such as @code{msql-tcl} and @code{msqljava} that use the
@code{mSQL} C API so that they work with the @strong{MySQL} C API.
The conversion procedure is:
@enumerate
@item
Run the shell script @code{msql2mysql} on the source. This requires the
@code{replace} program, which is distributed with @strong{MySQL}.
@item
Compile.
@item
Fix all compiler errors.
@end enumerate
Differences between the @code{mSQL} C API and the @strong{MySQL} C API are:
@itemize @bullet
@item
@strong{MySQL} uses a @code{MYSQL} structure as a connection type (@code{mSQL}
uses an @code{int}).
@item
@code{mysql_connect()} takes a pointer to a @code{MYSQL} structure as a
parameter. It is easy to define one globally or to use @code{malloc()} to get
one.
@code{mysql_connect()} also takes two parameters for specifying the user and
password. You may set these to @code{NULL, NULL} for default use.
@item
@code{mysql_error()} takes the @code{MYSQL} structure as a parameter. Just add
the parameter to your old @code{msql_error()} code if you are porting old code.
@item
@strong{MySQL} returns an error number and a text error message for all
errors. @code{mSQL} returns only a text error message.
@item
Some incompatibilities exist as a result of @strong{MySQL} supporting
multiple connections to the server from the same process.
@end itemize
@node Protocol differences, Syntax differences, Using mSQL tools, Compare mSQL
@subsection How @code{mSQL} and MySQL client/server communications protocols differ
There are enough differences that it is impossible (or at least not easy)
to support both.
The most significant ways in which the @strong{MySQL} protocol differs
from the @code{mSQL} protocol are listed below:
@itemize @bullet
@item
A message buffer may contain many result rows.
@item
The message buffers are dynamically enlarged if the query or the
result is bigger than the current buffer, up to a configurable server and
client limit.
@item
All packets are numbered to catch duplicated or missing packets.
@item
All column values are sent in ASCII. The lengths of columns and rows are sent
in packed binary coding (1, 2 or 3 bytes).
@item
@strong{MySQL} can read in the result unbuffered (without having to store the
full set in the client).
@item
If a single read/write takes more than 30 seconds, the server closes
the connection.
@item
If a connection is idle for 8 hours, the server closes the connection.
@end itemize
@node Syntax differences, , Protocol differences, Compare mSQL
@subsection How @code{mSQL} 2.0 SQL syntax differs from MySQL
@noindent
@strong{Column types}
@table @code
@item @strong{MySQL}
Has the following additional types (among others; see
@pxref{CREATE TABLE, , @code{CREATE TABLE}}):
@itemize @bullet
@item
@code{ENUM} type for one of a set of strings.
@item
@code{SET} type for many of a set of strings.
@item
@code{BIGINT} type for 64-bit integers.
@end itemize
@item
@strong{MySQL} also supports
the following additional type attributes:
@itemize @bullet
@item
@code{UNSIGNED} option for integer columns.
@item
@code{ZEROFILL} option for integer columns.
@item
@code{AUTO_INCREMENT} option for integer columns that are a
@code{PRIMARY KEY}.
@xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@item
@code{DEFAULT} value for all columns.
@end itemize
@item mSQL2
@code{mSQL} column types correspond to the @strong{MySQL} types shown below:
@multitable @columnfractions .15 .85
@item @code{mSQL} @strong{type} @tab @strong{Corresponding @strong{MySQL} type}
@item @code{CHAR(len)} @tab @code{CHAR(len)}
@item @code{TEXT(len)} @tab @code{TEXT(len)}. @code{len} is the maximal length.
And @code{LIKE} works.
@item @code{INT} @tab @code{INT}. With many more options!
@item @code{REAL} @tab @code{REAL}. Or @code{FLOAT}. Both 4- and 8-byte versions are available.
@item @code{UINT} @tab @code{INT UNSIGNED}
@item @code{DATE} @tab @code{DATE}. Uses ANSI SQL format rather than @code{mSQL}'s own format.
@item @code{TIME} @tab @code{TIME}
@item @code{MONEY} @tab @code{DECIMAL(12,2)}. A fixed-point value with two decimals.
@end multitable
@end table
@noindent
@strong{Index creation}
@table @code
@item @strong{MySQL}
Indexes may be specified at table creation time with the @code{CREATE TABLE}
statement.
@item mSQL
Indexes must be created after the table has been created, with separate
@code{CREATE INDEX} statements.
@end table
@noindent
@strong{To insert a unique identifier into a table}
@table @code
@item @strong{MySQL}
Use @code{AUTO_INCREMENT} as a column type
specifier.
@xref{mysql_insert_id, , @code{mysql_insert_id()}}.
@item mSQL
Create a @code{SEQUENCE} on a table and select the @code{_seq} column.
@end table
@noindent
@strong{To obtain a unique identifier for a row}
@table @code
@item @strong{MySQL}
Add a @code{PRIMARY KEY} or @code{UNIQUE} key to the table and use this.
New in 3.23.11: If the @code{PRIMARY} or @code{UNIQUE} key consists of only one
column and this is of type integer, one can also refer to it as
@code{_rowid}.
@item mSQL
Use the @code{_rowid} column. Observe that @code{_rowid} may change over time
depending on many factors.
@end table
@noindent
@strong{To get the time a column was last modified}
@table @code
@item @strong{MySQL}
Add a @code{TIMESTAMP} column to the table. This column is automatically set
to the current date and time for @code{INSERT} or @code{UPDATE} statements if
you don't give the column a value or if you give it a @code{NULL} value.
@item mSQL
Use the @code{_timestamp} column.
@end table
@noindent
@strong{@code{NULL} value comparisons}
@table @code
@item @strong{MySQL}
@strong{MySQL} follows
ANSI SQL and a comparison with @code{NULL} is always @code{NULL}.
@item mSQL
In @code{mSQL}, @code{NULL = NULL} is TRUE. You
must change @code{=NULL} to @code{IS NULL} and @code{<>NULL} to
@code{IS NOT NULL} when porting old code from @code{mSQL} to @strong{MySQL}.
@end table
@noindent
@strong{String comparisons}
@table @code
@item @strong{MySQL}
Normally, string comparisons are performed in case-independent fashion with
the sort order determined by the current character set (ISO-8859-1 Latin1 by
default). If you don't like this, declare your columns with the
@code{BINARY} attribute, which causes comparisons to be done according to the
ASCII order used on the @strong{MySQL} server host.
@item mSQL
All string comparisons are performed in case-sensitive fashion with
sorting in ASCII order.
@end table
@noindent
@strong{Case-insensitive searching}
@table @code
@item @strong{MySQL}
@code{LIKE} is a case-insensitive or case-sensitive operator, depending on
the columns involved. If possible, @strong{MySQL} uses indexes if the
@code{LIKE} argument doesn't start with a wildcard character.
@item mSQL
Use @code{CLIKE}.
@end table
@noindent
@strong{Handling of trailing spaces}
@table @code
@item @strong{MySQL}
Strips all spaces at the end of @code{CHAR} and @code{VARCHAR}
columns. Use a @code{TEXT} column if this behavior is not desired.
@item mSQL
Retains trailing space.
@end table
@noindent
@strong{@code{WHERE} clauses}
@table @code
@item @strong{MySQL}
@strong{MySQL} correctly prioritizes everything (@code{AND} is evaluated
before @code{OR}). To get @code{mSQL} behavior in @strong{MySQL}, use
parentheses (as shown below).
@item mSQL
Evaluates everything from left to right. This means that some logical
calculations with more than three arguments cannot be expressed in any
way. It also means you must change some queries when you upgrade to
@strong{MySQL}. You do this easily by adding parentheses. Suppose you
have the following @code{mSQL} query:
@example
mysql> SELECT * FROM table WHERE a=1 AND b=2 OR a=3 AND b=4;
@end example
To make @strong{MySQL} evaluate this the way that @code{mSQL} would,
you must add parentheses:
@example
mysql> SELECT * FROM table WHERE (a=1 AND (b=2 OR (a=3 AND (b=4))));
@end example
@end table
@noindent
@strong{Access control}
@table @code
@item @strong{MySQL}
Has tables to store grant (permission) options per user, host and
database. @xref{Privileges}.
@item mSQL
Has a file @file{mSQL.acl} in which you can grant read/write privileges for
users.
@item
@end table
@node Compare PostgreSQL, , Compare mSQL, Comparisons
@section How MySQL compares to PostgreSQL
We would first like to note that @code{PostgreSQL} and @strong{MySQL}
are both widely used products but their design goals are completely
different. This means that for some applications @strong{MySQL} is more
suitable and for others @code{PostgreSQL} is more suitable. When
choosing which database to use you should first check if the databases
feature set is good enough to satisfy your application. If you need
speed then @strong{MySQL} is probably your best choice, if you need some
of the extra features that @code{PostgreSQL} can offer you should use
@code{PostgreSQL}.
@code{PostgreSQL} has some more advanced features like user-defined
types, triggers, rules and some transaction support (currently it's
has about same symantic as @code{MySQL}'s transactions in that the
transaction is not 100 % atomic) . However, PostgreSQL lacks
many of the standard types and functions from ANSI SQL and ODBC. See the
@uref{http://www.mysql.com/information/crash-me.php, @code{crash-me} web page}
for a complete list of limits and which types and functions are supported
or unsupported.
Normally, @code{PostgreSQL} is a magnitude slower than
@strong{MySQL}. @xref{Benchmarks}. This is due largely to they have only
transaction safe tables and that their transactions system is not as
sophisticated as Berkeley DB's. In @strong{MySQL} you can decide per
table if you want the table to be fast or take the speed penalty of
making it transaction safe.
The most important things that @code{PostgreSQL} supports that @strong{MySQL}
don't yet support:
@table @code
@item Sub select
@item Foregin keys
@item Stored procedures
@item An extendable type system.
@item A way to extend the SQL to handle new key types (like R-trees)
@end table
@strong{MySQL} on the other hand supports a many ANSI SQL constructs
that @code{PostgreSQL} doesn't support; Most of these can be found at the
@uref{http://www.mysql.com/information/crash-me.php, @code{crash-me} web page}.
If you really need the rich type system @code{PostgreSQL} offers and you
can afford the speed penalty of having to do everything transaction
safe, you should take a look at @code{PostgreSQL}.
@node MySQL internals, Environment variables, Comparisons, Top
@chapter MySQL internals
This chapter describes a lot of things that you need to know when
working on the @strong{MySQL} code.
@menu
* MySQL threads:: MySQL threads
@end menu
@node MySQL threads, , MySQL internals, MySQL internals
@section MySQL threads
The @strong{MySQL} server creates the the following threads:
@itemize @bullet
@item
The TCP/IP connection thread handles all connect requests and
creates a new dedicated thread to handle the authentication and
and SQL query processing for the connection.
@item
On NT there is a named pipe handler thread that does the same work as
the TCP/IP connection thread on named pipe connect requests.
@item
The signal thread handles all signals. This thread also normally handles
alarms and calls @code{process_alarm()} to force timeouts on connections
that have been idle too long.
@item
If compiled with @code{-DUSE_ALARM_THREAD}, a dedicated thread that
handles alarms is created. This is only used on some systems where
there are some problems with @code{sigwait()} or if one wants to use the
@code{thr_alarm()} code in ones application without a dedicated signal
handling thread.
@item
If one uses the @code{--flush_time=#} option, a dedicated thread is created
to flush all tables at the given interval.
@item
Every connection has its own thread.
@item
Every different table on which one uses @code{INSERT DELAYED} gets its
own thread.
@item
If you use @code{--master-host} , slave replication thread will be
started to read and apply updates from the master.
@end itemize
@code{mysqladmin processlist} only shows the connection and @code{INSERT
DELAYED} threads.
@page
@node Environment variables, Users, MySQL internals, Top
@appendix Environment variables
Here follows a list of all environment variables that are used directly or
indirectly by @strong{MySQL}. Most of these can also be found at other
places in this manual.
Note that any options on the command line will take precedence over
values specified in configuration files and environment variables, and
values in configuration files take precedence over values in environment
variables.
In many cases its preferable to use a configure file instead of environment
variables to modify the behaviour of @strong{MySQL}. @xref{Option files}.
@tindex CCX environment variable
@tindex Environment variable, CCX
@tindex CC environment variable
@tindex Environment variable, CC
@tindex CFLAGS environment variable
@tindex Environment variable, CFLAGS
@tindex CXXFLAGS environment variable
@tindex Environment variable, CXXFLAGS
@tindex DBI_USER environment variable
@tindex Environment variable, DBI_USER
@tindex DBI_TRACE environment variable
@tindex Environment variable, DBI_TRACE
@tindex HOME environment variable
@tindex Environment variable, HOME
@tindex LD_RUN_PATH environment variable
@tindex Environment variable, LD_RUN_PATH
@tindex MYSQL_DEBUG environment variable
@tindex Environment variable, MYSQL_DEBUG
@tindex MYSQL_HISTFILE environment variable
@tindex Environment variable, MYSQL_HISTFILE
@tindex MYSQL_HOST environment variable
@tindex Environment variable, MYSQL_HOST
@tindex MYSQL_PWD environment variable
@tindex Environment variable, MYSQL_PWD
@tindex MYSQL_TCP_PORT environment variable
@tindex Environment variable, MYSQL_TCP_PORT
@tindex MYSQL_UNIX_PORT environment variable
@tindex Environment variable, MYSQL_UNIX_PORT
@tindex PATH environment variable
@tindex Environment variable, PATH
@tindex TMPDIR environment variable
@tindex Environment variable, TMPDIR
@tindex TZ environment variable
@tindex Environment variable, TZ
@tindex UMASK_DIR environment variable
@tindex Environment variable, UMASK_DIR
@tindex UMASK environment variable
@tindex Environment variable, UMASK
@tindex USER environment variable
@tindex Environment variable, USER
@multitable @columnfractions .2 .8
@item @code{CCX} @tab Set this to your C++ compiler when running configure.
@item @code{CC} @tab Set this to your C compiler when running configure.
@item @code{CFLAGS} @tab Flags for your C compiler when running configure.
@item @code{CXXFLAGS} @tab Flags for your C++ compiler when running configure.
@item @code{DBI_USER} @tab The default user name for Perl DBI.
@item @code{DBI_TRACE} @tab Used when tracing Perl DBI.
@item @code{HOME} @tab The default path for the @code{mysql} history file is @file{$HOME/.mysql_history}.
@item @code{LD_RUN_PATH} @tab Used to specify where your @code{libmysqlclient.so} is.
@item @code{MYSQL_DEBUG} @tab Debug-trace options when debugging
@item @code{MYSQL_HISTFILE} @tab The path to the @code{mysql} history file.
@item @code{MYSQL_HOST} @tab Default host name used by the @code{mysql} command line prompt.
@item @code{MYSQL_PWD} @tab The default password when connecting to mysqld. Note that use of this is insecure!
@item @code{MYSQL_TCP_PORT} @tab The default TCP/IP port.
@item @code{MYSQL_UNIX_PORT} @tab The default socket; used for connections to @code{localhost}.
@item @code{PATH} @tab Used by the shell to finds the @strong{MySQL} programs.
@item @code{TMPDIR} @tab The directory where temporary tables/files are created.
@item @code{TZ} @tab This should be set to your local timezone. @xref{Timezone problems}.
@item @code{UMASK_DIR} @tab The user-directory creation mask when creating directories. Note that this is ANDed with @code{UMASK}!
@item @code{UMASK} @tab The user-file creation mask when creating files.
@item @code{USER} @tab The default user on Windows to use when connecting to @code{mysqld}.
@end multitable
@page
@node Users, Contrib, Environment variables, Top
@appendix Some MySQL users
@appendixsec General news sites
@itemize @bullet
@item @uref{http://www.yahoo.com/, Yahoo!}
@item @uref{http://slashdot.org/, Slashdot: A pro-Linux/tech news and comment/discussion site}
@item @uref{http://www.linux.com/, All about Linux}
@item @uref{http://www.linuxtoday.com/, Linuxtoday}
@item @uref{http://www.32bitsonline.com/, 32Bits Online: because there's
more than one way to compute}
@item @uref{http://www.freshmeat.net/, Freshmeat: News about new versions of computer related stuff}
@end itemize
@appendixsec Some Web search engines
@itemize @bullet
@item @uref{http://www.aaa.com.au, AAA Matilda Web Search}
@item @uref{http://www.whatsnu.com/, What's New}
@item @uref{http://www.aladin.de/, Aladin}
@item @uref{http://www.columbus-finder.de/, Columbus Finder}
@item @uref{http://www.spider.de/, Spider}
@item @uref{http://www.blitzsuche.de/, Blitzsuche}
@item @uref{http://www.indoseek.co.id, Indoseek Indonesia}
@item @uref{http://www.yaboo.dk/, Yaboo - Yet Another BOOkmarker}
@c Didn't answer 2000-07-11
@c @item @uref{http://www.yahoosuck.com, Yahoosuck}
@item @uref{http://www.ozsearch.com.au, OzSearch Internet Guide}
@item @uref{http://www.splatsearch.com/, Splat! Search}
@item @uref{http://osdls.library.arizona.edu/, The Open Source Digital Library System Project}
@end itemize
@appendixsec Some Information search engines concentrated on some area
@itemize @bullet
@item @uref{http://www.tucows.com/, TuCows Network; Free Software archive}
@item @uref{http://www.jobvertise.com,Jobvertise: Post and search for jobs}
@item @uref{http://www.musicdatabase.com, The Music Database}
@item @uref{http://www.soccersearch.com, Fotball (Soccer) search page}
@item @uref{http://www.headrush.net/takedown, TAKEDOWN - wrestling}
@item @uref{http://www.lyrics.net, The International Lyrics Network}
@item @uref{http://TheMatrix.com/~matrix/band_search.phtml, Musicians looking for other musicians (Free Service)}
@item @uref{http://www.addall.com/AddBooks/Stores.html,AddALL books searching and price comparison}
@item @uref{http://www.herbaria.harvard.edu/Data/Gray/gray.html,Harvard's Gray Herbarium Index of Plant Names}
@item @uref{http://www.game-developer.com/,The Game Development Search Engine}
@item @uref{http://www.i-run.com/html/cookbook.html,My-Recipe.com; Cookbook at i-run.com}
@item @uref{www.theinnkeeper.com, The Innkeeper Vacation Guides}
@item @uref{http://www.macgamedatabase.com/, The Mac Game Database uses PHP and MySQL}
@c From: Marc Antony Vose <suzerain@suzerain.com>
@item @uref{http://www.csse.monash.edu.au/publications/, Research
Publications at Monash University in Australia}
@item @uref{http://www.ipielle.emr.it/bts/index.html,
Occupational Health & Safety website databse (a project for the ECC)}
@c c.presutti@ipielle.emr.it
@item @uref{http://data.mch.mcgill.ca/, Bioinformatics databases at the
Montreal Children's Hospital using MySQL}
@c saeed@www.debelle.mcgill.ca
@end itemize
@appendixsec Online magazines
@itemize @bullet
@item @uref{http://www.spoiler.com, Spoiler Webzine}.
An online magazine featuring music, literature, arts, and design content.
@item @uref{http://www.linux-magazin.de/newsflash/, Daily news about Linux in German language}
@item @uref{http://www.betazine.com,Betazine - The Ultimate Online Beta Tester's Magazine}
@item @uref{http://www.currents.net/ccinfo/aboutcc.html,Computer Currents Magazine}
@end itemize
@appendixsec Web sites that use MySQL as a backend
@itemize @bullet
@item @uref{http://lindev.jmc.tju.edu/qwor, Qt Widget and Object Repository}
@item @uref{http://www.samba-choro.com.br, Brazilian samba site (in Portuguese)}
@item @uref{http://pgss.iss.uw.edu.pl/en_index.ISS, Polish General Social Survey}
@item @uref{http://www.expo2000.com, Expo2000} World-wide distribution of
tickets for this event is implemented using @strong{MySQL} and tcl/tk. More than
5000 travel-agencies all over the world have access to it.
@item @uref{http://www.freevote.com/, FreeVote.com is a free voting
service with millions of users.}
@item @uref{http://f1.tauzero.se, Forza Motorsport}
@end itemize
@appendixsec Some Domain/Internet/Web and related services
@itemize @bullet
@item @uref{http://www.wix.com/mysql-hosting, Registry of Web providers that
support @strong{MySQL}}
@item @uref{http://www.yi.org/, Dynamic DNS Services}
@item @uref{http://www.dynodns.net/, Dynamic domain name service}
@item @uref{http://www.ods.org/, Open DNS Project; free dynamic DNS service}
@c @item @uref{http://dynodns.net, Free dynamic DNS implementation}
@c EMAIL: A Moore <amoore@mooresystems.com>
@item @uref{http://www.fdns.net/, Free 3rd level domains}
@item @uref{http://worldcommunity.com/, Online Database}
@item @uref{http://www.bigbiz.com, BigBiz Internet Services}
@item @uref{http://virt.circle.net, The Virt Gazette}
@item @uref{http://www.california.com, Global InfoNet Inc}
@item @uref{http://www.webhosters.com, WebHosters - A Guide to WWW Providers}
@item @uref{http://online.dn.ru, Internet information server}
@item @uref{http://www.stopbit.com, A technology news site}
@item @uref{http://www.worldnetla.net, WorldNet Communications - An Internet Services Provider}
@item @uref{http://www.netizen.com.au/, Netizen: Australian-based web consultancy}
@item @uref{http://www.trainingpages.co.uk, Search site for training courses in the UK}
@item @uref{http://chat.nitco.com, Gannon Chat (GPL). Written in Perl and Javascript}
@item @uref{http://www.addurls.com/,A general links directory}
@item @uref{http://www.bookmarktracker.com, A web-based bookmark management service}
@item @uref{http://www.cdrom.com,Walnut Creek CDROM}
@item @uref{http://www.wwwthreads.org/, WWWThreads; Interactive discussion Forums}
@item @uref{http://pvmon.portici.enea.it/Meteo, In Italian; Storage data from meteo station}
@item @uref{http://www.buysell.net/, Online "Person To Person" Auction}
@item @uref{http://tips.pair.com,Tips on web development}
@item @uref{http://www.mailfriends.com, Mailfriends.com is a FREE service for
everybody who wants to find friends over the internet.}
@item @uref{http://www.uninova.com/cgi-bin/wctelnets?list, Web Page Telnet BBS List}
@item @uref{http://www.uninova.com/cnc.html,UniNova Digital Postcards}
@c @item @uref{http://cabinboy.powersurfr.com, An Internet RFC search engine}
@item @uref{http://www.dslreports.com, DSL providers search with reviews}
Made with @strong{MySQL} and Modperl, all pages are generated dynamically out of
the @strong{MySQL} database
@end itemize
@appendixsec Web sites that use @code{PHP} and MySQL
@itemize @bullet
@c @item @uref{http://www.wh200th.com, White House 200th Anniversary site}
@item @uref{http://war.jgaa.com:8080/support/index.php3, Jgaa's Internet - Official Support Site}
@item @uref{http://io.incluso.com, Ionline - online publication:} @strong{MySQL},
PHP, Java, Web programming, DB development
@item @uref{http://www.baboo.com, BaBoo(Browse and bookmark). Free web-based bookmark manager and Calendar}
@item @uref{http://www.courses.pjc.cc.fl.us/Schedule/index.php, Course
Schedule System at Pensacola Junior College}
@item @uref{http://www.fccj.org, Florida Community College at Jacksonville}
@item @uref{http://www.32bit.com/, 32bit.com; An extensive shareware / freeware archive}
@item @uref{http://www.jokes2000.com/, Jokes 2000}
@c Added 990604; EMAIL: ah@dybdahl.dk
@item @uref{http://www.burken.nu/ , Burken.NU} Burken is a webhotel that
provides scripts, among other things, for remote users, like counters,
guestbooks etc.
@c Added 990608; EMAIL: spacedmp@SpaceDump.Burken.NU (Anders Olausson)
@item @uref{http://tips.pair.com, tips.pair.com} Contains tips on html,
javascript, 2d/3d graphics and PHP3/MySQL. All pages are generated from
a database.
@c Added 990614; EMAIL: downey@image.dk (Rune Madsen)
@end itemize
@appendixsec Some MySQL consultants
@itemize @bullet
@item @uref{http://www.ayni.com, Ayni AG}
@item @uref{http://worldcommunity.com/, Online Database}
@item @uref{http://www2.dataguard.no/,DataGuard (Uses @strong{MySQL} and PHP)}
@item @uref{http://wwits.net/programs/mysql.phtml, WWITS (Uses @strong{MySQL} and PHP)}
@item @uref{http://www.worldcommunity.com/, WCN - The World Community Network}
@item @uref{http://www.chipcastle.com, Chip Castle Dot Com Inc}
@c Added 990603 EMAIL: chip@chipcastle.com (Chip Castle)
@item @uref{http://www.cyber.com.au/, Cybersource Pty. Ltd}
@item @uref{http://www.spring.de, Spring infotainment gmbh & co. kg}
@c added 990905 "Oliver Pischke" <opischke@spring.de>
@item @uref{http://www.wamdesign.com/, Develops websites using MySQL}
@c Added 990905; max@wamdesign.com
@item @uref{http://www.berkeleyconsultants.com, Berkeley Consultants Group}
@end itemize
@appendixsec Programming
@itemize @bullet
@item @uref{http://www.perl.org/cpan-testers, The Perl CPAN Testers results page}
@end itemize
@appendixsec Uncategorized pages
@itemize @bullet
@item @uref{http://www.feature-showcase.com/htmls/demo_mysql.sql,
AZC.COM's Feature Showcase}
@item @uref{http://www.teach.org.uk/subjects/trainingcourse/g.html, Course Search}
@item @uref{http://www.northerbys.com, Northerbys Online Auctions}
@item @uref{http://www.schiphol.nl/flights/home.htm, Amsterdam Airport Schiphol}
@item @uref{http://TheMatrix.com/seventhsin/query.phtml, CD database}
@item @uref{http://TheMatrix.com/~flmm/GEAR.html, Used Audio Gear Database}
@item @uref{http://www.kiss.de/musik-mueller, Musical note-sheets}
@item @uref{http://www.bagism.com, Bagism - A John Lennon fan page}
@item @uref{http://www.selftaught.com/, US Folk art broker}
@item @uref{http://organizer.net/, Mail reading on the web}
@item @uref{http://www.mypage.org/, Free home pages on www.somecoolname.mypage.org}
@item @uref{http://www.schulweb.de/, Der Server f@"ur Schulen im Web (In German)}
@item @uref{http://www.ald.net/, Auldhaefen Online Services}
@item @uref{http://www.cary.net/, CaryNET Information Center}
@item @uref{http://www.dataden.com/, Dataden Computer Systems}
@item @uref{http://andree.grm.se/, Andr@'emuseet (In Swedish)}
@item @uref{http://www.him.net/, HOMESITE Internet Marketing}
@item @uref{http://www.jade-v.com/techinfo.html, Jade-V Network Services }
@item @uref{http://ww2010.atmos.uiuc.edu/(Gl)/abt/aknw/tech.rxml,
Weather World 2010 Technical Credits} @*
@item @uref{http://gimp.foebud.org/registry/doc/, About The Gimp plugin registry}
@item @uref{http://www.fast-inc.com/Products/Archiver/database.html, Java tool
Archiver technical detail (Slightly optimistic about @strong{MySQL}
ANSI-92 compliance)}
@item @uref{http://www.gamesdomain.com/cheats/usrcheat.phtml, Games Domain Cheats Database}
@item @uref{http://www.kcilink.com/poweredby/, The "Powered By" Page (Kcilink)}
@item @uref{http://www.netcasting.net/index.whtml, Netcasting}
@item @uref{http://homepages.tig.com.au/~mjj/nbltips, NBL (Australian National Basketball League) tipping}
@item @uref{http://www.cgishop.com/, CGI shop}
@item @uref{http://www.whirlycott.com/, Whirlycott: Website Design}
@item @uref{http://www.mtp.dk, Museum Tusculanum Press}
@item @uref{http://csdgi.historie.ku.dk/biblio, Centro Siciliano di Documentazione}
@item @uref{http://caribou.dyn.ml.org:8000, Quake statistics database}
@item @uref{http://www.astroforum.ch, Astroforum: Astrologie and related things (in German)}
@item @uref{http://www.opendebate.com, OpenDebate - Interactive Polls & Open Discussion}
@item @uref{http://vermeer.organik.uni-erlangen.de/dissertationen/, Online chemical dissertation server}
@item @uref{http://www.freschinfo.com, FreSch! The Free Scholarship Search Service}
@item @uref{http://www.nada.kth.se/~staffanu/pinball, Stockholm Pinball Locator}
@item @uref{http://www.hek.com, HEK A construction company}
@item @uref{http://www.nbi.nl, Elsevier Bussines Information}
@item @uref{http://vaccination.medicallink.se/, Medical Links (Using ColdFusion and @strong{MySQL})}
@item @uref{http://www.joblink-usa.com, Search for jobs & people at JobLink-USA}
@item @uref{http://www.skydive.net/competfs, Competition Formation Skydiving}
@item @uref{http://www.galaxy-net.net/Galaxy-NET Telecommunications, E-commerce and internal accounting}
@item @uref{http://www.borsen.dk/, Denmark's leading business daily newspaper B@o{}rsen}
@item @uref{http://tmmm.simplenet.com/indb/, The Internet NES Database}
@item @uref{http://www.russia.cz, Travel agency in Prague in 3 languages}
@item @uref{http://www.linkstation.de, Linkstation}
@item @uref{http://www.peoplestaff.com, Searchable online database at Peoplestaff}
@item @uref{http://www.dreamhorse.com, A searchable database system for horse classified ads}
@item @uref{http://pootpoot.com/,The Poot site}
@item @uref{http://grateful.net/hw_html/,"Playin' in the LAN"; a network monitoring suite}
@c Update from Christopher Milton <cmilton@bwn.net> 1999-12-21
@item @uref{http://www.usapa.army.mil,U.S. Army Publishing Agency}
@item @uref{http://www.nekretnine.co.yu/,Realestate handling in Yugoslavia}
@item @uref{http://demo.cpsoft.com/pims/devFAQ.html, PIMS; a Patient Information Management System}
@item @uref{http://cpsoft.com,Pilkington Software Inc}
@item @uref{http://www.no-quarter.org/,A Vietnam Veteran's Memorial (The Wall) database.}
@item @uref{http://www.gamers-union.com/,Gamer's Union specializes inauctions of used & out of print gaming material}
@item @uref{http://www.montereyhigh.com/office/dbul.php3, A daily bulletin at Monterey High school}
@item @uref{http://www.myEastside.com,Community-owned site serving Lake
Washington's Eastside residents and businesses}
@item @uref{http://bowling-france.net/,French bowling site}.
@end itemize
Send any additions to this list to @email{webmaster@@mysql.com}.
@page
@node Contrib, Credits, Users, Top
@appendix Contributed programs
Many users of @strong{MySQL} have contributed @emph{very} useful support
tools and addons.
@ifclear web
A list of what is available at @uref{http://www.mysql.com/Downloads/Contrib/}
(or any mirror) is shown below.
If you want to build @strong{MySQL} support for the Perl @code{DBI}/@code{DBD}
interface, you should fetch the @code{Data-Dumper}, @code{DBI}, and
@code{Msql-Mysql-modules} files and install them.
@xref{Perl support}.
@end ifclear
@uref{http://www.mysql.com/Downloads/Contrib/00-README, 00-README}
This listing.
@appendixsec API's
@itemize @bullet
@item Perl modules
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/Data-Dumper-2.101.tar.gz, Data-Dumper-2.101.tar.gz}
Perl @code{Data-Dumper} module. Useful with @code{DBI}/@code{DBD} support for
older perl installations.
@item @uref{http://www.mysql.com/Downloads/Contrib/DBI-1.13.tar.gz, DBI-1.13.tar.gz}
Perl @code{DBI} module.
@item @uref{http://www.mysql.com/Downloads/Contrib/KAMXbase1.0.tar.gz,KAMXbase1.0.tar.gz}
Convert between @file{.dbf} files and @strong{MySQL} tables. Perl
module written by Pratap Pereira @email{pereira@@ee.eng.ohio-state.edu},
extened by Kevin A. McGrail @email{kmcgrail@@digital1.peregrinehw.com}.
This converter can handle MEMO fields.
@item @uref{http://www.mysql.com/Downloads/Contrib/Msql-Mysql-modules-1.2214.tar.gz, Msql-Mysql-modules-1.2214.tar.gz}
Perl @code{DBD} module to access mSQL and @strong{MySQL} databases..
@item @uref{http://www.mysql.com/Downloads/Contrib/Data-ShowTable-3.3.tar.gz, Data-ShowTable-3.3.tar.gz}
Perl @code{Data-ShowTable} module. Useful with @code{DBI}/@code{DBD} support.
@end itemize
@item JDBC
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mm.mysql.jdbc-1.2c.tar.gz, mm.mysql.jdbc-1.2c.tar.gz}
The mm JDBC driver for @strong{MySQL}. This is a production release
and is actively developed. By Mark Matthews
(@email{mmatthew@@ecn.purdue.edu}).
@item @uref{http://www.mysql.com/Downloads/Contrib/mm.mysql.jdbc-2.0pre5.tar.gz, mm.mysql.jdbc-2.0pre5.tar.gz}
The mm JDBC driver for @strong{MySQL}. This is a pre-release beta version
and is actively developed. By Mark Matthews
(@email{mmatthew@@ecn.purdue.edu}).
The two drivers above have an LGPL
license. Please check @uref{http://www.worldserver.com/mm.mysql/} for
the latest drivers (and other JDBC information) because these drivers may be out of date.
@item @uref{http://www.mysql.com/Downloads/Contrib/twz1jdbcForMysql-1.0.4-GA.tar.gz, twz1jdbcForMysql-1.0.4-GA.tar.gz}
The twz driver: A type 4 JDBC driver by Terrence W. Zellers
@email{zellert@@voicenet.com}. This is commercial but is free for
private and educational use.
@c no answer from server 990830
@c You can always find the latest driver at @uref{http://www.voicenet.com/~zellert/tjFM/}.
@item
@item @uref{http://www.mysql.com/Downloads/Contrib/pmdamysql.tgz,pmdamysql.tgz}
A @strong{MySQL} PMDA. Provides @strong{MySQL} server status and configuration
variables.
@end itemize
@item C++
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-c++-0.02.tar.gz, mysql-c++-0.02.tar.gz}
@strong{MySQL} C++ wrapper library. By Roland Haenel,
@email{rh@@ginster.net}.
@item @uref{http://www.mysql.com/Downloads/Contrib/MyDAO.tar.gz, MyDAO}
@strong{MySQL} C++ API. By Satish @email{spitfire@@pn3.vsnl.net.in}. Inspired
by Roland Haenel's C++ API and Ed Carp's MyC library.
@item @uref{http://www.mysql.com/download_mysql++.html, mysql++}
@strong{MySQL} C++ API (More than just a wrapper library). Originally by
@email{kevina@@clark.net}. Nowadays maintained by Sinisa at MySQL AB.
@item @uref{http://nelsonjr.homepage.com/NJrAPI,NJrAPI}
A C++ database independent library that supports @strong{MySQL}.
@end itemize
@item Delphi
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/delphi-interface.gz, delphi-interface.gz}
Delphi interface to @code{libmysql.dll}, by Blestan Tabakov,
@email{root@@tdg.bis.bg}.
@item @uref{http://www.mysql.com/Downloads/Contrib/DelphiMySQL2.zip, DelphiMySQL2.zip}
Delphi interface to @code{libmysql.dll}, by @email{bsilva@@umesd.k12.or.us}
@item @uref{http://www.mysql.com/Downloads/Contrib/Udmysel.pas, Udmysql.pas}
A wrapper for libmysql.dll for usage in Delphi. By Reiner Sombrowsky.
@item @uref{http://www.fichtner.net/delphi/mysql.delphi.phtml, A Delphi interface to @strong{MySQL}.}
With source code. By Matthias Fichtner.
@item @uref{http://www.productivity.org/projects/mysql/, @strong{TmySQL}
A library to use @strong{MySQL} with Delphi}
@item @uref{http://www.geocities.com/CapeCanaveral/2064/mysql.html, Delphi TDataset-component}
@end itemize
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-ruby-2.2.0.tar.gz, mysql-ruby-2.2.0.tar.gz}
@strong{MySQL} Ruby module. By TOMITA Masahiro @email{tommy@@tmtm.org}
@uref{http://www.netlab.co.jp/ruby/,Ruby} is an Object-Oriented Interpreter Language.
@item @uref{http://www.mysql.com/Downloads/Contrib/JdmMysqlDriver-0.1.0.tar.gz,JdmMysqlDriver-0.1.0.tar.gz}
A VisualWorks 3.0 Smalltalk driver for @strong{MySQL}. By
@email{joshmiller@@earthlink.net}
@item @uref{http://www.mysql.com/Downloads/Contrib/Db.py, Db.py}
Python module with caching. By @email{gandalf@@rosmail.com}.
@item @uref{http://www.mysql.com/Downloads/Contrib/MySQLmodule-1.4.tar.gz, MySQLmodule-1.4.tar.gz}
Python interface for @strong{MySQL}. By Joseph Skinner @email{joe@@earthlight.co.nz}; Modified by Joerg Senekowitsch @email{senekow@@ibm.net}
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql_mex_1_1.tar.gz, mysql_mex_1_1.tar.gz}
An interface program for the Matlab program by MathWorks. The interface
is done by Kimmo Uutela and John Fisher (not by Mathworks).
Check @uref{http://boojum.hut.fi/~kuutela/mysqlmex.html,mysqlmex.html}
for more information.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqltcl-1.53.tar.gz, mysqltcl-1.53.tar.gz}
Tcl interface for @strong{MySQL}. Based on @file{msqltcl-1.50.tar.gz}.
Updated by Tobias Ritzau, @email{tobri@@ida.liu.se}.
@item @uref{http://www.mysql.com/Downloads/Contrib/MyC-0.1.tar.gz, MyC-0.1.tar.gz}
A Visual Basic-like API, by Ed Carp.
@item @uref{http://www.mysql.com/Downloads/Contrib/sqlscreens-1.0.1.tar.gz, sqlscreens-1.0.1.tar.gz}
Tcl/Tk code to generate database screens. By Jean-Francois Dockes.
@item @uref{http://www.mysql.com/Downloads/Contrib/Vdb-dflts-2.1.tar.gz, Vdb-dflts-2.1.tar.gz}
This is a new version of a set of library utilities intended
to provide a generic interface to SQL database engines such that your
application becomes a 3-tiered application. The advantage is that you
can easily switch between and move to other database engines by
implementing one file for the new backend without needing to make any
changes to your applications. By @email{damian@@cablenet.net}.
@item @uref{http://www.mysql.com/Downloads/Contrib/DbFramework-1.10.tar.gz, DbFramework-1.10.tar.gz}
DbFramework is a collection of classes for manipulating @strong{MySQL}
databases. The classes are loosely based on the CDIF Data Model
Subject Area. By Paul Sharpe @email{paul@@miraclefish.com}.
@item @uref{http://www.mysql.com/Downloads/Contrib/pike-mysql-1.4.tar.gz, pike-mysql-1.4.tar.gz}
@strong{MySQL} module for pike. For use with the Roxen web server.
@item @uref{http://www.mysql.com/Downloads/Contrib/squile.tar.gz, squile.tar.gz}
Module for @code{guile} that allows @code{guile} to interact with SQL
databases. By Hal Roberts.
@item @uref{http://www.mysql.com/Downloads/Contrib/stk-mysql.tar.gz, stk-mysql.tar.gz}
Interface for Stk. Stk is the Tk widgets with Scheme underneath instead of Tcl.
By Terry Jones
@item @uref{http://www.mysql.com/Downloads/Contrib/eiffel-wrapper-1.0.tar.gz,eiffel-wrapper-1.0.tar.gz}.
Eiffel wrapper by Michael Ravits.
@end itemize
@appendixsec Clients
@itemize @bullet
@item Graphical clients
@itemize @bullet
@item @uref{http://www.mysql.com/download_clients.html, mysqlgui homepage}
The @strong{MySQL} GUI client homepage. By Sinisa at MySQL AB.
@item @uref{http://www.mysql.com/Downloads/Contrib/kmysqladmin-0.4.1.tar.gz, kmysqladmin-0.4.1.tar.gz}
@item @uref{http://www.mysql.com/Downloads/Contrib/kmysqladmin-0.4.1-1.src.rpm, kmysqladmin-0.4.1-1.src.rpm}
@item @uref{http://www.mysql.com/Downloads/Contrib/kmysqladmin-0.4.1-1.i386.rpm, kmysqladmin-0.4.1-1.i386.rpm}
An administration tool for the @strong{MySQL} server using QT / KDE. Tested
only on Linux.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-admin-using-java+swing.tar.gz, Java client
using Swing} By Fredy Fischer, @email{se-afs@@dial.eunet.ch}. You can
always find the latest version
@uref{http://www.trash.net/~ffischer/admin/index.html, here}.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqlwinadmn.zip, mysqlwinadmn.zip}
Win32 GUI (binary only) to administrate a database, by David B. Mansel,
@email{david@@zhadum.org}.
@item @uref{http://www.mysql.com/Downloads/Contrib/netadmin.zip, netadmin.zip}
An administrator tool for @strong{MySQL} on Windows 95/98 and Windows NT
4.0. Only tested with @strong{MySQL} 3.23.5 - 3.23.7. Written using the
Tmysql components.
You can write queries and show tables, indexes, table syntax and
administrate user,host and database and so on. The is still beta and
have still some bugs. you can test the program with all features. Please
send bugs and hints to Marco Suess @email{ms@@it-netservice.de}. Original
URL @url{http://www.it-netservice.de/pages/software/index.html}.
@item @uref{http://www.mysql.com/Downloads/Win32/admin13.exe,Atronic's @strong{MySQL} client for Win32 1.3.0.0} and @uref{http://www.mysql.com/Downloads/Win32/admin13.readme,Atronic's @strong{MySQL} client readme}.
Home page for this can be found at: @uref{http://www.artronic.hr}.
@item @uref{http://www.mysql.com/Downloads/Win32/W9xstop.zip,Utility from Artronic to stop MySQL on win9x}
@item @uref{http://www.mysql.com/Downloads/Contrib/xmysqladmin-1.0.tar.gz, xmysqladmin-1.0.tar.gz}
An X based front end to the @strong{MySQL} database engine. It allows reloads,
status check, process control, myisamchk, grant/revoke privileges,
creating databases, dropping databases, create, alter, browse and drop
tables. Originally by Gilbert Therrien, @email{gilbert@@ican.net} but
now in public domain and supported by MySQL AB.
@item @uref{http://www.mysql.com/Downloads/Contrib/xmysql-1.9.tar.gz, xmysql-1.9.tar.gz}
@item @uref{http://web.wt.net/~dblhack, xmysql home page}
A front end to the @strong{MySQL} database engine. It allows for simple
queries and table maintenance, as well as batch queries. By Rick
Mehalick, @email{dblhack@@wt.net}.
Requires @uref{http://bragg.phys.uwm.edu/xforms,xforms 0.88} to work.
@item @uref{http://www.tamos.net/sw/dbMetrix,dbMetrix}
An open source client for exploring databases and executing SQL. Supports
@strong{MySQL}, Oracle, PostgreSQL and mSQL.
@item @uref{http://www.multimania.com/bbrox/GtkSQL,GtkSQL}
A query tool for @strong{MySQL} and PostgreSQL.
@item @uref{http://dbman.linux.cz/,dbMan}
A query tool written in Perl. Uses DBI and Tk.
@item @uref{http://www.mysql.com/Downloads/Contrib/mascon1.exe, mascon1.exe}
You can get the newest one from
@uref{http://www.SciBit.com,http://www.SciBit.com}.
@item @uref{http://www.virtualbeer.net/dbui/,DBUI}
DBUI is a Gtk graphical database editor.
@end itemize
@item Web clients
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqladmin-atif-1.0.tar.gz, mysqladmin-atif-1.0.tar.gz}
WWW @strong{MySQL} administrator for the @code{user,} @code{db} and
@code{host} tables. By Tim Sailer, modified by Atif Ghaffar
@email{aghaffar@@artemedia.ch}.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-webadmin-1.0a8-rz.tar.gz, mysql-webadmin-1.0a8-rz.tar.gz}
A tool written in PHP-FI to administrate @strong{MySQL} databases
remotely over the web within a Web-Browser. By Peter Kuppelwieser,
@email{peter.kuppelwieser@@kantea.it}. Updated by Wim Bonis,
@email{bonis@@kiss.de}. Not maintained anymore!
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqladm.tar.gz, mysqladm.tar.gz}
@strong{MySQL} Web Database Administration written in Perl. By Tim Sailer.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqladm-2.tar.gz, mysqladm-2.tar.gz}
Updated version of @file{mysqladm.tar.gz}, by High Tide.
@item @uref{http://www.mysql.com/Downloads/Contrib/billowmysql.zip, billowmysql.zip}
Updated version of @file{mysqladm.tar.gz}, by Ying Gao. You can get the
newest version from @uref{http://civeng.com/sqldemo/, the home site}.
@item @uref{http://www.mysql.com/Downloads/Contrib/myadmin-0.4.tar.gz, myadmin-0.4.tar.gz}
@item @uref{http://myadmin.cheapnet.net/, MyAdmin home page}
A web based mysql administrator by Mike Machado.
@item @uref{http://www.mysql.com/Downloads/Contrib/phpMyAdmin_2.0.1.tar.gz,phpMyAdmin_2.0.1.tar.gz}
A set of PHP3-scripts to adminstrate @strong{MySQL} over the WWW.
@item @uref{http://www.htmlwizard.net/phpMyAdmin/, phpMyAdmin home page}
A PHP3 tool in the spirit of mysql-webadmin, by Tobias Ratschiller, tobias@@dnet.it
@item @uref{http://www.mysql.com/Downloads/Contrib/useradm.tar.gz, useradm.tar.gz}
@strong{MySQL} administrator in PHP. By Ofni Thomas
@email{othomas@@vaidsystems.com}.
@end itemize
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-editor.tar.gz,mysql-editor.tar.gz}
This cgi scripts in Perl enables you to edit content of Mysql
database. By Tomas Zeman.
@item
@uref{http://futurerealm.com/opensource/futuresql.htm, FutureSQL Web Database Administration Tool}.
FutureSQL by Peter F. Brown, is a Free, Open Source Rapid Application
Development web database administration tool, written in Perl,
using @strong{MySQL}. It uses @code{DBI:DBD} and @code{CGI.pm}.
FutureSQL allows one to easily setup config files to view, edit, delete
and otherwise process records from a @strong{MySQL} database. It uses a data
dictionary, configuration files and templates, and allows "pre-processing"
and "post-processing" on both fields, records and operations.
@end itemize
@appendixsec Web tools
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mod_mysql_include_1.0.tar.gz, mod_mysql_include_1.0.tar.gz}
Apache module to include HTML from MySQL queries into your pages, and run update queries.
Originally written to implement a simple fast low-overhead banner-rotation system.
By Sasha Pachev.
@item @uref{http://www.odbsoft.com/cook/sources.htm}
This package has various functions for generating html code from a SQL
table structure and for generating SQL statements (Select, Insert,
Update, Delete) from an html form. You can build a complete forms
interface to a SQL database (query, add, update, delete) without any
programming! By Marc Beneteau, @email{marc@@odbsoft.com}.
@item @uref{http://www.mysql.com/Downloads/Contrib/sqlhtml.tar.gz, sqlhtml.tar.gz}
SQL/HTML is an HTML database manager for @strong{MySQL} using @code{DBI} 1.06.
@item @uref{http://www.mysql.com/Downloads/Contrib/udmsearch-2.2.1b.tar.gz, UdmSearch 2.2.1b (stable version)}
@item @uref{http://www.mysql.com/Downloads/Contrib/udmsearch-3.0.5.tar.gz, UdmSearch 3.0.5 (development version)}
@item @uref{http://mysearch.udm.net, UdmSearch home page}
A @strong{MySQL}- and PHP- based search engine over HTTP. By
Alexander I. Barkov @email{bar@@izhcom.ru}.
@item @uref{http://www.mysql.com/Downloads/Contrib/wmtcl.doc, wmtcl.doc}
@item @uref{http://www.mysql.com/Downloads/Contrib/wmtcl.lex, wmtcl.lex}
With this you can write HTML files with inclusions of Tcl code. By
@email{vvs@@scil.npi.msu.su}.
@item @uref{http://www.mysql.com/Downloads/Contrib/www-sql-0.5.7.lsm, www-sql-0.5.7.lsm}
@item @uref{http://www.mysql.com/Downloads/Contrib/www-sql-0.5.7.tar.gz, www-sql-0.5.7.tar.gz}
A CGI program that parses an HTML file containing special tags, parses
them and inserts data from a @strong{MySQL} database.
@item @uref{http://www.mysql.com/Downloads/Contrib/genquery.zip, genquery.zip}
Perl SQL database interface package for html.
@item @uref{http://www.mysql.com/Downloads/Contrib/cgi++-0.8.tar.gz, cgi++-0.8.tar.gz}
A macro-processor to simply writing CGI/Database programs in C++ by Sasha Pachev.
@item @uref{http://www.mysql.com/Downloads/Contrib/webboard-1.0.zip, WebBoard 1.0}
EU-Industries Internet-Message-Board.
@item @uref{http://www.mysql.com/Downloads/Contrib/DBIx-TextIndex-0.02.tar.gz, DBIx-TextIndex-0.02.tar.gz}
Full-text searching with Perl on @code{BLOB}/@code{TEXT} columns by Daniel Koch.
@end itemize
@appendixsec Performance Benchmarking tools
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-bench-0.6.tar.gz, mysql-super-smack and friends}
User-customizable multi-threaded tool set to benchmark @strong{MySQL}. By Sasha Pachev.
@end itemize
@appendixsec Authentication tools
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/ascend-radius-mysql-0.7.1.patch.gz,
ascend-radius-mysql-0.7.1.patch.gz}
This is authentication and logging patch using @strong{MySQL} for
Ascend-Radius. By @email{takeshi@@SoftAgency.co.jp}.
@item @uref{http://www.mysql.com/Downloads/Contrib/icradius-0.10.tar.gz, icradius 0.10}
@uref{http://www.mysql.com/Downloads/Contrib/icradius.README, icradius readme file}
@item @uref{http://www.mysql.com/Downloads/Contrib/checkpassword-0.81-mysql-0.6.5.patch.gz,
checkpassword-0.81-mysql-0.6.5.patch.gz}
@strong{MySQL} authentication patch for QMAIL and checkpassword. These are
useful for management user(mail,pop account) by @strong{MySQL}.
By @email{takeshi@@SoftAgency.co.jp}
@item @uref{http://www.mysql.com/Downloads/Contrib/jradius-diff.gz, jradius-diff.gz}
@strong{MySQL} support for Livingston's Radius 2.01. Authentication and
Accounting. By Jose de Leon, @email{jdl@@thevision.net}
@item @uref{http://www.mysql.com/Downloads/Contrib/mod_auth_mysql-2.20.tar.gz, mod_auth_mysql-2.20.tar.gz}
Apache authentication module for @strong{MySQL}. By Zeev Suraski,
@email{bourbon@@netvision.net.il}.
@strong{Please} register this module at:
@url{http://bourbon.netvision.net.il/mysql/mod_auth_mysql/register.html}. The
registering information is only used for statistical purposes and will
encourage further development of this module!
@item @uref{http://www.mysql.com/Downloads/Contrib/mod_log_mysql-1.05.tar.gz, mod_log_mysql-1.05.tar.gz}
@strong{MySQL} logging module for Apache. By Zeev Suraski,
@email{bourbon@@netvision.net.il}.
@item @uref{http://www.mysql.com/Downloads/Contrib/mypasswd-2.0.tar.gz, mypasswd-2.0.tar.gz}
Extra for @code{mod_auth_mysql}. This is a little tool that allows you
to add/change user records storing group and/or password entries in
@strong{MySQL} tables. By Harry Brueckner, @email{brueckner@@respublica.de}.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-passwd.README, mysql-passwd.README}
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql-passwd-1.2.tar.gz, mysql-passwd-1.2.tar.gz}
Extra for @code{mod_auth_mysql}. This is a two-part system for use with
@code{mod_auth_mysql}.
@item @uref{http://www.mysql.com/Downloads/Contrib/pam_mysql.tar.gz, pam_mysql.tar.gz}
This module authenticates users via @code{pam}, using @strong{MySQL}.
@item @uref{http://www.mysql.com/Downloads/Contrib/nsapi_auth_mysql.tar, nsapi_auth_mysql.tar}
Netscape Web Server API (NSAPI) functions to authenticate (BASIC) users
against @strong{MySQL} tables. By Yuan John Jiang.
@item @uref{http://www.mysql.com/Downloads/Contrib/qmail-1.03-mysql-0.6.5.patch.gz,
qmail-1.03-mysql-0.6.5.patch.gz}
Patch for qmail to authenticate users from a @strong{MySQL} table.
@item @uref{http://www.mysql.com/Downloads/Contrib/pwcheck_mysql-0.1.tar.gz,pwcheck_mysql-0.1.tar.gz}
An authentication module for the Cyrus IMAP server. By Aaron Newsome.
@end itemize
@appendixsec Converters
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/dbf2mysql-1.14.tgz, dbf2mysql-1.14.tgz}
Convert between @file{.dbf} files and @strong{MySQL} tables. By Maarten
Boekhold, @email{boekhold@@cindy.et.tudelft.nl}, William Volkman and
Michael Widenius. This converter includes rudementary read-only support
for MEMO fields.
@item @uref{http://www.mysql.com/Downloads/Contrib/dbf2mysql-1.13.tgz, dbf2mysql-1.13.tgz}
Convert between @file{.dbf} files and @strong{MySQL} tables. By Maarten
Boekhold, @email{boekhold@@cindy.et.tudelft.nl}, and Michael Widenius.
This converter can't handle MEMO fields.
@item @uref{http://www.mysql.com/Downloads/Contrib/dbf2mysql.zip, dbf2mysql.zip}
Convert between FoxPro @file{.dbf} files and @strong{MySQL} tables on Win32.
By Alexander Eltsyn, @email{ae@@nica.ru} or @email{ae@@usa.net}.
@item @uref{http://www.mysql.com/Downloads/Contrib/dump2h-1.20.gz, dump2h-1.20.gz}
Convert from @code{mysqldump} output to a C header file. By Harry Brueckner,
@email{brueckner@@mail.respublica.de}.
@item @uref{http://www.mysql.com/Downloads/Contrib/exportsql.txt, exportsql.txt}
A script that is similar to @code{access_to_mysql.txt}, except that this
one is fully configurable, has better type conversion (including
detection of @code{TIMESTAMP} fields), provides warnings and suggestions
while converting, quotes @strong{all} special characters in text and
binary data, and so on. It will also convert to @code{mSQL} v1 and v2,
and is free of charge for anyone. See
@uref{http://www.cynergi.net/prod/exportsql/} for latest version. By
Pedro Freire, @email{support@@cynergi.net}. Note: Doesn't work with
Access2!
@item @uref{http://www.mysql.com/Downloads/Contrib/access_to_mysql.txt, access_to_mysql.txt}
Paste this function into an Access module of a database which has the
tables you want to export. See also @code{exportsql}. By Brian Andrews.
Note: Doesn't work with Access2!
@item @uref{http://www.mysql.com/Downloads/Contrib/importsql.txt, importsql.txt}
A script that does the exact reverse of @code{exportsql.txt}. That is,
it imports data from @strong{MySQL} into an Access database via
ODBC. This is very handy when combined with exportsql, because it lets you
use Access for all DB design and administration, and synchronize with
your actual @strong{MySQL} server either way. Free of charge. See
@uref{http://www.netdive.com/freebies/importsql/} for any updates.
Created by Laurent Bossavit of NetDIVE.
@strong{Note:} Doesn't work with Access2!
@item @uref{http://www.mysql.com/Downloads/Contrib/msql2mysqlWrapper-1.0.tgz, /msql2mysqlWrapper 1.0}
A C wrapper from @code{mSQL} to @strong{MySQL}. By @email{alfred@@sb.net}
@item @uref{http://www.mysql.com/Downloads/Contrib/sqlconv.pl, sqlconv.pl}
A simple script that can be used to copy fields from one @strong{MySQL} table to
another in bulk. Basically, you can run @code{mysqldump} and pipe it to
the @code{sqlconv.pl} script and the script will parse through the
@code{mysqldump} output and will rearrange the fields so they can be
inserted into a new table. An example is when you want to create a new
table for a different site you are working on, but the table is just a
bit different (ie - fields in different order, etc.).
By Steve Shreeve.
@end itemize
@appendixsec Using MySQL with other products
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/emacs-sql-mode.tar.gz, emacs-sql-mode.tar.gz}
Raw port of a SQL mode for XEmacs. Supports completion. Original by
Peter D. Pezaris @email{pez@@atlantic2.sbi.com} and partial
@strong{MySQL} port by David Axmark.
@item @uref{http://www.mysql.com/Downloads/Win32/MyAccess97_Ver_1_01.zip, MyAccess97 1.01}
MyAccess is an AddIn for Access 97 and handles a lot of maintanance work
for @strong{MySQL} databases.
@item @uref{http://www.mysql.com/Downloads/Win32/MyAccess2000_Ver_1_01.zip, MyAccess2000 1.01}
MyAccess is an AddIn for Access 2000 and handles a lot of maintanance work
for @strong{MySQL} databases.
@uref{http://www.mysql.com/Downloads/Win32/MyAccess-1.01.readme,
MyAccess-readme}. By Hubertus Hiden.
@item @uref{http://www.mysql.com/Downloads/Contrib/radius-0.3.tar.gz, radius-0.3.tar.gz}
Patches for @code{radiusd} to make it support @strong{MySQL}. By Wim Bonis,
@email{bonis@@kiss.de}.
@end itemize
@appendixsec Useful tools
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql_watchdog.pl, mysql_watchdog.pl}
Monitor the @strong{MySQL} daemon for possible lockups. By Yermo Lamers,
@email{yml@@yml.com}.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqltop.tar.gz, mysqltop.tar.gz}
Sends a query in a fixed time interval to the server and shows the
resulting table. By Thomas Wana.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql_structure_dumper.tar.gz,mysql_structure_dumper.tar.gz}
Prints out the structure of the all tables in a database. By Thomas Wana.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql_structure_dumper.tgz, structure_dumper.tgz}
Prints the structure of every table in a database. By Thomas Wana.
@item @uref{http://www.mysql.com/Downloads/Contrib/mysqlsync, mysqlsync-1.0-alpha.tar.gz}.
A perl script to keep remote copies of a @strong{MySQL} database in sync with a
central master copy. By Mark Jeftovic. @email{markjr@@easydns.com}
@item @uref{http://www.mysql.com/Downloads/Contrib/MySQLTutor-0.2.tar.gz, MySQLTutor}.
MySQLTutor. A tutor of @strong{MySQL} for beginners
@item @uref{http://www.mysql.com/Downloads/Contrib/MySQLDB.zip, MySQLDB.zip}
A COM library for @strong{MySQL} by Alok Singh.
@item @uref{http://www.mysql.com/Downloads/Contrib/MySQLDB-readme.html, MySQLDB-readme.html}
@item @uref{http://www.mysql.com/Downloads/Contrib/mysql_replicate.pl, mysql_replicate.pl}
Perl program that handles replication. By @email{elble@@icculus.nsg.nwu.edu}
@item @uref{http://www.mysql.com/Downloads/Contrib/DBIx-TextIndex-0.02.tar.gz, DBIx-TextIndex-0.02.tar.gz}
Perl script that uses reverse indexing to handle text searching.
By Daniel Koch.
@item @uref{http://www.mysql.com/Downloads/Contrib/dbcheck, dbcheck}
Perl script that takes a backup of a tables before running isamchk on them.
By Elizabeth.
@end itemize
@appendixsec RPMs for common tools (Most are for RedHat 6.1)
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/perl-Data-ShowTable-3.3-2.i386.rpm,perl-Data-ShowTable-3.3-2.i386.rpm}
@item @uref{http://www.mysql.com/Downloads/Contrib/perl-Msql-Mysql-modules-1.2210-2.i386.rpm,perl-Msql-Mysql-modules-1.2210-2.i386.rpm}
@item @uref{http://www.mysql.com/Downloads/Contrib/php-pg-3.0.13-1.i386.rpm,php-pg-3.0.13-1.i386.rpm}
@item @uref{http://www.mysql.com/Downloads/Contrib/php-pg-manual-3.0.13-1.i386.rpm,php-pg-manual-3.0.13-1.i386.rpm}
@item @uref{http://www.mysql.com/Downloads/Contrib/php-pg-mysql-3.0.13-1.i386.rpm,php-pg-mysql-3.0.13-1.i386.rpm}
@item @uref{http://www.mysql.com/Downloads/Contrib/phpMyAdmin-2.0.5-1.noarch.rpm,phpMyAdmin-2.0.5-1.noarch.rpm}
@end itemize
@appendixsec Useful functions
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/mysnprintf.c,mysnprintf.c}
sprintf() function for SQL queries that can escape blobs. By Chunhua Liu.
@end itemize
@appendixsec Uncategorized
@itemize @bullet
@item @uref{http://www.mysql.com/Downloads/Contrib/findres.pl, findres.pl}
Find reserved words in tables. By Nem W Schlecht.
@item @uref{http://www.mysql.com/Downloads/Contrib/handicap.tar.gz, handicap.tar.gz}
Performance handicapping system for yachts. Uses PHP. By
@email{rhill@@stobyn.ml.org}.
@item @uref{http://www.mysql.com/Downloads/Contrib/hylalog-1.0.tar.gz, hylalog-1.0.tar.gz}
Store @code{hylafax} outgoing faxes in a @strong{MySQL} database. By Sinisa
Milivojevic, @email{sinisa@@mysql.com}.
@item @uref{http://www.mysql.com/Downloads/Contrib/mrtg-mysql-1.0.tar.gz, mrtg-mysql-1.0.tar.gz}
@strong{MySQL} status plotting with MRTG, by Luuk de Boer, @email{luuk@@wxs.nl}.
@item @uref{http://www.mysql.com/Downloads/Contrib/wuftpd-2.4.2.18-mysql_support.2.tar.gz, wuftpd-2.4.2.18-mysql_support.2.tar.gz}
Patches to add logging to @strong{MySQL} for WU-ftpd. By Zeev Suraski,
@email{bourbon@@netvision.net.il}.
@item @uref{http://www.mysql.com/Downloads/Contrib/wu-ftpd-2.6.0-mysql.4.tar.gz,wu-ftpd-2.6.0-mysql.4.tar.gz}
Patches to add logging to @strong{MySQL} for WU-ftpd 2.6.0. By,
@email{takeshi@@SoftAgency.co.jp}, based on Zeev Suraski wuftpd patches.
@item @uref{http://www.mysql.com/Downloads/Contrib/Old-Versions, Old-Versions}
Previous versions of things found here that you probably won't be
interested in.
@end itemize
@page
@node Credits, News, Contrib, Top
@appendix Contributors to MySQL
Contributors to the @strong{MySQL} distribution are listed below, in
somewhat random order:
@table @asis
@item Michael (Monty) Widenius
Has written the following parts of @strong{MySQL}:
@itemize @bullet
@item
All the main code in @code{mysqld}.
@item
New functions for the string library.
@item
Most of the @code{mysys} library.
@item
The @code{ISAM} and @code{MyISAM} libraries (B-tree index file
handlers with index compression and different record formats).
@item
The @code{HEAP} library. A memory table system with our superior full dynamic
hashing. In use since 1981 and published around 1984.
@item
The @code{replace} program (look into it, it's COOL!).
@item
@strong{MyODBC}, the ODBC driver for Windows95.
@item
Fixing bugs in MIT-pthreads to get it to work for @strong{MySQL}. And
also Unireg, a curses-based application tool with many utilities.
@item
Porting of @code{mSQL} tools like @code{msqlperl}, @code{DBD}/@code{DBI} and
@code{DB2mysql}.
@item
Most parts of crash-me and the @strong{MySQL} benchmarks.
@end itemize
@item David Axmark
@itemize @bullet
@item
Coordinator and main writer for the @strong{Reference Manual}, including
enhancements to @code{texi2html}. Also automatic website updating from
this manual.
@item
Autoconf, Automake and @code{libtool} support.
@item
The licensing stuff.
@item
Parts of all the text files. (Nowadays only the @file{README} is
left. The rest ended up in the manual.)
@item
Our Mail master.
@item
Lots of testing of new features.
@item
Our in-house ``free'' software lawyer.
@item
Mailing list maintainer (who never has the time to do it right...)
@item
Our original portability code (more than 10 years old now). Nowadays
only some parts of @code{mysys} are left.
@item
Someone for Monty to call in the middle of the night when he just got
that new feature to work. :-)
@end itemize
@item Paul DuBois
Help with making the Reference Manual correct and understandable. That
includes rewriting Monty's and David's attempts at English into English
as other people know it.
@item Gianmassimo Vigazzola @email{qwerg@@mbox.vol.it} or @email{qwerg@@tin.it}
The initial port to Win32/NT.
@item Kim Aldale
Helped to rewrite Monty's and David's early attempts at English into
English.
@item Allan Larsson (The BOSS for TCX DataKonsult AB)
For all the time he has allowed Monty to spend on this ``maybe useful''
tool (@strong{MySQL}). Dedicated user (and bug finder) of Unireg &
@strong{MySQL}.
@item Per Eric Olsson
For more or less constructive criticism and real testing of the dynamic
record format.
@item Irena Pancirov @email{irena@@mail.yacc.it}
Win32 port with Borland compiler. @code{mysqlshutdown.exe} and
@code{mysqlwatch.exe}
@item David J. Hughes
For the effort to make a shareware SQL database. We at TcX started with
@code{mSQL}, but found that it couldn't satisfy our purposes so instead we
wrote a SQL interface to our application builder Unireg. @code{mysqladmin}
and @code{mysql} are programs that were largely influenced by their
@code{mSQL} counterparts. We have put a lot of effort into making the
@strong{MySQL} syntax a superset of @code{mSQL}. Many of the APIs ideas are
borrowed from @code{mSQL} to make it easy to port free @code{mSQL} programs
to @strong{MySQL}. @strong{MySQL} doesn't contain any code from @code{mSQL}.
Two files in the distribution (@file{client/insert_test.c} and
@file{client/select_test.c}) are based on the corresponding (non-copyrighted)
files in the @code{mSQL} distribution, but are modified as examples showing
the changes necessary to convert code from @code{mSQL} to @strong{MySQL}.
(@code{mSQL} is copyrighted David J. Hughes.)
@item Fred Fish
For his excellent C debugging and trace library. Monty has made a number
of smaller improvements to the library (speed and additional options).
@item Richard A. O'Keefe
For his public domain string library.
@item Henry Spencer
For his regex library, used in @code{WHERE column REGEXP regexp}.
@item Free Software Foundation
From whom we got an excellent compiler (@code{gcc}), the @code{libc} library
(from which we have borrowed @file{strto.c} to get some code working in Linux)
and the @code{readline} library (for the @code{mysql} client).
@item Free Software Foundation & The XEmacs development team
For a really great editor/environment used by almost everybody at
TcX/MySQL AB/detron.
@item Patrick Lynch
For helping us acquire @code{http://www.mysql.com/}.
@item Fred Lindberg
For setting up qmail to handle @strong{MySQL} mailing list and for the
incredible help we got in managing the @strong{MySQL} mailing lists.
@item Igor Romanenko @email{igor@@frog.kiev.ua}
@code{mysqldump} (previously @code{msqldump}, but ported and enhanced by
Monty).
@item Tim Bunce, Alligator Descartes
For the @code{DBD} (Perl) interface.
@item Andreas Koenig @email{a.koenig@@mind.de}
For the Perl interface to @strong{MySQL}.
@item Eugene Chan @email{eugene@@acenet.com.sg}
For porting PHP to @strong{MySQL}.
@item Michael J. Miller Jr. @email{mke@@terrapin.turbolift.com}
For the first @strong{MySQL} manual. And a lot of spelling/language
fixes for the FAQ (that turned into the @strong{MySQL} manual a long
time ago).
@item Giovanni Maruzzelli @email{maruzz@@matrice.it}
For porting iODBC (Unix ODBC).
@item Chris Provenzano
Portable user level pthreads. From the copyright: This product includes
software developed by Chris Provenzano, the University of California,
Berkeley, and contributors. We are currently using version 1_60_beta6
patched by Monty (see @file{mit-pthreads/Changes-mysql}).
@item Xavier Leroy @email{Xavier.Leroy@@inria.fr}
The author of LinuxThreads (used by @strong{MySQL} on Linux).
@item Zarko Mocnik @email{zarko.mocnik@@dem.si}
Sorting for Slovenian language and the @file{cset.tar.gz} module that makes
it easier to add other character sets.
@item "TAMITO" @email{tommy@@valley.ne.jp}
The @code{_MB} character set macros and the ujis and sjis character sets.
@item Joshua Chamas @email{joshua@@chamas.com}
Base for concurrent insert, extended date syntax, debugging on NT and
answering on the @strong{MySQL} mailing list.
@item Yves Carlier @email{Yves.Carlier@@rug.ac.be}
@code{mysqlaccess}, a program to show the access rights for a user.
@item Rhys Jones @email{rhys@@wales.com} (And GWE Technologies Limited)
For the JDBC, a module to extract data from @strong{MySQL} with a Java
client.
@item Dr Xiaokun Kelvin ZHU @email{X.Zhu@@brad.ac.uk}
Further development of the JDBC driver and other @strong{MySQL}-related
Java tools.
@item James Cooper @email{pixel@@organic.com}
For setting up a searchable mailing list archive at his site.
@item Rick Mehalick @email{Rick_Mehalick@@i-o.com}
For @code{xmysql}, a graphical X client for @strong{MySQL}.
@item Doug Sisk @email{sisk@@wix.com}
For providing RPM packages of @strong{MySQL} for RedHat Linux.
@item Diemand Alexander V. @email{axeld@@vial.ethz.ch}
For providing RPM packages of @strong{MySQL} for RedHat Linux-Alpha.
@item Antoni Pamies Olive @email{toni@@readysoft.es}
For providing RPM versions of a lot of @strong{MySQL} clients for Intel
and SPARC.
@item Jay Bloodworth @email{jay@@pathways.sde.state.sc.us}
For providing RPM versions for @strong{MySQL} 3.21 versions.
@item Jochen Wiedmann @email{wiedmann@@neckar-alb.de}
For maintaining the Perl @code{DBD::mysql} module.
@item Therrien Gilbert @email{gilbert@@ican.net}, Jean-Marc Pouyot @email{jmp@@scalaire.fr}
French error messages.
@item Petr snajdr, @email{snajdr@@pvt.net}
Czech error messages.
@item Jaroslaw Lewandowski @email{jotel@@itnet.com.pl}
Polish error messages.
@item Miguel Angel Fernandez Roiz
Spanish error messages.
@item Roy-Magne Mo @email{rmo@@www.hivolda.no}
Norwegian error messages and testing of 3.21.#.
@item Timur I. Bakeyev @email{root@@timur.tatarstan.ru}
Russian error messages.
@item @email{brenno@@dewinter.com} && Filippo Grassilli @email{phil@@hyppo.com}
Italian error messages.
@item Dirk Munzinger @email{dirk@@trinity.saar.de}
German error messages.
@item Billik Stefan @email{billik@@sun.uniag.sk}
Slovak error messages.
@item Stefan Saroiu @email{tzoompy@@cs.washington.edu}
Romanian error messages.
@item Peter Feher
Hungarian error messages
@item David Sacerdote @email{davids@@secnet.com}
Ideas for secure checking of DNS hostnames.
@item Wei-Jou Chen @email{jou@@nematic.ieo.nctu.edu.tw}
Some support for Chinese(BIG5) characters.
@item Wei He @email{hewei@@mail.ied.ac.cn}
A lot of functionality for the Chinese(GBK) character set.
@item Zeev Suraski @email{bourbon@@netvision.net.il}
@code{FROM_UNIXTIME()} time formatting, @code{ENCRYPT()} functions, and
@code{bison} advisor.
Active mailing list member.
@item Luuk de Boer @email{luuk@@wxs.nl}
Ported (and extended) the benchmark suite to @code{DBI}/@code{DBD}. Have
been of great help with @code{crash-me} and running benchmarks. Some new
date functions. The mysql_setpermissions script.
@item Jay Flaherty @email{fty@@utk.edu}
Big parts of the Perl @code{DBI}/@code{DBD} section in the manual.
@item Paul Southworth @email{pauls@@etext.org}, Ray Loyzaga @email{yar@@cs.su.oz.au}
Proof-reading of the Reference Manual.
@item Alexis Mikhailov @email{root@@medinf.chuvashia.su}
User definable functions (UDFs); @code{CREATE FUNCTION} and
@code{DROP FUNCTION}.
@item Andreas F. Bobak @email{bobak@@relog.ch}
The @code{AGGREGATE} extension to UDF functions.
@item Ross Wakelin @email{R.Wakelin@@march.co.uk}
Help to set up InstallShield for @strong{MySQL}-Win32.
@item Jethro Wright III @email{jetman@@li.net}
The @file{libmysql.dll} library.
@item James Pereria @email{jpereira@@iafrica.com}
Mysqlmanager, a Win32 GUI tool for administrating @strong{MySQL}.
@item Curt Sampson @email{cjs@@portal.ca}
Porting of MIT-pthreads to NetBSD/Alpha and NetBSD 1.3/i386.
@item Sinisa Milivojevic @email{sinisa@@coresinc.com}
Compression (with @code{zlib}) to the client/server protocol.
Perfect hashing for the lexical analyzer phase.
@item Antony T. Curtis @email{antony.curtis@@olcs.net}
Porting of @strong{MySQL} to OS/2.
@item Martin Ramsch @email{m.ramsch@@computer.org}
Examples in the @strong{MySQL} Tutorial.
@item Tim Bunce
Author of @code{mysqlhotcopy}.
@item Steve Harvey
For making @code{mysqlaccess} more secure.
@item Jeremy Cole @email{jeremy@@spaceapes.com}
Proofreading and editing this fine manual.
@item Valueclick Inc.
For sponsoring the optimize section in this manual.
@end table
Other contributors, bugfinders and testers: James H. Thompson, Maurizio
Menghini, Wojciech Tryc, Luca Berra, Zarko Mocnik, Wim Bonis, Elmar
Haneke, @email{jehamby@@lightside}, @email{psmith@@BayNetworks.COM},
@email{duane@@connect.com.au}, Ted Deppner @email{ted@@psyber.com},
Mike Simons, Jaakko Hyv@"atti.
And lots of bug report/patches from the folks on the mailing list.
And a big tribute to those that help us answer questions on the
@code{mysql@@lists.mysql.com} mailing list:
@table @asis
@item Daniel Koch @email{dkoch@@amcity.com}
Irix setup.
@item Luuk de Boer @email{luuk@@wxs.nl}
Benchmark questions.
@item Tim Sailer @email{tps@@users.buoy.com}
@code{DBD-mysql} questions.
@item Boyd Lynn Gerber @email{gerberb@@zenez.com}
SCO related questions.
@item Richard Mehalick @email{RM186061@@shellus.com}
@code{xmysql}-related questions and basic installation questions.
@item Zeev Suraski @email{bourbon@@netvision.net.il}
Apache module configuration questions (log & auth), PHP-related
questions, SQL syntax related questions and other general questions.
@item Francesc Guasch @email{frankie@@citel.upc.es}
General questions.
@item Jonathan J Smith @email{jsmith@@wtp.net}
Questions pertaining to OS-specifics with Linux, SQL syntax, and other
things that might be needing some work.
@item David Sklar @email{sklar@@student.net}
Using @strong{MySQL} from PHP and Perl.
@item Alistair MacDonald @email{A.MacDonald@@uel.ac.uk}
Not yet specified, but is flexible and can handle Linux and maybe HP-UX.
Will try to get user to use @code{mysqlbug}.
@item John Lyon @email{jlyon@@imag.net}
Questions about installing @strong{MySQL} on Linux systems, using either
@file{.rpm} files, or compiling from source.
@item Lorvid Ltd. @email{lorvid@@WOLFENET.com}
Simple billing/license/support/copyright issues.
@item Patrick Sherrill @email{patrick@@coconet.com}
ODBC and VisualC++ interface questions.
@item Randy Harmon @email{rjharmon@@uptimecomputers.com}
@code{DBD}, Linux, some SQL syntax questions.
@end table
@node News, Bugs, Credits, Top
@appendix MySQL change history
Note that we tend to update the manual at the same time we implement new
things to @strong{MySQL}. If you find a version listed below that you can't
find on the
@uref{http://www.mysql.com/downloads/,@strong{MySQL} download page},
this means that the version has not yet been released!
@menu
* News-3.23.x:: Changes in release 3.23.x (Released as alpha)
* News-3.22.x:: Changes in release 3.22.x (Recommended version)
* News-3.21.x:: Changes in release 3.21.x
* News-3.20.x:: Changes in release 3.20.x
* News-3.19.x:: Changes in release 3.19.x
@end menu
@node News-3.23.x, News-3.22.x, News, News
@appendixsec Changes in release 3.23.x (Released as alpha)
The major difference between release 3.23 and releases 3.22 and 3.21 is that
3.23 contains a new ISAM library (MyISAM), which is more tuned for SQL
than the old ISAM was.
The 3.23 release is under development, and things will be added at a
fast pace to it. For the moment we recommend this version only for
users that desperately need a new feature that is found only in this
release (like big file support and machine-independent tables). (Note
that all new functionality in @strong{MySQL} 3.23 is extensively tested, but as
this release involves much new code, it's difficult to test everything).
We are not adding any more new features that are likely to break any
old code in @strong{MySQL} 3.23 so this version should stabilise pretty soon
and will soon be declared beta, gamma and release.
@menu
* News-3.23.22:: Changes in release 3.23.22
* News-3.23.21:: Changes in release 3.23.21
* News-3.23.20:: Changes in release 3.23.20
* News-3.23.19:: Changes in release 3.23.19
* News-3.23.18:: Changes in release 3.23.18
* News-3.23.17:: Changes in release 3.23.17
* News-3.23.16:: Changes in release 3.23.16
* News-3.23.15:: Changes in release 3.23.15
* News-3.23.14:: Changes in release 3.23.14
* News-3.23.13:: Changes in release 3.23.13
* News-3.23.12:: Changes in release 3.23.12
* News-3.23.11:: Changes in release 3.23.11
* News-3.23.10:: Changes in release 3.23.10
* News-3.23.9:: Changes in release 3.23.9
* News-3.23.8:: Changes in release 3.23.8
* News-3.23.7:: Changes in release 3.23.7
* News-3.23.6:: Changes in release 3.23.6
* News-3.23.5:: Changes in release 3.23.5
* News-3.23.4:: Changes in release 3.23.4
* News-3.23.3:: Changes in release 3.23.3
* News-3.23.2:: Changes in release 3.23.2
* News-3.23.1:: Changes in release 3.23.1
* News-3.23.0:: Changes in release 3.23.0
@end menu
@node News-3.23.22, News-3.23.21, News-3.23.x, News-3.23.x
@appendixsubsec Changes in release 3.23.22
@itemize @bullet
@item
Fixed that @code{lex_hash.h} is created properly for each @code{MySQL}
distribution.
@item
Fixed that @code{MASTER} and @code{COLLECTION} are not a reserved words.
@item
The log generated by @code{--slow-query-log} didn't contain the whole queries.
@item
Fixed that open transactions in BDB tables are rolled back if the
connection is closed unexpectedly.
@item
Added workaround for a bug in gcc 2.96 (intel) and gcc 2.9 (Ia64) in
gen_lex_hash.c.
@item
Fixed memory leak in the client library when using @code{host=..} in the
@code{my.cnf} file.
@item
Optimized functions that manipulates the hours/minutes/seconds.
@item
Fixed bug when comparing the result of @code{DATE_ADD}/@code{DATE_SUB}
against a number
@item
Changed the meaning of @code{-F, --fast} for @code{myisamchk}. Added option
@code{-C, --check-only-changed} to @code{myisamchk}.
@item
Added @code{ANALYZE table_name} to update key statistics for tables.
@item
Changed binary items @code{0x...} to be default regarded as an integer
@item
Fix for SCO and @code{show proesslist}.
@item
Added @code{auto-rehash} on reconnect for the @code{mysql} client.
@end itemize
@node News-3.23.21, News-3.23.20, News-3.23.22, News-3.23.x
@appendixsubsec Changes in release 3.23.21
@itemize @bullet
@item
Added @code{mysql_character_set_name(MYSQL *mysql)} function to the MySQL API.
@item
Made the update log @code{ASCII 0} safe.
@item
Added the @code{mysql_config} script.
@item
Fixed problem when using @code{<} or @code{>} with a char column that was only
partly indexed.
@item
One would get a core dump if the log file was not readable by the MySQL user.
@item
Changed @code{mysqladmin} to use the @code{CREATE DATABASE}/@code{DROP
DATABASE} commands instead of the old deprecated API calls.
@item
Fixed @code{chown} warning in @code{safe_mysqld}.
@item
Fixed a bug in @code{ORDER BY} that was introduced in 3.23.19.
@item
Only optimize the @code{DELETE FROM table_name} to do a drop+create of
the table if we are in @code{AUTOCOMMIT} mode. (Needed for BDB tables).
@item
Added extra checks to avoid index corruption when the @code{ISAM}/@code{MyISAM}
index files gets full during an @code{INSERT}/@code{UPDATE}.
@item
@code{myisamchk} didn't correctly update row checksum when used with
@code{-ro} (This only gave an warning in subsequent runs).
@item
Fixed bug in @code{REPAIR TABLE} so that it works with tables without index.
@item
Fixed buffer overrun in @code{DROP DATABASE}
@item
@code{LOAD TABLE FROM MASTER} is sufficiently bug-free to announce it as
a feature.
@item
@code{MATCH} and @code{AGAINST} are now reserved words.
@end itemize
@node News-3.23.20, News-3.23.19, News-3.23.21, News-3.23.x
@appendixsubsec Changes in release 3.23.20
@itemize @bullet
@item
Fixed bug in 3.23.19; @code{DELETE FROM table_name} removed the .frm file.
@end itemize
@node News-3.23.19, News-3.23.18, News-3.23.20, News-3.23.x
@appendixsubsec Changes in release 3.23.19
@itemize @bullet
@item
Changed copyright for all files to GPL for the server code and utilities and
LGPL for the client libraries.
@item
Fixed bug where all rows matching weren't updated on a @code{MyISAM} table
when doing update based on key on a table with many keys and some key changed
values.
@item
The Linux @strong{MySQL} RPM's and binaries are now staticly linked with
a linuxthread version that has faster mutex handling when used with
@strong{MySQL}.
@item
@code{ORDER BY} can now uses @code{REF} keys to find subset the rows
that needs to be sorted.
@item
Changed name of @code{print_defaults} to @code{my_print_defaults} to avoid
name confusion.
@item
Fixed @code{NULLIF()} to work according to ANSI SQL99.
@item
Added @code{net_read_timeout} and @code{net_write_timeout} as startup
parameters to @code{mysqld}.
@item
Fixed bug that destroyed index when doing @code{myisamchk --sort-records}
on a table with prefix compressed index.
@item
Added pack_isam and myisampack to the standard @strong{MySQL} distribution.
@item
Added the syntax @code{BEGIN WORK} (the same as @code{BEGIN}).
@item
Fixed core dump bug when using @code{ORDER BY} on a @code{CONV()} expression.
@item Added @code{LOAD TABLE FROM MASTER}
@item Added @code{FLUSH MASTER} and @code{FLUSH SLAVE}
@item Fixed big/little endian problem in the replication
@end itemize
@node News-3.23.18, News-3.23.17, News-3.23.19, News-3.23.x
@appendixsubsec Changes in release 3.23.18
@itemize @bullet
@item
Fixed a problem from 3.23.17 when choosing character set on the client side.
@item
Added @code{FLUSH TABLES WITH READ LOCK} to make a global lock suitable to
make a copy of @strong{MySQL} data files.
@item
@code{CREATE TABLE ... SELECT ... PROCEDURE} now works.
@item
Internal temporary tables will now uses compressed index when using
@code{GROUP BY} on @code{VARCHAR/CHAR} columns.
@item
Fixed a problem when locking the same table with both a @code{READ} and a
@code{WRITE} lock.
@item
Fixed problem with myisamchk and @code{RAID} tables.
@end itemize
@node News-3.23.17, News-3.23.16, News-3.23.18, News-3.23.x
@appendixsubsec Changes in release 3.23.17
@itemize @bullet
@item
Fixed a bug in @code{find_in_set()} when the first argument was @code{NULL}.
@item
Added table locks to Berkeley DB.
@item
Fixed a bug with @code{LEFT JOIN} and @code{ORDER BY} where the first
table had only one matching row.
@item
Added 4 sample @code{my.cfg} example files in the @file{support-files}
directory.
@item
Fixed @code{duplicated key} problem when doing big @code{GROUP BY}'s.
(This bug was probably introduced in 3.23.15).
@item
Changed syntax for @code{INNER JOIN} to match ANSI SQL.
@item
Added @code{NATURAL JOIN} syntax.
@item
A lot of fixes in the @code{BDB} interface.
@item
Added handling of @code{--no-defaults} and @code{--defaults-file} to
@code{safe_mysqld.sh} and @code{mysql_install_db.sh}.
@item
Fixed bug in reading compressed tables with many threads.
@item
Fixed that @code{USE INDEX} works with @code{PRIMARY} keys.
@item
Added @code{BEGIN} statement to start a transaction in @code{AUTOCOMMIT} mode.
@item
Added symbolic links support for Win32.
@item
Changed protocol to let client know if the server is in AUTOCOMMIT mode
and if there is a pending transaction. If there is a pending transaction
the client library will give an error before reconnecting to the server to
let the client know that the server did a rollback.
The protocol is still backward compatible with old clients
@item
@code{KILL} now works on a thread that is locked on a 'write' to a dead client.
@item
Fixed memory leak in the replication slave thread.
@item
Added new option @code{log-slave-updates} to allow daisy-chaining the slaves.
@item
Fixed compile error on FreeBSD and other systems where @code{pthread_t}
is not the same as @code{int}.
@item
Fixed master shutdown aborting the slave thread.
@item
Fixed a race condition in @code{INSERT DELAYED} code when doing
@code{ALTER TABLE}.
@item
Added deadlock detection sanity checks to @code{INSERT DELAYED}
@end itemize
@node News-3.23.16, News-3.23.15, News-3.23.17, News-3.23.x
@appendixsubsec Changes in release 3.23.16
@itemize @bullet
@item
Added option @code{TYPE=QUICK} to @code{CHECK} and @code{REPAIR}.
@item
Fixed bug in @code{REPAIR TABLE} when the table was in use by other threads.
@item
Added a thread cache to make it possible to debug @strong{MySQL} with
@code{gdb} when one does a lot of reconnects. This will also improve
systems where you can't use persistent connections.
@item
Lots of fixes in the Berekely DB interface.
@item
@code{UPDATE IGNORE} will not abort if an update results in a
@code{DUPLICATE_KEY} error.
@item
Put @code{CREATE TEMPORARY TABLE} commands in the update log.
@item
Fixed bug in handling of masked IP numbers in the privilege tables.
@item
Fixed bug with @code{delayed_key_writes} tables and @code{CHECK TABLE}.
@item
Added @code{replicate-do-db} and @code{replicate-ignore-db} options to
restrict which databases get replicated
@item
Added @code{SQL_LOG_BIN} option
@end itemize
@node News-3.23.15, News-3.23.14, News-3.23.16, News-3.23.x
@appendixsubsec Changes in release 3.23.15
@itemize @bullet
@item
To start @code{mysqld} as @code{root}, you must now use the @code{--user=root} option.
@item
Added interface to Berkeley DB. (This is not yet functional; Play with it at
your own risk!)
@item
Replication between master and slaves.
@item
Fixed bug that other threads could steal a lock when a thread had
a lock on a table and did a @code{FLUSH TABLES} command.
@item
Added the @code{slow_launch_time} variable and the @code{Slow_launch_threads}
status variable to @code{mysqld}. These can be examined with
@code{mysqladmin variables} and @code{mysqladmin extended-status}.
@item
Added functions @code{INET_NTOA()} and @code{INET_ATON()}.
@item
The default type of @code{IF()} now depends on the second and
third arguments and not only on the second argument.
@item
Fixed case when @code{myisamchk} could go into a loop when trying to
repair a crashed table.
@item
Don't write @code{INSERT DELAYED} to update log if @code{SQL_LOG_UPDATE=0}.
@item
Fixed problem with @code{REPLACE} on @code{HEAP} tables.
@item
Added possible character sets and time zone to @code{SHOW VARIABLES}.
@item
Fixed bug in locking code that could result it locking problems with
concurrent inserts under high load.
@item
Fixed a problem with @code{DELETE} of many rows on a table with
compressed keys where @strong{MySQL} scanned the index to find the rows.
@item
Fixed problem with @code{CHECK} on table with deleted keyblocks.
@item
Fixed a bug in reconnect (at the client side) where it didn't free memory
properly in some contexts.
@item
Fixed problems in update log when using @code{LAST_INSERT_ID()} to update
a table with an auto_increment key.
@item
Added function @code{NULLIF()}.
@item
Fixed bug when using @code{LOAD DATA INFILE} on a table with
@code{BLOB/TEXT} columns.
@item
Optimised MyISAM to be faster when inserting keys in sorted order.
@item
@code{EXPLAIN SELECT..} now also prints out whether @strong{MySQL} needs to
create a temporary table or use file sorting when resolving the @code{SELECT}.
@item
Added optimization to skip @code{ORDER BY} parts where the part is a
constant expression in the @code{WHERE} part. Indexes can now be used
even if the @code{ORDER BY} doesn't match the index exactly, as long as
all the not used index parts and all the extra @code{ORDER BY}
columns are constants in the @code{WHERE} clause. @xref{MySQL indexes}.
@item
@code{UPDATE} and @code{DELETE} on a whole unique key in the @code{WHERE} part,
is now faster than before.
@item
Changed @code{RAID_CHUNKSIZE} to be in 1024 byte increments.
@item
Fixed coredump in LOAD_FILE(NULL).
@end itemize
@node News-3.23.14, News-3.23.13, News-3.23.15, News-3.23.x
@appendixsubsec Changes in release 3.23.14
@itemize @bullet
@item
Fixed a bug in @code{CONCAT()} where one of the arguments was a function
that returned a modified argument.
@item
Fixed a critical bug in @code{myisamchk}, where it updated the header in
the index file when one only checked the table. This confused the
@code{mysqld} daemon if it updated the same table at the same time. Now
the status in the index file is only updated if one uses
@code{--update-state}. With older @code{myisamchk} versions you should
use @code{--read-only} when only checking tables, if there is the
slightest chance that the @code{mysqld} server is working on the table at the
same time!
@item
Fixed that @code{DROP TABLE} is logged in the update log.
@item
Fixed problem when searching on @code{DECIMAL()} key field
where the column data contained leading zeros.
@item
Fix bug in @code{myisamchk} when the auto_increment isn't the first key.
@item
Allow @code{DATETIME} in ISO8601 format: 2000-03-12T12:00:00
@item
Dynamic character sets. A @code{mysqld} binary can now handle many different
character sets (you can choose which when starting @code{mysqld}).
@item
Added command @code{REPAIR TABLE}.
@item
Added C API function @code{mysql_thread_safe()}.
@item
Added the @code{UMASK_DIR} environment variable.
@item
Added function @code{CONNECTION_ID()}.
@item
When using @code{=} on @code{BLOB} or @code{VARCHAR BINARY} keys, where
only a part of the column was indexed, the whole column of the result
row wasn't compared.
@item
Fix for sjis character set and @code{ORDER BY}.
@item
When running in ANSI mode, don't allow columns to be used that aren't in
the @code{GROUP BY} part.
@end itemize
@node News-3.23.13, News-3.23.12, News-3.23.14, News-3.23.x
@appendixsubsec Changes in release 3.23.13
@itemize @bullet
@item
Fixed problem when doing locks on the same table more than 2 times in
the same @code{LOCK TABLE} command; This fixed the problem one got when running
the test-ATIS test with @code{--fast} or @code{--check-only-changed}.
@item
Added option @code{SQL_BUFFER_RESULT} to @code{SELECT}.
@item
Removed end space from double/float numbers in results from temporary
tables.
Added @code{CHECK TABLE} command.
@item
Added changes for MyISAM in 3.23.12 that didn't get into the source
distribution because of CVS problems.
@item
Fixed bug so that mysqladmin shutdown will wait for the local server to close
down.
@item
Fixed a possible endless loop when calculating timestamp.
@item
Added print_defaults to the .rpm files. Removed mysqlbug from the client
rpm file.
@end itemize
@node News-3.23.12, News-3.23.11, News-3.23.13, News-3.23.x
@appendixsubsec Changes in release 3.23.12
@itemize @bullet
@item
Fixed bug in @code{MyISAM} involving @code{REPLACE ... SELECT} which could
give a corrupted table.
@item
Fixed bug in @code{myisamchk} where it wrongly reset the auto_increment value.
@item
LOTS of patches for Linux Alpha. @strong{MySQL} now appears to be relatively
stable on Alpha.
@item
Changed @code{DISTINCT} on @code{HEAP} temporary tables to use hashed
keys to quickly find duplicated rows. This mostly concerns queries of
type @code{SELECT DISTINCT ... GROUP BY ..}. This fixes a problem where
not all duplicates were removed in queries of the above type. In
addition, the new code is MUCH faster.
@item
Added patches to make @code{MySQL} compile on MacOS X.
@item
Added option @code{IF NOT EXISTS} to @code{CREATE DATABASE}.
@item
Added options @code{--all-databases} and @code{--databases} to @code{mysqldump}
to allow dumping of many databases at the same time.
@item
Fixed bug in compressed @code{DECIMAL()} index in @code{MyISAM} tables.
@item
Fixed bug when storing 0 into a timestamp.
@item
When doing @code{mysqladmin shutdown} on a local connection, @code{mysqladmin} now
waits until the pidfile is gone before terminating.
@item
Fixed core dump with some @code{COUNT(DISTINCT ...)} queries.
@item
Fixed that @code{myisamchk} works properly with RAID:ed tables.
@item
Fixed problem with @code{LEFT JOIN} and @code{key_field IS NULL}.
@item
Fixed bug in @code{net_clear()} which could give the error @code{Aborted
connection} in the @strong{MySQL} clients.
@item
Added options @code{USE INDEX (key_list)} and @code{IGNORE INDEX (key_list)} as
join parameters in @code{SELECT}.
@item
@code{DELETE} and @code{RENAME} should now work on @code{RAID} tables.
@end itemize
@node News-3.23.11, News-3.23.10, News-3.23.12, News-3.23.x
@appendixsubsec Changes in release 3.23.11
@itemize @bullet
@item
Allow the @code{ALTER TABLE tbl_name ADD (field_list)} syntax.
@item
Fixed problem with optimizer that could sometimes use wrong keys.
@item
Fixed that @code{GRANT/REVOKE ALL PRIVILEGES} doesn't affect
@code{GRANT OPTION}.
@item
Removed extra @code{)} from the output of @code{SHOW GRANTS}
@item
Fixed problem when storing numbers in timestamps.
@item
Fix problem with timezones that have half hour offsets.
@item
Allow the syntax @code{UNIQUE INDEX} in @code{CREATE} statements.
@item
@code{mysqlhotcopy} - fast on-line hot-backup utility for local
@strong{MySQL} databases. By Tim Bunce.
@item
New more secure @code{mysqlaccess}. Thanks to Steve Harvey for this.
@item
Added options @code{--i-am-a-dummy} and @code{--safe-updates} to @code{mysql}.
@item
Added variables @code{select_limit} and @code{max_join_size} to @code{mysql}.
@item
Added sql variables: @code{SQL_MAX_JOIN_SIZE} and @code{SQL_SAFE_UPDATES}.
@item
Added @code{READ LOCAL} lock that doesn't lock the table for concurrent
inserts. (This is used by @code{mysqldump}).
@item
Changed that @code{LOCK TABLES .. READ} doesn't anymore allow concurrent
inserts.
@item
Added option @code{--skip-delay-key-write} to @code{mysqld}.
@item
Fixed security problem in the protocol regarding password checking.
@item
@code{_rowid} can now be used as an alias for an integer type unique indexed
column.
@item
Added back blocking of @code{SIGPIPE} when compiling with @code{--thread-safe-clients}
to make things safe for old clients.
@end itemize
@node News-3.23.10, News-3.23.9, News-3.23.11, News-3.23.x
@appendixsubsec Changes in release 3.23.10
@itemize @bullet
@item
Fixed bug in 3.23.9 where memory wasn't properly freed when doing
@code{LOCK TABLES}.
@end itemize
@node News-3.23.9, News-3.23.8, News-3.23.10, News-3.23.x
@appendixsubsec Changes in release 3.23.9
@itemize @bullet
@item
Fixed problem that affected queries that did arithmetic on group functions.
@item
Fixed problem with timestamps and @code{INSERT DELAYED}.
@item
Fixed that @code{date_column BETWEEN const_date AND const_date} works.
@item
Fixed problem when only changing a 0 to @code{NULL} in a table with
@code{BLOB/TEXT} columns.
@item
Fixed bug in range optimizer when using many key parts and or on the middle
key parts: @code{WHERE K1=1 and K3=2 and (K2=2 and K4=4 or K2=3 and K4=5)}
@item
Added command @code{source} to @code{mysql} to allow reading of batch files
inside the @code{mysql} client. Original patch by Matthew Vanecek.
@item
Fixed critical problem with the @code{WITH GRANT OPTION} option.
@item
Don't give an unnecessary @code{GRANT} error when using tables from many
databases in the same query.
@item
Added VIO wrapper (needed for SSL support ; By Andrei Errapart and
Tõnu Samuel).
@item
Fixed optimizer problem on @code{SELECT} when using many overlapping indexes.
@strong{MySQL} should now be able to choose keys even better when there
is many keys to choose from.
@item
Changed optimizer to prefer a range key instead of a ref key when the
range key can uses more columns than the ref key (which only can use
columns with =). For example, the following type of queries should now
be faster: @code{SELECT * from key_part_1=const and key_part_2 > const2}
@item
Fixed bug that a change of all @code{VARCHAR} columns to @code{CHAR} columns
didn't change row type from dynamic to fixed.
@item
Disabled floating point exceptions for FreeBSD to fix core dump when
doing @code{SELECT floor(pow(2,63))}.
@item
Changed @code{mysqld} startup option @code{--delay-key-write} to
@code{--delay-key-write-for-all-tables}
@item
Added @code{read-next-on-key} to @code{HEAP} tables. This should fix all
problems with @code{HEAP} tables when using not @code{UNIQUE} keys.
@item
Added print of default arguments options to all clients.
@item
Added @code{--log-slow-queries} to @code{mysqld} to log all queries that take a
long time to a separate log file with a time of how long the query took.
@item
Fixed core dump when doing @code{WHERE key_column=RAND(...)}
@item
Fixed optimization bug in @code{SELECT .. LEFT JOIN ... key_column IS NULL},
when @code{key_column} could contain @code{NULL} values.
@item
Fixed problem with 8-bit characters as separators in @code{LOAD DATA INFILE}.
@item
@end itemize
@node News-3.23.8, News-3.23.7, News-3.23.9, News-3.23.x
@appendixsubsec Changes in release 3.23.8
@itemize @bullet
@item
Fixed problem when handling indexfiles larger than 8G.
@item
Added latest patches to mit-pthreads for NetBSD.
@item
Fixed problem with timezones that are < GMT -11.
@item
Fixed a bug when deleting packed keys in @code{NISAM}.
@item
Fixed problem with @code{ISAM} when doing some @code{ORDER BY ... DESC} queries.
@item
Fixed bug when doing a join on a text key which didn't cover the whole key.
@item
Option @code{--delay-key-write} didn't enable delayed key writing.
@item
Fixed update of @code{TEXT} column which only involved case changes.
@item
Fixed that @code{INSERT DELAYED} doesn't update timestamps that are given.
@item
Added function @code{YEARWEEK()} and options @code{x}, @code{X}, @code{v} and
@code{V} to @code{DATE_FORMAT()}.
@item
Fixed problem with @code{MAX(indexed_column)} and HEAP tables.
@item
Fixed problem with @code{BLOB NULL} keys and @code{LIKE} "prefix%".
@item
Fixed problem with @code{MyISAM} and fixed length rows < 5 bytes.
@item
Fixed problem that could cause @strong{MySQL} to touch freed memory when
doing very complicated @code{GROUP BY} queries.
@item
Fixed core dump if you got a crashed table where an @code{ENUM} field value
was too big.
@end itemize
@node News-3.23.7, News-3.23.6, News-3.23.8, News-3.23.x
@appendixsubsec Changes in release 3.23.7
@itemize @bullet
@item
Fixed workaround under Linux to avoid problems with @code{pthread_mutex_timedwait},
which is used with @code{INSERT DELAYED}. @xref{Linux}.
@item
Fixed that one will get a 'disk full' error message if one gets disk full
when doing sorting (instead of waiting until we got more disk space).
@item
Fixed a bug in @code{MyISAM} with keys > 250 characters.
@item
In @code{MyISAM} one can now do an @code{INSERT} at the same time as other
threads are reading from the table.
@item
Added variable @code{max_write_lock_count} to @code{mysqld} to force a
@code{READ} lock after a certain number of @code{WRITE} locks.
@item
Inverted flag @code{delayed_key_write} on @code{show variables}.
@item
Renamed variable @code{concurrency} to @code{thread_concurrency}.
@item
The following functions are now multi-byte-safe:
@code{LOCATE(substr,str)}, @code{POSITION(substr IN str)},
@code{LOCATE(substr,str,pos)}, @code{INSTR(str,substr)},
@code{LEFT(str,len)}, @code{RIGHT(str,len)},
@code{SUBSTRING(str,pos,len)}, @code{SUBSTRING(str FROM pos FOR len)},
@code{MID(str,pos,len)}, @code{SUBSTRING(str,pos)}, @code{SUBSTRING(str
FROM pos)}, @code{SUBSTRING_INDEX(str,delim,count)}, @code{RTRIM(str)},
@code{TRIM([[BOTH | TRAILING] [remstr] FROM] str)},
@code{REPLACE(str,from_str,to_str)}, @code{REVERSE(str)},
@code{INSERT(str,pos,len,newstr)}, @code{LCASE(str)}, @code{LOWER(str)},
@code{UCASE(str)} and @code{UPPER(str)}; Patch by Wei He.
@item
Fix core dump when releasing a lock from a non-existant table.
@item
Remove locks on tables before starting to remove duplicates.
@item
Added option @code{FULL} to @code{SHOW PROCESSLIST}.
@item
Added option @code{--verbose} to @code{mysqladmin}.
@item
Fixed problem when automatically converting HEAP to MyISAM.
@item
Fixed bug in HEAP tables when doing insert + delete + insert + scan the
table.
@item
Fixed bugs on Alpha with @code{REPLACE()} and @code{LOAD DATA INFILE}.
@item
Added @code{mysqld} variable @code{interactive_timeout}.
@item
Changed the argument to @code{mysql_data_seek()} from @code{ulong} to
@code{ulonglong}.
@end itemize
@node News-3.23.6, News-3.23.5, News-3.23.7, News-3.23.x
@appendixsubsec Changes in release 3.23.6
@itemize @bullet
@item
Added @code{mysqld} option @code{-O lower_case_table_names=@{0|1@}} to allow
users to force table names to lower case.
@item
Added @code{SELECT ... INTO DUMPFILE}.
@item
Added mysqld option @code{--ansi} to make some functions @code{ANSI SQL}
compatible.
@item
Temporary tables now starts with @code{#sql}.
@item
Added quoting of identifiers with @code{`} (@code{"} in @code{--ansi} mode).
@item
Changed to use snprintf() when printing floats to avoid some buffer
overflows on FreeBSD.
@item
Made @code{[floor()} overflow safe on FreeBSD.
@item
Added option @code{--quote-names} to @code{mysqldump}
@item
Fixed bug that one could make a part of a @code{PRIMARY KEY NOT NULL}.
@item
Fixed @code{encrypt()} to be thread safe and not reuse buffer.
@item
Added @code{mysql_odbc_escape_string()} function to support big5 characters in
MyOBC.
@item
Rewrote the table handler to use classes. This introduces a lot of new code,
but will make table handling faster and better.
@item
Added patch by Sasha for user defined variables.
@item
Changed that @code{FLOAT} and @code{DOUBLE} (without any length modifiers) are
not anymore fixed decimal point numbers.
@item
Changed the meaning of @code{FLOAT(X)}: Now this is the same as @code{FLOAT} if
X <= 24 and a @code{DOUBLE} if 24 < X <= 53.
@item
@code{DECIMAL(X)} is now an alias for @code{DECIMAL(X,0)} and @code{DECIMAL}
is now an alias for @code{DECIMAL(10,0)}. The same goes for @code{NUMERIC}.
@item
Added option @code{ROW_FORMAT=@{default | dynamic | static | compressed@}} to
@code{CREATE_TABLE}.
@item
@code{DELETE FROM table_name} didn't work on temporary tables.
@item
Changed function @code{CHAR_LENGTH()} to be multi-byte character safe.
@item
Added function @code{ORD(string)}.
@end itemize
@node News-3.23.5, News-3.23.4, News-3.23.6, News-3.23.x
@appendixsubsec Changes in release 3.23.5
@itemize @bullet
@item
Fixed some Y2K problems in the new date handling in 3.23.
@item
Fixed problem with @code{SELECT DISTINCT ... ORDER BY RAND()}.
@item
Added patches by Sergei A. Golubchik for text searching on the MyISAM level.
@item
Fixed cache overflow problem when using full joins without keys.
@item
Fixed some configure issues.
@item
Some small changes to make parsing faster.
@item
@code{ALTER TABLE} + adding a column after the last field didn't work.
@item
Fixed problem when using an auto_increment column in two keys
@item
One can now with MyISAM have the auto_increment part as a sub part:
@code{CREATE TABLE foo (a int not null auto_increment, b char(5), primary key (b,a))}
@item
Fixed bug in MyISAM with packed char keys that could be @code{NULL}.
@item
@code{AS} on fieldname with @code{CREATE TABLE table_name SELECT ...} didn't
work.
@item
Allow use of @code{NATIONAL} and @code{NCHAR} when defining character columns.
This is the same as not using @code{BINARY}.
@item
Don't allow @code{NULL} columns in a @code{PRIMARY KEY} (only in @code{UNIQUE}
keys).
@item
Clear @code{LAST_INSERT_ID} if one uses this in ODBC:
@code{WHERE auto_increment_column IS NULL}. This seems to fix some problems
with Access.
@item
@code{SET SQL_AUTO_IS_NULL=0|1} now turns on/off the handling of
searching after the last inserted row with @code{WHERE
auto_increment_column IS NULL}.
@item
Added new @code{mysqld} variable @code{concurrency} for Solaris.
@item
Added option @code{--relative} to @code{mysqladmin} to make
@code{extended-status} more useful to monitor changes.
@item
Fixed bug when using @code{COUNT(DISTINCT..)} on an empty table.
@item
Added support for the Chinese character set GBK.
@item
Fixed problem with @code{LOAD DATA INFILE} and @code{BLOB} columns.
@item
Added bit operator @code{~} (negation).
@item
Fixed problem with @code{UDF} functions.
@end itemize
@node News-3.23.4, News-3.23.3, News-3.23.5, News-3.23.x
@appendixsubsec Changes in release 3.23.4
@itemize @bullet
@item
Inserting a @code{DATETIME} into a @code{TIME} column will not anymore
try to store 'days' in it.
@item
Fixed problem with storage of float/double on little endian machines.
(This affected @code{SUM()}.)
@item
Added connect timeout on TCP/IP connections.
@item
Fixed problem with @code{LIKE} "%" on an index that may have @code{NULL} values.
@item
@code{REVOKE ALL PRIVILEGES} didn't revoke all privileges.
@item
Allow creation of temporary tables with same name as the original table.
@item
When granting a user a grant option for a database, he couldn't grant
privileges to other users.
@item
New command: @code{SHOW GRANTS FOR user} (by Sinisa).
@item
New @code{date_add} syntax: @code{date/datetime + INTERVAL # interval_type}.
By Joshua Chamas.
@item
Fixed privilege check for @code{LOAD DATA REPLACE}.
@item
Automatic fixing of broken include files on Solaris 2.7
@item
Some configure issues to fix problems with big file system detection.
@item
@code{REGEXP} is now case insensitive if you use non-binary strings.
@end itemize
@node News-3.23.3, News-3.23.2, News-3.23.4, News-3.23.x
@appendixsubsec Changes in release 3.23.3
@itemize @bullet
Added patches for MIT-pthreads on NetBSD.
@item
Fixed range bug in MyISAM.
@item
@code{ASC} is now the default again for @code{ORDER BY}.
@item
Added @code{LIMIT} to @code{UPDATE}.
@item
New client function: @code{mysql_change_user()}.
@item
Added character set to @code{SHOW VARIABLES}.
@item
Added support of @code{--[whitespace]} comments.
@item
Allow @code{INSERT into tbl_name VALUES ()}, that is, you may now specify
an empty value list to insert a row in which each column is set to its
default value.
@item
Changed @code{SUBSTRING(text FROM pos)} to conform to ANSI SQL. (Before this
construct returned the rightmost 'pos' characters).
@item
@code{SUM(..)} with @code{GROUP BY} returned 0 on some systems.
@item
Changed output for @code{SHOW TABLE STATUS}.
@item
Added @code{DELAY_KEY_WRITE} option to @code{CREATE TABLE}.
@item
Allow @code{AUTO_INCREMENT} on any key part.
@item
Fixed problem with @code{YEAR(NOW())} and @code{YEAR(CURDATE())}.
@item
Added @code{CASE} construct.
@item
New function @code{COALESCE()}.
@end itemize
@node News-3.23.2, News-3.23.1, News-3.23.3, News-3.23.x
@appendixsubsec Changes in release 3.23.2
@itemize @bullet
@item
Fixed range optimizer bug: @code{SELECT * FROM table_name WHERE
key_part1 >= const AND (key_part2 = const OR key_part2 = const)}. The
bug was that some rows could be duplicated in the result.
@item
Running @code{myisamchk} without @code{-a} updated the index
distribution wrong.
@item
@code{SET SQL_LOW_PRIORITY_UPDATES=1} gave parse error before.
@item
You can now update indexes columns that are used in the @code{WHERE} clause.
@code{UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100}
@item
Date handling should now be a bit faster.
@item
Added handling of fuzzy dates (dates where day or month is 0):
(Like: 1999-01-00)
@item
Fixed optimization of @code{SELECT ... WHERE key_part1=const1 AND
key_part_2=const2 AND key_part1=const4 AND key_part2=const4} ; Indextype
should be @code{range} instead of @code{ref}.
@item
Fixed @code{egcs} 1.1.2 optimizer bug (when using @code{BLOB}s) on Linux Alpha.
@item
Fixed problem with @code{LOCK TABLES} combined with @code{DELETE FROM table}.
@item
MyISAM tables now allow keys on @code{NULL} and @code{BLOB/TEXT} columns.
@item
The following join is now much faster:
@code{SELECT ... FROM t1 LEFT JOIN t2 ON ... WHERE t2.not_null_column IS NULL}.
@item
@code{ORDER BY} and @code{GROUP BY} can be done on functions.
@item
Changed handling of 'const_item' to allow handling of @code{ORDER BY RAND()}.
@item
Indexes are now used for @code{WHERE key_column = function}.
@item
Indexes are now used for @code{WHERE key_column = column_name} even if
the columns are not identically packed.
@item
Indexes are now used for @code{WHERE column_name IS NULL}.
@item
Changed heap tables to be stored in low_byte_first order (to make it easy
to convert to MyISAM tables)
@item
Automatic change of HEAP temporary tables to MyISAM tables in case of
'table is full' errors.
@item
Added option @code{--init-file=file_name} to @code{mysqld}.
@item
@code{COUNT(DISTINCT value,[value,...])}
@item
@code{CREATE TEMPORARY TABLE} now creates a temporary table, in its own
namespace, that is automatically deleted if connection is dropped.
@item
New reserved words (required for @code{CASE}): @code{CASE, THEN, WHEN, ELSE and END}.
@item
New functions @code{EXPORT_SET()} and @code{MD5()}.
@item
Support for the GB2312 Chinese character set.
@end itemize
@node News-3.23.1, News-3.23.0, News-3.23.2, News-3.23.x
@appendixsubsec Changes in release 3.23.1
@itemize @bullet
@item
Fixed some compilation problems.
@end itemize
@node News-3.23.0, , News-3.23.1, News-3.23.x
@appendixsubsec Changes in release 3.23.0
@itemize @bullet
A new table handler library (@code{MyISAM}) with a lot of new features.
@xref{MyISAM}.
@item
You can create in-memory @code{HEAP} tables which are extremely fast for
lookups.
@item
Support for big files (63 bit) on OSes that support big files.
@item
New function @code{LOAD_FILE(filename)} to get the contents of a file as a
string value.
@item
New operator @code{<=>} which will act as @code{=} but will return TRUE
if both arguments are @code{NULL}. This is useful for comparing changes
between tables.
@item
Added the ODBC 3.0 @code{EXTRACT(interval FROM datetime)} function.
@item
Columns defined as @code{FLOAT(X)} is not rounded on storage and may be
in scientific notation (1.0 E+10) when retrieved.
@item
@code{REPLACE} is now faster than before.
@item
Changed @code{LIKE} character comparison to behave as @code{=};
This means that @code{'e' LIKE '@'e'} is now true.
@item
@code{SHOW TABLE STATUS} returns a lot of information about the tables.
@item
Added @code{LIKE} to the @code{SHOW STATUS} command.
@item
Added privilege column to @code{SHOW COLUMNS}.
@item
Added columns @code{packed} and @code{comment} to @code{SHOW INDEX}.
@item
Added comments to tables (with @code{CREATE TABLE ... COMMENT "xxx"}).
@item
Added @code{UNIQUE}, as in
@code{CREATE TABLE table_name (col int not null UNIQUE)}
@item
New create syntax: @code{CREATE TABLE table_name SELECT ....}
@item
New create syntax: @code{CREATE TABLE IF NOT EXISTS ...}
@item
Allow creation of @code{CHAR(0)} columns.
@item
@code{DATE_FORMAT()} now requires @samp{%} before any format character.
@item
@code{DELAYED} is now a reserved word (sorry about that :( ).
@item
An example procedure is added: @code{analyse}, file: @file{sql_analyse.c}.
This will describe the data in your query. Try the following:
@example
SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max elements,[max memory]])
@end example
This procedure is extremely useful when you want to check the data in your
table!
@item
@code{BINARY} cast to force a string to be compared case sensitively.
@item
Added option @code{--skip-show-database} to @code{mysqld}.
@item
Check if a row has changed in an @code{UPDATE} now also works with
@code{BLOB}/@code{TEXT} columns.
@item
Added the @code{INNER} join syntax. @strong{NOTE}: This made @code{INNER}
a reserved word!
@item
Added support for netmasks to the hostname in the @strong{MySQL} tables.
You can specify a netmask using the @code{IP/NETMASK} syntax.
@item
If you compare a @code{NOT NULL DATE/DATETIME} column with @code{IS
NULL}, this is changed to a compare against @code{0} to satisfy some ODBC
applications. (By @email{shreeve@@uci.edu}).
@item
@code{NULL IN (...)} now returns @code{NULL} instead of @code{0}. This will
ensure that @code{null_column NOT IN (...)} doesn't match
@code{NULL} values.
@item
Fix storage of floating point values in @code{TIME} columns.
@item
Changed parsing of @code{TIME} strings to be more strict. Now the
fractional second part is detected (and currently skipped). The
following formats are supported:
@table @code
@item [[DAYS] [H]H:]MM:]SS[.fraction]
@item [[[[[H]H]H]H]MM]SS[.fraction]
@end table
@item
Detect (and ignore) second fraction part from @code{DATETIME}.
@item
Added the @code{LOW_PRIORITY} attribute to @code{LOAD DATA INFILE}.
@item
The default index name now uses the same case as the used column name.
@item
Changed default number of connections to 100.
@item
Use bigger buffers when using @code{LOAD DATA INFILE}.
@item
@code{DECIMAL(x,y)} now works according to ANSI SQL.
@item
Added aggregate UDF functions. Thanks to Andreas F. Bobak
@email{bobak@@relog.ch} for this!
@item
@code{LAST_INSERT_ID()} is now updated for @code{INSERT INTO ... SELECT}.
@item
Some small changes to the join table optimizer to make some joins faster.
@item
@code{SELECT DISTINCT} is much faster; It uses the new @code{UNIQUE}
functionality in @code{MyISAM}. One difference compared to @strong{MySQL} 3.22
is that the output of @code{DISTINCT} is not sorted anymore.
@item
All C client API macros are now functions to make shared libraries more
reliable. Because of this, you can no longer call @code{mysql_num_fields()} on
a @code{MYSQL} object, you must use @code{mysql_field_count()} instead.
@item
Added use of @code{LIBEWRAP}; Patch by Henning P . Schmiedehausen.
@item
Don't allow @code{AUTO_INCREMENT} for other than numerical columns.
@item
Using @code{AUTO_INCREMENT} will now automatically make the column
@code{NOT NULL}.
@item
Show @code{NULL} as the default value for AUTO_INCREMENT columns.
@item
Added @code{SQL_BIG_RESULT}; @code{SQL_SMALL_RESULT} is now default.
@item
Added a shared library RPM. This enchancement was contributed by David
Fox (dsfox@@cogsci.ucsd.edu).
@item
Added a @code{--enable-large-files/--disable-large-files} switch to
@code{configure}. See @file{configure.in} for some systems where this is
automatically turned off because of broken implementations.
@item
Upgraded @code{readline} to 4.0.
@item
New @code{CREATE TABLE} options: @code{PACK_KEYS} and @code{CHECKSUM}.
@item
Added @code{mysqld} option @code{--default-table-type}.
@end itemize
@node News-3.22.x, News-3.21.x, News-3.23.x, News
@appendixsec Changes in release 3.22.x
The 3.22 version has faster and safer connect code and a lot of new nice
enhancements. The reason for not including these changes in the 3.21 version
is mainly that we are trying to avoid big changes to 3.21 to keep it as
stable as possible. As there aren't really any MAJOR changes, upgrading to
3.22 should be very easy and painless.
@xref{Upgrading-from-3.21}.
3.22 should also be used with the new @code{DBD-mysql} (1.20xx) driver
that can use the new connect protocol!
@menu
* News-3.22.35:: Changes in release 3.22.35
* News-3.22.34:: Changes in release 3.22.34
* News-3.22.33:: Changes in release 3.22.33
* News-3.22.32:: Changes in release 3.22.32
* News-3.22.31:: Changes in release 3.22.31
* News-3.22.30:: Changes in release 3.22.30
* News-3.22.29:: Changes in release 3.22.29
* News-3.22.28:: Changes in release 3.22.28
* News-3.22.27:: Changes in release 3.22.27
* News-3.22.26:: Changes in release 3.22.26
* News-3.22.25:: Changes in release 3.22.25
* News-3.22.24:: Changes in release 3.22.24
* News-3.22.23:: Changes in release 3.22.23
* News-3.22.22:: Changes in release 3.22.22
* News-3.22.21:: Changes in release 3.22.21
* News-3.22.20:: Changes in release 3.22.20
* News-3.22.19:: Changes in release 3.22.19
* News-3.22.18:: Changes in release 3.22.18
* News-3.22.17:: Changes in release 3.22.17
* News-3.22.16:: Changes in release 3.22.16
* News-3.22.15:: Changes in release 3.22.15
* News-3.22.14:: Changes in release 3.22.14
* News-3.22.13:: Changes in release 3.22.13
* News-3.22.12:: Changes in release 3.22.12
* News-3.22.11:: Changes in release 3.22.11
* News-3.22.10:: Changes in release 3.22.10
* News-3.22.9:: Changes in release 3.22.9
* News-3.22.8:: Changes in release 3.22.8
* News-3.22.7:: Changes in release 3.22.7
* News-3.22.6:: Changes in release 3.22.6
* News-3.22.5:: Changes in release 3.22.5
* News-3.22.4:: Changes in release 3.22.4
* News-3.22.3:: Changes in release 3.22.3
* News-3.22.2:: Changes in release 3.22.2
* News-3.22.1:: Changes in release 3.22.1
* News-3.22.0:: Changes in release 3.22.0
@end menu
@node News-3.22.35, News-3.22.34, News-3.22.x, News-3.22.x
@appendixsubsec Changes in release 3.22.35
@itemize @bullet
@item
Fixed problem with @code{STD()}.
@item
Merged changes from the newest @code{ISAM} library from 3.23.
@item
Fixed problem with @code{INSERT DELAYED}.
@item
Fixed a bug core dump when using a @code{LEFT JOIN}/@code{STRAIGHT_JOIN}
on a table with only one row.
@end itemize
@node News-3.22.34, News-3.22.33, News-3.22.35, News-3.22.x
@appendixsubsec Changes in release 3.22.34
@itemize @bullet
@item
Fixed problem with @code{GROUP BY} on @code{TINYBLOB} columns; This
caused bugzilla to not show rows in some queries.
@item
Had to do total recompile of the Windows binary version as VC++ didn't
compile all relevant files for 3.22.33 :(
@end itemize
@node News-3.22.33, News-3.22.32, News-3.22.34, News-3.22.x
@appendixsubsec Changes in release 3.22.33
@itemize @bullet
@item
Fixed problems in windows when locking tables with @code{LOCK TABLE}
@item
Quicker kill of @code{SELECT DISTINCT} queries.
@end itemize
@node News-3.22.32, News-3.22.31, News-3.22.33, News-3.22.x
@appendixsubsec Changes in release 3.22.32
@itemize @bullet
@item
Fixed problem when storing numbers in timestamps.
@item
Fix problem with timezones that have half hour offsets.
@item
@code{mysqlhotcopy} - fast on-line hot-backup utility for local @strong{MySQL}
databases. By Tim Bunce.
@item
New more secure @code{mysqlaccess}. Thanks to Steve Harvey for this.
@item
Fixed security problem in the protocol regarding password checking.
@item
Fixed problem that affected queries that did arithmetic on @code{GROUP} functions.
@item
Fixed a bug in the @code{ISAM} code when deleting rows on tables with
packed indexes.
@end itemize
@node News-3.22.31, News-3.22.30, News-3.22.32, News-3.22.x
@appendixsubsec Changes in release 3.22.31
@itemize @bullet
@item
A few small fixes for the Win32 version.
@end itemize
@node News-3.22.30, News-3.22.29, News-3.22.31, News-3.22.x
@appendixsubsec Changes in release 3.22.30
@itemize @bullet
@item
Fixed optimizer problem on @code{SELECT} when using many overlapping indexes.
@item
Disabled floating point exceptions for FreeBSD to fix core dump when
doing @code{SELECT floor(pow(2,63))}.
@item
Added print of default arguments options to all clients.
@item
Fixed critical problem with the @code{WITH GRANT OPTION} option.
@item
Fixed non-critical Y2K problem when writing short date to log files.
@end itemize
@node News-3.22.29, News-3.22.28, News-3.22.30, News-3.22.x
@appendixsubsec Changes in release 3.22.29
@itemize @bullet
@item
Upgraded the configure and include files to match the latest 3.23 version.
This should increase portability and make it easier to build shared libraries.
@item
Added latest patches to mit-pthreads for NetBSD.
@item
Fixed problem with timezones that are < GMT -11.
@item
Fixed a bug when deleting packed keys in NISAM.
@item
Fixed problem that could cause @strong{MySQL} to touch freed memory when
doing very complicated @code{GROUP BY} queries.
@item
Fixed core dump if you got a crashed table where an @code{ENUM} field value
was too big.
@item
Added @code{mysqlshutdown.exe} and @code{mysqlwatch.exe} to the Windows
distribution.
@item
Fixed problem when doing @code{ORDER BY} on a reference key.
@item
Fixed that @code{INSERT DELAYED} doesn't update timestamps that are given.
@end itemize
@node News-3.22.28, News-3.22.27, News-3.22.29, News-3.22.x
@appendixsubsec Changes in release 3.22.28
@itemize @bullet
@item
Fixed problem with @code{LEFT JOIN} and @code{COUNT()} on a column which
was declared @code{NULL} + and it had a @code{DEFAULT} value.
@item
Fixed core dump problem when using @code{CONCAT()} in a @code{WHERE} clause.
@item
Fixed problem with @code{AVG()} and @code{STD()} with @code{NULL} values.
@end itemize
@node News-3.22.27, News-3.22.26, News-3.22.28, News-3.22.x
@appendixsubsec Changes in release 3.22.27
@itemize @bullet
@item
Fixed prototype in @file{my_ctype.h} when using other character sets.
@item
Some configure issues to fix problems with big file system detection.
@item
Fixed problem when sorting on big blob columns.
@item
@code{ROUND()} will now work on Win32.
@end itemize
@node News-3.22.26, News-3.22.25, News-3.22.27, News-3.22.x
@appendixsubsec Changes in release 3.22.26
@itemize @bullet
@item
Fixed core dump with empty @code{BLOB/TEXT} column to @code{REVERSE()}.
@item
Extended @code{/*! */} with version numbers.
@item
Changed @code{SUBSTRING(text FROM pos)} to conform to ANSI SQL. (Before this
construct returned the rightmost 'pos' characters).
@item
Fixed problem with @code{LOCK TABLES} combined with @code{DELETE FROM table}
@item
Fixed problem that INSERT ... SELECT didn't use SQL_BIG_TABLES.
@item
@code{SET SQL_LOW_PRIORITY_UPDATES=#} didn't work.
@item
Password wasn't updated correctly if privileges didn't change on:
@code{GRANT ... IDENTIFIED BY}
@item
Fixed range optimizer bug in
@code{SELECT * FROM table_name WHERE key_part1 >= const AND (key_part2 = const OR key_part2 = const)}
@item
Fixed bug in compression key handling in ISAM.
@end itemize
@node News-3.22.25, News-3.22.24, News-3.22.26, News-3.22.x
@appendixsubsec Changes in release 3.22.25
@itemize @bullet
@item
Fixed some small problems with the installation.
@end itemize
@node News-3.22.24, News-3.22.23, News-3.22.25, News-3.22.x
@appendixsubsec Changes in release 3.22.24
@itemize @bullet
@item
@code{DATA} is not a reserved word anymore.
@item
Fixed optimizer bug with tables with only one row.
@item
Fixed bug when using @code{LOCK TABLES table_name READ; FLUSH TABLES;}
@item
Applied some patches for HP-UX.
@item
@code{isamchk} should now work on Win32.
@item
Changed @file{configure} to not use big file handling on Linux as this
crashes some RedHat 6.0 systems
@end itemize
@node News-3.22.23, News-3.22.22, News-3.22.24, News-3.22.x
@appendixsubsec Changes in release 3.22.23
@itemize @bullet
@item
Upgraded to use Autoconf 2.13, Automake 1.4 and @code{libtool} 1.3.2.
@item
Better support for SCO in @code{configure}.
@item
Added option @code{--defaults-file=###} to option file handling to force use
of only one specific option file.
@item
Extended @code{CREATE} syntax to ignore @strong{MySQL} 3.23 keywords.
@item
Fixed deadlock problem when using @code{INSERT DELAYED} on a table locked with
@code{LOCK TABLES}.
@item
Fixed deadlock problem when using @code{DROP TABLE} on a table that was
locked by another thread.
@item
Add logging of @code{GRANT/REVOKE} commands in the update log.
@item
Fixed @code{isamchk} to detect a new error condition.
@item
Fixed bug in @code{NATURAL LEFT JOIN}.
@end itemize
@node News-3.22.22, News-3.22.21, News-3.22.23, News-3.22.x
@appendixsubsec Changes in release 3.22.22
@itemize @bullet
@item
Fixed problem in the C API when you called @code{mysql_close()} directly after
@code{mysql_init()}.
@item
Better client error message when you can't open socket.
@item
Fixed @code{delayed_insert_thread} counting when you couldn't create a new
delayed_insert thread.
@item
Fixed bug in @code{CONCAT()} with many arguments.
@item
Added patches for DEC 3.2 and SCO.
@item
Fixed path-bug when installing @strong{MySQL} as a service on NT.
@item
The @strong{MySQL}-Win32 version is now compiled with VC++ 6.0 instead of
with VC++ 5.0.
@item
New installation setup for @strong{MySQL}-Win32.
@end itemize
@node News-3.22.21, News-3.22.20, News-3.22.22, News-3.22.x
@appendixsubsec Changes in release 3.22.21
@itemize @bullet
@item
Fixed problem with @code{DELETE FROM TABLE} when table was locked by
another thread.
@item
Fixed bug in @code{LEFT JOIN} involving empty tables.
@item
Changed the @code{mysql.db} column from @code{char(32)} to @code{char(60)}.
@item
@code{MODIFY} and @code{DELAYED} are not reserved words anymore.
@item
Fixed a bug when storing days in a @code{TIME} column.
@item
Fixed a problem with @code{Host '..' is not allowed to connect to this MySQL
server} after one had inserted a new @strong{MySQL} user with a @code{GRANT}
command.
@item
Changed to use @code{TCP_NODELAY} also on Linux (Should give faster TCP/IP
connections).
@end itemize
@node News-3.22.20, News-3.22.19, News-3.22.21, News-3.22.x
@appendixsubsec Changes in release 3.22.20
@itemize @bullet
@item
Fixed @code{STD()} for big tables when result should be 0.
@item
The update log didn't have newlines on some operating systems.
@item
@code{INSERT DELAYED} had some garbage at end in the update log.
@end itemize
@node News-3.22.19, News-3.22.18, News-3.22.20, News-3.22.x
@appendixsubsec Changes in release 3.22.19
@itemize @bullet
@item
Fixed bug in @code{mysql_install_db} (from 3.22.17).
@item
Changed default key cache size to 8M.
@item
Fixed problem with queries that needed temporary tables with @code{BLOB}
columns.
@end itemize
@node News-3.22.18, News-3.22.17, News-3.22.19, News-3.22.x
@appendixsubsec Changes in release 3.22.18
@itemize @bullet
@item
Fixes a fatal problem in 3.22.17 on Linux; After @code{shutdown}
all threads didn't die properly.
@item
Added option @code{-O flush_time=#} to @code{mysqld}. This is mostly
useful on Win32 and tells how often @strong{MySQL} should close all
unused tables and flush all updated tables to disk.
@item
Fixed problem that a @code{VARCHAR} column compared with @code{CHAR} column
didn't use keys efficiently.
@end itemize
@node News-3.22.17, News-3.22.16, News-3.22.18, News-3.22.x
@appendixsubsec Changes in release 3.22.17
@itemize @bullet
@item
Fixed a core dump problem when using @code{--log-update} and connecting
without a default database.
@item
Fixed some @code{configure} and portability problems.
@item
Using @code{LEFT JOIN} on tables that had circular dependencies caused
@code{mysqld} to hang forever.
@end itemize
@node News-3.22.16, News-3.22.15, News-3.22.17, News-3.22.x
@appendixsubsec Changes in release 3.22.16
@itemize @bullet
@item
@code{mysqladmin processlist} could kill the server if a new user logged in.
@item
@code{DELETE FROM tbl_name WHERE key_column=col_name} didn't find any matching
rows. Fixed.
@item
@code{DATE_ADD(column,...)} didn't work.
@item
@code{INSERT DELAYED} could deadlock with status 'upgrading lock'
@item
Extended @code{ENCRYPT()} to take longer salt strings than 2 characters.
@item
@code{longlong2str} is now much faster than before. For @code{Intel x86}
platforms, this function is written in optimized assembler.
@item
Added the @code{MODIFY} keyword to @code{ALTER TABLE}.
@end itemize
@node News-3.22.15, News-3.22.14, News-3.22.16, News-3.22.x
@appendixsubsec Changes in release 3.22.15
@itemize @bullet
@item
@code{GRANT} used with @code{IDENTIFIED BY} didn't take effect until privileges
were flushed.
@item
Name change of some variables in @code{SHOW STATUS}.
@item
Fixed problem with @code{ORDER BY} with 'only index' optimization when there
were multiple key definitions for a used column.
@item
@code{DATE} and @code{DATETIME} columns are now up to 5 times faster than
before.
@item
@code{INSERT DELAYED} can be used to let the client do other things while the
server inserts rows into a table.
@item
@code{LEFT JOIN USING (col1,col2)} didn't work if one used it with tables
from 2 different databases.
@item
@code{LOAD DATA LOCAL INFILE} didn't work in the Unix version because of
a missing file.
@item
Fixed problems with @code{VARCHAR}/@code{BLOB} on very short rows (< 4 bytes);
error 127 could occur when deleting rows.
@item
Updating @code{BLOB/TEXT} through formulas didn't work for short (< 256 char)
strings.
@item
When you did a @code{GRANT} on a new host, @code{mysqld} could die on the first
connect from this host.
@item
Fixed bug when one used @code{ORDER BY} on column name that was the same
name as an alias.
@item
Added @code{BENCHMARK(loop_count,expression)} function to time expressions.
@end itemize
@node News-3.22.14, News-3.22.13, News-3.22.15, News-3.22.x
@appendixsubsec Changes in release 3.22.14
@itemize @bullet
@item
Allow empty arguments to @code{mysqld} to make it easier to start from shell
scripts.
@item
Setting a @code{TIMESTAMP} column to @code{NULL} didn't record the timestamp
value in the update log.
@item
Fixed lock handler bug when one did
@code{INSERT INTO TABLE ... SELECT ... GROUP BY}.
@item
Added a patch for @code{localtime_r()} on Win32 so that it will not crash
anymore if your date is > 2039, but instead will return a time of all zero.
@item
Names for
user-defined functions are no longer case sensitive.
@item
Added escape of @code{^Z} (ASCII 26) to @code{\Z} as @code{^Z} doesn't
work with pipes on Win32.
@item
@code{mysql_fix_privileges} adds a new column to the @code{mysql.func} to
support aggregate UDF functions in future @strong{MySQL} releases.
@end itemize
@node News-3.22.13, News-3.22.12, News-3.22.14, News-3.22.x
@appendixsubsec Changes in release 3.22.13
@itemize @bullet
@item
Saving @code{NOW()}, @code{CURDATE()} or @code{CURTIME()} directly in a
column didn't work.
@item
@code{SELECT COUNT(*) ... LEFT JOIN ...} didn't work with no @code{WHERE} part.
@item
Updated @file{config.guess} to allow @strong{MySQL} to configure on
UnixWare 7.0.x.
@item
Changed the implementation of @code{pthread_cond()} on the Win32 version.
@code{get_lock()} now correctly times out on Win32!
@end itemize
@node News-3.22.12, News-3.22.11, News-3.22.13, News-3.22.x
@appendixsubsec Changes in release 3.22.12
@itemize @bullet
@item
Fixed problem when using @code{DATE_ADD()} and @code{DATE_SUB()} in a
@code{WHERE} clause.
@item
You can now set the password for a user with the @code{GRANT ... TO user
IDENTIFIED BY 'password'} syntax.
@item
Fixed bug in @code{GRANT} checking with @code{SELECT} on many tables.
@item
Added missing file @code{mysql_fix_privilege_tables} to the RPM
distribution. This is not run by default because it relies on the client
package.
@item
Added option @code{SQL_SMALL_RESULT} to @code{SELECT} to force use of
fast temporary tables when you know that the result set will be small.
@item
Allow use of negative real numbers without a decimal point.
@item
Day number is now adjusted to maximum days in month if the resulting month
after @code{DATE_ADD}/@code{DATE_SUB()} doesn't have enough days.
@item
Fix that @code{GRANT} compares columns in case-insensitive fashion.
@item
Fixed a bug in @file{sql_list.h} that made @code{ALTER TABLE} dump core in
some contexts.
@item
The hostname in @code{user@@hostname} can now include @samp{.} and @samp{-}
without quotes in the context of the @code{GRANT}, @code{REVOKE} and
@code{SET PASSWORD FOR ...} statements.
@item
Fix for @code{isamchk} for tables which need big temporary files.
@end itemize
@node News-3.22.11, News-3.22.10, News-3.22.12, News-3.22.x
@appendixsubsec Changes in release 3.22.11
@itemize @bullet
@item
@strong{IMPORTANT}: You must run the @code{mysql_fix_privilege_tables} script
when you upgrade to this version! This is needed because of the new
@code{GRANT} system. If you don't do this, you will get @code{Access
denied} when you try to use @code{ALTER TABLE}, @code{CREATE INDEX} or
@code{DROP INDEX}.
@item
@code{GRANT} to allow/deny users table and column access.
@item
Changed @code{USER()} to return @code{user@@host}
@item
Changed the syntax for how to set @code{PASSWORD} for another user.
@item
New command @code{FLUSH STATUS} that sets most status variables to zero.
@item
New status variables: @code{aborted_threads}, @code{aborted_connects}.
@item
New option variable: @code{connection_timeout}.
@item
Added support for Thai sorting (by Pruet Boonma
@email{pruet@@ds90.intanon.nectec.or.th}).
@item
Slovak and japanese error messages.
@item
Configuration and portability fixes.
@item
Added option @code{SET SQL_WARNINGS=1} to get a warning count also for simple
inserts.
@item
@strong{MySQL} now uses @code{SIGTERM} instead of @code{SIGQUIT} with
shutdown to work better on FreeBSD.
@item
Added option @code{\G} (print vertically) to @code{mysql}.
@item
@code{SELECT HIGH_PRIORITY} ... killed @code{mysqld}.
@item
@code{IS NULL} on a @code{AUTO_INCREMENT} column in a @code{LEFT JOIN} didn't
work as expected.
@item
New function @code{MAKE_SET()}.
@end itemize
@node News-3.22.10, News-3.22.9, News-3.22.11, News-3.22.x
@appendixsubsec Changes in release 3.22.10
@itemize @bullet
@item
@code{mysql_install_db} no longer starts the @strong{MySQL} server! You
should start @code{mysqld} with @code{safe_mysqld} after installing it! The
@strong{MySQL} RPM will however start the server as before.
@item
Added @code{--bootstrap} option to @code{mysqld} and recoded
@code{mysql_install_db} to use it. This will make it easier to install
@strong{MySQL} with RPMs.
@item
Changed @code{+}, @code{-} (sign and minus), @code{*}, @code{/}, @code{%},
@code{ABS()} and @code{MOD()} to be @code{BIGINT} aware (64-bit safe).
@item
Fixed a bug in @code{ALTER TABLE} that caused @code{mysqld} to crash.
@item
@strong{MySQL} now always reports the conflicting key values when a
duplicate key entry occurs. (Before this was only reported for @code{INSERT}).
@item
New syntax: @code{INSERT INTO tbl_name SET col_name=value,col_name=value,...}
@item
Most errors in the @file{.err} log are now prefixed with a time stamp.
@item
Added option @code{MYSQL_INIT_COMMAND} to @code{mysql_options()} to make
a query on connect or reconnect.
@item
Added option @code{MYSQL_READ_DEFAULT_FILE} and
@code{MYSQL_READ_DEFAULT_GROUP} to @code{mysql_options()} to read the
following parameters from the @strong{MySQL} option files: @code{port},
@code{socket}, @code{compress}, @code{password}, @code{pipe}, @code{timeout},
@code{user}, @code{init-command}, @code{host} and @code{database}.
@item
Added @code{maybe_null} to the UDF structure.
@item
Added option @code{IGNORE} to @code{INSERT} statemants with many rows.
@item
Fixed some problems with sorting of the koi8 character sets; Users of koi8
@strong{MUST} run @code{isamchk -rq} on each table that has an index on
a @code{CHAR} or @code{VARCHAR} column.
@item
New script @code{mysql_setpermission}, by Luuk de Boer, allows one
to easily create new users with permissions for specific databases.
@item
Allow use of hexadecimal strings (0x...) when specifying a constant string
(like in the column separators with @code{LOAD DATA INFILE}).
@item
Ported to OS/2 (thanks to Antony T. Curtis @email{antony.curtis@@olcs.net}).
@item
Added more variables to @code{SHOW STATUS} and changed format of output to
be like @code{SHOW VARIABLES}.
@item
Added @code{extended-status} command to @code{mysqladmin} which will show the
new status variables.
@end itemize
@node News-3.22.9, News-3.22.8, News-3.22.10, News-3.22.x
@appendixsubsec Changes in release 3.22.9
@itemize @bullet
@item
@code{SET SQL_LOG_UPDATE=0} caused a lockup of the server.
@item
New SQL command: @code{FLUSH [ TABLES | HOSTS | LOGS | PRIVILEGES ] [, ...]}
@item
New SQL command: @code{KILL} @code{thread_id}.
@item
Added casts and changed include files to make @strong{MySQL} easier to
compile on AIX and DEC OSF1 4.x
@item
Fixed conversion problem when using @code{ALTER TABLE} from a @code{INT}
to a short @code{CHAR()} column.
@item
Added @code{SELECT HIGH_PRIORITY}; This will get a lock for the
@code{SELECT} even if there is a thread waiting for another
@code{SELECT} to get a @code{WRITE LOCK}.
@item
Moved wild_compare to string class to be able to use @code{LIKE} on
@code{BLOB}/@code{TEXT} columns with @code{\0}.
@item
Added @code{ESCAPE} option to @code{LIKE}.
@item
Added a lot more output to @code{mysqladmin debug}.
@item
You can now start @code{mysqld} on Win32 with the @code{--flush} option.
This will flush all tables to disk after each update. This makes things
much safer on NT/Win98 but also @strong{MUCH} slower.
@end itemize
@node News-3.22.8, News-3.22.7, News-3.22.9, News-3.22.x
@appendixsubsec Changes in release 3.22.8
@itemize @bullet
@item
Czech character sets should now work much better. You must also install
@uref{http://www.mysql.com/Downloads/Patches/czech-3.22.8-patch}.
This patch should also be installed if you are using a character set with
uses @code{my_strcoll()}! The patch should always be safe to install (for any system),
but as this patch changes ISAM internals it's not yet in the default
distribution.
@item
@code{DATE_ADD()} and @code{DATE_SUB()} didn't work with group functions.
@item
@code{mysql} will now also try to reconnect on @code{USE DATABASE} commands.
@item
Fix problem with @code{ORDER BY} and @code{LEFT JOIN} and @code{const} tables.
@item
Fixed problem with @code{ORDER BY} if the first @code{ORDER BY} column
was a key and the rest of the @code{ORDER BY} columns wasn't part of the key.
@item
Fixed a big problem with @code{OPTIMIZE TABLE}.
@item
@strong{MySQL} clients on NT will now by default first try to connect with
named pipes and after this with TCP/IP.
@item
Fixed a problem with @code{DROP TABLE} and @code{mysqladmin shutdown} on Win32
(a fatal bug from 3.22.6).
@item
Fixed problems with @code{TIME columns} and negative strings.
@item
Added an extra thread signal loop on shutdown to avoid some error messages
from the client.
@item
@strong{MySQL} now uses the next available number as extension for the update
log file.
@item
Added patches for UNIXWARE 7.
@end itemize
@node News-3.22.7, News-3.22.6, News-3.22.8, News-3.22.x
@appendixsubsec Changes in release 3.22.7
@itemize @bullet
@item
Added @code{LIMIT} clause for the @code{DELETE} statement.
@item
You can now use the @code{/*! ... */} syntax to hide @strong{MySQL}-specific
keywords when you write portable code. @strong{MySQL} will parse the code
inside the comments as if the surrounding @code{/*!} and @code{*/} comment
characters didn't exist.
@item
@code{OPTIMIZE TABLE tbl_name} can now be used to reclaim disk space
after many deletes. Currently, this uses @code{ALTER TABLE} to
re-generate the table, but in the future it will use an integrated
@code{isamchk} for more speed.
@item
Upgraded @code{libtool} to get the configure more portable.
@item
Fixed slow @code{UPDATE} and @code{DELETE} operations when using
@code{DATETIME} or @code{DATE} keys.
@item
Changed optimizer to make it better at deciding when to do a full join
and when using keys.
@item
You can now use @code{mysqladmin proc} to display information about your own
threads. Only users with the @strong{Process_priv} privilege can get
information about all threads.
@item
Added handling of formats @code{YYMMDD}, @code{YYYYMMDD},
@code{YYMMDDHHMMSS} for numbers when using @code{DATETIME} and
@code{TIMESTAMP} types. (Formerly these formats only worked with strings.)
@item
Added connect option @code{CLIENT_IGNORE_SPACE} to allow use of spaces
after function names and before @samp{(} (Powerbuilder requires this).
This will make all function names reserved words.
@item
Added the @code{--log-long-format} option to @code{mysqld} to enable timestamps
and INSERT_ID's in the update log.
@item
Added @code{--where} option to @code{mysqldump} (patch by Jim Faucette).
@item
The lexical analyzer now uses ``perfect hashing'' for faster parsing of SQL
statements.
@end itemize
@node News-3.22.6, News-3.22.5, News-3.22.7, News-3.22.x
@appendixsubsec Changes in release 3.22.6
@itemize @bullet
@item
Faster @code{mysqldump}.
@item
For the @code{LOAD DATA INFILE} statement, you can now use the new @code{LOCAL}
keyword to read the file from the client. @code{mysqlimport} will
automatically use @code{LOCAL} when importing with the TCP/IP protocol.
@item
Fixed small optimize problem when updating keys.
@item
Changed makefiles to support shared libraries.
@item
@strong{MySQL}-NT can now use named pipes, which means that you can now use
@strong{MySQL}-NT without having to install TCP/IP.
@end itemize
@node News-3.22.5, News-3.22.4, News-3.22.6, News-3.22.x
@appendixsubsec Changes in release 3.22.5
@itemize @bullet
@item
All table lock handing is changed to avoid some very subtle
deadlocks when using @code{DROP TABLE}, @code{ALTER TABLE}, @code{DELETE FROM
TABLE} and @code{mysqladmin flush-tables} under heavy usage.
Changed locking code to get better handling of locks of different types.
@item
Updated @code{DBI} to 1.00 and @code{DBD} to 1.2.0.
@item
Added a check that the error message file contains error messages suitable for
the current version of @code{mysqld}. (To avoid errors if you accidentally
try to use an old error message file.)
@item
All count structures in the client (@code{affected_rows()},
@code{insert_id()},...) are now of type @code{BIGINT} to allow 64-bit values
to be used.
This required a minor change in the @strong{MySQL} protocol which should affect
only old clients when using tables with @code{AUTO_INCREMENT} values > 24M.
@item
The return type of @code{mysql_fetch_lengths()} has changed from @code{uint *}
to @code{ulong *}. This may give a warning for old clients but should work
on most machines.
@item
Change @code{mysys} and @code{dbug} libraries to allocate all thread variables
in one struct. This makes it easier to make a threaded @file{libmysql.dll}
library.
@item
Use the result from @code{gethostname()} (instead of @code{uname()}) when
constructing @file{.pid} file names.
@item
New better compressed server/client protocol.
@item
@code{COUNT()}, @code{STD()} and @code{AVG()} are extended to handle more than
4G rows.
@item
You can now store values in the range @code{-838:59:59} <= x <=
@code{838:59:59} in a @code{TIME} column.
@item
@strong{WARNING: INCOMPATIBLE CHANGE!!}
If you set a @code{TIME} column to too short a value, @strong{MySQL} now
assumes the value is given as: @code{[[[D ]HH:]MM:]SS} instead of
@code{HH[:MM[:SS]]}.
@item
@code{TIME_TO_SEC()} and @code{SEC_TO_TIME()} can now handle negative times
and hours up to 32767.
@item
Added new option
@code{SET OPTION SQL_LOG_UPDATE=@{0|1@}} to allow users with
the @strong{process} privilege to bypass the update log.
(Modified patch from Sergey A Mukhin @email{violet@@rosnet.net}.)
@item
Fixed fatal bug in @code{LPAD()}.
@item
Initialize line buffer in @file{mysql.cc} to make @code{BLOB} reading from
pipes safer.
@item
Added @code{-O max_connect_errors=#} option to @code{mysqld}.
Connect errors are now reset for each correct connection.
@item
Increased the default value of @code{max_allowed_packet} to @code{1M} in
@code{mysqld}.
@item
Added @code{--low-priority-updates} option to @code{mysqld}, to give
table-modifying operations (@code{INSERT}, @code{REPLACE}, @code{UPDATE},
@code{DELETE}) lower priority than retrievals. You can now use
@code{@{INSERT | REPLACE | UPDATE | DELETE@} LOW_PRIORITY ...} You can
also use @code{SET OPTION SQL_LOW_PRIORITY_UPDATES=@{0|1@}} to change
the priority for one thread. One side effect is that @code{LOW_PRIORITY}
is now a reserved word. :(
@item
Add support for @code{INSERT INTO table ... VALUES(...),(...),(...)},
to allow inserting multiple rows with a single statement.
@item
@code{INSERT INTO tbl_name} is now also cached when used with @code{LOCK TABLES}.
(Previously only @code{INSERT ... SELECT} and @code{LOAD DATA INFILE} were
cached.)
@item
Allow @code{GROUP BY} functions with @code{HAVING}:
@example
mysql> SELECT col FROM table GROUP BY col HAVING COUNT(*)>0;
@end example
@item
@code{mysqld} will now ignore trailing @samp{;} characters in queries. This
is to make it easier to migrate from some other SQL servers that require the
trailing @samp{;}.
@item
Fix for corrupted fixed-format output generated by @code{SELECT INTO OUTFILE}.
@item
@strong{WARNING: INCOMPATIBLE CHANGE!!}
Added Oracle @code{GREATEST()} and @code{LEAST()} functions. You must now use
these instead of the @code{MAX()} and @code{MIN()} functions to get the
largest/smallest value from a list of values. These can now handle @code{REAL},
@code{BIGINT} and string (@code{CHAR} or @code{VARCHAR}) values.
@item
@strong{WARNING: INCOMPATIBLE CHANGE!!}
@code{DAYOFWEEK()} had offset 0 for Sunday. Changed the offset to 1.
@item
Give an error for queries that mix @code{GROUP BY} columns and fields when
there is no @code{GROUP BY} specification.
@item
Added @code{--vertical} option to @code{mysql}, for printing results in
vertical mode.
@item
Index-only optimization; some queries are now resolved using
only indexes. Until @strong{MySQL} 4.0, this works only for numeric columns.
@xref{MySQL indexes, , @strong{MySQL} indexes}.
@item
Lots of new benchmarks.
@item
A new C API chapter and lots of other improvements in the manual.
@end itemize
@node News-3.22.4, News-3.22.3, News-3.22.5, News-3.22.x
@appendixsubsec Changes in release 3.22.4
@itemize @bullet
@item
Added @code{--tmpdir} option to @code{mysqld}, for specifying the location
of the temporary file directory.
@item
@strong{MySQL} now automatically changes a query from an ODBC client:
@example
SELECT ... FROM table WHERE auto_increment_column IS NULL
@end example
to:
@example
SELECT ... FROM table WHERE auto_increment_column == LAST_INSERT_ID()
@end example
This allows some ODBC programs (Delphi, Access) to retrieve the newly
inserted row to fetch the @code{AUTO_INCREMENT} id.
@item
@code{DROP TABLE} now waits for all users to free a table before deleting it.
@item
Fixed small memory leak in the new connect protocol.
@item
New functions @code{BIN()}, @code{OCT()}, @code{HEX()} and @code{CONV()} for
converting between different number bases.
@item
Added function @code{SUBSTRING()} with 2 arguments.
@item
If you created a table with a record length smaller than 5, you couldn't
delete rows from the table.
@item
Added optimization to remove const reference tables from @code{ORDER BY} and
@code{GROUP BY}.
@item
@code{mysqld} now automatically disables system locking on Linux and Win32,
and for systems that use MIT-pthreads. You can force the use of locking
with the @code{--enable-locking} option.
@item
Added @code{--console} option to @code{mysqld}, to force a console window
(for error messages) when using Win32.
@item
Fixed table locks for Win32.
@item
Allow @samp{$} in identifiers.
@item
Changed name of user-specific configuration file from @file{my.cnf} to
@file{.my.cnf} (Unix only).
@item
Added @code{DATE_ADD()} and @code{DATE_SUB()} functions.
@end itemize
@node News-3.22.3, News-3.22.2, News-3.22.4, News-3.22.x
@appendixsubsec Changes in release 3.22.3
@itemize @bullet
@item
Fixed a lock problem (bug in @strong{MySQL} 3.22.1) when closing temporary tables.
@item
Added missing @code{mysql_ping()} to the client library.
@item
Added @code{--compress} option to all @strong{MySQL} clients.
@item
Changed @code{byte} to @code{char} in @file{mysql.h} and @file{mysql_com.h}.
@end itemize
@node News-3.22.2, News-3.22.1, News-3.22.3, News-3.22.x
@appendixsubsec Changes in release 3.22.2
@itemize @bullet
@item
Searching on multiple constant keys that matched more than 30% of the rows
didn't always use the best possible key.
@item
New functions @code{<<}, @code{>>}, @code{RPAD()} and @code{LPAD()}.
@item
You can now save default options (like passwords) in a configuration file
(@file{my.cnf}).
@item
Lots of small changes to get @code{ORDER BY} to work when no records are found
when using fields that are not in @code{GROUP BY} (@strong{MySQL} extension).
@item
Added @code{--chroot} option to @code{mysqld}, to start @code{mysqld} in
a chroot environment (by Nikki Chumakov @email{nikkic@@cityline.ru}).
@item
Trailing spaces are now ignored when comparing case-sensitive strings;
this should fix some problems with ODBC and flag 512!
@item
Fixed a core-dump bug in the range optimizer.
@item
Added @code{--one-thread} option to @code{mysqld}, for debugging with
LinuxThreads (or @code{glibc}). (This replaces the @code{-T32} flag)
@item
Added @code{DROP TABLE IF EXISTS} to prevent an error from occurring if the
table doesn't exist.
@item
@code{IF} and @code{EXISTS} are now reserved words (they would have to
be sooner or later).
@item
Added lots of new options to @code{mysqldump}.
@item
Server error messages are now in @file{mysqld_error.h}.
@item
The server/client protocol now supports compression.
@item
All bug fixes from @strong{MySQL} 3.21.32.
@end itemize
@node News-3.22.1, News-3.22.0, News-3.22.2, News-3.22.x
@appendixsubsec Changes in release 3.22.1
@itemize @bullet
@item
Added new C API function @code{mysql_ping()}.
@item
Added new API functions @code{mysql_init()} and @code{mysql_options()}.
You now MUST call @code{mysql_init()} before you call
@code{mysql_real_connect()}.
You don't have to call @code{mysql_init()} if you only use
@code{mysql_connect()}.
@item
Added @code{mysql_options(...,MYSQL_OPT_CONNECT_TIMEOUT,...)} so you can set a
timeout for connecting to a server.
@item
Added @code{--timeout} option to @code{mysqladmin}, as a test of
@code{mysql_options()}.
@item
Added @code{AFTER column} and @code{FIRST} options to
@code{ALTER TABLE ... ADD columns}.
This makes it possible to add a new column at some specific location
within a row in an existing table.
@item
@code{WEEK()} now takes an optional argument to allow handling of weeks when
the week starts on Monday (some European countries). By default,
@code{WEEK()} assumes the week starts on Sunday.
@item
@code{TIME} columns weren't stored properly (bug in @strong{MySQL} 3.22.0).
@item
@code{UPDATE} now returns information about how many rows were
matched and updated, and how many ``warnings'' occurred when doing the update.
@item
Fixed incorrect result from @code{FORMAT(-100,2)}.
@item
@code{ENUM} and @code{SET} columns were compared in binary (case-sensitive)
fashion; changed to be case insensitive.
@end itemize
@node News-3.22.0, , News-3.22.1, News-3.22.x
@appendixsubsec Changes in release 3.22.0
@itemize @bullet
@item
New (backward compatible) connect protocol that allows you to
specify the database to use when connecting, to get much faster
connections to a specific database.
The @code{mysql_real_connect()} call is changed to:
@example
mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
const char *passwd, const char *db, uint port,
const char *unix_socket, uint client_flag)
@end example
@item
Each connection is handled by its own thread, rather than by the
master @code{accept()} thread. This fixes permanently the telnet bug
that was a topic on the mail list some time ago.
@item
All TCP/IP connections are now checked with backward resolution of
the hostname to get better security. @code{mysqld} now has a local hostname
resolver cache so connections should actually be faster than before,
even with this feature.
@item
A site automatically will be blocked from future connections if someone
repeatedly connects with an ``improper header'' (like when one uses telnet).
@item
You can now refer to tables in different databases with references of the form
@code{tbl_name@@db_name} or @code{db_name.tbl_name}. This makes it possible to
give a user read access to some tables and write access to others simply by
keeping them in different databases!
@item
Added @code{--user} option to @code{mysqld}, to allow it to run
as another Unix user (if it is started as the Unix @code{root} user).
@item
Added caching of users and access rights (for faster access rights checking)
@item
Normal users (not anonymous ones) can change their password with
@code{mysqladmin password 'new_password'}. This uses encrypted passwords
that are not logged in the normal @strong{MySQL} log!
@item
All important string functions are now coded in assembler for x86 Linux
machines. This gives a speedup of 10% in many cases.
@item
For tables that have many columns, the column names are now hashed for
much faster column name lookup (this will speed up some benchmark
tests a lot!)
@item
Some benchmarks are changed to get better individual timing.
(Some loops were so short that a specific test took < 2 seconds. The
loops have been changed to take about 20 seconds to make it easier
to compare different databases. A test that took 1-2 seconds before
now takes 11-24 seconds, which is much better)
@item
Re-arranged @code{SELECT} code to handle some very specific queries
involving group functions (like @code{COUNT(*)}) without a @code{GROUP BY} but
with @code{HAVING}. The following now works:
@example
mysql> SELECT count(*) as C FROM table HAVING C > 1;
@end example
@item
Changed the protocol for field functions to be faster and avoid some
calls to @code{malloc()}.
@item
Added @code{-T32} option to @code{mysqld}, for running all queries under the
main thread. This makes it possible to debug @code{mysqld} under Linux with
@code{gdb}!
@item
Added optimization of @code{not_null_column IS NULL} (needed for some Access
queries).
@item
Allow @code{STRAIGHT_JOIN} to be used between two tables to force the optimizer
to join them in a specific order.
@item
String functions now return @code{VARCHAR} rather than @code{CHAR} and
the column type is now @code{VARCHAR} for fields saved as @code{VARCHAR}.
This should make the @strong{MyODBC} driver better, but may break some old
@strong{MySQL} clients that don't handle @code{FIELD_TYPE_VARCHAR} the same
way as @code{FIELD_TYPE_CHAR}.
@item
@code{CREATE INDEX} and @code{DROP INDEX} are now implemented through
@code{ALTER TABLE}.
@code{CREATE TABLE} is still the recommended (fast) way to create indexes.
@item
Added @code{--set-variable} option @code{wait_timeout} to @code{mysqld}.
@item
Added time column to @code{mysqladmin processlist} to show how long a query
has taken or how long a thread has slept.
@item
Added lots of new variables to @code{show variables} and some new to
@code{show status}.
@item
Added new type @code{YEAR}. @code{YEAR} is stored in 1 byte with allowable
values of 0, and 1901 to 2155.
@item
Added new @code{DATE} type that is stored in 3 bytes rather than 4 bytes.
All new tables are created with the new date type if you don't use the
@code{--old-protocol} option to @code{mysqld}.
@item
Fixed bug in record caches; for some queries, you could get
@code{Error from table handler: #} on some operating systems.
@item
Added @code{--enable-assembler} option to @code{configure}, for x86 machines
(tested on Linux + @code{gcc}). This will enable assembler functions for the
most important string functions for more speed!
@end itemize
@node News-3.21.x, News-3.20.x, News-3.22.x, News
@appendixsec Changes in release 3.21.x
@menu
* News-3.21.33:: Changes in release 3.21.33
* News-3.21.32:: Changes in release 3.21.32
* News-3.21.31:: Changes in release 3.21.31
* News-3.21.30:: Changes in release 3.21.30
* News-3.21.29:: Changes in release 3.21.29
* News-3.21.28:: Changes in release 3.21.28
* News-3.21.27:: Changes in release 3.21.27
* News-3.21.26:: Changes in release 3.21.26
* News-3.21.25:: Changes in release 3.21.25
* News-3.21.24:: Changes in release 3.21.24
* News-3.21.23:: Changes in release 3.21.23
* News-3.21.22:: Changes in release 3.21.22
* News-3.21.21a:: Changes in release 3.21.21a
* News-3.21.21:: Changes in release 3.21.21
* News-3.21.20:: Changes in release 3.21.20
* News-3.21.19:: Changes in release 3.21.19
* News-3.21.18:: Changes in release 3.21.18
* News-3.21.17:: Changes in release 3.21.17
* News-3.21.16:: Changes in release 3.21.16
* News-3.21.15:: Changes in release 3.21.15
* News-3.21.14b:: Changes in release 3.21.14b
* News-3.21.14a:: Changes in release 3.21.14a
* News-3.21.13:: Changes in release 3.21.13
* News-3.21.12:: Changes in release 3.21.12
* News-3.21.11:: Changes in release 3.21.11
* News-3.21.10:: Changes in release 3.21.10
* News-3.21.9:: Changes in release 3.21.9
* News-3.21.8:: Changes in release 3.21.8
* News-3.21.7:: Changes in release 3.21.7
* News-3.21.6:: Changes in release 3.21.6
* News-3.21.5:: Changes in release 3.21.5
* News-3.21.4:: Changes in release 3.21.4
* News-3.21.3:: Changes in release 3.21.3
* News-3.21.2:: Changes in release 3.21.2
* News-3.21.0:: Changes in release 3.21.0
@end menu
@node News-3.21.33, News-3.21.32, News-3.21.x, News-3.21.x
@appendixsubsec Changes in release 3.21.33
@itemize @bullet
@item
Fixed problem when sending @code{SIGHUP} to @code{mysqld};
@code{mysqld} core dumped when starting from boot on some systems.
@item
Fixed problem with losing a little memory for some connections.
@item
@code{DELETE FROM tbl_name} without a @code{WHERE} condition is now done the
long way when you use @code{LOCK TABLES} or if the table is in use, to
avoid race conditions.
@item
@code{INSERT INTO TABLE (timestamp_column) VALUES (NULL);} didn't set timestamp.
@end itemize
@node News-3.21.32, News-3.21.31, News-3.21.33, News-3.21.x
@appendixsubsec Changes in release 3.21.32
@itemize @bullet
@item
Fixed some possible race conditions when doing many reopen/close on the same
tables under heavy load! This can happen if you execute @code{mysqladmin
refresh} often. This could in some very rare cases corrupt the header of the
index file and cause error 126 or 138.
@item
Fixed fatal bug in @code{refresh()} when running with the
@code{--skip-locking} option. There was a ``very small'' time gap after
a @code{mysqladmin refresh} when a table could be corrupted if one
thread updated a table while another thread did @code{mysqladmin
refresh} and another thread started a new update ont the same table
before the first thread had finished. A refresh (or
@code{--flush-tables}) will now not return until all used tables are
closed!
@item
@code{SELECT DISTINCT} with a @code{WHERE} clause that didn't match any rows
returned a row in some contexts (bug only in 3.21.31).
@item
@code{GROUP BY} + @code{ORDER BY} returned one empty row when no rows where
found.
@item
Fixed a bug in the range optimizer that wrote
@code{Use_count: Wrong count for ...} in the error log file.
@end itemize
@node News-3.21.31, News-3.21.30, News-3.21.32, News-3.21.x
@appendixsubsec Changes in release 3.21.31
@itemize @bullet
@item
Fixed a sign extension problem for the @code{TINYINT} type on Irix.
@item
Fixed problem with @code{LEFT("constant_string",function)}.
@item
Fixed problem with @code{FIND_IN_SET()}.
@item
@code{LEFT JOIN} core dumped if the second table is used with a constant
@code{WHERE/ON} expression that uniquely identifies one record.
@item
Fixed problems with @code{DATE_FORMAT()} and incorrect dates.
@code{DATE_FORMAT()} now ignores @code{'%'} to make it possible to extend
it more easily in the future.
@end itemize
@node News-3.21.30, News-3.21.29, News-3.21.31, News-3.21.x
@appendixsubsec Changes in release 3.21.30
@itemize @bullet
@item
@code{mysql} now returns an exit code > 0 if the query returned an error.
@item
Saving of command line history to file in @code{mysql} client.
By Tommy Larsen @email{tommy@@mix.hive.no}.
@item
Fixed problem with empty lines that were ignored in @file{mysql.cc}.
@item
Save the pid of the signal handler thread in the pid file instead
of the pid of the main thread.
@item
Added patch by @email{tommy@@valley.ne.jp} to support Japanese characters
SJIS and UJIS.
@item
Changed @code{safe_mysqld} to redirect startup messages to
@code{'hostname'.err} instead
of @code{'hostname'.log} to reclaim file space on @code{mysqladmin refresh}.
@item
@code{ENUM} always had the first entry as default value.
@item
@code{ALTER TABLE} wrote two entries to the update log.
@item
@code{sql_acc()} now closes the @code{mysql} grant tables after a reload to
save table space and memory.
@item
Changed @code{LOAD DATA} to use less memory with tables and @code{BLOB}
columns.
@item
Sorting on a function which made a division / 0 produced a wrong set
in some cases.
@item
Fixed @code{SELECT} problem with @code{LEFT()} when using the czech character
set.
@item
Fixed problem in @code{isamchk}; it couldn't repair a packed table in a very
unusual case.
@item
@code{SELECT} statements with @code{&} or @code{|} (bit functions) failed on
columns with @code{NULL} values.
@item
When comparing a field = field, where one of the fields was a part key,
only the length of the part key was compared.
@end itemize
@node News-3.21.29, News-3.21.28, News-3.21.30, News-3.21.x
@appendixsubsec Changes in release 3.21.29
@itemize @bullet
@item
@code{LOCK TABLES} + @code{DELETE from tbl_name} never removed locks properly.
@item
Fixed problem when grouping on an @code{OR} function.
@item
Fixed permission problem with @code{umask()} and creating new databases.
@item
Fixed permission problem on result file with @code{SELECT ... INTO OUTFILE ...}
@item
Fixed problem in range optimizer (core dump) for a very complex query.
@item
Fixed problem when using @code{MIN(integer)} or @code{MAX(integer)} in
@code{GROUP BY}.
@item
Fixed bug on Alpha when using integer keys. (Other keys worked on Alpha).
@item
Fixed bug in @code{WEEK("XXXX-xx-01")}.
@end itemize
@node News-3.21.28, News-3.21.27, News-3.21.29, News-3.21.x
@appendixsubsec Changes in release 3.21.28
@itemize @bullet
@item
Fixed socket permission (clients couldn't connect to Unix socket on Linux).
@item
Fixed bug in record caches; for some queries, you could get
@code{Error from table handler: #} on some operating systems.
@end itemize
@node News-3.21.27, News-3.21.26, News-3.21.28, News-3.21.x
@appendixsubsec Changes in release 3.21.27
@itemize @bullet
@item
Added user level lock functions @code{GET_LOCK(string,timeout)},
@code{RELEASE_LOCK(string)}.
@item
Added @code{opened_tables} to @code{show status}.
@item
Changed connect timeout to 3 seconds to make it somewhat harder
for crackers to kill @code{mysqld} through telnet + TCP/IP.
@item
Fixed bug in range optimizer when using
@code{WHERE key_part_1 >= something AND key_part_2 <= something_else}.
@item
Changed @code{configure} for detection of FreeBSD 3.0 9803xx and above
@item
@code{WHERE} with string_column_key = constant_string didn't always find
all rows if the column had many values differing only with characters of
the same sort value (like e and @'e).
@item
Strings keys looked up with 'ref' were not compared in case-sensitive fashion.
@item
Added @code{umask()} to make log files non-readable for normal users.
@item
Ignore users with old (8-byte) password on startup if not using
@code{--old-protocol} option to @code{mysqld}.
@item
@code{SELECT} which matched all key fields returned the values in the
case of the matched values, not of the found values. (Minor problem.)
@end itemize
@node News-3.21.26, News-3.21.25, News-3.21.27, News-3.21.x
@appendixsubsec Changes in release 3.21.26
@itemize @bullet
@item
@code{FROM_DAYS(0)} now returns "0000-00-00".
@item
In @code{DATE_FORMAT()}, PM and AM were swapped for hours 00 and 12.
@item
Extended the default maximum key size to 256.
@item
Fixed bug when using @code{BLOB}/@code{TEXT} in @code{GROUP BY} with many
tables.
@item
An @code{ENUM} field that is not declared @code{NOT NULL} has @code{NULL} as
the default value.
(Previously, the default value was the first enumeration value.)
@item
Fixed bug in the join optimizer code when using many part keys
on the same key: @code{INDEX (Organization,Surname(35),Initials(35))}.
@item
Added some tests to the table order optimizer to get some cases with
@code{SELECT ... FROM many_tables} much faster.
@item
Added a retry loop around @code{accept()} to possibly fix some problems on some
Linux machines.
@end itemize
@node News-3.21.25, News-3.21.24, News-3.21.26, News-3.21.x
@appendixsubsec Changes in release 3.21.25
@itemize @bullet
@item
Changed @code{typedef 'string'} to @code{typedef 'my_string'} for better
portability.
@item
You can now kill threads that are waiting on a disk full condition.
@item
Fixed some problems with UDF functions.
@item
Added long options to @code{isamchk}. Try @code{isamchk --help}.
@item
Fixed a bug when using 8 bytes long (alpha); @code{filesort()} didn't work.
Affects @code{DISTINCT}, @code{ORDER BY} and @code{GROUP BY} on 64-bit
processors.
@end itemize
@node News-3.21.24, News-3.21.23, News-3.21.25, News-3.21.x
@appendixsubsec Changes in release 3.21.24
@itemize @bullet
@item
Dynamic loadable functions. Based on source from Alexis Mikhailov.
@item
You couldn't delete from a table if no one had done a @code{SELECT} on the
table.
@item
Fixed problem with range optimizer with many @code{OR} operators on key parts
inside each other.
@item
Recoded @code{MIN()} and @code{MAX()} to work properly with strings and
@code{HAVING}.
@item
Changed default umask value for new files from @code{0664} to @code{0660}.
@item
Fixed problem with @code{LEFT JOIN} and constant expressions in the @code{ON}
part.
@item
Added Italian error messages from @email{brenno@@dewinter.com}.
@item
@code{configure} now works better on OSF1 (tested on 4.0D).
@item
Added hooks to allow @code{LIKE} optimization with international character
support.
@item
Upgraded @code{DBI} to 0.93.
@end itemize
@node News-3.21.23, News-3.21.22, News-3.21.24, News-3.21.x
@appendixsubsec Changes in release 3.21.23
@itemize @bullet
@item
The following symbols are now reserved words:
@code{TIME}, @code{DATE}, @code{TIMESTAMP}, @code{TEXT}, @code{BIT},
@code{ENUM}, @code{NO}, @code{ACTION}, @code{CHECK}, @code{YEAR},
@code{MONTH}, @code{DAY}, @code{HOUR}, @code{MINUTE}, @code{SECOND},
@code{STATUS}, @code{VARIABLES}.
@item
Setting a @code{TIMESTAMP} to @code{NULL} in @code{LOAD DATA INFILE ...} didn't
set the current time for the @code{TIMESTAMP}.
@item
Fix @code{BETWEEN} to recognize binary strings. Now @code{BETWEEN} is
case sensitive.
@item
Added @code{--skip-thread-priority} option to @code{mysqld}, for systems
where @code{mysqld}'s thread scheduling doesn't work properly (BSDI 3.1).
@item
Added ODBC functions @code{DAYNAME()} and @code{MONTHNAME()}.
@item
Added function @code{TIME_FORMAT()}. This works like @code{DATE_FORMAT()},
but takes a time string (@code{'HH:MM:DD'}) as argument.
@item
Fixed unlikely(?) key optimizer bug when using @code{OR}s of key parts
inside @code{AND}s.
@item
Added command @code{variables} to @code{mysqladmin}.
@item
A lot of small changes to the binary releases.
@item
Fixed a bug in the new protocol from @strong{MySQL} 3.21.20.
@item
Changed @code{ALTER TABLE} to work with Win32 (Win32 can't rename open files).
Also fixed a couple of small bugs in the Win32 version.
@item
All standard @strong{MySQL} clients are now ported to @strong{MySQL}-Win32.
@item
@strong{MySQL} can now be started as a service on NT.
@end itemize
@node News-3.21.22, News-3.21.21a, News-3.21.23, News-3.21.x
@appendixsubsec Changes in release 3.21.22
@itemize @bullet
@item
Starting with this version, all @strong{MySQL} distributions will be
configured, compiled and tested with @code{crash-me} and the benchmarks on
the following platforms: SunOS 5.6 sun4u, SunOS 5.5.1 sun4u, SunOS 4.14 sun4c,
SunOS 5.6 i86pc, Irix 6.3 mips5k, HP-UX 10.20 hppa, AIX 4.2.1 ppc,
OSF1 V4.0 alpha, FreeBSD 2.2.2 i86pc and BSDI 3.1 i386.
@item
Fix @code{COUNT(*)} problems when the @code{WHERE} clause didn't match any
records. (Bug from 3.21.17.)
@item
Removed that @code{NULL = NULL} is true. Now you must use @code{IS NULL}
or @code{IS NOT NULL} to test whether or not a value is @code{NULL}.
(This is according to ANSI SQL but may break
old applications that are ported from @code{mSQL}.)
You can get the old behavior by compiling with @code{-DmSQL_COMPLIANT}.
@item
Fixed bug that core dumped when using many @code{LEFT OUTER JOIN} clauses.
@item
Fixed bug in @code{ORDER BY} on string formula with possible @code{NULL} values.
@item
Fixed problem in range optimizer when using <= on sub index.
@item
Added functions @code{DAYOFYEAR()}, @code{DAYOFMONTH()}, @code{MONTH()},
@code{YEAR()}, @code{WEEK()}, @code{QUARTER()}, @code{HOUR()}, @code{MINUTE()},
@code{SECOND()} and @code{FIND_IN_SET()}.
@item
Added command @code{SHOW VARIABLES}.
@item
Added support of ``long constant strings'' from ANSI SQL:
@example
mysql> SELECT 'first ' 'second'; -> 'first second'
@end example
@item
Upgraded mSQL-Mysql-modules to 1.1825.
@item
Upgraded @code{mysqlaccess} to 2.02.
@item
Fixed problem with Russian character set and @code{LIKE}.
@item
Ported to OpenBSD 2.1.
@item
New Dutch error messages.
@end itemize
@node News-3.21.21a, News-3.21.21, News-3.21.22, News-3.21.x
@appendixsubsec Changes in release 3.21.21a
@itemize @bullet
@item
Configure changes for some operating systems.
@end itemize
@node News-3.21.21, News-3.21.20, News-3.21.21a, News-3.21.x
@appendixsubsec Changes in release 3.21.21
@itemize @bullet
@item
Fixed optimizer bug when using
@code{WHERE data_field = date_field2 AND date_field2 = constant}.
@item
Added command @code{SHOW STATUS}.
@item
Removed @file{manual.ps} from the source distribution to make it smaller.
@end itemize
@node News-3.21.20, News-3.21.19, News-3.21.21, News-3.21.x
@appendixsubsec Changes in release 3.21.20
@itemize @bullet
@item
Changed the maximum table name and column name lengths from 32 to 64.
@item
Aliases can now be of ``any'' length.
@item
Fixed @code{mysqladmin stat} to return the right number of queries.
@item
Changed protocol (downward compatible) to mark if a column has the
@code{AUTO_INCREMENT} attribute or is a @code{TIMESTAMP}. This is needed for
the new Java driver.
@item
Added Hebrew sorting order by Zeev Suraski.
@item
Solaris 2.6: Fixed @code{configure} bugs and increased maximum table size
from 2G to 4G.
@end itemize
@node News-3.21.19, News-3.21.18, News-3.21.20, News-3.21.x
@appendixsubsec Changes in release 3.21.19
@itemize @bullet
@item
Upgraded @code{DBD} to 1823. This version implements @code{mysql_use_result} in
@code{DBD-Mysql}.
@item
Benchmarks updated for empress (by Luuk).
@item
Fixed a case of slow range searching.
@item
Configure fixes (@file{Docs} directory).
@item
Added function @code{REVERSE()} (by Zeev Suraski).
@end itemize
@node News-3.21.18, News-3.21.17, News-3.21.19, News-3.21.x
@appendixsubsec Changes in release 3.21.18
@itemize @bullet
@item
Issue error message if client C functions are called in wrong order.
@item
Added automatic reconnect to the @file{libmysql.c} library. If a write command
fails, an automatic reconnect is done.
@item
Small sort sets no longer use temporary files.
@item
Upgraded @code{DBI} to 0.91.
@item
Fixed a couple of problems with @code{LEFT OUTER JOIN}.
@item
Added @code{CROSS JOIN} syntax. @code{CROSS} is now a reserved word.
@item
Recoded @code{yacc}/@code{bison} stack allocation to be even safer and to allow
@strong{MySQL} to handle even bigger expressions.
@item
Fixed a couple of problems with the update log.
@item
@code{ORDER BY} was slow when used with key ranges.
@end itemize
@node News-3.21.17, News-3.21.16, News-3.21.18, News-3.21.x
@appendixsubsec Changes in release 3.21.17
@itemize @bullet
@item
Changed documentation string of @code{--with-unix-socket-path} to avoid
confusion.
@item
Added ODBC and ANSI SQL style @code{LEFT OUTER JOIN}.
@item
The following are new reserved words: @code{LEFT}, @code{NATURAL},
@code{USING}.
@item
The client library now uses the value of the environment variable
@code{MYSQL_HOST} as the default host if it's defined.
@item
@code{SELECT col_name, SUM(expr)} now returns @code{NULL} for @code{col_name}
when there are matching rows.
@item
Fixed problem with comparing binary strings and @code{BLOB}s with ASCII
characters over 127.
@item
Fixed lock problem: when freeing a read lock on a table with multiple
read locks, a thread waiting for a write lock would have been given the lock.
This shouldn't affect data integrity, but could possibly make @code{mysqld}
restart if one thread was reading data that another thread modified.
@item
@code{LIMIT offset,count} didn't work in @code{INSERT ... SELECT}.
@item
Optimized key block caching. This will be quicker than the old algorithm when
using bigger key caches.
@end itemize
@node News-3.21.16, News-3.21.15, News-3.21.17, News-3.21.x
@appendixsubsec Changes in release 3.21.16
@itemize @bullet
@item
Added ODBC 2.0 & 3.0 functions @code{POWER()}, @code{SPACE()},
@code{COT()}, @code{DEGREES()}, @code{RADIANS()}, @code{ROUND(2 arg)}
and @code{TRUNCATE()}.
@item
@strong{WARNING: INCOMPATIBLE CHANGE!!} @code{LOCATE()} parameters were
swapped according to ODBC standard. Fixed.
@item
Added function @code{TIME_TO_SEC()}.
@item
In some cases, default values were not used for @code{NOT NULL} fields.
@item
Timestamp wasn't always updated properly in @code{UPDATE SET ...} statements.
@item
Allow empty strings as default values for @code{BLOB} and @code{TEXT}, to
be compatible with @code{mysqldump}.
@end itemize
@node News-3.21.15, News-3.21.14b, News-3.21.16, News-3.21.x
@appendixsubsec Changes in release 3.21.15
@itemize @bullet
@item
@strong{WARNING: INCOMPATIBLE CHANGE!!} @code{mysqlperl} is now from
Msql-Mysql-modules. This means that @code{connect()} now takes
@code{host}, @code{database}, @code{user}, @code{password} arguments! The old
version took @code{host}, @code{database}, @code{password}, @code{user}.
@item
Allow @code{DATE '1997-01-01'}, @code{TIME '12:10:10'} and
@code{TIMESTAMP '1997-01-01 12:10:10'} formats required by ANSI SQL.
@strong{WARNING: INCOMPATIBLE CHANGE!!} This has the unfortunate
side-effect that you no longer can have columns named @code{DATE}, @code{TIME}
or @code{TIMESTAMP}. :( Old columns can still be accessed through
@code{tablename.columnname}!)
@item
Changed Makefiles to hopefully work better with BSD systems. Also,
@file{manual.dvi} is now included in the distribution to avoid having stupid
@code{make} programs trying to rebuild it.
@item
@code{readline} library upgraded to version 2.1.
@item
A new sortorder german-1. That is a normal ISO-Latin1 with a german sort
order.
@item
Perl @code{DBI}/@code{DBD} is now included in the distribution. @code{DBI}
is now the recommended way to connect to @strong{MySQL} from Perl.
@item
New portable benchmark suite with @code{DBD}, with test results from
@code{mSQL} 2.0.3, @strong{MySQL}, PostgreSQL 6.2.1 and Solid server 2.2.
@item
@code{crash-me} is now included with the benchmarks; This is a Perl program
designed to find as many limits as possible in a SQL server. Tested with
@code{mSQL}, PostgreSQL, Solid and @strong{MySQL}.
@item
Fixed bug in range-optimizer that crashed @strong{MySQL} on some queries.
@item
Table and column name completion for @code{mysql} command line tool, by Zeev
Suraski and Andi Gutmans.
@item
Added new command @code{REPLACE} that works like @code{INSERT} but
replaces conflicting records with the new record. @code{REPLACE INTO
TABLE ... SELECT ...} works also.
@item
Added new commands @code{CREATE DATABASE db_name} and @code{DROP
DATABASE db_name}.
@item
Added @code{RENAME} option to @code{ALTER TABLE}: @code{ALTER TABLE name
RENAME AS new_name}.
@item
@code{make_binary_distribution} now includes @file{libgcc.a} in
@file{libmysqlclient.a}. This should make linking work for people who don't
have @code{gcc}.
@item
Changed @code{net_write()} to @code{my_net_write()} because of a name
conflict with Sybase.
@item
@cindex ODBC compatibility
@cindex Compatibility, with ODBC
New function @code{DAYOFWEEK()} compatible with ODBC.
@item
Stack checking and @code{bison} memory overrun checking to make @strong{MySQL}
safer with weird queries.
@end itemize
@node News-3.21.14b, News-3.21.14a, News-3.21.15, News-3.21.x
@appendixsubsec Changes in release 3.21.14b
@itemize @bullet
@item
Fixed a couple of small @code{configure} problems on some platforms.
@end itemize
@node News-3.21.14a, News-3.21.13, News-3.21.14b, News-3.21.x
@appendixsubsec Changes in release 3.21.14a
@itemize @bullet
@item
Ported to SCO Openserver 5.0.4 with FSU Pthreads.
@item
HP-UX 10.20 should work.
@item
Added new function @code{DATE_FORMAT()}.
@item
Added @code{NOT IN}.
@item
Added automatic removal of 'ODBC function conversions': @code{@{fn now() @}}
@item
Handle ODBC 2.50.3 option flags.
@item
Fixed comparison of @code{DATE} and @code{TIME} values with @code{NULL}.
@item
Changed language name from germany to german to be consistent with
the other language names.
@item
Fixed sorting problem on functions returning a @code{FLOAT}. Previously, the
values were converted to @code{INT}s before sorting.
@item
Fixed slow sorting when sorting on key field when using
@code{key_column=constant}.
@item
Sorting on calculated @code{DOUBLE} values sorted on integer results instead.
@item
@code{mysql} no longer needs a database argument.
@item
Changed the place where @code{HAVING} should be. According to ANSI, it should
be after @code{GROUP BY} but before @code{ORDER BY}. @strong{MySQL} 3.20
incorrectly had it last.
@item
Added Sybase command @code{USE DATABASE} to start using another database.
@item
Added automatic adjusting of number of connections and table cache size
if the maximum number of files that can be opened is less than needed.
This should fix that @code{mysqld} doesn't crash even if you haven't done a
@code{ulimit -n 256} before starting @code{mysqld}.
@item
Added lots of limit checks to make it safer when running with too little
memory or when doing weird queries.
@end itemize
@node News-3.21.13, News-3.21.12, News-3.21.14a, News-3.21.x
@appendixsubsec Changes in release 3.21.13
@itemize @bullet
@item
Added retry of interrupted reads and clearing of @code{errno}.
This makes Linux systems much safer!
@item
Fixed locking bug when using many aliases on the same table in the same
@code{SELECT}.
@item
Fixed bug with @code{LIKE} on number key.
@item
New error message so you can check whether the connection was lost while
the command was running or whether the connection was down from the start.
@item
Added @code{--table} option to @code{mysql} to print in table format.
Moved time and row information after query result.
Added automatic reconnect of lost connections.
@item
Added @code{!=} as a synonym for @code{<>}.
@item
Added function @code{VERSION()} to make easier logs.
@item
New multi-user test @file{tests/fork_test.pl} to put some strain on the
thread library.
@end itemize
@node News-3.21.12, News-3.21.11, News-3.21.13, News-3.21.x
@appendixsubsec Changes in release 3.21.12
@itemize @bullet
@item
Fixed @code{ftruncate()} call in MIT-pthreads. This made @code{isamchk}
destroy the @file{.ISM} files on (Free)BSD 2.x systems.
@item
Fixed broken @code{__P_} patch in MIT-pthreads.
@item
Many memory overrun checks. All string functions now return @code{NULL}
if the returned string should be longer than @code{max_allowed_packet} bytes.
@item
Changed the name of the @code{INTERVAL} type to @code{ENUM}, because
@code{INTERVAL} is used in ANSI SQL.
@item
In some cases, doing a @code{JOIN} + @code{GROUP} + @code{INTO OUTFILE},
the result wasn't grouped.
@item
@code{LIKE} with @code{'_'} as last character didn't work. Fixed.
@item
Added extended ANSI SQL @code{TRIM()} function.
@item
Added @code{CURTIME()}.
@item
Added @code{ENCRYPT()} function by Zeev Suraski.
@item
Fixed better @code{FOREIGN KEY} syntax skipping. New reserved words:
@code{MATCH}, @code{FULL}, @code{PARTIAL}.
@item
@code{mysqld} now allows IP number and hostname to the @code{--bind-address}
option.
@item
Added @code{SET OPTION CHARACTER SET cp1251_koi8} to enable conversions of
data to/from cp1251_koi8.
@item
Lots of changes for Win95 port. In theory, this version should now be
easily portable to Win95.
@item
Changed the @code{CREATE COLUMN} syntax of @code{NOT NULL} columns to be after
the @code{DEFAULT} value, as specified in the ANSI SQL standard. This will
make @code{mysqldump} with @code{NOT NULL} and default values incompatible with
@strong{MySQL} 3.20.
@item
Added many function name aliases so the functions can be used with
ODBC or ANSI SQL92 syntax.
@item
Fixed syntax of @code{ALTER TABLE tbl_name ALTER COLUMN col_name SET DEFAULT
NULL}.
@item
Added @code{CHAR} and @code{BIT} as synonyms for @code{CHAR(1)}.
@item
Fixed core dump when updating as a user who has only @strong{select} privilege.
@item
@code{INSERT ... SELECT ... GROUP BY} didn't work in some cases. An
@code{Invalid use of group function} error occurred.
@item
When using @code{LIMIT}, @code{SELECT} now always uses keys instead of record
scan. This will give better performance on @code{SELECT} and a @code{WHERE}
that matches many rows.
@item
Added Russian error messages.
@end itemize
@node News-3.21.11, News-3.21.10, News-3.21.12, News-3.21.x
@appendixsubsec Changes in release 3.21.11
@itemize @bullet
@item
Configure changes.
@item
@strong{MySQL} now works with the new thread library on BSD/OS 3.0.
@item
Added new group functions @code{BIT_OR()} and @code{BIT_AND()}.
@item
Added compatibility functions @code{CHECK} and @code{REFERENCES}.
@code{CHECK} is now a reserved word.
@item
Added @code{ALL} option to @code{GRANT} for better compatibility. (@code{GRANT}
is still a dummy function.)
@item
Added partly-translated dutch messages.
@item
Fixed bug in @code{ORDER BY} and @code{GROUP BY} with @code{NULL} columns.
@item
Added function @code{last_insert_id()} to retrieve last @code{AUTO_INCREMENT}
value. This is intended for clients to ODBC that can't use the
@code{mysql_insert_id()} API function, but can be used by any client.
@item
Added @code{--flush-logs} option to @code{mysqladmin}.
@item
Added command @code{STATUS} to @code{mysql}.
@item
Fixed problem with @code{ORDER BY}/@code{GROUP BY} because of bug in @code{gcc}.
@item
Fixed problem with @code{INSERT ... SELECT ... GROUP BY}.
@end itemize
@node News-3.21.10, News-3.21.9, News-3.21.11, News-3.21.x
@appendixsubsec Changes in release 3.21.10
@itemize @bullet
@item
New @code{mysqlaccess}.
@item
@code{CREATE} now supports all ODBC types and the @code{mSQL} @code{TEXT} type.
All ODBC 2.5 functions are also supported (added @code{REPEAT}). This provides
better portability.
@item
Added text types @code{TINYTEXT}, @code{TEXT}, @code{MEDIUMTEXT} and
@code{LONGTEXT}. These are actually @code{BLOB}types, but all searching is
done in case-insensitive fashion.
@item
All old @code{BLOB} fields are now @code{TEXT} fields. This only
changes that all searching on strings is done in case-sensitive fashion.
You must do an @code{ALTER TABLE} and change the field type to @code{BLOB}
if you want to have tests done in case-sensitive fashion.
@item
Fixed some @code{configure} issues.
@item
Made the locking code a bit safer. Fixed very unlikely
deadlock situation.
@item
Fixed a couple of bugs in the range optimizer. Now the new range benchmark
@code{test-select} works.
@end itemize
@node News-3.21.9, News-3.21.8, News-3.21.10, News-3.21.x
@appendixsubsec Changes in release 3.21.9
@itemize @bullet
@item
Added @code{--enable-unix-socket=pathname} option to @code{configure}.
@item
Fixed a couple of portability problems with include files.
@item
Fixed bug in range calculation that could return empty
set when searching on multiple key with only one entry (very rare).
@item
Most things ported to FSU Pthreads, which should allow @strong{MySQL} to
run on SCO. @xref{SCO}.
@end itemize
@node News-3.21.8, News-3.21.7, News-3.21.9, News-3.21.x
@appendixsubsec Changes in release 3.21.8
@itemize @bullet
@item
Works now in Solaris 2.6.
@item
Added handling of calculation of @code{SUM()} functions.
For example, you can now use @code{SUM(column)/COUNT(column)}.
@item
Added handling of trigometric functions:
@code{PI()}, @code{ACOS()}, @code{ASIN()}, @code{ATAN()}, @code{COS()},
@code{SIN()} and @code{TAN()}.
@item
New languages: norwegian, norwegian-ny and portuguese.
@item
Fixed parameter bug in @code{net_print()} in @file{procedure.cc}.
@item
Fixed a couple of memory leaks.
@item
Now allow also the old @code{SELECT ... INTO OUTFILE} syntax.
@item
Fixed bug with @code{GROUP BY} and @code{SELECT} on key with many values.
@item
@code{mysql_fetch_lengths()} sometimes returned incorrect lengths when you used
@code{mysql_use_result()}. This affected at least some cases of
@code{mysqldump --quick}.
@item
Fixed bug in optimization of @code{WHERE const op field}.
@item
Fixed problem when sorting on @code{NULL} fields.
@item
Fixed a couple of 64-bit (Alpha) problems.
@item
Added @code{--pid-file=#} option to @code{mysqld}.
@item
Added date formatting to @code{FROM_UNIXTIME()}, originally by Zeev Suraski.
@item
Fixed bug in @code{BETWEEN} in range optimizer (Did only test = of the first
argument).
@item
Added machine-dependent files for MIT-pthreads i386-SCO. There is probably
more to do to get this to work on SCO 3.5.
@end itemize
@node News-3.21.7, News-3.21.6, News-3.21.8, News-3.21.x
@appendixsubsec Changes in release 3.21.7
@itemize @bullet
@item
Changed @file{Makefile.am} to take advantage of Automake 1.2.
@item
Added the beginnings of a benchmark suite.
@item
Added more secure password handling.
@item
Added new client function @code{mysql_errno()}, to get the error number of
the error message. This makes error checking in the client much easier.
This makes the new server incompatible with the 3.20.x server when running
without @code{--old-protocol}. The client code is backward compatible.
More information can be found in the @file{README} file!
@item
Fixed some problems when using very long, illegal names.
@end itemize
@node News-3.21.6, News-3.21.5, News-3.21.7, News-3.21.x
@appendixsubsec Changes in release 3.21.6
@itemize @bullet
@item
Fixed more portability issues (incorrect @code{sigwait} and @code{sigset}
defines).
@item
@code{configure} should now be able to detect the last argument to
@code{accept()}.
@end itemize
@node News-3.21.5, News-3.21.4, News-3.21.6, News-3.21.x
@appendixsubsec Changes in release 3.21.5
@itemize @bullet
@item
Should now work with FreeBSD 3.0 if used with
@file{FreeBSD-3.0-libc_r-1.0.diff},
which can be found at @uref{http://www.mysql.com/Downloads/Patches/}.
@item
Added new option @code{-O tmp_table_size=#} to @code{mysqld}.
@item
New function @code{FROM_UNIXTIME(timestamp)} which returns a date string in
'YYYY-MM-DD HH:MM:DD' format.
@item
New function @code{SEC_TO_TIME(seconds)} which returns a string in
'HH:MM:SS' format.
@item
New function @code{SUBSTRING_INDEX()}, originally by Zeev Suraski.
@end itemize
@node News-3.21.4, News-3.21.3, News-3.21.5, News-3.21.x
@appendixsubsec Changes in release 3.21.4
@itemize @bullet
@item
Should now configure and compile on OSF1 4.0 with the DEC compiler.
@item
Configuration and compilation on BSD/OS 3.0 works, but due to some bugs in
BSD/OS 3.0, @code{mysqld} doesn't work on it yet.
@item
Configuration and compilation on FreeBSD 3.0 works, but I couldn't get
@code{pthread_create} to work.
@end itemize
@node News-3.21.3, News-3.21.2, News-3.21.4, News-3.21.x
@appendixsubsec Changes in release 3.21.3
@itemize @bullet
@item
Added reverse check lookup of hostnames to get better security.
@item
Fixed some possible buffer overflows if filenames that are too long are used.
@item
@code{mysqld} doesn't accept hostnames that start with digits followed by a
@code{'.'}, because the hostname may look like an IP number.
@item
Added @code{--skip-networking} option to @code{mysqld}, to only allow socket
connections. (This will not work with MIT-pthreads!)
@item
Added check of too long table names for alias.
@item
Added check if database name is okay.
@item
Added check if too long table names.
@item
Removed incorrect @code{free()} that killed the server on
@code{CREATE DATABASE} or @code{DROP DATABASE}.
@item
Changed some @code{mysqld} @code{-O} options to better names.
@item
Added @code{-O join_cache_size=#} option to @code{mysqld}.
@item
Added @code{-O max_join_size=#} option to @code{mysqld}, to be able to set a
limit how big queries (in this case big = slow) one should be able to handle
without specifying @code{SET OPTION SQL_BIG_SELECTS=1}. A # = is about 10
examined records. The default is ``unlimited''.
@item
When comparing a @code{TIME}, @code{DATE}, @code{DATETIME} or @code{TIMESTAMP}
column to a constant, the constant is converted to a time value before
performing the comparison.
This will make it easier to get ODBC (particularly Access97) to work with
the above types. It should also make dates easier to use and the comparisons
should be quicker than before.
@item
Applied patch from Jochen Wiedmann that allows @code{query()} in
@code{mysqlperl} to take a query with @code{\0} in it.
@item
Storing a timestamp with a 2-digit year (@code{YYMMDD}) didn't work.
@item
Fix that timestamp wasn't automatically updated if set in an @code{UPDATE}
clause.
@item
Now the automatic timestamp field is the FIRST timestamp field.
@item
@code{SELECT * INTO OUTFILE}, which didn't correctly if the outfile already
existed.
@item
@code{mysql} now shows the thread ID when starting or doing a reconnect.
@item
Changed the default sort buffer size from 2M to 1M.
@end itemize
@node News-3.21.2, News-3.21.0, News-3.21.3, News-3.21.x
@appendixsubsec Changes in release 3.21.2
@itemize @bullet
@item
The range optimizer is coded, but only 85% tested. It can be enabled with
@code{--new}, but it crashes core a lot yet...
@item
More portable. Should compile on AIX and alpha-digital.
At least the @code{isam} library should be relatively 64-bit clean.
@item
New @code{isamchk} which can detect and fix more problems.
@item
New options for @code{isamlog}.
@item
Using new version of Automake.
@item
Many small portability changes (from the AIX and alpha-digital port)
Better checking of pthread(s) library.
@item
czech error messages by @email{snajdr@@pvt.net}.
@item
Decreased size of some buffers to get fewer problems on systems with little
memory. Also added more checks to handle ``out of memory'' problems.
@item
@code{mysqladmin}: you can now do @code{mysqladmin kill 5,6,7,8} to kill
multiple threads.
@item
When the maximum connection limit is reached, one extra connection by a user
with the @strong{PROCESS_ACL} privilege is granted.
@item
Added @code{-O backlog=#} option to @code{mysqld}.
@item
Increased maximum packet size from 512K to 1024K for client.
@item
Almost all of the function code is now tested in the internal test suite.
@item
@code{ALTER TABLE} now returns warnings from field conversions.
@item
Port changed to 3306 (got it reserved from ISI).
@item
Added a fix for Visual FoxBase so that any schema name from a table
specification is automatically removed.
@item
New function @code{ASCII()}.
@item
Removed function @code{BETWEEN(a,b,c)}. Use the standard ANSI
synax instead: @code{expr BETWEEN expr AND expr}.
@item
@strong{MySQL} no longer has to use an extra temporary table when sorting
on functions or @code{SUM()} functions.
@item
Fixed bug that you couldn't use @code{tbl_name.field_name} in @code{UPDATE}.
@item
Fixed @code{SELECT DISTINCT} when using 'hidden group'. For example:
@example
mysql> SELECT DISTINCT MOD(some_field,10) FROM test
GROUP BY some_field;
@end example
Note: @code{some_field} is normally in the @code{SELECT} part. ANSI SQL should
require it.
@end itemize
@node News-3.21.0, , News-3.21.2, News-3.21.x
@appendixsubsec Changes in release 3.21.0
@itemize @bullet
@item
New reserved words used: @code{INTERVAL}, @code{EXPLAIN}, @code{READ},
@code{WRITE}, @code{BINARY}.
@item
Added ODBC function @code{CHAR(num,...)}.
@item
New operator @code{IN}. This uses a binary search to find a match.
@item
New command @code{LOCK TABLES tbl_name [AS alias] @{READ|WRITE@} ...}
@item
Added @code{--log-update} option to @code{mysqld}, to get a log suitable for
incremental updates.
@item
New command @code{EXPLAIN SELECT ...} to get information about how the
optimizer will do the join.
@item
For easier client code, the client should no longer use
@code{FIELD_TYPE_TINY_BLOB}, @code{FIELD_TYPE_MEDIUM_BLOB},
@code{FIELD_TYPE_LONG_BLOB} or @code{FIELD_TYPE_VAR_STRING} (as
previously returned by @code{mysql_list_fields}). You should instead only use
@code{FIELD_TYPE_BLOB} or @code{FIELD_TYPE_STRING}. If you want exact
types, you should use the command @code{SHOW FIELDS}.
@item
Added varbinary syntax: @code{0x######} which can be used as a string
(default) or a number.
@item
@code{FIELD_TYPE_CHAR} is renamed to @code{FIELD_TYPE_TINY}.
@item
Changed all fields to C++ classes.
@item
Removed FORM struct.
@item
Fields with @code{DEFAULT} values no longer need to be @code{NOT NULL}.
@item
New field types:
@table @code
@item ENUM
A string which can take only a couple of defined values. The value is
stored as a 1-3 byte number that is mapped automatically to a string.
This is sorted according to string positions!
@item SET
A string which may have one or many string values separated with ','.
The string is stored as a 1-, 2-, 3-, 4- or 8-byte number where each bit stands
for a specific set member. This is sorted according to the unsigned value
of the stored packed number.
@end table
@item
Now all function calculation is done with @code{double} or @code{long long}.
This will provide the full 64-bit range with bit functions and fix some
conversions that previously could result in precision losses. One should
avoid using @code{unsigned long long} columns with full 64-bit range
(numbers bigger than 9223372036854775807) because calculations are done
with @code{signed long long}.
@item
@code{ORDER BY} will now put @code{NULL} field values first. @code{GROUP BY}
will also work with @code{NULL} values.
@item
Full @code{WHERE} with expressions.
@item
New range optimizer that can resolve ranges when some keypart prefix is
constant. Example:
@example
mysql> SELECT * FROM tbl_name
WHERE key_part_1="customer"
AND key_part_2>=10 AND key_part_2<=10;
@end example
@end itemize
@node News-3.20.x, News-3.19.x, News-3.21.x, News
@appendixsec Changes in release 3.20.x
Changes from 3.20.18 to 3.20.32b are not documented here because the
3.21 release branched here. And the relevant changes are also
documented as changes to the 3.21 version.
@menu
* News-3.20.18:: Changes in release 3.20.18
* News-3.20.17:: Changes in release 3.20.17
* News-3.20.16:: Changes in release 3.20.16
* News-3.20.15:: Changes in release 3.20.15
* News-3.20.14:: Changes in release 3.20.14
* News-3.20.13:: Changes in release 3.20.13
* News-3.20.11:: Changes in release 3.20.11
* News-3.20.10:: Changes in release 3.20.10
* News-3.20.9:: Changes in release 3.20.9
* News-3.20.8:: Changes in release 3.20.8
* News-3.20.7:: Changes in release 3.20.7
* News-3.20.6:: Changes in release 3.20.6
* News-3.20.3:: Changes in release 3.20.3
* News-3.20.0:: Changes in releases 3.20.0
@end menu
@node News-3.20.18, News-3.20.17, News-3.20.x, News-3.20.x
@appendixsubsec Changes in release 3.20.18
@itemize @bullet
@item
Added @code{-p#} (remove @code{#} directories from path) to @code{isamlog}.
All files are written with a relative path from the database directory
Now @code{mysqld} shouldn't crash on shutdown when using the
@code{--log-isam} option.
@item
New @code{mysqlperl} version. It is now compatible with @code{msqlperl-0.63}.
@item
New @code{DBD} module available at @uref{http://www.mysql.com/Downloads/Contrib/}
site.
@item
Added group function @code{STD()} (standard deviation).
@item
The @code{mysqld} server is now compiled by default without debugging
information. This will make the daemon smaller and faster.
@item
Now one usually only has to specify the @code{--basedir} option to
@code{mysqld}. All other paths are relative in a normal installation.
@item
@code{BLOB} columns sometimes contained garbage when used with a @code{SELECT}
on more than one table and @code{ORDER BY}.
@item
Fixed that calculations that are not in @code{GROUP BY} work as expected
(ANSI SQL extension).
Example:
@example
mysql> SELECT id,id+1 FROM table GROUP BY id;
@end example
@item
The test of using @code{MYSQL_PWD} was reversed. Now @code{MYSQL_PWD} is
enabled as default in the default release.
@item
Fixed conversion bug which caused @code{mysqld} to core dump with
Arithmetic error on Sparc-386.
@item
Added @code{--unbuffered} option to @code{mysql}, for new @code{mysqlaccess}.
@item
When using overlapping (unnecessary) keys and join over many tables,
the optimizer could get confused and return 0 records.
@end itemize
@node News-3.20.17, News-3.20.16, News-3.20.18, News-3.20.x
@appendixsubsec Changes in release 3.20.17
@itemize @bullet
@item
You can now use @code{BLOB} columns and the functions @code{IS NULL} and
@code{IS NOT NULL} in the @code{WHERE} clause.
@item
All communication packets and row buffers are now allocated dynamically
on demand. The default value of @code{max_allowed_packet} is now 64K for
the server and 512K for the client. This is mainly used to catch
incorrect packets that could trash all memory. The server limit may be
changed when it is started.
@item
Changed stack usage to use less memory.
@item
Changed @code{safe_mysqld} to check for running daemon.
@item
The @code{ELT()} function is renamed to @code{FIELD()}. The new
@code{ELT()} function returns a value based on an index: @code{FIELD()}
is the inverse of @code{ELT()} Example: @code{ELT(2,"A","B","C")} returns
@code{"B"}. @code{FIELD("B","A","B","C")} returns @code{2}.
@item
@code{COUNT(field)}, where @code{field} could have a @code{NULL} value, now
works.
@item
A couple of bugs fixed in @code{SELECT ... GROUP BY}.
@item
Fixed memory overrun bug in @code{WHERE} with many unoptimizable brace levels.
@item
Fixed some small bugs in the grant code.
@item
If hostname isn't found by @code{get_hostname}, only the IP is checked.
Previously, you got @code{Access denied}.
@item
Inserts of timestamps with values didn't always work.
@item
@code{INSERT INTO ... SELECT ... WHERE} could give the error
@code{Duplicated field}.
@item
Added some tests to @code{safe_mysqld} to make it ``safer''.
@item
@code{LIKE} was case sensitive in some places and case insensitive in others.
Now @code{LIKE} is always case insensitive.
@item
@file{mysql.cc}: Allow @code{'#'} anywhere on the line.
@item
New command @code{SET OPTION SQL_SELECT_LIMIT=#}. See the FAQ for more details.
@item
New version of the @code{mysqlaccess} script.
@item
Change @code{FROM_DAYS()} and @code{WEEKDAY()} to also take a full
@code{TIMESTAMP} or @code{DATETIME} as argument. Before they only took a
number of type @code{YYYYMMDD} or @code{YYMMDD}.
@item
Added new function @code{UNIX_TIMESTAMP(timestamp_column)}.
@end itemize
@node News-3.20.16, News-3.20.15, News-3.20.17, News-3.20.x
@appendixsubsec Changes in release 3.20.16
@itemize @bullet
@item
More changes in MIT-pthreads to get them safer. Fixed also some link
bugs at least in SunOS.
@item
Changed @code{mysqld} to work around a bug in MIT-pthreads. This makes multiple
small @code{SELECT} operations 20 times faster. Now @code{lock_test.pl} should
work.
@item
Added @code{mysql_FetchHash(handle)} to @code{mysqlperl}.
@item
The @code{mysqlbug} script is now distributed built to allow for reporting
bugs that appear during the build with it.
@item
Changed @file{libmysql.c} to prefer @code{getpwuid()} instead of
@code{cuserid()}.
@item
Fixed bug in @code{SELECT} optimizer when using many tables with the same
column used as key to different tables.
@item
Added new latin2 and Russian KOI8 character tables.
@item
Added support for a dummy @code{GRANT} command to satisfy Powerbuilder.
@end itemize
@node News-3.20.15, News-3.20.14, News-3.20.16, News-3.20.x
@appendixsubsec Changes in release 3.20.15
@itemize @bullet
@item
Fixed fatal bug @code{packets out of order} when using MIT-pthreads.
@item
Removed possible loop when a thread waits for command from client
and @code{fcntl()} fails. Thanks to Mike Bretz for finding this bug.
@item
Changed alarm loop in @file{mysqld.cc} because shutdown didn't always
succeed in Linux.
@item
Removed use of @code{termbits} from @file{mysql.cc}. This conflicted with
@code{glibc} 2.0.
@item
Fixed some syntax errors for at least BSD and Linux.
@item
Fixed bug when doing a @code{SELECT} as superuser without a database.
@item
Fixed bug when doing @code{SELECT} with group calculation to outfile.
@end itemize
@node News-3.20.14, News-3.20.13, News-3.20.15, News-3.20.x
@appendixsubsec Changes in release 3.20.14
@itemize @bullet
@item
If one gives @code{-p} or @code{--password} option to @code{mysql} without
an argument, the user is solicited for the password from the tty.
@item
Added default password from @code{MYSQL_PWD} (by Elmar Haneke).
@item
Added command @code{kill} to @code{mysqladmin} to kill a specific
@strong{MySQL} thread.
@item
Sometimes when doing a reconnect on a down connection this succeeded
first on second try.
@item
Fixed adding an @code{AUTO_INCREMENT} key with @code{ALTER_TABLE}.
@item
@code{AVG()} gave too small value on some @code{SELECT}s with
@code{GROUP BY} and @code{ORDER BY}.
@item
Added new @code{DATETIME} type (by Giovanni Maruzzelli
@email{maruzz@@matrice.it}).
@item
Fixed that define @code{DONT_USE_DEFAULT_FIELDS} works.
@item
Changed to use a thread to handle alarms instead of signals on Solaris to
avoid race conditions.
@item
Fixed default length of signed numbers. (George Harvey
@email{georgeh@@pinacl.co.uk}.)
@item
Allow anything for @code{CREATE INDEX}.
@item
Add prezeros when packing numbers to @code{DATE}, @code{TIME} and
@code{TIMESTAMP}.
@item
Fixed a bug in @code{OR} of multiple tables (gave empty set).
@item
Added many patches to MIT-pthreads. This fixes at least one lookup bug.
@end itemize
@node News-3.20.13, News-3.20.11, News-3.20.14, News-3.20.x
@appendixsubsec Changes in release 3.20.13
@itemize @bullet
@item
Added ANSI SQL94 @code{DATE} and @code{TIME} types.
@item
Fixed bug in @code{SELECT} with @code{AND}-@code{OR} levels.
@item
Added support for Slovenian characters. The @file{Contrib} directory contains
source and instructions for adding other character sets.
@item
Fixed bug with @code{LIMIT} and @code{ORDER BY}.
@item
Allow @code{ORDER BY} and @code{GROUP BY} on items that aren't in the
@code{SELECT} list.
(Thanks to Wim Bonis @email{bonis@@kiss.de}, for pointing this out.)
@item
Allow setting of timestamp values in @code{INSERT}.
@item
Fixed bug with @code{SELECT ... WHERE ... = NULL}.
@item
Added changes for @code{glibc} 2.0. To get @code{glibc} to work, you should
add the @file{gibc-2.0-sigwait-patch} before compiling @code{glibc}.
@item
Fixed bug in @code{ALTER TABLE} when changing a @code{NOT NULL} field to
allow @code{NULL} values.
@item
Added some ANSI92 synonyms as field types to @code{CREATE TABLE}.
@code{CREATE TABLE} now allows @code{FLOAT(4)} and @code{FLOAT(8)} to mean
@code{FLOAT} and @code{DOUBLE}.
@item
New utility program @code{mysqlaccess} by @email{Yves.Carlier@@rug.ac.be}.
This program shows the access rights for a specific user and the grant
rows that determine this grant.
@item
Added @code{WHERE const op field} (by @email{bonis@@kiss.de}).
@end itemize
@node News-3.20.11, News-3.20.10, News-3.20.13, News-3.20.x
@appendixsubsec Changes in release 3.20.11
@itemize @bullet
@item
When using @code{SELECT ... INTO OUTFILE}, all temporary tables are ISAM
instead of HEAP to allow big dumps.
@item
Changed date functions to be string functions. This fixed some ``funny''
side effects when sorting on dates.
@item
Extended @code{ALTER TABLE} according to SQL92.
@item
Some minor compability changes.
@item
Added @code{--port} and @code{--socket} options to all utility programs and
@code{mysqld}.
@item
Fixed MIT-pthreads @code{readdir_r()}. Now @code{mysqladmin create database}
and @code{mysqladmin drop database} should work.
@item
Changed MIT-pthreads to use our @code{tempnam()}. This should fix the ``sort
aborted'' bug.
@item
Added sync of records count in @code{sql_update}. This fixed slow updates
on first connection. (Thanks to Vaclav Bittner for the test.)
@end itemize
@node News-3.20.10, News-3.20.9, News-3.20.11, News-3.20.x
@appendixsubsec Changes in release 3.20.10
@itemize @bullet
@item
New insert type: @code{INSERT INTO ... SELECT ...}
@item
@code{MEDIUMBLOB} fixed.
@item
Fixed bug in @code{ALTER TABLE} and @code{BLOB}s.
@item
@code{SELECT ... INTO OUTFILE} now creates the file in the current
database directory.
@item
@code{DROP TABLE} now can take a list of tables.
@item
Oracle synonym @code{DESCRIBE} (@code{DESC}).
@item
Changes to @code{make_binary_distribution}.
@item
Added some comments to installation instructions about @code{configure}'s
C++ link test.
@item
Added @code{--without-perl} option to @code{configure}.
@item
Lots of small portability changes.
@end itemize
@node News-3.20.9, News-3.20.8, News-3.20.10, News-3.20.x
@appendixsubsec Changes in release 3.20.9
@itemize @bullet
@item
@code{ALTER TABLE} didn't copy null bit. As a result, fields that were allowed
to have @code{NULL} values were always @code{NULL}.
@item
@code{CREATE} didn't take numbers as @code{DEFAULT}.
@item
Some compatibility changes for SunOS.
@item
Removed @file{config.cache} from old distribution.
@end itemize
@node News-3.20.8, News-3.20.7, News-3.20.9, News-3.20.x
@appendixsubsec Changes in release 3.20.8
@itemize @bullet
@item
Fixed bug with @code{ALTER TABLE} and multi-part keys.
@end itemize
@node News-3.20.7, News-3.20.6, News-3.20.8, News-3.20.x
@appendixsubsec Changes in release 3.20.7
@itemize @bullet
@item
New commands: @code{ALTER TABLE}, @code{SELECT ... INTO OUTFILE} and
@code{LOAD DATA INFILE}.
@item
New function: @code{NOW()}.
@item
Added new field @strong{file_priv} to @code{mysql/user} table.
@item
New script @code{add_file_priv} which adds the new field @strong{file_priv}
to the @code{user} table. This script must be executed if you want to
use the new @code{SELECT ... INTO} and @code{LOAD DATA INFILE ...} commands
with a version of @strong{MySQL} earlier than 3.20.7.
@item
Fixed bug in locking code, which made @code{lock_test.pl} test fail.
@item
New files @file{NEW} and @file{BUGS}.
@item
Changed @file{select_test.c} and @file{insert_test.c} to include
@file{config.h}.
@item
Added command @code{status} to @code{mysqladmin} for short logging.
@item
Increased maximum number of keys to 16 and maximum number of key parts to 15.
@item
Use of sub keys. A key may now be a prefix of a string field.
@item
Added @code{-k} option to @code{mysqlshow}, to get key information for a table.
@item
Added long options to @code{mysqldump}.
@end itemize
@node News-3.20.6, News-3.20.3, News-3.20.7, News-3.20.x
@appendixsubsec Changes in release 3.20.6
@itemize @bullet
@item
Portable to more systems because of MIT-pthreads, which will
be used automatically if @code{configure} cannot find a @code{-lpthreads}
library.
@item
Added GNU-style long options to almost all programs. Test with
@code{@kbd{program} --help}.
@item
Some shared library support for Linux.
@item
The FAQ is now in @file{.texi} format and is available in @file{.html},
@file{.txt} and @file{.ps} formats.
@item
Added new SQL function @code{RAND([init])}.
@item
Changed @code{sql_lex} to handle @code{\0} unquoted, but the client can't send
the query through the C API, because it takes a str pointer.
You must use @code{mysql_real_query()} to send the query.
@item
Added API function @code{mysql_get_client_info()}.
@item
@code{mysqld} now uses the @code{N_MAX_KEY_LENGTH} from @file{nisam.h} as
the maximum allowed key length.
@item
The following now works:
@example
mysql> SELECT filter_nr,filter_nr FROM filter ORDER BY filter_nr;
@end example
Previously, this resulted in the error:
@code{Column: 'filter_nr' in order clause is ambiguous}.
@item
@code{mysql} now outputs @code{'\0'}, @code{'\t'}, @code{'\n'} and @code{'\\'}
when encountering ASCII 0, tab, newline or @code{'\'} while writing
tab-separated output.
This is to allow printing of binary data in a portable format.
To get the old behavior, use @code{-r} (or @code{--raw}).
@item
Added german error messages (60 of 80 error messages translated).
@item
Added new API function @code{mysql_fetch_lengths(MYSQL_RES *)}, which
returns an array of of column lengths (of type @code{uint}).
@item
Fixed bug with @code{IS NULL} in @code{WHERE} clause.
@item
Changed the optimizer a little to get better results when searching on a key
part.
@item
Added @code{SELECT} option @code{STRAIGHT_JOIN} to tell the optimizer that
it should join tables in the given order.
@item
Added support for comments starting with @code{'--'} in @file{mysql.cc}
(Postgres syntax).
@item
You can have @code{SELECT} expressions and table columns in a @code{SELECT}
which are not used in the group part. This makes it efficient to implement
lookups. The column that is used should be a constant for each group because
the value is calculated only once for the first row that is found for a group.
@example
mysql> SELECT id,lookup.text,sum(*) FROM test,lookup
WHERE test.id=lookup.id GROUP BY id;
@end example
@item
Fixed bug in @code{SUM(function)} (could cause a core dump).
@item
Changed @code{AUTO_INCREMENT} placement in the SQL query:
@example
INSERT into table (auto_field) values (0);
@end example
inserted 0, but it should insert an @code{AUTO_INCREMENT} value.
@item
@file{mysqlshow.c}: Added number of records in table. Had to change the
client code a little to fix this.
@item
@code{mysql} now allows doubled @code{''} or @code{""} within strings for
embedded @code{'} or @code{"}.
@item
New math functions:
@code{EXP()}, @code{LOG()}, @code{SQRT()}, @code{ROUND()}, @code{CEILING()}.
@end itemize
@node News-3.20.3, News-3.20.0, News-3.20.6, News-3.20.x
@appendixsubsec Changes in release 3.20.3
@itemize @bullet
@item
The @code{configure} source now compiles a thread-free client library
@code{-lmysqlclient}. This is the only library that needs to be linked
with client applications. When using the binary releases, you must
link with @code{-lmysql -lmysys -ldbug -lstrings} as before.
@item
New @code{readline} library from @code{bash-2.0}.
@item
LOTS of small changes to @code{configure} and makefiles (and related source).
@item
It should now be possible to compile in another directory using
@code{VPATH}. Tested with GNU Make 3.75.
@item
@code{safe_mysqld} and @code{mysql.server} changed to be more compatible
between the source and the binary releases.
@item
@code{LIMIT} now takes one or two numeric arguments.
If one argument is given, it indicates the maximum number of rows in
a result. If two arguments are given, the first argument indicates the offset
of the first row to return, the second is the maximum number of rows.
With this it's easy to do a poor man's next page/previous page WWW
application.
@item
Changed name of SQL function @code{FIELDS()} to @code{ELT()}.
Changed SQL function @code{INTERVALL()} to @code{INTERVAL()}.
@item
Made @code{SHOW COLUMNS} a synonym for @code{SHOW FIELDS}.
Added compatibility syntax @code{FRIEND KEY} to @code{CREATE TABLE}. In
@strong{MySQL}, this creates a non-unique key on the given columns.
@item
Added @code{CREATE INDEX} and @code{DROP INDEX} as compatibility functions.
In @strong{MySQL}, @code{CREATE INDEX} only checks if the index exists and
issues an error if it doesn't exist. @code{DROP INDEX} always succeeds.
@item
@file{mysqladmin.c}: added client version to version information.
@item
Fixed core dump bug in @code{sql_acl} (core on new connection).
@item
Removed @code{host}, @code{user} and @code{db} tables from database @code{test}
in the distribution.
@item
@code{FIELD_TYPE_CHAR} can now be signed (-128 - 127) or unsigned (0 - 255)
Previously, it was always unsigned.
@item
Bug fixes in @code{CONCAT()} and @code{WEEKDAY()}.
@item
Changed a lot of source to get @code{mysqld} to be compiled with SunPro
compiler.
@item
SQL functions must now have a @code{'('} immediately after the function name
(no intervening space).
For example, @code{'user('} is regarded as beginning a function call, and
@code{'user ('} is regarded as an identifier @code{user} followed by a
@code{'('}, not as a function call.
@end itemize
@node News-3.20.0, , News-3.20.3, News-3.20.x
@appendixsubsec Changes in release 3.20.0
@itemize @bullet
@item
The source distribution is done with @code{configure} and Automake.
It will make porting much easier. The @code{readline} library is included
in the distribution.
@item
Separate client compilation:
the client code should be very easy to compile on systems which
don't have threads.
@item
The old Perl interface code is automatically compiled and installed.
Automatic compiling of @code{DBD} will follow when the new @code{DBD} code
is ported.
@item
Dynamic language support: @code{mysqld} can now be started with Swedish
or English (default) error messages.
@item
New functions: @code{INSERT()}, @code{RTRIM()}, @code{LTRIM()} and
@code{FORMAT()}.
@item
@code{mysqldump} now works correctly for all field types (even
@code{AUTO_INCREMENT}). The format for @code{SHOW FIELDS FROM tbl_name}
is changed so the @code{Type} column contains information suitable for
@code{CREATE TABLE}. In previous releases, some @code{CREATE TABLE}
information had to be patched when recreating tables.
@item
Some parser bugs from 3.19.5 (@code{BLOB} and @code{TIMESTAMP}) are corrected.
@code{TIMESTAMP} now returns different date information depending on its
create length.
@item
Changed parser to allow a database, table or field name to
start with a number or @code{'_'}.
@item
All old C code from Unireg changed to C++ and cleaned up. This makes
the daemon a little smaller and easier to understand.
@item
A lot of small bug fixes done.
@item
New @file{INSTALL} files (not final version) and some info regarding porting.
@end itemize
@node News-3.19.x, , News-3.20.x, News
@appendixsec Changes in release 3.19.x
@menu
* News-3.19.5:: Changes in release 3.19.5
* News-3.19.4:: Changes in release 3.19.4
* News-3.19.3:: Changes in release 3.19.3
@end menu
@node News-3.19.5, News-3.19.4, News-3.19.x, News-3.19.x
@appendixsubsec Changes in release 3.19.5
@itemize @bullet
@item
Some new functions, some more optimization on joins.
@item
Should now compile clean on Linux (2.0.x).
@item
Added functions @code{DATABASE()}, @code{USER()}, @code{POW()},
@code{LOG10()} (needed for ODBC).
@item
In a @code{WHERE} with an @code{ORDER BY} on fields from only one table,
the table is now preferred as first table in a multi-join.
@item
@code{HAVING} and @code{IS NULL} or @code{IS NOT NULL} now works.
@item
A group on one column and a sort on a group function (@code{SUM()},
@code{AVG()}...) didn't work together. Fixed.
@item
@code{mysqldump}: Didn't send password to server.
@end itemize
@node News-3.19.4, News-3.19.3, News-3.19.5, News-3.19.x
@appendixsubsec Changes in release 3.19.4
@itemize @bullet
@item
Fixed horrible locking bug when inserting in one thread and reading
in another thread.
@item
Fixed one-off decimal bug. 1.00 was output as 1.0.
@item
Added attribute @code{'Locked'} to process list as info if a query is
locked by another query.
@item
Fixed full magic timestamp. Timestamp length may now be 14, 12, 10, 8, 6, 4
or 2 bytes.
@item
Sort on some numeric functions could sort incorrectly on last number.
@item
@code{IF(arg,syntax_error,syntax_error)} crashed.
@item
Added functions @code{CEILING()}, @code{ROUND()}, @code{EXP()}, @code{LOG()} and @code{SQRT()}.
@item
Enhanced @code{BETWEEN} to handle strings.
@end itemize
@node News-3.19.3, , News-3.19.4, News-3.19.x
@appendixsubsec Changes in release 3.19.3
@itemize @bullet
@item
Fixed @code{SELECT} with grouping on @code{BLOB} columns not to return
incorrect @code{BLOB} info. Grouping, sorting and distinct on @code{BLOB}
columns will not yet work as
expected (probably it will group/sort by the first 7 characters in the
@code{BLOB}). Grouping on formulas with a fixed string size (use @code{MID()}
on a @code{BLOB}) should work.
@item
When doing a full join (no direct keys) on multiple tables with @code{BLOB}
fields, the @code{BLOB} was garbage on output.
@item
Fixed @code{DISTINCT} with calculated columns.
@end itemize
@node Bugs, TODO, News, Top
@appendix Known errors and design deficiencies in MySQL
The following is known bugs in @strong{MySQL} 3.23.22 that will be fixed
in the next release:
@itemize @bullet
@item
Searching on part keys on BDB tables doesn't return all rows:
@example
CREATE TABLE t1 (
user_id int(10) DEFAULT '0' NOT NULL,
name varchar(100),
phone varchar(100),
ref_email varchar(100) DEFAULT '' NOT NULL,
detail varchar(200),
PRIMARY KEY (user_id,ref_email)
)type=bdb;
INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777.hotmail.com','xxx'),(10292,'shirish','2333604','shirish.yahoo.com','ddsds'),(10292,'sonali','323232','sonali.bolly.com','filmstar');
select * from t1 where user_id=10292;
@end example
@end itemize
Other known problems:
@itemize @bullet
@item
You cannot build in another directory when using
MIT-pthreads. Because this requires changes to MIT-pthreads, we are not
likely to fix this.
@item
@code{BLOB} values can't ``reliably'' be used in @code{GROUP BY} or
@code{ORDER BY} or @code{DISTINCT}. Only the first @code{max_sort_length}
bytes (default 1024) are used when comparing @code{BLOB}bs in these cases.
This can be changed with the @code{-O max_sort_length} option to
@code{mysqld}. A workaround for most cases is to use a substring:
@code{SELECT DISTINCT LEFT(blob,2048) FROM tbl_name}.
@item
Calculation is done with @code{BIGINT} or @code{DOUBLE} (both are
normally 64 bits long). It depends on the function which precision one
gets. The general rule is that bit functions are done with @code{BIGINT}
precision, @code{IF}, and @code{ELT()} with @code{BIGINT} or @code{DOUBLE}
precision and the rest with @code{DOUBLE} precision. One should try to
avoid using bigger unsigned long long values than 63 bits
(9223372036854775807) for anything else than bit fields!
@item
All string columns, except @code{BLOB} and @code{TEXT} columns, automatically
have all trailing spaces removed when retrieved. For @code{CHAR} types this
is okay, and may be regarded as a feature according to ANSI SQL92. The bug is
that in @strong{MySQL}, @code{VARCHAR} columns are treated the same way.
@item
You can only have up to 255 @code{ENUM} and @code{SET} columns in one table.
@item
@code{safe_mysqld} re-directs all messages from @code{mysqld} to the
@code{mysqld} log. One problem with this is that if you execute
@code{mysqladmin refresh} to close and reopen the log,
@code{stdout} and @code{stderr} are still redirected to the old log.
If you use @code{--log} extensively, you should edit @code{safe_mysqld} to
log to @file{'hostname'.err} instead of @file{'hostname'.log} so you can
easily reclaim the space for the old log by deleting the old one and
executing @code{mysqladmin refresh}.
@item
In the @code{UPDATE} statement, columns are updated from left to right.
If you refer to a updated column, you will get the updated value instead of the
original value. For example:
@example
mysql> UPDATE tbl_name SET KEY=KEY+1,KEY=KEY+1
@end example
will update @code{KEY} with @code{2} instead of with @code{1}.
@item
You can't use temporary tables more than once in the same query.
@example
select * from temporary_table, temporary_table as t2;
@end example
@item
Because @strong{MySQL} allows you to work with table types that doesn't
support transactions (and thus can't @code{rollback} data) some things
behaves a little different in @strong{MySQL} than in other SQL servers:
(This is just to ensure that @strong{MySQL} never need to do a rollback
for a SQL command). This may be a little akward at times as column
values must be checked in the application, but this will actually give
you a nice speed increase as it allows @strong{MySQL} to do some
optimizations that otherwice would be very hard to do.
If you set a colum to a wrong value, @strong{MySQL} will instead of doing
a rollback instead store the @code{best possible value} in the column.
@itemize @bullet
@item
If you try to store a value outside of the range in a numerical column,
@strong{MySQL} will instead store the smallest or biggest possible value in
the column.
@item
If you try to store a string, that doesn't start with a number, into a
numerical column @strong{MySQL} will store 0 into it.
@item
If you try to to store @code{NULL} into a column that doesn't take
@code{NULL} values, @code{MySQL} will store 0 or @code{''} (empty
string) in it instead. (This behavour can however be changed with the
-DDONT_USE_DEFAULT_FIELDS compile option).
@item
@strong{MySQL} allows you to store some wrong date values into
@code{DATE} and @code{DATETIME} columns. (Like 2000-02-31 or 2000-02-00).
If the date is totally wrong, @strong{MySQL} will store the special
0000-00-00 date value in the column.
@item
If you set an @code{enum} to an not supported value, it will be set to
the error value 'empty string', with numeric value 0.
@end itemize
@item
If you execute a @code{PROCEDURE} on a query with returns an empty set then
in some cases the @code{PROCEDURE} will not transform the columns.
@end itemize
The following is known bugs in earlier versions of @strong{MySQL}:
@itemize @bullet
@item
You can get a hanged thread if you do a @code{DROP TABLE} on a table that is
one among many tables that is locked with @code{LOCK TABLES}.
@item
In the following case you can get a core dump:
@enumerate
@item
Delayed insert handler has pending inserts to a table.
@item
@code{LOCK table} with @code{WRITE}
@item
@code{FLUSH TABLES}
@end enumerate
@item
Before @strong{MySQL} 3.23.2 an @code{UPDATE} that updated a key with
a @code{WHERE} on the same key may have failed because the key was used to
search for records and the same row may have been found multiple times:
@example
UPDATE tbl_name SET KEY=KEY+1 WHERE KEY > 100;
@end example
A workaround is to use:
@example
mysql> UPDATE tbl_name SET KEY=KEY+1 WHERE KEY+0 > 100;
@end example
This will work because @strong{MySQL} will not use index on expressions in
the @code{WHERE} clause.
@item
Before @strong{MySQL} 3.23, all numeric types where treated as fixed-point
fields. That means you had to specify how many decimals a floating-point
field shall have. All results were returned with the correct number of
decimals.
@end itemize
For platform-specific bugs, see the sections about compiling and porting.
@cindex TODO
@node TODO, Porting, Bugs, Top
@appendix List of things we want to add to MySQL in the future (The TODO)
@menu
* TODO future:: Things that must done in the very near future
* TODO sometime:: Things that have to be done sometime
* TODO unplanned:: Some things we don't have any plans to do
@end menu
Everything in this list is in the order it will be done. If you want to
affect the priority order, please register a license or support us and
tell us what you want to have done more quickly. @xref{Licensing and Support}.
@node TODO future, TODO sometime, TODO, TODO
@appendixsec Things that must done in the real near future
@itemize @bullet
@item
Fail safe replication.
@item
Optimize, test and document transactions safe tables
@item
Subqueries. @code{select id from t where grp in (select grp from g where u > 100)}
@item
Port of @strong{MySQL} to BeOS.
@item
Add a temporary key buffer cache during @code{insert/delete/update} so that we
can gracefully recover if the index file gets full.
@item
If you perform an @code{ALTER TABLE} on a table that is symlinked to another
disk, create temporary tables on this disk.
@item
@code{RENAME table as table, table as table [,...]}
@item
Allow users to change startup options.
@item
FreeBSD and MIT-pthreads; Do sleeping threads take CPU?
@item
Check if locked threads take any CPU.
@item
Change to use mkstemp() instead of tempnam() for system that supports the call.
We need to add a my_mkstemp() function in mysys and also change the cache
code to not create the filename until we do the actual open.
@item
Allow join on key parts (optimization issue).
@item
Entry for @code{DECRYPT()}.
@item
@code{INSERT SQL_CONCURRENT} and @code{mysqld --concurrent-insert} to do
a concurrent insert at the end of the file if the file is read-locked.
@item
Remember @code{FOREIGN} key definitions in the @file{.frm} file.
@item
Server side cursors.
@item
Check if @code{lockd} works with modern Linux kernels; If not, we have
to fix @code{lockd}! To test this, start @code{mysqld} with
@code{--enable-locking} and run the different fork* test suits. They shouldn't
give any errors if @code{lockd} works.
@item
Allow SQL variables in @code{LIMIT}, like in @code{LIMIT @@a,@@b}.
@item
Don't add automatic @code{DEFAULT} values to columns. Give an error when using
an @code{INSERT} that doesn't contain a column that doesn't have a
@code{DEFAULT}.
@item
Caching of queries and results. This should be done as a separated
module that examines each query and if this is query is in the cache
the cached result should be returned. When one updates a table one
should remove as few queries as possible from the cache.
This should give a big speed bost on machines with much RAM where
queries are often repeated (like WWW applications).
One idea would be to only cache queries of type:
@code{SELECT CACHED ....}
@item
Fix @file{libmysql.c} to allow two @code{mysql_query()} commands in a row
without reading results or give a nice error message when one does this.
@item
Optimize @code{BIT} type to take 1 bit (now @code{BIT} takes 1 char).
@item
Check why MIT-pthreads @code{ctime()} doesn't work on some FreeBSD systems.
@item
Add @code{ORDER BY} to update. This would be handy with functions like:
@code{generate_id(start,step)}.
@item
Add an @code{IMAGE} option to @code{LOAD DATA INFILE} to not update
@code{TIMESTAMP} and @code{AUTO_INCREMENT} fields.
@item
Make @code{LOAD DATA INFILE} understand a syntax like:
@example
LOAD DATA INFILE 'file_name.txt' INTO TABLE tbl_name
TEXT_FIELDS (text_field1, text_field2, text_field3)
SET table_field1=concatenate(text_field1, text_field2), table_field3=23
IGNORE text_field3
@end example
@item
@code{LOAD DATA INFILE 'file_name' INTO TABLE 'table_name' ERRORS TO err_table_name}
which would cause any errors/warnings to be logged into the err_table_name
table. That table would have a structure like:
@example
line_number - line number in data file
error_message - the error/warning message
and maybe
data_line - the line from the data file
@end example
@item
We should extend @code{LOAD DATA INFILE} so that we can skip over extra
columns in the text file.
@item
Add true @code{VARCHAR} support (There is already support for this in MyISAM).
@item
Automatic output from @code{mysql} to netscape.
@item
@code{LOCK DATABASES}. (with various options)
@item
Change sort to allocate memory in ``hunks'' to get better memory utilization.
@item
@code{DECIMAL} and @code{NUMERIC} types can't read exponential numbers;
@code{Field_decimal::store(const char *from,uint len)} must be recoded
to fix this.
@item
Fix @code{mysql.cc} to do fewer @code{malloc()} calls when hashing field
names.
@item
Functions:
ADD_TO_SET(value,set) and REMOVE_FROM_SET(value,set)
@item
Add use of @code{t1 JOIN t2 ON ...} and @code{t1 JOIN t2 USING ...}
Currently, you can only use this syntax with @code{LEFT JOIN}.
@item
Add full support for @code{unsigned long long} type.
@item
Function @code{CASE}.
@item
Many more variables for @code{show status}. Counts for:
@code{INSERT}/@code{DELETE}/@code{UPDATE} statements. Records reads and
updated. Selects on 1 table and selects with joins. Mean number of
tables in select. Key buffer read/write hits (logical and real).
@code{ORDER BY}, @code{GROUP BY}, temporary tables created.
@item
If you abort @code{mysql} in the middle of a query, you should open
another connection and kill the old running query.
Alternatively, an attempt should be made to detect this in the server.
@item
Add a handler interface for table information so you can use it as a system
table. This would be a bit slow if you requested information about all tables,
but very flexible. @code{SHOW INFO FROM tbl_name} for basic table information
should be implemented.
@item
Add support for UNICODE.
@item
@code{NATURAL JOIN}.
@item
Oracle like @code{CONNECT BY PRIOR ...} to search hierarchy structures.
@item
@code{RENAME DATABASE}
@item
@code{mysqladmin copy database new-database}.
@item
Processlist should show number of queries/thread.
@item
@code{DELETE} and @code{REPLACE} options to the @code{UPDATE} statement
(this will delete rows when one gets a dupplicate key error while updating).
@item
Change the format of @code{DATETIME} to store fractions of seconds.
@item
Add all missing ANSI92 and ODBC 3.0 types.
@item
Change table names from empty strings to @code{NULL} for calculated columns.
@item
Don't use 'Item_copy_string' on numerical values to avoid
number->string->number conversion in case of:
@code{SELECT COUNT(*)*(id+0) FROM table_name GROUP BY id}
@item
Make it possible to use the new GNU regexp library instead of the current
one (The GNU library should be much faster than the old one).
@item
Change that @code{ALTER TABLE} doesn't abort clients that executes
@code{INSERT DELAYED}.
@item
Allow @code{select a from crash_me left join crash_me2 using (a)}; In this
case a is assumed to come from the crash_me table.
@item
Fix that when columns referenced in an @code{UPDATE} clause contains the old
values before the update started.
@item
Allow update of varibles in @code{UPDATE} statements. For example:
@code{UPDATE TABLE foo SET @@a=a+b,a=@@a, b=@@a+c}
@item
@code{myisamchk}, @code{REPAIR} and @code{OPTIMIZE TABLE} should be able
to handle cases where the data and/or index files are symbolic links.
@item
Add simulation of @code{pread()}/@code{pwrite()} on windows to enable
concurrent inserts.
@item
A logfile analyzer that could parsed out information about which tables
are hit most often, how often multi-table joins are executed, etc. It
should help users identify areas or table design that could be optimized
to execute much more efficient queries.
@end itemize
@node TODO sometime, TODO unplanned, TODO future, TODO
@appendixsec Things that have to be done sometime
@itemize @bullet
@item
Implement function: @code{get_changed_tables(timeout,table1,table2,...)}
@item
Atomic updates; This includes a language that one can even use for
a set of stored procedures.
@item
@code{update items,month set items.price=month.price where items.id=month.id;}
@item
Change reading through tables to use memmap when possible. Now only
compressed tables use memmap.
@item
Add a new privilege @strong{'Show_priv'} for @code{SHOW} commands.
@item
Make the automatic timestamp code nicer. Add timestamps to the update
log with @code{SET TIMESTAMP=#;}
@item
Use read/write mutex in some places to get more speed.
@item
Full foreign key support. One probably wants to implement a procedural
language first.
@item
Simple views (first on one table, later on any expression).
@item
Automatically close some tables if a table, temporary table or temporary files
gets error 23 (not enough open files).
@item
When one finds a field=#, change all occurrences of field to #. Now this
is only done for some simple cases.
@item
Change all const expressions with calculated expressions if possible.
@item
Optimize key = expression. At the moment only key = field or key =
constant are optimized.
@item
Join some of the copy functions for nicer code.
@item
Change @file{sql_yacc.yy} to an inline parser to reduce its size and get
better error messages (5 days).
@item
Change the parser to use only one rule per different number of arguments
in function.
@item
Use of full calculation names in the order part. (For ACCESS97)
@item
@code{UNION}, @code{MINUS}, @code{INTERSECT} and @code{FULL OUTER JOIN}.
(Currently only @code{LEFT OUTER JOIN} is supported)
@item
Allow @code{UNIQUE} on fields that can be @code{NULL}.
@item
@code{SQL_OPTION MAX_SELECT_TIME=#} to put a time limit on a query.
@item
Make the update log to a database.
@item
Negative @code{LIMIT} to retrieve data from the end.
@item
Alarm around client connect/read/write functions.
@item
Make a @code{mysqld} version which isn't multithreaded (3-5 days).
@item
Please note the changes to @code{safe_mysqld}: according to FSSTND (which
Debian tries to follow) PID files should go into @file{/var/run/<progname>.pid}
and log files into @file{/var/log}. It would be nice if you could put the
"DATADIR" in the first declaration of "pidfile" and "log", so the
placement of these files can be changed with a single statement.
@item
Better dynamic record layout to avoid fragmentation.
@item
@code{UPDATE SET blob=read_blob_from_file('my_gif') where id=1;}
@item
Allow a client to request logging.
@item
Add use of @code{zlib()} for @code{gzip}-ed files to @code{LOAD DATA INFILE}.
@item
Fix sorting and grouping of @code{BLOB} columns (partly solved now).
@item
Stored procedures. This is currently not regarded to be very
important as stored procedures are not very standardized yet.
Another problem is that true stored procedures make it much harder for
the optimizer and in many cases the result is slower than before
We will, on the other hand, add a simple (atomic) update language that
can be used to write loops and such in the @strong{MySQL} server.
@item
Change to use semaphores when counting threads. One should first implement
a semaphore library to MIT-pthreads.
@item
Don't assign a new @code{AUTO_INCREMENT} value when one sets a column to 0.
Use @code{NULL} instead.
@item
Add full support for @code{JOIN} with parentheses.
@item
Reuse threads for systems with a lot of connections.
@item
As an alternative for one thread / connection manage a pool of threads
to handle the queries.
@item
Allow one to get more than one lock with @code{GET_LOCK}. When doing this,
one must also handle the possible deadlocks this change will introduce.
@end itemize
Time is given according to amount of work, not real time.
@node TODO unplanned, , TODO sometime, TODO
@appendixsec Some things we don't have any plans to do
@itemize @bullet
@item
Nothing; In the long run we plan to be fully ANSI 92 / ANSI 99 compliant.
@end itemize
@node Porting, Regexp, TODO, Top
@appendix Comments on porting to other systems
A working Posix thread library is needed for the server. On Solaris 2.5
we use Sun PThreads (the native thread support in 2.4 and earlier
versions are not good enough) and on Linux we use LinuxThreads by Xavier
Leroy, @email{Xavier.Leroy@@inria.fr}.
The hard part of porting to a new Unix variant without good native
thread support is probably to port MIT-pthreads. See
@file{mit-pthreads/README} and
@uref{http://www.humanfactor.com/pthreads/, Programming POSIX Threads}.
The @strong{MySQL} distribution includes a patched version of
Provenzano's Pthreads from MIT (see
@uref{http://www.mit.edu:8001/people/proven/pthreads.html, MIT Pthreads
web page}). This can be used for some operating systems that do not
have POSIX threads.
It is also possible to use another user level thread package named
FSU Pthreads (see
@uref{http://www.informatik.hu-berlin.de/~mueller/pthreads.html, FSU Pthreads
home page}). This implementation is being used for the SCO port.
See the @file{thr_lock.c} and @file{thr_alarm.c} programs in the @file{mysys}
directory for some tests/examples of these problems.
Both the server and the client need a working C++ compiler (we use @code{gcc}
and have tried SparcWorks). Another compiler that is known to work is the
Irix @code{cc}.
To compile only the client use @code{./configure --without-server}.
There is currently no support for only compiling the server, nor is it
likly to be added unless someone has a good reason for it.
If you want/need to change any @file{Makefile} or the configure script you must
get Automake and Autoconf. We have used the @code{automake-1.2} and
@code{autoconf-2.12} distributions.
All steps needed to remake everything from the most basic files.
@example
/bin/rm */.deps/*.P
/bin/rm -f config.cache
aclocal
autoheader
aclocal
automake
autoconf
./configure --with-debug --prefix='your installation directory'
# The makefiles generated above need GNU make 3.75 or newer.
# (called gmake below)
gmake clean all install init-db
@end example
If you run into problems with a new port, you may have to do some debugging
of @strong{MySQL}!
@xref{Debugging server}.
@strong{Note:} Before you start debugging @code{mysqld}, first get the test
programs @code{mysys/thr_alarm} and @code{mysys/thr_lock} to work. This
will ensure that your thread installation has even a remote chance to work!
@menu
* Debugging server:: Debugging a @strong{MySQL} server
* Debugging client:: Debugging a @strong{MySQL} client
* The DBUG package:: The DBUG package
* Locking methods::
* RTS-threads:: Comments about RTS threads
* Thread packages:: Differences between different thread packages
@end menu
@node Debugging server, Debugging client, Porting, Porting
@appendixsec Debugging a MySQL server
If you are using some functionality that is very new in @strong{MySQL},
you can try to run mysqld with the @code{--skip-new} (which will disable all
new, potentially unsafe functionality) or with @code{--safe-mode} which
disables a lot of optimization that may cause problems.
@xref{Crashing}.
If @code{mysqld} doesn't want to start, you should check that you don't have
any @code{my.cnf} files that interfere with your setup!
You can check your @code{my.cnf} arguments with @code{mysqld --print-defaults}
and avoid using them by starting with @code{mysqld --no-defaults ...}.
If you have some very specific problem, you can always try to debug
@strong{MySQL}. To do this you must configure @strong{MySQL} with the
option @code{--with-debug}. You can check whether or not
@strong{MySQL} was compiled with debugging by doing: @code{mysqld
--help}. If the @code{--debug} flag is listed with the options then you
have debugging enabled. @code{mysqladmin ver} also lists the
@code{mysqld} version as @code{mysql ... -debug} in this case.
If you are using gcc or egcs, the recommended configure line is:
@example
CC=gcc CFLAGS="-O6" CXX=gcc CXXFLAGS="-O6 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-debug --with-extra-charsets=complex
@end example
This will avoid problems with the @code{libstdc++} library and with C++
exceptions (many compilers have problems with C++ exceptions in threaded
code) and compile a @strong{MySQL} version with support for all character sets.
If @code{mysqld} stops crashing when you compile it with
@code{--with-debug}, you have probably found a compiler bug or a timing
bug within @strong{MySQL}. In this case you can try to add @code{-g} to
the @code{CFLAGS} and @code{CXXFLAGS} variables above and not use
@code{--with-debug}. If @code{mysqld} now dies, you can at least attach
to it with @code{gdb} or use @code{gdb} on the core file to find out
what happened.
If you can cause the @code{mysqld} server to crash quickly, you can try to
create a trace file of this:
Start the @code{mysqld} server with a trace log in @file{/tmp/mysql.trace}.
The log file will get very @emph{BIG}.
@code{mysqld --debug --log}
or you can start it with
@code{mysqld --debug=d,info,error,query,general,where:O,/tmp/mysql.trace}
which only prints information with the most interesting tags.
When you configure @strong{MySQL} for debugging you automatically enable a
lot of extra safety check functions that monitor the health of @code{mysqld}.
If they find something ``unexpected,'' an entry will be written to
@code{stderr}, which @code{safe_mysqld} directs to the error log! This also
means that if you are having some unexpected problems with @strong{MySQL} and
are using a source distribution, the first thing you should do is to
configure @strong{MySQL} for debugging! (The second thing, of course, is to
send mail to @email{mysql@@lists.mysql.com} and ask for help. Please use the
@code{mysqlbug} script for all bug reports or questions regarding the
@strong{MySQL} version you are using!
On most system you can also start @code{mysqld} from @code{gdb} to get
more information if @code{mysqld} crashes.
With some older @code{gdb} versions on Linux you must use @code{run
--one-thread} if you want to be able to debug @code{mysqld} threads. In
this case you can only have one thread active at a time.
It's very hard to debug @strong{MySQL} under @code{gdb} if you do a lot of
new connections the whole time as @code{gdb} doesn't free the memory for
old threads. You can avoid this problem by starting @code{mysqld} with
@code{-O thread_cache_size= 'max_connections +1'}. In most cases just
using @code{-O thread_cache_size= 5'} will help a lot!
If you are using gdb 4.17.x or above on Linux, you should install a
@file{.gdb} file, with the following information, in your current
directory:
@example
set print sevenbit off
handle SIGUSR1 nostop noprint
handle SIGUSR2 nostop noprint
handle SIGWAITING nostop noprint
handle SIGLWP nostop noprint
handle SIGPIPE nostop
handle SIGALRM nostop
handle SIGHUP nostop
handle SIGTERM nostop noprint
@end example
If you have problems debugging threads with gdb, you should download
gdb 5.x and try this instead. The new gdb version has very improved
thread handling!
Here follows an example how to debug mysqld:
@example
shell> gdb /usr/local/libexec/mysqld
gdb> run
...
back # Do this when mysqld crashes
info locals
up
info locals
up
...
(until you get some information about local variables)
quit
@end example
Include the above output in a mail generated with @code{mysqlbug} and
mail this to @code{mysql@@lists.mysql.com}.
If @code{mysqld} hangs you can try to use some system tools like
@code{strace} or @code{/usr/proc/bin/pstack} to examine where
@code{mysqld} has hung.
If @code{mysqld} starts to eat up CPU or memory or if it ``hangs'', you
can use @code{mysqladmin processlist status} to find out if someone is
executing a query that takes a long time. It may be a good idea to
run @code{mysqladmin -i10 processlist status} in some window if you are
experiencing performance problems or problems when new clients can't connect.
If @code{mysqld} dies or hangs, you should start @code{mysqld} with
@code{--log}. When @code{mysqld} dies again, you can check in the log
file for the query that killed @code{mysqld}. Note that before starting
@code{mysqld} with @code{--log} you should check all your tables with
@code{myisamchk}. @xref{Maintenance}.
If you are using a log file, @code{mysqld --log}, you should check the
'hostname' log files, that you can find in the database directory, for
any queries that could cause a problem. Try the command @code{EXPLAIN}
on all @code{SELECT} statements that takes a long time to ensure that
mysqld are using indexes properly. @xref{EXPLAIN, , @code{EXPLAIN}}. You
should also test complicated queries that didn't complete within the
@code{mysql} command line tool.
If you find the text @code{mysqld restarted} in the error log file (normally
named @file{hostname.err}) you have probably found a query that causes
@code{mysqld} to fail. If this happens you should check all your tables with
@code{myisamchk} (@pxref{Maintenance}), and test the queries in the
@strong{MySQL} log files to see if one doesn't work. If you find such a query,
try first upgrading to the newest @strong{MySQL} version. If this doesn't
help and you can't find anything in the @code{mysql} mail archive, you should
report the bug to @email{mysql@@lists.mysql.com}. Links to mail archives are
available online at the @uref{http://www.mysql.com/documentation/, @strong{MySQL}
documentation page}.
If you get corrupted tables or if @code{mysqld} always fails after some
update commands, you can test if this bug is reproducible by doing the
following:
@itemize @bullet
@item
Stop the mysqld daemon (with @code{mysqladmin shutdown})
@item
Check all tables with @code{myisamchk -s database/*.MYI}. Repair any
wrong tables with @code{myisamchk -r database/table.MYI}.
@item
Start @code{mysqld} with @code{--log-update}. @xref{Update log}.
@item
When you have gotten a crashed table, stop the @code{mysqld server}.
@item
Restore the backup.
@item
Restart the @code{mysqld} server @strong{without} @code{--log-update}
@item
Re-execute the commands with @code{mysql < update-log}. The update log
is saved in the @strong{MySQL} database directory with the name
@code{your-hostname.#}.
@item
If the tables are corrupted again, you have found reproducible bug
in the @code{ISAM} code! FTP the tables and the update log to
@uref{ftp://support.mysql.com/pub/mysql/secret} and we will fix this as soon as
possible!
@end itemize
The command @code{mysqladmin debug} will dump some information about
locks in use, used memory and query usage to the mysql log file. This
may help solve some problems. This command also provides some useful
information even if you haven't compiled @strong{MySQL} for debugging!
If the problem is that some tables are getting slower and slower you
should try to optimize the table with @code{OPTIMIZE TABLE} or
@code{myisamchk}. @xref{Maintenance}. You should also check the slow
queries with @code{EXPLAIN}.
You should also read the OS-specific section in this manual for
problems that may be unique to your environment.
@xref{Source install system issues}.
@findex DBI->trace
@findex trace DBI method
@tindex DBI_TRACE environment variable
@tindex Environment variable, DBI_TRACE
If you are using the Perl @code{DBI} interface, you can turn on
debugging information by using the @code{trace} method or by
setting the @code{DBI_TRACE} environment variable.
@xref{Perl DBI Class, , Perl @code{DBI} Class}.
@node Debugging client, The DBUG package, Debugging server, Porting
@appendixsec Debugging a MySQL client
To be able to debug a @strong{MySQL} client with the integrated debug package,
you should configure @strong{MySQL} with @code{--with-debug}.
@xref{configure options}.
@tindex MYSQL_DEBUG environment variable
@tindex Environment variable, MYSQL_DEBUG
Before running a client, you should set the @code{MYSQL_DEBUG} environment
variable:
@example
shell> MYSQL_DEBUG=d:t:O,/tmp/client.trace
shell> export MYSQL_DEBUG
@end example
This causes clients to generate a trace file in @file{/tmp/client.trace}.
If you have problems with your own client code, you should attempt to
connect to the server and run your query using a client that is known to
work. Do this by running @code{mysql} in debugging mode (assuming you
have compiled @strong{MySQL} with debugging on):
@example
shell> mysql --debug=d:t:O,/tmp/client.trace
@end example
This will provide useful information in case you mail a bug report.
@xref{Bug reports}.
If your client crashes at some 'legal' looking code, you should check
that your @file{mysql.h} include file matches your mysql library file.
A very common mistake is to use an old @file{mysql.h} file from an old
@strong{MySQL} installation with new @strong{MySQL} library.
@node The DBUG package, Locking methods, Debugging client, Porting
@appendixsec The DBUG package.
The @strong{MySQL} server and most @strong{MySQL} clients are compiled
with the DBUG package originally made by Fred Fish. When one has configured
@strong{MySQL} for debugging, this package makes it possible to get a trace
file of what the program is debugging.
One uses the debug package by invoking the program with the
@code{--debug="..."} or the @code{-#...} option.
The debug control string is a sequence of colon separated fields
as follows:
@example
<field_1>:<field_2>:...:<field_N>
@end example
Each field consists of a mandatory flag character followed by
an optional "," and comma separated list of modifiers:
@example
flag[,modifier,modifier,...,modifier]
@end example
The currently recognized flag characters are:
@multitable @columnfractions .1 .9
@item d @tab Enable output from DBUG_<N> macros for for the current state. May be followed by a list of keywords which selects output only for the DBUG macros with that keyword. A empty list of keywords implies output for all macros.
@item D @tab Delay after each debugger output line. The argument is the number of tenths of seconds to delay, subject to machine capabilities. I.E. @code{-#D,20} is delay two seconds.
@item f tab Limit debugging and/or tracing, and profiling to the list of named functions. Note that a null list will disable all functions. The appropriate "d" or "t" flags must still be given, this flag only limits their actions if they are enabled.
@item F @tab Identify the source file name for each line of debug or trace output.
@item i @tab Identify the process with the pid or thread id for each line of debug or trace output.
@item g @tab Enable profiling. Create a file called 'dbugmon.out' containing information that can be used to profile the program. May be followed by a list of keywords that select profiling only for the functions in that list. A null list implies that all functions are considered.
@item L @tab Identify the source file line number for each line of debug or trace output.
@item n @tab Print the current function nesting depth for each line of debug or trace output.
@item N @tab Number each line of dbug output.
@item o @tab Redirect the debugger output stream to the specified file. The default output is stderr.
@item O @tab As @code{O} but the file is really flushed between each write. When neaded the file is closed and reopened between each write.
@item p @tab Limit debugger actions to specified processes. A process must be identified with the DBUG_PROCESS macro and match one in the list for debugger actions to occur.
@item P @tab Print the current process name for each line of debug or trace output.
@item r @tab When pushing a new state, do not inherit the previous state's function nesting level. Useful when the output is to start at the left margin.
@item S @tab Do function _sanity(_file_,_line_) at each debugged function until _sanity() returns something that differs from 0. (Mostly used with safemalloc to find memory leaks)
@item t @tab Enable function call/exit trace lines. May be followed by a list (containing only one modifier) giving a numeric maximum trace level, beyond which no output will occur for either debugging or tracing macros. The default is a compile time option.
@end multitable
Some examples of debug control strings which might appear on a shell
command line (the "-#" is typically used to introduce a control string
to an application program) are:
@example
-#d:t
-#d:f,main,subr1:F:L:t,20
-#d,input,output,files:n
-#d:t:i:O,\\mysqld.trace
@end example
In @strong{MySQL}, common tags to print (with the @code{d} option) are:
@code{enter},@code{exit},@code{error},@code{warning},@code{info} and
@code{loop}.
@node Locking methods, RTS-threads, The DBUG package, Porting
@appendixsec Locking methods
Currently MySQL only supports table locking for
@code{ISAM}/@code{MyISAM} and @code{HEAP} tables and page level locking
for @code{BDB} tables. @xref{Internal locking}. With @code{MyISAM}
tables one can freely mix @code{INSERT} and @code{SELECT} without locks
(@code{Versioning}).
Some database users claim that @strong{MySQL} cannot support near the
number of concurrent users because it lacks row-level locking. This is
a may be true for some specific applications, but is' not generally
true. As always this depends totally on what the application does and what is the access/update pattern of the data.
Pros for row locking:
@itemize @bullet
@item
Fewer lock conflicts when accessing different rows in many threads.
@item
Less changes for rollbacks.
@item
Makes it possbile to lock a single row a long time.
@end itemize
Cons:
@itemize @bullet
@item
Takes more memory than page level or table locks.
@item
Is slower than page level or table locks when used one a big part of the table,
because one has to do many more locks.
@item
Is definitely much worse than other locks if you do often do @code{GROUP
BY} on a large part of the data or if one has to often scan the whole table.
@item
With higher level locks one can also more easily support locks of
different types to tune the application as the lock overhead is less
notable as for row level locks.
@end itemize
Table locks are superior to page level / row level locks in the
following cases:
@itemize @bullet
@item
Mostly reads
@item
Read and updates on strict keys; This is where one updates or deletes
a row that can be fetched with one key read:
@example
UPDATE table_name SET column=value WHERE unique_key#
DELETE FROM table_name WHERE unique_key=#
@end example
@item
@code{SELECT} combined with @code{INSERT} (and very few @code{UPDATE}'s
and @code{DELETE}'s.
@item
Many scans / @code{GROUP BY} on the whole table without any writers.
@end itemize
Other options than row / page level locking:
Versioning (like we use in MySQL for concurrent inserts) where you can
have one writer at the same time as many readers. This means that the
database/table supports different views for the data depending on when
one started to access it. Other names for this are time travel, copy
on write or copy on demand.
Copy on demand is in many case much better than page or row level
locking; The worst case does however use much more memory than
when using normal locks.
Instead of using row level locks one can use application level locks.
(Like get_lock/release_lock in @strong{MySQL}). This works of course
only in well-behaved applications.
In many cases one can do an educated guess which locking type is best
for the application but generally it's very hard to say that a given
lock type is better than another; Everything depends on the application
and different part of the application may require different lock types.
Here follows some tips about locking in @strong{MySQL}:
On web application most applications do lots of selects, very few
deletes, updates mainly on keys and inserts in some specific tables.
The base @strong{MySQL} setup is VERY tuned for this.
Concurrent users is not a problem if one doesn't mix updates and selects
that needs to examine many rows in the same table.
If one mix a insert and deletes on the same table then @code{INSERT DELAY}
may be of great help.
One can also use @code{LOCK TABLES} to speed up things (many updates within
a single lock is much faster than updates without locks). Splitting
thing to different tables will also helps.
If you get speed problems with the table locks in @strong{MySQL}, you
may be able to solve these to convert some of your tables to @code{BDB} tables.
@xref{BDB}.
The optimization section in the manual covers a lot of different aspects of
how to tune ones application. @xref{Tips}.
@node RTS-threads, Thread packages, Locking methods, Porting
@appendixsec Comments about RTS threads
I have tried to use the RTS thread packages with @strong{MySQL} but
stumbled on the following problems:
They use an old version of a lot of POSIX calls and it is very tedious to
make wrappers for all functions. I am inclined to think that it would
be easier to change the thread libraries to the newest POSIX
specification.
Some wrappers are already written. See @file{mysys/my_pthread.c} for more info.
At least the following should be changed:
@code{pthread_get_specific} should use one argument.
@code{sigwait} should take two arguments.
A lot of functions (at least @code{pthread_cond_wait},
@code{pthread_cond_timedwait})
should return the error code on error. Now they return -1 and set @code{errno}.
Another problem is that user-level threads use the @code{ALRM} signal and this
aborts a lot of functions (@code{read}, @code{write}, @code{open}...).
@strong{MySQL} should do a retry on interrupt on all of these but it is
not that easy to verify it.
The biggest unsolved problem is the following:
To get thread-level alarms I changed @file{mysys/thr_alarm.c} to wait between
alarms with @code{pthread_cond_timedwait()}, but this aborts with error
@code{EINTR}. I tried to debug the thread library as to why this happens,
but couldn't find any easy solution.
If someone wants to try @strong{MySQL} with RTS threads I suggest the
following:
@itemize @bullet
@item
Change functions @strong{MySQL} uses from the thread library to POSIX.
This shouldn't take that long.
@item
Compile all libraries with the @code{-DHAVE_rts_threads}.
@item
Compile @code{thr_alarm}.
@item
If there are some small differences in the implementation, they may be fixed
by changing @file{my_pthread.h} and @file{my_pthread.c}.
@item
Run @code{thr_alarm}. If it runs without any ``warning'', ``error'' or aborted
messages, you are on the right track. Here follows a successful run on
Solaris:
@example
Main thread: 1
Tread 0 (5) started
Thread: 5 Waiting
process_alarm
Tread 1 (6) started
Thread: 6 Waiting
process_alarm
process_alarm
thread_alarm
Thread: 6 Slept for 1 (1) sec
Thread: 6 Waiting
process_alarm
process_alarm
thread_alarm
Thread: 6 Slept for 2 (2) sec
Thread: 6 Simulation of no alarm needed
Thread: 6 Slept for 0 (3) sec
Thread: 6 Waiting
process_alarm
process_alarm
thread_alarm
Thread: 6 Slept for 4 (4) sec
Thread: 6 Waiting
process_alarm
thread_alarm
Thread: 5 Slept for 10 (10) sec
Thread: 5 Waiting
process_alarm
process_alarm
thread_alarm
Thread: 6 Slept for 5 (5) sec
Thread: 6 Waiting
process_alarm
process_alarm
...
thread_alarm
Thread: 5 Slept for 0 (1) sec
end
@end example
@end itemize
@node Thread packages, , RTS-threads, Porting
@appendixsec Differences between different thread packages
@strong{MySQL} is very dependent on the thread package used. So when
choosing a good platform for @strong{MySQL}, the thread package is very
important.
There are at least three types of thread packages:
@itemize @bullet
@item
User threads in a single process. Thread switching is managed with
alarms and the threads library manages all non-thread-safe functions
with locks. Read, write and select operations are usually managed with a
thread-specific select that switches to another thread if the running
threads have to wait for data. If the user thread packages are
integrated in the standard libs (FreeBSD and BSDI threads) the thread
package requires less overhead than thread packages that have to map all
unsafe calls (MIT-pthreads, FSU Pthreads and RTS threads). In some
environments (for example, SCO), all system calls are thread-safe so the
mapping can be done very easily (FSU Pthreads on SCO). Downside: All
mapped calls take a little time and it's quite tricky to be able to
handle all situations. There are usually also some system calls that are
not handled by the thread package (like MIT-pthreads and sockets). Thread
scheduling isn't always optimal.
@item
User threads in separate processes. Thread switching is done by the
kernel and all data are shared between threads. The thread package
manages the standard thread calls to allow sharing data between threads.
LinuxThreads is using this method. Downside: Lots of processes. Thread
creating is slow. If one thread dies the rest are usually left hanging
and you must kill them all before restarting. Thread switching is
somewhat expensive.
@item
Kernel threads. Thread switching is handled by the thread library or the
kernel and is very fast. Everything is done in one process, but on some
systems, @code{ps} may show the different threads. If one thread aborts, the
whole process aborts. Most system calls are thread-safe and should
require very little overhead. Solaris, HP-UX, AIX and OSF1 have kernel
threads.
@end itemize
In some systems kernel threads are managed by integrating user
level threads in the system libraries. In such cases, the thread
switching can only be done by the thread library and the kernel isn't
really ``thread aware''.
@node Regexp, Unireg, Porting, Top
@appendix Description of MySQL regular expression syntax
A regular expression (regex) is a powerful way of specifying a complex search.
@strong{MySQL} uses Henry Spencer's implementation of regular
expressions, which is aimed to conform to POSIX
1003.2. @strong{MySQL} uses the extended version.
This is a simplistic reference that skips the details. To get more exact
information, see Henry Spencer's @code{regex(7)} manual page that is
included in the source distribution. @xref{Credits}.
A regular expression describes a set of strings. The simplest regexp is
one that has no special characters in it. For example, the regexp
@code{hello} matches @code{hello} and nothing else.
Non-trivial regular expressions use certain special constructs so that
they can match more than one string. For example, the regexp
@code{hello|word} matches either the string @code{hello} or the string
@code{word}.
As a more complex example, the regexp @code{B[an]*s} matches any of the
strings @code{Bananas}, @code{Baaaaas}, @code{Bs} and any other string
starting with a @code{B}, ending with an @code{s}, and containing any
number of @code{a} or @code{n} characters in between.
A regular expression may use any of the following special
characters/constructs:
@table @code
@item ^
Match the beginning of a string.
@example
mysql> select "fo\nfo" REGEXP "^fo$"; -> 0
mysql> select "fofo" REGEXP "^fo"; -> 1
@end example
@item $
Match the end of a string.
@example
mysql> select "fo\no" REGEXP "^fo\no$"; -> 1
mysql> select "fo\no" REGEXP "^fo$"; -> 0
@end example
@item .
Match any character (including newline).
@example
mysql> select "fofo" REGEXP "^f.*"; -> 1
mysql> select "fo\nfo" REGEXP "^f.*"; -> 1
@end example
@item a*
Match any sequence of zero or more @code{a} characters.
@example
mysql> select "Ban" REGEXP "^Ba*n"; -> 1
mysql> select "Baaan" REGEXP "^Ba*n"; -> 1
mysql> select "Bn" REGEXP "^Ba*n"; -> 1
@end example
@item a+
Match any sequence of one or more @code{a} characters.
@example
mysql> select "Ban" REGEXP "^Ba+n"; -> 1
mysql> select "Bn" REGEXP "^Ba+n"; -> 0
@end example
@item a?
Match either zero or one @code{a} character.
@example
mysql> select "Bn" REGEXP "^Ba?n"; -> 1
mysql> select "Ban" REGEXP "^Ba?n"; -> 1
mysql> select "Baan" REGEXP "^Ba?n"; -> 0
@end example
@item de|abc
Match either of the sequences @code{de} or @code{abc}.
@example
mysql> select "pi" REGEXP "pi|apa"; -> 1
mysql> select "axe" REGEXP "pi|apa"; -> 0
mysql> select "apa" REGEXP "pi|apa"; -> 1
mysql> select "apa" REGEXP "^(pi|apa)$"; -> 1
mysql> select "pi" REGEXP "^(pi|apa)$"; -> 1
mysql> select "pix" REGEXP "^(pi|apa)$"; -> 0
@end example
@item (abc)*
Match zero or more instances of the sequence @code{abc}.
@example
mysql> select "pi" REGEXP "^(pi)*$"; -> 1
mysql> select "pip" REGEXP "^(pi)*$"; -> 0
mysql> select "pipi" REGEXP "^(pi)*$"; -> 1
@end example
@item @{1@}
@itemx @{2,3@}
The is a more general way of writing regexps that match many
occurrences of the previous atom.
@table @code
@item a*
Can be written as @code{a@{0,@}}.
@item a+
Can be written as @code{a@{1,@}}.
@item a?
Can be written as @code{a@{0,1@}}.
@end table
To be more precise, an atom followed by a bound containing one integer
@code{i} and no comma matches a sequence of exactly @code{i} matches of
the atom. An atom followed by a bound containing one integer @code{i}
and a comma matches a sequence of @code{i} or more matches of the atom.
An atom followed by a bound containing two integers @code{i} and
@code{j} matches a sequence of @code{i} through @code{j} (inclusive)
matches of the atom.
Both arguments must @code{0 >= value <= RE_DUP_MAX (default 255)}.
If there are two arguments, the second must be greater than or equal to the
first.
@item [a-dX]
@itemx [^a-dX]
Matches
any character which is (or is not, if ^ is used) either @code{a}, @code{b},
@code{c}, @code{d} or @code{X}. To include a literal @code{]} character,
it must immediately follow the opening bracket @code{[}. To include a
literal @code{-} character, it must be written first or last. So
@code{[0-9]} matches any decimal digit. Any character that does not have
a defined meaning inside a @code{[]} pair has no special meaning and
matches only itself.
@example
mysql> select "aXbc" REGEXP "[a-dXYZ]"; -> 1
mysql> select "aXbc" REGEXP "^[a-dXYZ]$"; -> 0
mysql> select "aXbc" REGEXP "^[a-dXYZ]+$"; -> 1
mysql> select "aXbc" REGEXP "^[^a-dXYZ]+$"; -> 0
mysql> select "gheis" REGEXP "^[^a-dXYZ]+$"; -> 1
mysql> select "gheisa" REGEXP "^[^a-dXYZ]+$"; -> 0
@end example
@item [[.characters.]]
The sequence of characters of that collating element. The sequence is a
single element of the bracket expression's list. A bracket expression
containing a multi-character collating element can thus match more than
one character, e.g., if the collating sequence includes a @code{ch}
collating element, then the regular expression @code{[[.ch.]]*c} matches the
first five characters of @code{chchcc}.
@item [=character_class=]
An equivalence class, standing for the sequences of characters of all
collating elements equivalent to that one, including itself.
For example, if @code{o} and @code{(+)} are the members of an
equivalence class, then @code{[[=o=]]}, @code{[[=(+)=]]}, and
@code{[o(+)]} are all synonymous. An equivalence class may not be an
endpoint of a range.
@item [:character_class:]
Within a bracket expression, the name of a character class enclosed in
@code{[:} and @code{:]} stands for the list of all characters belonging
to that class. Standard character class names are:
@multitable @columnfractions .33 .33 .33
@item alnum @tab digit @tab punct
@item alpha @tab graph @tab space
@item blank @tab lower @tab upper
@item cntrl @tab print @tab xdigit
@end multitable
These stand for the character classes defined in the @code{ctype(3)} manual
page. A locale may provide others. A character class may not be used as an
endpoint of a range.
@example
mysql> select "justalnums" REGEXP "[[:alnum:]]+"; -> 1
mysql> select "!!" REGEXP "[[:alnum:]]+"; -> 0
@end example
@item [[:<:]]
@itemx [[:>:]]
These match the null string at the beginning and end of a word
respectively. A word is defined as a sequence of word characters which
is neither preceded nor followed by word characters. A word character is
an alnum character (as defined by @code{ctype(3)}) or an underscore
(@code{_}).
@example
mysql> select "a word a" REGEXP "[[:<:]]word[[:>:]]"; -> 1
mysql> select "a xword a" REGEXP "[[:<:]]word[[:>:]]"; -> 0
@end example
@end table
@example
mysql> select "weeknights" REGEXP "^(wee|week)(knights|nights)$"; -> 1
@end example
@node Unireg, GPL license, Regexp, Top
@appendix What is Unireg?
Unireg is our tty interface builder, but it uses a low level connection
to our ISAM (which is used by @strong{MySQL}) and because of this it is
very quick. It has existed since 1979 (on Unix in C since ~1986).
Unireg has the following components:
@itemize @bullet
@item
One table viewer with updates/browsing.
@item
Multi table viewer (with one scrolling region).
@item
Table creator. (With lots of column tags you can't create with @strong{MySQL})
This is WYSIWYG (for a tty). You design a screen and Unireg prompts for
the column specification.
@item
Report generator.
@item
A lot of utilities (quick import/export of tables to/from text files,
analysis of table contents...).
@item
Powerful multi-table updates (which we use a lot) with a BASIC-like
language with LOTS of functions.
@item
Dynamic languages (at present in Swedish and Finnish). If somebody wants
an English version there are a few files that would have to be translated.
@item
The ability to run updates interactively or in a batch.
@item
Emacs-like key definitions with keyboard macros.
@item
All this in a binary of 800K.
@item
The @code{convform} utility. Converts @file{.frm} and text files between
different character sets.
@item
The @code{myisampack} utility. Packs an ISAM table (makes it 50-80%
smaller). The table can be read by @strong{MySQL} like an ordinary
table. Only one record has to be decompressed per access. Cannot handle
@code{BLOB} or @code{TEXT} columns or updates (yet).
@end itemize
We update most of our production databases with the Unireg interface and
serve web pages through @strong{MySQL} (and in some extreme cases the Unireg
report generator).
Unireg takes about 3M of disk space and works on at least the following
platforms: SunOS 4.x, Solaris, Linux, HP-UX, ICL Unix, DNIX, SCO and
MS-DOS.
Unireg is currently only available in Swedish and Finnish.
The price tag for Unireg is 10,000 Swedish kr (about $1500 US), but this
includes support. Unireg is distributed as a binary. (But all the ISAM
sources can be found in @strong{MySQL}). Usually we compile the binary for the
customer at their site.
All new development is concentrated to @strong{MySQL}.
@page
@c This node name is special
@node GPL license, LGPL license, Unireg, Top
@appendix GNU General Public License
@example
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.
@end example
@page
@node LGPL license, Function Index, GPL license, Top
@appendix GNU Library General Public License
@example
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!
@end example
@node Function Index, Concept Index, LGPL license, Top
@unnumbered SQL command, type and function index
@printindex fn
@page
@node Concept Index, , Function Index, Top
@unnumbered Concept Index
@printindex cp
@summarycontents
@contents
@bye
|