\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=#FFFFFF TEXT=#000000 LINK=#101090 VLINK=#7030B0 @c @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 @set _extra_head @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 @c @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? * Public license:: The @strong{MySQL} server license * Win license:: The @strong{MySQL} license for Microsoft operating systems * Function Index:: SQL command, type and function index * Concept Index:: Concept Index @end menu @cindex Overview @cindex General Information @node Introduction, Questions, Top, Top @chapter @strong{MySQL} についての一般情報 @menu * What-is:: @strong{MySQL} とは何か? * Manual-info:: このマニュアルについて * History:: @strong{MySQL} の歴史 * MySQL-Books:: Books about MySQL * Features:: @strong{MySQL}の主な機能 * Stability:: @strong{MySQL} はどれくらい安定か? * Year 2000 compliance:: 2000 年対応 * General-SQL:: 一般的な SQL 情報とチュートリアル * Useful Links:: 便利な @strong{MySQL} 関連リンク @end menu これは @strong{MySQL} のリファレンスマニュアルです; これは @strong{MySQL} バージョン @value{mysql_version} について記述しています。 @strong{MySQL} は発展中なので、マニュアルは頻繁に更新されます。そのため、 オンラインで参照しない限り、このバージョンが期限切れである可能性があります。 このマニュアルの最新バージョンは @uref{http://www.mysql.com/doc.html} に多 様な形式で置いてあります。マニュアル内の情報を見つけるつらい時間を持つなら、 検索可能 PHP バージョン @uref{http://www.mysql.com/php/manual.php3} を試す ことが可能です。 @strong{MySQL} はとても高速で、マルチスレッド、マルチユーザ、頑丈な SQL (Structured Query Language)データベースサーバです。 Unix と OS/2 プラットフォームでは @strong{MySQL} は基本的に無償であり、Microsoft プラットフォームでは、30日の試用期間を過ぎて使用する場合に @strong{MySQL} ライセンスを 買わなければなりません. @xref{Licensing and Support}. @uref{http://www.mysql.com/, @strong{MySQL} ホームページ}は @strong{MySQL} についての最新情報を提供しています。 次のリストはマニュアルのいくつかの有用なセクションを説明しています: @itemize @bullet @item @strong{MySQL} の能力の説明については、@ref{Features} を参照してください。 @item インストール方法については @ref{Installing} を参照してください。 @strong{MySQL} を新しいマシンや OS に移行するためのヒントについては @ref{Porting} を参照してください。 @item 3.21 リリースからのアップグレードについての情報は、 @ref{Upgrading-from-3.21} を参照してください。 @item @strong{MySQL} 導入のチュートリアルについては、@ref{Tutorial} を参照してください。 @item SQL の例とベンチマーク情報についてはベンチマーキングのディレクトリを参照 してください。(@file{sql-bench} ディレクトリです) @item 新しい機能とバグ修正の履歴については @ref{News} を参照してください。 @item 現在知られているバグと無い機能の一覧については @ref{Bugs} を参照してくだ さい。 @item 将来の計画については @ref{TODO} を参照してください。 @item このプロジェクトへの全ての貢献者のリストについては @ref{Credits} を参照してくだ さい。 @end itemize @strong{重要:} @c if the @email is at the beginning of a line the texi2html fails エラー(バグ)レポート、質問、コメントは メーリングリスト @email{mysql@@lists.mysql.com} に送ってください。@xref{Bug reports}。 バグレポートを生成するためには @code{mysqlbug} スクリプトを使用すべきです。 @c FIX! RPMs are also binary ソースディストリビューションでは、@code{mysqlbug} スクリプトは @file{scripts} ディレクトリ に見つけることができます。バイナリディストリビューションでは、@code{mysqlbug} は @file{bin} ディレクトリに見つけることができます。 @c FIX! Remeber to create the alias! このマニュアルへの追加または修正に関連する提案がある場合は、それらを @strong{MySQL} マニュアルチーム (@email{docs@@mysql.com})に 送ってください。 @cindex @strong{MySQL}, what it is @node What-is, Manual-info, Introduction, Introduction @section @strong{MySQL} とは何か? @strong{MySQL} は本当にマルチユーザ、マルチスレッドの SQL データベースサーバです。SQL は世界でもっともポピュラーな データベース言語です。@strong{MySQL} は、サーバデーモン @code{mysqld} と 多くの種類のクライアントプログラムとライブラリからなるクライアント/サー バ実装です。 SQLは、情報を保存し、更新し、そしてアクセスすることを簡単にするために標準化された言語です。 例えば、あなたは、商品案内を検索するためにSQLを使って、 ウェブサイトに関するカスタマー情報を蓄積することができます。 @strong{MySQL} は、ログや写真を保存させるにも、十分にはやく、フレキシブルです。 @strong{MySQL} の主な目的は高速で頑丈で簡単に使用できることです。 @strong{MySQL} は独自に開発されました。我々は、とても大きなデータ ベースを、他のデータベースベンダが我々に提供するものよりも速く、重要度の 順に処理できる SQL サーバを必要としていたからです。我々は、10,000 テー ブルを含む 40 以上のデータベースの環境で 1996 年から @strong{MySQL} を使 用しています。そのテーブルの 500 テーブル以上は 700万以上のレコードを持ちます。 これは約100ギガバイトの、基幹業務のデータです。 @strong{MySQL} が作成される上での基本は、何年もの間、製品環境の高い要求 で使用されていたルーチンのセットです。@strong{MySQL} はまだ開発中ですが、 豊富でとても有用な関数セットを既に提供しています。 @cindex How to pronounce @strong{MySQL} @cindex @strong{MySQL}, how to pronounce @strong{MySQL} の公式な発音は ``My Ess Que Ell'' です(MY-SEQUEL ではあり ません)。 @cindex Manual information @node Manual-info, History, What-is, Introduction @section このマニュアルについて このマニュアルは以下の方々により訳されました (ハンドル名だけ書きます。敬称略。翻訳サーバーに登録した順 :) ): @itemize @bullet @item 民斗 @item hama @item dale @item kippara @item kenji @item aoki @item tok21108 @item こむら @item tamori @end itemize @menu * Manual conventions:: Conventions used in this manual @end menu このマニュアルは現在 Texinfo, プレーンテキスト, Info, HTML, PostScript, PDF バージョン があります。サイズが大きいため Postscript と PDF バージョンは @strong{MySQL} のディストリビューションには含まれていませんが、別にダウン ロードするようになっています。@uref{http://www.mysql.com/}. プライマリドキュメントは Texinfo ファイルです。HTML バージョンは @code{texi2html} の変更されたバージョンで自動的に提供されます。プレーン テキストと Info バージョンは @code{makeinfo} で提供されます。PostScript バージョンは @code{texi2dvi} と @code{divps} を使用して提供されます。PDF バージョンは Ghostscript ユーティリティ @code{ps2pdf} で提供されます。 このマニュアルは David Axmark, Michael (Monty) Widenius, Paul DuBois, によって作成され、維持されています。他の貢献者については @ref{Credits} を参照してください。 @node Manual conventions, , Manual-info, Manual-info @subsection このマニュアル中で使用されている表記 このマニュアルは特定の印刷上の表記を使用しています: @table @asis @item @code{constant} 固定幅フォントは次のものに使用されます。コマンド名, オプション; SQL ステー トメント; データベース名, テーブル名, フィールド名; C と Perl コード; 環境変数。 例: ``@code{mysqladmin} がどのように動作するかを見るためには、 @code{--help} オプションをつけて起動してください。'' @item @file{filename} 引用符で括られた固定幅フォントはファイル名とパス名に使用されます。例: `` ディストリビューションは @file{/usr/local} ディレクトリ配下にインストールされます。'' @item @samp{c} 引用符で括られた固定幅フォントは文字シーケンスを示すためにも使用されます。 例: ``ワイルドカードを指定するためには、@samp{%} 文字を使用してください。'' @item @emph{italic} イタリックフォントは強調のために使用されます, @emph{このように}。 @item @strong{boldface} ボールドフォントはアクセス権名(例えば、``@strong{process} 権を容易に 与えないでください'')と、@strong{特に強い強調}を伝えるために使用されます。 @end table コマンドが特定のプログラムによって実行されることを意味することを表す時、 コマンドと共に表示されるプロンプトによって、そのプログラムを表します。例えば、 @code{shell>} は、あなたのログインシェルから実行するコマンドを表し、 @code{mysql>} は @code{mysql} クライアントプログラムから実行するコマンドを表します: @example shell> type a shell command here mysql> type a mysql command here @end example シェルコマンドは Bourne シェル構文で示されます。@code{csh} 形式のシェ ルを使用している場合は、わずかに変更してコマンドを発行する必要があるでしょ う。例えば、環境変数を設定してコマンドを実行するシーケンスは、Bourne シェ ル構文では次のようになります: @example shell> VARNAME=value some_command @end example @code{csh} では、次のようなシーケンスを実行してください: @example shell> setenv VARNAME value shell> some_command @end example データベース名, テーブル名, フィールド名はコマンドの中で置換しなければいけない ことがよくあります。このような置換が必要なことを示すために、このマニュア ルは @code{db_name}, @code{tbl_name}, @code{col_name} を使用します。 例えば、次のようなステートメントを見た場合: @example mysql> SELECT col_name FROM db_name.tbl_name; @end example これは、同様のステートメントを入力するためには、おそらく次のように、あな た自身のデータベース名, テーブル名, フィールド名を供給することを意味します: @example mysql> SELECT author_name FROM biblio_db.author_list; @end example SQL ステートメントは大文字でも小文字でも記述できます。このマニュアルが SQL ステートメントを示すときは、特別なキーワードを説明している時には(そ れを強調するために)そのキーワードに大文字が使用され、残りのステートメン トに小文字が使用されます。 例えば、@code{SELECT} ステートメントの説明中 には次が見られるでしょう: @example mysql> SELECT count(*) FROM tbl_name; @end example 一方、@code{COUNT()} 関数の説明中では、ステートメントは次のように書かれ ます: @example mysql> select COUNT(*) from tbl_name; @end example 特別な強調が意図されない場合、全てのキーワードは大文字で書かれます。 構文の説明中では、角括弧(@samp{[} と @samp{]})はオプションの単語や節であ ることを示すために使用されます: @example DROP TABLE [IF EXISTS] tbl_name @end example 構文要素がいくつかのものからなる場合、垂直バー(@samp{|})で区切られます。 選択セットから一つのメンバを選ぶことができるときは、角括弧中にリストされ ます。 (@samp{[} and @samp{]}): @example TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str) @end example 選択セットから一つのメンバを選ぶ必要があるときは、波括弧(@samp{@{} と @samp{@}})中にリストされます: @example @{DESCRIBE | DESC@} tbl_name @{col_name | wild@} @end example @cindex @strong{MySQL} version @node History, MySQL-Books, Manual-info, Introduction @section @strong{MySQL} の歴史 我々自身の速くて低レベルな (ISAM) ルーチンを使用する、我々のテーブルへ 接続するために、 我々は一度 @code{mSQL} を使用するつもりでした。しかし、いくつかのテストの後、我々は @code{mSQL} は我々が必要とするほど高速ではなく、柔軟度を持っていないとの 結論に至りました。この結果、@code{mSQL} とほとんど同じ API インタフェー スを持つ、我々のデータベースへの新しい SQL インタフェースに帰結しました。 この API はサードパーティコードの移植を簡単にするために選択されました。 @strong{MySQL} の名前の由来は完全には明らかではありません。我々のベース ディレクトリと多くのライブラリとツールは接頭辞 ``my'' を 10 年以上も使っ ています。しかし、Monty の娘(何年か若い)も My という名前です。そのため、 この2つのどちらが @strong{MySQL} に名前を与えたかは、我々にとっても未だ 謎です。 @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 are 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://mysql.com/Contrib/Examples/samp_db.tar.gz, @code{samp_db.tar.gz}} @item Errata @tab @uref{http://www.mysql.com/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 @strong{MySQL}の主な機能 @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 カーネルスレッドを使用する完全なマルチスレッド。これは有効であれば簡単に 複数の CPU を使用できることを意味します。 @item C, C++, Ruby, Eiffel, Java, Perl, PHP, Python そして Tcl API。@xref{Clients}。 @item 多くの種類のプラットフォームで動作します。@xref{Which OS}。 @item 多くのフィールド型: 1, 2, 3, 4, 8 バイト長の符号付き/符号無し整数, @code{FLOAT}, @code{DOUBLE}, @code{CHAR}, @code{VARCHAR}, @code{TEXT}, @code{BLOB}, @code{DATE}, @code{TIME}, @code{DATETIME}, @code{TIMESTAMP}, @code{YEAR}, @code{SET}, @code{ENUM} 型。@xref{Column types}。 @item 最適化された one-sweep multi-join を使用するとても速い結合。 @item クエリの @code{SELECT} と @code{WHERE} 部内での全ての演算子と関数のサポー ト。例: @example mysql> SELECT CONCAT(first_name, " ", last_name) FROM tbl_name WHERE income/dependents > 10000 AND age > 30; @end example @item SQL 関数は高度に最適化されたクラスライブラリを通して実装されていて、それ が得ることのできるのと同じくらい速いのです! 普通、クエリの初期化の後に は、全くメモリ割り当てはありません。 @item SQL @code{GROUP BY} と @code{ORDER BY} 節の完全なサポート。グループ関数 (@code{COUNT()}, @code{COUNT(DISTINCT)}, @code{AVG()}, @code{STD()}, @code{SUM()}, @code{MAX()}, @code{MIN()}) のサポート。 @item ANSI SQL と ODBC 構文での @code{LEFT OUTER JOIN} のサポート。 @item 同一クエリ内に異なるデータベースからのテーブルを混在できます (バージョン 3.22)。 @item とても柔軟で安全な 特権システム とパスワードシステム。 ホストベースの証明が可能です。 サーバに接続する時の全てのパスワードトラフィックは暗号化されているためパ スワードは安全です。 @item Windows95 の ODBC (Open-DataBase-Connectivity) (ソースつき)。全ての ODBC 2.5 関数と他の多く。あなたの @strong{MySQL} サーバに接続するために、例え ば Access を使用できます。@xref{ODBC}。 @item インデックス圧縮つきのとても速い B-tree ディスクテーブル。 @item テーブル毎に 16 インデックスが許されます。各インデックスは 1 から 16 個 のフィールドまたはフィールドの一部からなります。最大インデックス長は 256 バイトです (これは @strong{MySQL} のコンパイル時に変更できます)。インデックスは @code{CHAR} または @code{VARCHAR} フィールドの先頭部分を使用できます。 @item 固定長と可変長のレコード。 @item 一時テーブルとして使用されるメモリ内ハッシュテーブル。 @item 大きなデータベースの操作。我々は、50,000,000 レコードを含むいくつかのデー タベースで @strong{MySQL} を使用しています。 @item 全てのフィールドはデフォルト値を持ちます。 テーブル項目のサブセットを挿入するた めに @code{INSERT} を使用でき、明示的に値が与えられていないフィールドはそのデ フォルト値が設定されます。 @item 可搬性のために GNU Automake, Autoconf, @code{libtool} を使用しています。 @item C と C++ で書かれています。広範な種類のコンパイラでテストされてます。 @item とても速いスレッドベースのメモリ割り当てシステム。 @item メモリリークがありません。市販のメモリリーク検出製品(@code{purify})でテ ストされています。 @item @code{myisamchk} を含んでいます。これは、テーブル検査、最適化、修復のため のとても速いユーティリティです。@xref{Maintenance}。 @item 異なるキャラクタセットの完全なサポート。ISO-8859-1 (Latin1), big5, ujis など。 例えば、スカンジナビ ア語文字 @ringaccent{a}, @"a そして @"o はテーブル名やフィールド名として許され ます。 @item 全てのデータは 選択されたキャラクターセットの形式で保存されています。通常文字列フィールド の全ての比較はケース非依存です。 @item ソートは、@strong{MySQL} サーバー起動時に、選択されたキャラクターセットに に従って行なわれます。(デフォルトは、スウェーデン語の方法)。 ソース内に新しいソート順序配列を追加することで、こ れは変更可能です。とても先進的なソートの例を見るには、Czech ソートコード を見てください。 @strong{MySQL} は多くの種類のキャラクタセットをサポート し、コンパイル時や実行時に指定できます。 @item SQL92 標準にあるようなテーブルとフィールドのエイリアス名。 @item @code{DELETE}, @code{INSERT}, @code{REPLACE}, @code{UPDATE} は 変更された(影響を受けた)行の数を返します。 サーバ接続時にフラグを設定することにより、代わりに適合したレコード数を返す ことも可能です。 @item 関数名はテーブル名やフィールド名と衝突しません。例えば @code{ABS} は正しいフィールド 名です。制限は、関数呼び出しに、関数名とそれに続く @samp{(} の間に空白が 許されないことだけです。@xref{Reserved words}。 @item 全ての @strong{MySQL} プログラムはオンラインヘルプを得るために、 @code{--help} と @code{-?} オプションで呼び出すことができます。 @item サーバは多くの言語でクライアントへのエラーメッセージを提供できます。 @xref{Languages}。 @item クライアントは、TCP/IP 接続または Unix ソケット、あるいは NT の場合は ネームドパイプを使用して @strong{MySQL} サーバと接続します。 @item @strong{MySQL} 固有の @code{SHOW} コマンドはデータベース、テーブル、イン デックスについての情報を取出すために使用できます。@code{EXPLAIN} コマン ドはオプティマイザがどのようにクエリを解析するかを決定するために使用 できます。 @end itemize @cindex Stability @node Stability, Year 2000 compliance, Features, Introduction @section @strong{MySQL} はどれくらい安定か? この節では、``@strong{MySQL} はどれくらい安定か?'' と ``私はこのプロジェ クトで @strong{MySQL} に依存できるか?'' という質問について回答します。 我々はここで、いくつかの問題を明らかにし、多くの人に関係すると思われるさ らに重要な質問のいくつかを回答することを試みます。この節は、メーリングリ スト(そこではとても活発にバグが報告されています)から取り込まれた情報が一 緒に置かれています。 TcX では、@strong{MySQL} は 1996 中頃から我々のプロジェクトで何の問題も なく動いていました。広く公にリリースされた時、我々は、@strong{MySQL} 内 に ``テストされていないコード'' の部分があることに注意しました。これは、 我々とは異なる方法でクエリを作成する新しいユーザによってすぐに見つけられました。 新しい各リリースは、(多くの新しい機能を持っているのに)前のものよりも問題 は少なくなります。そして次のリリースの一つを ``安定'' と呼ぶことができるよ うに我々は望んでいます。 @strong{MySQL} の各リリースは実用的で、ユーザが ``グレイゾーン'' からの コードの使用を開始する時にだけ問題があります。当然、外部のユーザは、何が グレイゾーンかを知ることができません; この節で現在知られているこれらを示 してみます。 説明は @strong{MySQL} の 3.22.x バージョンで扱われます。知られていて報告 されているバグは全て最新のバージョンで修正されています。bugs 節に 書かれているバグは除きます。それらは ``設計'' 関連のものです。@xref{Bugs}. @strong{MySQL} は複数の階層と様々な独立モジュールで書かれています。これ らのモジュールは、それぞれがどのようにテストされているかとともに次にリス トされています: @table @strong @item ISAM テーブル処理 --- 安定 これは @strong{MySQL} 3.22 とそれ以前のバージョンにおいて、 全てのデータの保存と検索を管理します。全ての @strong{MySQL} リリースでは、 このコード内には(報告された)バグは一つもありません。不正なテーブルを得る 唯一の方法は、更新の途中にあるサーバを殺すことだけです。そして各クエリ間 で全てのデータはディスクにフラッシュされるため、いかなるデータも 修復外の破壊が起こるということはまずないでしょう。 @strong{MySQL} 内のバグのためにデータが 失われたというバグレポートは一つもありません。 @item The MyISAM table handler --- Beta これは @strong{MySQL} 3.23 での新機能です. これは ISAM テーブルのコードを元に拡張されていますが、 多くの便利な機能を持っています。 @item パーサと単語解析 --- 安定 このシステム内には長い間バグは一つも報告されていません。 @item C クライアントコード --- 安定 知られている問題はありません。3.20 リリースの初期には、送信/受信バッファ サイズにいくつかの制限がありました。3.21.x 以降、バッファはデフォルトの 24M まで動的に大きくなります。 @item 標準クライアントプログラム --- 安定 これらは @code{mysql}, @code{mysqladmin}, @code{mysqlshow}, @code{mysqldump}, @code{mysqlimport} を含みます. @item 基本的な SQL --- 安定 基本的な SQL 機能システムと文字列節と動的メモリ処理。このシステムには報 告されたバグは一つもありません。 @item クエリオプティマイザ --- 安定 @item 範囲オプティマイザ --- 安定 @item 結合オプティマイザ --- 安定 @item ロック --- ガンマ これはとてもシステムに依存しています。いくつかのシステムでは、これは、標 準 OS ロック (fcntl) を使用するため大きな問題があります。これらの場合で は、@strong{MySQL} デーモンを @code{--skip-locking} フラグつきで動かすべ きです。知られている問題は、いくつかの Linux システムと NFS マウントされ たファイルシステム使用時の SunOS です。 @item Linux スレッド --- ガンマ @code{fcntl()} コールでだけ問題が見つかっています。これは @code{mysqld} への @w{@code{--skip-locking}} オプションの使用で修正できます。何人かは 0.5 リリースで lockup 問題を報告しました。1000以上の同時接続を使用する予 定であれば、LinuxThreads を再コンパイルする必要があります。しかし、デフォ ルトの LinuxThread でも多くの接続を実行することは可能です(しかし 1021 以 上にならないようにしてください)。デフォルトの 2MB のスタック空間は、アプ リケーションを不安定にします。そして 1021 個のアイドル接続の生成後に coredump を引き起こします。詳しくは Linux Notes をご覧ください。 @item Solaris 2.5+ pthread --- 安定 我々は、我々の全ての製品でこれを使用しています。 @item MIT スレッド (他のシステム) --- ガンマ 3.20.15 から報告されたバグはありません。3.20.15 から知られたバグはありま せん。いくつかのシステムでは、いくつかの操作が遅くなるという ``misfeature'' があります(1/20 秒の sleep が各クエリ間で行なわれます)。 もちろん、MIT スレッドはすべてを少し遅くします。しかしインデックスベース の @code{SELECT} では、ステートメントは通常一度のフレームで行われるため、 mutex locking/thread juggling はありません。 @item 他のスレッド実装 --- アルファ - ベータ 他のシステムへの移行はまだとても新しく、多分 @strong{MySQL} に、しかし一 番多いのはスレッド実装自身に、多くのバグを持っています。 @item @code{LOAD DATA...}, @code{INSERT ... SELECT} --- 安定 何人かはこれにバグを見つけたと考えましたが、それは結局誤解でした。問題の 報告の前にマニュアルを良くチェックしてください! @item @code{ALTER TABLE} --- 安定 3.22.12 で少し変更しました。 @item DBD --- 安定 現在、Jochen Wiedmann @email{wiedmann@@neckar-alb.de} によってメンテされています。感謝! @item @code{mysqlaccess} --- ガンマ @email{Yves.Carlier@@rug.ac.be} によって書かれメンテされてます。感謝! @item @code{GRANT} --- ガンマ @strong{MySQL} 3.22.12 で大きな変更が行なわれました。 @item @strong{MyODBC} (uses ODBC SDK 2.5) --- ガンマ いくつかのプログラムでちゃんと動作しているように見えます。 @end table TcX は代金を支払った顧客のために email サポートを提供しています。しかし @strong{MySQL} メーリングリストは通常、全ての一般的な質問に回答を提供し ています。バグは通常すぐにパッチで修正され、深刻なバグには、ほとんどいつ も新しいリリースがあります。 @cindex Year 2000 compliance @node Year 2000 compliance, General-SQL, Stability, Introduction @section 2000 年対応 @strong{MySQL} 自身は 2000 年問題(Y2K)に対して何の問題も持っていません: @itemize @bullet @item @strong{MySQL} は Unix 時間関数を使用し、@code{2069} 年まで日付には何の 問題もありません; 全ての2桁の年は @code{1970} から @code{2069} の範囲に あると見なされます。これは、@code{year} フィールド内に @code{01} を格納する場 合、@strong{MySQL} はそれを @code{2001} として扱うということを意味します。 @item 全ての @strong{MySQL} 日付関数は一つのファイル @file{sql/time.cc} に格納 され、2000年安全にとても注意深くコード化されています。 @item @strong{MySQL} 3.22 以降のバージョンでは、新しい @code{YEAR} フィールド型は @code{0} と @code{1901} から @code{2155} までの年を1バイトで格納でき、2 桁または4桁で表示できます。 @end itemize 2000年安全でない方法で @strong{MySQL} を使用するアプリケーションでは問題 になります。例えば、多くの古いアプリケーションは4桁値ではなく2桁値(これ は曖昧です)を使用して年を格納し操作します。この問題は、@code{00} または @code{99} のような値を ``欠けている'' 値の表われとして使用するアプリケー ションによって作られます。 あいにく、これらの問題を修正するのは困難です。様々なアプリケーションが様々 なプログラムによって書かれていて、その各々が慣習と日付操作関数の様々な組 み合わせを使用するからです。 これは、MySQL が 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 これは、@code{DATE} と @code{DATETIME} 型は未来のいかなる日付において 問題のないことををしめします (これら日付は 9999 年まで扱えます) @code{TIMESTAMP} 型は、時刻を保存しますが、@code{2030-01-01} までです。 @code{TIMESTAMP} は 32-bit マシンでは @code{1970} から @code{2030} の範囲です。 64-bit マシンでは、 @code{2106} 年まで扱えれます。 @strong{MySQL} は 2000年対応ですが、曖昧でない入力を提供するのはあなたの 責任です。曖昧な日付の入力データ(2桁の年の値)の扱いについての @strong{MySQL} の規則については @ref{Y2K issues} を参照してください。 @node General-SQL, Useful Links, Year 2000 compliance, Introduction @section 一般的な SQL 情報とチュートリアル この本は @strong{MySQL} メーリングリストの数人によって推奨されています: @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 この本も @strong{MySQL} ユーザーにいくつかの推薦を受けています: @example Martin Gruber Understanding SQL ISBN 0-89588-644-8 Publisher Sybex 510 523 8233 Alameda, CA USA @end example SQL チュートリアルがネット上にあります @url{http://www.geocities.com/SiliconValley/Vista/2207/sql1.html} SQL in 21 Tagen (online book in German language): @url{http://www.mut.de/leseecke/buecher/sql/inhalt.htm} @node Useful Links, , General-SQL, Introduction @section 便利な @strong{MySQL} 関連リンク 次のリンク以外にも、多くの @strong{MySQL} プログラム、ツール、API を @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 tutoral 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.ecker-software.de, Win32 GUI client} A Win32 GUI client by David Ecker. @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), pcANYWHERET(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 クライアント/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 (Frik Bilhaut) @uref{http://www.penguinpowered.com/~kmysql, KMySQL} KMySQL is a database client for KDE that primarily supports @strong{MySQL}. @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://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. @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 @strong{MySQL} をサポートする Web 開発ツール @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)} @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 @strong{MySQL} ツールでの Web サーバ @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. @end itemize @subheading @strong{API} 関連リンク @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 他の @strong{MySQL} 関連リンク @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} @item @c Removed 990510 @c @item @c @uref{http://www.cgishop.com/bin/mysqllist, @strong{MySQL} Apps and @c Utilities Listing} @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 とデータベースインタフェース @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 例とソース @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://www.productivity.org/projects/mysql/, @strong{TmySQL}; A library to use @strong{MySQL} with Delphi} @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} @end itemize @subheading 一般的なデータベースリンク @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 @strong{MySQL} を使用した多くの web ページもあります。@xref{Users}。この リストへ追加できるものを @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 @strong{MySQL} メーリングリストと質問をする方法またはエラー(バグ)を報告する方法 @menu * Mailing-list:: @strong{MySQL} メーリングリスト * Asking questions:: 質問やバグの報告 * Bug reports:: バグや問題を報告する方法 * Answering questions:: メーリングリストで質問に答えるためのガイドライン @end menu @node Mailing-list, Asking questions, Questions, Questions @section @strong{MySQL} メーリングリスト メイン @strong{MySQL} メーリングリストを購読するには、メッセージを 電子メールアドレス @email{mysql-subscribe@@lists.mysql.com} に送ってください。 メイン @strong{MySQL} メーリングリストの購読の中止は、メッセージを 電子メールアドレス @email{mysql-unsubscribe@@lists.mysql.com} に送ってください。 メッセージを送る先のアドレスだけが重要です。メッセージのサブジェクトと 本文は無視されます。 @c the last two addresses in this paragraph are NOT @email because they @c shouldn't be live links. もし、あなたのリプライアドレスが妥当な物でない場合、アドレスを明確に指定することが出来ます。 subscribe あるいは unsubscribe のあとにハイフンを付け、そのあとにあなたの アドレスを記述します。ただし @samp{@@} 文字は @samp{=} に置き変えて書きます。 例えば、 @code{john@@host.domain} で購読したい場合、 @code{mysql-subscribe-john=host.domain@@lists.mysql.com} 宛にメッセージを送ります。 @email{mysql-subscribe@@lists.mysql.com} や @email{mysql-unsubscribe@@lists.mysql.com} へのメールは ezmlm メーリングリストプロセッサによって自動的に処理されます。 ezmlm についての情報は @uref{http://www.ezmlm.org, The ezmlm Website}. 本メーリングリストへの投稿を行うには、@code{mysql@@lists.mysql.com} にメッセージを送ります。 しかし、subscribe あるいは unsubscribe のメールを @email{mysql@@lists.mysql.com} に@emph{送らないでください}。 これらのアドレスへ送られたメールは、何千ものユーザーに配送されてしまいます。 あなたのローカルサイトが多くの @email{mysql@@lists.mysql.com} 購読者を持つことも あります。この場合、ローカルメーリングリストを作り、@code{lists.mysql.com} からの 一つのメッセージがそのサイトに送られ、ローカルなリストで複写されるように してください。この場合、ローカルの @strong{MySQL} リストへの追加と削除は、 あなたのシステム管理者に問い合わせて下さい。 次の @strong{MySQL} メーリングリストがあります: @table @code @item announce これは @strong{MySQL} と関連プログラムの新しいバージョンのアナウンスのた めです。これは、全ての @strong{MySQL} ユーザが入るべきと我々が考える少な い量のリストです。 @item mysql 一般の @strong{MySQL} 議論のための主なリストです。さらに専門的なリストに 行くべきものもあることに注意してください。間違ったリストに投稿しても、答 を得られないでしょう! @item mysql-digest ダイジェスト形式の @code{mysql} リストです。これは、一日に一回、一つの大 きなメールが送られることで個々のメッセージ全てが得られることを意味します。 @item bugs このリストには、完全で再現可能なバグレポートだけを、@code{mysqlbug} を使 用して投稿すべきです(Windows 上で実行している場合は、OS と @strong{MySQL} バージョンの記述を含めるべきです)。できれば、投稿前に @strong{MySQL} の最新の安定バージョンか開発バージョンを使用して問題をテ ストすべきです! 含められたテストケース上で、'mysql test < script' を使 用することで、誰もがバグを再現できるべきです。このリストに投稿された全て のバグは、次の @strong{MySQL} リリースで修正されるかドキュメント化されま す! 小さなコードの変更だけですめば、我々はこの問題を修正するパッチの投 稿も行ないます。 @item bugs-digest ダイジェスト形式の @code{bugs} リストです。 @item developer @strong{MySQL} コードを動かす人のためのリスト。このリストでは @strong{MySQL} 開発の議論とパッチの投稿も可能です。 @item developer-digest @code{developer} リストのダイジェストバージョン。 @item java @strong{MySQL} と Java についての議論。多くは JDBC ドライバについてです。 @item java-digest @code{java} リストのダイジェストバージョン。 @item win32 Windows NT のような Microsoft OS 上の @strong{MySQL} に関連する全て。 @item win32-digest @code{win32} リストのダイジェストバージョン。 @item myodbc ODBC で @strong{MySQL} への接続に関連する全て。 @item myodbc-digest @code{myodbc} リストのダイジェストバージョン。 @item msql-mysql-modules @strong{MySQL} でサポートする Perl についてのリスト。 @item msql-mysql-modules-digest @code{msql-mysql-modules} リストのダイジェストバージョン。 @end table 上述したのと同じ方法で全てのリストの購読または購読中止ができます。あなた の購読または購読中止のメッセージは、@code{mysql} ではなく適切なメーリングリス トに送ってください。例えば、 @code{myodbc} リストを購読または購読中止するには、 @email{myodbc-subscribe@@lists.mysql.com} または @email{myodbc-unsubscribe@@lists.mysql.com} にメールを送ります。 @cindex Net etiquette @node Asking questions, Bug reports, Mailing-list, Questions @section 質問またはバグ報告 メーリングリストへ質問を尋ねる前に、以下の手順を踏んでください: @itemize @bullet @item @strong{MySQL} のオンラインマニュアルを調べることからはじめます: @example @uref{http://www.mysql.com/Manual_chapter/manual_toc.html} @end example 我々は、新しく見つかった問題の解決でマニュアルを頻繁に更新することで、それを 最新に保持しようとしています! @item @strong{MySQL} メーリングリストアーカイブを検索します: @example @uref{http://www.mysql.com/doc.html} @end example @item @uref{http://www.mysql.com/} の全ての Web ページ(マニュアルも含む)を検索するために @uref{http://www.mysql.com/search.html} も使用できます。 @end itemize ここで回答が見つけられない場合は、近くの @strong{MySQL} 熟練者ととも に調べて下さい。まだあなたの質問の回答が見つけられなければ、先に進み、次 のセクションの @email{mysql@@lists.mysql.com} へメールを送る方法についてを読んで ください。 @cindex Bug reports @cindex Reporting bugs @node Bug reports, Answering questions, Asking questions, Questions @section バグや問題を報告する方法 良いバグレポートを書くのは忍耐が要りますが、それを最初に正しく行なうこと は我々とあなたから時間を節約します。 そのバグについての完全なテストケースを含む良いバグレポートは、次のリリー スでそれが修正される可能性がとても高くなります。 この節では、かなりの、または全く我々 の助けにならないことにあなたの時間を浪費しないように、あなたがレポートを 正しく書くことを手助けします。 我々は、バグレポートまた可能ならば全ての問題についてのレポートの作成に @code{mysqlbug} スクリプトを使用することを奨励します。@code{mysqlbug} は ソース配布内の @file{scripts} ディレクトリ、または、バイナリ配布では @strong{MySQL} をインストールしたディレクトリ配下の @file{bin} ディレク トリから見つけられます。@code{mysqlbug} を使用できない場合は、この節に挙 げられている全ての必要な情報を含めるべきです。 @code{mysqlbug} スクリプトは、下記の多くの情報を自動的に見つけ出すことで、 レポートの作成を手助けします。しかし、重要な何かが足りない場合、あなたの メッセージにそれを含めてください! この節を慎重に読んで、ここで述べられ ている全ての情報がレポート中に含まれていることを確認してください。 バグを明確に示すテストケースを作ることができれば、 @email{bugs@@list.mysql.com} リストにそれを投稿してください。注意: この リストには、完全で再現可能なバグ情報を @code{mysqlbug} スクリプトを使用 して投稿すべきです(Windows 上で実行している場合は、OS と @strong{MySQL} バージョンの記述を含めるべきです)。できれば、投稿前に @strong{MySQL} の最新の安定バージョンか開発バージョンを使用して問題をテ ストすべきです! 含められたテストケース上で、'mysql test < script' を使 用することで、または、バグレポートに含められたシェル/Perlスクリプトを実 行することで、誰もがバグを再現できるべきです。このリストに投稿された全て のバグは、次の @strong{MySQL} リリースで修正されるかドキュメント化されま す! 小さなコードの変更だけですめば、我々はこの問題を修正するパッチの投 稿も行ないます。 多すぎる情報を含むメッセージに答えることはできますが、少なすぎる情報を含 むものにはできないということを覚えていてください。しばしば人は事実を省い てしまいます。問題の原因をわかっていると思い、いくつかの詳細を重大でない と見なしてしまうからです。良い原則は: 何かを言おうか迷ったときには、言っ てください! 最初にあなたが十分な情報を含めなかったために、再び質問して 回答を待つことを強要されるより、数行をあなたのレポートに書く方が千倍速く て迷惑ではありません。 良くある間違いは、使用している @strong{MySQL} 配布のバージョン番号を示さ ない、または @strong{MySQL} をインストールしたプラットフォームを(プラッ トフォームのバージョン番号を含めて)示さない事です。これはとても関連した 情報で、100 のバグレポートのうち 99 の場合、この情報がないと役に立ちませ ん! 我々は ``何故私では動作しないの?'' のような質問をとても良く受けま す。そして我々は、要求された機能はその @strong{MySQL} バージョンに実装さ れていない、または、レポート中に述べられているバグは新しい @strong{MySQL} バージョンで既に修正されているであることを見つけます。時々、 エラーはプラットフォーム依存で、オペレーティングシステムとプラットフォー ムのバージョン番号を知らないことには、何も修正することはできません。 問題に関連している場合は、コンパイラについての情報も与えることを忘れない でください。しばしば人はコンパイラのバグを見つけて、問題は @strong{MySQL} に関連していると考えます。多くのコンパイラはいつも開発中 で、バージョンを上げることによってより良いバージョンになります。問題がコ ンパイラに依存しているかどうかを確定するには、どのコンパイラが使用されて いるかを知ることが必要です。全てのコンパイルの問題はバグレポートとみなさ れ、それに従って報告されるべきであることに注意してください。 最も役に立つのは、問題の良い説明がバグレポートに含められることです。つま り、問題に導かれる全ての行なったことの例と、正確に記述された問題それ自身 です。良いバグレポートは、バグや問題を再現する方法を示す完全な例を含むも のです。 問題がエラーメッセージを与える場合、それをレポートに含めることはとても重 要です! 我々がプログラムを使用するアーカイブから何かを検索しようとする 場合、エラーメッセージはプログラムが与えたものと正確に一致する方が良いで す(大文字小文字も守られるべきです!)。どのようなエラーメッセージだったか を覚えるなんてことはしてはいけません;レポートに完全なメッセージをコピー し張りつけてください。 MyODBC での問題がある場合、MyODBC トレースファイルの生成を試みるべきです。 @xref{MyODBC bug report}。 あなたのレポートを読む多くの人が 80桁ディスプレイを使用しているというこ とを覚えておいて下さい。従って、@code{mysql} コマンドラインツールを使用 してレポートまたはサンプルを生成する時、そのようなディスプレイの有効幅を 超える出力(例えば、@code{EXPLAIN SELECT} ステートメント; 後述のサンプル を見てください)には、@code{--vertical} オプション(または @code{\G} ステー トメント終端)を使用すべきです。 次の情報をレポートに含めてください: @itemize @bullet @item 使用している @strong{MySQL} 配布のバージョン番号 (例えば @strong{MySQL} 3.22.22)。どのバージョンを動かしているかは @code{mysqladmin version} の 実行で見つけられます。@code{mysqladmin} は @strong{MySQL} のインストール ディレクトリ配下の @file{bin} ディレクトリに見つけられます。 @item あなたが作業しているマシンのメーカーとモデル。 @item オペレーティングシステム名とバージョン。多くのオペレーティングシステムで は、Unix コマンド @code{uname -a} の実行によってこの情報が得られます。 @item 時にはメモリ(実メモリと仮想メモリ)の量も関係します。疑わしければ、それを 含めてください。 @item @strong{MySQL} のソース配布を使用している場合は、使用したコンパイラの名 前とバージョン番号につての情報も必要です。バイナリ配布の場合は、配布名が 必要です。 @item 問題がコンパイル中に発生する場合、正確なエラーメッセージと、エラーが発生 したファイルの問題のコードの回りの数行も含めて下さい。 @item 何かのデータベーステーブルが問題に関連する場合は、 @code{mysqldump --no-data db_name tbl_name1 tbl_name2 ...} からの出力を含めて ください。これはデータベース内の任意のテーブルについての情報を得るとても 簡単で強力な方法で、我々があなたの状況に一致するものを生成する手助けにな ります。 @item @code{SELECT} ステートメントでの速度に関するバグや問題では、 @code{EXPLAIN SELECT ...} の出力と、少なくとも @code{SELECT} ステートメ ントが与える行の数を常に含めるべきです。あなたの状況について、より多くの 情報を、誰かがあなたを助けられるように、より適切に与えてください! 例え ば、次はとても良いバグレポートの例です(もちろん @code{mysqlbug} スクリプトで投 稿されてます): @code{mysql} コマンド行ツール配下での実行例(注意: 出力幅がディスプレイ装 置の80桁を超えるステートメントには、@code{\G} ステートメント終端を使用し てください): @example mysql> SHOW VARIABLES; mysql> SHOW COLUMNS FROM ...\G mysql> EXPLAIN SELECT ...\G mysql> FLUSH STATUS; mysql> SELECT ...; mysql> SHOW STATUS; @end example @item 問題やバグが @strong{MySQL} 実行中に発生する場合、バグを再現する入力スク リプトが必要です。このスクリプトは必要なソースファイル全てを含めるべきで す。より精密なスクリプトはあなたのに似た状況を良く再現できます。 もしスクリプトを提供することができなければ、少なくとも、 @code{mysqladmin variables extended-status processlist} の 出力結果をメールにを含むべきです。 これはあなたのシステムの情報を 提供します! @item @strong{MySQL} がクエリから異常な結果を与えると思う場合は、結果だけでな く、結果がどうなるべきかというあなたの意見と、あなたの意見の基本を説明す る理由も含めてください。 @item 問題のサンプルを提供する時に、新しい名前にするよりも、実際の状況で存在す るのと同じ変数名やテーブル名等を使用した方が良いです。問題は変数やテーブ ル等の名前に関連することがあります! おそらくこれはまれなケースですが、 sorry よりも safe の方が良いです。結局、実際に持っているあなたのサンプル 中の同じ状況を使用することはあなたにとっても簡単で、我々にとっても全ての 意味で良いことです。他の人に見せたくないデータをいくつか持っている場合、 @code{ftp} を使用して @uref{ftp://www.mysql.com/pub/mysql/secret/} にデー タを転送することができます。データが本当に最高機密で我々にさえ見せたくな い場合は、先に進んで、他の変数名等を使用してサンプルを作ってみてください。 しかしこれは最後の選択と思ってください。 @item 可能ならば、関連プログラムに与えられた全てのオプションを含めてください。 例えば、@code{mysqld} デーモン開始時に使用したオプションと @strong{MySQL} クライアントプログラム実行に使用したオプションを示してく ださい。。@code{mysqld}, @code{mysql} または @code{configure} スクリプト へのオプションはしばしば回答へのキーになり、とても関連しています! とに かくそれらを含めるというのは悪い考えではありません! Perl や PHP などの モジュールを使用している場合、それらのバージョン番号も含めてください。 @item 数行のテストケースを提供できない場合、またはテストテーブルがメーリングリ ストにメールするには大きすぎる(10行以上)場合、@code{mysqldump} を使用し てあなたのテーブルをダンプし、あなたの問題を説明した @file{README} ファ イルを作るべきです。 @code{tar} と @code{gzip} または @code{zip} を使用して、ファイルの圧縮アー カイブを生成し、そのアーカイブを @code{ftp} を使用して @uref{ftp://www.mysql.com/pub/mysql/secret/} に転送してください。それか ら問題の短い説明を @email{mysql@@lists.mysql.com} に送ってください。 @item 質問が権限システムに関連する場合、@code{mysqlaccess} の出力、 @code{mysqladmin reload} の出力、接続しようとした時に得られた全てのエラー メッセージを含めてください! 権限をテストする時、まず @code{mysqlaccess} を実行すべきです。その後、@code{mysqladmin reload version} を実行し、最 後に問題が発生するプログラムでの接続を試みるべきです。@code{mysqlaccess} は@strong{MySQL} インストールディレクトリ配下の @file{bin} ディレクトリ に見つけられます。 @item あなたがバグについてのパッチを持っているのは良い事ですが、そ のパッチがすべて、我々が求めているもので、あなたのパッチが修正するバグの テスト情報を提供しなくても、我々がそれを使用するだろう、 と思わないでください。我々はあなたのパッチに問題を見つけるかもしれません し、または、それを全く理解できないかもしれません。その場合はそれを使用で きません。 そのパッチに意味があることが正確に確かめられなければ、我々はそれを使用し ません。テストケースは我々にこの手助けをします。パッチが起りうる全ての状 況を扱うことを示してください。パッチが動作しない境界線のケース(それが稀 でも)を見つけた場合、パッチは使用されないでしょう。 @item 何がバグか、何故発生するのか、何に依存しているのか、についての推測は通常 間違いです。我々でさえ、まずデバッガを使用してバグの実際の原因を見つけな ければ、そのことは推測できません。 @item メールメッセージ中に、あなたがリファレンスマニュアルとメールアーカイブを チェックしたことを示してください。そうすれば、あなたの問題をあなた自身で 解決しようとしたことを他の人がわかります。 @item @code{パースエラー}が発生する場合、構文を厳密にチェックしてください! 何 が間違っているのかを見つけられなければ、多分、使用しているクエリを @strong{MySQL} の現在のバージョンがサポートしていないということです。現 在のバージョンを使用していて、@uref{http://www.mysql.com/doc.html} のマ ニュアルがあなたの使用しているクエリ構文をカバーしていない場合は、これは @strong{MySQL} があなたのクエリをサポートしていないという意味です。この 場合、あなたの選択は、その構文をあなた自身で実装することか、 @email{mysql-support@@mysql.com} に email でこれを実装するように申し込むこ とです! マニュアルがあなたの使用している構文をカバーしているのに@strong{MySQL} の古いバージョンを使用している場合、文法が実装された時期について @strong{MySQL} の変更履歴をチェックすべきです。@xref{News}。この場合、よ り新しいバージョンの @strong{MySQL} へのアップグレードを選択できます。 @item もしあなたのデータが悪くなったように思えたり、または、ある特定の テーブルにアクセスする時、エラーとなるなら、 まず最初に、テーブルを @code{myisamchk} で検査し、修復を試みるべきです @xref{Maintenance}. @item もししょっちゅうテーブルがダメになるようなら、いつ、なぜ起こるのかを 探し出すべきです! この場合、@file{mysql-data-directory/'hostname'.err} ファイルに 何が起こっているのか含まれている場合があります。 このファイルから 関連する情報を抜きだしバグレポートに含めてください! 通常、 @code{mysqld} は 更新の最中に kill されない限りは テーブルを@strong{絶対に}破壊しません! もしなぜ @code{mysqld} が死ぬのか 見つけた場合は、我々があなたに問題解決のための修正を提供することが、 はるかに簡単になります! @xref{What is crashing} @item 可能な場合、最新の @strong{MySQL} バージョンをダウンロードして、これで問 題が解決されるかどうかをチェックしてください。全ての @strong{MySQL} バー ジョンは通してテストされ、問題なしに動作します! 全てが可能な限り以前と 互換があるように作られていて、すぐに @strong{MySQL} バージョンを切り替え ることができると我々は信じています! @xref{Which version}。 @end itemize あなたがサポート顧客なら、より高い優先順位で取り扱うため @email{mysql-support@@mysql.com} にバグレポートをクロスポストしてください。 同様に、他の誰かが問題を経験済み(そしておそらく解決済み)かどうかを知るた めに適切なメーリングリストにも。 @strong{MyODBC} のバグ報告上の情報については、@ref{ODBC Problems} を参照 してください。 いくつかの一般的な問題の解決法のために → @xref{Problems}. 回答があなたに個人的に送られて、メーリングリストに送られていない時、回答 を要約し、あなたの問題の解決の手助けになった返事の恩恵を他の人にも与える ために、その要約をメーリングリストに送信することは、良いエチケットです! @cindex Net etiquette @node Answering questions, , Bug reports, Questions @section メーリングリストで質問に答えるためのガイドライン あなたの回答が広く関心を持たれると考えられる場合、尋ねた人に個人的に直接 返事をする代わりに、メーリングリストに投稿したいと思うでしょう。オリジナ ルの投稿者以外の人もそれから恩恵を受けられるように十分一般的に回答を作成 することを試みてください。メーリングリストに投稿する場合は、あなたの回答 が以前の回答と重複していないか確認して下さい。 あなた返事の中で、質問の本質部分の要約を試みてください。質問全体を引用す ることを義務と感じないで下さい。 HTML モードを ON にしたブラウザからメールメッセージを投稿しないでくださ い! 多くのユーザはブラウザでメールを読んでいません! @cindex Licensing terms @cindex Support terms @node Licensing and Support, Installing, Questions, Top @chapter @strong{MySQL} ライセンスとサポート (訳注:正確さをきすため原文を併記しています。訳文だけでなく原文に目を通してください。 もし意味の取違いを見つけたなら、@email{takeshi@@SoftAgency.co.jp} に連絡してください。) @menu * Licensing policy:: @strong{MySQL} licensing policy * Licensing policy on Win32:: * Copyright:: Copyrights used by @strong{MySQL} * Commercial use:: Distributing @strong{MySQL} commercially * Licensing examples:: Example licensing situations * Cost:: @strong{MySQL} licensing and support costs * Support:: Types of commercial support @end menu This chapter describes @strong{MySQL} licensing and support arrangements, including: 本章では @strong{MySQL} のライセンスとサポート契約について述べます。 @itemize @bullet @item Our licensing policies for non-Microsoft and Microsoft operating systems @item The copyrights under which @strong{MySQL} is distributed (@pxref{Copyright}) @item Sample situations illustrating when a license is required (@pxref{Licensing examples}) @item Licensing and support costs (@pxref{Cost}), and support benefits (@pxref{Support}) @end itemize @itemize @bullet @item 非Microsoft と Mirosoft のオペレーティングシステムに対するライセンスのポリシー @item @strong{MySQL} 配布における著作権 (@pxref{Copyright}) @item ライセンスが必要となる場合の例 (@pxref{Licensing examples}) @item ライセンスとサポートの費用 (@pxref{Cost}), そして サポートの利益 (@pxref{Support}) @end itemize @cindex Licensing policy @node Licensing policy, Licensing policy on Win32, Licensing and Support, Licensing and Support @section @strong{MySQL} licensing policy The formal terms of the license for non-Microsoft operating systems such as Unix or OS/2 are specified in @ref{Public license}. Basically, our licensing policy is as follows: UnixやOS/2などの非マイクロソフトオペレーティングシステムにおけるライセンスの 正式な条項は @ref{Public license}. に明記してあります。 基本的に、我々のライセンスのポリシーは以下のようになっています: @itemize @bullet @item For normal internal use, @strong{MySQL} generally costs nothing. You do not have to pay us if you do not want to. @item A license is required if: @itemize @minus @item You sell the @strong{MySQL} server directly or as a part of another product or service @item You charge for installing and maintaining a @strong{MySQL} server at some client site @item You include @strong{MySQL} in a distribution that is non-redistributable and you charge for some part of that distribution @end itemize @item 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! @item You do not need a license to include client code in commercial programs. The client access part of @strong{MySQL} is in the public domain. The @code{mysql} command line client includes code from the @code{readline} library that is under the GNU Public License. @item @cindex @code{myisampack} For customers who have purchased 1 license or @strong{MySQL} support, we provide additional functionality. Currently, this means we provide the @code{myisampack} utility for creating fast compressed read-only databases. (The server includes support for reading such databases but not the packing tool used to create them.) When support agreements generate sufficient revenue, we will release this tool under the same license as the @strong{MySQL} server. @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 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 @itemize @bullet @item 内部での使用は、@strong{MySQL} にコストはかかりません。もし望まないのであれば、 我々に支払う必要はありません。 @item ライセンスは以下では必要です: @itemize @minus @item @strong{MySQL} を直接販売するか、または他の製品やサービスの一部として @strong{MySQL} を販売する場合 @item @strong{MySQL} のインストールやメンテナンスサービスで料金をとる場合。 @item 再配布不可の配布物に @strong{MySQL} を含め、そのなかのいくつかに料金をかす場合 @end itemize @item @strong{MySQL} ライセンスが必要な情況として、@code{mysqld} サーバを 走らせるマシン 1 台につき 1 つのライセンスを必要とします. しかし、マルチ CPU マシンは1台のマシンとみなします。 1台のマシン上で走らせる @strong{MySQL} サーバの数に制限はありません。 そのマシン上に走るサーバーに接続するクライアントの数にも制限は ありません。 @item 市販のプログラムにクライアントコードを含むために、ライセンスを必要としません。 @strong{MySQL} のクライアントアクセスの部分はパブリックドメインです。 @code{mysql} コマンドラインクライアントは、GNU Public License 下にある @code{readline} を含みます。 @item @cindex @code{myisampack} For customers who have purchased 1 license or MySQL support, we provide additional functionality. Currently, this means we provide the @code{myisampack} utility for creating fast compressed read-only databases. (The server includes support for reading such databases but not the packing tool used to create them.) When support agreements generate sufficient revenue, we will release this tool under the same license as the @strong{MySQL} server. @item @strong{MySQL} の使用にライセンスを必要としない場合でも、@strong{MySQL} が好きで, 一層の開発を奨励したいならば,確かに,あなたがライセンスを購入する事は歓迎さ れています. @item あなたが商用で @strong{MySQL} を使用しており、それで利益になっているのなら、 我々は,あなたがいくつかのサポートを購入することによって @strong{MySQL} の開発を 促進するように頼みます. 我々は,@strong{MySQL} があなたのビジネスを助けるならば、 あなたが @strong{MySQL} を助けるように頼むのが道理に合うと感じます. (あなたが我々に質問のサポートを求めるのであれば、 我々が多くの労力をつぎ込んだものを無償で使用することはやめてください。 無償のサポートの提供を我々に頼むこともです。) @end itemize If you have any questions as to whether or not a license is required for your particular use of @strong{MySQL}, please contact us. @xref{Contact information}. @strong{MySQL} の使用に際してライセンスが必要であるかどうかに関しての質問があるならば 我々に問い合わせてください。@xref{Contact information}. If you require a @strong{MySQL} license, the easiest way to pay for it is to use the license form on TcX's secure server at @url{https://www.mysql.com/license.htmy}. Other forms of payment are discussed in @ref{Payment information}. あなたが @strong{MySQL} ライセンスを必要としており、簡単な支払い方法を 望むのであれば、TcXの安全なサーバにおけるライセンスフォームを使用する ことです. @url{https://www.mysql.com/license.htmy}. ほかの支払い方法については @ref{Payment information}. (日本での購入は @uref{http://www.softagency.co.jp/}. ) @strong{MySQL} licensing policy @cindex Licensing on Win32 @node Licensing policy on Win32, Copyright, Licensing policy, Licensing and Support @section MySQL licensing policy on Win32 For use under Microsoft operating systems (Win95/Win98/WinNT/Win2000), you need a @strong{MySQL} license after a trial period of 30 days, with the exceptions that are listed later. @xref{Win license}. A shareware version of @strong{MySQL}-Win32, that you can try before buying, is available at @uref{http://www.mysql.com/mysql_w32.htmy}. This is based on a very late, stable @strong{MySQL} version, but compiled with full debugging support, which makes this a lot slower than the registered version. After you have registered for a @strong{MySQL} license, you will get a password that will enable you to access the newest @strong{MySQL}-Win32 version. Microsoft オペレーティングシステム(Win95/Win98/WinNT/Win2000)下における使用では、 あなたは30日のトライアル期間の後に @strong{MySQL} ライセンスを必要とします。 @xref{Win license}. あなたが購入の前に試みることができる @strong{MySQL}-Win32 のシェアウェアバージョンは @uref{http://www.mysql.com/mysql_w32.htmy}. にあります. これは安定版の @strong{MySQL} をベースにフル・デバッグモードでコンパイルしており、 正式登録版に比べて速度は遅くなっています。 ライセンス代を支払った後に,あなたは最も新しい @strong{MySQL}-Win32 バージョンに アクセスするためのパスワードを得るでしょう. (日本語版 @strong{MySQL}-Win32 の評価版と申し込みは @uref{http://www.softagency.co.jp/}. ) The reason for always requiring a license under Microsoft Windows is that because Windows is a highly commercial OS with very high development costs (it usually takes 3 times longer to build and test things under windows), we see no other alternative than only give the latest @strong{MySQL} Windows version to paying customers. If we didn't do this we would not be able to keep up development on Windows. We do give free @strong{MySQL} licenses on request in the following cases: @itemize @bullet @item Educational purposes, like teaching students. @item Non-commercial research settings. @item Churches. @item Registered charity organizations. @item Individual students who have database related educational project. @item People who help us with @strong{MySQL} development in some constructive manner. @end itemize If something of the above applies to you, you can apply for a license by sending an email to @email{mysql-licensing@@mysql.com}. This should include a full description of for what you need a free @strong{MySQL} license. As soon as we can afford it we plan to release @strong{MySQL} Win32 under the same license as @strong{MySQL} under other OS. This will however also require that we can find some Windows developers that would like to work on @strong{MySQL} development under Windows and build windows version for all @strong{MySQL} releases. @cindex Copyright @node Copyright, Commercial use, Licensing policy on Win32, Licensing and Support @section Copyrights used by @strong{MySQL} @menu * Copyright changes:: Possible future copyright changes @end menu There are several different copyrights on the @strong{MySQL} distribution: @strong{MySQL} 配布における、いくつか異なるコピーライトを示します: @enumerate @item The @strong{MySQL}-specific source needed to build the @code{mysqlclient} library and programs in the @file{client} directory is in the public domain. Each file that is in the public domain has a header which clearly states so. This includes everything in the @file{client} directory and some parts of the @code{mysys}, @code{mystring} and @code{dbug} libraries. @item Some small parts of the source (GNU @code{getopt}) are covered by the ``GNU LIBRARY LIBRARY GENERAL PUBLIC LICENSE''. See the @file{mysys/COPYING.LIB} file. @item Some small parts of the source (GNU @code{readline}) are covered by the ``GNU GENERAL PUBLIC LICENSE''. See the @file{readline/COPYING} file. @item Some parts of the source (the @code{regexp} library) are covered by a Berkeley style copyright. @item The other source needed for the @strong{MySQL} server on non-Microsoft platforms is covered by the ``MySQL FREE PUBLIC LICENSE'', which is based on the ``Aladdin FREE PUBLIC LICENSE.'' @xref{Public license}. When running @strong{MySQL} on any Microsoft operating system, other licensing applies. @end enumerate @enumerate @item @file{client} ディレクトリ以下の @code{mysqlclient} ライブラリと プログラム群を作成するに必要とされる特定の @strong{MySQL} のソースは、 パブリックドメインです。 それぞれのパブリックドメイン下のファイルの冒頭には、その事を明記してあります。 これは、@file{client} ディレクトリ以下の全ファイルと、 @code{mysys}, @code{mystring}, @code{dbug} ライブラリのいくつかを含みます。 @item ソースのいくつかの部分は (GNU @code{getopt}) ``GNU LIBRARY GENERAL PUBLIC LICENSE'' に従って変更したものです。See the @file{mysys/COPYING.LIB} file. @item ソースのいくつかの部分は (GNU @code{readline}) ``GNU GENERAL PUBLIC LICENSE'' に従って変更したものです。 See the @file{readline/COPYING} file. @item ソースのいくつかの部分は (@code{regexp} library) バークレイスタイルのコピーライトに従って変更したものです。 @item 非Microsoft プラットフォームの @strong{MySQL} サーバーに必要なソースは、 ``MySQL FREE PUBLIC LICENSE'' 下にあります。このライセンスは ``Aladdin FREE PUBLIC LICENSE'' を元にしています @xref{Public license}。 Microsoftのオペレーティングシステム上で @strong{MySQL} を使用する場合は、 違うライセンスが適用されます。@xref{Win license} @end enumerate The following points set forth the philosophy behind our copyright policy: 以下にわれわれのコピーライトの基本理念を示します: @itemize @bullet @item The SQL client library should be totally free so that it can be included in commercial products without limitations. @item People who want free access to the software into which we have put a lot of work can have it, so long as they do not try to make money directly by distributing it for profit. @item People who want the right to keep their own software proprietary, but also want the value from our work, can pay for the privilege. @item That means normal in-house use is FREE. But if you use @strong{MySQL} for something important to you, you may want to help further its development by purchasing a license or a support contract. @xref{Support}. @end itemize @itemize @bullet @item 本 SQL client ライブラリーは無償であること。 これは商用の製品に対しても無制限であることを含む。 @item 商売のための配布を行って対価を得ようとしない限りは、 我々が尽力して作った本ソフトウェアに制限なくアクセスできる。 @item 自分自身のソフトウェアの独占権もほしいが,我々のソフトを使用して対価も得たいと 考えている人々は,特権を買うことができます. @item それは,通常の内部の使用が無料であることを意味します。 しかし,あなたにとって何か重要なものにそれを使用するならば, あなたは,サポート契約を購入することによって, @strong{MySQL} の一層の開発をサポートしたがるかもしれません. @end itemize @node Copyright changes, , Copyright, Copyright @subsection Possible future copyright changes We may choose to distribute older versions of @strong{MySQL} with the GPL in the future. However, these versions will be identified as @strong{GNU MySQL}. Also, all copyright notices in the relevant files will be changed to the GPL. 我々は,将来 GPL で @strong{MySQL} の旧式のバージョンを配布する事を選ぶかもしれません. この場合,これらのバージョンは @strong{GNU MySQL} とするつもりです. また,関連ファイルの中のすべての版権情報を GPL に変えるつもりです. @node Commercial use, Licensing examples, Copyright, Licensing and Support @section Distributing @strong{MySQL} commercially 商用配布 This section is a clarification of the license terms that are set forth in the ``MySQL FREE PUBLIC LICENSE'' (FPL). @xref{Public license}. 以下に ``MySQL FREE PUBLIC LICENSE'' (FPL) を明確に記します. @xref{Public license}. @strong{MySQL} may be @strong{used} freely, including by commercial entities for evaluation or unsupported internal use. However, @strong{distribution} for commercial purposes of @strong{MySQL}, or anything containing or derived from @strong{MySQL} in whole or in part, requires a written commercial license from TcX AB, the sole entity authorized to grant such licenses. @strong{MySQL} の使用には制限はありません。 これは商用利用のための評価や、内部で非サポートで使用することを含みます。 しかし次の条件では TcX AB (ライセンスを与える権限を持つ唯一の機関) によって記載された商用ライセンスが必要です。 @strong{MySQL} 自身を商用目的で@strong{配布}すること。 @strong{MySQL} の一部、あるいは全部を含んだ物を商用目的で@strong{配布}すること。 @strong{MySQL} を利用して作った物の一部、あるいは全部を含んだ物を商用目的で@strong{配布}すること。 You may not include @strong{MySQL} ``free'' in a package containing anything for which a charge is being made, except as noted below. 金銭が発生するいかなる物の中にも、@strong{MySQL} を ``無償'' で含んではいけません。 ただし、以下は除きます。 The intent of the exception provided in the second clause of the license is to allow commercial organizations operating an FTP server or a bulletin board to distribute @strong{MySQL} freely from it, provided that: 本ライセンスの2番目に例外措置をもうけている意図は、営利団体が運営している FTP サーバー、 掲示板等で、自由に @strong{MySQL} を配布することを許可するためです。 @enumerate @item The organization complies with the other provisions of the FPL, which include among other things a requirement to distribute the full source code of @strong{MySQL} and of any derived work, and to distribute the FPL itself along with @strong{MySQL}; @item The only charge for downloading @strong{MySQL} is a charge based on the distribution service and not one based on the content of the information being retrieved (i.e., the charge would be the same for retrieving a random collection of bits of the same size); @item The server or BBS is accessible to the general public, i.e., the phone number or IP address is not kept secret, and anyone may obtain access to the information (possibly by paying a subscription or access fee that is not dependent on or related to purchasing anything else). @end enumerate @enumerate @item その団体は FPL の他の条項を受け入れること。その要求の中でもとりわけ @strong{MySQL} といかなる派生物の全ソースの配布と、 @strong{MySQL} と一緒に FPL 自身を配布することは受け入れること。 @item @strong{MySQL} をダウンロードする行為にだけ課金する場合で、 この値段は配布サービスの費用であり、受信する対象物によって変わらない事。 (例えば、受信する物が違っていても受信量が同じであれば同じ値段であること。) @item サーバー、BBS は一般に公開されていてアクセス可能なこと。例えば、電話番号や IPアドレスが隠されておらず、だれもがその情報にアクセスできること。 (なにかを買うということに関連したり依存したりしない購読料やアクセス料金による物も可) @end enumerate If you want to distribute software in a commercial context that incorporates @strong{MySQL} and you do @strong{not} want to meet these conditions, you should contact TcX AB to find out about commercial licensing, which involves a payment. The only ways you legally can distribute @strong{MySQL} or anything containing @strong{MySQL} are by distributing @strong{MySQL} under the requirements of the FPL, or by getting a commercial license from TcX AB. @strong{MySQL} を組み込んだ商業ソフトウェアを配布したいが, これらの条件を満たしたく@strong{ない}ならば,あなたは,商業認可に関して TcX AB に連絡するべきです. 商業ライセンスは支払いに影響し,サポートその他の利点を含みます. これらはあなたが @strong{MySQL} 自身や @strong{MySQL} を含む物を 合法的に配布することができる唯一の方法です: FPLの条件の下に @strong{MySQL} を配布することか, または TcX AB から商業ライセンスを得ることによって. @node Licensing examples, Cost, Commercial use, Licensing and Support @section Example licensing situations ライセンス例 @menu * Products that use MySQL:: Selling products that use @strong{MySQL} * MySQL services:: Selling @strong{MySQL}-related services * 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 part of a product or service that you are selling to a customer, or requiring that @strong{MySQL} be used in conjunction with your product. In such cases, it is your responsibility to obtain a license for the customer if one is necessary. (This requirement is waived if your customer already has a @strong{MySQL} license. But the seller must send customer information and the license number to TcX, and the license must be a full license, not an OEM license.) このセクションでは、あなたがどういった状況で @strong{MySQL} サーバライセンスを 得なければならないか否かを、いくつか説明します。 一般にこれらの例は、 @strong{MySQL} が、あなたが顧客に売っている製品やサービスの一部に含まれている場合や、 あなたの製品が @strong{MySQL} の使用を要求している場合などです。 このような場合、顧客のためにライセンスを得るのはあなたの責任です。 (ただし、すでにその顧客が @strong{MySQL} のライセンスを持っている場合はのぞきます。 が、売り手は顧客の情報とライセンスナンバーをTcXに送る必要があり、かつ、 そのライセンスはOEMライセンスではなく、フルライセンスでなければなりません。) Note that a single @strong{MySQL} license covers any number of CPUs/users/customers/@code{mysqld} servers on a machine! @strong{MySQL} ライセンス一つで、一台のマシン上の、 全 CPU数/ユーザー数/顧客数/@code{mysqld} 数をカバーします。 @node Products that use MySQL, MySQL services, 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 contingent on the use of @strong{MySQL} and whether you include @strong{MySQL} with your product. There are several cases to consider: アプリケーションを販売するとき、あなたが @strong{MySQL} ライセンスを 必要とするかどうか決定するためには, あなたのアプリケーションが適切に機能するためには @strong{MySQL} を必要とするかどうか、 製品に @strong{MySQL} を含むかどうかを尋ねるべきです. 考えうるいくつか のケースがあります: @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. @item Do you include @strong{MySQL} in a distribution and charge for that distribution? If you include @strong{MySQL} with a distribution that you sell to customers, you will need a license for any machine that runs the @code{mysqld} server, because in this case you are selling a system that includes @strong{MySQL}. This is true whether the use of @strong{MySQL} with your product is required or optional. @item Do you neither require for your product nor include @strong{MySQL} with it? Suppose you want to sell a product that is designed generally to use ``some database'' and that can be configured to use any of several supported alternative database systems (@strong{MySQL}, PostgreSQL, or something else). That is, your product does not not require @strong{MySQL}, but can support any database with a base level of functionality, and you don't rely on anything that only @strong{MySQL} supports. Does one of you owe us money if your customer actually does choose to use @strong{MySQL}? In this case, if you don't provide, obtain or set up @strong{MySQL} for the customer should the customer decide to use it, neither of you need a license. If you do perform that service, see @ref{MySQL services, , @strong{MySQL} services}. @end itemize @itemize @bullet @item あなたのアプリケーションが適切に機能するためには、@strong{MySQL} を必要としますか? あなたの製品が @strong{MySQL} を必要とするならば,@strong{mysqld} サーバを 走らせるどんなマシンにもライセンスを必要とします. 例えばあなたが @strong{MySQL} の周りで自分のアプリケーションを設計したならば、 本当にエンジンを必要とする商業製品を作った事になるので、ライセンスが必要です. あなたのアプリケーションが @strong{MySQL} を必要としないならば,あなたは ライセンスを得る必要はありません。 例えば @strong{MySQL} がただあなたの製品に いくつかの新しい任意の特徴を加えたならば (テキストファイルへのロギングより、データベースへのロギングに @strong{MySQL} が 使用されるような場合)、それは通常の使用下なので、ライセンスは必要ないでしょう。 言い換えれば, @strong{MySQL} とともに使用される製品を売る場合や、 完全に機能するために @strong{MySQL} を必要とするのであれば、 ライセンスが必要です。あなたが @strong{MySQL} を製品の一部として 顧客に配布しようがしまいが、この場合にはライセンスが必要です。 また、あなたが顧客のためにしている事にも依ります。 あなたは,あなたのソフトウェアとともに @strong{MySQL} をインストールし、 顧客に提供するのを計画していますか? そのばあい,あなたの製品は @strong{MySQL} の使用を条件としていますか ; そうだとすれば, あなたは,ライセンスを買う必要があります. 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. @item @strong{MySQL} を配布物に含め、その配布物に料金をかしますか? もし顧客に売る配布物に @strong{MySQL} を含めるのであれば、 @code{mysqld} サーバーの走るいかなるマシンにライセンスが必要です。 なぜなら、 @strong{MySQL} を含むシステムを売っているからです。 これは製品が @strong{MySQL} の使用を 必須としていようがオプションとしていようが、適用されます。 @item あなたの製品は @strong{MySQL} をその中に含むことを要求しますか? ``なんらかのデータベース'' の使用をデザインしている製品で、この製品が いくつかのデーターベースシステム (@strong{MySQL}, PostgreSQL, or something else) の中から代わりのもを 使用するように調整可能できる製品、こういった物をあなたが 売ろうとしていると仮定します。 この場合、あなたの製品は @strong{MySQL} を必要としませんが、 いかなるデータベースの基本機能をサポートしており、 @strong{MySQL} だけをサポートしているものではありません。 が、もし顧客が @strong{MySQL} の使用を選んだ場合に、あなたが我々に支払う義務が あるのか? この場合、もしその顧客のために、あなたが @strong{MySQL} を提供したりあるいは、 入手したり、セットアップしたりしていないならば、あなたにライセンスは不要です。 もしあなたが顧客にこういったサービスを提供するなら、@ref{MySQL services, , @strong{MySQL} services}. @end itemize @node MySQL services, ISP, Products that use MySQL, Licensing examples @subsection Selling @strong{MySQL}-related services @strong{MySQL} 関連サービスを売る If you perform @strong{MySQL} installation on a client's machine and any money changes hands for the service (directly or indirectly), then you must buy a @strong{MySQL} license. もし @strong{MySQL} をクライアントにインストールし、そのサービスでなんらかの 代価をえるならば(直接、間接問わず)、あなたは @strong{MySQL} ライセンスを 購入しなくてはなりません。 If you sell an application for which @strong{MySQL} is not strictly required but can be used, a license may be indicated, depending on how @strong{MySQL} is set up. Suppose your product neither requires @strong{MySQL} nor includes it in your product distribution, but can be configured to use @strong{MySQL} for those customers who so desire. (This would be the case, for example, if your product can use any of a number of database engines.) @strong{MySQL} は完全に必要というわけではないが,@strong{MySQL} を使用することができる アプリケーションを販売するならば, @strong{MySQL} をセットアップする方法によって, ライセンスは必要になる場合があります。あなたの製品配布物の中に @strong{MySQL} が 含まれておらず、また、 @strong{MySQL} を必要としていないが、 あなたの製品は顧客の希望に合わせて @strong{MySQL} を使用するように調整できるものだと 仮定します。 (例えば,あなたの製品が多くのデータベースエンジンのどれかを使用することが できるならば,この場合に該当するでしょう.) If the customer obtains and installs @strong{MySQL}, no license is needed. If you perform that service for your customer, then a license is needed because then you are selling a service that includes @strong{MySQL}. もし顧客自身が @strong{MySQL} を入手しインストールするならば、 あなたにライセンスは不要です。もしあなたがそういったサービスを顧客に行うなら、 ライセンスは必要です。なぜなら、 @strong{MySQL} を含んだサービスをあなたが 売ることになるからです。 @node ISP, Web server, MySQL services, Licensing examples @subsection ISP @strong{MySQL} services Internet Service Providers (ISPs) often host @strong{MySQL} servers for their customers. If you are an ISP that allows customers to install and administer @strong{MySQL} for themselves on your machine with no assistance from you, neither you nor your customer need a @strong{MySQL} license. Note that this doesn't apply if you are are using Win32; In this case you will always need a license for each computer that runs the @strong{MySQL} server. If you charge for @strong{MySQL} installation and administrative support as part of your customer service, then you need a license because you are selling a service that includes @strong{MySQL}. インターネットサービスプロバイダー(ISP) は @strong{MySQL} サーバーを自分のお客に 提供することもしばしばです。 もしあなたが ISP で、顧客があなたのマシンに @strong{MySQL} をインストールして管理する事を 許可しているのであれば(あなたの手助けは無しで)、 あなたと顧客のどちらにも @strong{MySQL} ライセンスは不要です。 もし Win32 を使用しているなら、これは適用されないことに注意してください。 Win32 の場合は、@strong{MySQL} サーバーを実行するコンピュータ毎に ライセンスが必要です。 もしあなたが顧客サービスとして @strong{MySQL} をインストールし管理することに料金をかすなら、 あなたは @strong{MySQL} を含んだサービスを売っていることになるので、 あなたはライセンスが必要です。 @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}, since you are not selling @strong{MySQL} itself. However, in this case we would like you to purchase @strong{MySQL} support, because @strong{MySQL} is helping your enterprise. もしあなたが UNIX 上で Webサーバー とともに @strong{MySQL} を使用するなら、 ライセンスを買う必要はありません。 これはたとえ @strong{MySQL} を使用した商用の Webサーバー を走らせていても、 @strong{MySQL} 自身を売っていないので、ライセンスを買う必要はありません。 しかしこの場合、我々はあなたが @strong{MySQL} サポート契約をすることを望みます。 なぜなら、@strong{MySQL} はあなたの事業を助けているからです。 @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. 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. 現在のライセンスの価格を以下に示します。全ての価格は US ドルです。 もしあなたがクレジットカードで買いたいならば、通貨は EURO (European Union Euro) です。(価格がわずかに異なる) @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: 大量購入(OEM 販売)の場合は: @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.  OEM 販売をする場合、ユーザーからの問題や要望に対して、 あなたは仲買人として振る舞わなくてはなりません。 われわれは OEM の客に対し、少なくとも拡張電子メールサポート契約を要求します。 OEM ライセンスは、@strong{MySQL} サーバーに直接アクセスする必要のない 製品にのみ適用されます (組み込みシステム)。 いうならば、 @strong{MySQL} は、ただ、あなたが提供しているアプリケーションと共にのみ 使用されなくてはなりません。 (OEM 供給を受けた MySQL サーバーライセンスのみを単体で売ることはできません。) 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.  もしあなたが薄利多売の製品を持っているなら、他の条件についていつでも 我々と話し合うことができます(例えば売値のパーセンテージとか)。 もしあなたが製品を売りたいなら、 あなたの製品説明、値段、市場、その他関連項目を我々に知らせてください。 @cindex @code{myisampack} After buying 1 @strong{MySQL} licenses, you will get a personal copy of the @code{myisampack} utility. You are not allowed to redistribute this utility but you can distribute tables packed with it. 1 @code{MySQL} ライセンスの購入後、@code{myisampack} ユーティリティーが 個人むけにコピーできます。これの再配布は許可されませんが、 @code{myisampack} でパックしたテーブルは配布できます。 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. より包括的なサポートは別々に販売されます. それぞれのレベルのサポートが含む事に 関する記述は @ref{Support}. にあります。様々なタイプの商用サポートの価格は以下に 示します. サポートレベル価格は EURO (European Union Euro) です。 1 EURO はおよそ 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. 下位レベルのサポートから、それより高いレベルのサポートに、 2つのサポートの価格差分の支払いで、アップグレードが可能です。 @cindex Payment information @node Payment information, Contact information, Cost, Cost @subsection Payment information Currently we can take SWIFT payments, cheques or credit cards. 現在,SWIFT支払い,小切手またはクレジットカードでの支払いができます. 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. あなたの購入ライセンス かつ/又は サポートと,名前と Eメールアドレスを記述のこと。 In Europe and Japan you can use EuroGiro (that should be less expensive) to the same account. ヨーロッパと日本では,あなたは支払いに EuroGiro(それが高価ではない) を使用することができます. If you want to pay by cheque, make it payable to ``MySQL Finland AB'' and mail it to the address below: あなたが小切手によって支払いたいと思っているならば,それを ``Monty Program KB'' に支払い満期にして, 以下のアドレスに郵送してください. @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://www.tcx.se/license.htmy, TcX's secure license form}. インターネット上でクレジットカードで支払いたいと思っているならば, あなたは @uref{https://www.tcx.se/license.htmy, TcXの安全なライセンスフォーム} を使用することができます. 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. 請求書を送って欲しい場合,あなたはライセンスフォームを使用し, 注釈欄に ``請求書 希望'' を書いてください. あるいは,あなたの会社の情報を記載したメッセージを @email{sales@@mysql.com} におくり, (@email{mysql@@lists.mysql.com} ではありません!) 請求書を送るように我々に依頼する事もできます。 @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 TCX 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. 基本電子メールサポートは非常に費用のかからないサポートオプションであり, 我々の @strong{MySQL} の開発をサポートする本当のサポートオプションで、 よりよい方法として考えられるべきです. 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{mysql-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}. このサポートレベルでは, @strong{MySQL} メーリングリストはコミュニケーション を取るには好まれる方法です. 通常, 質問は主要なメーリングリスト (@email{mysql@@lists.mysql.com}) か他のメーリングリストのどれかに送信されるべきで、 (例えば, Windows に関連する @strong{MySQL} の質問のための @email{mysql-win32@@lists.mysql.com} ) これは他の誰かが同じ問題を経験して, 既に解決しているかもしれないからです。 @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}. しかし、基本電子メールサポートを購入することによって, あなたはサポートアドレス @email{mysql-support@@mysql.com} にアクセスできます. (このメールアドレスは最小の @strong{MySQL} ライセンスの購入では利用不可能です。) これは特に重要な質問のために使用されており、また、@email{mysql-support@@mysql.com}. とクロスポストすることも可能です。 (メッセージに機密のデータが含まれる場合、あなたは @email{mysql-support@@mysql.com}. だけに送信するべきです.) メッセージを @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. @end itemize @itemize @bullet @item もしあなたの質問が既にマニュアルで答えられているのであれば、 答えを見つけれるであろう正しいセクションをあなたに教えます。 もし答えがマニュアルに無ければ、問題解決のための正しい方向を指し示します。 @item 素早い返信を保証致します。必ずしもどんな問題も解決できると保証は致しませ んが、あなたが E メールでコンタクト可能ならば少なくとも返信は受け取るでしょ う。 @item サポートされているプラットフォームにおいてバイナリー配布形態から @strong{MySQL} をインストールする時、予期しない問題が現れた場合お助け致します。 このレベルのサポートではソース配布形態から @strong{MySQL} をインストール する場合はふくまれておりません。``サポート対象'' プラットフォームとは、 @strong{MySQL} が動作すると知られているものです @xref{Which OS}. @item バグや足りない機能がある場合 。見付かったバグに付いては次期 @strong{MySQL} リリースにおいて直されます。もしそのバグがあなたにとって致命的であれば、修正次第そ のバグの対するパッチをメールでお送りします。致命的バグは常に高い優先度になり、 可能な限り速く、修正が行われます。 @item さらなる @strong{MySQL} 開発のためにあなたの意見は考慮されます。 あなたが E メールサポートをお持ちならば、もう既に @strong{MySQL} の更なる 開発への手助けをされている事になります。もっと意見を取り入れたいならば、 上位のサポートにアップグレードしてください。 @item もしあなたが私供によるのシステムの最適化の手助けをお望みであれば、更に 上位のサポートへアップグレードする必要があります。 @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 @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_CALCULATION(col_name1,col_name2) from tbl_name; @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 @strong{MySQL} のインストール @menu * Getting MySQL:: @strong{MySQL} を得る方法 * Which OS:: @strong{MySQL} がサポートする OS * Which version:: 使用する @strong{MySQL} バージョン * Many versions:: アップデートがリリースされる方法と時 * Installation layouts:: インストールレイアウト * Installing binary:: @strong{MySQL} バイナリ配布のインストール * Installing source:: @strong{MySQL} ソース配布のインストール * Compilation problems:: Problems compiling? * MIT-pthreads:: MIT-pthreads に関して * Perl support:: Perl installation comments * Source install system issues:: System-specific notes * Win32:: Win32 notes * OS/2:: OS/2 notes * TcX binaries:: TcX binaries * Post-installation:: インストール後の設定とテスト * Upgrade:: @strong{MySQL} のアップグレード/ダウングレード時に特別に行なうことが何かあるか? @end menu この章では、どのようにして @strong{MySQL} を得、インストールするのかをのべます: @itemize @bullet @item @strong{MySQL} を得ることができるサイトのリスト → @ref{Getting MySQL, , Getting @strong{MySQL}}. @item どのプラットフォームをサポートしているかは → @ref{Which OS}. @item @strong{MySQL} のいくつかのバージョンは、バイナリ、ソース両方の配布物があります。 どのバージョンを使用するのか、どのタイプを使用するかを決めるためには → @ref{Many versions}. @item バイナリとソースのインストールについては → @ref{Installing binary}, と @ref{Installing source}. それぞれのセットには、あなたが出くわすかもしれない システムに特有の問題のセクションが含まれます。 @item インストール後に行うことの説明は → @ref{Post-installation}. @strong{MySQL} のインストールにおいて、バイナリまたはソース配布にかかわらず、 これらのプロシージャは適用します。 @end itemize @cindex Downloading @cindex @strong{MySQL} version @cindex Version, latest @cindex Getting @strong{MySQL} @node Getting MySQL, Which OS, Installing, Installing @section @strong{MySQL} を得る方法 現在のバージョンとダウンロードの指示についての情報は @uref{http://www.mysql.com/, @strong{MySQL} ホームページ} をチェックしてく ださい。 しかし、TcX のインターネット接続はそんなに速くありません; 下記に一覧され たミラーサイトの一つから実際にダウンロードすることを@emph{お勧めします}。 悪いまたは遅れているミラーは @email{webmaster@@mysql.com} に報告してくださ い。 @c START_OF_MIRROR_LISTING @strong{ヨーロッパ:} @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 Libovicky) @image{Flags/czech-republic} Czech Republic [www.sopik.cz] @ @uref{http://www.mysql.cz/, WWW} @item @c Added: 000418 @c EMAIL: (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 EMAIL: tonu@tradenet.ee (Samuel) @c @image{Flags/estonia} Estonia [Tradenet] @ @c @uref{http://mysql.tradenet.ee, WWW} @item @c EMAIL: tonu@spam.ee (Tonu 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 @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 Sacrist) @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{北アメリカ:} @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{南アメリカ:} @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{アジア:} @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 [SoftAgency] @ @uref{http://www.softagency.co.jp/MySQL, WWW}   @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{オーストラリア:} @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{アフリカ:} @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 @strong{MySQL} がサポートする OS 我々は GNU Autoconf を使用していますので、@strong{MySQL} は POSIX スレッ ドと C++ コンパイラが動作する全ての新しいシステムに移植可能です。(クライ アントコードのコンパイルだけは C++ を必要としますが、スレッドは必要ではありません。) 我々は自身のソフトウェアを、最初に Sun Solaris (現在は 2.5 & 2.6 & 2.7) 上で、より 小さい範囲は RedHat Linux 5.0 上で、使用し開発します。 @strong{MySQL} は次の OS/スレッドパッケージの組み合わせで、コンパイルの 成功が報告されています。多くの OS では、ネイティブスレッドは最新バージョ ンだけで動作することに注意してください。 @itemize @bullet @item AIX 4.x with native threads @item BSDI 2.x with the included MIT-pthreads package @item BSDI 3.0, 3.1 and 4.x with native threads @item DEC UNIX 4.x with native threads @item FreeBSD 2.x with the included MIT-pthreads package @item FreeBSD 3.x with native threads @item HP-UX 10.20 with the included MIT-pthreads package @item HP-UX 11.x with the native threads. @item Linux 2.0+ with LinuxThreads 0.7.1 or @code{glibc} 2.0.7 @item MacOS X Server @item NetBSD 1.3/1.4 Intel and NetBSD 1.3 Alpha (Requires GNU make) @item OpenBSD > 2.5 with native therads. OpenBSD < 2.5 with the included MIT-pthreads package @item OS/2 Warp 3, FixPack 29 and OS/2 Warp 4, FixPack 4 @item SGI Irix 6.x with native threads @item Solaris 2.5 and above with native threads on SPARC and x86 @item SunOS 4.x with the included MIT-pthreads package @item SCO OpenServer with a recent port of the FSU Pthreads package @item SCO UnixWare 7.0.1 @item Tru64 Unix @item Win95, Win98, NT and Win2000 (the newest version is currently available only for users with a @strong{MySQL} license or @strong{MySQL} email support). For those who wish to test before they buy, we have released @uref{http://www.mysql.com/mysql_w32.htmy,@strong{MySQL} 3.22.33} (an older version) as shareware. @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 使用する @strong{MySQL} バージョン make を行う前に決める事は、あなたが最新の開発リリースを使用するのか、 または最新の安定リリースを使用するのかです。 @itemize @bullet @item 通常、あなたが最初に @strong{MySQL} を使い始める場合、またはバイナリ配布 がない他のシステムに @strong{MySQL} を移植しようとする場合、 我々は開発リリース (現在は @value{mysql_version}) の選択を 勧めます。開発リリースには普通は本当に悪いバグはありません。それは、あなたのマシン上で、 @code{crash-me} とベンチマークテストで簡単にテストできます。 @xref{Benchmarks}。注意: すべての @strong{MySQL} リリースはそれぞれのリリー スの前に @strong{MySQL} ベンチマークと広範囲なテストスイートでチェックされ ます。 @item そうでなくて、古いシステムで実行していてアップグレードしたいけれども、 開発版は試したくない場合は、あなたが使用している物と同じブランチ中の 最新のもの(あなたが使用している物より新しいバージョンの物)に アップグレードすべきです。 このバージョンでは、致命的なバグだけを修正し、 比較的安全で小さな変更を行っています。 @end itemize make 前の2番目の決定事項は、ソース配布とバイナリ配布のどちらを使用するかです: @itemize @bullet @item あなたが現在バイナリ配布が存在するプラットフォーム上で @strong{MySQL} を 実行したいのなら、それを使用してください。通常、ソース配布よりもインストー ルは簡単です。 @item @strong{MySQL} を作る C と C++ コードを読みたい(そして/または変更したい) 場合はソース配布を入手するべきです。ソースコードはいつでも究極のマニュア ルです。ソース配布はバイナリ配布よりも多くのテストと例も含んでいます。 @end itemize @strong{MySQL} の命名法では、リリース番号は3つの数値とサフィックスからな ります。例えば、@code{mysql-3.21.17-beta} のようなリリース名は次のように 解釈されます: @itemize @bullet @item 最初の数値(@code{3})はファイル形式を表します。全てのバージョン 3 リリー スは同じファイルフォーマットを持ちます。バージョン 4 が現れた時、全ての テーブルは新しい形式に変換する必要があります (このための良いツールはもち ろん含まれます)。 @item 2番目の数値(@code{21})はリリースレベルです。通常は二つから選択します。一 つはリリース/安定ブランチで(現在は @code{22})、もう一つは開発ブランチです(現在は @code{23})。 通常は両方とも安定ですが、開発バージョンはきまぐれで、ドキュメントがなく、いくつかのシ ステムではコンパイルに失敗します。 @item 3番目の数値(@code{17})はリリースレベル内のバージョン番号です。これは新し い配布の度に増加します。普通はあなたの選択したリリースレベルの最新バージョ ンを求めます。 @item サフィックス(@code{beta})はリリースの安定レベルを表します: @itemize @minus @item @code{alpha} は、100% テストされていないいくつかの新しい大きなコードセク ションが存在することを示し、知られているバグは News 節に記述されています (通常はありません)。@xref{News}。多くの alpha リリースには新しいコマ ンドと拡張もあります。 大きなコード変更を含む開発中のものは、alpha リリース上に現れます。しかし 全てリリース前にテストされます。それぞれの @code{MySQL} リリースには既知 のバグはありません。 @item @code{beta} は全ての新しいコードがテストされたことを意味します。大きな新 しいものは追加されません。知られているバグはありません。 alpha バージョンで、少なくとも一カ月間、致命的なバグが報告されなくて、古 いコマンドをより信頼できなくするような新しい機能を追加する計画がない時に、 alpha から beta にバージョンが変更されます。 @item @code{gamma} は beta がしばらくして、正しく動くように見えるものです。 小さな修正だけが追加されます。 これは多くの他の会社がリリースと呼ぶものです。 @item サフィックスがない場合は、多くの異なる場所で、プラットフォーム固有のバグ を除いてバグレポートなしでそのバージョンがしばらくの間動作していたことを 意味します。 致命的なバグ修正だけがリリースに適用されます。 これは我々が stable リリースと呼ぶものです。 @end itemize @end itemize @strong{MySQL} の全てのバージョンは、比較的安全に使用できることを確かめ るため、我々は標準テストとベンチマークを通して確認しています。標準テス トは以前に見つかった全てのバグをチェックするように拡張されるため、テスト スイートはより良く保持されます。 全てのリリースは少なくても次のテストがされていることに注意してください: @table @asis @item 内部テストスイート これは顧客のための製品システムの一部です。多くのテーブルと何百というメガ バイトのデータを持っています。 @item @strong{MySQL} ベンチマークスイート これは一般的な範囲のクエリを実行します。これは、最適化の最新バッチが実際 にコードをより速く作れるかどうかを確認するテストでもあります。 @xref{Benchmarks}。 @item @code{crash-me} テスト これは、データベースがサポートしている機能と、その許容量と制限を決定しよ うとします。@xref{Benchmarks}。 @end table 他のテストは我々の内部製品環境で最新の @strong{MySQL} バージョンを我々が 少なくとも1つのマシンで使用することです。我々は動作のため 100ギガバイト 以上のデータを持ちます。 @node Many versions, Installation layouts, Which version, Installing @section アップデートがリリースされる方法と時 @strong{MySQL} は TcX でかなり速く進化していて、我々はこれを他の @strong{MySQL} ユーザに共有してもらいたいです。我々は、他の人が必要とし ていると思われるとても便利な機能を持った時に、リリースの作成を試みます。 我々は、実装が簡単な機能を要求するユーザの手助けも試みます。我々は、我々 のライセンスユーザが求めるものにも注目し、特に我々の拡張 email サポート 顧客が求めるものに注目して、彼らの手助けを試みます。 新しいリリースをダウンロードする必要はありません。News 節は、新しいリリー スが、あなたが本当に求める何かを持っているかどうかをあなたに教えます。 @xref{News}。 我々は @strong{MySQL} の更新時は次のポリシーにしたがって行います: @itemize @bullet @item それぞれのマイナーアップデートで、バージョン文字列中の最後の数値が増加し ます。主要な新機能や前のバージョンとのマイナーな非互換があった時には、バー ジョン文字列中の2番目の数値が増加します。ファイル形式が変更した時、最初 の数値が増加します。 @item 安定にテストされたリリースは年に約 1-2 回現れます。しかし小さなバグが見 つかった場合は、バグフィックスだけのリリースがリリースされます。 @item 作業中のリリースは約 1-8 週間毎に現れます。 @item いくつかのプラットフォームのためのバイナリ配布は我々によってメジャーリリー スから作られます。他の人が他のシステムのためにバイナリ配布を作りますが、 おそらく頻繁ではありません。 @item 通常、小さなバグを見つけて修正するとすぐに、有効なパッチを作ります。 @item 危険ではないけれども困らされるバグには、我々に知らせて頂ければ有効なパッ チを作成します。その他の場合、大きなパッチの中にそれらの多くを結合します。 @item 偶然、致命的なバグがリリース中にある場合、我々は新しいリリースを可能な限 りすぐに作ります。他の会社もそうしてもらいたいです。:) @end itemize 現在の安定リリースは 3.22 です; 我々はすでに 3.23 の開発に移行しています。 しかし、安定バージョンでもバグはまだ修正されます。 我々は、バグ修正と``行なわなければいけない''ことを無視するような、完全な 凍結を考えていません。``幾分かの凍結''とは、``ほとんど確実に既に動作して いるものに影響を与えない''小さなことを追加するかもしれないということを意 味します。 @node Installation layouts, Installing binary, Many versions, Installing @section インストールレイアウト この節では、バイナリとソース配布のインストールで生成されるディレクトリの デフォルトのレイアウトを説明します。 バイナリ配布はアンパックすることによりインストールされ、インストール場所 はあなたが選択した場所(通常 @file{/usr/local/mysql})の中の次のディレクト リを選択し生成します: @multitable @columnfractions .3 .7 @item @strong{ディレクトリ} @tab @strong{ディレクトリの内容} @item @file{bin} @tab クライアントプログラム, @code{mysqld} サーバ @item @file{data} @tab ログファイル, データベース @item @file{include} @tab インクルード(ヘッダ)ファイル @item @file{lib} @tab ライブラリ @item @file{scripts} @tab @code{mysql_install_db} @item @file{share/mysql} @tab エラーメッセージファイル @item @file{sql-bench} @tab ベンチマーク @end multitable ソース配布は configure しコンパイルした後にインストールされます。デフォ ルトではインストールステップは @file{/usr/local} 配下のファイルを次のサ ブディレクトリにインストールします: @multitable @columnfractions .3 .7 @item @strong{ディレクトリ} @tab @strong{ディレクトリの内容} @item @file{bin} @tab クライアントプログラムとスクリプト @item @file{include/mysql} @tab インクルードファイル @item @file{info} @tab Info 形式のドキュメント @item @file{lib/mysql} @tab ライブラリ @item @file{libexec} @tab @code{mysqld} サーバ @item @file{share/mysql} @tab エラーメッセージファイル @item @file{sql-bench} @tab ベンチマークと @code{crash-me} テスト @item @file{var} @tab データベースとログファイル @end multitable ソースインストールのレイアウトはバイナリインストールと次の点が異なります: @itemize @bullet @item @code{mysqld} サーバは @file{/bin} ではなく @file{libexec} ディレクトリにインストールされます。 @item データディレクトリは @file{data} ではなく @file{var} です。 @item @code{mysql_install_db} は @file{/usr/local/mysql/scripts} ではなく @file{/usr/local/bin} ディレクトリにインストールされます。 @item ヘッダーファイルのディレクトリは @file{include/mysql} で、 ライブラリのディレクトリは @file{lib/mysql} です。 @file{include} や @file{lib} ではありません。 @end itemize @node Installing binary, Installing source, Installation layouts, Installing @section @strong{MySQL} バイナリ配布のインストール @menu * Linux-RPM:: Linux RPM files * Building clients:: Building client programs * Binary install system issues:: System-specific issues @end menu 次にさらに詳細な説明を行ないます: @strong{MySQL} バイナリ配布をインストールするには、次のツールが必要です: @itemize @bullet @item GNU @code{gunzip}。配布の伸長のため。 @item 適正な @code{tar}。配布の展開のため。GNU @code{tar} は動くことが知られて います。 @end itemize @cindex RPM @cindex RedHat Package Manager Linux では、代わりのインストール方法として RPM (RedHat Package Manager) を使用することができます。 @xref{Linux-RPM}. @c texi2html fails to split chapters if I use strong for all of this. 問題が起きたときは、@email{mysql@@lists.mysql.com} に質問を投稿する時に @code{mysqlbug} を@strong{常に使用してください}。問題がバグでないとして も、@code{mysqlbug} はあなたの問題を解決する助けになるであろうシステム情 報を収集します。@code{mysqlbug} を使用しないと、あなたの問題の解決を得る 可能性が小さくなります! @code{mysqlbug} は、配布のアンパック後に @file{bin} ディレクトリ内に見つけられます。@xref{Bug reports}. @strong{MySQL} バイナリ配布をインストールし、使用するために行なわなければならない 基本的なコマンド: @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 ここでさらに詳細な説明を続けます: バイナリ配布のインストールには、次のステップに従い、それから インストー ル後のセットアップとテストのために @ref{Post-installation} に進んでくだ さい。 @enumerate @item 配下に配布をアンパックしたいディレクトリを選んで、そこに移ってください。 以下の例では、@file{/usr/local} 配下に配布をアンパックし、@strong{MySQL} をインストールするディレクトリ @file{/usr/local/mysql} を生成します。(し たがって、以下の指示は @file{/usr/local} にファイルを生成するパーミッショ ンを持っているとみなします。ディレクトリがプロテクトされている場合は、 @code{root} でインストールを行なう必要があります。) @item 配布ファイル @ref{Getting MySQL, , Getting @strong{MySQL}}. にリストされたサイトの一つから得てください。 @strong{MySQL} バイナリ配布は圧縮された @code{tar} アーカイブとして提供 され、@file{mysql-VERSION-OS.tar.gz} のような名前を持ちます。ここで @code{VERSION} は数値(例えば、@code{3.21.15})で、@code{OS} は配布が意図 しているオペレーティングシステムの種類を表します(例えば @code{pc-linux-gnu-i586})。 @item 配布をアンパックし、インストールディレクトリを生成してください: @example shell> gunzip < mysql-VERSION-OS.tar.gz | tar xvf - shell> ln -s mysql-VERSION-OS mysql @end example 最初のコマンドは @file{mysql-VERSION-OS} という名前のディレクトリを生成 します。二番目のコマンドはそのディレクトリにシンボリックリンクを作成しま す。これはインストールディレクトリを @file{/usr/local/mysql} として、よ り簡単に参照させるためです。 @item インストールディレクトリに移ってください: @example shell> cd mysql @end example いくつかのファイルとサブディレクトリが @code{mysql} ディレクトリ中に見つ けられます。インストール目的の最も重要なものは @file{bin} と @file{scripts} サブディレクトリです。 @table @file @item bin @tindex PATH environment variable @tindex Environment variable, PATH このディレクトリはクライアントプログラムとサーバを含んでいます。シェルが @strong{MySQL} プログラムを正しく見つけられるように、このディレクトリの フルパス名をあなたの @code{PATH} 環境変数に追加すべきです。@xref{Environment variables}. @item scripts このディレクトリは @code{mysql_install_db} スクリプトを含んでいます。こ れはサーバアクセスパーミッションを初期化するために使用されます。 @end table @item @code{mysqlaccess} を使用し、かつ @strong{MySQL} 配布を非標準の場所に持 ちたい場合は、@code{mysqlaccess} が @code{mysql} クライアントを見つけよ うとする場所を変更する必要があります。@file{bin/mysqlaccess} スクリプト の 18 行目付近を編集してください。次のような行を探してください: @example $MYSQL = '/usr/local/bin/mysql'; # path to mysql executable @end example パスを @code{mysql} が実際にシステム上におかれている場所を示すように変更 してください。これを行なわないと、@code{mysqlaccess} 実行時に @code{broken pipe} エラーになるでしょう。 @item @strong{MySQL} 許可テーブルを作成します (これは初めて @strong{MySQL} をインストールするときだけ行います): @example shell> scripts/mysql_install_db @end example 3.22.10以前のバージョンの @strong{MySQL} は、@code{mysql_install_db}. 実行時に @strong{MySQL} を起動していましたが、もはやこれは起動しなくなりました @item Perl @code{DBI}/@code{DBD} インタフェースのサポートをインストールしたい 場合、@ref{Perl support} を見てください。 @item @strong{MySQL} をマシン起動時に自動的に開始したい場合、 @code{support-files/mysql.server} をシステムのスタートアップファイルがある場所にコ ピーしてください。さらなる情報は @code{support-files/mysql.server} スクリプト自身 の中と、@ref{Automatic start} に見つけられます。 @end enumerate 全てがアンパックされてインストールされた後、配布の初期化とテストを行なう べきです。 @strong{MySQL} サーバーは以下のコマンドで開始できます: @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 (訳注:もし RedHat 以外の Linux を使用しており、.rpm を、自分が使用している パッケージ管理システムの管理下におきたい場合、@strong{alien : http://kitenet.net/programs/alien/} というツールを 使用します。これは RPM(Debian, Slackware) を自分が使用しているパッケージの形式に変換してくれます。 ) RPM を使用して @strong{MySQL} をインストールすることを推奨します。 @strong{MySQL} RPMS は RedHat 5.2 で作成していますが、 他の @code{rpm} と @code{glibc} をサポートしている Linux でも動作するでしょう。 RPM file での問題, 例えば @code{Sorry, the host 'xxxx' could not be looked up} は、see @ref{Binary notes-Linux}. 以下が使用するであろう RPM files です: @itemize @bullet @item @code{MySQL-VERSION.i386.rpm} @strong{MySQL} サーバー。 ただ単に他のマシン上で走っている @strong{MySQL} サーバーに接続するだけなら、 これは不要でしょう。 @item @code{MySQL-client-VERSION.i386.rpm} @strong{MySQL} クライアント標準プログラム。 このパッケージはほとんどの場合インストールすることになるでしょう。 @item @code{MySQL-bench-VERSION.i386.rpm} ベンチマーク。perl msql-mysql-modules RPM が必要。 @item @code{MySQL-devel-VERSION.i386.rpm} 他の @strong{MySQL} クライアント(perlモジュールのような)をコンパイルするのに必要な ライブラリーとインクルードファイルを含みます。 @item @code{MySQL-VERSION.src.rpm} 上記全てのソース。これは他のアーキテクチャ用に RPM を作成する場合にのみ必要でしょう。 (例えば Alpha or SPARC). @end itemize RPM パッケージに含まれるファイルをみるには: @example shell> rpm -qpl MySQL-VERSION.i386.rpm @end example インストールの最小の方法: @example shell> rpm -i MySQL-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm @end example クライアントパッケージだけをインストール: @example shell> rpm -i MySQL-client-VERSION.i386.rpm @end example RPM はデータを @file{/var/lib/mysql} に保存します。 RPM は起動時にサーバーを立ちあげるように、@file{/etc/rc.d/} に登録します。 (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 クライアントプログラムのビルド 自分で書いたか、第三者が作成した @strong{MySQL} クライアントプログラムをコンパイルする場合、 @code{-lmysqlclient} オプションを使用してリンクされなければなりません。 また @code{-L} オプションを指定して、ライブラリがどこにあるか指定する必要がある場合もあります。 例えばライブラリが @file{/usr/local/mysql/lib} にインストールされるならば、 リンクの時に @code{-L/usr/local/mysql/lib -lmysqlclient} と指定します。 @strong{MySQL} ヘッダーファイルを使用するクライアントのために、 あなたがそれらをコンパイルする時には、@code{-I} オプションを指定しなければならない事もあります。 (例えば, @code{-I/usr/local/mysql/include}) @node Binary install system issues, , Building clients, Installing binary @subsection System 特有の問題 @menu * Binary notes-Linux:: Linux notes * Binary notes-HP-UX:: HP-UX notes @end menu 以下のセクションでは特定のシステム上に起こると認められたいくつかの問題のを示します。 @node Binary notes-Linux, Binary notes-HP-UX, Binary install system issues, Binary install system issues @subsubsection Linux notes TcX のバイナリリリースは @code{-static} でリンクされており、これはあなたのシステムが どのバージョンのライブラリーを使用しているか気にする必要がありません。 よって、LinuxThreads もこの場合必要ありません。 @code{-static} でリンクされたプログラムのサイズは ダイナミックリンクされたプログラムより大きくなりますが、少し(3-5%)速くなります。 しかし一つの問題として、このスタティックリンクされたプログラムでは、 ユーザー定義関数(UDF)が使用できないことです。 もし UDF を使用する(書く)場合(C, C++とかで)、自分自身で @strong{MySQL} を ダイナミックリンクを使用してコンパイルしなくてはなりません。 もし @code{glibc2} ではなく libc5 のシステムを使用しているなら、 このバイナリリリースではホスト名解決とgetpwnam()にいくつか問題が出ます。 (これは @code{glibc} がホスト名解決とgetwpent()にいくつかの外部ライブラリに 依存しているためで、たとえ @code{-static} リンクしても解決しません). この場合、@code{mysql_install_db} 実行時に以下のエラーが出るでしょう: @example Sorry, the host 'xxxx' could not be looked up @end example あるいは、@code{--user} オプションで mysqld を起動しようとしたとき、 以下のエラーが出る場合: @example getpwnam: No such file or directory @end example この問題は、以下のうちのどれかの方法で解決できます: @itemize @bullet @item @strong{MySQL} ソース配布を入手し( RPM か @code{tar} )、代わりに インストールします。 @item @code{mysql_install_db --force} を実行します; これは @code{mysql_install_db} に かかれている @code{resolveip} テストを実行しません。 また許可テーブル内でホスト名が使えなくなっています; ホスト名でなく IP アドレスで登録します (@code{localhost} は除). もし @code{--force} を持っていないような古い @strong{MySQL} を使用しているなら、 エディターで、@code{resolveip} テストを @code{mysql_install} から削除します。 @item mysqld を @code{--user} の代わりに @code{su} で起動。 @end itemize Linux-Intel binary と @strong{MySQL} RPM リリースは、もっとも速くなるように 調整されています。我々はもっとも早く安定したコンパイラーを常に使用しています。 @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 path to 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 @strong{MySQL} ソース配布のインストール ソースから @strong{MySQL} を作成しインストールするためには次のツールが必 要です: @itemize @bullet @item GNU @code{gunzip}。配布の伸張のため。 @item 適正な @code{tar}。配布の展開のため。GNU @code{tar} は動くことが知られて います。 @item ANSI C++ コンパイラ。@code{gcc} >= 2.8.1, @code{egcs} >= 1.0.2, SGI C++, SunPro C++ は働くことが知られているコンパイラのいくつかです。 @code{libg++} は @code{gcc} 使用時には必要ではありません。@code{gcc} 2.7.x は、@file{sql/sql_base.cc} のような、完全に正当な C++ ファイルのい くつかをコンパイルできないというバグがあります。@code{gcc} 2.7.x だけし かなければ、@strong{MySQL} をコンパイルできるように @code{gcc} をアップ グレードする必要があります。 @item 良い @code{make} プログラム。GNU @code{make} は常に推奨され、時々は必要 とされます。問題があれば GNU @code{make} 3.75 以上を試すことをお勧めしま す。 @end itemize @c texi2html fails to split chapters if I use strong for all of this. 問題が起きたときは、@email{mysql@@lists.mysql.com} に質問を投稿する時に @strong{@code{mysqlbug} を常に使用してください}。問題がバグでないとして も、@code{mysqlbug} はあなたの問題を解決する助けになるであろうシステム情 報を収集します。@code{mysqlbug} を使用しないと、あなたの問題の解決を得る 可能性が小さくなります! @code{mysqlbug} は、配布のアンパック後に @file{scripts} ディレクトリ内に見つけられます。@xref{Bug reports}。 @menu * Quick install:: 素早いインストールの概要 * Applying patches:: パッチの適用 * configure options:: 典型的な @code{configure} オプション @end menu @node Quick install, Applying patches, Installing source, Installing source @subsection 素早いインストールの概要 @strong{MySQL} をソースからインストールするために行なわなければならない 基本的なコマンド(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 RPM ソースから開始する場合は: @example shell> rpm --rebuild MySQL-VERSION.src.rpm @end example これはインストールできるRPMバイナリを作成します もし @code{DBI} と @code{Msql-Mysql-modules} Perl モジュールをインストールするなら、 @code{bin/mysql_setpermission} スクリプトが使用する新しいユーザーを 追加することができます。 次にさらに詳細な説明を行ないます: ソース配布のインストールには、次のステップに従い、それから インストール 後の初期化とテストのために @xref{Post-installation} に進んでください。 @enumerate @item 配布をアンパックしたいディレクトリを選んで、そこに移ってください。 @item 配布ファイルを @ref{Getting MySQL, , Getting @strong{MySQL}}. にリストされたサイトの一つから得てください。 @strong{MySQL} ソース配布は圧縮された @code{tar} アーカイブとして提供さ れ、@file{mysql-VERSION.tar.gz} のような名前を持ちます。ここで @code{VERSION} は @value{mysql_version} のような番号です。 @item カレントディレクトリに配布をアンパックしてください: @example shell> gunzip < mysql-VERSION.tar.gz | tar xvf - @end example このコマンドは @file{mysql-VERSION} という名前のディレクトリを作成します。 @item アンパックされた配布のトップレベルディレクトリに移ってください: @example shell> cd mysql-VERSION @end example @item リリースを configure し、全てをコンパイルしてください: @example shell> ./configure --prefix=/usr/local/mysql shell> make @end example @code{configure} の実行時、いくつかのオプションを指定できます。オプショ ンの一覧は @code{./configure --help} を実行してください。@ref{configure options, , @code{configure} options}, さらに有用なオプションのいくつかに ついて議論しています。 @code{configure} が失敗して、援助を得るために @email{mysql@@lists.mysql.com} にメー ルを送ろうとする場合、@file{config.log} から問題の解決の手助けにできると 考えられる行を含めてください。@code{configure} が異常終了する場合、 @code{configure} からの出力の最後の数行も含めてください。バグレポートは @code{mysqlbug} スクリプトを使用して投稿してください。@xref{Bug reports}。 コンパイルが失敗する場合、いくらかのよくある問題での手助けのため、 @ref{Compilation problems} を参照してください。 @item 全てをインストールしてください: @example shell> make install @end example このコマンドは @code{root} として実行する必要があります。 @item @strong{MySQL} 権限テーブルを生成してください(以前に @strong{MySQL} をイ ンストールしていない時にだけ必要です): @example shell> scripts/mysql_install_db @end example 注意: 3.22.10 より古い @strong{MySQL} バージョンでは、 @code{mysql_install_db} 実行時に @strong{MySQL} サーバが開始されましたが、 これはもはや真ではありません! @item Perl @code{DBI}/@code{DBD} インタフェースのサポートをインストールしたい 場合、@ref{Perl support} を見てください。 @item @strong{MySQL} をマシン起動時に自動的に開始したい場合、 @code{support-files/mysql.server} をシステムのスタートアップファイルがあ る場所にコピーしてください。さらなる情報は @code{support-files/mysql.server} スクリプト自身の中と、@ref{Automatic start} に見つけられます。 @end enumerate 全てがインストールされた後、配布の初期化とテストを行なうべきです。 @strong{MySQL} サーバーを以下のコマンドで開始できます。 @code{BINDIR} は @code{safe_mysqld} がインストールされているディレクトリ (@file{/usr/local/bin} by default) です: @example shell> BINDIR/safe_mysqld & @end example コマンドがすぐに @code{mysqld daemon ended} エラーで失敗する場合、 @file{mysql-data-directory/'hostname'.err} ファイルになんらかの情報を 見つけることができます。 よくあることとして、すでに他の @code{mysqld} が 走っている場合などがあります。 @xref{Multiple servers}. @xref{Post-installation}。 @node Applying patches, configure options, Quick install, Installing source @subsection パッチの適用 時々、パッチは、メーリング・リストに流されたり、または @strong{MySQL} FTPサイトの @uref{ftp://www.mysql.com/pub/mysql/Downloads/Patches,パッチエリア} に置かれます。 メーリング・リストからのパッチを適用するには、パッチが載っているメッセージを ファイルに保存して、あなたの @strong{MySQL} ソース・ツリーの 一番上のディレクトリーに移動し、以下のようにコマンドを実行します: @example shell> patch -p1 < patch-file-name shell> rm config.cache shell> make clean @end example FTPサイトに置かれるパッチは、プレーンテキストファイルとして、 あるいは @code{gzip} で圧縮されたファイルとして頒布されます。 プレーンテキストのパッチの場合は、上に示したメーリングリストの パッチと同様に適用します。 圧縮されたパッチを適用するには、 @strong{MySQL} ソース・ツリーの 一番上のディレクトリーに移動し、以下のようにコマンドを実行します: @example shell> gunzip < patch-file-name.gz | patch -p1 shell> rm config.cache shell> make clean @end example それから通常のソースインストールの指示を @code{./configure} ステップから 始めます。@code{make install} ステップ実行後、あなたの @strong{MySQL} サー バを再起動します。 @code{make install} を実行する前に、現在走っているサーバーを止める必要があるかもしれません。 ( @code{mysqladmin shutdown} で止めます ) いくつかのシステムでは、現在実行しているものを止めない限り、 新しいバージョンをインストールできないようになっています。 @node configure options, , Applying patches, Installing source @subsection 典型的な configure オプション @code{configure} スクリプトは @strong{MySQL} 配布をどのようにコンフィグ するかを制御するための多くの処理を提供します。典型的には、 @code{configure} コマンドラインにオプションを使用してこれを行ないます。 いくつかの環境変数を使用しても @code{configure} に影響を与えることができ ます。 @xref{Environment variables}. @code{configure} がサポートするオプションの一覧は、次のコマンドを 実行してください: @example shell> ./configure --help @end example 良く使われる @code{configure} オプションのいくつか以下に説明します: @itemize @bullet @item @strong{MySQL} クライアントライブラリとクライアントプログラムだけをコン パイルするには、@code{--without-server} オプションを使用してください: @example shell> ./configure --without-server @end example C++ コンパイラがなければ、@code{mysql} はコンパイルできません(これは C++ を要求するクライアントプログラムの一つです)。この場合、@code{configure} から C++ コンパイラをテストするコードを削除でます。それから @code{./configure} を @code{--without-server} オプションつきで実行してく ださい。コンパイルステップは @code{mysql} の作成を試みますが、 @file{mysql.cc} についての警告は無視できます。(@code{make} が止まる場合、 エラーが発生しても残りの作成を継続するように @code{make -k} を試してくだ さい。) @item ログファイルとデータベースディレクトリを @file{/usr/local/var} 配下にお きたくない場合は、次の一つのような @code{configure} コマンドを使用してく ださい: @example shell> ./configure --prefix=/usr/local/mysql shell> ./configure --prefix=/usr/local \ --localstatedir=/usr/local/mysql/data @end example 最初のコマンドはインストールプレフィックスを変更し、デフォルトの @file{/usr/local} ではなく @file{/usr/local/mysql} 配下にインストールし ます。次のコマンドはデフォルトのインストールプレフィックスを保存しますが、 データベースディレクトリのデフォルト位置(通常は @file{/usr/local/var})を 上書きし、@code{/usr/local/mysql/data} に変更します。 @item UNIX を使用していて、ソケットの位置をデフォルト位置(通常は @file{/tmp} または @file{/var/run})でなく他のどこかにしたい場合は、@code{configure} コマン ドを次のように使用します: @example shell> ./configure --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock @end example ファイル名は絶対パス名でないといけません。 @item 静的リンクされたプログラムをコンパイルしたい場合(例えば、バイナリ配布を 作成するため、もっと速くするため、いくつかの RedHat 配布での問題を回避す るため)は、次のように @code{configure} を実行します: @example shell> ./configure --with-client-ldflags=-all-static \ --with-mysqld-ldflags=-all-static @end example @item @code{gcc} を使用していて、@code{libg++} や @code{libstdc++} がインストー ルされていない場合、@code{configure} に @code{gcc} を C++ コンパイラとし て使用することを伝えてください: @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 @code{gcc} を C++ コンパイラとして使用する時、@code{libg++} または @code{libstdc++} のリンクは試みません。 コンパイラやリンカが共有ライブラリ @file{libmysqlclient.so.#} を生成でき ないというエラーになる場合、@code{--disable-shared} オプションを @code{configure} に与えることで、この問題を回避できます。この場合、 @code{configure} は共有ライブラリ @code{libmysqlclient.so.#} を作成しま せん。 @item 非 @code{NULL} 項目(すなわち、@code{NULL} が許されていない項目)に @code{DEFAULT} 項目値を使用しないように @strong{MySQL} をコンフィグでき ます。これは、非 @code{NULL} 値を要求する全ての項目に値を明示的に指定し なければ、@code{INSERT} ステートメントはエラーを生成します。デフォルト値 の使用を抑えるには、次のように @code{configure} を実行します: @tindex CXXFLAGS environment variable @tindex Environment variable, CXXFLAGS @example shell> CXXFLAGS=-DDONT_USE_DEFAULT_FIELDS ./configure @end example @item デフォルトでは、@strong{MySQL} は ISO-8859-1 (Latin1) 文字セットを使用し ます。デフォルトセットを変更するには、@code{--with-charset} オプションを 使用します: @example shell> ./configure --with-charset=CHARSET @end example @code{CHARSET} は次の一つです: @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}. 注意: 文字セットを変更したい場合は、コンフィグレーション間で @code{make distclean} を行なう必要があります! (3.23.14 以前の場合) サーバとクライアント間で文字を変換したい場合は、 @code{SET OPTION CHARACTER SET} コマンドを調べるべきです。 @xref{SET OPTION, , @code{SET OPTION}}. @cindex @code{myisamchk} @strong{警告:} テーブルを生成した後に文字セットを変更する場合、 @code{myisamchk -r -q} を全てのテーブルに実行する必要があります。そうでな いと、インデックスは正しくソートされません。(これは、@strong{MySQL} のイ ンストール時、いくつかのテーブルの生成時、異なる文字セットを使用して @strong{MySQL} の再コンフィグ時、そして再インストール時に発生します。) @item デバッグコードつきで @strong{MySQL} をコンフィグするには、 @code{--with-debug} オプションを使用します: @example shell> ./configure --with-debug @end example これにより、いくつかのエラーを見つけられる安全なメモリ割り当てが含まれ、 何が発生しているかについての出力を提供します。 @xref{Debugging server}. @item あなたのクライアントプログラムがスレッドを使用している場合、 @strong{MySQL} クライアントライブラリを @code{--with-thread-safe-client} でスレッド安全用にコンパイルする必要が あります; これは、デフォルトではいくつかのスレッド安全でない関数で、ライ ブラリがスレッド安全関数コールを使用するようになります。これを行なうこと で小さなパフォーマンスペナルティがありますが、通常このオプションの使用は 完全に安全です。 @item 固有のシステムに関係するオプションについては、この章より後のシステム固有 の節で見つけることができます。@xref{Source install system issues}。 @end itemize @node Compilation problems, MIT-pthreads, Installing source, Installing @section コンパイルの問題か? Solaris 上で @code{gcc} を使用した場合、一切警告無く全ての @strong{MySQL} プログラムがきれいに作れます。 他のシステムではインクルードファイルの違いから警告が出るかもしれません。 MIT-pthreads を使用した際の警告は @ref{MIT-pthreads} を参照してください。 他の問題は、以下をチェックしてください。 多くの問題の解決のために、再 configure が必要です。 あなたが再構成する必要があるならば、以下に気をつけてください: @cindex Running @code{configure} after prior invocation @cindex @code{configure}, running after prior invocation @itemize @bullet @item もし @code{configure} を一度実行した後に実行するならば、 @code{configure} は 前に作った情報を利用します。この情報は @file{config.cache} に保存されます。 @code{configure} は起動時にこのファイルを探し、もし存在するならば、 その中の情報が正しい物として読み込みます。 これはあなたが再コンフィグするならば無効になります。 @item @code{configure} を実行するごとに、 @code{make} を実行してコンパイルしなければなりません。 しかし、最初に、前のビルドでできたオブジェクトを、消しておいてください。 なぜなら、違うコンフィグオプションにより生成されたからです。 @end itemize 古いコンフィグやオブジェクトファイルの使用を防ぐため、 @code{configure} 前に以下のコマンドを実行してください: @example shell> rm config.cache shell> make clean @end example こうするかわりに、@code{make distclean} としても構いません。 以下に、 @strong{MySQL} をコンパイルする際に起こりやすい問題をあげておきます: @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 @file{sql_yacc.cc} コンパイル時に、以下のようなエラーが出た場合、 メモリー、スワップが足りません: @example Internal compiler error: program cc1plus got fatal signal 11 or Out of virtual memory or Virtual memory exhausted @end example この問題は、@code{gcc} がインライン展開で @file{sql_yacc.cc} をコンパイルするのに、 とても多くのメモリーを必要とするからです。 この場合、 @code{configure} を @code{--with-low-memory} オプション指定で実行します: @example shell> ./configure --with-low-memory @end example このオプションは、 @code{gcc} を使用しているなら @code{-fno-inline} オプションを コマンドラインに加え、@code{gcc} 以外ならば @code{-O0} を加えます。 多くのメモリーとスワップを持っていない限りは、@code{--with-low-memory} オプションを使用すべきです。 この問題はけっこうなハードウェア構成でも起こることが知られています。 通常、 @code{--with-low-memory} オプションでこの問題は解決できます。 @item 標準では、@code{configure} は @code{c++} という名前でコンパイラーを使用し、 GNU @code{c++} は @code{-lg++} を使ってリンクします。 もし @code{gcc} を使用しているならば、コンフィグ時に以下のような問題が出るかもしれません: @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 この問題は、@code{g++}, @code{libg++} あるいは @code{libstdc++} に関連したものです。 原因の一つとして考えられることは、 @code{g++} を持っていないか、あるいは、 @code{g++} はあっても @code{libg++} か @code{libstdc++} がないという事です。 @file{config.log} ファイルは c++ コンパイラが動作しなかった理由を記録しています! この問題を解決するに当たり、あなたが持っている C++ コンパイラーの代わりに @code{gcc} を使用しても構いません。@code{CXX} 環境変数に @code{"gcc -O3"} としてみてください。 例えば: @tindex CXX environment variable @tindex Environment variables, CXX @example shell> CXX="gcc -O3" ./configure @end example これは @code{gcc} が @code{g++} と同様に C++ ソースをコンパイルするので動きますが、 @code{libg++} か @code{libstdc++} が標準ではリンクされません。 他の解決方法は、もちろん、@code{g++}, @code{libg++}, @code{libstdc++} をインストールすることです。 @item もし以下のエラーのどれかが起きた場合、 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 と FreeBSD の @code{make} プログラムには問題があることが知られています。 GNU @code{make} version 3.75 は動作確認されています。 @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 もし C,C++ のためにフラグを与えたい場合、@code{CFLAGS} と @code{CXXFLAGS} 環境変数に フラグを追加してください。同様に、 @code{CC} と @code{CXX} にコンパイラー名を 与えることもできます。 例えば: @example shell> CC=gcc shell> CFLAGS=-O6 shell> CXX=gcc shell> CXXFLAGS=-O6 shell> export CC CFLAGS CXX CXXFLAGS @end example @ref{TcX binaries} にはフラグの定義がリストされています。 色々なシステム上で役に立つと思います。 @item 以下のようなエラーの場合、@code{gcc} コンパイラーをアップグレードしてください: @example client/libmysql.c:273: parse error before `__attribute__' @end example @code{gcc} 2.8.1 は動作することが確認されていますが、 @code{gcc} 2.95.2 以上をお勧めします。 @item @code{mysqld} コンパイル時に以下のようなエラーが出た場合、 @code{configure} が@code{accept()}, @code{getsockname()}, @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 これを修正するには、@file{config.h} ファイル(@code{configure} により作られる) を修正します。 いかのように: @example /* Define as the base type of the last arg to accept */ #define SOCKET_SIZE_TYPE XXX @end example @code{XXX} を @code{size_t} か @code{int} (あなたのオペレーティングシステムが依存している型)に変えます。 (@code{configure} すると毎回 @file{config.h} は作り直されるので、 この修正は @code{configure} する度に行わなければならないことに注意) @item @file{sql_yacc.cc} ファイルは @file{sql_yacc.yy} から生成されます。 通常、 @strong{MySQL} が既に生成されたコピーとともにあるので、 @file{sql_yacc.cc} ファイルを自分自身で作成することはありません。 しかし、以下のエラーの場合、再作成する必要があります: @example "sql_yacc.yy", line xxx fatal: default action causes potential... @end example これはあなたの @code{yacc} のバージョンが不十分であることを示しています。 @code{bison} (the GNU version of @code{yacc}) を代わりにインストールして使用する必要があります。 @item もし @code{mysqld} か @strong{MySQL} クライアントをデバッグしたいなら、 @code{configure} を @code{--with-debug} オプション付きで実行します。 そしてコンパイルし、新しいクライアントライブラリーでクライアントをリンクします。 @xref{Debugging client}. @end itemize @node MIT-pthreads, Perl support, Compilation problems, Installing @section MIT-pthreads に関して このセクションではMIT-pthreadsを使っているさいに起こる問題についていくつか述べて います。 Linux では、MIT-pthreads を使用してはならず、 LinuxThreads をインストールするべきです! @xref{Linux}. もしあなたのシステムが本来のスレッドのサポートを提供しなければ、あなたは、 MIT-pthreadsパッケージを使って、@strong{MySQL} を構築する必要があります。 これにはほとんどのFreeBSDシステム、SunOS4.x,Solaris 2.4とそれ以前、ほかいくつか が含まれます。 @xref{Which OS}. @itemize @bullet @item ほとんどのシステム上では @code{--with-mit-threads} オプションで @code{configure} 実行することによって、 MIT-pthreadsが使われることを強制することができます。 @example shell> ./configure --with-mit-threads @end example MIT-pthreadsを使う時、非ソースディレクトリで構築することはサポートされていませ ん。なぜなら、私たちはこのコードへ私たちの変更を最小にしたいからです。 @item MIT-pthreadsは、Unixソケット実装に使われている @code{AF_UNIX} プロトコルをサポートしません。 これは、もしあなたが使っている MIT-pthreads をコンパイルすれば、全ての接続は、 TCP/IP を使う(つまり少し遅くなる)ことを意味します。 もし、あなたが @strong{MySQL} を構築したあとで、ローカルのサーバーに接続できないならば、 それはあなたのクライアントがデフォルトで Unix ソケットを使って @code{localhost} へ接続しようとしているのかもしれません。 明示的にローカルホスト名を指定するために、ホスト名指定のオプション (@code{-h} か @code{--host}) で @code{mysql} を使用して、TCP/IP 接続を試してみてください。 @item MIT-pthreads が使われているかどうかチェックはサーバコードを configure するときに だけ行われます。もし、あなたが @code{--without-server} を使ってクライアントコードのみを ビルドすることを設定したならば、クライアントは MIT-othreads が使われているかいないか、 Unixソケット接続がデフォルトで使われているのかわかりません。なぜなら Unix ソケットは MIT-pthreads 下では動作しないからです。また、あなたはそのようなインスタンスでは @code{-h} または @code{--host} を使う必要があります。 @item @strong{MySQL} が MIT-pthreads を使ってコンパイルされると、パフォーマンス上の問題のた めシステムロックはデフォルトでディスエーブルとされます。 @code{--use-locking} オプション を指定してサーバーに伝えることで、システムロックは使えるようになります。 @item ときどき(少なくともSolarisでは) pthread の @code{bind()} コマンドは何のエラーメッセージ なしにソケットへの bind に失敗することがあります。これは結果としてサーバーへの接続 失敗となります。たとえば、 @example shell> mysqladmin version mysqladmin: connect to server at '' failed; error: 'Can't connect to mysql server on localhost (146)' @end example これを解決するために @code{mysqld} サーバーを終了して、再起動してください。こ れは私たちがサーバーダウンを強制して、すぐにリスタートさせようとしたときだけ起こ りました。 @item MIT-pthreads を使っていると、@code{sleep()} システムコールは @code{SIGINT} (break) では割り込みできません。 これは @code{mysqladmin --sleep} を走らせているときにだけ 起こることがわかっています。 割り込みが発生してプロセスが停止する前に、あなたは終了させるための @code{sleep()} コールを待たなく てはなりません。 @item リンクしているとき(少なくともSolarisでは)、あなたはこのような warning メッセージ を受け取るでしょう。これらは無視してかまいません。 @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 他のいくつかの warnings もまた無視してかまいません。 @example implicit declaration of function `int strtoll(...)' implicit declaration of function `int strtoul(...)' @end example @item 私たちはまだ MIT-pthread とともに動く @code{readline} を手に入れていません(これは必要では ないのですが、おそらく誰かには興味があるでしょう)。 @end itemize @node Perl support, Source install system issues, MIT-pthreads, Installing @section Perl のインストールについて @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 Unix への Perl のインストール @strong{MySQL} は Perl @code{DBI}/@code{DBD} インターフェースをサポートします。@xref{Perl}. @code{DBI}/@code{DBD} インターフェースの Perl のクライアントは、Perl 5.004 以上が必要です。 これより古いバージョンの Perl ですと@emph{動きません}。 @strong{MySQL} Perl は、 @strong{MySQL} クライアント・プログラミング・サポートが 既にインストールされていることが条件です。 もしあなたが RPM ファイルから @strong{MySQL} をインストールしたのなら、 クライアント・プログラムは、クライアント RPM にあります。 が、 クライアント・プログラミング・サポートは、開発者向け RPM にあります。 開発者向け RPM をインストールしたことを確かめて下さい。 これらは 3.22.8 から @strong{MySQL} 配布とは分けられて配布されています。 もし Perl モジュールをインストールしたいなら、@uref{http://www.mysql.com/Contrib} を 確認してください。ここにおかれています。 Perl の配布物は @code{tar} でアーカイブされ、圧縮されています。 @file{MODULE-VERSION.tar.gz} という命名規則で配布されています。 (@code{MODULE} はモジュール名、@code{VERSION} はバージョン番号) @code{Data-Dumper}, @code{DBI}, @code{Msql-Mysql-modules} が必要です。 これを取ってきたら、以下のようにしてインストールします。 @code{Data-Dumper} モジュールを例にしますが、他も同様にできます。 @enumerate @item 配布物をカレントディレクトリに展開: @example shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf - @end example これは @file{Data-Dumper-VERSION} というディレクトリを作ります。 @item 展開したディレクトリに入ります: @example shell> cd Data-Dumper-VERSION @end example @item コンパイル、インストール: @example shell> perl Makefile.PL shell> make shell> make test shell> make install @end example @end enumerate モジュールが動作するかを確かめるので @code{make test} コマンドは重要です。 インターフェースコードのテストのために @code{Msql-Mysql-modules} の インストール中にこれらのコマンドを実行する際には、 @strong{MySQL} サーバーが稼働していなければなりません。 でなければ、テストは失敗します。 新しいリリースの @strong{MySQL} をインストールした場合に常に @code{Msql-Mysql-modules} を再構築、再インストールすることは いい考えです。すべての @code{DBI} スクリプトが @strong{MySQL} の アップグレード後にコアダンプする兆候に気づいた場合は、特に そうしてください。 もし Perl module を正しくシステムディレクトリーやローカルのPerlディレクトリ にインストールできない場合、以下の文献が役立ちます: @example @uref{http://www.iserver.com/support/contrib/perl5/modules.html} @end example このページの以下を参照してください: @code{Installing New Modules that Require Locally Installed Modules}. @node ActiveState Perl, Win32 Perl, Perl installation, Perl support @subsection Win32 への ActiveState Perl のインストール Win32 上に、 ActiveState Perl に @strong{MySQL} @code{DBD} モジュールを インストールするには、以下のようにしなくてはなりません: @itemize @bullet @item Open a DOS shell. @item もし必要なら、HTTP_proxy 変数をセット。 例えば @code{set HTTP_proxy=my.proxy.com:3128} @item PPM プログラムの起動: @code{C:\perl\bin\ppm.pl} @item @code{DBI} のインストール(もし入っていなければ): @code{install DBI} @item この成功後に、 @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. もし上記のように出来なければ、代わりに @strong{MyODBC} ドライバーを入れ、 @strong{MySQL} サーバーに 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 Win32 への @strong{MySQL} Perl 配布物のインストール @strong{MySQL} Perl 配布は @code{DBI}, @code{DBD:MySQL} , @code{DBD:ODBC} を含みます。 @itemize @bullet @item @uref{http://www.mysql.com/download.html} から Perl distribution for Win32 を取得。 @item @code{C:} で unzip します。 @file{C:\PERL} ができます。 @item あなたのパスに @file{C:\PERL\BIN} を加えます。 @item あなたのパスに @file{C:\PERL\BIN\MSWin32-x86-thread} か @file{C:\PERL\BIN\MSWin32-x86} を加えます。 @item DOS shell で、 @code{perl -v} を実行して @code{perl} をテストします。 @end itemize @node Perl support problems, , Win32 Perl, Perl support @subsection Perl @code{DBI}/@code{DBD} 使用時の問題 もし Perl が @code{../mysql/mysql.so} モジュールが見つからないとメッセージを出した場合、 シェアードライブラリ @file{libmysqlclient.so} を取りこめなかったと考えられます。 以下のような方法で解決方法があります: @itemize @bullet @item @code{Msql-Mysql-modules} のコンパイルでは、 @code{perl Makefile.PL} のかわりに @code{perl Makefile.PL -static -config} とします。 @item @code{libmysqlclient.so} を他のシェアードライブラリがあるところ(@file{/usr/lib} とか @file{/lib})にコピーします。 @item @code{Linux} の場合、@file{/etc/ld.so.conf} ファイルに、@code{libmysqlclient.so} があるディレクトリを書き加え、@code{ldconfig -v} を実行します。 @item @tindex LD_RUN_PATH environment variable @tindex Environment variable, LD_RUN_PATH @code{LD_RUN_PATH} (@code{LD_LIBRARY_PATH}) 環境変数に @code{libmysqlclient.so} があるディレクトリを書き加えます。 @end itemize もし @code{DBD-mysql} で以下のエラーが出た場合、 @code{gcc} (あるいは、@code{gcc} でコンパイルされた古いバイナリ) を使用していると 思われます: @example /usr/bin/perl: can't resolve symbol '__moddi3' /usr/bin/perl: can't resolve symbol '__divdi3' @end example @file{mysql.so} を作成する時のリンクコマンドに @code{-L/usr/lib/gcc-lib/... -lgcc} を追加してください。 (Perlクライアントを作る際の @code{make} の出力をチェックしてください) @code{-L} オプションに指定するのは、あなたのシステム内の @file{libgcc.a} があるディレクトリです。 Perl と @strong{MySQL} が @code{gcc} を使用して作られていない場合も原因としてあります。 この場合、両方を @code{gcc} でコンパイルすることにより、ミスマッチを避けることができます。 ダイナミックリンクをサポートしていないシステム(like SCO)でPerlモジュールを使用したい場合、 @code{DBI} と @code{DBD-mysql} を含むスタティックのPerlを作る事もできます。 これは、まず、 @code{DBI} コードがリンクされているPerlを作って現在のPerlの上にインストールします。 そして、 @code{DBD} コードをさらにリンクさせるPerlを作り、それをインストールします。 SCOでは、環境変数を以下のようにしなくてはなりません: @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 最初、@code{DBI} をスタティックリンクしたPerlを作るために、 @file{perl/DBI} ディレクトリで以下のように実行します: @example shell> perl Makefile.PL -static -config shell> make shell> make install shell> make perl @end example この後、あなたは新しいPerlをインストールしなければなりません。 @code{make perl} をすると、インストール操作に実行するに必要な @code{make} コマンドを 表示します。 SCOでは、@code{make -f Makefile.aperl inst_perl MAP_TARGET=perl} とします。 次に、@code{DBD::mysql} をスタティックリンクしたPerlを作るために、 @file{perl/Mysql-modules} ディレクトリで以下のように実行します: @example shell> perl Makefile.PL -static -config shell> make shell> make install shell> make perl @end example これも新しいPerlをインストールしなくてはなりません。 @code{make perl} の出力は使用するコマンドを示します。 @node Source install system issues, Win32, Perl support, Installing @section System-specific issue 以下のセクションは、ソース配布から @strong{MySQL} をインストールする際に 特定のシステム上に起こると認められた問題のいくつかを示します. @menu * Solaris:: Solaris notes * Solaris 2.7:: Solaris 2.7 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:: * MaxOSX:: MaxOSX notes @end menu @node Solaris, Solaris 2.7, Source install system issues, Source install system issues @subsection Solaris notes Solaris では @strong{MySQL} ソースを展開するときトラブルが出るでしょう! Solaris の @code{tar} は長い名前を扱えず、 @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 この場合、GNU @code{tar} (@code{gtar}) を展開に使用してください。 コンパイルずみのものが以下にあります: @uref{http://www.mysql.com/Downloads/}. Sun ネイティブスレッドは Solaris 2.5 以上で動きます。 2.4 以下の場合、@strong{MySQL} は時動的に MIT-pthreads を使用します @xref{MIT-pthreads}. もし、configure 時に、以下のエラーが出たなら: @example checking for restartable system calls... configure: error can not run test programs while cross compiling @end example これはコンパイラーのインストールでなにかを間違っています! この場合、あなたは、より新しいバージョンへコンパイラーをアップグレードすべきです。 以下の行を @code{config.cache} ファイルに追加することによって、 この問題を解決してもかまいません: @example ac_cv_sys_restartable_syscalls=$@{ac_cv_sys_restartable_syscalls='no'@} @end example もしあなたが SPARC の Solaris を使用しているなら、 @code{gcc} 2.95.2 を推奨します。 これは @uref{ttp://gcc.gnu.org/}. で見つけれます。 @code{egs} 1.1.1 と @code{gcc} 2.8.1 は SPARC 上では完全に動作しないことに注意! @code{gcc} 2.95.2 を使用した、推奨する @code{configure} は: @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 もし Sun Workshop 4.2 compiler を使用するなら、@code{configure} を以下のようにします: 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 @code{configure} スクリプトの次の行を: @example #if !defined(__STDC__) || __STDC__ != 1 @end example 以下に変えます: @example #if !defined(__STDC__) @end example もし @code{-Xc} オプションで @code{__STDC__} を有効にした場合、 Sun compiler は Solaris の @file{pthread.h} ヘッダーファイルを使用して コンパイルすることができません。 これはサンのバグです(インクルードファイルかコンパイラーのバグ) もし @code{mysqld} を起動時に以下のエラーが出た場合、 マルチスレッドを外して(オプション @code{-mt} を指定) Sun compiler を使って @strong{MySQL} をコンパイルし直してください: @example libc internal error: _rmutex_unlock: rmutex not held @end example @code{-mt} を @code{CFLAGS} と @code{CXXFLAGS} に加えます。 @code{gcc} で @strong{MySQL} をコンパイルするときに以下のエラーが出た場合、 これは @code{gcc} があなたの 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 この場合、新しい @code{gcc} でコンパイルします! 少なくとも Solaris 2.5 では、ほとんどの @code{gcc} のバイナリのバージョンが古く、 スレッドを使用するプログラムにはこのインクルードファイルは使えません! Solaris は スタテックリンクのシステムライブラリーを用意していません (@code{libpthreads} and @code{libdl})。 そのため、@code{--static} オプションで @strong{MySQL} をコンパイルできません。 もしこれを試みた場合、以下のエラーになります: @example ld: fatal: library -ldl: not found @end example もし多くのプロセスが速く @code{mysqld} に接続を試みた場合、 @strong{MySQL} ログに以下のようにエラーが出ます: @example Error in accept: Protocol error @end example サーバーを @code{--set-variable back_log=50} オプションで起動すれば、この問題に対処できるでしょう。 もし自分の @strong{MySQL} クライアントプログラムをリンクして 実行時に以下のようにエラーが出た場合: @example ld.so.1: ./my: fatal: libmysqlclient.so.#: open failed: No such file or directory @end example これは以下のどれかで回避できます: @table @bullet @item 以下のフラグでクライアントをリンクします(@code{-Lpath} の代わりに): @code{-Wl,r/full-path-to-libmysqlclient.so} @item @code{libmysqclient.so} を @file{/usr/lib} にコピーします @item @tindex LD_RUN_PATH environment variable @tindex Environment variable, LD_RUN_PATH @code{LD_RUN_PATH} 環境変数を @file{libmysqlclient.so} が存在するところに セットした後、クライアントを実行します。 @end table @code{--with-libwrap} configure オプション使用時、@code{libwrap.a} が必 要とするライブラリも含める必要があります: @example --with-libwrap="/opt/NUtcpwrapper-7.6/lib/libwrap.a -lnsl -lsocket @end example configure や @strong{MySQL} が @code{-lz} のリンクを試み、あなたがそれを インストールしていないという問題がある場合は、2つの選択肢があります: @itemize @bullet @item 圧縮通信プロトコルを使用できるようにしたい場合、ftp.gnu.org から zlib を 入手してインストールする必要があります。 @item @code{--with-named-z-libs=no} をつけて configure を行ないます。 @end itemize @node Solaris 2.7, Solaris x86, Solaris, Source install system issues @subsection Solaris 2.7 notes 通常、Solaris 2.6 のバイナリは Solaris 2.7 で使用できます。 ほとんどの Solaris 2.6 の問題も Solaris 2.7 に適用できます。 Solaris 2.7 は、インクルードファイルにいくつかバグがあります。 @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 以下のようにして回避します: @code{/usr/include/widec.h} を @code{.../lib/gcc-lib/os/gcc-version/include} にコピー 41 行目を変更: @example 変更前: #if !defined(lint) && !defined(__lint) 変更後: #if !defined(lint) && !defined(__lint) && !defined(getwc) @end example 代わりに、@file{/usr/include/widec.h} を直接変更してもかまいません。 どちらの方法にしても、ファイルを修正後は、@file{config.cache} を 消して @code{configure} を再実行しなくてはなりません! @code{make} 実行時に以下のようなエラーになった場合、@code{configure} が @file{curses.h} ファイルを検出できていません (これは @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 これを解決するには、以下のうち一つを行います: @itemize @bullet @item 前述したとおり、@file{/usr/include/widec.h} を修正し、configure を再実行します。 @item @code{#define HAVE_TERM} 行を @file{config.h} ファイルから消し、 @code{make} を再実行します。 @item @code{CFLAGS=-DHAVE_CURSES CXXFLAGS=-DHAVE_CURSES ./configure} とコンフィギャーします。 @end itemize @node Solaris x86, SunOS, Solaris 2.7, Source install system issues @subsection Solarix x86 notes @code{gcc} か @code{egcs} を Solaris x86 で使用した場合、load 時にコアダンプする場合、 以下のように @code{configure} します: @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 これは @code{libstdc++} ライブラリーと C++ の問題を回避します。 もしこれが該当しない場合、デバッグモードでコンパイルして デバッグのトレースファイルを書き出すようにして起動するか、 @code{gdb} を使用して起動してください。 @xref{Debugging server}. @node SunOS, Linux, Solaris x86, Source install system issues @subsection SunOS 4 notes SunOS 4 では MIT-pthreads が必要です。 このために、 GNU @code{make} が @strong{MySQL} のコンパイルに必要になります。 いくつかの SunOS 4 では dynamic libraries と @code{libtool} に問題があります。 これを避けるために、以下のようにして @code{configure} します: @example shell> ./configure --disable-shared --with-mysqld-ldflags=-all-static @end example @code{readline} のコンパイル時、二重定義のワーニングが出ますが、 これは無視して構いません。 @code{mysqld} をコンパイルする時、 いくつか @code{implicit declaration of function} ワーニングがでますが、 無視して構いません。 @node Linux, Alpha-DEC-Unix, SunOS, Source install system issues @subsection Linux notes (all Linux versions) Linux では @strong{MySQL} は LinuxThreads を使用します。 もし @code{glibc2} を持たない古い Linux を使用している場合、 @strong{MySQL} のコンパイルの前に、 LinuxThreads をインストールしなければなりません。 @uref{http://www.mysql.com/Downloads/Linux} 注意: 2.1.1 とそれ以前の @code{glibc} バージョンは @code{pthread_mutex_timedwait} 操作中に致命的なバグがあります。これは @code{INSERT DELAYED} を行なう時に使用されます。@code{INSERT DELAYED} を 使用する場合、次のパッチを glibc ライブラリに追加@strong{しなければなり ません}: @uref{http://www.mysql.com/Downloads/Patches/glibc-pthread_cond_timedwait.patch}。 @strong{MySQL} 3.23.7 と @strong{MySQL} 3.22.32 はこのバグの一時的な回避 を含んでいます。 1000以上の同時接続を使用する予定であれば、LinuxThreads にいくつかの変更 をして、再コンパイルし、MySQL を新しい libthread.a を使用するように再リ ンクする必要があります。sysdeps/unix/sysv/linux/bits/local_lim.h 内の PTHREAD_THREADS_MAX を 4096 に増加し、internals.h 中の STACK_SIZE を 256 KB に減少させてください。注意: STACK_SIZE がデフォルトの 2MB である 場合、MySQL は 1000 程度の接続で安定でなくなります。 glibc 2.1.3-65 かそれ以降の場合、STACK_SIZE を増やす必要はありません; @code{mysqld} の @code{thread_stack} 値を代わりに変更できます。 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. もし @code{mysqld} が動かなかったり、 @code{mysql_install_db} が動かない場合、 以下を読みすすめてください! LinuxThreads か @code{libc}/@code{glibc} ライブラリーに問題のある Linux システムだけに起こります。 しかし @strong{MySQL} を動かせるために簡単な方法が多くあります。 一番簡単な方法は、バイナリになった @strong{MySQL} (not the RPM) を使用することです; このバージョンのバイナリは、あなた自身がコンパイルしたものより 10% ほど速いでしょう! @xref{Compile and link options}. 一つ知られている問題として、バイナリ配布を @code{libc5} の古い Linux システム (RedHat 4.x , Slackware 3.6以下, Debian 1.3 bo 以下など) で使用すると、ホスト名解決の致命的なエラーが出ます @xref{Binary notes-Linux}. @code{myisamchk} は @code{libc.so.5.3.12} で使用するとハングります. 最新の @code{libc} にアップグレードしてください。 LinuxThreads を使用している場合、最低3つのプロセスが走ります。 これらは実スレッドで、一つは LinuxThreads マネージャーのために、 一つは接続のハンドルに、もうひとつはアラームとシグナルのハンドルです。 注意: linux カーネルと linuxthread ライブラリはデフォルトでは 1024 スレッ ドだけ持つことができます。これはパッチを適用していないシステム上では MySQL への接続は最大 1021 だけであるということを意味します。ページ @uref{http://www.volano.com/linuxnotes.html} はこの制限をどのように回避 するかの情報が含まれています。 もし @code{mysqld} デーモンプロセスが @code{ps} などでみると死んでいるようであれば, 通常これは @strong{MySQL} バグか、壊れたテーブルを持っています。 @xref{Crashing}. LinuxThreads を使用していて @code{mysqladmin shutdown} が動かない場合、 LinuxThreads 0.7.1 以上にアップグレードしてください。 RedHat を使用していて, 以下のようなエラーが出た場合: @example /usr/bin/perl is needed... /usr/sh is needed... /usr/sh is needed... @end example この場合、 @code{rpm} のバージョンを @file{rpm-2.4.11-1.i386.rpm} と @file{rpm-devel-2.4.11-1.i386.rpm} (以上) にしなくてはいけません。 RedHat 4.2 は以下からアップグレードが入手できます。 @uref{ftp://ftp.redhat.com/updates/4.2/i386}. あるいは他の場合は @uref{http://www.sunsite.unc.edu/pub/Linux/distributions/redhat/code/rpm/} もし @strong{MySQL} クライアントを実行して以下のエラーになった場合: @example ld.so.1: ./my: fatal: libmysqlclient.so.4: open failed: No such file or directory @end example 以下の方法で解決できます: @itemize @bullet @item クライアントを以下のフラグで(@code{-Lpath}のかわりに)リンクします: @code{-Wl,r/path-libmysqlclient.so} @item @code{libmysqclient.so} を @file{/usr/lib} にコピーします @item @tindex LD_RUN_PATH environment variable @tindex Environment variable, LD_RUN_PATH @code{LD_RUN_PATH} 環境変数を @file{libmysqlclient.so} が存在する場所に設定します。 (クライアントを実行する前に設定します) @end itemize 富士通コンパイラ @code{(fcc / FCC)} を使用している場合、@strong{MySQL} のコンパイルにいくつかの問題があります。Linux ヘッダファイルはとても @code{gcc} 指向であるためです。 次の @code{configure} 行は @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 @end menu @node Linux-x86, Linux-RedHat50, Linux, Linux @subsubsection Linux-x86 notes @strong{MySQL} は @code{libc} 5.4.12 以上が必要です。@code{libc} 5.4.46 で動作します。 @code{glibc} 2.0.6 以上でも動作します。 @code{glibc} の RPM にはいくつか問題があり、アップデートをチェックしてください。 @code{glibc} 2.0.7-19 と 2.0.7-29 RPM で動作します。 古い Linux 配布物では、@code{configure} 時に以下のようなエラーが出るかもしれません: @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 これは @code{_P} マクロが一つのアンダースコアしかもてないためで、 このエラーメッセージのように対処してください。 以下のようなワーニングは無視して構いません: @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 Debian GNU/Linux では、@strong{MySQL} をマシンの起動時に立ちあげるためには、 以下のようにします: @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} スクリプトは @strong{MySQL} をインストールした先の @file{share/mysql} directory にあります。 あるいは、 @strong{MySQL} のソースの中の @file{support-files} ディレクトリにあります。 @code{mysqld} がつねにスタート時にコアをはく場合、 古い @file{/lib/libc.a} を使用しているかもしれません。 @file{sql/mysqld} を消去して、新しく @code{make install} してみてください。 これはいくつかの Slackware で報告された現象です。 RedHat 5.0 は @code{glibc} のバージョンによって問題が発生します。 @xref{Linux-RedHat50}. もし @code{mysqld} をリンクする場合に以下のようなエラーが出た場合、 @file{libg++.a} が正しくインストールされていません: @example /usr/lib/libc.a(putc.o): In function `_IO_putc': putc.o(.text+0x0): multiple definition of `_IO_putc' @end example @file{libg++.a} の使用を避けるには、 @code{configure} を以下のようにします: @example shell> CXX=gcc ./configure @end example @node Linux-RedHat50, Linux-RedHat51, Linux-x86, Linux @subsubsection RedHat 5.0 notes もし RedHat で @strong{MySQL} に問題がある場合、まず @code{glibc} のバージョンを新しいものにあげてください! RedHat のオフィシャルパッチ(including @code{glibc-2.0.7-19} and @code{glibc-devel-2.0.7-19}) をインストールしているなら、 @strong{MySQL} は問題なく動くはずです! @code{glibc} 2.0.5 には @code{pthread_key_create} 変数を解放する部分にバグがあり、 アップデートが必要です。@code{glibc} 2.0.5 を使用する場合、 スタティックリンクされて作成された @strong{MySQL} バイナリ配布物を使用すべきです。 ソースからコンパイルしたい場合、 @uref{http://www.mysql.com/Downloads/Linux} にある LinuxThreads の修正版をインストールするか、 あるいは @code{glibc} をバージョンアップしなくてはなりません。 もし @code{glibc} or LinuxThreads のバージョンが問題のあるものだと、 @code{mysqld} はコネクションの度にクラッシュします。 例えば、@code{mysqladmin version} は @code{mysqld} を完全にクラッシュします! また、問題のあるライブラリーを使用していると、 @code{mysqld} は起動時にクラッシュします。 いくつかの Linux systems では、以下のようにして configure でこれを避けることができます: @example shell> ./configure --with-mysqld-ldflags=-all-static @end example RedHat 5.0 では、@code{glibc} 2.0.7-19 RPM を簡単にインストールできますので、 インストール後、@code{--with-mysqld-ldflags=-all-static} なしで @code{configure} できます。 @code{glibc} 2.0.7 のソースに対するパッチは @example @uref{http://www.mysql.com/Download/Linux/glibc-2.0.7-total-patch.tar.gz} @end example にあります。 このパッチは @strong{MySQL} がテストされたパッチで、簡単に適用できます。 もし @strong{MySQL} 構築時にクラッシュする場合、新しい @strong{MySQL} の バイナリをダウンロードしてみてください。これはスタティックリンクで作成されており、 ライブラリーの衝突を避けることができ、全ての Linux で動くはずです! @strong{MySQL} はデバッグのためトレースファイルに情報を書き出すことができます。 これは問題を解決するためにヒントになる情報を多く出力します。 @xref{Debugging server}. @node Linux-RedHat51, Linux-SPARC, Linux-RedHat50, Linux @subsubsection RedHat 5.1 notes RedHat 5.1 の @code{glibc} (@code{glibc} 2.0.7-13) はメモリーリークします。 @code{glibc} を 2.0.7-19 にアップグレードしなくてはなりません。 あるいは、バイナリ配布の @code{mysqld} を使用するかです。 もしこれを行わなかった場合、メモリー関連の問題が発生します(out of memory, etc.,etc.)。 多くの場合以下のように: @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 @code{glibc} 2.0.7-19 にアップグレード後は、@strong{MySQL} を ダイナミックリンク指定(デフォルト)で configure できます。 が、@code{glibc} 2.0.7-19 をソースからインストールしない限り、 @code{--with-mysqld-ldflags=-all-static} オプションは @code{configure} で@strong{使用できません}! @code{glibc} のバージョンは @code{rpm -q glibc} で確認できます。 @node Linux-SPARC, Linux-Alpha, Linux-RedHat51, Linux @subsubsection Linux-SPARC notes いくつかの埋め込み関数, @code{readdir_r()} が壊れます。 この顕れとして、@code{SHOW DATABASES} が常に空を返します。 これは configure 後、コンパイルする前に、 @file{config.h} から @code{HAVE_READDIR_R} を取り除くことで解決します。 その他いくつかの問題は、あなたの Linux にパッチを当てる必要があります。 パッチは @uref{http://www.mysql.com/patches/Linux-sparc-2.0.30.diff} にあります。 このパッチは、@code{vger.rutgers.edu} にある @file{sparclinux-2.0.30.tar.gz} 用です。 (これは正式の 2.0.30 とは違います。パッチを正式2.0.30に当てないように) そして LinuxThreads 0.6 かそれ以上にしなくてはなりません。 これは @email{jacques@@solucorp.qc.ca} から寄せられました。 @node Linux-Alpha, MKLinux, Linux-SPARC, Linux @subsubsection Linux-Alpha notes @strong{MySQL} 3.23.12 が、Linux-Alpha 上で最初にテストされたバージョンです。 もし @strong{MySQL} を Linux-Alpha 上で使用したいと考えたなら、 このバージョンより新しいものを使用します。 Linux-Alpha での一番大きな問題は、このプラットフォームの @code{glibc} に まだいくつか問題があることです。 最新の @code{glibc} を得ることから はじめてください。 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. もしシグナルで問題がある場合 (@strong{MySQL} dies unexpectedly under high load)、これは OS とスレッドのバグでしょう。 この場合、@strong{MySQL} をシグナルを使用しないように、configure 時に指定できます: @example shell> CFLAGS=-DDONT_USE_THR_ALARM \ CXXFLAGS=-DDONT_USE_THR_ALARM \ ./configure ... @end example これは @strong{MySQL} のパフォーマンスに影響しませんが、 @code{mysqladmin kill} or @code{mysqladmin shutdown} を使用して、 接続が ``sleeping'' になっているクライアントを kill できません。 次のコマンドを発行したとき、そのクライアントは死にます。 @node MKLinux, Qube2, Linux-Alpha, Linux @subsubsection MkLinux notes @strong{MySQL} は最新の @code{glibc} を使用した MkLinux で動作します。 (@code{glibc} 2.0.7 でテストしました). @node Qube2, , MKLinux, Linux @subsubsection Qube2 Linux notes Qube2 (Linux Mips) 上で @strong{MySQL} を動作させるには、 最新の @code{glibc} ライブラリでなくてはなりません(@code{glibc-2.0.7-29C2} は動作することが分かっています)。 そして、 @code{egcs} C++ compiler (@code{egcs-1.0.2-9}, @code{gcc 2.95.2} 以上) を使用しなくてはなりません。 @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 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't detect warnings, only errors. 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 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 @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. 最も簡単にインストールする方法は、@uref{http://www.freebsd.org} の mysql-server と mysql-client の ports を利用することです。 @uref{http://www.freebsd.org} これは以下のような利点をもたらします: @itemize @bullet @item オプティマイズされた @strong{MySQL} が動く @item 自動 configuration と build @item スタートアップ用のスクリプトが /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 FreeBSD 2.x 上では MIT-pthreads を、そして versions 3 以上では、 ネイティブのスレッドを使用してください。 最近のいくつかの 2.2.x ではネイティブのスレッド で動作が可能ですが、 mysqld を 落とすときに問題が起こります。 名前解決の設定を確実にしておいてください。 でないと、mysqld に接続する際、 名前解決にとても時間がかかり、接続に失敗するでしょう。 確実に @file{/etc/hosts} ファイルに @code{localhost} が登録されているように してください。 (でないと、データベースへの接続で問題が出ます)。 @file{/etc/hosts} ファイルは、以下の行から始まるべきです: @example 127.0.0.1 localhost localhost.your.domain @end example もし @code{configure} が MIT-pthread を使用すると分かった場合、 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 FreeBSD の @code{make} の振る舞いは GNU の @code{make} と少し違います。 もし @code{make} にかかわる問題が出たなら、 GNU @code{make} を インストールすべきです。 FreeBSD では、デフォルトのファイルハンドルの上限値がとても少ない 値であることも知られています。@xref{Not enough file handles}. safe_mysqld 中の ulimit -n のコメントを外すか、/etc/login.conf ファイルで mysqld ユーザーの制限値を増加させます。 (/etc/login.conf の変更の際は cap_mkdb /etc/login.conf で再構築が必要です)。 もしデフォルトを使用したくなければ、このユーザーに password ファイル中で 適切な Class を与えることでも、変更可能になります。(use: chpass mysqld-user-name) もし @strong{MySQL} が現在時で問題があるなら、 @code{TZ} 環境変数を設定しなくてはなりません。 @xref{Environment variables}. 安全で安定したシステムを入れるなら、 @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}. もし @strong{MySQL} が現在時で問題があるなら、 @code{TZ} 環境変数を設定しなくてはなりません。 @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{ftp://www.mysql.com/pub/mysql/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{ftp://www.mysql.com/pub/mysql/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 @code{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 using the IBM compiler: @example shell> CC="xlc_r -ma -O3 -qstrict -DHAVE_INT_8_16_32" \ CXX="xlC_r -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> CXX=gcc \ CXXFLAGS="-felide-constructors -fno-exceptions -fno-rtti" \ ./configure --prefix=/home/monty --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=/home/monty --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, MaxOSX, 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 (*)(), void (*)())' 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 MaxOSX, , 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 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 この節では Win32 上での @strong{MySQL} の使用とインストールについて述べます。 これは @strong{MySQL} Win32 配布物の @file{README} ファイルにも述べられています。 @menu * Win32 installation:: Installing @strong{MySQL} on Win32 * Win95 start:: Starting @strong{MySQL} on Win95 / Win98 * NT start:: Starting @strong{MySQL} on NT * 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 vs. Unix:: @strong{MySQL}-Win32 compared to Unix @strong{MySQL} @end menu @node Win32 installation, Win95 start, Win32, Win32 @subsection Win32 への @strong{MySQL} のインストール もし正式版 @strong{MySQL} を持っていないなら、最初に以下から シェアウエアバージョンをダウンロードすべきです: @uref{http://www.mysql.com/mysql_w32.htmy,@strong{MySQL} 3.22.x} 日本語版の評価版、および正式版(3.22)の取得は以下になります: @uref{http://www.softagency.co.jp/, @strong{MySQL} 日本語版} もし他のプログラムから @strong{MySQL} に接続しようと考えているなら、 多分 @strong{MyODBC} ドライバーも必要でしょう。 これは @uref{http://www.mysql.com/ownload_myodbc.html,@strong{MySQL} download page}. にあります。 日本語版の @strong{MyODBC} ドライバー は: @uref{http://www.softagency.co.jp/,@strong{MyODBC} 日本語版} それぞれの配布物のインストールをするには、ダウンロードした物を どこか からのディレクトリで unzip し、@code{Setup.exe} プログラムを 実行します。 標準では、@strong{MySQL}-Win32 は @file{C:\mysql} にインストールされるように なっています。 もし違う場所に @strong{MySQL} をインストールしたいなら、 一度 @file{C:\mysql} にインストールした後に、そのフォルダを移動します。 @strong{MySQL} を @file{C:\mysql} から移動したならば、 @code{mysqld} に対して、移動先を必ず教えねばなりません。 もし @strong{MySQL} を @file{D:\programs\mysql} に移動したなら, @code{mysqld} を以下のようにして起動します: @code{D:\programs\mysql\bin\mysqld --basedir D:\programs\mysql} なお、 @code{C:\mysql\bin\mysqld --help} とすると、全てのオプションが表示されます! 正式版の @strong{MySQL} では、@file{C:\my.cnf} ファイルを作成し、 そこに @strong{MySQL} サーバーのオプションを記述することが可能です。 @file{\mysql\my-xxxxx.cnf} を @file{C:\my.cnf} にコピーし、 ご自分の環境に合わせて編集して使用してください。 全てのパスには @code{\} ではなくて @code{/} を使用しなくてはなりません。 もし @code{\} を使用する場合には、これを2倍します。 @strong{MySQL} では @code{\} はエスケープ文字だからです。 @xref{Option files}. @node Win95 start, NT start, Win32 installation, Win32 @subsection Win95 / Win98 上での @strong{MySQL} 起動 @strong{MySQL} は TCP/IP をクライアントからサーバーへの接続に使用します。 (これは、あなたのネットワーク上のいかなるマシンからも @strong{MySQL} サーバーに 接続できるでしょう)。 このため、@strong{MySQL} を起動する前に、 あなたは TCP/IP をインストールしなくてはなりません。 これは Windows CD-ROM にあります。 もし古い Win95 (for example OSR2) を使用しているなら、 これは古い Winsock パッケージを使用しているかもしれません! @strong{MySQL} は Winsock 2 を要求します! 最新の Winsock は @uref{http://www.microsoft.com,Microsoft} にあります。 Win98 はデフォルトで新しい Winsock 2 ライブラリですので、 これは Win98 には当てはまりません。 2つの違う @strong{MySQL} サーバーがあります: @multitable @columnfractions .15 .85 @item @code{mysqld} @tab フルデバッグを有効にして、自動 memory allocation をチェックするようにコンパイル @item @code{mysqld-opt} @tab Pentium プロセッサー用に最適化した物 @end multitable 両方とも Intel プロセッサー >= i386 で動作します。 @code{mysqld} サーバーを起動するには, MS-DOS から以下のようにしなくてはなりません: @example C:\mysql\bin\mysqld @end example これは @code{mysqld} をバックグラウンドで動かします。 @strong{MySQL} サーバーの kill には: @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 NT 上での @strong{MySQL} 起動 The Win95/Win98 section also applies to @strong{MySQL} on NT, with the following differences: TCP/IP で @strong{MySQL} を動かすには、service pack 3(以上) が必須です! NT では, サーバーの名前は @code{mysqld-nt} です. 通常、以下のようにして NT のサービスとして @strong{MySQL} をインストールしなくてはなりません: @example C:\mysql\bin\mysqld-nt --install @end example (@code{mysqld} や @code{mysqld-opt} を NT 上で動作させることも出来ます。 しかしこれらは、サービスとしてスタートさせることが出来ず、また、 named pipes の使用も出来ません。) @strong{MySQL} サービスの起動と停止は: @example NET START mysql NET STOP mysql @end example この場合、@code{mysqld} に、いかなるオプションも使用できないことに注意! もし @code{mysqld-nt} をオプション無しで起動する必要があるならば、 @code{mysqld-nt} をスタンドアローンのプログラムとして NT 上で走らせることも 出来ます! もし @code{mysqld-nt} をオプション無しで NT 上で起動すると、 @code{mysqld-nt} は自分自身をサービスとして立ち上げようとします。 デフォルトのサービスオプションを使用して。 もし既に @code{mysqld-nt} を止めていたなら、 @code{NET START mysql} で 起動しなくてはなりません。 サービスは @code{MySql} という名前で登録されます。 一度インストールしたら、 これは Services Control Manager (SCM) Utility (コントロールパネルにある) を使用するか、@code{NET START MySQL} コマンドを使用するかして、 起動されなくてはなりません。 もし、オプションがなにも指定されていないなら、@code{MySQL} サービス開始前に、 SCM Utility の "Startup parameters" に記述しなくてはなりません。 一度走れば、 @code{mysqld-nt} は @code{mysqladmin} や SCM utility 、 @code{NET STOP MySQL} コマンドで停止できます。 もし SCM を使用して @code{mysqld-nt} 停止するなら、 @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. NT では以下のエラーメッセージが出るかもしれません: @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 もし @code{mysqld-nt} をサービスとしてインストールする場合に 問題が発生した場合、フルパスで実行してみてください: @example C:\mysql\bin\mysqld-nt --install @end example もしこれで動作しないようなら、レジストリ内のパスを修正すれば @code{mysqld-nt} を 起動できるでしょう。 サービスとして @code{mysqld-nt} を起動したくないなら以下のようにします: @example C:\mysql\bin\mysqld-nt --standalone @end example or @example C:\mysql\bin\mysqld --standalone --debug @end example 最新のバージョンでは、デバッグのトレースを @file{C:\mysqld.trace} に出します。 @node Win32 running, Win32 and SSH, NT start, Win32 @subsection Win32 上で @strong{MySQL} を実行 @strong{MySQL}は全ての Win32 プラットフォーム上で TCP/IP をサポートし、 NT 上で named pipe をサポートします。 デフォルトは、NT 上でローカルに接続するときにネームド・パイプが使用され、 そのほかの全ての場合で TCP/IP が使用されます。 ホスト名はどのプロトコルを使用するかを決めます: @multitable @columnfractions .3 .7 @strong{Host name} @tab @strong{protocol} @item NULL (none) @tab NT では最初にネームド・パイプを試み、動かなければ TCP/IP を使用します。 Win95/Win98 では TCP/IP を使用します。 @item . @tab ネームド・パイプ @item localhost @tab TCP/IP to current host @item hostname @tab TCP/IP @end multitable @strong{MySQL} クライアントに named pipes を強制的に使用させるには、 @code{--pipe} オプションを指定します。 そして、@code{--socket} オプションで パイプの名前を指定します。 @strong{MySQL} が動いているかどうかは、以下のようにして確認できます: @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 もし Win95/Win98 上で @code{mysqld} への接続が遅いようなら、DNS の問題かもしれません。 この場合、 @code{mysqld} を @code{--skip-name-resolve} オプションで 起動し、@strong{MySQL} 許可テーブルには、@code{localhost} と IP アドレスだけ 使用します。 NT上で走る @code{mysqld-nt} @strong{MySQL} サーバーに対しての接続時に DNS を避けるために、 @code{--pipe} 引数を指定してネームド・パイプを 使用できます。 これはほとんどの @strong{MySQL} クライアントで動きます。 2つの @strong{MySQL} コマンドラインツールがあります: @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 もし @code{mysqlc.exe} を使用したいなら, @file{C:\mysql\lib\cygwinb19.dll} を @file{\windows\system} (か、似たパス) にコピーしなくてはなりません。 Win32 の @strong{MySQL} の初期の権限は、ローカルの全てのユーザーに 対して、全てのデータベースで全ての権限が与えられています。 @strong{MySQL} を安全にするために、全てのユーザーにパスワードを 設定すべきです。また、@code{mysql.user} テーブルから @code{Host='localhost'} で @code{User=''} となっているレコードを 削除すべきです。 @code{root} ユーザーにもパスワードを設定すべきです: (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 パスワードを設定した後、もし @code{mysqld} サーバーを停止させるなら、 以下のようにします: @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 SSH を利用してリモートの @strong{MySQL} に Win32 から接続 SSH を利用して、Win32 から、どうやってリモートの MySQL に接続するかの説明です。 (by David Carlson). @itemize @bullet @item あなたの windows マシンに SSH クライアントをインストールします - 私はフリー版の SSH クライアントを使用しました。 @uref{http://www.doc.ic.ac.uk/~ci2/ssh/}. 他の有益な情報は: @uref{http://www.npaci.edu/Security/npaci_security_software.html} and @uref{http://www.npaci.edu/Security/samples/ssh32_windows/index.html}. @item SSH を起動。 Host Name を あなたの MySQL サーバーの名前か IP アドレスにセットします。 userid を、あなたのサーバーへのログイン名にセットします。 @item "local forwards" をクリック。 @code{local port: 3306}, @code{host: localhost}, @code{remote port: 3306} にそれぞれセット。 @item 全て保存(Save)。 保存しても次回やり直しができます。 @item SSH であなたのサーバーにログイン。 @item なにか ODBC アプリケーション(例えば Access) を起動。 @item ODBC ドライバーを利用して MySQL への新しいファイルとリンクを作成。 これは通常の時と作成方法は変わりないですが、サーバーが "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 vs. Unix, 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 vs. Unix, , Win32 symbolic links, Win32 @subsection @strong{MySQL}-Win32 compared to Unix @strong{MySQL} @strong{MySQL}-Win32 バージョンは現在それ自体とても安定した(stableな)状態で供給されています。 MySQL-win32 バージョンは すべての機能がUNIXバージョンのMySQLと対応しています。 ただし、下記のような例外があります。 @table @strong @item Win95 とスレッド Win95は、各々のスレッドの作成のためにメインメモリのおよそ200バイトをメモリリーク します。これのために、もしあなたが多くの接続をすれば、@strong{MySQL} の各々の接続が新しい スレッドを作成するので、あなたはWin95では長時間、@code{mysqld} を実行させるべきではあり ません! 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 ブロック読み込み @strong{MySQL} はそれぞれの接続のためにブロック読み込みを使います。 これは以下の事柄を意味しています: @itemize @bullet @item 接続は、@strong{MySQL} のUnixバージョンで起こるように、8時間の後に自動的に接続が断 ち切られるわけではありません @item もし接続が「ハングすれば」、@strong{MySQL}を終了しないでそれを中断することは、不可能です。 @item @code{mysqladmin kill} は、スリープしている接続上では働かないはずです。 @item スリープしている接続があるかぎり、@code{mysqladmin shutdown} は、中絶することができません。 @end itemize 私たちは、近い将来にこれを修正することを計画しています。 @item UDF 関数 差し当り、@strong{MySQL}-Win32 はユーザの定義できる関数をサポートしません。 @item @code{DROP DATABASE} 複数のスレッドで使われているデータベースはDROPをすることができません。 @item タスクマネージャーからの @strong{MySQL} の終了 Windows95では「Windowsの終了」やタスクマネージャから @strong{MySQL} を終了することはできません。 @code{mysqladmin shutdown} で終了しなければなりません。 @item 大文字小文字を区別しない名前 Win32ではファイルネームは大文字小文字が区別されます。そのため、Win32用の @strong{MySQL} で はテーブル名は大文字小文字が区別されます。唯一の制限は、名前が所定のステートメン トの至る所の同じケースで与えられなければならないそのデータベースと表です。 下のようなクエリーは働きません。それが表の @code{MY_TABLE}, @code{my_table} 両方を参照するからで す。 @example SELECT * FROM my_table WHERE MY_TABLE.col=1; @end example @item The @samp{\} (ディレクトリ名) Win95のパス名コンポーネントは、 @samp{\} によって離されますが、その文字は同じく @strong{MySQL} のエ スケープ文字でもあります。もしあなたは @code{LOAD DATA INFILE} または @code{SELECT ... INTO OUTFILE} を使って、UNIXでのファイルネームで @samp{/} を書くようにしたいなら、その代わりに 「\\」と @samp{\} をダブルで使わなくてはなりません。 @example LOAD DATA INFILE "C:\\tmp\\skr.txt" INTO TABLE skr; SELECT * FROM skr INTO OUTFILE 'C:/tmp/skr.txt'; @end example @item @code{Can't open named pipe} エラー もしあなたが最新の mysql-clients を持つNTの上で @strong{MySQL}-Win32 のシェアウェアバージョン を使えば、あなたは、次のエラーを得ることになるはずです: @example error 2017: can't open named pipe to host: . pipe... @end example @tindex .my.cnf file これは、 @strong{MySQL} のリリースバージョンがデフォルトでNTの上にネームドパイプを使ってい るために起こっています。 あなたは新しい @strong{MySQL} クライアントにまたは @file{C:\my.cnf} ファイルを作るさい(このファイ ルは以下の情報を含みます)に @code{--host=localhost} オプションを使うことによってこのエ ラーを避けられます。 @example [client] host = localhost @end example @item @code{Access denied for user} error もしあなたが同じマシン上の @strong{MySQL} サーバーにアクセスした時 @code{Access denied for user: 'some-user@@unknown' to database 'mysql'} エラーを得るなら、これはあなたの @strong{MySQL} があなた のマシンのホスト名を正しく解決できてないことを意味します。 これを修正するにはあな たはファイル @file{\windows\hosts} を作り、以下の情報を書くことによってすべきです。 (注:Windows95,98には\Windowsフォルダ上にサンプルとして「lmhosts.sam」ファイルが 既にあるはずです) @example 127.0.0.1 localhost @end example @end table ここにはWin32リリースを助けてくれる誰かのためにいくつかオープンになっている問題 があります: @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. @file{MySQL.DLL}. @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 NT上で @code{mysqld} をサービスとして @code{--install} フラグで登録するとき、もしあなたがコマンドラ インの上でデフォルトのオプションを同じく加えることができれば、それは、良いだろ う。この問題は差し当たって、 @file{C:\my.cnf} ファイルを代わりにすることで代用していま す。 @item あなたがラップトップの走るWin95を中断すると、ラップトップのレジュームされる時、 @code{mysqld} デーモンは新しい接続を受け入れません。私たちは、これがWin95、TCP/IP、また は、 @strong{MySQL} が持つ問題であるかどうかわかりません。 @item また、タスクマネージャから @code{mysqld} を終了させることができればほんとうに親切でしょう。 今のところ、あなたは @code{mysqladmin shutdown} を使わなければなりません。 @item @code{mysql} のコマンドラインツールとして @code{readline} をWin32に移植しませんか? @item 標準の @strong{MySQL} クライアント(@code{mysql}、@code{mysqlshow}、@code{mysqladmin}、および、@code{mysqldump})のGUI バージョンがあればいいでしょうねぇ。 @item もし @file{net.c} のソケットへ「読み込み」と「書き込み」がinterruptibleならば、それはい いのですが。これができればWin32上で @code{mysqladmin kill} を使用して開かれたスレッドを終 了できるのですが。 @item @strong{MySQL}-Win32/@strong{MyODBC} について書かれたWindowsプログラミングのドキュメント…それらが 動いていることを確認済みであること。 @item @code{mysqld} はデフォルトロケールではなく、常に「C」ロケールで起動します。私たちは、 ソート順序のために、 @code{mysqld} に、現在のロケールを使わせたい。 @item MysqlManagerにもっと多くのオプションを。 @item クライアントとサーバーのコミュニケーションプロトコルの変更…socketsとTCP/IPの代 わりにWindows内部のコミュニケーションを使う @item UDF 関数の @code{.DLL} での実装 @item Add macros to use the faster thread-safe increment/decrement methods provided by Win32. @end itemize 他のwin32に限定された症状は @strong{MySQL}-Win32 ディストリビューションに同梱されている @file{README} ファイルで説明されています。 @node OS/2, TcX 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 TcX binaries, Post-installation, OS/2, Installing @section TcX binaries サービスとして、TcX は @strong{MySQL} のバイナリ配布を提供しています。 これらのコンパイルは TcX 内部でおこなったり、我々にマシンの アクセスを提供してもらっている顧客のマシン上で行っています。 これらの配布物は @code{scripts/make_binary_distribution} で作成され、 以下のコンパイルオプションで調整されています。 @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} @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} @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} @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} @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} @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} @item AIX 2 4 with @code{gcc} 2.7.2.2 @code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql} @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} @item Irix 6.3 IP32 with @code{gcc} 2.8.0 @code{CC=gcc CXX=gcc CXXFLAGS=-O3 ./configure --prefix=/usr/local/mysql} @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} @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} @end table 上で示したオプション以外で最適化を施した方はだれでも、開発者向けの メーリングリストにポストできます。 @email{developer@@lists.mysql.com}. RPM 配布では @strong{MySQL} 3.22 を user-contributed としています。 3.22 をはじめ、いくつかの RPM パッケージは TcX 製です。 @node Post-installation, Upgrade, TcX binaries, Installing @section インストール後の設定とテスト @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 * Option files:: Option files @end menu 初めて @strong{MySQL}をインストールしたら(バイナリからでもソースからでもですが)、 サーバーを動作させるために、許可テーブルを初期化しなくてはなりません。 またマシンの起動時、停止時に、サーバーを自動で開始、停止することもできます。 通常、許可テーブルのインストールとサーバーの開始は、 ソースディストリビューションなら以下のようにします: @example shell> ./scripts/mysql_install_db shell> cd mysql_installation_directory shell> ./bin/safe_mysqld & @end example バイナリディストリビューションでは次を行ないます: @example shell> cd mysql_installation_directory shell> ./bin/mysql_install_db shell> ./bin/safe_mysqld & @end example テストは、@strong{MySQL} のトップディレクトリーから簡単に実行できます。 バイナリ配布を使用する場合、これ(トップディレクトリ)は インストール先のディレクトリーになるでしょう(@file{/usr/local/mysql})。 ソース配布の場合、これは @strong{MySQL} のソースディレクトリです。 コマンドは本節といかに続く節で説明しますが、@code{BINDIR} は @code{mysqladmin} や @code{safe_mysqld} がインストールされたディレクトリを示します。 バイナリ配布を使用している場合、@code{BINDIR} はバイナリ配布の @file{bin} ディレクトリになります。 ソースからインストールした場合、@code{BINDIR} は、@code{configure} で特別指定しない限り、 @file{/usr/local/bin} です。 @code{EXECDIR} は @code{mysqld} サーバーのインストール先です。 バイナリ配布を使用している場合、これは @code{BINDIR} ディレクトリと同一になります。 ソースからインストールした場合、@file{/usr/local/libexec} です。 テストについて以下に詳細に説明します: @enumerate @item 必要ならば、@code{mysqld} サーバーを起動し @strong{MySQL} の許可テーブルを初期化します。 (許可テーブルはユーザーがどのような権限をもってサーバーに接続を許すかを決定するものです。) これは通常、@code{mysql_install_db} スクリプトで初期化されます。 @example shell> scripts/mysql_install_db @end example 通常、@code{mysql_install_db} の実行は初めて @strong{MySQL} をインストール したあと一度だけ必要です。 すでにインストールされているものを アップグレードする際にはこの手順は飛ばせます。 (しかし、@code{mysql_install_db} は実に安全で、すでにテーブルが 存在している場合はいかなるテーブルも更新しません。したがって、 実行すべきかどうかわからない場合は、@code{mysql_install_db} を常に 走らせることができます) @code{mysql_install_db} は 6個のテーブルを作ります (@code{user}, @code{db}, @code{host}, @code{tables_priv}, @code{columns_priv} and @code{func}) @code{mysql} データベースに。 初期の権限状態についての説明は @ref{Default privileges}. これらの権限は @strong{MySQL} @code{root} ユーザーに なんでもできるように許可し、そして、だれもが @code{'test'} という名前か @code{'test_'} ではじまる名前をもつ データベースを作成、使用できるように許可されています。 もし許可テーブルを設定していない場合、サーバーを起動時に以下のエラーが出ます: @tindex host.frm, problems finding @example mysqld: Can't find file: 'host.frm' @end example バイナリ配布の @strong{MySQL} では、もし @strong{MySQL} を @code{./bin/safe_mysqld} を実行しないで起動した場合に、このエラーがおきます。! @code{root} で @code{mysql_install_db} を実行する必要があるとあなたは思うかもしれません。 しかし、 @strong{MySQL} は @code{root} 以外のユーザーで起動できます。 データベースディレクトリがサーバーを起動したユーザに対して読み書きが許可されていれば良いのです。 @strong{MySQL} を一般ユーザーで走らせる方法は @ref{Changing MySQL user, , Changing @strong{MySQL} user}. もし @code{mysql_install_db} で問題が出たら、 @ref{mysql_install_db, , @code{mysql_install_db}}. を参照のこと。 @code{mysql_install_db} スクリプトを走らせるにはいくつか選択があります: @itemize @bullet @item @code{mysql_install_db} を走らせる前に編集して、許可の初期状態を変更してもいいでしょう。 これは多くのマシンに同じ権限設定をして @strong{MySQL} をインストールする際に 役立ちます。 この場合、いくつかの @code{INSERT} 構文を @code{mysql.user} と @code{mysql.db} テーブルにたいして追加するようにするだけですみます! @item もしインストール後に許可を変更したい場合、 @code{mysql -u root mysql} で @strong{MySQL} @code{root} ユーザーで接続して直接許可テーブルを変更する SQL 文を実行します。 @item すでに許可テーブルが作成された状態で、完全に許可テーブルを作成し直すことができます。 これはすでにインストールされたテーブルがある場合や、@code{mysql_install_db} を編集した後にそう思うかもしれません。 @end itemize これらの選択については @ref{Default privileges} からさらに情報が得られます。 @item @strong{MySQL} サーバーを以下のようにして起動します: @example shell> cd mysql_installation_directory shell> bin/safe_mysqld & @end example サーバの起動に問題があれば、@ref{Starting server} を見てください。 @item @code{mysqladmin} でサーバーが走っているか確認します。 サーバーが立ち上がり接続を受け付けるか確認する簡単な方法を以下に示します: @example shell> BINDIR/mysqladmin version shell> BINDIR/mysqladmin variables @end example 例えば、@code{mysqladmin version} の出力はあなたのプラットフォームと @strong{MySQL} のバージョンを出力します。 出力は以下の様にでます: @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 @code{BINDIR/mysqladmin} の使用方法は、@code{--help} オプションで起動することにより得られます。 @item サーバーをシャットダウンするには: @example shell> BINDIR/mysqladmin -u root shutdown @end example @item サーバーをリスタートするには、@code{safe_mysqld} か @code{mysqld} を直接実行します。 例えば: @example shell> BINDIR/safe_mysqld --log & @end example @code{safe_mysqld} が失敗するなら、 @strong{MySQL} のインストールディレクトリーから実行してみてください。 もしそれでも起動しないなら、@ref{Starting server} を参照のこと。 @item いくつかの簡単なテストでサーバーが動いているか確認できます。 以下のようになります: @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 他のプラットフォームで @strong{MySQL} のパフォーマンスを比較するために @file{sql-bench} にベンチマークがあります。 @file{sql-bench/Results} ディレクトリには、他のデータベースやプラットフォームで ベンチを実行した結果があります。 全てのテストを実行するには、以下のようにします: @example shell> cd sql-bench shell> run-all-tests @end example RPM バイナリ配布には @file{sql-bench} ディレクトリがありません。 (RPM のソース配布には含まれます) この場合、ベンチマークをインストールしなくてはなりません。 @strong{MySQL} 3.22 のバイナリ配布から、 @file{mysql-bench-VERSION-i386.rpm} という名前で RPM パッケージを作っており、 これにはベンチマークのデータとコードが含まれます。 @file{tests} サブディレクトリでテストすることも可能です。 例えば、@file{auto_increment.tst} の実行は以下のようにします: @example shell> BINDIR/mysql -vvf test < ./tests/auto_increment.tst @end example これの結果は @file{./tests/auto_increment.res} ファイルに書き出されます。 @end enumerate @node mysql_install_db, Starting server, Post-installation, Post-installation @subsection @code{mysql_install_db} 実行時の問題 この節では @code{mysql_install_db} を実行した際にでくわすかもしれない問題について述べます: @table @strong @item @code{mysql_install_db} doesn't install the privilege tables これは @code{mysql_install_db} が権限テーブルをインストールできなかった事のメッセージですが、 続いて以下のようにメッセージが出た場合: @example starting mysqld daemon with databases from XXXXXX mysql daemon ended @end example この場合、注意深く log ファイルを調べてください! エラーメッセージに出ている @file{XXXXXX} ディレクトリにログファイルがあり、 これに @code{mysqld} がなぜスタートしなかったか記されているはずです。 もし何が起こったかわからない場合、このログファイルを含んで @code{mysqlbug} を使用して バグレポートを投稿してください! @xref{Bug reports}. @item There is already a @code{mysqld} daemon running この場合、 @code{mysql_install_db} を実行する必要はありません。 @code{mysql_install_db} を実行するのは @strong{MySQL} を初めてインストールした後、 たった一回だけです。 @item Installing a second @code{mysqld} daemon doesn't work when one daemon is running これはすでに @strong{MySQL} がインストールされており、 しかし新しいインストールを違うところに行おうとした場合に発生します。 (例えば、一度に二つのインストールを実行した場合など) 一般にこの問題は二つ目のサーバーを動いているサーバーと同じポート、ソケットを使用して起動しようとした場合に発生します。 この場合、@code{Can't start server: Bind on TCP/IP port: Address already in use} エラーメッセージか @code{Can't start server : Bind on unix socket...} エラーメッセージが出ます。 新しいサーバーは以下のようにして違うポート、ソケットで起動できます: @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 付録は @code{mysqld} に影響する他の環境変数の 一覧を含んでいます。@xref{Environment variables}。 この後、二つのデーモンを違うポート、ソケットで実行するように、起動スクリプトを変更します。 例えば、@code{safe_mysqld} を二つ書きますが、@code{--socket}, @code{--port} と @code{--basedir} オプションをそれぞれの @code{safe_mysqld} に指定します。 @item @file{/tmp} に書き込み許可をあなたが持っていないなら もしソケットファイルを標準の場所(@file{/tmp})に作成するための書き込み許可がないなら、 あるいは、一時ファイルを @file{/tmp} に作成できないなら、 @code{mysql_install_db} の実行時、あるいは @code{mysqld} の起動/使用時に エラーとなるでしょう。 違うディレクトリーにソケットファイルや一時ファイルを指定するには: @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} は書き込みが可能なディレクトリーを指定しなくてはなりません。 @xref{Environment variables}. この後、@code{mysql_install_db} を走らせ、サーバーを起動する事ができます: @example shell> scripts/mysql_install_db shell> BINDIR/safe_mysqld & @end example @item @code{mysqld} crashes at once もし RedHat 5.0 上で 2.0.7-5 より古い @code{glibc} を使用している場合、 全ての @code{glibc} パッチを当てなくてはなりません! これに関しては @strong{MySQL} メールのアーカイブに情報が多くあります。 メーリングリストのアーカイブのリンクは @uref{http://www.mysql.com/doc.html, @strong{MySQL} documentation page}. see @ref{Linux}. @code{mysqld} を @code{--skip-grant-tables} 指定で起動することもできます。 そして以下のように @code{mysql} を使用して自分自身の手により許可を加えます: @example shell> BINDIR/safe_mysqld --skip-grant-tables & shell> BINDIR/mysql -u root mysql @end example @code{mysql} から手動で @code{mysql_install_db} に書かれている SQL コマンドを実行します。 許可テーブルをサーバーに読み込ますためには、 @code{mysqladmin flush-privileges} か @code{mysqladmin reload} を実行します。 @end table @node Starting server, Automatic start, mysql_install_db, Post-installation @subsection @strong{MySQL} サーバー起動時の問題 通常 @code{mysqld} サーバーの起動は、以下の三つの方法のうち一つで行います: @itemize @bullet @item @code{mysql.server} による起動。このスクリプトはシステムの起動時、停止時に使われます。 詳細は @ref{Automatic start} @item @code{safe_mysqld} による起動。これは @code{mysqld} への適切なオプションを決定し、 それらのオプションでサーバーの起動を試みます。 @item NT 上では @code{mysqld} を次のようにサービスとしてインストールすべきです: @example bin\mysqld-nt --install # Install MySQL as a service @end example すると、次のように @code{mysqld} を起動/停止できます: @example NET START mysql NET STOP mysql @end example 注意: この場合 mysqld に対して他のオプションは使用できません! 次のようにしてサービスを削除できます: @example bin\mysqld-nt --remove # remove MySQL as a service @end example @item @code{mysqld} を直接起動。 @end itemize どの方法でサーバーを起動しても、もし起動に失敗すれば、ログファイルを確認してください。 なぜ失敗したか記録されています。ログファイルはデータベースディレクトリにあります。 (バイナリ配布の場合 @file{/usr/local/mysql/data} 、ソース配布の場合 @file{/usr/local/var}、 Windows では @file{\mysql\mysql.err} ) データベースディレクトリに @file{host_name.err} と @file{host_name.log} という ファイル (@code{host_name} はあなたのサーバー名) を探してください。 以下のようにしてそのファイルの最後の数行を確認します: @example shell> tail host_name.err shell> tail host_name.log @end example @code{mysqld} デーモンの起動時に、デーモンはデータディレクトリにディレクトリを変えます。 ログファイルと pid (process ID) ファイルがこのディレクトリに書ける事、 そしてデータベースがこのディレクトリにある事を、デーモンは要求します。 データディレクトリの場所は配布物のコンパイル時に指定されています。 @code{mysqld} があなたのシステム上にデータベースディレクトリを見つけれなかった場合、 サーバーは動きません。 @code{mysqld} を @code{--help} オプションで起動すれば @code{mysqld} の デフォルトのパスを知ることができますので、 サーバーが起動しない理由が違うパスを使用しているために起こっているかどうかがわかります。 パスが違う場合、@code{mysqld} のコマンドラインの引数に正しいパスを指定して、デフォルト値を 上書きすることが可能です。(これらオプションは @code{safe_mysqld} にも同様に使用できます) 通常、@strong{MySQL} がインストールされたディレクトリのベースディレクトリだけを @code{mysqld} に教えればいいはずです。 これは @code{--basedir} オプションを指定します。 @code{--help} オプションを使用すればパスの変更が確認できます。 (@code{--help} は@emph{必ず} 最後に指定のこと)  例えば: @example shell> EXECDIR/mysqld --basedir=/usr/local --help @end example パスの設定が思い通りに言ったことを確認したら、 @code{--help} オプションを外してサーバーを起動します。 以下のエラーの場合、他のプログラム(か他の @code{mysqld} サーバー)が @code{mysqld} が使用しようとしている TCP/IP ソケットを使っています: @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 他の @code{mysqld} サーバーが走っていないかを @code{ps} で確認します。 もし他のサーバーが起動していないなら、 @code{telnet your-host-name tcp-ip-port-number} コマンドを実行し、何回か @code{RETURN} キーをたたいてみてください。 もし、 @code{telnet: Unable to connect to remote host: Connection refused} のような エラーが出た場合、なにかが @code{mysqld} が使用しようとしているポートを既に使っています。 @xref{mysql_install_db, , @code{mysql_install_db}}, and @ref{Multiple servers}. @code{safe_mysqld} スクリプトは、ソース配布からでもバイナリ配布の @strong{MySQL} からでも、 たとえ違う場所にインストールされていても、サーバーを起動できるように作られています。 @code{safe_mysqld} は以下のどれか一つが真であることを期待します: @itemize @bullet @item @code{safe_mysqld} が起動されたカレントディレクトリからの相対パスに、 サーバーとデータベースがある場合。 @code{safe_mysqld} は @file{./bin}, @file{./data} ディレクトリ(バイナリ配布物の場合)、 あるいは @file{./libexec}, @file{./var} ディレクトリ(ソース配布物の場合)を探します。 あなたが @strong{MySQL} をインストールしたディレクトリ(例えば @file{/usr/local/mysql} ディレクトリ) から @code{safe_mysqld} を実行した場合、この条件に適合します。 @item サーバーとデータベースが相対パス以下にない場合、@code{safe_mysqld} は絶対パスでそれらを探します。 典型的なディレクトリは @file{/usr/local/libexec} と @file{/usr/local/var} です。 実際のディレクトリは @code{safe_mysqld} がある配布物が作成されるときに決められます。 これらは @strong{MySQL} がインストールされた標準のパスに正しく配置されていなければなりません。 @end itemize @code{safe_mysqld} はサーバーとデータベースを自分が起動されたディレクトリからの相対パスで探します。 よって、 @code{safe_mysqld} を @strong{MySQL} のインストールディレクトリから起動する限りは、 @strong{MySQL} バイナリ配布物を自分の好きなところにインストールできます。 その場合の起動は: @example shell> cd mysql_installation_directory shell> bin/safe_mysqld & @end example もし @code{safe_mysqld} が @strong{MySQL} インストールディレクトリから起動しても失敗するなら、 @code{safe_mysqld} をあなたのシステム用に @code{mysqld} のパスやパス名のオプションを 書き換えてもかまいません。 この場合、 @strong{MySQL} をアップグレードした場合、あなたが変更した @code{safe_mysqld} は上書きされるので、変更したものはインストール前にコピーしておき、 再び戻さなくてはなりません。 もし @code{mysqld} がすでに走っている場合、以下のコマンドにてパスの設定を知ることができます: @example shell> mysqladmin variables or shell> mysqladmin -h 'your-host-name' variables @end example もし @code{safe_mysqld} がサーバーを起動しても接続できないようなら、 @file{/etc/hosts} ファイルに以下のような記述を持たせてください: @example 127.0.0.1 localhost @end example この問題はスレッドライブラリーがなくて @strong{MySQL} を MIT-pthreads を 使用するようにして作ったシステムにだけ起こります。 Windows では、次のようにして @code{mysqld} の起動を試みることができます: @example C:\mysql\bin\mysqld --standalone --debug @end example これは、バックグランドで動作せず、@file{\mysqld.traec} にトレースを書き 出します。これは問題の原因を解決する手助けになります。@xref{Win32}。 @node Automatic start, Option files, Starting server, Post-installation @subsection @strong{MySQL} の自動起動と自動停止 @code{mysql.server} スクリプトは @code{start}, @code{stop} 引数を指定することにより サーバーを起動、停止できます: @example shell> mysql.server start shell> mysql.server stop @end example @code{mysql.server} は @strong{MySQL} インストールディレクトリの @file{share/mysql} ディレクトリ、 または @strong{MySQL} ソースツリーの @file{support-files} ディレクトリにあります。 @code{mysql.server} はサーバーを起動時する前に @strong{MySQL} がインストールされた ディレクトリにディレクトリを変え、@code{safe_mysqld} を起動します。 もし標準以外にインストールしているバイナリ配布を使用しているなら、 @code{mysql.server} を編集する必要があるかもしれません。 @code{safe_mysqld} を起動する前に正しいディレクトリに @code{cd} するように変更します。 @code{safe_mysqld} に他のオプションを与えるように @code{mysql.server} を変えても構いません。 他のユーザーで実行したい場合、@code{mysql_daemon_user=root} を変更しても構いません。 @code{safe_mysqld} に他のオプションを与えるために、 @code{mysql.server} を変更しても構いません。 @code{mysql.server stop} はサーバーにシグナルを送ってサーバーを停止します。 @code{mysqladmin shutdown} で手動でサーバーを落とすこともできます。 @strong{MySQL} を使用している製品のために、これらスタート、ストップを @file{/etc/rc*} に書きたいと思われるかもしれません。 ここでの注意点は、変更した @code{mysql.server} は、 @strong{MySQL} をアップグレードしたときに上書きされるということです。 よって、変更したものはインストール前にコピーを取っておくべきです。 もしあなたのシステムが @file{/etc/rc.local} を起動スクリプトとして使用しているなら、 以下のようにその中に記述します: @example /bin/sh -c 'cd /usr/local/mysql ; ./bin/safe_mysqld &' @end example グローバル設定ファイルである @file{/etc/my.cnf} に、 @code{mysql.server} の オプションを記述することも可能です。@file{/etc/my.cnf} ファイルは以下のような 記述になっています: @example [mysqld] datadir=/usr/local/mysql/var socket=/tmp/mysqld.sock port=3306 [mysql.server] user=mysql basedir=/usr/local/mysql @end example @code{mysql.server} スクリプトは以下の変数を使用します: @code{user}, @code{datadir}, @code{basedir}, @code{bindir} そして @code{pid-file}. @xref{Option files}. @cindex Default options @cindex Option files @node Option files, , Automatic start, Post-installation @subsection オプションファイル ( @code{my.cnf} ) @strong{MySQL} 3.22 のサーバー、クライアントともに、オプションファイルからデフォルトの起動オプションを読み込むことができます。 UNIX では @strong{MySQL} は以下のファイルからデフォルトオプションを読みます: @tindex .my.cnf file @multitable @columnfractions .3 .7 @item @strong{ファイル名} @tab @strong{意味} @item @code{/etc/my.cnf} @tab 全体のオプション @item @code{DATADIR/my.cnf} @tab サーバ固有オプション @item @code{~/.my.cnf} @tab ユーザ固有オプション @end multitable @code{DATADIR} は @strong{MySQL} データディレクトリです (普通 @file{/usr/local/mysql/data} or @file{/usr/local/var}). このディレクトリはconfigure時に決定されており、 @code{--datadir} を @code{mysqld} 起動時に指定しても変更されません。 (サーバーはコマンドラインの引数を処理する前にオプションファイルを探します。 よって、@code{--datadir} 引数を指定してもオプションファイルを探す場所を指定することにはなりません。) Win32 では @strong{MySQL} は以下のファイルからデフォルトオプションを読みます: @multitable @columnfractions .3 .7 @item @strong{ファイル名} @tab @strong{意味} @item @code{windows-system-directory\my.ini} @item @code{C:\my.cnf} @tab 全体のオプション @item @code{C:\mysql\data\my.cnf} @tab サーバ固有オプション @end multitable 注意: Win32 では @code{\} の代わりに @code{/} で全てのパスを記述すべきで す。@code{\} を使用する場合、@code{\} は @strong{MySQL} のエスケープ文字 なので、これを二重に記述する必要があります。 @cindex Environment variables @strong{MySQL} は上記の表にかかれている順にオプションファイルを読みます。 もし複数オプションファイルがあった場合、後から読まれた設定が有効になります。 全てのオプションはコマンドラインの引数に上書きされます。 いくつかのオプションは環境変数に定義できます。 オプションファイルとコマンドラインの引数は環境変数を上書きします。 以下のプログラムはオプションファイルをサポートします:@code{mysql}, @code{mysqladmin}, @code{mysqld}, @code{mysqldump}, @code{mysqlimport}, @code{myisamchk} and @code{myisampack}. オプションファイルには、プログラムがサポートしているコマンドラインの long オプション(例えば、@code{-u} ではなくて @code{--user} の方)を書くことができます。 プログラムを @code{--help} で起動すれば、設定可能な変数名が得られます。 オプションファイルの書式は以下です: @table @code @item #comment コメントは @samp{#} か @samp{;} 文字で始めます。空の行は無視します。 @item [group] グループ宣言。 @code{group} はオプションを定義するプログラムかグループの名前です。 この宣言の後、@code{オプション} か @code{set-variable} 行で、このグループにオプションを与えます。 このセクションの範囲は、他のグループ宣言の行が来るか、ファイルの最後に来るまでです。 @item option これはコマンドラインの @code{--option} と等価です。 @item option=value これはコマンドラインの @code{--option=value} と等価です。 @item set-variable = variable=value これはコマンドラインの @code{--set-variable variable=value} と等価です。 これは @code{mysqld} 変数で使用される形式です。 @end table @code{client} グループは、全ての @strong{MySQL} クライアント(@code{mysqld}は除)に対してオプションを定義します。 これはサーバーに接続する際に使用するパスワードを指定できるグループです。 (この場合、オプションファイルは自分だけが読み書きできるようにしてください) オプションや値の善後にある全てのブランク文字は自動で取り除かれます。 値として、@samp{\b},@samp{\t}, @samp{\n}, @samp{\r}, @samp{\\} and @samp{\s} のエスケープシーケンスが使用できます。 (@samp{\s} == blank). オプションファイル例: @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 ユーザーオプションファイル例: @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 もしソース配布を持っているなら、 @file{my-xxxx.cnf} という名前のサンプルファイルを @file{support-files} ディレクトリに見ることができます。 もしバイナリ配布を使用しているなら、 @file{DIR/share/mysql} ディレクトリを探してください (ここで @code{DIR} は @strong{MySQL} がインストールされたディレクトリのパス名で、普通は @file{/usr/local/mysql})。 この @file{my-xxxx.cnf} ファイルを自分のディレクトリに @file{.my.cnf} という名前でコピーして使用できます。 @strong{MySQL} プログラムにオプションファイルを読ませないようにするには、 コマンドラインの一番最初に @code{--no-defaults} を書きます。 これはオプションの最初でないと有効になりません! どのオプションが定義されているか確かめるには、@code{--print-defaults} を最初のオプションに指定します。 特定のコンフィグファイルを強制的に使用したい場合、オプション @code{--defaults-file=デフォルトファイルのフルパス} を使用できます。これ を行なう場合、指定したファイルだけが読まれます。 開発者向け情報: オプションファイルの操作は全てのオプションをコマンドラインの引数より先に処理するように簡単に埋め込まれています。 これはオプションを最後に処理するプログラムを複数立ちあげる場合に都合よく動きます。 もしオプションファイルを読み込む機能のない古いプログラムを使用しているなら、 たった二行だけ注意して書けばいいだけです。 この動作については @strong{MySQL} クライアントプログラムのコードを参考にしてください。 @node Upgrade, , Post-installation, Installing @section @strong{MySQL} のアップグレード/ダウングレード時に特別に行なうことが何かあるか? @strong{MySQL} 形式とデータファイルは、@strong{MySQL} が同じベースバージョ ンである限り、同じアーキテクチャ上の異なるバージョン間でいつでも移動でき ます。現在のベースバージョンは 3 です。@strong{MySQL} の実行時に 文字セットが変更された場合(これはソート順も変更します)、全てのテーブル に @code{myisamchk -r -q} を行なう必要があります。そうしなければ、インデッ クスが正しい順になりません。 もしあなたが神経質だったり新しいバージョンを恐れている場合、いつでもあな たの古い @code{mysqld} を @code{mysqld}-'old-version-number' のような何 かにリネームできます。もし新しい @code{mysqld} が予期せぬ何かを行った場 合、単純にそれをシャットダウンし、古い @code{mysqld} を再起動することが できます! アップグレード時には、もちろん、古いデータベースをバックアップもしておく べきです。時々は少し神経質になるのは良いことです! アップグレード後、再コンパイルされたクライアントプログラムで、 @code{Commands out sync} や予期せぬコアダンプのような問題が起きる場合、 おそらく、プログラムのコンパイル時に古いヘッダやライブラリファイルを使用 したのでしょう。この場合、@file{mysql.h} ファイルと @file{libmysql.a} ラ イブラリが、新しい @strong{MySQL} 配布からのものであるかどうかを確かめる ために、日付をチェックすべきです。もし違っていれば、プログラムを再コンパ イルしてください! もし新しい @code{mysqld} サーバーが起動できないとか、パスワード無しで 接続できないとか、いくつかの問題が発生した場合、以前のインストールでできた 古い @file{my.cnf} ファイルがあるかどうかを確認してください! @code{program-name --print-defaults} で確認できます. もしこの出力が プログラムの名称以外の物を返した場合、有効になっている @code{my.cnf} ファイルが あります! 新しいリリースの @strong{MySQL} をインストールした場合に常に @code{Msql-Mysql-modules} を再構築、再インストールすることは いい考えです。すべての @code{DBI} スクリプトが @strong{MySQL} の アップグレード後にコアダンプする兆候に気づいた場合は、特に そうしてください。 @menu * Upgrading-from-3.22:: 3.22 から 3.23 バージョンへのアップグレード * Upgrading-from-3.21:: 3.21 から 3.22 バージョンへのアップグレード * Upgrading-from-3.20:: 3.20 から 3.21 バージョンへのアップグレード * Upgrading-to-arch:: 他のアーキテクチャへのアップグレード @end menu @cindex Compatibility, between MySQL versions @node Upgrading-from-3.22, Upgrading-from-3.21, Upgrade, Upgrade @subsection 3.22 から 3.23 バージョンへのアップグレード @strong{MySQL} 3.23 は新しい @code{MyISAM} 型のテーブルと、古い @code{ISAM} 型の テーブルをサポートします。 3.23 を使用する際、古いテーブル(ISAM) を変換する必要はありません。 デフォルトでは、新しく作られるテーブルが @code{MyISAM} 型になります。 (これは @code{mysqld} を @code{--default-table-type=isam} オプションで 起動することにより、変更できます)。 @code{ISAM} テーブルを @code{MyISAM} に変更するには、 @code{ALTER TABLE} を使用するか、@code{mysql_convert_table_format} perl スクリプトを使用します。 3.22 と 3.21 のクライアントは問題なく 3.23 サーバーで動作します。 以下に、3.23 にアップグレードするときに、注目する必要があるものを列挙します: @itemize @bullet @item @code{IF} のデフォルトの戻り値型は現在両方の引数に依存します。最初の引数だけではありません。 @item @code{AUTO_INCREMENT} 負数では働きません。 @item @code{INNER} と @code{DELAYED} は、予約語になりました。 @item @code{FLOAT(X)} は本当の浮動小数点型になりました。桁数固定の値ではありません。 @item @code{DECIMAL(length,dec)} 宣言時、length 引数はもはや符号や小数点の場所を含みません。 @item @code{TIME} 文字列は以下のフォーマットのいずれかでなければなりません: @code{[[[DAYS] [H]H:]MM:]SS[.fraction]} か @code{[[[[[H]H]H]H]MM]SS[.fraction]} @item @code{LIKE} は、同一文字の比較 @code{'='} ルールを使用して、 比較を行うようになりました。 もし古い比較方法にするならば、 @strong{MySQL} を @code{CXXFLAGS=-DLIKE_CMP_TOUPPER} フラグでコンパイルします。 @item @code{REGEXP} は、通常の文字列(非 binary) では、ケース非依存になりました。 @item @code{MyISAM} テーブル(@code{.MYI}) の検査・修復には、@code{CHECK TABLE} を使用するか、@code{myisamchk} を使用します。 @code{isamchk} は ISAM(@code{.ISM}) テーブル用に使用します。. @item もし、3.22 と 3.23 の間で互換性を持たせて @code{mysqldump} を行いたいならば、 @code{--opt} や @code{--full} オプションを @code{mysqldump} に指定してはいけません。 @item 全ての @code{DATE_FORMAT()} をチェックしてください。 各フォーマット文字の前には @samp{%} 文字が必要になりました。 (@strong{MySQL} 3.22 バージョン以降ではこの文法が許されます。) @item @code{mysql_fetch_fields_direct} が関数になり (今まではマクロだったのが)、 @code{MYSQL_FIELD} 型ではなく @code{MYSQL_FIELD} ポインター型を返します。 @item @code{mysql_num_fields()} は、 @code{MYSQL*} object をもはや使うことができません。 (これは今、 @code{MYSQL_RES*} を引数に取る関数になりました)。 代わりに、 @code{mysql_field_count()} を使用すべきです。 @item @code{MySQL} 3.22 では, @code{SELECT DISTINCT ...} の出力は ほとんどいつもソートされました。 3.23 では, ソートを行った結果を得るには @code{GROUP BY} か @code{ORDER BY} を使用しなくてはなりません。 @item もし、一致するレコードが無かった場合、@code{SUM()} は 0 の代わりに @code{NULL} を返すようになりました。 これは ANSI SQL 準拠です。 @item 新しい予約語: @code{CASE, THEN, WHEN, ELSE and END} @item @code{NULL} 値での @code{AND} や @code{OR} は現在 0 ではなく @code{NULL} を返します。 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 3.21 から 3.22 バージョンへのアップグレード 3.21 と 3.22 の間には互換性に影響する変更はありません。@code{DATE} 型を 伴って生成された新しいテーブルは、日付の格納に新しい方法を使用することだ けが pitfall です。これらの新しいフィールドに古いバージョンの @code{mysqld} からアクセスすることはできません。 @code{MySQL 3.22} インストール後、新しいサーバを開始して、 @code{mysql_fix_privilege_tables} スクリプトを実行すべきです。これは @code{GRANT} コマンドを使用するために必要な権限を追加します。これを忘れ ると、@code{ALTER TABLE} や @code{CREATE/DROP INDEX} を使用しようとした 時に @code{Access denied} になります。@strong{MySQL} root ユーザがパスワー ドを要求する場合、@code{mysql_fix_privilege_tables} への引数としてそれを 与えてください。 C API インタフェース @code{mysql_real_connect()} は変更されました。この 関数を呼び出す古いクライアントプログラムを持っている場合は、新しい @code{db} 引数に @code{0} を置く(またはより速い接続のために @code{db} 要 素を送るようにクライアントをコーディングしなおす)必要があります。 @code{mysql_real_connect()} を呼び出す前に @code{mysql_init()} を呼ばなくてはなりません! この変更は、@code{MYSQL} の構造体にオプションを保存するための 新しい @code{mysql_options()} 関数を有効にします。 @code{mysqld} 変数 @code{key_buffer} は @code{key_buffer_size} に名前が 変わりました。しかし、まだ前の名前もスターとアップファイル中で使用できま す。 @node Upgrading-from-3.20, Upgrading-to-arch, Upgrading-from-3.21, Upgrade @subsection 3.20 から 3.21 バージョンへのアップグレード 既に 3.20.28 より前のバージョンが稼働していて、3.21.x に変更したい場合は、 次を行なう必要があります: @code{safe_mysqld --old-protocol} で @code{mysqld} 3.21 サーバを起動すれ ば、3.20 配布からのクライアントでそれを使用できます。この場合、新しいク ライアント関数 @code{mysql_errno()} はサーバのエラーは何も返さず、 @code{CR_UNKNOWN_ERROR} だけを返します (ただしクライアントのエラーについ ては働きます)。そして サーバは古い password() チェックを新しいものの代わ りに使用します。 @code{mysqld} に @code{--old-protocol} オプションを@emph{使わない}場合、 次の変更をする必要があります: @itemize @bullet @item 全てのクライアントコードは再コンパイルする必要があります。ODBC を使用し ている場合は新しい @strong{MyODBC} 2.x ドライバを入手する必要があります。 @item @code{mysql.user} テーブル内の @code{password} フィールドを @code{CHAR(16)} に変換するために、スクリプト @code{scripts/add_long_password} を実行する必要があります。 @item 全てのパスワードは @code{mysql.user} テーブル内に再配置する必要がありま す(31ビットパスワードの代わりに、62ビットを得るために)。 @item テーブル形式は変更されていないので、どのテーブルも変換する必要はありませ ん。 @end itemize @strong{MySQL} 3.20.28 とそれ以降は、クライアントに影響を及ぼさずに、新 しい @code{user} テーブル形式を処理することができます。3.20.28 より前の @strong{MySQL} バージョンを持っている場合は、@code{user} テーブルを変換 すると、パスワードはその上ではもう働きません。安全のため、最初に少なくと も 3.20.28 にアップグレードし、それから 3.21.x にアップグレードすべきで す。 @cindex Protocol mismatch 新しいクライアントコードは 3.20.x @code{mysqld} サーバで動作するので、も し 3.21.x で問題があった場合は、クライアントをもう一度再コンパイルする必 要はなく、古い 3.20.x サーバを使用することができます。 @code{mysqld} に @code{--old-protocol} オプションを使用しない場合、古い クライアントはエラーメッセージを発します: @example ERROR: Protocol mismatch. Server Version = 10 Client Version = 9 @end example 新しい Perl インタフェース @code{DBI}/@code{DBD} は古い @code{mysqlperl} インタフェースもサポートします。@code{mysqlperl} を使用する場合に行う必 要のある変更は、@code{connect()} 関数の引数の変更だけです。新しい引数は: @code{host}, @code{database}, @code{user}, @code{password} (@code{user} と @code{password} 引数の順番が変更されました)。 @xref{Perl DBI Class, , Perl @code{DBI} Class}. 次の変更は古いアプリケーションでのクエリに影響します: @itemize @bullet @item @code{HAVING} は現在 @code{ORDER BY} 節より前になければいけません。 @item @code{LOCATE()} へのパラメータは交換されました。 @item 新しい予約語がいくつかあります。最も注意すべきは @code{DATE}, @code{TIME} そして @code{TIMESTAMP} です。 @end itemize @node Upgrading-to-arch, , Upgrading-from-3.20, Upgrade @subsection 他のアーキテクチャへのアップグレード もし、@strong{MySQL} 3.23 を使用しているならば、 違うアーキテクチャのマシンに、@code{.frm}, @code{.MYI},@code{.MYD} ファイルを コピーすることが出来ます。 ただし、両者間で、同じ浮動小数点のフォーマットをサポートしている場合に限ります。 (@strong{MySQL} takes care of any byte swapping issues). 現在 @strong{MySQL} データとインデックスファイル (@code{ISAM} @file{*.ISD} と @file{*.ISM} ファイル) はアーキテクチャ依存で、いくつかのケースでは OS 依存です。アプリケーションを、現在のマシンとは異なるアーキテクチャ/OS を 持つ他のマシンに移したい場合は、単純にファイルを他のマシンにコピーするこ とでデータベースを移行しようとすべきではありません。@code{mysqldump} を 使用すべきです。 デフォルトでは @code{mysqldump} は、完全な SQL ステートメントファイルを 生成します。それからそのファイルを他のマシンへ転送し、@code{mysql} クラ イアントへの入力として与えることができます。 有効なオプションが何かを見るためには、@code{mysqldump --help} を試してく ださい。データを @strong{MySQL} のより新しいバージョンに移す場合、速くコ ンパクトなダンプを得るために、より新しいバージョンで @code{mysqldump --opt} を使用すべきです。 2つのマシン間でデータベースを移動する最も簡単な (しかし最も速くはない) 方法は、データベースが置かれているマシン上で次のコマンドを実行することで す: @example shell> mysqladmin -h 'other hostname' create db_name shell> mysqldump --opt db_name \ | mysql -h 'other hostname' db_name @end example 遅いネットワーク上でリモートマシンからデータベースをコピーしたい場合は、 次を使用できます: @example shell> mysqladmin create db_name shell> mysqldump -h 'other hostname' --opt --compress db_name \ | mysql db_name @end example ファイル内の結果を格納することもできます (この例では圧縮されています): @example shell> mysqldump --quick db_name | gzip > db_name.contents.gz @end example データベースの中身を含んでいるファイルを、目的のマシンに転送して、次のコ マンドを実行してください: @example shell> mysqladmin create db_name shell> gunzip < db_name.contents.gz | mysql db_name @end example @cindex @code{mysqldump} @cindex @code{mysqlimport} データベース転送を実行するために、@code{mysqldump} と @code{mysqlimport} も使用できます。大きなテーブルでは、これは単純な @code{mysqldump} の使用 よりもとても速いです。次に示すコマンドでは、@code{DUMPDIR} は @code{mysqldump} からの出力を格納するために使用するディレクトリの完全な パス名を表わしています。 まず、出力ファイルのためのディレクトリを作成して、データベースをダンプし ます: @example shell> mkdir DUMPDIR shell> mysqldump --tab=DUMPDIR db_name @end example それから、@code{DUMPDIR} ディレクトリ内のファイルを目的のマシン上の対応 するディレクトリに転送し、@strong{MySQL} にファイルをロードします: @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 @code{mysql} データベースのコピーも忘れないでください。それは承認テーブ ル (@code{user}, @code{db}, @code{host}) が格納されるためです。 @code{mysql} データベースをその場所に置くまで、新しいマシン上では @strong{MySQL} @code{root} ユーザとしてコマンドを実行する必要があります。 新しいマシン上へ @code{mysql} データベースを導入した後、サーバが承認テー ブル情報を再ロードするために、@code{mysqladmin flush-privileges} を実行してください。 @cindex Compatibility, with ANSI SQL @node Compatibility, Privilege system, Installing, Top @chapter @strong{MySQL} はどのように標準互換か? @menu * Extensions to ANSI:: @strong{MySQL} の ANSI SQL92 に対する拡張 * Ansi mode:: Runnning @strong{MySQL} in ANSI mode * Differences from ANSI:: @strong{MySQL} differences compared to ANSI SQL92 * Missing functions:: @strong{MySQL} に無い機能 * Standards:: @strong{MySQL} が準拠する標準 * Commit-rollback:: @code{COMMIT}/@code{ROLLBACK} なしでうまくやる方法 @end menu @node Extensions to ANSI, Ansi mode, Compatibility, Compatibility @section @strong{MySQL} の ANSI SQL92 に対する拡張 @strong{MySQL} は、他の SQL データベース内に見られないであろう、いくつか の拡張を含んでいます。あなたがそれらを使用する場合、コードは他の SQL サー バに移行できなくなるので注意してください。いくつかのケースでは、形式 @code{/*! ... */} のコメントを使用することで、@strong{MySQL} 拡張を含む 移行可能コードを書くことができます。この場合、@strong{MySQL} はコメント 内のコードを実行しますが、ほかのSQLサーバーはこれを無視します。例えば: @example SELECT /*! STRAIGHT_JOIN */ col_name FROM table1,table2 WHERE ... @end example @code{'!'} の後ろにバージョン番号を追加すると、文法は @strong{MySQL} バー ジョンが使用されるバージョン番号と等しいか大きい場合にのみ実行されます: @example CREATE /*!32302 TEMPORARY */ TABLE (a int); @end example 上記は 3.23.02 かそれ以上の場合という意味で、そのとき @strong{MySQL} は @code{TEMPORARY} キーワードを使用します。 @strong{MySQL} 拡張を以下に示します: @itemize @bullet @item フィールド型 @code{MEDIUMINT}, @code{SET}, @code{ENUM} そして様々な @code{BLOB} と @code{TEXT} 型。 @item フィールド属性 @code{AUTO_INCREMENT}, @code{BINARY}, @code{NULL}, @code{UNSIGNED} そして @code{ZEROFILL}。 @item 全ての文字列比較はデフォルトではケース非依存で、現在の文字セット(デフォ ルトでは ISO-8859-1 Latin1)に従ったソート順です。これを好まない場合は、 @code{BINARY} 属性であなたのフィールドを宣言すべきです。これは、@strong{MySQL} サーバホストの上で使用される ASCII 順に従って比較が実行されるようになり ます。 @item @strong{MySQL} はデータベースを@strong{MySQL} データディレクトリ 以下のディレクトリに、 テーブルをデータベースディレクトリ以下のファイル名に マップします。これは2つの関係を持ちます: @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 ケース依存のファイル名を持つ OS (UNIXのような)上の @strong{MySQL} では、 データベース名とテーブル名はケース依存です。 テーブル名の記憶に問題がある場合、常にデータベースとテーブルを 小文字で生成するという具合に、一貫して同じように命名するようにします。 @item テーブルのバックアップ, リネーム, 移動, 削除, コピーに標準システムコマン ドを使用できます。例えば、テーブルをリネームするには、テーブルに対応する @file{.MYD}, @file{.MYI}, @file{.frm} ファイルをリネームしてください。 @end itemize @item SQL 文では、 @code{db_name.tbl_name} 構文を使用して違うデータベースのテーブルにアクセスできます。 いくつかのSQLサーバーは同様の機能を提供しますが、これを @code{User space} でコールします。 @strong{MySQL} は以下のようなテーブルスペースをサポートしません: @code{create table ralph.my_table...IN my_tablespace}. @item 数値フィールド上での @code{LIKE} が許されます。 @item @code{SELECT} ステートメント内の @code{INTO OUTFILE} と @code{STRAIGHT_JOIN} の使用。@xref{SELECT, , @code{SELECT}}. @item どのようにテーブルが結合されるかの詳細を得るための @code{EXPLAIN SELECT}。 @item インデックス名、フィールドの一部のインデックス、そして @code{CREATE TABLE} ス テートメント内の @code{INDEX} または @code{KEY} の使用。 @xref{CREATE TABLE, , @code{CREATE TABLE}}. @item @code{CREATE TABLE} での @code{TEMPORARY} か @code{IF NOT EXISTS} の使用。 @item 'list' 要素が一つ以上の @code{COUNT(DISTINCT list)} の使用。 @item @code{ALTER TABLE} ステートメント内の @code{CHANGE col_name}, @code{DROP col_name}, @code{DROP INDEX} の使用。 @xref{ALTER TABLE, ,@code{ALTER TABLE}}. @item @code{ALTER TABLE} ステートメント内の @code{IGNORE} の使用。 @item @code{ALTER TABLE} ステートメント内の複数の @code{ADD}, @code{ALTER}, @code{DROP}, @code{CHANGE} 節の使用。 @item キーワード @code{IF EXISTS} 付きの @code{DROP TABLE} の使用。 @item 複数のテーブルを一回の @code{DROP TABLE} で破棄できる @item @code{DELETE} ステートメントの @code{LIMIT} 節。 @item @code{INSERT} と @code{REPLACE} ステートメントの @code{DELAYED} 節。 @item @code{INSERT}, @code{REPLACE}, @code{DELETE}, @code{UPDATE} ステートメント の @code{LOW_PRIORITY} 節。 @cindex Oracle compatibility @cindex Compatibility, with Oracle @item @code{LOAD DATA INFILE} の使用。多くの場合、この構文は ORACLE の @code{LOAD DATA INFILE} と互換があります。@xref{LOAD DATA, , @code{LOAD DATA}}. @item @code{OPTIMIZE TABLE} ステートメント。 @xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}. @item @code{SHOW} ステートメント。 @xref{SHOW, , @code{SHOW}}. @item @samp{'} だけでなく @samp{"} または @samp{'} によって文字列を括ることが 可能。 @item エスケープ @samp{\} 文字の使用。 @item @code{SET OPTION} ステートメント。@xref{SET OPTION, , @code{SET OPTION}}. @item @code{GROUP BY} 部に全てのフィールドを持つ必要はありません。 This gives better performance for some very specific, but quite normal queries. @xref{Group by functions}. @item 異なる SQL 環境から来たユーザに対し、より簡単にするため、@strong{MySQL} は多くの関数に別名をサポートしています。例えば、全ての文字列関数は ANSI SQL と ODBC 構文の両方をサポートします。 @item @strong{MySQL} は @code{||} と @code{&&} 演算子を、C プログラミング言語 のように、論理和と論理積を意味すると理解します。@strong{MySQL} では @code{||} と @code{OR}、@code{&&} と @code{AND} は同義語です。この良い構 文のため、@strong{MySQL} は ANSI SQL の文字列結合演算子 @code{||} をサポー トしません。@code{CONCAT()} を代わりに使用してください。@code{CONCAT()} は任意の数の引数を使用できるので、@code{||} 演算子の使用を @strong{MySQL} に変換するのは簡単です。 @item @code{CREATE DATABASE} または @code{DROP DATABASE}. @xref{CREATE DATABASE, , @code{CREATE DATABASE}}. @cindex PostgreSQL compatibility @cindex Compatibility, with PostgreSQL @item @code{MOD()} と同義の @code{%}。 @code{N % M} は @code{MOD(N,M)} と等価です。 @code{%} は C プログラマーと PostgreSQL との互換のためにサポートされます。 @item フィールドステートメントでの @code{=}, @code{<>}, @code{<=} ,@code{<}, @code{>=}, @code{>}, @code{<<}, @code{>>}, @code{<=>}, @code{AND}, @code{OR}, @code{LIKE}。 例えば: @example mysql> SELECT col1=1 AND col2=2 FROM tbl_name; @end example @item @code{LAST_INSERT_ID()} 関数。 @xref{mysql_insert_id, , @code{mysql_insert_id()}}. @item @code{REGEXP} または @code{NOT REGEXP}。 @item 1つまたは2以上の引数での @code{CONCAT()} または @code{CHAR()}。 @strong{MySQL} では、これらの関数は任意の数の引数を取ることができます。 @item @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()}, @code{WEEKDAY()} 関数。 @item サブ文字列の整形のために @code{TRIM()} を使用できます。ANSI SQL は一文字 の削除だけをサポートします。 @item @code{GROUP BY} 関数 @code{STD()}, @code{BIT_OR()} そして @code{BIT_AND()}。 @item @code{DELETE} + @code{INSERT} の代わりの @code{REPLACE} の使用。 @xref{REPLACE, , @code{REPLACE}}. @item @code{FLUSH flush_option} 構文。 @item @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 ANSI モードでの MySQL の実行 @code{--ansi} オプションつきで mysqld を開始すると、その @strong{MySQL} の 振舞いが変わります。 @itemize @bullet @item @code{||} は @code{OR} ではなく文字列結合です。 @item 関数名と '(' の間に任意の数のスペースを置くことができます。これはすべての 関数を予約語にします。 @item @code{"} は(@strong{MySQL} @code{`} 引用文字に似た)識別子引用文字になり、 文字列引用文字ではありません。 @item @code{REAL} は @code{DOUBLE} の同義語ではなく @code{FLOAT} の同義語になり ます。 @end itemize @node Differences from ANSI, Missing functions, Ansi mode, Compatibility @section @strong{MySQL} と ANSI SQL92 との違い 我々は @strong{MySQL} を ANSI SQL 標準と ODBC SQL 標準に従うように試みてい ますが、いくつかのケースで @strong{MySQL} は何か違いがあります: @itemize @bullet @item @code{--} は空白が続く場合だけコメントになります。@xref{Missing comments}。 @item @code{VARCHAR} フィールドでは、値が格納される時に末尾の空白が削除されます。 @xref{Bugs}。 @item いくつかのケースで、@code{CHAR} フィールドは黙って @code{VARCHAR} フィール ドに変更されます。@xref{Silent column changes}。 @item テーブルを削除する時に、テーブルについての権限は自動的には破棄されません。 テーブルについての権限を破棄するには、明示的に @code{REVOKE} を発行する必 要があります。@xref{GRANT, , @code{GRANT}}. @item @code{NULL AND FALSE} は @code{FALSE} ではなく @code{NULL} と評価されます。 このケースで、多くの余計な条件を評価する必要があることは良いことではないと、 我々は考えているからです。 @end itemize @node Missing functions, Standards, Differences from ANSI, Compatibility @section @strong{MySQL} に無い機能 次の機能が @strong{MySQL} の現在のバージョンにはありません。新しい拡張の 優先度については、次を参考にしてください @uref{http://www.mysql.com/Manual_chapter/manual_Todo.html, the @strong{MySQL} TODO list}。これはこのマニュアル中の TODO リストの最新バー ジョンです。@xref{TODO}。 @menu * Missing Sub-selects:: Sub-selects * Missing SELECT INTO TABLE:: @code{SELECT INTO TABLE} * Missing Transactions:: トランザクション * Missing Triggers:: トリガ * Missing Foreign Keys:: Foreign Keys * Missing Views:: ビュー * Missing comments:: コメント開始としての @samp{--} @end menu @node Missing Sub-selects, Missing SELECT INTO TABLE, Missing functions, Missing functions @subsection Sub-selects 次は @strong{MySQL} ではまだ働きません: @example SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2); @end example しかし多くの場合、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 さらに複雑なサブクエリでは、サブクエリを保持するために一時テーブルを作成で きます。しかし、この方法でも動かない場合があります。このケースには、 @code{DELETE} ステートメントでもっとも頻繁に遭遇します。@code{DELETE} ステー トメントでは、標準 SQL では(sub select の中を除いて)join をサポートして いません。サブクエリが @strong{MySQL} にサポートされるまで、この状況には2 つの選択肢があります。 最初の選択肢は、手続きプログラミング言語(Perl や PHP のような)を使用して、 @code{SELECT} クエリを発行して削除されるレコードのプライマリキーを獲得し、 それから @code{DELETE} ステートメント(@code{DELETE FROM ... WHERE ... IN (key1, key2, ...)})を構築するためにその値を使用することです。 二番目の選択肢は、対話型 SQL を使用し、@code{DELETE} ステートメントのセッ トを(標準 @code{||} オペレータの代わりに)@strong{MySQL} 拡張 @code{CONCAT()} を使用して、自動的に組み立てることです。例えば: @example SELECT CONCAT('DELETE FROM tab1 WHERE pkid = ', tab1.pkid, ';') FROM tab1, tab2 WHERE tab1.col1 = tab2.col2; @end example このクエリをスクリプトファイル中に置き、入力を @code{mysql} コマンドライン インタプリタに切替え、その出力を二番目のインタプリタインスタンスにパイプし ます: @example prompt> mysql --skip-column-names mydb < myscript.sql | mysql mydb @end example @strong{MySQL} は @code{INSERT ... SELECT ...} と @code{REPLACE ... SELECT ...} だけをサポートします。独立した sub-selects はおそらく 3.24.0 で有効になります。しかし今は他の文脈内で関数 @code{IN()} を使用できます。 @node Missing SELECT INTO TABLE, Missing Transactions, Missing Sub-selects, Missing functions @subsection @code{SELECT INTO TABLE} @strong{MySQL} はまだ Oracle SQL extension: @code{SELECT ... INTO TABLE ...} をサポートしません。 @strong{MySQL} は @code{INSERT INTO ... SELECT ...} をサポートします。 これは基本的に同じことです。 代わりに、@code{INSERT INTO ... SELECT ...} や @code{CREATE TABLE ... SELECT} が使用できます。 @xref{INSERT, , @code{INSERT}}. @node Missing Transactions, Missing Triggers, Missing SELECT INTO TABLE, Missing functions @subsection トランザクション @strong{MySQL} は現在トランザクションをサポートするため、次の議論は非トラ ンザクション安全テーブル型を使用する場合にだけ有効です。@xref{COMMIT}。 ``なぜ @strong{MySQL} はトランザクションのデータベースでないのか?'' とか ``なぜ @strong{MySQL} はトランザクションをサポートしないのか?'' といった質問がしばしばなされます。 @strong{MySQL} は、データの取り扱いに対し、他のパラダイム、 ``アトミック・オペレーション''をサポートする事を意図して決定しました。 アトミック・オペレーションが同等かあるいはより良いパフォーマンスを 提供するというのが、我々の経験、および考えです。 それでも、我々はトランザクション的データベースパラダイムとプランを評価し、 理解しています。次の数リリースのうちに、テーブル単位を基本に、トランザクショ ン安全テーブルを導入します。 その時我々は、ユーザーが、 スピード重視でアトミック・オペレーションを使用するのか、あるいは アプリケーションでトランザクションの機能を使うのか、 を、選択できるようにしようと考えています。 厳密に integrity 維持するには @strong{MySQL} の機能をどのように使用するの でしょう? そして、トランザクション的パラダイムでこれらの機能をどのように 比較するのでしょう? 最初に、トランザクションのパラダイムでは、 もし、あなたのアプリケーションが 基本となる部分で ``commit'' の代わりに ``rollback'' の呼び出しに依存しているなら、 トランザクションはより便利になるでしょう。 おまけに、トランザクションは完了できなかった更新や不整合を起こした データが、確実にデータベースに登録されないようにできます。 そのサーバーには、自動的な rollback をする機会が与えられ、 あなたのデータは守られるでしょう。 @strong{MySQL} はほとんどの場合、更新前の簡単なチェックを含ませることができたり、 あるいはデータベースの矛盾を検査して自動修復や警告の表示を行ったりする 簡単なスクリプトを実行することができるような、 ポテンシャルをあなたに提供します。 @strong{MySQL} ログの使用や外部へのログの追加を行ったりする事で、 通常、データに不整合のおきたテーブルを完全に修復できることに注意してください。 さらに、``fatal'' transactional updates はアトミックで書き換えることができます。 実際、トランザクションが解決する全ての integrity problems は @code{LOCK TABLES} や atomic updates で置き換えることが出来、 さらにこれは、トランザクションのデータベースにある一般的な問題である、 データベースからの自動的な中断を得ること無しに、可能なはずです。 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. もしサーバーがダウンすればトランザクションでも全てを失うことを阻止できません。 この場合、トランザクションのシステムでもデータを全て失うでしょう。 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. @strong{MySQL} を安全にするには、バックアップを取ることと、 更新ログを有効にすることだけです。 これで、あなたが他のトランザクションを持つデータベースで行っているような いかなる場面での修復が可能です。 もちろん、バックアップをとることは、どのデータベースを使用しているかに 関わらず、常に良いことです。 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 READ lock until they relaease their read locks. With INSERT DELAYED you can queue insert into a local queue, until the locks are released, without having to have the client to 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. 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 ストアドプロシジャとトリガ ストアドプロシジャは、サーバ内でコンパイルでき格納できる SQL コマンドの セットです。一度これが行なわれると、クライアントはクエリ全体の再発行を保 持する必要がなく、ストアドプロシジャを参照できます。これはさらにより速い速度を提 供します。クエリは一度だけ解釈され、より少ないデータがサーバとクライアン ト間で送信されるからです。サーバ内に関数ライブラリを持つことにより概念レ ベルを上げることもできます。 トリガは特別なイベントが発生した時に呼び出されるストアドプロシジャです。 例えば、トランザクションテーブルからレコードが削除される度にトリガされ、 トランザクションが削除された時に自動的に対応する顧客を顧客テーブルから削 除するというストアドプロシジャをインストールすることができます。 計画されている言語の更新はストアドプロシジャを処理できるようになりますが、 トリガは除きます。トリガは通常全てを、それらを必要としないクエリでさえも 遅くします。 @strong{MySQL} がストアドプロシジャを得る時を知るには、@ref{TODO} を参照 してください。 @node Missing Foreign Keys, Missing Views, Missing Triggers, Missing functions @subsection 外部キー 注意: SQL の外部キーはテーブルを結合するためには使用できませんが、指示の 完全性の検査のために良く使用されます。@code{SELECT} ステートメントで複数 テーブルから結果を得たい場合、テーブルの結合によってこれを行ないます! @example SELECT * from table1,table2 where table1.id = table2.id; @end example @xref{JOIN, , @code{JOIN}}. @xref{example-Foreign keys}. @strong{MySQL} 内での @code{FOREIGN KEY} 構文は、他の SQL ベンダの @code{CREATE TABLE} コマンドとの互換のためだけに存在します; これは何も行 ないません。@code{ON DELETE ...} がない @code{FOREIGN KEY} 構文は、目的 の作成のために主に使われます。いくつかの ODBC アプリケーションは、自動的 に @code{WHERE} 節を提供するために、これを使用しますが、しかしこれは通常 簡単に無効にできます。@code{FOREIGN KEY} は時々強制チェックとして使用さ れます。しかし、テーブルに正しい順で行が挿入される場合、このチェックは実 際には不要です。いくつかのアプリケーションがそれが存在することを要求する ため @strong{MySQL} はこれらの節だけをサポートします(それが動作するかど うかに関わらず!)。 @strong{MySQL} では、外部キーを持つテーブルからレコードを削除する時に適 切な @code{DELETE} ステートメントをアプリケーションに追加することで、 @code{ON DELETE ...} が実装されていないという問題を回避できます。実際に は、これは速く(いくつかの場合はより速く)そして外部キーの使用よりもさらに 可搬性があります。 近い将来、少なくとも情報が保存され、そして @code{mysqldump} と ODBC によっ て取り出されるように、我々は @code{FOREIGN KEY} 実装を拡張します。 @menu * Broken Foreign KEY:: 外部キーを使用しない理由 @end menu @node Broken Foreign KEY, , Missing Foreign Keys, Missing Foreign Keys @subsubsection 外部キーを使用しない理由 我々がどこから始めるのかわからない @code{FOREIGN KEY} には多くの問題があ ります: @itemize @bullet @item 外部キーは人生をとても複雑にします。外部キー定義はデータベースに格納しな ければならず、それの実装は移動、コピー、削除できるファイルを使用するとい う ``良いアプローチ'' 全てを破棄するからです。 @item @code{INSERT} と @code{UPDATE} ステートメントへの速度の影響はものすごく、 そしてこの場合、ほとんど全ての @code{FOREIGN KEY} チェックは役に立ちませ ん。通常は、正しいテーブルに正しい順でレコードを挿入するためです。 @item 一つのテーブルの更新時にもっと多くのテーブル上でロックを保持する必要もあ ります。副作用がデータベース全体を通して発生するからです。まず一つのテー ブルからレコードを削除して、それから他のテーブルからそれらを削除するほう がとても速いです。 @item テーブルから完全な削除を行なってから全てのレコードを(新しいソースやバッ クアップから)リストアすることによって、テーブルを復元することはもうでき ません。 @item 外部キーを持つ場合、テーブルのダンプとリストアは特定の順に行なわないとで きません。 @item 一回の create ステートメントで各テーブルを再生成することをテーブルにでき なくするような ``許された'' 巡回定義を行なうことはとても簡単です。その定 義が動作して使用できたとしてもです。 @end itemize 外部キーの良い面は、ODBC と他のいくつかのクライアントプログラムに、どの ようにテーブルが接続されるかを見る機能を与え、これを使用して接続図を示し、 生成アプリケーションの手助けをすることだけです。 @strong{MySQL} は間もなく、クライアントがどのようにオリジナル接続が作成 されたかを問い合わせ、回答を受けられるように @code{FOREIGN KEY} 定義を格 納します。現在の @file{.frm} ファイル形式にはそれを置く場所はありません。 @node Missing Views, Missing comments, Missing Foreign Keys, Missing functions @subsection ビュー @strong{MySQL} はビューをサポートしません。しかしこれは TODO にあります。 @node Missing comments, , Missing Views, Missing functions @subsection コメント開始としての @samp{--} 他のいくつかの SQL データベースは、@samp{--} をコメントの開始のために使 用します。@strong{MySQL} は @samp{#} をコメント開始文字とします。 @code{mysql} コマンドラインツールが @samp{--} で始まる全ての行を削除した としてもです。@strong{MySQL} では C コメントスタイル @code{/* これはコメ ント */} も使用できます。@xref{Comments}。 @strong{MySQL} 3.23.3 以上は @samp{--} をサポートしません; この退化したコメントスタ イルは、次のコードのように @code{!payment!} の payment の値を自動的に挿 入するような何かを使用して自動的に生成される SQL クエリで多くの問題を引 き起こすためです: @example UPDATE tbl_name SET credit=credit-!payment! @end example @code{payment} の値が負の場合に何が起きると思いますか? @code{1--1} は正しい SQL なので、我々は @samp{--} をコメント開始と見なす ことはひどいことだと思います。 しかし @strong{MySQL} 3.23 では次を使用できます: @code{1-- これはコメント} 以降の説明では、3.23 よりも前の @strong{MySQL} バージョンを実行している場 合だけが対象です: テキストファイルの SQL プログラムが @samp{--} コメントを含んでいる場合、 次を使用すべきです: @example shell> replace " --" " #" < text-file-with-funny-comments.sql \ | mysql database @end example 通常の次の代わりに: @example shell> mysql database < text-file-with-funny-comments.sql @end example 次の方法でも、コマンドファイル中の @samp{--} コメントを @samp{#} コメン トに変更できます: @example shell> replace " --" " #" -- text-file-with-funny-comments.sql @end example それらは次のコマンドで戻してください: @example shell> replace " #" " --" -- text-file-with-funny-comments.sql @end example @node Standards, Commit-rollback, Missing functions, Compatibility @section @strong{MySQL} が準拠している標準 Entry level SQL92. ODBC level 0-2. @node Commit-rollback, , Standards, Compatibility @section @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. この型のテーブルは、自動的にテーブルをクリーンアップする拡張スレッドも必要 とし、ディスク使用量はさらに大きくなります。 これは @strong{MySQL} を現在 よりも 2〜4 倍遅くしてしまいます。 今、我々は SQL サーバ言語(ストアドプロシジャのようなもの)の実装にさらに 賛成です。これで、本当に @code{COMMIT}-@code{ROLLBACK} を必要とするのは めったにありません。これはさらに良い性能も与えるでしょう。 トランザクションを必要とするループは、通常は @code{LOCK TABLES} の助けで コード化でき、そして fly 上でレコードの更新時にはカーソルは必要としませ ん。 我々 TcX で本当に必要としているのは、100% 標準のデータベースではなくて、 本当に速いデータベースです。速度低下なしでそれらの機能を実装する方法を見つけた ときには、我々はそれを行なうでしょう。しばらくは行なうべきさらに重要なこ とが多くあります。今の我々の優先度については TODO をチェックしてください。 高レベルのサポートを持つ顧客はこれを変えることができ、再び優先順位づけが 行なわれます。 現在の問題は実際には @code{ROLLBACK} です。@code{ROLLBACK} なしでも @code{LOCK TABLES} で @code{COMMIT} アクションのいくつかの種類を行なうこ とができます。@code{ROLLBACK} をサポートするためには、更新される全ての古 いレコードを格納し、@code{ROLLBACK} が発行された場合に開始位置に全てを戻 すように、@strong{MySQL} を変更しなければなりません。単純な場合には、こ れを行なうには難しくありません(現在の @code{isamlog} をこの目的に使用し ます)。しかし、@code{ALTER/DROP/CREATE TABLE} での @code{ROLLBACK} の実 装を行うことはとても困難です。 @code{ROLLBACK} の使用の回避のために、次の方法を使用することができます: @enumerate @item @code{LOCK TABLES ...} をアクセスしたいテーブルの全てをロックするために 使用します @item 条件のテスト。 @item 全て OK なら更新。 @item @code{UNLOCK TABLES} をロックの解除に使用します @end enumerate これは普通は @code{ROLLBACK} 可能なトランザクションの使用よりも速いです が、常にではありません。この解が処理できない状況は、更新中に誰かがスレッ ドを kill する時だけです。この場合、全てのロックはリリースされますが、い くつかの更新は実行されません。 1回のオペレーション中でレコードを更新する関数も使用できます。次のテクニック によってとても効率的なアプリケーションを得ることができます。 @itemize @bullet @item フィールドを現在の値と比較して変更する @item 実際に変更されたフィールドだけを更新する @end itemize 例えば、いくつかの顧客情報で更新を行なっている時、我々は変更された顧客デー タだけを更新し、変更されていないデータはテストせず、変更されたデータに依 存して変更されたデータがオリジナルの行と比較されます。変更のテストは @code{UPDATE} ステートメント内の @code{WHERE} 節で行われます。レコードが 更新されなかった時は、我々はクライアントにメッセージ: "Some of the data you have changed has been changed by another user" を与え、そしてそれか ら古い行と新しい行をウィンドウ内で表示します。ユーザは顧客レコードのどち らのバージョンを使用すべきかを決定できます。 これは ``column locking'' に似たものを我々に与えますが、実際には十分です。 なぜなら、我々はそれらの現在の値に関連した値を持つフィールドだけを更新するから です。これは、典型的な @code{UPDATE} ステートメントが次のように見えると いうことを意味します: @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 見ての通り、他のクライアントが @code{pay_back} または @code{money_he_owes_us} フィールドの値を変更したとしても、これはとても効率的で 働きます。 @findex mysql_insert_id() @findex LAST_INSERT_ID() 多くの場合、ユーザは @code{ROLLBACK} そして/または @code{LOCK TABLES} が いくつかのテーブルでユニークな識別子を管理することを望みます。これは、 @code{AUTO_INCREMENT} フィールドと SQL @code{LAST_INSERT_ID()} 関数や C API 関 数 @code{mysql_insert_id} の使用によって、さらに効率的に処理できます。 @xref{mysql_insert_id, , @code{mysql_insert_id()}}. @cindex row-level locking TcX では、我々はいつでもそれを回避してコード可能なので、我々は行レベルロッ クを必要としていません。本当に行ロックを必要とするケースもありますが、し かしこれは非常にまれです。行レベルロックを望むのなら、テーブル内でフラグ 項目を使用して、次のようにして行なえます: @example UPDATE tbl_name SET row_flag=1 WHERE id=ID; @end example 行が見つかり、オリジナル行内で @code{row_flag} が既に 1 でない場合、 @strong{MySQL} は影響された行数として 1 を返します。 @strong{MySQL} が上述のクエリを次に変更したと考えることが可能です: @example UPDATE tbl_name SET row_flag=1 WHERE id=ID and row_flag <> 1; @end example @node Privilege system, Reference, Compatibility, Top @chapter @strong{MySQL} のユーザー権限はどのように動くか? @strong{MySQL} は先進的な非標準のセキュリティ/特権システムを持っています。 本章ではどのようにそれが動くかを述べます。 @menu * General security:: General security * Security:: @strong{MySQL} をクラッカーに対して安全にする方法 * What Privileges:: 特権システムの行うこと * User names:: @strong{MySQL} user names and passwords * Connecting:: @strong{MySQL} サーバーに接続 * Password security:: Keeping your password secure * Privileges provided:: @strong{MySQL} が提供する権限 * Privileges:: 特権システムはどのように動くか? * Connection access:: Access control, stage 1: 接続の承認 * Request access:: Access control, stage 2: 要求の承認 * Privilege changes:: When privilege changes take effect * Default privileges:: @strong{MySQL} 権限許可の初期設定 * Adding users:: 新しいユーザ権限を @strong{MySQL} へ追加 * Passwords:: パスワードの設定法 * Access denied:: 何故 @code{Access denied} エラーになるのか @end menu @node General security, Security, Privilege system, Privilege system @section セキュリティ概要 よくあるセキュリティの間違いを避けるために、インターネットに接続されたコン ピュータ上で @strong{MySQL} を使用する誰もが、このセクションを読むべきです。 ``セキュリティ'' の議論では、すべての該当するアタックタイプ (eavesdropping, altering, playback, Denial of Service)に対して、すべてのサー バホスト(単なる @strong{MySQL} サーバではなく)の完全な保護の必要を強調しま す。We do not cover all aspects of availability and fault tolerance here. @strong{MySQL} は、ユーザが実行しようとするすべての接続、クエリ、その他の オペレーションに対して、アクセス制御リスト(ACLs: Access Control Lists)セキュ リティを使用します。@strong{MySQL} クライアントとサーバの間で SSL 暗号化接 続のサポートもいくつかあります。ここで議論されるコンセプトの多くは、 @strong{MySQL} に特有のものではありません; 同じ一般的なアイデアはほとんど すべてのアプリケーションに適用します。 @strong{MySQL} 実行時、可能な限りいつでもこれらのガイドラインに従ってくだ さい: @itemize @bullet @item @strong{MySQL} ACL システムの理解に努めるべきです。 @code{GRANT} と @code{REVOKE} コマンドは @strong{MySQL} へのアクセスを制限するための物です。 必要以上の権限を誰にも与えないでください。 全てのホストに対して、何か出来るような許可を与えてはいけません。 Checklist: @itemize @bullet @item @code{mysql -u root} を行ってみます。 パスワードを尋ねられること無しにサーバへの接続ができる場合、問題があります。 どのユーザでも(root でなくても)、@strong{MySQL} サーバに完全な権限で接続で きます! @code{root} パスワードの設定についての項目に特別な注意を払って @strong{MySQL} インストール説明を見直してください。 @item @code{SHOW GRANTS} を使用し、だれがなんのアクセスを持つかチェックします。 必要ない権限を、@code{REVOKE} コマンドを使用して削除してください。 @end itemize @item いかなる平文パスワードもデータベースに保存しないようにします。 あなたのコンピュータが妥協される時、新入者はパスワードの完全なリストを得て、 それらを使用できます。代わりに @code{MD5()} や他の one-way hashing 関数を 使用してください。 @item 辞書にのっている単語をパスワードに使用してはいけません。 それらを破る プログラムがあるのです。 ``xfish98'' のようなパスワードは悪い例です。 これよりは ``duag98'' の方がよいでしょう。 これは "fish" を打つ際に、 キーを一つずつずらしたものです。 他の方法としては、 "Mhall" 、これは "Mary had a little lamb" という文の頭文字を羅列したものです。 これを知っている物には打ちやすいパスワードですが、知らない者にとっては、 類推することが難しいパスワードです。 @item ファイアーウォールを導入します。This protects from at least 50% of all types of exploits in any software. @strong{MySQL} をファイアーウォールで守られた方に置くか、 DMZ (緩衝地帯, 非武装地帯) に置きます。 Checklist: @itemize @bullet @item インターネットから @code{nmap} のようなツールを使用して、 あなたのマシンのポートをスキャンしてみます。 @strong{MySQL} はデフォルトで 3306 番を使用しています。 このポートには、ほとんどの場合、アクセスできないようにすべきです。 @strong{MySQL} ポートがオープンしているかどうかをチェックする他の簡単な方 法は、いくつかのリモートマシンから @code{telnet server_host 3306} を実行す ることです。ここで @code{server_host} はあなたの @strong{MySQL} サーバのホ スト名です。接続し、いくつかのゴミ文字が得られた場合、ポートはオープンして います。それをオープンしておく正当な理由が本当にない限り、ファイアーウォー ルやルータでクローズすべきです。@code{telnet} がハングする場合、すべて OK です。ポートはブロックされています。 @end itemize @item ユーザーから入力されたデータは信頼しないで下さい。 ユーザーは、Webのフォーム、URL、あるいはあなたのカスタムプログラムから 特定の文字を入れることが可能です。 もしユーザーがフォームに @code{; DROP ALL DATABASES ;} のような文字を入力しても、 あなたのアプリケーションは安全ですか? これは極端な例ですが、それらに対して準備しない場合、似たようなテクニックを 使用するハッカーの結果として、大きなセキュリティリークとデータ喪失が発生し 得ます。 数値データのチェックも忘れないでください。よくある間違いは文字列しか保護し ないことです。時々、人はデータベースが保護される必要のない公に有効なデータ だけを含んでいるかどうかを考えます。これは間違いです。少なくとも、 Denial-of-Service タイプのアタックはそのようなデータベースでも実行されます。 このタイプのアタックから保護するもっとも簡単な方法は、数値定数の回りにアポ ストロフィを使用することです: @code{SELECT * FROM table WHERE ID=234} の代 わりに @code{SELECT * FROM table WHERE ID='234'}。@strong{MySQL} は自動的 にこの文字列を数値に変換し、そこからすべての非数値シンボルを取り除きます。 チェックリスト: @itemize @bullet @item すべての WWW アプリケーション: @itemize @bullet @item あなたの WWW の全てのフォームに、@samp{'} と @samp{"} を入力することを試みてください。 もしなんらかの @strong{MySQL} エラーがでたら、あなたのサイトを停止したほうが よいでしょう。 @item あなたの URL に @code{%22} (@samp{"}), @code{%23} (@samp{#}) , @code{%27} (@samp{'}) をつけてみて、動的URLを いろいろ変更して試してみてください。 @item 動的 URL のデータタイプを数値から上述の例の文字を含む文字列に修正してみて ください。アプリケーションはこれと似たようなアタックに対して安全であるべき です。 @item 数値フィールドに対して、文字、スペース、特殊文字の入力を試みてください。 アプリケーションは、それらを @strong{MySQL} に送る前に取り除くか、 あるいはエラーを出すべきです。 検査しない値を @strong{MySQL} に送ることは危険です。 @item @strong{MySQL} にデータを送る前に、そのサイズをチェックします。 @item あなたのアプリケーションが、管理目的であなたが使用するのと異なるユーザ名を 使用してデータベースに接続することを考慮してください。必要以上のアクセス権 をアプリケーションに与えないで下さい。 @end itemize @item PHP ユーザ: @itemize @bullet @item @code{addslashes()} 関数を調べます。 @end itemize @item @strong{MySQL} C API ユーザ: @itemize @bullet @item @code{mysql_escape()} API コールがあるか調べます. @end itemize @item @strong{MySQL}++ ユーザ: @itemize @bullet @item Check out the @code{escape} and @code{quote} modifiers for query streams. @end itemize @item Perl DBI ユーザ: @itemize @bullet @item Check out the @code{escape} and @code{quote} modifiers (?) for query streams. @item Check out the @code{quote()} method. @end itemize @end itemize @item 生のデータ(暗号化されていないデータ)をインターネット越しに送ってはいけません。 This data is accessible to everyone who have interest to trap this information and reuse it somewhere. もし送る必要があるなら、SSL のような暗号化された通信を 使用すべきです。 @strong{MySQL} supports internal SSL connections beginning from version 3.23.9. SSH port-forwarding can be used to create an encrypted (and compressed) tunnel for the communication. @item "tcpdump", "strings" ユーティリティを使うことを学んで下さい. 以下のコマンドで、ほとんどの場合、暗号化されていない @strong{MySQL} のデータが見えるでしょう: @example shell> tcpdump -l -i eth0 -w - src or dst port 3306 | strings @end example (この例は Linux のものです。他のシステムでは少し違うでしょう). Warning: If you do not see data this doesn't actually always mean that it is encrypted. If you need high security you should consult with security expert. @end itemize @node Security, What Privileges, General security, Privilege system @section @strong{MySQL} をクラッカーに対して安全にする方法 @strong{MySQL} サーバーに接続するときは、パスワードを使用すべきです。 パスワードはコネクション間で、べたテキストでは流れません。 その他の全ての情報はテキストで転送され、 これは接続を覗くことが出来る人に読まれます。 もしこれを心配するなら、圧縮プロトコル(@strong{MySQL} 3.22 以上)を 使用することが出来ます。より安全にしたい場合、 @code{ssh} (@uref{http://www.cs.hut.fi/ssh}) をインストールすべきです。 これを使用すれば、@strong{MySQL} サーバーと @strong{MySQL} クライアント 間の TCP/IP コネクションは全て暗号化されます。 @strong{MySQL} システムを安全にするためには、次のことを考えるべきです: @itemize @bullet @item 全ての @strong{MySQL} ユーザにパスワードを使用すべきです。 @code{other_user} にパスワードが設定されていない場合、 誰でも @code{mysql -u other_user db_name} として簡単に他の人としてログインでき ることを覚えてください。これは全てのクライアント/サーバアプリケーション で一般的な振る舞いです。全てのユーザのパスワードは、 @code{mysql_install_db} スクリプトを実行前に編集することで、または @strong{MySQL} @code{root} ユーザだけは次のようにして変更することができます。 @example shell> mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; @end example @item @strong{MySQL} デーモンを Unix の @code{root} ユーザーで実行しないでください。 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} は任意のユーザで実行できます。 より安全にするため、新しく Unix ユーザ @code{mysql} を追加することもできます。 @code{mysqld} を 他の Unix ユーザーで起動したとしても、 @strong{MySQL} の @code{user} テーブルの @code{root} ユーザーの名前を変更する必要はありません。 なぜなら、 @strong{MySQL} ユーザーの名前は Unix のユーザー名とはなんの関係もないからです。 root ユーザ名を変更する必要はありません。 @code{mysqld} を他の Unix ユーザで起動するために、@code{mysql.server} 編集してもよいでしょう。 通常、これは @code{su} コマンドで行われます。 より詳しい情報は → @ref{Changing MySQL user, , Changing @strong{MySQL} user}. @item @code{mysql.server} スクリプト内に Unix @code{root} ユーザーのためにパスワードを 書いた場合、このスクリプトは @code{root} だけが読めるようにしなくては なりません。 @item データベースディレクトリは @code{mysqld} を実行している Unix ユーザだけが 読み込み/書き込み可能なことをチェックしてください。 @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 @strong{process} 権限を全てのユーザに与えないでください。この許可がある人は誰でも @code{mysqladmin processlist} コマンドで実行されているクエリーの中身を見ることができます。 もし誰かが、@code{UPDATE user SET password=PASSWORD('not_secure')} クエリーを 実行していたとして、それが見えてしまいます。 @code{mysqld} は @strong{process} 権限を持つユーザに対する特別な接続をリザーブします。 そのため、たとえ全ての通常接続が使われたとしても、@strong{MySQL} @code{root} ユーザだけは、 ログインでき、いろいろチェックできます。 @item @strong{file} を全てのユーザに与えないでください。ユーザがこの権限を持つ場 合、@code{mysqld} デーモンを実行している Unix ユーザーの権限で ファイルシステム内のどこにでもファイルを書き込むことができます! これを少し安全にするために、@code{SELECT ... INTO OUTFILE} で作成される全てのファイルは 全員に読み込み可能で生成され、既存のファイルには上書きできません。 @tindex /etc/passwd @strong{file} 権限はサーバーを走らせている UNIX ユーザーがアクセスできる 全てのファイルを読むために使用されかもしれません。 例えば、 @file{/etc/passwd} をテーブルに取り込むために @code{LOAD DATA} が 使用されると、 @code{SELECT} でその内容が読めることになります。 @item あなたの DNS を信用しない場合、権限テーブル内にはホスト名の代わりに IP を使用すべきです。@code{mysqld} への @code{--secure} オプションは原理上はホスト名を安 全にします。どんな場合でも、ワイルドカードを含んだホスト名を、許可テーブルに登録する 事は本当に注意深くすべきです! @end itemize @code{mysqld} への次のオプションはセキュリティに影響します: @table @code @item --secure @code{gethostbyname()} から返される ip がオリジナルのホスト名に戻せるかど うかをチェックします。これは、外の誰かが他のホストを真似てアクセスを得る ことを難しくします。このオプションはいくつかの正しいホスト名チェックも追 加します。これは、時にチェックに長い時間がかかるため、@strong{MySQL} 3.21 ではデフォルトではオフにされています。@strong{MySQL} 3.22 ではこのオプションは デフォルトで有効になっていますが、ホスト名をキャッシュするようになっています。 @item --skip-grant-tables 特権システムを全く使用しません。これは全員に全てのデータベースへの @emph{完全なアクセス} を与えます! (@code{mysqladmin flush-privileges} か @code{mysqladmin reload} を実行することで、 起動しているサーバーは特権システムを使用するようになります。) @item --skip-name-resolve ホスト名を解析しません。権限テーブル中の全ての @code{Host}フィールドは IP アドレスか @code{localhost} でなければなりません。 @item --skip-networking ネットワーク (TCP/IP) 経由の接続を許可しません。@code{mysqld} への全ての接続は、 Unix ソケットで行われます。MIT-pthreads は Unix ソケットをサポートしない ため、このオプションは MIT-pthreads を使用するシステム上では、うまく動きません。 @end table @node What Privileges, User names, Security, Privilege system @section 特権システムの行うこと @strong{MySQL} 特権システムの基本機能は、与えられたホストから接続する ユーザを認証すること、そしてデータベースに対する @strong{select}, @strong{insert}, @strong{update}, @strong{delete} 等の権限を与えることです。 拡張機能は匿名ユーザをもつ能力を含み、@code{LOAD DATA INFILE} のような @strong{MySQL} 固有の機能を使用する許可を与えます。 @node User names, Connecting, What Privileges, Privilege system @section @strong{MySQL} ユーザ名とパスワード @strong{MySQL} によって使用されるユーザー名とパスワードの使用のされ方と、 UNIX, Windows で使用される方法とは、いくつか異なる点があります。 @itemize @bullet @item @strong{MySQL} データベースのアクセス認証に使用するユーザー名は、 UNIX のログインユーザやWindowsのユーザー名で行うことはありません(一致していません)。 利便性をはかるため、多くの @strong{MySQL} クライアントは現在のログインしているユーザ名を @strong{MySQL}のユーザー名としてログインを試みます。 しかしこれは @code{-u} か @code{--user} スイッチで変更できます。 これは、全てのユーザに対しパスワードを設定しておかないと、 全くデータベースを安全にできないことを意味します。 もしパスワードを全ユーザーに設定しておかないと、そのユーザー名で認証なしにサーバーに接続できます。 @item @strong{MySQL} のユーザー名は 16文字まで(英数半角)使用できます。 UNIXはだいたい8文字ですが。(8文字をこえるシステムもある) @item @strong{MySQL} ユーザーのパスワードは、Unix のパスワードと違います。 よって、それらのマシン上で Unix のログインパスワードと データベースのパスワードは同じにする必要はありません。 @item @strong{MySQL} は Unix のログインパスワードとは全く違う、 独自の暗号化されたパスワードだけを使用します。 @code{PASSWORD()} と @code{ENCRYPT()} 関数の説明を参照 → @ref{Miscellaneous functions}. @end itemize @node Connecting, Password security, User names, Privilege system @section @strong{MySQL} サーバーに接続 @strong{MySQL} クライアントプログラムは、共通の決まった引数を持ちます: 接続したいホスト名、接続ユーザー名、そしてパスワードです。 例えば、@code{mysql} コマンドは以下のような引数を持ちます (オプションの引数は @samp{[} と @samp{]} で囲まれている部分です) @example shell> mysql [-h host_name] [-u user_name] [-pyour_pass] @end example @code{-h}, @code{-u}, @code{-p} オプションは以下と等価です。 @code{--host=host_name}, @code{--user=user_name}, @code{--password=your_pass} @code{-p} とパスワードの間にはスペースがないことに注意 @strong{注意:} コマンドラインにパスワードを与えるのは安全ではありません! システムに入っている如何なるユーザーも @code{ps auxww} のようなコマンドを 使用する事でパスワードを見付ける事ができます @xref{Option files}. @code{mysql} コマンドはコマンドラインに引数がなければ接続にデフォルト値を用います。 @itemize @bullet @item デフォルトのホスト名は @code{localhost}, ユーザー名は Unix のログイン名です。 @item (@code{-p} が指定されていなければパスワードは与えられません) @end itemize Unix のログインユーザーが @code{joe} の場合、以下のコマンドは等価です: @example shell> mysql -h localhost -u joe shell> mysql -h localhost shell> mysql -u joe shell> mysql @end example 他の @strong{MySQL} クライアントも同じように動作します。 Unix システムでは、ある値をデフォルト値にして接続に使用することができます。 そうすることにそり、毎回毎回コマンドラインに引数を与えなくてすむようになります: @itemize @bullet @item @tindex .my.cnf file 自分のホームディレクトリに @file{.my.cnf} を作り、そのファイルの中の @code{[client]} セクションに接続用のパラメターを記述できます。 その記述は以下のようです: @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 接続のパラメターに環境変数を使用することもできます。 ホスト名は @code{MYSQL_HOST} 環境変数を使用します。 @strong{MySQL} のユーザー名は @code{USER} (これは Windows のみ) に設定された値を使用します。 パスワードは @code{MYSQL_PWD} 環境変数を見ますが、これは危険です。(次の節参照) @xref{Environment variables}. @end itemize @node Password security, Privileges provided, Connecting, Privilege system @subsection パスワードを安全にする 自分のパスワードを他人にさらけ出すのは勧められることではありません。 それぞれの方法に於ける危険度に応じ、以下に示す方法でクライアントプログラムに あなたのパスワードをあたえて走らせることができます: @itemize @bullet @item @code{-pyour_pass} か @code{--password=your_pass} オプションをコマンドラインで使用します。 これは便利ですが安全ではありません。あなたのパスワードは (@code{ps} コマンドのような) システムの状態を見るコマンドにて見ることができます。 (@strong{MySQL} クライアントは初期化過程においてコマンドラインの引数をゼロで上書きして 見せないようにしているのですが、瞬間ですが値が見えてしまうのです) @item @code{-p} あるいは @code{--password} オプションを @code{your_pass} を与えないで使用します。 この場合、クライアントプログラムはターミナルを通じてパスワードの入力を促してきます: @example shell> mysql -u user_name -p Enter password: ******** @end example クライアントはあなたの入力したパスワードを @samp{*} 文字で端末に返していますので、 画面をのぞき込まれたとしてもパスワードはわかりません。 これはコマンドラインにパスワードを指定するより安全です。他のユーザーには見えませんから。 しかしこのパスワードを毎回入れる方法は対話式のプログラムを実行する場合だけに使用できる手です。 もし非対話式のスクリプトからクライアントプログラムを起動したい場合、 パスワードを端末から入れる機会がありません。 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 設定ファイルにパスワードを書いておくこともできます。 例えば、自分のホームディレクトリーにある @file{.my.cnf} ファイルの @code{[client]} セクションに、以下のような形で書きます: @example [client] password=your_pass @end example もし @file{.my.cnf} ファイルにパスワードを書いているなら、ファイルはグループや その他のユーザーが読み書きできないようにすべきです。ファイルのモードは @code{400} か @code{600} にします。 @xref{Option files}. @item @code{MYSQL_PWD} 環境変数にパスワードを設定することもできます。しかしこの方法は きわめて危険であるので、使用すべきではありません。 @code{ps} のあるバージョンでは、実行中のプロセスの環境変数を表示するオプションがあります; もし @code{MYSQL_PWD} 環境変数にパスワードを設定していると全てべたで見れます。 このバージョンの @code{ps} を持っていないシステムだとしても、プロセスの環境変数を調べる 方法がないとはいえないので、この方法はあまりいい方法ではありません。 @xref{Environment variables}. @end itemize まとめると、より安全な方法は、 パスワードプロンプトを返すクライアントプログラムを実行するか、 適切なパーミッションをかけた @file{.my.cnf} ファイルにパスワードを書くか です。 @node Privileges provided, Privileges, Password security, Privilege system @section @strong{MySQL} が提供する権限 権限の設定は @code{mysql} データベースの @code{user}, @code{db}, @code{host}, @code{tables_priv}, @code{columns_priv} で行います。 (@code{mysql} はデータベースの名前です) @strong{MySQL} サーバーは、サーバーの起動時か @ref{Privilege changes} で説明されている方法により、 これらのテーブルから権限の設定を読み込みます。 @strong{MySQL} が提供する権限の名称は, 本マニュアルでは以下の表の名称を用います。 この表の項目名がそれぞれの許可される権限とその説明に対応しています: @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 @strong{select}, @strong{insert}, @strong{update}, @strong{delete} の権限は、 存在しているデータベースのテーブルに対して許可されます。 もしテーブルから行を取り出すだけなら、@code{SELECT} 構文を実行するためには @strong{select} 権限だけあればかまいません。 だけでなく、サーバーのどのデータベースにアクセスを許可されていない場合でも、 ある種の @code{SELECT} は実行することができます。 例えば、簡単な計算を @code{mysql} クライアントで行う場合です: @example mysql> SELECT 1+1; mysql> SELECT PI()*2; @end example @strong{index} 権限はインデックスの作成と破棄(削除)を許可します。 @strong{alter} 権限は @code{ALTER TABLE} の実行を許可します。 @strong{create} と @strong{drop} 権限は、新しいデータベースやテーブルの作成、 あるいは既に存在するデータベース、テーブルの破棄(削除)を許可します。 注意: @code{mysql} データベースに登録されているユーザーに @strong{drop} 権限を与えると、 そのユーザーは @strong{MySQL} のアクセス権限が格納されているデータベースを破棄できます! @strong{grant} 権限は、あなたが他のユーザーに対して自分の権限を持たせる事を許可します。 @strong{file} の権限を与えると、@code{LOAD DATA INFILE} と @code{SELECT ... INTO OUTFILE} 構文を使用して、サーバーのファイルを読み書きする事ができます。 @strong{MySQL} サーバーがが読み書きできるファイルに対して、この権限が与えられたユーザーはファイルを読み書きできます。 残りの権限はアドミン操作に関する許可で、@code{mysqladmin} コマンドを使用して実行します。 次の表に @code{mysqladmin} コマンドのどれが、どの権限に対応しているかを示します: @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 @code{reload} コマンドはサーバーに権限の設定を再読込させるように伝えます。 @code{refresh} コマンドは全てのテーブルをフラッシュし、ログファイルを開き直します。 @code{flush-privileges} は @code{reload} と同義です。 その他の @code{flush-*} コマンドは @code{refresh} の動作とよく似ていますが、 適用範囲を絞っており、ちょっとした場合に有効です。 例えば、ログファイルだけをフラッシュしたい場合、 @code{refresh} を行うよりも @code{flush-logs} がいいです。 @code{shutdown} コマンドは、サーバーをシャットダウンします。 @code{processlist} コマンドはサーバーが実行しているスレッドの情報を表示します。 @code{kill} コマンドはサーバーのスレッドをkillします。 自分のスレッドは常に表示、killできますが、他人のスレッドをそうするには @strong{process} 権限が必要です。 ある権限を欲しがるユーザーだけにその権限を許可するのはよい考えですが、 権限を与えるときには、特定の事項を熟知していなければなりません: @itemize @bullet @item @strong{grant} 権限を許可されたユーザーは、他のユーザーの権限を変える事ができます。 二人のユーザー間で違っている権限と @code{grant} 権限を入れ換えることができます。 @item @strong{alter} 権限は、テーブル名の変更を行うことにより特権システムを破るために 使用されるかもしれません。 @item @strong{file} 権限は、サーバー上にある全ての読み込み可能なファイルを データベースに取り込むことができ、これは @code{SELECT} 文でアクセスできます。 This includes the contents of all databases hosted by the server! @item @strong{shutdown} 権限は、他のユーザーに対するサービスを、サーバーを 停止することによって、拒否するようにできます。 @item @strong{process} 権限は実行されているクエリーをプレーンテキストで見ることに使えます。 パスワードの設定、変更のクエリーも含みます。 @item @code{mysql} データベースに対しての権限は、パスワードの変更と他の権限の設定を変更ができます。 パスワードは暗号化されて登録されており、悪意のあるユーザーでも 単純に読むことはできませんが、この権限を許可されたそのユーザーは、 パスワードを違うものに変えることができます。 @end itemize 以下は @strong{MySQL} の特権システムで行うものではありません: @itemize @bullet @item アクセスを拒否するユーザーを特定して設定することはできません。 完全に一致したユーザーからの接続を拒否できません。 @item データベース内のテーブルの作成、破棄の権限を持つが、 データベースそのものを作成、破棄できる、そのようなユーザーを設定できません。 @end itemize @node Privileges, Connection access, Privileges provided, Privilege system @section 特権システムはどのように動くか? @strong{MySQL} の特権システムは、全てのユーザーが与えられた許可の範囲内で動く事を保証します。 @strong{MySQL} サーバーに接続するとき、本人の身元は、@strong{接続元のホスト} と @strong{接続に使用するユーザー名} によって確認されます。 このシステムは、あなたの身元と@strong{あなたが要求することが何か} によって、権限を与えます。 @strong{MySQL} はあなたのホスト名とユーザー名の両方をあわせてチェックします。 これはインターネット上に同じ名前のユーザーがどこかにいるかもしれないということからそうしています。 例えば、@code{whitehouse.gov} から接続してきた @code{bill} と、 @code{microsoft.com} から接続してきた @code{bill} は同一人物である必要はありません。 @strong{MySQL} はこの違うホストから接続してきた同名のユーザーを以下のようにして扱います: @code{whitehouse.gov} から接続した @code{bill} にある許可をあたえ、 それとは違う許可を @code{microsoft.com} から接続してきた @code{bill} に与えます。 @strong{MySQL} のアクセスコントロールは以下の二つからなります: @itemize @bullet @item Stage 1: サーバーは接続許可があるかどうかをチェックします。 @item Stage 2: 接続許可後、サーバーはそれぞれのリクエストをチェックします。 あなたが要求してきた事柄を、あなたが実行できるかどうかをチェックします。 例えば、あるデータベースのテーブルの行の取り出しやテーブルの破棄をあなたが命令した場合、 サーバーは、あなたにそのテーブルに対する @strong{select} 許可があるのか、 データベースに対して @strong{drop} する許可が与えられているのか、を確認します。 @end itemize サーバーは @code{mysql} データベースの @code{user}, @code{db}, @code{host} 3つのテーブルから、 この2つのアクセス制限を決定します。 このテーブルのフィールドは以下のようになっています: @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  アクセスコントロールの第2段階(要求承認)のために、サーバーはこれら 3 つの テーブルによって決められた許可を基本としますが、もしテーブルに対する要求で あるならば、@code{tables_priv} と @code{columns_priv} テーブルを さらに調べます。これらのテーブルのフィールドは以下のようになっています: @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{Type} @item @tab @code{Column_priv} @tab @item @strong{Other fields} @tab @code{Timestamp} @tab @code{Timestamp} @item @tab @code{Grantor} @tab @end multitable  テーブルの各フィールドを分類すると、2種類にわかれます: 適用範囲を指定するフィールド(以下 スコープフィールド)と許可を定義するフィールド(以下 権限フィールド)です。  スコープフィールドは、権限テーブルの登録ごとに、その適用範囲を決めます。 例えば、 @code{user} テーブルの @code{Host} と @code{User} に @code{'thomas.loc.gov'} と @code{'bob'} が登録されている場合、 サーバーへの接続は ホスト @code{thomas.loc.gov} から来た @code{'bob'} に許可されます。 同様に、@code{db} テーブルの @code{Host}, @code{User}, @code{Db} に @code{'thomas.loc.gov'}, @code{'bob'}, @code{'reports'} が登録されていると、 ホスト @code{thomas.loc.gov} から来た @code{bob} に対し @code{reports} データベースへの接続が許されます。 @code{tables_priv} と @code{columns_priv} テーブルは、 テーブルか、テーブルとフィールドを対にしたスコープフィールドを含みます。 @cindex Case sensitivity, in access checking  アクセスのチェックは、@code{Host} の値はケース非依存で比較されます。 @code{User}, @code{Password}, @code{Db}, @code{Table_name} の値はケース依存で比較されます。 @code{Column_name} の値は @strong{MySQL} 3.22.12 以上ではケース非依存で比較されます。 (3.22.11 までは ケース依存です) 権限フィールドは、テーブルに登録されることにより有効になった許可をしめし、 これはどの操作が実行できるかを示します。 サーバーは許可テーブルの情報をユーザーの権限を得るためにまとめます。 このユーザーの権限許可を割り出す方法は @ref{Request access} に述べておきます。 スコープフィールドは文字で定義され、デフォルト値は空文字になっています: @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 @code{user}, @code{db}, @code{host} テーブルでは、 全ての権限フィールドは @code{ENUM('N','Y')} で定義されます。 この値は @code{'N'} か @code{'Y'} のどちらかで、デフォルト値は @code{'N'} です。 @code{tables_priv} と @code{columns_priv} テーブルでは、 権限フィールドは @code{SET} フィールドとして定義されます: @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 サーバーは以下のように許可テーブルを使用します: @itemize @bullet @item @code{user} テーブルのスコープフィールドは、接続要求を受け入れるか拒否するかを決定します。 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. (訳注: 例えば、@code{user} テーブル の権限を @code{'Y'} にした場合、 どんなに @code{Db} や @code{Host} で @code{'N'} にしたとしても @code{'Y'} のままである。 ようは @code{user} テーブルの権限許可 @code{'Y'} が全てに反映されてしまうという事。 @code{user} テーブルには最低限の許可を与えるようにし、 @code{Db} や @code{Host} ごとに、それぞれの権限許可を定義する方が無難。 ) @item @code{db} と @code{host} テーブルは一緒に使用されます: @itemize @minus @item @code{db} テーブルのスコープフィールドはどのホストからどのデータベースのアクセスできるかを決定します。 権限フィールドは、どういった操作ができるか定義します。 @item @code{host} テーブルは、@code{db} テーブルの登録ににホストを与えた場合に、 @code{db} テーブルの拡張として使用されます。 例えば、ネットワーク上の限定したマシンからデータベースを使用したい場合、 @code{db} テーブルの @code{Host} の値は空にしておきます。 そして @code{host} テーブルにそれぞれのホストについての登録を行います。 この機構は、 @ref{Request access} で詳細に述べられています。 @end itemize @item @code{tables_priv} と @code{columns_priv} テーブルは @code{db} テーブルに似ていますが、 それらはより細かく定義できます; データベースレベルではなく、テーブルとフィールドのレベルで与えます。 @end itemize 管理者権限 (@strong{reload}, @strong{shutdown},など) は @code{user} テーブルにだけ定義するように。 これは、管理者操作はデータベースではなくサーバーへの操作であり、 他の許可テーブルにある必要がないからです。 またこうしておくと、管理者操作の許可は、@code{user} テーブルの定義だけを 見ればわかるようになります。 @strong{file} 操作の権限は @code{user} テーブルにだけ定義するように。 これは管理者操作ではありませんが、アクセスしているデータベースにかかわらず、 サーバー内のファイルを読み書きできるのです。 @code{mysqld} サーバーは起動時にこれらのテーブルを読み込みます。 許可テーブルの変更を反映させる方法はこちらを参照のこと → @ref{Privilege changes} これらのテーブルの登録を変更した場合、思ったとおりの権限状態になっている事を確認することはいいことです。 問題の解決には, @ref{Access denied}. セキュリティに関するアドバイスは @ref{Security}. 便利なツールとして @code{mysqlaccess} スクリプト( Yves Carlier 作)が @strong{MySQL} の配布に含まれています。 @code{mysqlaccess} を @code{--help} オプションで起動するとヘルプが表示されます。 @code{mysqlaccess} は @code{user},@code{db} and @code{host} テーブルだけしか 検査しません。テーブルレベルの権限、フィールドレベルの権限は調べません。 @node Connection access, Request access, Privileges, Privilege system @section Access control, stage 1: 接続の承認 @strong{MySQL} サーバーに接続すると、あなたがパスワード認証して接続していようがいまいが、 サーバーはあなたの身元により接続の許可拒否を行います。 もし身元が一致しない場合接続を拒否し、接続許可した場合、サーバーは stage 2 へと進み、要求を待ちます。 身元は二つのものに基づいて確認されます: @itemize @bullet @item あなたが接続しようとしているホスト @item あなたの @strong{MySQL} ユーザー名 @end itemize 身元の確認は @code{user} テーブルのスコープフィールド(@code{Host}, @code{User}, @code{Password}) を使用して行います。 サーバーは @code{user} テーブルの登録に一致しているホスト名とユーザー名に限り接続を許可し、その後、パスワードを要求します。 @code{user} テーブルのスコープフィールドの登録は以下のようになります: @itemize @bullet @item @code{Host} の値はホスト名か IP アドレスか @code{'localhost'}(ローカルホスト) です。 @item @cindex Wildcards, in @code{mysql.user} table @code{Host} にはワイルドカード文字 @samp{%} と @samp{_} を使用できます。 @item @code{Host} に @code{'%'} を設定すると、全てのホストにマッチします。 @code{Host} を空にすると、@code{'%'} と同じになります。 これらの値は、@emph{どんなホストもサーバーに接続できる}ということになります! @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 ワイルドカード文字は @code{User} フィールドには設定できませんが、 @code{User} フィールドをブランク(空)にすることはできます。ブランクは全ての名前にマッチします。 これはユーザー名がない状態で接続してきたものに適用され、 クライアントがユーザー名を明記しない限り、匿名ユーザー(名前がブランク)として扱われます。 全てのアクセスのチェックにブランクのユーザー名が使用される事を意味します。(that is, during stage 2) @item @code{Password} フィールドは空にできます。その場合、パスワードなして接続できることになります。 @end itemize @findex PASSWORD() 非ブランクの @code{Password} 値はパスワードを暗号化したものです。 @strong{MySQL} はだれもが見れるようにパスワードを平文では保存しません。 接続を試みようとしているユーザーのパスワードも、(@code{PASSWORD()} 関数で) 暗号化され、@code{user} テーブルに保存されている暗号化パスワードと 比較します。もし一致したなら、パスワードは正しいということです。 以下の表は、接続要求に対して与える、 @code{user} テーブルの @code{Host} と @code{User} の設定例です: @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}, @code{thomas.loc.gov} から接続 @item @code{'thomas.loc.gov'} @tab @code{''} @tab @code{thomas.loc.gov} から接続してくる全てのユーザー @item @code{'%'} @tab @code{'fred'} @tab @code{fred}, 全てのホストから接続 @item @code{'%'} @tab @code{''} @tab 全てのホストから接続してくる全ユーザー @item @code{'%.loc.gov'} @tab @code{'fred'} @tab @code{fred}, @code{loc.gov} ドメイン内の全てのホストからの接続 @item @code{'x.y.%'} @tab @code{'fred'} @tab @code{fred}, @code{x.y.net}, @code{x.y.com},@code{x.y.edu}, などからの接続. (あまり有効な使い方ではないです) @item @code{'144.155.166.177'} @tab @code{'fred'} @tab @code{fred}, IP address が @code{144.155.166.177} のホストからの接続 @item @code{'144.155.166.%'} @tab @code{'fred'} @tab @code{fred}, @code{144.155.166} class C subnet 内の全てのホストからの接続 @item @code{'144.155.166.0/24'} @tab @code{'fred'} @tab Same as previous example @end multitable @code{Host} に IP のワイルドカード(例えば @code{'144.155.166.%'} は サブネットの全てのホストにマッチ) を使用することができます。 が、この場合、 @code{144.155.166.somewhere.com} というホスト名で だれかが接続しようとしてくるかもしれません。 このような攻撃に対し、@strong{MySQL} は数字やドットで始まるホスト名を拒否しています。 もし @code{1.2.foo.com} のような名前のホストを持っている場合、 許可テーブルの @code{Host} には絶対にマッチしません。 IPアドレスのみ、IP のワイルドカードにマッチする事になります。 サーバーに来る接続は、@code{user} テーブル内の登録に1つ以上 マッチするかもしれません。 例えば, @code{thomas.loc.gov} の @code{fred} からの接続は、上に示された 登録のうちのいくつかにマッチするでしょう。 サーバーは、複数の登録にマッチした場合、どのようにしてその中から 使用する登録を選ぶのでしょう? サーバーは起動後に @code{user} テーブルをソートし、並び換えられた順に 登録を検索することにより、この問題を解決します。 最初にマッチした登録が使用されます。 @code{user} テーブルが以下のようにソートされていた場合: @example +-----------+----------+- | Host | User | ... +-----------+----------+- | % | root | ... | % | jeffrey | ... | localhost | root | ... | localhost | | ... +-----------+----------+- @end example サーバーがこのテーブルを読むと、@code{Host} に値が最も確実に特定できるホストを指定しているエントリを、最初に参照します。 (@code{Host} 項の @code{'%'} は ``すべてのホスト'' を意味し、ホスト名をはっきりと特定しているものではありません) @code{Host} の値が同じエントリがあった場合、もっとも明確に @code{User} の値がユーザーを指定しているエントリを最初に参照します。(@code{User} の値が空の場合、``だれでも'' を意味します) この結果、@code{user} テーブルは以下のようにソートされます: @example +-----------+----------+- | Host | User | ... +-----------+----------+- | localhost | root | ... | localhost | | ... | % | jeffrey | ... | % | root | ... +-----------+----------+- @end example @cindex Grant tables, sorting @cindex Sorting, grant tables @cindex @code{user} table, sorting 接続が試みられた場合、サーバーは並び換えられた登録を探し、最初に見つけたものを 使用します。 @code{'localhost'} の @code{jeffrey} からの接続は、まず最初に @code{Host} に @code{localhost} を設定しているエントリにマッチします。 ユーザー名が空のエントリは、ホスト名とユーザー名の両方を指定した接続にもマッチします。 ( @code{'%'/'jeffrey'} エントリもマッチします。が、これは最初にはマッチしません。) もう一例。@code{user} が以下の設定と仮定します: @example +----------------+----------+- | Host | User | ... +----------------+----------+- | % | jeffrey | ... | thomas.loc.gov | | ... +----------------+----------+- @end example これは次のようにソートされます: @example +----------------+----------+- | Host | User | ... +----------------+----------+- | thomas.loc.gov | | ... | % | jeffrey | ... +----------------+----------+- @end example @code{thomas.loc.gov} の @code{jeffrey} からの接続は、最初のエントリにマッチし、 @code{whitehouse.gov} の @code{jeffrey} からの接続は、二つ目のエントリにマッチします。 最初にサーバが,接続のためのマッチを見つけるのを試みるとき,共通の誤解は与えられた ユーザ名に明らかにそのユーザを命名するすべてのエントリが使用されると思うことです. これは単に本当ではありません. jeffreyによるthomas.loc.govからの接続が最初に エントリによってユーザ分野値として‘jeffrey'を含まないいずれのエントリによってる合わ せられる場合,前の例はこれをユーザ名なしで例示します! よくある考え違いは、ユーザー名を与えた場合、 サーバーが接続にマッチするものを探す際に、 そのユーザーが登録されている全てのルールが、 最初に使用されるだろうと考えることです。これは正しくありません。 前の例でこれを示しましたが、@code{thomas.loc.gov} の @code{jeffrey} からの接続が 最初にマッチするのは、 @code{User} フィールドの値が @code{'jeffrey'} に なっているエントリではなく、ユーザー名なし(=だれでも) のエントリの方が 先にマッチします! もしサーバーへの接続がうまく行かない場合、 @code{user} テーブルを表示し、 マニュアルでソートしてみて、どのエントリに最初にマッチするか探してください。 @node Request access, Privilege changes, Connection access, Privilege system @section Access control, stage 2: 要求の承認 一度接続か確立されると、サーバーはステージ2に移ります。 このステージでは、サーバーはこの接続から来るそれぞれの要求が許可されているかどうかをチェックします。 チェックは実行しようとしている操作のタイプにより行います。 その操作が許可テーブルのどの権限フィールドに当てはまるかを見ます。 これら権限は @code{user}, @code{db},@code{host}, @code{tables_priv} か @code{columns_priv} テーブルより導出されます。 許可テーブルは @code{GRANT} コマンドで操作します。 @xref{GRANT, , @code{GRANT}}. (You may find it helpful to refer to the table shown earlier that lists the fields present in each of the grant tables; see @ref{Privileges}.) @code{user} テーブルは全てに対して基本となる権限をユーザーに割り当てます。 たとえカレントのデータベースが許可を与えていなくても、@code{user} テーブルの設定が有効になります。 例えば、@code{user} テーブルで @strong{delete} を許可した場合、 サーバーにあるどんなデータベースの行も削除できるのです! いうならば、@code{user} テーブルの権限はスーパーユーザーの権限と言ってもいいでしょう。 この権限はスーパーユーザー(サーバーやデーターベース管理者)のみに与えておく事が賢明です。 他のユーザーは、@code{user} テーブルの権限の設定を @code{'N'} のままにしておくべきですし、 また、@code{db} テーブルと @code{host} テーブルを利用して、 データベースを指定した上でユーザーに権限を許可すべきです。 @cindex Anonymous user @cindex Wildcards, in @code{mysql.db} table @cindex Wildcards, in @code{mysql.host} table @code{db} テーブルと @code{host} テーブルは特定のデータベースに対する権限許可を行います。 Values in the scope fields may be specified as follows: @itemize @bullet @item ワイルドカード文字 @samp{%} と @samp{_} は @code{Db} テーブルと @code{Host} フィールドだけに使用できます。 @item @code{'%'} @code{Host} 値は ``あらゆるホスト'' を意味します。 @code{db} テーブルの @code{Host} に空を設定すると、``さらに @code{host} テーブルに許可情報を探しにいく'' となります。 @item @code{'%'} か 空値を @code{Host} テーブルに設定すると、それは ``あらゆるホスト'' となります。 @item @code{'%'} か 空値を @code{host} テーブルの @code{Db} フィールドに設定すると、 それは ``あらゆるデータベース'' となります。 @item @code{User} を空値にすると、匿名ユーザーにマッチします。 @end itemize @cindex Grant tables, sorting @cindex Sorting, grant tables @cindex @code{db} table, sorting @cindex @code{host} table, sorting サーバー起動時に、@code{db} テーブルと @code{host} テーブルはサーバーに読み込まれます。 (@code{user} テーブルもこの時に同時に読まれます) @code{db} テーブルは @code{Host}, @code{Db}, @code{User} のフィールドでソートされ、 @code{host} テーブルは @code{Host}, @code{Db} フィールドでソートされます。 @code{user} テーブルは、一番特定できるエントリを最初に、一番特定できないものを最後にソートします。 サーバーはソートされたものの中から、最初にマッチしたものを使用します。 @cindex Wildcards, in mysql.tables_priv table @cindex Wildcards, in mysql.columns_priv table @code{tables_priv} と @code{columns_priv} テーブルは、 特定のテーブルとフィールドに対する権限を許可します。 スコープフィールドの値は、いかにそって記述されます: @itemize @bullet @item ワイルドカード文字 @samp{%} と @samp{_} はどちらかのテーブルの @code{Host} フィールドに使用できます。 @item どちらかのテーブルの @code{Host} 値を @code{'%'} かブランクにすると、 ``any host.'' を意味します。 @item @code{Db}, @code{Table_name}, @code{Column_name} フィールドはどのテーブルにも ワイルドカードやブランクは使用できません。 @end itemize @code{tables_priv} と @code{columns_priv} テーブルは @code{Host}, @code{Db}, @code{User} フィールドで並び換えられます。 これは @code{db} テーブルのソートに似ていますが、 @code{Host} フィールドだけが ワイルドカードを含むので、ソートはより単純なものになります。 この要求の承認は次のようにして行います。 もしアクセス承認を決定する部分のソースコードを理解できるなら、 ちょっと変わったアルゴリズムで承認の決定を行っている事に気づくでしょう。 管理者の要求(@strong{shutdown}, @strong{reload}, etc.)については、サーバーは @code{user} テーブルだけを参照します。(@code{user} テーブルだけが管理者権限のフィールドを持つ)。 エントリに許可登録されている操作は受け入れられ、それ以外は拒否されます。 例えば、@code{mysqladmin shutdown} を実行しようとしても、@code{user} テーブルの @strong{shutdown} 権限が許されていなければ実行できません。この時、@code{db} と @code{host} テーブルはチェックされません。(これらのテーブルには @code{Shutdown_priv} フィールドが無いからです) データベースへの要求 (@strong{insert}, @strong{update}, etc.) において、サーバーはまず最初に、ユーザーのグローバルな権限(スーパーユーザー)を @code{user} の中から探しだします。 もし許可が与えられていれば、アクセスは成功します。 @code{user} テーブルのグローバルな権限の設定が不十分であるなら、サーバーはユーザーのデータベースに対する権限を @code{db} テーブルと @code{host} テーブルから決定します: @enumerate @item サーバーは @code{db} テーブルの @code{Host},@code{Db},@code{User}フィールドを参照します。 @code{Host} と @code{User} フィールドはユーザーの接続時のホスト名と @strong{MySQL} ユーザー名にマッチします。 @code{Db} フィールドはユーザーがアクセスしたいデータベース名にマッチします。 @code{Host} と @code{User} にマッチするものが無かった場合、アクセスは拒否されます。 @item @code{db} テーブル内の @code{Host} フィールドが空でないエントリにマッチした場合、 ユーザーの指定されているデータベースに対する権限が定義されます。 @item @code{Host} フィールドが空値の @code{db} テーブルのエントリにマッチした場合、 どのホストがそのデータベースへアクセスできるかを @code{host} テーブルから探し出します。 この場合、@code{host} テーブル の @code{Host}, @code{Db} フィールドとマッチするものを探し出します。 @code{host} テーブルにエントリがなかった場合、アクセスは拒否されます。 もしマッチすると、ユーザーの特定データベースに対する権限は、 @code{host} テーブルと @code{db} テーブル両方にまたがった権限から割り出されます。 いうならば両方とも @code{'Y'} である権限。 (この方法を使用すると、まず @code{db} テーブルのエントリに大まかな権限を設定しておき、 それから @code{host} テーブルのエントリを使用して、ホスト情報もとに権限を限定していくという事ができます) @end enumerate 特定データベースに対する権限が @code{db} テーブルと @code{host} テーブルのエントリから決定された後、 サーバーはその割り出された権限に対し、@code{user} テーブルて設定されている権限を加えます。 この結果から得られた権限にマッチした要求は受け入れられます。 そうでなければ、サーバーはユーザーのテーブル、フィールドに対する許可を、 @code{tables_priv} と @code{columns_priv} 内に探します。 アクセスはこの結果により、許可、拒否されます。 先のユーザーの権限が計算される方法の記述は、boolean 表記で示すならば、 以下のようになるでしょう: @example global privileges OR (database privileges AND host privileges) OR table privileges OR column privileges @end example これは少し分かりにくいかもしれません。もしグローバルの @code{user} エントリ 権限許可が、リクエストされたオペレーションには不十分だと最初に分かった際、 サーバーがこれらの権限を database-, table-, column-固有の権限の 後に、なぜ、追加してしまうのか。 その理由は、リクエストが1個以上の権限を要求するだろうということです。 例えば、もしあなたが @code{INSERT ... SELECT} 構文を実行するなら、 あなたには @strong{insert} と @strong{select} 許可が必要です。 あなたの権限が、 @code{user} テーブルエントリで一つの権限が許可され、 @code{db} テーブルで、そのほかの権限が許可されていたとします。 この場合、あなたは、そのリクエストを実行するために、必要な権限を持っています。 しかし、サーバーはどちらのテーブル、それ単体からでは、権限を得ることが出来ません。 権限は、両方のエントリーを合わせなくてはならないのです。 @code{host} テーブルは ``安全な'' ホストのリストを維持するために使用できます。 TcX では、@code{host} テーブルにはローカルネット上の全てのホストが登録されています。 これらのホストは全ての権限が許可されています。 逆に @code{host} table で安全@emph{ではない}ホストを指定することもできます。 @code{public.your.domain} というマシンが安全ではない、公開されている場所にあるとします。 その場合以下のようにして、その公開マシン以外のネットワーク上のホストに対して、アクセスを許可することができます: @example +--------------------+----+- | Host | Db | ... +--------------------+----+- | public.your.domain | % | ... (all privileges set to 'N') | %.your.domain | % | ... (all privileges set to 'Y') +--------------------+----+- @end example 権限のテーブル設定は、あなたの思い通りに許可が得られるのか、常に(@code{mysqlaccess}等を使用して)チェックすべきです。 @node Privilege changes, Default privileges, Request access, Privilege system @section いつ権限の変更が反映されるか @code{mysqld} の起動時、全ての許可テーブルはメモリーに読み込まれ、 この時点で有効になります。 @code{GRANT}, @code{REVOKE}, @code{SET PASSWORD} を使用して許可テーブルを 変更した場合、直にサーバに通知されます。 もし手動で許可テーブルを変更した場合(@code{INSERT}, @code{UPDATE} などで)、 @code{FLUSH PRIVILEGES} 構文か @code{mysqladmin flush-privileges} コマンド か @code{mysqladmin reload} コマンドを実行して、 サーバーに許可テーブルの読み込みを指示しなければなりません。 そうしなければ、サーバーを再起動させるまで、変更は@emph{反映されません}。 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! サーバーが許可テーブルの変更を通知した場合、既に接続している クライアントは、以下のような影響を受けます: @itemize @bullet @item テーブルとフィールドの許可の変更は、次のクライアントの要求から反映されます。 @item データベースに対する許可の変更は次の @code{USE db_name} コマンド以降から 有効になります。 @end itemize グローバル権限とパスワードの変更は、次のクライアントの接続時から反映されます。 @node Default privileges, Adding users, Privilege changes, Privilege system @section @strong{MySQL} 権限許可の初期設定 @strong{MySQL} インストール後、@code{scripts/mysql_install_db} を実行して権限のアクセス許可を初期化します。 @xref{Quick install}. @code{mysql_install_db} スクリプトは @code{mysqld} サーバーを起動し、 以下のように権限を初期化してテーブルに登録します: @itemize @bullet @item @strong{MySQL} @code{root} ユーザーはスーパーユーザーとして登録され、 全ての操作ができます。 localhostからしか接続できません。 @strong{注意:} @code{root} のパスワードの初期値は空です。 全ての人が @emph{パスワードなしで} @code{root} になれ、全ての権限許可を得ることができます。 @item @cindex Anonymous user @code{'test'} あるいは @code{'test_'} で名前がはじまっているデータベースに対して、 匿名ユーザーでもなんでもできるように許可が与えられます。 これは ローカルホストからの全てのユーザーは パスワード無しで接続ができ、 匿名ユーザーとして扱われるということです。 @item その他の要求は拒否されます。例えば、一般ユーザーは @code{mysqladmin shutdown} や @code{mysqladmin processlist} を実行できません。 @end itemize @strong{注意:} デフォルトの権限は Win32 では違います。 @xref{Win32 running}. 初期インストールの状態ではかなりアクセスが解放されているので、 インストール後最初にすることは、@strong{MySQL} @code{root} ユーザーにパスワードを設定することです。 以下のようにします(パスワードは @code{PASSWORD()} 関数を使用することをお忘れなく): @example shell> mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; mysql> FLUSH PRIVILEGES; @end example @strong{MySQL} 3.22 以上では、@code{SET PASSWORD} 構文も使用できます: @example shell> mysql -u root mysql mysql> SET PASSWORD FOR root=PASSWORD('new_password'); @end example password をセットする他の方法として、@code{mysqladmin} コマンドも使用できます: @example shell> mysqladmin -u root password new_password @end example もし最初の方法で @code{user} テーブルのパスワードを直接更新したなら、 サーバーに許可テーブルの再読み込みを行わせなければなりません(@code{FLUSH PRIVILEGES} を使用して)。 一度 @code{root} のパスワードを設定したなら、@code{root} でサーバーに接続する場合は 常にパスワードを与えなければなりません。 追加設定やテストをしているためパスワードを入れたくない場合、 @code{root} パスワードをブランクのままにしておこうと考えるかも知れませんが、 実稼働させる前には必ず設定してください。 どのようにデフォルトの権限を設定しているか、@code{scripts/mysql_install_db} 見てみてください。 これは他のユーザーを設定するときに使えるでしょう。 もし権限の初期状態を違うものにして初期化したいなら、 @code{mysql_install_db} を実行する前に編集してもよいでしょう。 もしテーブルを完全に作り直したいなら、@code{mysql} データベースのディレクトリに存在する 全ての @file{*.frm}, @file{*.MYI}, @file{*.MYD} ファイルを削除します。 (このディレクトリーはデータベースディレクトリーの下に @code{mysql} という名前で存在します。 @code{mysqld --help} とすればデータベースのディレクトリーが表示されます。) そして好みの許可状態に @code{mysql_install_db} を編集してから実行します。 @strong{注意:} @strong{MySQL} 3.22.10 以前のバージョンでは, @file{*.frm} ファイルを消してはいけません. もしうっかり消してしまった場合、 @code{mysql_install_db} を実行する前に、 @strong{MySQL} 配布からコピーしなおさ なくてはなりません。 @node Adding users, Passwords, Default privileges, Privilege system @section 新しいユーザ権限を @strong{MySQL} へ追加 ユーザーは2つの違った方法で追加できます: @code{GRANT} 構文を使用して行う方法と、 @strong{MySQL} の許可テーブルを直接操作する方法とです。 @code{GRANT} 構文の使用をお勧めします。 以下の例では、いかにして @code{mysql} クライアントを使用して新規にユーザーを登録するかを示します。 以下の例では、権限は前節で述べたデフォルト値になっているとします。 よって変更を行うためには、あなたは @code{mysqld} が走っているマシン上にログインしていなくてはなりませんし、 かつ、@strong{MySQL} @code{root} ユーザーで接続していなければなりません。 さらに @strong{MySQL} @code{root} ユーザーには @code{mysql} データベースに対して @strong{insert} 権限を持ち、 @strong{reload} のアドミニストレーター権限を持っていなければなりません。 もし @code{root} ユーザーのパスワードを変えていたならば、 @code{mysql} コマンドにパスワード指定を与えなくてはなりません。 @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 これら @code{GRANT} 構文では3つの新しいユーザを作ります: @table @code @item monty どこからでもサーバーに接続できる完全なスーパーユーザ。 しかし、@strong{MySQL} を使用する時にはパスワード @code{'some_pass'} を 使用する必要があります。 @code{monty@@localhost} と @code{monty@@"%"} の両方に @code{GRANT} 構文を 発行しなくてはならない事に注意してください。 もし @code{localhost} からの許可をした登録がないと、@code{localhost} から接続した時、 @code{mysql_install_db} が自動で作成した @code{localhost} への匿名ユーザーが優先されます。 なぜなら、 @code{Host} フィールドの値が(ブランクやワールドカード以外に)明記されており、 許可登録が MySQL 内部でソートされる時に順番が上にソートされるからです。 @item admin @code{localhost} からパスワードなしで接続できますが、@code{reload}, @code{process} の使用だけが許されます。 これは、@code{mysqladmin reload}, @code{mysqladmin refresh}, @code{mysqladmin flush-*} そして @code{mysqladmin processlist} コマンドの実行がこのユーザーに許可されます。 データベースへのアクセスは許可されていません。 しかしこれは後でテーブル @code{GRANT} 構文を発行すれば、 個々のデータベースへのアクセス権限が設定できます。 @item dummy パスワードなしで localhost からのみ、接続できるユーザー。 グローバルな権限は全て @code{'N'} に設定されます。 @code{USAGE} 権限は権限無しユーザーの設定を許可する事になります。 これは、特定データーベースに対しての許可を後から与える事を想定しています。 @end table 同じアクセス許可を @code{INSERT} 構文を使用して直接設定できます。 サーバーに許可テーブルの再読み込みを指示します: @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 @strong{MySQL} のバージョンにより、上の @code{'Y'} の数が違う事に注意してください。 (3.22.11 以前のバージョンでは項目数が少なくなります). @code{admin} ユーザーを登録で使用している @code{INSERT} の拡張は 3.22.11 以上で可能です。 スーパーユーザーを定義するためには、@code{user} テーブルの許可フィールドを @code{'Y'} にするだけでかまいません。 @code{db} や @code{host} テーブルに登録は必要無いのです。 @code{user} テーブルの許可フィールドは最後の @code{INSERT} 文で(@code{dummy} ユーザーのために) は設定されていません。これらのフィールドはデフォルト値の @code{'N'} になります。 これは @code{GRANT USAGE} が行うのと同じものです。 以下は、@code{localhost}, @code{server.domain}, @code{whitehouse.gov} から接続が可能な @code{custom} ユーザーの追加例です。 @code{custom} ユーザーは @code{bankaccount} データーベースには @code{localhost} からの接続のみを許可され、 @code{expenses} データベースには @code{whitehouse.gov} からのみ接続が許可され、 @code{customer} データベースには全てのホストから接続できます。 @code{custom} ユーザーは、 @code{stupid} というパスワードを全てのホストで使用したいとします。 このユーザーの許可を @code{GRANT} 構文で定義するには、以下のようにします: @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 許可テーブルを直接変更してこのユーザーの権限を設定するにはいかのようにします (@code{FLUSH PRIVILEGES} を最後に実行している事に注意): @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 最初の3つの @code{INSERT} 文は、 @code{custom} ユーザーがそれぞれのホストから パスワードつきで接続できるように @code{user} テーブルに追加しています。 しかしここでは権限は1つも与えられていません(権限のデフォルト値は @code{'N'} です)。 次の三つの @code{INSERT} 文は、@code{bankaccount}, @code{expenses}, @code{customer} データベースに対する該当ホストからのアクセス許可を @code{custom} ユーザーに与えるように、 @code{db} テーブルに追加しています。 許可テーブルが直接変更された場合、これらをサーバーに反映させるために、許可テーブルの 再読み込みを(@code{FLUSH PRIVILEGES}で) サーバーにつげなければなりません。 もし、あるドメインの全てのマシンに接続を許可したい場合、 以下のように @code{GRANT} 構文を発行します: @example mysql> GRANT ... ON *.* TO myusername@@"%.mydomainname.com" IDENTIFIED BY 'mypassword'; @end example 許可テーブルを直接変更するには以下のようにします: @example mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername', PASSWORD('mypassword'),...); mysql> FLUSH PRIVILEGES; @end example もちろん、@code{xmysqladmin}, @code{mysql_webadmin}, そして @code{xmysql} を使って も、権限テーブルへの値の挿入/変更/更新ができます。これらのユーティリティは @uref{http://www.mysql.com/Contrib/,Contrib directory of the @strong{MySQL} Website}. に見つけることができます。 @node Passwords, Access denied, Adding users, Privilege system @section パスワードの設定法 @cindex Passwords, setting @findex PASSWORD() 前節の例で述べた、とても重要な基本原則: @code{INSERT} か @code{UPDATE} で空ではないパスワードを設定する場合、 暗号化するために @code{PASSWORD()} 関数を使用しなくてはなりません。 これは @code{user} テーブルはプレーンテキストでなく、暗号化されたパスワードであることを要求しているからです。 この原則を忘れてしまった場合、以下のようにしてパスワードをセットしてしまうかもしれません: @example shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey','biscuit'); mysql> FLUSH PRIVILEGES; @end example これは @code{user} テーブルにプレーンテキストの @code{'biscuit'} をパスワードとして登録してしまいます。 @code{jeffrey} ユーザーでこのパスワードを使用してサーバーに接続しようとすると、 @code{mysql} クライアントは暗号化したパスワードをサーバーに送ります。 サーバーは暗号化されたパスワード(@code{'biscuit'} では@emph{ありません}) と @code{user} テーブルに登録された値(@code{'biscuit'}) を比較します。 その結果、比較は失敗し、サーバーは接続を拒否します: @example shell> mysql -u jeffrey -pbiscuit test Access denied @end example @code{user} テーブルに登録されるパスワードは暗号化されたものでなくてはなりません。 @code{INSERT} 構文は以下のようにして使用しなくてはなりません: @example mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey',PASSWORD('biscuit')); @end example @code{SET PASSWORD} 構文を使用する場合は、以下のようにしなくてはなりません: @example mysql> SET PASSWORD FOR jeffrey@@"%" = PASSWORD('biscuit'); @end example もし @code{GRANT ... IDENTIFIED BY} 構文や @code{mysqladmin password} コマンド でパスワードを設定した場合、@code{PASSWORD()} 関数は必要ありません。 両方とも、パスワードを暗号化してくれますので、 以下のように@code{'biscuit'}と与えます: @example mysql> GRANT USAGE ON *.* TO jeffrey@@"%" IDENTIFIED BY 'biscuit'; shell> mysqladmin -u jeffrey password biscuit @end example @strong{注意}: @code{PASSWORD()} がパスワードを暗号化することに注意してください。 この暗号化は UNIX のパスワードで使用されている暗号化と違うことにも留意してください。 UNIX パスワードファイルに記録されている暗号と @code{PASSWORD()} が暗号化した物が同じでも、 同じパスワードであるとは思わないでください。 @xref{User names}. @node Access denied, , Passwords, Privilege system @section 何故 @code{Access denied} エラーになるのか もし、@strong{MySQL} サーバーに接続しようとして @code{Access denied} エラーに 遭遇してしまったら、以下に記すことが問題の解決のための指標となるでしょう: @itemize @bullet @item @strong{MySQL} をインストールした後に、スクリプト @code{mysql_install_db} を実行して 許可テーブルを初期化しましたか? していなければ実行してください。@xref{Default privileges} 権限許可のテーブルが初期化されているかを試すには以下のようにします: @example shell> mysql -u root test @end example これは普通はエラーなしで接続できます。 @strong{MySQL} データベースディレクトリ内に @file{user.MYD} ファイルがあるかどうかでもチェックします。 (普通は @file{PATH/var/mysql/user.MYD} です。ここで @code{PATH} は @strong{MySQL} をインストールしたディレクトリーパスを示します。) @item 初めてインストールした後は、以下のようにしてサーバーに接続してユーザーとアクセス権を設定しなくてはなりません: @example shell> mysql -u root mysql @end example 初期状態では、@strong{MySQL} に @code{root} ユーザーをパスワードなしで登録しているので、 問題なく接続できるはずです。 しかしこれはセキュリティ上危険な状態なので、 他の @strong{MySQL} ユーザーを登録している時に、 @code{root} のパスワードを設定しておいてください。 もし @code{root} で接続しようとして以下のエラーが出た場合: @example Access denied for user: '@@unknown' to database mysql @end example これは @code{user} テーブルに、 @code{User} フィールド = @code{root} かつ @code{mysqld} がリゾルブできなかったホスト名で、クライアントが登録されていないからです。 この場合、 @file{/etc/hosts} ファイルあるいは @file{\windows\hosts} ファイルを編集して ホスト名を追加し、@code{--skip-grant-tables} オプションでサーバーをリスタートします。 @cindex @code{mysql_fix_privilege_tables} もし 3.22.11 より前の @strong{MySQL} から 3.22.11 以上にバージョンアップしたなら、 @code{mysql_fix_privilege_tables} スクリプトを実行しましたか? 実行していないなら、このエラーになります。 許可テーブルの構造が @strong{MySQL} 3.22.11 から変更され、 @code{GRANT} 構文が機能しています。 @item もし許可テーブルを直接変えて(@code{INSERT} か @code{UPDATE} 構文で)、 変更が無視されているようならば、サーバーにテーブルを再読み込みさせるために、 @code{FLUSH PRIVILEGES} 構文か @code{mysqladmin flush-privileges} コマンドを 実行する事を思い出してください。 これを実行しなかった場合、変更は次のサーバーのリスタートまで反映されません。 @code{root} ユーザーのパスワードを設定したあとでも、 権限情報を再読み込みするまでは新しいパスワードは不要です。 なぜなら、サーバーは新しいパスワードをまだ知らないからです! @code{mysqladmin reload} を行っても、権限が有効なのは、 このコマンド発行後に新しく接続したクライアントに対してだけです。 (多くの権限情報がサーバーにキャッシュされているためです) @item もしあなたの権限がセッションの途中で変更されたように思ったなら、それは スーパーユーザーが権限を変えたのかも知れません。許可テーブルの再読み込みは 新しいクライアントの接続から反映されますが、すでに接続している場合でも @ref{Privilege changes}. に示す条件下では影響を受けます。 @item テストのためには、@code{mysqld} デーモンを @code{--skip-grant-tables} オプショ ンで開始すべきです。そうすれば @strong{MySQL} 承認テーブルを変更でき、スクリプ ト @code{mysqlaccess} を、あなたの承認が働くかどうかのチェックのために使 用できます。 @code{mysqladmin flush-privileges} は @code{mysqld} デーモンに新しい承認テーブルの 使用を開始するように知らせます。これは @code{--skip-grant-tables} オプションを上書きします。 ユーザーの許可テーブルを読み込ませるのに、サーバーを落して立ち上げ直す必要はありません。 @item Perl, PHP, Python または ODBC でアクセスの問題があった場合も、常に @code{mysql -u user_name db_name} または @code{mysql -u user_name -pyour_pass db_name} で、 権限の問題をテストしてください。(@code{-p} と password の間には空 白がないことに注意してください。@code{--password=your_password} 構文でも パスワードを与えられます) @code{mysql} クライアントで接続できるなら、アクセスの権限の設定の問題ではなく、 プログラムの問題です。 @item もしあなたのパスワードが働かないのであれば、 @code{INSERT}, @code{UPDATE}, @code{SET PASSWORD} 構文でパスワードを設定するとき @code{PASSWORD()} 関数を使用しなければならないことを思い出してください。 しかし @code{PASSWORD()} 関数は、@code{GRANT ... INDENTIFIED BY} 構文や @code{mysqladmin password} コマンドでは不要です。 @xref{Passwords}. @item @code{localhost} はローカルのホスト名です。 もしクライアントがホストを指定せずに接続してきた場合、@code{localhost} がデフォルトで使用されます。 しかし、 MIT-pthreads を使用している場合、@code{localhost} への接続は失敗します。 (@code{localhost} への接続は、Unixソケットを使用しますが、 MIT-pthreads が ソケット接続をサポートしていないためです。) この問題が起きるシステムでは、サーバー名を指定するために @code{--host} オプションを使用すべきです。 これは TCP/IP 接続を使用して @code{mysqld} サーバーに接続します。 この場合、@code{user} テーブルに、サーバーの実ホスト名を登録しておかなくてはなりません。 (これはクライアントプログラムをサーバーと同じホスト上で動かしている場合真となります) @item @code{mysql -u user_name db_name} を使用してデータベースに接続しているときに @code{Access denied} エラーが発生した場合、@code{user} テーブルの設定違いが考えられます。 @code{mysql -u root mysql} を実行し、以下の SQL 文を試してください: @example mysql> SELECT * FROM user; @end example @code{Host} と @code{User} にあなたのコンピュータ名と @strong{MySQL} ユーザー名にマッチする登録がなされていなければなりません。 @item @code{Access denied} エラーは、どのユーザーで接続してきたか、どのホストから接続しようとしているか、パスワードを使用しているのかをメッセージに出力します。 通常、エラーになっているホスト名とユーザー名がマッチするエントリが @code{user} テーブルに一つはなければなりません。 @item 他のホストから @strong{MySQL} サーバーに接続を試みた時に以下のエラーが出た場合、 @code{user} テーブルにあなたがアクセスしているホストにマッチする行がありません: @example Host ... is not allowed to connect to this MySQL server @end example @code{mysql} コマンドをサーバーのホスト上で使用して、 @code{user}, @code{db}, @code{host} テーブルに、接続しようとしている ユーザー名/ホスト名 を 加えれば解決できるでしょう。 もしサーバーが @strong{MySQL} 3.22 ではなく、接続しようとしているホストの IP もホスト名もわからない場合、 @code{user} テーブルの @code{Host} フィールドに @code{'%'} を設定し、 @code{mysqld} を @code{--log} オプションで再起動してください。 そしてクライアントホストから接続すれば、@strong{MySQL} のログファイルに そのホストの情報が記録されているはずです。 それがわかれば、先に設定した @code{user} テーブルの @code{Host} フィールドの @code{'%'} を ログに記録されたホスト名に置き換えます。(しかしこれはシステムを危険にさらします) @item @code{mysql -u root test} は動いたものの @code{mysql -h your_hostname -u root test} が @code{Access denied} を返した場合、 @code{user} テーブルに正しいホスト名が使用されていないと思われます。 @code{user} テーブルの @code{Host} フィールドにホスト名を確定できる形で指定していないか、 使用しているシステムのリゾルブが FQDN (or vice-versa) を返しているかだと思われます。 例えば、@code{user} テーブルに @code{'tcx'} ホストの定義があったとして、 DNS が @strong{MySQL} に @code{'tcx.subnet.se'} をホスト名として返した場合、 これは動きません。 @code{user} テーブルの @code{Host} フィールドの値に、あなたのホストの IP 番号を加えてください。 (@code{user} テーブルの @code{Host} の値にワイルドカードを使用することができます。@code{'tcx.%'} のように。 しかしホスト名の値を @samp{%} 文字で終わらせる設定は、@emph{安全ではなく}、@emph{推奨されません}) @item もし @code{mysql -u user_name test} が動作し @code{mysql -u user_name other_db_name} が 動作しない場合は、@code{db} テーブルに @code{other_db_name} のエントリが 登録されていません。 @item @code{mysql -u user_name db_name} はザーバー上では動作するが、 @code{mysql -u host_name -u user_name db_name} がクライアントホスト上で動作しない場合、 @code{user} テーブルか @code{db} テーブルにクライアントホストの名前が登録されていません。 @item @code{Access denied} の原因がもし上記に当てはまらない場合は、 @code{user} テーブルから @code{Host} にワイルドカードを使用しているエントリを全て消去してみてください。(@samp{%} や @samp{_} を含む値です) よくある間違いは、@code{localhost} に対して @code{localhost} と同じマシン上から の接続を許可すると考えて @code{Host}=@code{'%'} と @code{User}=@code{'some user'} を登録することです。 これは動きません。なぜなら、デフォルトの権限に @code{Host}=@code{'localhost'} と @code{User}=@code{''} が含まれているからです。 @code{Host} の値が @code{'localhost'} の場合、これは @code{'%'} よりも 具体的に指定されているので、@code{localhost} からの接続にはこちらの方が 使用されるのです! 正しい指定の仕方は、二番目の登録として @code{Host}=@code{'localhost'} と @code{User}=@code{'some_user'} を追加するか、 あるいは、@code{Host}=@code{'localhost'} と @code{User}=@code{''} を削除することです。 @item もし以下のエラーが出た場合 @code{db} か @code{host} テーブルに問題があるのかもしれません。: @example Access to database denied @end example もし @code{db} テーブルに @code{Host} フィールドが空の登録がある場合には、 @code{host} テーブル中に、@code{db} テーブルに登録されている ホストを明記した物が一つ以上あるかどうかを確認してください。 もし @code{SELECT ... INTO OUTFILE} や @code{LOAD DATA INFILE} SQL 文を 使用している時にこのエラーが出る場合、 @code{user} テーブルのあなたの登録に @strong{file} 権限が 許可されていないと思われます。 @item @cindex Configuration files @cindex Environment variables @tindex .my.cnf file クライアントプログラムは接続に際して、 設定ファイルで設定された値か環境変数の値を使用することに注意してください。 もしクライアントプログラムが誤った値を接続に使用しているようなら、 環境変数とホームディレクトリにある @file{.my.cnf} ファイルを確認してください。 もちろんシステムワイドの @strong{MySQL} 設定ファイルも、パラメターが記述されていないか、 チェックしてみてください。@xref{Option files}. もしクライアントをオプションなしで起動していて @code{Access denied} がでるなら、 オプションファイルに古いパスワードが書かれているか確認してください。 @xref{Option files}. @item もし全て失敗するなら、@code{mysqld} デーモンをデバッグオプションで起動してください。 例えば、@code{--debug=d,general,query}。これはコネクションに試みたホストやユーザーの情報、 また実行したコマンドを表示します。 @xref{Debugging server}. @item もし @strong{MySQL} の権限許可についてその他の問題が起こり、 メーリング・リストに問題をポストしなくてはいけないと感じれば、 いつも @strong{MySQL} 許可テーブルのダンプを提供して下さい。 @code{mysqldump mysql} コマンドでダンプできます。 いつものように、 @code{mysqlbug} スクリプトでポストしてください。@xref{Bug reports}. ときにはは、 @code{mysqldump} を実行するために、 @code{mysqld} を @code{--skip-grant-tables} オプションで実行しないと いけないかもしれません。 @end itemize @node Reference, Table types, Privilege system, Top @chapter @strong{MySQL} 言語リファレンス @menu * Literals:: リテラル:文字列と数値をどのように書くか? * Variables:: ユーザ変数 * Column types:: フィールド型 * Functions:: 関数 * CREATE DATABASE:: @code{CREATE DATABASE} 構文 * DROP DATABASE:: @code{DROP DATABASE} 構文 * CREATE TABLE:: @code{CREATE TABLE} 構文 * ALTER TABLE:: @code{ALTER TABLE} 構文 * DROP TABLE:: @code{DROP TABLE} 構文 * OPTIMIZE TABLE:: @code{OPTIMIZE TABLE} 構文 * CHECK TABLE:: @code{CHECK TABLE} syntax * REPAIR TABLE:: @code{REPAIR TABLE} syntax * DELETE:: @code{DELETE} 構文 * SELECT:: @code{SELECT} 構文 * JOIN:: @code{JOIN} 構文 * INSERT:: @code{INSERT} 構文 * REPLACE:: @code{REPLACE} 構文 * LOAD DATA:: @code{LOAD DATA INFILE} 構文 * UPDATE:: @code{UPDATE} 構文 * USE:: @code{USE} 構文 * FLUSH:: @code{Flush} 構文 (キャッシュのクリア) * KILL:: @code{KILL} 構文 * SHOW:: @code{SHOW} 構文 (テーブルやフィールドなどについての情報を得る) * EXPLAIN:: @code{EXPLAIN} 構文 (@code{SELECT}についての情報を得る ) * DESCRIBE:: @code{DESCRIBE} 構文 (フィールド名についての情報を得る) * COMMIT:: * LOCK TABLES:: @code{LOCK TABLES/UNLOCK TABLES} 構文 * SET OPTION:: @code{SET OPTION} 構文 * GRANT:: @code{GRANT} と @code{REVOKE} 構文 * CREATE INDEX:: @code{CREATE INDEX} 構文 * DROP INDEX:: @code{DROP INDEX} 構文 * Comments:: Comment 構文 * CREATE FUNCTION:: @code{CREATE FUNCTION} 構文 * Reserved words:: Is @strong{MySQL} picky about reserved words? @end menu @cindex Strings @cindex Strings, escaping characters @node Literals, Variables, Reference, Reference @section リテラル:文字列と数値をどのように書くか? @menu * String syntax:: Strings * Number syntax:: Numbers * 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 文字列 文字列は文字の並びです。引用符(@samp{'})または二重引用符(@samp{"})で括ら れます(後者は ANSI モードで実行していない場合のみ)。 例: @example 'a string' "another string" @end example 文字列中では、いくつかのシーケンスは特別な意味を持ちます。これらのシーケ ンスのそれぞれは@emph{エスケープ文字}として知られるバックスラッシュ (@samp{\})で始まります。@strong{MySQL} は次のエスケープシーケンスを認識 します。 @c these aren't really functions, but that's probably the most reasonable index @table @code @findex \0 (ASCII 0) @findex NUL @item \0 ASCII 0 (@code{NUL}) 文字。 @findex \n (newline) @findex newline (\n) @item \n 改行文字。 @findex \t (tab) @findex tab (\t) @item \t タブ文字。 @findex \r (carriage return) @findex return (\r) @findex carriage return (\r) @item \r リターン文字。 @findex \b (backspace) @findex backspace (\b) @item \b バックスペース文字。 @findex \' (single quote) @findex single quote (\') @item \' 引用符(@samp{'})。 @findex \" (double quote) @findex double quote (\") @item \" 二重引用符(@samp{"})。 @findex \\ (escape) @findex escape (\\) @item \\ バックスラッシュ(@samp{\})文字。 @findex % (wildcard character) @findex Wildcard character (%) @item \% @samp{%} 文字。これは @samp{%} がワイルドカード文字として解釈される文脈 で、@samp{%} そのものを検索するために使用されます。 @xref{String comparison functions}. @findex _ (wildcard character) @findex Wildcard character (_) @item \_ @code{_} 文字。これは @samp{_} がワイルドカード文字として解釈される文脈 で、@code{_} そのものを検索するために使用されます。 @xref{String comparison functions}. @end table いくつかの文字列文脈で @samp{\%} または @samp{\_} を使用すると、これらは文 字列 @samp{%} と @samp{_} ではなく、@samp{\%} と @samp{\_} を返します。 @noindent 文字列中に引用符を含める方法はいくつかあります: @itemize @bullet @item @samp{'} で括られる文字列中の @samp{'} は @samp{''} として書くことができ ます。 @item @samp{"} で括られる文字列中の @samp{"} は @samp{""} として書くことができ ます。 @item 引用符の前にエスケープ文字 (@samp{\}) を置くことができます。 @item @samp{"} で括られた文字列中の @samp{'} は特別扱いの必要はなく、二重にし たり、エスケープする必要はありません。同じように、@samp{'} で括られた文 字列中の @samp{"} は特別扱いの必要はありません。 @end itemize 次の @code{SELECT} ステートメントは、クォートとエスケープがどのように働 くかを示します: @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 バイナリデータを @code{BLOB} フィールドに挿入したい場合、次の文字をエスケープ シーケンスで表す必要があります: @table @code @item NUL ASCII 0。@samp{\0} (バックスラッシュと ASCII @samp{0} 文字) に置き換える べきです。 @item \ ASCII 92, バックスラッシュ。@samp{\\} と表記してください。 @item ' ASCII 39, 引用符。@samp{\'} と表記してください。 @item " ASCII 34, 二重引用符。@samp{\"} と表記してください。 @end table @cindex Quoting @cindex @code{BLOB}, inserting binary data @findex mysql_escape_string() @findex DBI->quote C コードを書く場合、@code{INSERT} 節で文字をエスケープするために、C API 関数 @code{mysql_escape_string()} を使用できます。@xref{C API function overview}. Perl では、@code{DBI} パッケージの @code{quote} メソッドを使 用して、特殊文字を適当なエスケープシーケンスに変換できます。@xref{Perl DBI Class, , Perl @code{DBI} Class}. 上記の特殊文字のどれかを含む可能性のある全ての文字列について、エスケープ 関数を使用すべきです! @node Number syntax, Hexadecimal values, String syntax, Literals @subsection 数値 整数は数字の並びで表現されます。 浮動小数点は @samp{.} で小数を分割します。 どちらの型も負数を表すために @samp{-} を前につけます。 正当な数値の例: @example 1221 0 -32 @end example 有効な浮動小数点の例: @example 294.42 -32032.6809e+10 148.00 @end example 整数が浮動小数点の文脈で使用されるかもしれません; この場合、浮動小数点に 変換されます。 @tindex Hexadecimal values @node Hexadecimal values, NULL values, Number syntax, Literals @subsection 16進法の値 @strong{MySQL} は16進法の値をサポートします。 数値の文脈では、これらは整数(64ビット精度)のように振る舞います。 文字列の文脈では、hexの桁のそれぞれのペアが文字に変換された バイナリー文字のように振る舞います。 @example mysql> SELECT 0xa+0 -> 10 mysql> select 0x5061756c; -> Paul @end example 16進数表記は、ODBC において BLOB の値を与えるためにしばしば使用されます。 @tindex NULL value @node NULL values, Legal names, Hexadecimal values, Literals @subsection @code{NULL} 値 @code{NULL} は ``no data'' を意味し、数値型の @code{0} や文字列型の空文 字列とは異なることに注意してください。 @xref{Problems with NULL, , Problems with @code{NULL}}. テキストファイルの読み込みや書き出し時に、@code{NULL} は @code{\N} で 表現されます。 (@code{LOAD DATA INFILE}, @code{SELECT ... INTO OUTFILE}). @xref{LOAD DATA, , @code{LOAD DATA}}. @node Legal names, , NULL values, Literals @subsection データベース名、テーブル名、インデックス名、フィールド名、エイリアス名 @menu * Name case sensitivity:: Case sensitivity in names @end menu データベース名、テーブル名、インデックス名、フィールド名、エイリアス名は @strong{MySQL} では全て同じ規則に基づきます: @tindex Quoting of identifiers @tindex ` @tindex " 注意: 規則は @strong{MySQL} 3.23.6 で変更されました。それは識別子(データベー ス名、テーブル名、フィールド名)の @code{`} でのクォートを導入した時です (ANSI モードで実行する場合は、@code{"} も識別子をクォートするために働きま す)。 @multitable @columnfractions .15 .7 .78 @item @strong{識別子} @tab @strong{最大長} @tab @strong{許される文字} @item データベース @tab 64 @tab ディレクトリ名として許されるすべての文字。@code{/} を除く。 @item テーブル @tab 64 @tab ファイル名として許されるすべての文字。@code{/} と @code{.} を除く。 @item フィールド @tab 64 @tab すべての文字 @item エイリアス @tab 255 @tab すべての文字 @end multitable 注意: 上記に加え、識別子内には ASCII(0) と ASCII(255) を持てません。 注意: 識別子が制限された単語であったり特殊文字を含む場合は、それを使用する 時には常に @code{`} でクォートする必要があります: @example SELECT * from `select` where `select`.id > 100; @end example @strong{MySQL} の前のバージョンでは、名前の規則は次に従います: @itemize @bullet @item 名前は、現在の文字セットのアルファベットと数字文字から成り、@samp{_} と @samp{$} も含みます。デフォルト文字セットは ISO-8859-1 Latin1 ですが、 これは @code{mysqld} に @code{--default-character-set} オプションを 与えることで変更できます. (3.23.14 以上の場合のみ。 それ以前のバージョンでは @strong{MySQL} 再コンパイルが必要) @xref{Character sets}. @item 名前は、名前として正しい任意の文字で始めることができます。特に、名前は数 字で始めることができます(これは他の多くのシステムと異なります!)。しかし、 数字@emph{だけ}の名前にする事はできません。 @item 名前の中に @samp{.} 文字を使用することはできません。フィールドを参照できるよう に形式を拡張するために使用されるためです(後述)。 @end itemize @code{1e} のような名前は使用しないことを勧めます。@code{1e+1} のような式が あいまいだからです。これは、式 @code{1e + 1} として、または数値 @code{1e+1} として解釈されます。 @strong{MySQL} では次の形式のいずれかを使用してフィールドを参照できます: @multitable @columnfractions .35 .65 @item @strong{フィールドの参照方法} @tab @strong{意味} @item @code{col_name} @tab クエリ中で使用されるテーブル内に存在している @code{col_name} という名前のフィールド @item @code{tbl_name.col_name} @tab 現在のデータベースのテーブル @code{tbl_name} 内のフィールド @code{col_name} @item @code{db_name.tbl_name.col_name} @tab データベース @code{db_name} のテーブル @code{tbl_name} 内のフィールド @code{col_name}。この形式は 3.22 以降 で有効です。 @item @code{`column_name`} @tab キーワードであったり特殊文字を含むフィールド。 @end multitable 参照が曖昧でないならば、ステートメント中のフィールド参照の前に @code{tbl_name} または @code{db_name.tbl_name} を記述する必要はありません。例えば、テー ブル @code{t1} と @code{t2} がそれぞれフィールド @code{c} を含み、@code{t1} と @code{t2} の両方を使用する @code{SELECT} ステートメントで @code{c} を取 り出すとします。この場合、@code{c} はステートメントで使用されるテーブル 間で唯一でないので曖昧です。そのため、@code{t1.c} または @code{t2.c} と 記述するこよによりどちらのテーブルを意味するかを示す必要があります。同様 に、データベース @code{db1} のテーブル @code{t} とデータベース @code{db2} のテーブル @code{t} から取り出す場合、これらのテーブル中の項 目は、@code{db1.t.col_name} と @code{db2.t.col_name} として参照する必要 があります。 @cindex ODBC compatibility @cindex Compatibility, with ODBC 構文 @code{.tbl_name} は現在のデータベース内のテーブル @code{tbl_name} を意味します。この構文はいくつかの ODBC が @samp{.} 文字をテーブル名の前 に置くために許されています。 @node Name case sensitivity, , Legal names, Legal names @subsubsection 名前のケース依存性 @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 @strong{MySQL} では、データベースとテーブルは、ディレクトリと そのディレクトリ中のファイルに対応します。そのため、下で動作するオペレー ティングシステムのケース依存性は、データベースとテーブル名のケース依存性を決定します。 データベース名とテーブル名は Unix ではケース依存で、Win32 ではケース非依 存です。 @strong{注意:} Win32 ではデータベース名とファイル名はケース非依存ですが、 同じクエリ内で、データベースやテーブルを異なるケースを使用して参照すべき ではありません。 以下のクエリは動きません。なぜなら @code{my_table} と @code{MY_TABLE} の両方を 参照しているからです: @example mysql> SELECT * FROM my_table WHERE MY_TABLE.col=1; @end example フィールド名は全ての場合でケース非依存です。 テーブルの別名はケース依存です。 以下のクエリは動きません。なぜなら @code{a} と @code{A} のエイリアスを両方 参照しているからです: @example mysql> SELECT col_name FROM tbl_name AS a WHERE a.col_name = 1 OR A.col_name = 2; @end example フィールドのエイリアス名はケース非依存です。 @node Variables, Column types, Literals, Reference @section ユーザー変数 @strong{MySQL} は、@code{@@variablename} 構文でスレッド固有の変数をサポー トします。変数名は現在の文字セットのアルファベットと数字、それに @samp{_}、@samp{$}、@samp{.} 文字からなります。デフォルト文字セットは ISO-8859-1 Latin1 です。 これは @code{mysqld} に @code{--default-character-set} オプションを 与えることで変更できます. (3.23.14 以上の場合のみ。 それ以前のバージョンでは @strong{MySQL} 再コンパイルが必要) @xref{Character sets}。 変数は初期化する必要はありません。デフォルトでは @code{NULL} であり、整数 値、実数値、文字列値を格納できます。すべてのスレッド変数は、スレッドが終了 すると自動的に解放されます。 @code{SET} 構文で変数を設定できます: @example SET @@variable= @{ integer expression | real expression | string expression @} [,@@variable= ...]. @end example @code{@@variable:=expr} 構文で、式中で変数を設定することも可能です: @example select @@t1:=(@@t2:=1)+@@t3:=4,@@t1,@@t2,@@t3; +----------------------+------+------+------+ | @@t1:=(@@t2:=1)+@@t3:=4 | @@t1 | @@t2 | @@t3 | +----------------------+------+------+------+ | 5 | 5 | 1 | 4 | +----------------------+------+------+------+ @end example (我々は @code{:=} 構文を使用する必要がありました。@code{=} は比較のために 予約されていたからです。) ユーザー変数は式が許される場所で使用できます。注意: これは現在、 @code{SELECT} ステートメントの @code{LIMIT} 節、@code{LOAD DATA} ステート メントの @code{IGNORE number LINES} 節のように、数値が明示的に要求される文 脈での使用を含みません。 @strong{注意:} @code{SELECT} ステートメントでは、それぞれの式はクライアン トに送られた時にだけ評価されます。これは、@code{SELECT} 部で設定された変数 を必要とする式を参照する @code{HAVING}, @code{GROUP BY}, @code{ORDER BY} 節ができないことを意味します。例えば、次のステートメントは期待通りには動作 しません: @example SELECT (@@aa:=id) AS a, (@@aa+3) AS b FROM table_name HAVING b=5; @end example この理由は、@code{@@aa} が現在のレコードの値ではなく、前に受け取ったレコー ドの @code{id} の値になるからです。 @node Column types, Functions, Variables, Reference @section フィールド型 @strong{MySQL}は多くのフィールド型をサポートしており、それらは3つのカテゴリにグループ化されます: 数値型、日付及び時間型、そして文字列(文字)型。 この章ではまず、利用できる型の概要から始まり、それから各カテゴリの各フィールド型の所要記憶容量の要約と、型の属性についてのより詳細な情報を提供します。 概要は意図的に簡潔にまとめています。値として指定できる書式のようなフィールド型固有の付加情報は、詳細の説明部にて調べて下さい。 @strong{MySQL}でサポートされるフィールド型は以下に示す通りです。後に続く文字の意味は説明のために使われます: @table @code @item M 最大表示サイズを意味します。最大の表示桁数は 255. @item D 浮動小数点数型に適用され、小数点以下の桁数を表します。 最大の値は 30 ですが、これは @code{M}-2 より大きくなってはいけません。 @end table 中カッコ(@samp{[}及び@samp{]})は型定義の一部であり、それがオプションであることを表します。 @tindex Types @c The @w{-number} stuff keeps a linebreak from occurring between @c the - and number. もしあるフィールドに @code{ZEROFILL} を指定した場合、 @strong{MySQL} は自動で @code{UNSIGNED} 属性をそのフィールドに 追加します。 @table @code @tindex TINYINT @item TINYINT[(M)] [UNSIGNED] [ZEROFILL] とても小さい整数。符号つきの範囲は @code{-128}〜@code{127}。符号なしの範囲は @code{0}〜@code{255}。 @tindex SMALLINT @item SMALLINT[(M)] [UNSIGNED] [ZEROFILL] 小さい整数。符号つきの範囲は @code{-32768}〜@code{32767}。符号なしの範囲は @code{0}〜@code{65535}。 @tindex MEDIUMINT @item MEDIUMINT[(M)] [UNSIGNED] [ZEROFILL] 中間の整数。符号ありの範囲は @code{-8388608}〜@code{8388607}。符号なしの範囲は @code{0}〜@code{16777215} @tindex INT @item INT[(M)] [UNSIGNED] [ZEROFILL] 通常の整数。符号ありの範囲は @code{-2147483648}〜@code{2147483647}。符号なしの範囲は @code{0}〜@code{4294967295} @tindex INTEGER @item INTEGER[(M)] [UNSIGNED] [ZEROFILL] これは、@code{INT}の同義語です。 @tindex BIGINT @item BIGINT[(M)] [UNSIGNED] [ZEROFILL] 大きい整数。符号ありの範囲は @code{-9223372036854775808}〜@code{9223372036854775807}。 符号なしの範囲は @code{0}〜@code{18446744073709551615}。 全ての演算は符合付き @code{BIGINT} または @code{DOUBLE} で行われるため、 符合無しの @code{9223372036854775807} (63 bits) よりも大きな整数を ビット関数以外で使用すべきではありません! @code{-}、@code{+}及び@code{*}は、両方の引数が@code{INTEGER}値の時、@code{BIGINT}演算を使うことに注意して下さい!これは、2つの大きな整数のかけ算を行なう(又は整数を返す関数の結果が大きな整数である)時、結果が@code{9223372036854775807}よりも大きい場合に予期しない結果を受け取ることがあるということを意味しています。 @tindex FLOAT(precision) @item FLOAT(precision) [ZEROFILL] 浮動小数点数。符号なしにはできません。単精度浮動小数点数では @code{precision} が @code{<=24} で、倍精度浮動小数点数では 25〜53 の間です。 これらの型は次で述べる@code{FLOAT}や@code{DOUBLE}型に似ています。 @code{FLOAT(X)}は、@code{FLOAT}及び@code{DOUBLE}型に一致する同じ範囲を持っていますが、 表示サイズや小数点以下桁数が定義されません。 @strong{MySQL} 3.23 では、これは正しい浮動小数点です。前の @strong{MySQL} バージョンでは, @code{FLOAT(precision)} は常に小数部は2桁で した。 @cindex ODBC compatibility @cindex Compatibility, with ODBC この構文は ODBC 互換です。 @tindex FLOAT @tindex FLOAT(M,D) @item FLOAT[(M,D)] [ZEROFILL] 小さい浮動小数点数。符号なしにはできません。 範囲は @code{@w{-3.402823466E+38}}〜@code{@w{-1.175494351E-38}}、 @code{0}、 @code{@w{1.175494351E-38}}〜@code{3.402823466E+38}です。 M は表示幅で D は小数部桁数です。引数が無いか引数が24以下の @code{FLOAT} は単精度浮動小数点数を意味します。 @tindex DOUBLE @tindex FLOAT(precision) @item DOUBLE[(M,D)] [ZEROFILL] 通常の浮動小数点数。符号なしにはできません。 範囲は @code{@w{-1.7976931348623157E+308}}〜@code{@w{-2.2250738585072014E-308}}、 @code{0}、@code{2.2250738585072014E-308}〜@code{1.7976931348623157E+308}です。 M は表示幅で D は小数部桁数です。引数が無いか @code{DOUBLE} か、25 <= X <= 53 である @code{FLOAT(X)} は倍精度浮動小数点数を意味します。 @tindex DOUBLE PRECISION @tindex REAL @item DOUBLE PRECISION[(M,D)] [ZEROFILL] @itemx REAL[(M,D)] [ZEROFILL] これらは@code{DOUBLE}の同義語です。 @tindex DECIMAL @item DECIMAL[(M[,D])] [ZEROFILL] パック無し浮動小数点数。符号なしにはできません。@code{CHAR}フィールドのように振舞います。`パック無し'は、数値が文字列として格納されることを意味し、数値のそれぞれの桁、小数点、及び負数での@samp{-}符号に1文字使用します。 @code{D}が0の時、値は小数点や小数部を持ちません。@code{DECIMAL}値の最大範囲は@code{DOUBLE}と同じですが、実際の範囲は@code{DECIMAL}フィールドに与えられた@code{M}及び@code{D}の選択に強制されます。 @code{D} を省略した場合は 0 に設定されいます。@code{M} を省略した場合は 10 に設定されます。 @strong{MySQL} 3.22 では、 @code{M} 引数は符号や小数点を含みます。 @tindex NUMERIC @item NUMERIC(M,D) [ZEROFILL] @code{DECIMAL}と同じ。 @tindex DATE @item DATE 日付。サポートされる範囲は@code{'1000-01-01'}から@code{'9999-12-31'}まで。 @strong{MySQL}は@code{'YYYY-MM-DD'}の書式で@code{DATE}値を表示しますが、@code{DATE}フィールドへの値の割当ては、文字列もしくは数値のいずれかの使用が許されます。 @tindex DATETIME @item DATETIME 日付と時刻の組み合わせ。サポートされる範囲は@code{'1000-01-01 00:00:00'}〜@code{'9999-12-31 23:59:59'}です。@strong{MySQL}は@code{DATETIME}値を@code{'YYYY-MM-DD HH:MM:SS'}という書式で表示しますが、@code{DATETIME}フィールドへの値の割当ては、文字列もしくは数値のいずれかの使用が許されます。 @tindex TIMESTAMP @item TIMESTAMP[(M)] タイムスタンプ。範囲は@code{'1970-01-01 00:00:00'}〜@code{2106}年末までです。@strong{MySQL}は@code{TIMESTAMP}値を@code{YYYYMMDDHHMMSS}、@code{YYMMDDHHMMSS}、@code{YYYYMMDD}又は@code{YYMMDD}という書式で表示し、それは@code{M}に@code{14}(もしくは誤ってそれ以上の値を指定した時)、@code{12}、@code{8}又は@code{6}のいずれが指定されたかに依存します。しかしながら@code{TIMESTAMP}フィールドへの値の割当ては、文字列もしくは数値のいずれかの使用が許されます。 @code{TIMESTAMP}フィールドは、最後に操作された時刻を自動的に設定するので、@code{INSERT}や@code{UPDATE}操作の時刻を記録するのに役立ちます。 @code{NULL}値を与えることによっても、現在時刻を設定できます。 @xref{Date and time types}。 @tindex TIME @item TIME 時間。範囲は@code{'-838:59:59'}〜@code{'838:59:59'}です。 @strong{MySQL}は@code{TIME}値を@code{'HH:MM:SS'}という書式で表示しますが、@code{TIME}フィールドへの値の割当ては、文字列もしくは数値のいずれかの使用が許されます。 @tindex YEAR @item YEAR[(2|4)] 年。2桁または4桁形式(デフォルトは4桁)。許される値は、4桁形式では @code{1901}〜@code{2155}, @code{0000} で、2桁形式(70〜69)では 1970〜2069 です。@strong{MySQL} は @code{YEAR} 値を @code{YYYY} 形式で表示しますが、 @code{YEAR} フィールドへの値の割り当ては文字列と数字のどちらでも使用できま す。(@code{YEAR} は @strong{MySQL} 3.22 での新しい型です。) @tindex NATIONAL CHAR @tindex NCHAR @tindex CHAR @tindex CHARACTER @item [NATIONAL] CHAR(M) [BINARY] 固定長文字列で、格納時には必ず指定された長さまで右側に空白を埋めます。 @code{M}の範囲は 1 から 255 文字です。後続の空白は値の取り出し時に削除され ます。@code{BINARY} キーワードが与えられない場合、@code{CHAR} 値のソートと 比較は、デフォルト文字セットに従ってケース非依存の方法で行なわれます。 @code{NATIONAL CHAR} (短い形式は @code{NCHAR}) は、ANSI SQL で、CHAR フィー ルドがデフォルト文字セットを使用することを定義する方法です。これは @code{MySQL} ではデフォルトです。 @code{CHAR} は @code{CHARACTER} の略記です。 @strong{MySQL} は @code{CHAR(0)} 型のフィールドの生成を許します。これは主 に、実際にはもう値が使われていないフィールドが存在することに依存しているよ うないくつかの古いアプリケーションに対応する必要がある時に便利です。2つの 値だけを取ることができるフィールドを必要とする時にもとても良いことです: @code{NOT NULL} として定義されていない @code{CHAR(0)} は1ビットだけを占有 し、2つの値だけを取ることができます: @code{NULL} または @code{""}。 @tindex CHARACTER VARYING @tindex CHAR VARYING @tindex VARCHAR @item [NATIONAL] VARCHAR(M) [BINARY] 可変長文字列。 注意: 後続の空白は格納時に削除されます(これは ANSI SQL 仕様と異なります)。 @code{M}の範囲は 1 から 255 文字です。 @code{BINARY} キーワードが与えられない場合、ソートと比較はケースに依存しません。 @xref{Silent column changes}. @code{VARCHAR} は @code{CHARACTER VARYING} の略記です。 @tindex TINYBLOB @tindex TINYTEXT @item TINYBLOB @itemx TINYTEXT 最大長 255 (2^8 - 1) 文字の @code{TEXT}/@code{BLOB}。@xref{Silent column changes}. @tindex BLOB @tindex TEXT @item BLOB @itemx TEXT 最大長 65535 (2^16 - 1) 文字の @code{TEXT}/@code{BLOB}。@xref{Silent column changes}. @tindex MEDIUMBLOB @tindex MEDIUMTEXT @item MEDIUMBLOB @itemx MEDIUMTEXT 最大長 16777215 (2^24 - 1) 文字の @code{TEXT}/@code{BLOB}。@xref{Silent column changes}. @tindex LONGBLOB @tindex LONGTEXT @item LONGBLOB @itemx LONGTEXT 最大長 4294967295 (2^32 - 1) 文字の @code{TEXT}/@code{BLOB}。@xref{Silent column changes}. @tindex ENUM @item ENUM('value1','value2',...) 列挙。 対象となる文字列は、値を一つだけ持ち、値リスト@code{'value1', 'value2',...}(又は@code{NULL})から選ばれます。@code{ENUM}は最大65535個の固有値を持つことができます。 @tindex SET @item SET('value1','value2',...) 組。 対象となる文字列は0以上の値を持ち、それぞれ値リスト@code{'value1', 'value2',...}から選ばれなければなりません。 @code{SET}は、最大 64個の要素を持つことができます。 @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 * Casts:: Cast operators * 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 フィールドタイプの所要容量 @strong{MySQL}がサポートする各フィールドタイプ毎の所要容量を、カテゴリ別に以下に記述します。 @subheading 数値タイプ @multitable @columnfractions .35 .65 @item @strong{フィールドタイプ} @tab @strong{所要容量} @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 X <= 24 の場合 4、25 <= X <= 53 の場合 8 @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{M < D} の場合 @code{D}+2) @item @code{NUMERIC(M,D)} @tab @code{M} bytes (@code{M < D} の場合 @code{D}+2) @end multitable @subheading 日付と時間タイプ @multitable @columnfractions .35 .65 @item @strong{フィールドタイプ} @tab @strong{所要容量} @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 文字列タイプ @multitable @columnfractions .35 .65 @item @strong{フィールドタイプ} @tab @strong{所要容量} @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, 列挙値の数に依存 (最大値は 65535 ) @item @code{SET('value1','value2',...)} @tab 1, 2, 3, 4 or 8 bytes, 要素の数に依存 (最大要素 64 ) @end multitable @code{VARCHAR}、@code{BLOB}、及び@code{TEXT}型は可変長型であり、所要容量は、フィールドのとり得る最大サイズというよりはむしろフィールド値の実際の長さに依存します(前の表で@code{L}と表しました)。 例えば、@code{VARCHAR(10)}フィールドは、最大10文字分の長さの文字列を保持することが出来ます。実際の所要容量は、文字列の長さ(@code{L})と、その長さを記録するための1バイトを加えます。文字列@code{'abcd'}においては、@code{L}は4で、所要容量は5バイトです。 @code{BLOB}と@code{TEXT}型は、フィールド値の長さを記録するのに、1、2、3、又は4バイト必要とし、型のとり得る最大の長さに依存します。 テーブルが可変長フィールド型を含む場合、そのレコードフォーマットもまた可変長となるでしょう。 テーブルが作成された時、@strong{MySQL}は確かな条件の下、フィールドを可変長タイプから固定長タイプへ変更し、副作用を起こすことに注意して下さい。 @code{ENUM}オブジェクトのサイズは、異なる列挙値の数によって決められます。 列挙する数が255以内では、1バイトが使用されます。 列挙する数が65535以内では、2バイトが使用されます。 @code{SET}オブジェクトのサイズは、異なる要素の数によって決められます。 組のサイズを@code{N}とすると、オブジェクトは@code{(N+7)/8}バイトを占有し、1、2、3、4又は8バイトに切上げられます。 1つの@code{SET}は、最大64要素を持つことができます。 @node Numeric types, Date and time types, Storage requirements, Column types @subsection 数値型 @strong{MySQL} は ANSI/ISO SQL92 数値型をすべてサポートします。これらの型 は正確な数値データ型(@code{NUMERIC}, @code{DECIMAL}, @code{INTEGER}, @code{SMALLINT})、近似数値型(@code{FLOAT}, @code{REAL}, @code{DOUBLE PRECISION})を含みます。キーワード @code{INT} は @code{INTEGER} の同義語で、 @code{DEC}は @code{DECIMAL} の同義語です。 @strong{MySQL} では @code{NUMERIC} と @code{DECIMAL} 型は、SQL92 標準で許 されているように同じ型として実装されています。これらは正確な精度を維持する ことが重要な値(例えば金銭データ)に使用されます。これらの型の一つのフィール ドを宣言する時、精度と大きさが指定できます(通常はそうします); 例えば: @example salary DECIMAL(9,2) @end example この例では、@code{9} (@code{precisoin}) は値を格納する重要な数値の桁数を表 します。そして @code{2} (@code{scale}) は小数点に続いて格納される桁数を表 します。従って、この場合 @code{salary} フィールドに格納することができる値 の範囲は、@code{-9999999.99} から @code{9999999.99} です。ANSI/ISO SQL92 では、構文 @code{DECIMAL(p)} は @code{DECIMAL(p,0)} と等しいです。同様に、 構文 @code{DECIMAL} は @code{DECIMAL(p,0)} と等しいです。ここで @code{p} の値の決定は実装に許されてます。@code{DECIMAL}/@code{NUMERIC} データ型のこ れらの異なる形式は、@strong{MySQL} は現在サポートしていません。この型の主 な利益は精度と大きさの両方を明示的に制御する機能から引き出されるので、これ は通常深刻な問題ではありません。 @code{DECIMAL} と @code{NUMERIC} 値は、値の小数の精度を維持するため、バイ ナリ浮動小数点数としてではなく、文字列として格納されます。1文字は値のそれ ぞれの桁(@code{scale} > 0 の場合)と @samp{-} 記号(負数の場合)に使用されま す。@code{scale} が 0 の場合、@code{DECIMAL} と @code{NUMERIC} 値は小数点 と小数部を含みません。 @code{DECIMAL} と @code{NUMERIC} 値の最大範囲は @code{DOUBLE} と同じです。 しかし @code{DECIMAL} や @code{NUMERIC} フィールドに与えられる実際の範囲は フィールドに与えられた @code{precision} と @code{scale} によって強制されま す。このフィールドに、指定された @code{scale} で許されるよりも多い桁の小数 部を持つ数値が割り当てられた場合、値はその @code{scale} に丸められます。 @code{DECIMAL} や @code{NUMERIC} フィールドに、指定された(またはデフォルト の) @code{precision} と @code{scale} で示された範囲を超えた大きさの値を割 り当てた時、@strong{MySQL} はその範囲の対応する最大値を表す値を格納します。 ANSI/ISO SQL92 標準に対する拡張として、上の表にリストしたように、 @strong{MySQL} は整数型 @code{TINYINT}, @code{MEDIUMINT}, @code{BIGINT} も サポートします。@strong{MySQL} によってサポートされる他の拡張として、オプ ションで、型の基本キーワードに続けて括弧内に指定する整数値の表示幅(例えば @code{INT(4)})があります。このオプションの幅指定は、フィールドに指定された 幅よりも少ない幅の値の表示の左側を埋めるために使用されます。しかしフィール ドに格納することができる値の範囲や、フィールドに指定された幅を超える幅の値 について表示される桁数は制約されません。オプションの拡張属性 @code{ZEROFILL} を指定して使用された場合、デフォルトの埋められる空白は 0 で置き換えられます。例えば、@code{INT(5) ZEROFILL} として宣言されたフィー ルドでは、値 @code{4} は @code{0004} として取り出されます。注意: 整数フィー ルド内に表示幅よりも大きい値を格納する場合、@strong{MySQL} が複雑な join のために一時テーブルを生成する時に、問題を体験するでしょう。この場合 @strong{MySQL} はデータがオリジナルのフィールド幅に合っていることを信用す るためです。 すべての整数型はオプションの(非標準)属性 @code{UNSIGNED} を持つことができ ます。符合無しの値はフィールド内に正の数だけを許可したくて、フィールドに対 して少し大きい数値の範囲が必要な時に使用できます。 @code{FLOAT} 型は近似数データ型を表すために使用されます。ANSI/ISO SQL92 標 準は、@code{FLOAT} キーワードに続く括弧中にオプションの精度(指数の範囲では ない)の指定を許しています。@strong{MySQL} 実装はこのオプションの精度指定も サポートしています。キーワード @code{FLOAT} が精度の指定無しでフィールド型 として使用された時は、@strong{MySQL} は値を格納するために4バイトを使用しま す。@code{FLOAT} キーワードに続く括弧中に2つの数値を与える構文もサポートさ れます。このオプションでの、最初の数値は値に必要な容量をバイトで表します。 2番目の数値は、格納、表示される小数部の桁数を指定します(@code{DECIMAL} と @code{NUMERIC} と同様)。@strong{MySQL} がフィールドに指定されたよりも大き い小数部の桁数を持つ数値をこのフィールドに格納する時、値の格納時に余計な桁 を取り除くように値が丸められます。 @code{REAL} と @code{DOUBLE PRECISION} 型は精度指定を許しません。 ANSI/ISO SQL92 標準に対する拡張として、@strong{MySQL} は @code{DOUBLE} を @code{DOUBLE PRECISION} 型の同義語として認識します。@code{REAL} の精度は @code{DOUBLE PRECISION} の指定よりも小さいことを要求する標準と異なり、 @strong{MySQL} はどちらも8バイトの倍精度小数点の値として実装しています ("ANSI モード"で実行していない場合)。移植性を最大にするためには、近似数値 データ値の格納を要求するコードは、精度や小数部桁数の指定無しの @code{FLOAT} か @code{DOUBLE PRECISION} を使用すべきです。 フィールドの型の値の許容範囲を超えた数値を代入しようとすると、@strong{MySQL} は その値を許容範囲いっぱいに切り詰め、その結果を代わりに代入します。 例えば、 @code{INT} フィールドの範囲は @code{-2147483648} から @code{2147483647} です。 もし @code{-9999999999} を @code{INT} フィールドに挿入しようとすると、値は範囲の最低値に 修正され、 @code{-2147483648} が代わりに代入されます。同様に、@code{9999999999} の場合、 @code{2147483647} が代わりに代入されます。 そして、@code{INT} フィールドが符号無しの場合、フィールドの範囲の大きさは 同じですが、限界値は @code{0} と@code{4294967296} になります。 もし @code{-9999999999} と @code{9999999999} を代入しようとすると、 値は @code{0} と @code{4294967296} として代入されます。 @code{ALTER TABLE}, @code{LOAD DATA INFILE}, @code{UPDATE} または multi-row @code{INSERT} 時、これらの変換は `警告' として得られます。 @cindex Types, Date and Time @cindex Date and Time types @node Date and time types, String types, Numeric types, Column types @subsection 日付と時間の型 @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 日付と時間の型は @code{DATETIME}, @code{DATE}, @code{TIMESTAMP}, @code{TIME}, @code{YEAR} です. これらはそれぞれ値に適正な範囲があり、 ``zero'' はあなたが間違った値を指定した場合に用いられます。注意: @strong{MySQL} は 確実に '厳密でない' 正しい日付の値、例えば @code{1999-11-31} を格納するこ とができます。この理由は、日付をチェックする処理の責任はアプリケーションに あり、SQL サーバにはないと考えているからです。日付を'速く'チェックするため に、@strong{MySQL} は月が 0〜12 の範囲であるかと日が 0〜31 の範囲であるか だけをチェックします。上述の範囲は、@strong{MySQL} が @code{DATE} または @code{DATETIME} フィールドに、日または月日が 0 である日付を格納できるため に定義されています。これは、正確な日付を知らない誕生日を登録する必要がある アプリケーションに非常に有用です。この場合、@code{1999-00-00} や @code{1999-01-00} のような日付を単純に登録できます(もちろん、このような日 付を @code{DATE_SUB()} や @code{DATE_ADD} のような関数で使用して、正しい値 が返ることは期待できません)。 これは、日付と時間型で作業する場合に、一般的に考慮しなければならないことです: @itemize @bullet @item @strong{MySQL}は、標準形式で与えられた日付や時間から値を抽出しますが、与えられた多様な形式の値(例えば、指定された値を日付や時間型に割り当てたり、比較したり)を解釈しようと試みます。 それでも、次節で述べる形式だけがサポートされます。 それは、正当な値が与えられることを期待し、他の形式の値を使用されるような事態が起こると、どのような結果となるか予想できません。 @item @strong{MySQL} はいくつかの形式に値を変えてくれますが、 常に年の部分と日にちの部分は左から与えられていると期待しています。 日付は 年-月-日 の順(例えば、@code{'98-09-04'})でなくてはなりません。 月-日-年 や 日-月-年 の様などこでも使われているような形であってはなりません。 (例えば、@code{'09-04-98'}や@code{'04-09-98'}). @item @strong{MySQL} は、もし数値の文脈で日付と時間の型が使用されると、 自動的に日付と時間を数値に直します。逆も行います。 @item @strong{MySQL} が範囲外の誤った値を日付と時間型として受け取った場合 (このセクションの最初をみてください)、その値は ``ゼロ'' に変換されます。 (例外は、範囲外の@code{TIME}値が適切な@code{TIME}の範囲の限界値に切り詰められることです。) 以下に、それぞれの型の `ゼロ' の形式を示します: @multitable @columnfractions .3 .7 @item @strong{フィールドタイプ} @tab @strong{`ゼロ'値} @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 `ゼロ'値は特別ですが、表に示された値を明示的に使用して、格納したり参照したりできます。 この値は、 @code{'0'} 又は @code{0} を使用することにより、より簡潔に書くこともできます。 @item @strong{MyODBC} 内で使用されている `ゼロ' の日付と時間は、 @strong{MyODBC} 2.50.12 以上では自動的に @code{NULL} に変換されます。 これは ODBC がこれらの値を扱えないからです。 @end itemize @cindex Year 2000 issues @node Y2K issues, DATETIME, Date and time types, Date and time types @subsubsection 西暦2000年問題とデータ型 @strong{MySQL} 自体は2000年問題に対して安全です(@pxref{Year 2000 compliance})が、 @strong{MySQL} に提示される入力値に関してはそうではありません。2桁の 年の入力は何世紀なのかわからないので全て曖昧です。このような値は @strong{MySQL} が内部で年に4桁を使っていることから4桁の形式に変換されてしまいます。 @strong{MySQL} は曖昧な日付を @code{DATETIME}, @code{DATE}, @code{TIMESTAMP} および @code{YEAR} 型に関して、以下の ルールに従って解釈します。 @itemize @bullet @item @code{00-69} の範囲の年は @code{2000-2069} に変換。 @item @code{70-99} の範囲の年は @code{1970-1999} に変換。 @end itemize これらのルールはデータが何を意味しているかに対して妥当な推定を与えるに 過ぎないことに注意してください。この @strong{MySQL} 発見的手法が正しい値を生成し ない場合は曖昧でない4桁の年を含む入力を与えるべきです。 @code{ORDER BY} は2桁の @code{YEAR/DATE/DATETIME} 型を正しくソートされます。 注意: @code{MIN()} と @code{MAX()} のようないくつかの関数は @code{TIMESTAMP/DATE} を数値 に変換します。これは年が2桁のタイムスタンプはこれらの関数で正しく動作しな いことを意味します。この場合の修復は、@code{TIMESTAMP/DATE} を4桁の年の形 式に変換するか、@code{MIN(DATE_ADD(timestamp,INTERVAL 0 DAYS))} のような何 かを使用することです。 @tindex DATETIME @tindex DATE @tindex TIMESTAMP @node DATETIME, TIME, Y2K issues, Date and time types @subsubsection @code{DATETIME}, @code{DATE}, @code{TIMESTAMP} 型 @code{DATETIME}, @code{DATE}, @code{TIMESTAMP}型はお互いに関連しています。このセクションで はそれらの特徴と、それぞれがどう同じでどう違うかを示します。 @code{DATETIME} 型は日付と時刻の情報を含む値が必要な場合に使います。@strong{MySQL} は @code{DATETIME} 値を @code{'YYYY-MM-DD HH:MM:SS'} のフォーマットで取り出し、表示します。 サポートされる範囲は @code{'1000-01-01 00:00:00'} から @code{'9999-12-31 23:59:59'} です。 (「サポートされる」とはさらに過去の値でも動くかも知れませんが保証の限りではないという意味です) @code{DATE} 型は時刻の部分なしで日付の値のみが必要な場合に使います。@strong{MySQL} は @code{DATE} 値を@code{'YYYY-MM-DD'} のフォーマットで取り出し、表示します。サポートされ る範囲は @code{'1000-01-01'} から @code{'9999-12-31'} です。 @code{TIMESTAMP} タイプは @code{INSERT} や @code{UPDATE} 操作に自動的に 現在の日付と時刻をマークする場合に提供される型です。 もし複数の @code{TIMESTAMP} フィールドがある場合には最初 の一つだけが自動的に更新されます。 最初の @code{TIMESTAMP} フィールドの自動更新は以下のいずれかの条件で起こります: @itemize @bullet @item そのフィールドが明示的に @code{INSERT} または @code{LOAD DATA INFILE} 文で指定されていないとき。 @item そのフィールドが明示的に @code{UPDATE} 文で指定されず、かつ、他のフィールドの値が変わった場合。 (もともとフィールドに入っていた値と同じ値に更新しようとする @code{UPDATE} 文は @code{TIMESTAMP} フィールドを更新しないことに注意。なぜならあるフィールドを現在と同じ値に変えようとしても @strong{MySQL} は効率のためにそれを無視するからです。) @item 明示的に @code{TIMESTAMP} フィールドを @code{NULL} にした場合。 @end itemize 最初以外の @code{TIMESTAMP} フィールドも現在の日付と時刻にすることができます。それらのフィールドを @code{NULL} または @code{NOW()} にすることです。 どの @code{TIMESTAMP} フィールドも明示的に望む値をセットすることで現在の日時でない値に することができます。それは最初の @code{TIMESTAMP} フィールドについても同じです。この特 性は例えば @code{TIMESTAMP} フィールドをあるレコードが生成されたときの日時にし、その後その行 が更新されても変化しないようにしたいというようなときに使えます。 @itemize @bullet @item @strong{MySQL} にレコードが生成されたときにそのフィールドをセットさせる。これで現在日時に初 期化される。 @item 以降の他のフィールドに対する更新時に @code{TIMESTAMP} フィールドをそれ自体が今持っている値に 明示的に更新する。 @end itemize 一方、この手法は @code{DATATIME} フィールドを行生成時に @code{NOW()} で初期化し、以降の更新時に それをほうっておくのと同じように簡単であるとわかるでしょう。 @code{TIMESTAMP} の値は @code{1970} 年の最初から @code{2037} 年のどこかの時点までの範囲で有効で、 1秒の時間分解能を持ちます。値は数値として表示されます。 @strong{MySQL} が @code{TIMESTAMP} 値を取り出したり表示するのに使うフォーマットは以下の表 に示すようにその表示サイズに依存します。「目一杯の」 @code{TIMESTAMP} フォーマッ トは14桁ですが、 @code{TIMESTAMP} フィールドはより短い表示サイズで生成することもできます: @multitable @columnfractions .3 .7 @item @strong{フィールド型} @tab @strong{表示フォーマット} @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 全ての @code{TIMESTAMP} フィールドは表示サイズに関係なく同じ格納サイズを持ちます。もっ とも一般的な表示サイズは 6 , 8 , 12 および 14 です。表示サイズはテーブル生成時 に任意の値に指定できますが、 0 および 14 以上の値は強制的に 14 になります。1 から 13 までの奇数のサイズは強制的に一つ大きい偶数になります。 @code{DATETIME}, @code{DATE}, @code{TIMESTAMP} 値は以下の共通フォーマットセットのいずれかを 使って指定できます: @itemize @bullet @item 文字列で @code{'YYYY-MM-DD HH:MM:SS'} か @code{'YY-MM-DD HH:MM:SS'} の形式。 "柔軟な"書き方を許しています -- 日付や時刻の区切り文字として、いかなる句読記号 も使用できます。例えば、@code{'98-12-31 11:30:45'}, @code{'98.12.31 11+30+45'}, @code{'98/12/31 11*30*45'}, @code{'98@@12@@31 11^30^45'} は等価です。 @item 文字列で @code{'YYYY-MM-DD'} か @code{'YY-MM-DD'} の形式。 これも"柔軟な"書き方ができます。 例えば, @code{'98-12-31'},@code{'98.12.31'}, @code{'98/12/31'}, @code{'98@@12@@31'} は 等価です。 @item 文字列 @code{'YYYYMMDDHHMMSS'} または @code{'YYMMDDHHMMSS'} フォーマット。 「緩やかな」文法が認められていて、句読記号は日付、時刻部分の区切り として使えます。例えば @code{'98-12-31 11:30:45'}, @code{'98.12.31 11+30+45'}, @code{'98/12/31 11*:30*:45'}, @code{'98@@12@@31 11^30^45'} は全て等価です。 @item 文字列 @code{'YYYY-MM-DD'} または @code{'YY-MM-DD'} フォーマット。これも「緩やかな」文法 が認められています。例えば @code{'98-12-31'}, @code{'98.12.31'}, @code{'98/12/31'}, @code{'98@@12@@31'} は全て等価です。 @item 区切り文字なしの文字列 @code{'YYYYMMDDHHMMSS'} または @code{'YYMMDDHHMMSS'} フォーマッ トで日時として意味のあるもの。例えば @code{'19970523091528'} および @code{'970523091528'} は @code{'1997-05-23 09:15:28'} と解釈されます。しかし @code{'971122129015'} は無効で (時と分の部分がおかしい)、 @code{'0000-00-00 00:00:00'} になります。 @item 区切り文字なしの文字列 @code{'YYYYMMDD'} または @code{'YYMMDD'} フォーマットで、日付と して意味のあるもの。例えば @code{'19970523'} および @code{'970523'} は @code{'1997-05-23'} と解釈 されます。しかし @code{'971332'} は無効で(月と日の部分がおかしい)、 @code{'0000-00-00'} になります。 @item @code{YYYYMMDDHHMMSS} または @code{YYMMDDHHMMSS} のフォーマットの数値で、日時として意 味のあるもの。例えば @code{19830905132800} および @code{830905132800} は @code{'1983-09-05 13:28:00'} と解釈されます。 @item @code{YYYYMMDD} または @code{YYMDD} のフォーマットの数値で日付として意味のあるもの。 例えば @code{19830905} および @code{830905} は @code{'1983-09-05'} として解釈されます。 @item @code{NOW()} や @code{CURRENT_DATE} のように @code{DATETIME} , @code{DATE} , @code{TIMESTAMP} のコンテキストで アクセス可能な値を返す関数の結果。 @end itemize 無効な @code{DATETIME} , @code{DATE} , @code{TIMESTAMP} の値は適切な「ゼロ」値に変換されます( @code{'0000-00-00 00:00:00'} , @code{'0000-00-00'} または @code{00000000000000} )。 日時の部分に区切りを持つ文字列で指定される値で、月、日の値が10未満の場 合は2桁で指定しなくてもかまいません。 @code{'1979-6-9'} は @code{'1979-06-09'} と等価で す。同様に時刻の部分に区切りを持つ文字列で指定される値で、時、分、秒が @code{10} 未満の場合は2桁で指定しなくてもかまいません。 @code{'1979-10-30 1:2:3'} は @code{'1979-10-30 01:02:03'} と等価です。 数値でしていされる値は 6, 8, 12 または 14 桁である必要があります。もしその数 値が 8 または 14 桁の長さの時はそれぞれ @code{YYYYMMDD} および @code{YYYYMMDDHHMMSS} フォー マットで、最初の 4 桁で年が与えられるものと仮定されます。もしその数値が 6 または12桁の長さの時は @code{YYMMDD} および @code{YYMMDDHHMMSS} フォーマットで最初の2桁で 年が与えられるものと仮定されます。これら以外の長さの数値はあとに @code{0} が追加 されてこれらのうちのもっとも近い長さのものと解釈されます。 区切りなしの文字列で与えられる値はそれ自身の長さを使って解釈されます。 もし文字列が8または14文字ならば年は最初の4文字で与えられると仮定されま す。そうでなければ最初の2文字で与えられると仮定されます。文字列は左か ら右に年、月、日、時、分、秒と文字列中に表現されている分だけ順に解釈さ れます。つまり6文字以下の文字列は使ってはいけないということです。例え ば1999年3月を指定するつもりで @code{'9903'} を指定した場合、 @strong{MySQL} は「ゼロ」日付 をテーブルに挿入します。これは年と月の部分は @code{99} と @code{03} ですが日の部分が欠け ている(ゼロ)ために値が有効な日付でないために起こります。 @code{TIMESTAMP} フィールドは有効な値を、表示サイズに関係なく指定された値を最高精度の 時間分解能で格納します。このことはいくつかの意味合いを持ちます。 年の値が二桁で指定された場合、世紀の部分がないので曖昧な値となります。 @strong{MySQL} は二桁の年の値を以下に示す規則にそって変換します: @itemize @bullet @item 列の型がTIMESTAMP(4)であってもTIMESTAMP(2)であっても常に年月日を指定 すること。そうでなければ値は無効で0が格納されます。 @item もし短い形式の @code{TIMESTAMP} を @code{ALTER TABLE} を使って拡張しようとした場合、拡 張前には「隠れていた」情報が現れます。 @item 同様に @code{TIMESTAMP} フィールドを縮めた場合も、値が表示された時により少ない情報し か現れないという点を除いて、情報は失われません。 @item @code{TIMESTAMP} 値は最高精度の時間分解能で格納されますが、内部的に格納され た値を直接操作できる関数は @code{UNIX_TIMESTAMP()} のみです。他の関数はフォーマッ トされて取り出された値について操作します。つまり、 @code{HOUR()} や @code{SECOND()} など の関数は @code{TIMESTAMP} 値の対応する部分がフォーマットされた値で含まれないと 使うことができません。例えば @code{TIMESTAMP} 列の @code{HH} の部分は表示サイズが少なく とも10以上ないと表示されないので、それより短い @code{TIMESTAMP} 値に @code{HOUR()} の操 作を行っても無意味な値しか得られません。 @end itemize ある日付型を他の日付型のオブジェクトに拡張して指定することができます。 しかしそれは値の変化や情報の欠落を起こす可能性があります。 @itemize @bullet @item @code{DATE} の値を @code{DATETIME} か @code{TIMESTAMP} の物に与えた場合、 時刻の部分は @code{'00:00:00'} になります。これは @code{DATE} 値が 時刻の情報を持っていないからです。 @item @code{DATETIME} か @code{TIMESTAMP} の値を @code{DATE} の物に与えた場合、 時刻の部分は削られます。これは @code{DATE} 値が 時刻の情報を持っていないからです。 @item @code{DATETIME}, @code{DATE}, @code{TIMESTAMP} 値は同じフォーマットのセットを使って表現で きますが、どの型も同じ値の範囲を持っているわけではないことを覚えておい てください。例えば @code{TIMESTAMP} 値は @code{1970} 年より前や @code{2037} 年より後の値にはでき ません。つまり @code{'1968-01-01'} という値は @code{DATETIME} や @code{DATE} の値としては有効です が @code{TIMESTAMP} の値としては無効で、そのようなオブジェクトを指定した場合は @code{0} に変換されます。 @end itemize 日付の値を指定するときの落とし穴に注意してください: @itemize @bullet @item 文字列として指定される値の柔軟なフォーマットに騙されないよう。例え ば @code{'10:11:12'} は @samp{':'} を区切り文字とする時刻のように見えますが、日付のコン テキストで使われるとこれは @code{'2010-11-12'} と解釈されます。@code{'10:45:15'} は @code{'45'} が有効な月ではないので @code{'0000-00-00'} に変換されます。 @item 2桁で表される年は世紀の部分が不明なので曖昧です。 @strong{MySQL} は以下のルール で2桁の年を解釈します。 @itemize @minus @item @code{00-69} の範囲にある年の値は @code{2000-2069} 年とする。 @item @code{70-99} の範囲にある年の値は @code{1970-1999} 年とする。 @end itemize @end itemize @tindex TIME @node TIME, YEAR, DATETIME, Date and time types @subsubsection @code{TIME} 型 @strong{MySQL} は @code{TIME} の値を @code{'HH:MM:SS'} (時の部分が大きい場合は @code{'HHH:MM:SS'}) というフォーマットで扱い、また表示します。 (時の部分が大きい場合は @code{'HHH:MM:SS'})。 @code{TIME} 値の範囲は @code{'-838:59:59'} から @code{'838:59:59'} の範囲です。 時の部分がこんなに大きいのは、@code{TIME} 型は一日すなわち24時間以内 の時刻を表現するのに用いられるだけではなく経過時間や二つの事象の間隔 (どちらも24時間を越えたり、負の数になる場合もあります)を表現すること もあるからです。 @code{TIME} 値は様々なフォーマットで指定可能です: @itemize @bullet @item 文字列で @code{'D HH:MM:SS.fraction'} というフォーマット。 (@strong{MySQL}はまだこの fraction を time フィールドに保存できません)。 以下の ``柔軟な'' 文法が使用できます: @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 文字列で @code{'HHMMSS'} というように区切りのないフォーマットで時刻として有効 なもの。例えば @code{'101112'} は @code{'10:11:12'} と解釈されますが @code{'109712'} は無効で(分 の部分が無意味) @code{'00:00:00'} になります。 @item 数値で @code{HHMMSS} のフォーマットで時刻として有効なもの。 例えば @code{101112} は @code{'10:11:12'} と解釈されます。 次の別の形式も解釈できます: @code{SS}, @code{MMSS},@code{HHMMSS}, @code{HHMMSS.fraction}。注意: @strong{MySQL} はまだ fraction 部を保存でき ません。 @item 例えば @code{CURRENT_TIME} のように @code{TIME} のコンテキストで受け付けられる値を返す 関数の結果。 @end itemize 文字列で時刻の各部の区切りを含む @code{TIME} の値については、時、分、秒が @code{10} 以下 の場合、2桁の数字を指定する必要はありません。@code{'8:3:2'} は @code{'08:03:02'} と同 じです。 「短い」 @code{TIME} 値を @code{TIME} フィールドとして指定する場合は要注意です。 @strong{MySQL} はその値をもっとも右端の桁は秒を表すと仮定して解釈します (@strong{MySQL} は @code{TIME} の値を一日の うちの時刻としてより経過時間として解釈します)。例えば @code{'11:12'},@code{'1112'}, @code{1112} が @code{'00:11:12'} (11時12分)を表しているつもりでいても、 @strong{MySQL} はこれらを @code{'00:00:12'} (11分12秒)として解釈します。 同様に @code{'12'} および @code{12} は @code{'00:00:12'} と解釈します。 @code{TIME} の範囲外にある値で値以外は正しいものは範囲の端の値の適当な方にクリッ プされます。例えば @code{'-850:00:00'} および @code{'850:00:00'} は それぞれ @code{'-838:59:59'} および @code{'838:59:59'} になります。 無効な @code{TIME} 値は @code{'00:00:00'} に変換されます。 ここで @code{'00:00:00'} 自体は有効な @code{TIME} 値なので、 テーブル内に保存された'00:00:00'という値からそれがもとも と @code{'00:00:00'} と指定された値なのか無効なために変換された結果なのかを区 別する方法はないことに注意してください。 @tindex YEAR @node YEAR, , TIME, Date and time types @subsubsection @code{YEAR} 型 @code{YEAR} 型は年を表現するのに使われる1バイトの値です。 @strong{MySQL} は @code{YEAR} の値を @code{YYYY} というフォーマットで扱い、 また表示します。範囲は @code{1901} から @code{2155} です。 @code{YEAR} 型は様々なフォーマットで指定可能です: @itemize @bullet @item @code{'1901'} から @code{'2155'} の範囲にある4桁の文字列 @item @code{1901} から @code{2155} の範囲にある4桁の数値。 @item @code{'00'} から @code{'99'} の範囲にある2桁の文字列。 @code{'00'} から @code{'69'} までおよび @code{'70'} から @code{'99'} までの範囲はそれぞれ @code{2000} から @code{2069} まで および @code{1970} から @code{1999} までの範囲の YEAR型に変換されます。 @item @code{1} から @code{99} の範囲にある2桁の数値。@code{1} から @code{69} まで および @code{70} から @code{99} までの範囲は それぞれ @code{2001} から @code{2069} までおよび @code{1970} から @code{1999} まで の範囲の @code{YEAR} 型に変換されます。 2桁の数値の場合は2桁の文字列の場合と若干異なっている点に注意して ください。なぜなら0を数値として指定し、それを2000年として解釈させるこ とができないからです。その場合は文字列で @code{'0'} または @code{'00'} を@emph{指定しなければ なりません}。そうでなければ数値0は無効なYEAR値を示す @code{0000} に変換されます。 @item 例えば @code{NOW()} のように @code{YEAR} コンテキストで受け入れられる値を返す関数の結 果。 @end itemize 無効な @code{YEAR} 値は @code{0000} に変換されます。 @node String types, Choosing types, Date and time types, Column types @subsection 文字列型 文字列型は @code{CHAR}, @code{VARCHAR}, @code{BLOB}, @code{TEXT}, @code{ENUM} および @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 @code{CHAR} 型と @code{VARCHAR} 型 @code{CHAR} 型と @code{VARCHAR} 型はよく似ていますが格納、取り出しの手順に違いがあります。 @code{CHAR} フィールドの長さはテーブルを生成するときに宣言した長さに固定されます。長さ は 1 から 255 までの値を取ります。@code{CHAR} が格納されるときには指定された長さに なるように右側に空白が詰められます。@code{CHAR} の値が取り出された場合には右側 (後続)の空白は取り除かれます。 @code{VARCHAR} フィールドの値は可変長文字列です。 @code{VARCHAR} フィールドは @code{CHAR} フィールド と同じく 1 から 255 までの長さに宣言できます。 (@strong{MySQL} 3.23 では, @code{CHAR} の長さは 0 から 255 まで許されています.) しかし @code{CHAR} 型と異なり @code{VARCHAR} 型の値は必要な文字数の分に 長さを記録する1 バイトを足した領域に格納されます。値には桁合わせのための空白はつけられ ません。後続の空白は値の格納時に取り除かれます。(この空白の除去は ANSI SQL仕様とは違っています。) もし @code{CHAR} または @code{VARCHAR} フィールドに、フィールドの最大長を 越える長さの値を与えた場合は、適合するように切り詰められます。 以下の表はこれらの二つのフィールド型の違いを、@code{CHAR(4)} および @code{VARCHAR(4)} に様々 な文字列値を格納した結果を示すことで表しています。 @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{値} @tab @code{CHAR(4)} @tab @strong{必要な格納域} @tab @code{VARCHAR(4)} @tab @strong{必要な格納域} @item @code{''} @tab @code{'@ @ @ @ '} @tab 4 バイト @tab @code{''} @tab 1 バイト @item @code{'ab'} @tab @code{'ab@ @ '} @tab 4 バイト @tab @code{'ab'} @tab 3 バイト @item @code{'abcd'} @tab @code{'abcd'} @tab 4 バイト @tab @code{'abcd'} @tab 5 バイト @item @code{'abcdefgh'} @tab @code{'abcd'} @tab 4 バイト @tab @code{'abcd'} @tab 5 バイト @end multitable @code{CHAR(4)} フィールドの後続の空白は取り出し時にとりのぞかれるので、CHAR(4)および @code{VARCHAR(4)} から取り出される値はどの場合でも同じです。 @code{CHAR} および @code{VARCHAR} フィールドの値はテーブルの生成時に @code{BINARY} 属性が つけられない限り、大文字と小文字を区別しないでソート・比較されます。@code{BINARY} 属性はその 列の値が大文字、小文字を区別して、MySQLサーバを実行しているマシンの ASCII順にソート・比較されることを意味します。 @code{BINARY} 属性は「固定的」です。つまり、もし @code{BINARY} であると指定された フィールドが式の中にあると式全体が @code{BINARY} の値として比較されるのです。 @strong{MySQL} はテーブル生成時に何も断らずに@code{CHAR} または @code{VARCHAR} 型の フィールドを変更する事があります。 @xref{Silent column changes}. @tindex BLOB @tindex TEXT @node BLOB, ENUM, CHAR, String types @subsubsection @code{BLOB} と @code{TEXT} 型 @code{BLOB} は大きなバイナリ型のオブジェクトで、可変長のデータを保持できます。 4 つの @code{BLOB} 型、すなわち @code{TINYBLOB}, @code{BLOB}, @code{MEDIUMBLOB} と @code{LONGBLOB} は保持できるデータの最大長が違うだけです。 @xref{Storage requirements}. 4 つの @code{TEXT} 型、すなわち @code{TINYTEXT}, @code{TEXT}, @code{MEDIUMTEXT} と @code{LONGTEXT} は 4 つの @code{BLOB} 型に対応し、同じ最大長と 格納条件を持っています。 @code{TEXT} と @code{BLOB} の違いは、 @code{TEXT} はケースに依存しないでソートと比較され、 @code{BLOB} はケースに依存して(文字コードで)比較されることだけです。 いうならば、@code{TEXT} は、ケースに依存しない @code{BLOB} です。 もし @code{BLOB} や @code{TEXT} フィールドにそれらの最大長以上の値が与えられた場合、 その値はきっちり収まるように切り落とされます。 ほとんどの点で、@code{TEXT} フィールドを @code{VARCHAR} の大きい物と見なすことが出来ます。 同様に、@code{BLOB} フィールドは @code{VARCHAR BINARY} フィールドの大きくなった物です。 違いは、 @itemize @bullet @item @strong{MySQL} 3.23.2 以上では、@code{BLOB} と @code{TEXT} 項に インデックスを持つことが出来ます。それ以前のバージョンでは インデックスをもつことが出来ません。 @item @code{VARCHAR} フィールドで行っているようには、@code{BLOB} と @code{TEXT} フィールドの 値の後ろについている連続した空白文字は切り落とされません。 @item @cindex Default values, @code{BLOB} and @code{TEXT} columns @cindex @code{BLOB} columns, default values @cindex @code{TEXT} columns, default values @code{BLOB} と @code{TEXT} 項は @code{DEFAULT} 値を持つことが出来ません。 @end itemize @code{MyODBC} は @code{BLOB} を @code{LONGVARBINARY} として、 @code{TEXT} を @code{LONGVARCHAR} として定義します。 @code{BLOB} と @code{TEXT} フィールドは極端に長いので、それらを使用する際には、 いくつかの困った事にでくわすかもしれません: @itemize @bullet @item もし @code{GROUP BY} か @code{ORDER BY} を @code{BLOB} フィールドや @code{TEXT} フィールド で使用したいなら、フィールドの値を固定長のものに変換しなくてはなりません。 標準的な方法は、 @code{SUBSTRING} 関数を使用することです。 たとえば: @example mysql> select comment from tbl_name,substring(comment,20) as substr ORDER BY substr; @end example もしこれをしない場合、フィールドの最初の @code{max_sort_length} バイトが ソート時に使用されます。 @code{max_sort_length} のデフォルト値は 1024; この値は @code{mysqld} サーバー起動時に @code{-O} オプションを使用することで 変更できます。 フィールドの位置を指定することによってか、エイリアスを使用することによって、 @code{BLOB} や @code{TEXT} の値で group 化できます。 @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 @code{BLOB} または @code{TEXT} オブジェクトの最大長はその型により決定されますが、 あなたがクライアントとサーバの間で実際に送ることができるは最大長は、 利用可能なメモリ量とコミュニケーションバッファのサイズによって決定されます。 メッセージバッファサイズを変えることができますが、その場合、サーバーとクライアント、 両方共に変更しなければなりません。@xref{Server parameters}. @end itemize それぞれの @code{BLOB}, @code{TEXT} フィールドは、一意のアロケートされたオブジェクトによって、 内部では表されることに注意してください.。 これはテーブルが開かれるときに一度だけアロケートされる他のフィールドとは対照的です。 @tindex ENUM @node ENUM, SET, BLOB, String types @subsubsection @code{ENUM} 型 @code{ENUM} はストリングオブジェクトで、 その値は、通常、テーブル作成時のフィールド定義で列挙された値の中から選ばれます。 値はある状況下では 空文字 (@code{""}) か @code{NULL} を取ることがあります: @itemize @bullet @item もし @code{ENUM} に無効な値 (列挙されている値の中に含まれない文字) を 代入した場合、 そのエラーになる文字の代わりに空文字が挿入されます。 @item もし @code{ENUM} が @code{NULL} と定義された場合, @code{NULL} はそのフィールドで 許可される値となり、デフォルト値が @code{NULL} になります。 もし @code{ENUM} が @code{NOT NULL} と定義されたならば、 デフォルト値は、 列挙リストの最初の値になります。 @end itemize 列挙されたそれぞれの値はインデックスを持ちます: @itemize @bullet @item 列挙リストの要素は 1 から付番されます。 @item 空文字エラーのインデックス値は 0 。 これは不正な @code{ENUM} 値が与えられているレコードを見つけるために 以下のような @code{SELECT} 構文が使用できることを意味します: @example mysql> SELECT * FROM tbl_name WHERE enum_col=0; @end example @item @code{NULL} のインデックス値は @code{NULL}. @end itemize たとえば、フィールドが @code{ENUM("one", "two", "three")} と定義されたなら、 以下に示す値をとります。 それぞれのインデックス値も示します。 @multitable @columnfractions .2 .8 @item @strong{値} @tab @strong{インデックス} @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 列挙は最大 65535 個の要素まで可能です。 @code{ENUM} フィールドに値を与える場合は大文字小文字は無関係です。 しかし、後でフィールドから検索される値は、大文字小文字をもちます。 これはテーブル作成時に与えられたリストの値です。 もし @code{ENUM} を数値の文脈で検索した場合、そのメンバーを前から数えた 時の順番が数値で返ってきます。 もし @code{ENUM} に数値を代入しようとした場合、その数値の位置にある メンバーが代入されます。 (しかし、これは @code{LOAD DATA} では働きません。これはすべての入力を文字 列として扱います。) @code{ENUM} 値は列挙メンバがフィールド指定にリストされた順に従ってソートさ れます。 (つまり、@code{ENUM} 値はインデックス値に従ってソートされます。) 例えば、@code{ENUM("a", "b")} ならば @code{"a"} が @code{"b"} の前にソートされ、 @code{ENUM("b", "a")} ならば @code{"b"} が @code{"a"} の前にソートされます。 空文字列は空ではない文字の前にソートされ、 @code{NULL} は他の列挙の前に並びます。 @code{ENUM} フィールドで指定可能な値のリストを全て取りたいならば、 次のようにします: @code{SHOW COLUMNS FROM table_name LIKE enum_column_name} そして二番目のフィールドの @code{ENUM} 定義を分析します。 @tindex SET @node SET, , ENUM, String types @subsubsection @code{SET} 型 @code{SET} は文字型オブジェクトでゼロかそれ以上を値持ちます。 テーブル作成時には、それぞれの値はリストから選ばれるべきです。 @code{SET} 型のフィールドの値は、コンマ(@samp{,}) 区切りで並べられた複数のメンバーで構成されています。 これは、 @code{SET} メンバーの値中にコンマを含むことが出来ない、 ということです。 例えば、 @code{SET("one", "two") NOT NULL} と指定されたフィールドは以下の値をとります: @example "" "one" "two" "one,two" @end example @code{SET} は最大 64 個の異なったメンバーがもてます。 @strong{MySQL} は @code{SET} の値を数値として代入します。代入された 値の最下位のビットが最初のメンバーに対応します。もし @code{SET} 値を 数値の文脈で検索した場合、検索される値はフィールドの値に対応します。 もしメンバーが @code{SET} フィールドに代入された場合、 二進数で表される数値が、メンバーの数値として決定されます。 @code{SET("a","b","c","d")} とフィールドが定義されたとします。 メンバーは以下の2進数の値を持ちます: @multitable @columnfractions .2 .2 .6 @item @code{SET} @strong{member} @tab @strong{10進数} @tab @strong{2進数値} @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 もしこのフィールドに @code{9} を与えた場合、これは2進数で @code{1001} ですから、 1 番目と 4 番目の @code{SET} メンバーである @code{"a"} と @code{"d"} が 選択され、結果、 @code{"a,d"} となります。 1つ以上の @code{SET} 要素を含む値においては,あなたが値を挿入するとき,要素がどんな 順序で記載されているのかは重要ではありません. また,何回要素が与えられたのかは 重要ではありません. 後で値が検索されるとき, 値の中のそれぞれの要素は ただ一回だけ表れます。そのとき、テーブル作成時に与えられた順に要素は並びます。 例えば、フィールドが @code{SET("a","b","c","d")} と設定されていたなら、 @code{"a,d"}, @code{"d,a"}, @code{"d,a,a,d,d"} は検索されると @code{"a,d"} と なります。 @code{SET} 値は数値として代入されます。 @code{NULL} 値は非 @code{NULL} @code{SET} 値の前にソートされます。 通常、@code{LIKE} か @code{FIND_IN_SET()} を使用して @code{SET} フィールド の @code{SELECT} を行います: @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 しかし、以下も動作します: @example mysql> SELECT * FROM tbl_name WHERE set_col = 'val1,val2'; mysql> SELECT * FROM tbl_name WHERE set_col & 1; @end example 最初の文は完全一致するものを探します。 二つ目は第一番目のメンバーを含む値を探します。 もし @code{SET} フィールドで設定可能なすべてのメンバーを知りたい場合: @code{SHOW COLUMNS FROM table_name LIKE set_column_name} とし、 2番目にあらわされる @code{SET} 定義を分析します。 @cindex Types, choosing @cindex Choosing types @node Choosing types, Indexes, String types, Column types @subsection 正しいフィールド型の選択 もっとも効率よく格納するには、全てにおいて一番正確な型を使用することです。 例えば、@code{1}-@code{99999} の整数 には、@code{MEDIUMINT UNSIGNED} が最良の型です。 良くある問題は、貨幣の値の正確な表現です。@strong{MySQL} では @code{DECIMAL} 型を使用すべきです。これは文字列として格納し、正確さのロ スは発生しません。正確さが重要でない場合は @code{DOUBLE} 型でも十分良い です。 高精度のため、常に @code{BITINT} に格納される固定小数点型に変換できます。 これは、全ての計算を整数で行なうようにし、結果だけを浮動小数点に変換して 戻します。 @cindex Indexes @cindex Keys @node Indexes, Multiple-column indexes, Choosing types, Column types @subsection フィールドインデックス @strong{MySQL} の全てのフィールドはインデックスを持つことができます。 適切なフィールドでのインデックスの使用は、@code{SELECT} の 性能を向上する最良の方法です。 一つのテーブルには最大16個のインデックスが許されます。 インデックスの最大長は256バイトで、 これは @strong{MySQL} コンパイル時に変更できます。 @code{CHAR} と @code{VARCHAR} フィールドには接頭部にインデックスを持つことができます。 フィールド全体をインデックス化するより、 これははるかに早く、少ないディスク容量でできます。 @code{CREATE TABLE} 構文でフィールドにインデックスを作るには、 以下のようにします: @example KEY index_name (col_name(length)) @end example 以下の例は @code{name} フィールドの最初の10文字にインデックスを創り出します: @example mysql> CREATE TABLE test ( name CHAR(200) NOT NULL, KEY index_name (name(10))); @end example @code{BLOB} と @code{TEXT} フィールドでは、そのフィールドの頭の部分に インデックスを張らなくてはなりません。 フィールドの全体にインデックスは張れません。 @node Multiple-column indexes, Other-vendor column types, Indexes, Column types @subsection 複数フィールドインデックス @strong{MySQL} は異なるフィールドのセットに一つのインデックスを持つことができます。 インデックスは最大15個のコラムまで許されます。 (@code{CHAR} と @code{VARCHAR} フィールドの接頭部をインデックスとして使用できます) 複数フィールドインデックスは、 ソートされた配列(インデックス化されたフィールドの値が結合されている配列)  を扱うことができます。 インデックス化されたコラムに対して、既知の値を @code{WHERE} 節で指定した時、 たとえ他のフィールドの値を指定しなくとも、 @strong{MySQL} は複数フィールドインデックスを使用します。 以下のテーブルがあると仮定してください: @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 @code{name} インデックスは、@code{last_name} と @code{first_name} にまたがるインデックスです。 このインデックスは、@code{last_name} に対するクエリや、 @code{name} インデックスは以下のクエリで使われます: @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 しかし @code{name} インデックスは以下のクエリでは使用されません: @example mysql> SELECT * FROM test WHERE first_name="Michael"; mysql> SELECT * FROM test WHERE last_name="Widenius"             OR first_name="Michael"; @end example @strong{MySQL} がクエリの性能を上げるためにどうインデックスを使用しているか、 より詳しい情報はこちら: @ref{MySQL indexes, , @strong{MySQL} indexes}. @cindex Type portability @node Other-vendor column types, , Multiple-column indexes, Column types @subsection 他のデータベースエンジンのフィールド型の使用 ほかのベンダーからSQLを簡単に書けれるように、 @strong{MySQL} は以下の表に しめすフィールド型をサポートします。これらは、テーブルの定義を、 他のデータベースエンジンから @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 もし他のベンダーの型を使用してテーブルを作ろうとすると、 テーブル作成時のフィールドの型のマッピングが発生し、 @code{DESCRIBE tbl_name} 構文を発行します。 そして @strong{MySQL} は、使用された型と等価な @strong{MySQL} の型を用いて テーブルを構成したことを告げます。 @cindex Functions for @code{SELECT} and @code{WHERE} clauses @node Functions, CREATE DATABASE, Column types, Reference @section @code{SELECT} と @code{WHERE} 節で使用する関数 SQL ステートメント中の @code{select_expression} または @code{where_definition} は後述の関数を使用した任意の式からなります。 演算と関数を式の中で呼ぶ時、本ドキュメントに示しているもの以外の、 @code{NULL} を含む式は常に @code{NULL} 値を生成します @strong{注意:} 関数名とそれに続く語句の間には、空白はありません。 これは関数の呼び出しと、関数と同名のテーブル(かフィールド)の参照を、 @strong{MySQL} パーサが区別するのを助けます。 @need 2000 次の例では、@code{mysql} プログラムの出力は短くなっています。つまり: @example mysql> select MOD(29,9); 1 rows in set (0.00 sec) +-----------+ | mod(29,9) | +-----------+ | 2 | +-----------+ @end example これは次に変換されています: @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 * Control flow functions:: Control flow functions * Casts:: Cast operators * 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 グループ化関数 @cindex Grouping of expressions @table @code @findex () (parentheses) @findex parentheses ( and ) @item ( ... ) 丸かっこ。 式の評価の優先度を強制するために使用します。 @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 通常の算術演算 普通の算術演算が有効です。 @code{-}, @code{+}, @code{*} は、二つの引数が正数ならば @code{BIGINT} (64bit精度) で計算されることに注意してください! @cindex Arithmetic expressions @table @code @findex + (addition) @findex addition (+) @item + 足し算 @example mysql> select 3+5; -> 8 @end example @findex - (subtraction) @findex subtraction (-) @item - 引き算 @example mysql> select 3-5; -> -2 @end example @findex * (multiplication) @findex multiplication (*) @item * 掛け算 @example mysql> select 3*5; -> 15 mysql> select 18014398509481984*18014398509481984.0; -> 324518553658426726783156020576256.0 mysql> select 18014398509481984*18014398509481984; -> 0 @end example 最後の式の結果は不当です。なぜなら結果は 64 ビットを超えた整数だからです。 @findex / (division) @findex division (/) @item / 割り算。 @example mysql> select 3/5; -> 0.60 @end example 0 で割った場合、@code{NULL} になります。 @example mysql> select 102/(1-1); -> NULL @end example 演算結果が整数になる場合にだけ、 @code{BIGINT} を用いて割り算は計算されます。 @end table @findex Arithmetic functions @findex Bit functions @findex Functions, arithmetic @findex Functions, bit @node Bit functions, Logical functions, Arithmetic functions, Functions @subsection ビット関数 これらは最大 64 ビットの範囲を持ちます。@strong{MySQL} は @code{BIGINT} (64-bit) 演算を使用するためです。 @table @code @findex | (bitwise OR) @findex OR, bitwise @item | ビット演算 OR @example mysql> select 29 | 15; -> 31 @end example @findex & (bitwise AND) @findex AND, bitwise @item & ビット演算 AND @example mysql> select 29 & 15; -> 13 @end example @findex << (left shift) @item << 左に longlong (@code{BIGINT}) number 分、ビットをシフトします @example mysql> select 1 << 2 -> 4 @end example @findex >> (right shift) @item >> 右に longlong (@code{BIGINT}) number 分、ビットをシフトします @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) 引数 @code{N} がいくつビットを持っているか(2進数表記したときの1の数) @example mysql> select BIT_COUNT(29); -> 4 @end example @end table @findex Logical functions @node Logical functions, Comparison functions, Bit functions, Functions @subsection 論理演算 全ての論理関数は @code{1} (TRUE) or @code{0} (FALSE) を返します。 @table @code @findex NOT, logical @findex ! (logical NOT) @item NOT @itemx ! 論理否定。引数が @code{0} なら @code{1} を返し、そうでなければ @code{0} を返します。 例外: @code{NOT NULL} は @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 最後の例は @code{1} を返します。なぜなら、式の評価が @code{(!1)+1} と同じだからです。 @findex OR, logical @findex || (logical OR) @item OR @itemx || 論理和。引数のどれかが @code{0} または @code{NULL} でなければ @code{1} を返します。 @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 && 論理積。全ての引数が @code{0} または @code{NULL} でなければ @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 比較演算子 @code{1} (TRUE), @code{0} (FALSE) または @code{NULL} を返します。 これらの関数は数値と文字列の両方で働きます。 必要ならば、文字は自動的に数字に変換され、数字は文字に変換されます。 (Perlがおこなっているみたいに) @strong{MySQL} は以下の規則で比較を行います: @itemize @bullet @item どちらかまたは両方の引数が @code{NULL} の場合は、比較結果は @code{NULL} です。@code{<=>} 演算子を除きます。 @item 比較操作の両方の引数が文字列の場合、文字列として比較されます。 @item 両方の引数が整数の場合、整数として比較されます。 @item 16進数の値は、もし数値と比較されないのであれば、文字列として扱われます。 @item @cindex ODBC compatibility @cindex Compatibility, with ODBC 引数の一方が @code{TIMESTAMP} または @code{DATETIME} フィールドで、他の引数が 定数の場合は、定数は比較前に timestamp に変換されます。これはより ODBC フレンドリにするためです。 @item 他の場合は全て浮動小数点(real)として比較されます。 @end itemize 文字列の比較は、ケースに依存せず、標準のキャラクターセットに従って 行われます。(ISO-8859-1 Latin1 がデフォルトです。これは English です) 以下は、比較のために文字が数値へ変換されている例です: @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 = 等しい @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 != 等しくない @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 <= より小さいか等しい @example mysql> select 0.1 <= 2; -> 1 @end example @findex < (less than) @findex less than (<) @item < より小さい @example mysql> select 2 <= 2; -> 1 @end example @findex >= (greater than or equal) @findex greater than or equal (>=) @item >= より大きいか等しい @example mysql> select 2 >= 2; -> 1 @end example @findex > (greater than) @findex greater than (>) @item > より大きい @example mysql> select 2 > 2; -> 0 @end example @findex <=> (Equal to) @item <=> 等しい(NULL 安全) @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 値が @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 もし @code{expr} が @code{min} 以上、 @code{max} 以下なら @code{1}を返します。 そうでないなら @code{0} を返します。 これは 全ての引数が同じ型ならば、@code{(min <= expr AND expr <= max)} と同じです。 最初の引数 (@code{expr}) はいかのように比較方法を決定します。 @itemize @bullet @item もし @code{exor} が @code{TIMESTAMP}, @code{DATE}, @code{DATETIME} フィー ルドなら、最小と最大はそれらが定数の場合と同じフォーマットになります。 @item もし @code{expr} が文字式なら、ケース非依存で比較が行われます。 @item もし @code{expr} がバイナリ文字なら、ケース依存で比較が行われます。 @item もし @code{expr} が整数なら、整数で比較が行われます。 @item その他は浮動小数点(実数)で比較されます。 @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,...) もし @code{expr} が @code{IN} リストにある値のどれかならば、@code{1} を返します。 そうでなければ @code{0} を返します。 もし全ての値が定数なら、すべての値が @code{expr} の型に従って評価され、 ソートされます。この検索にはバイナリサーチが使用されます。 これは @code{IN} リストに定数を与えた場合、@code{IN} が速くなることを意味します。 もし @code{expr} がケース依存の文字式なら、ケース依存のやり方で比較されます。 @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,...) @code{NOT (expr IN (value,...))} と同じ。 @findex ISNULL() @item ISNULL(expr) @code{expr} が @code{NULL} なら @code{1} を、そうでなければ @code{0} を返します。 @example mysql> select ISNULL(1+1); -> 0 mysql> select ISNULL(1/0); -> 1 @end example @code{NULL} の値を @code{=} を使用して比較した場合は常に偽(false) となることに 注意してください! @findex COALESCE() @item COALESCE(list) list 中の、最初に現れた 非-@code{NULL} 要素を返します。 @example mysql> select COALESCE(NULL,1); -> 1 mysql> select COALESCE(NULL,NULL,NULL); -> NULL @end example @findex INTERVAL() @item INTERVAL(N,N1,N2,N3,...) もし @code{N} < @code{N1} なら @code{0} を返します。 もし @code{N} < @code{N2} なら @code{1} を返します。 全ての引数は整数として扱われます。 これは @code{N1} < @code{N2} < @code{N3} < @code{...} < @code{Nn}を正しく動作させるために 必要なことです。これはバイナリ検索が使用されます(速いです) @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 文字列比較関数 @cindex Case sensitivity, in string comparisons @cindex String comparisons, case sensitivity 通常、比較される表現がケース依存でない場合、比較はケース非依存で行われます。 @table @code @findex LIKE @item expr LIKE pat [ESCAPE 'escape-char'] SQL の簡単な正規表現比較です。@code{1} (TRUE) または @code{0} (FALSE) を返します。 @code{LIKE} には2つのワイルドカードがあります: @multitable @columnfractions .1 .9 @item @code{%} @tab 任意の数の文字(0文字も含む)に適合します。 @item @code{_} @tab 厳密に1つの文字に適合します。 @end multitable @example mysql> select 'David!' LIKE 'David_'; -> 1 mysql> select 'David!' LIKE '%D%v%'; -> 1 @end example ワイルドカード文字のテストをするためには、エスケープ文字より先行しておこなって ください。 @code{ESCAPE} を指定しない場合は、文字 @code{'\'} が使われます: @multitable @columnfractions .1 .9 @item @code{\%} @tab 1つの @code{%} に適合します。 @item @code{\_} @tab 1つの @code{_} に適合します。 @end multitable @example mysql> select 'David!' LIKE 'David\_'; -> 0 mysql> select 'David_' LIKE 'David\_'; -> 1 @end example 違うエスケープ文字を指定するには、 @code{ESCAPE} 節を使用します: @example mysql> select 'David_' LIKE 'David|_' ESCAPE '|'; -> 1 @end example @code{LIKE} は数値表現でも許されます! (これは @strong{MySQL} の、ANSI SQL @code{LIKE} に対する拡張です) 注意: @strong{MySQL} は文字列中に C のエスケープ文字を使用しているので(e.g., @samp{\n}), @code{LIKE} の指定文字列として使用するには @samp{\} を 二倍しなくてはなりません。 例えば、 @samp{\n} を探すには、@samp{\\n} と 記述します。 @samp{\} を探すには、 @samp{\\\\} (バックスラッシュは、 一つはパーサーに取り除かれ、パターンマッチが行われる際にもうひとつ 取り除かれ、一致を探すために残った一つのバックスラッシュが使用されます) @findex NOT LIKE @item expr NOT LIKE pat [ESCAPE 'escape-char'] @code{NOT (expr LIKE pat [ESCAPE 'escape-char'])} と同じ @example mysql> select 10 LIKE '1%'; -> 1 @end example @cindex mSQL compatibility @cindex Compatibility, with mSQL @findex REGEXP @findex RLIKE @item expr REGEXP pat @itemx expr RLIKE pat パターン @code{pat} に対し、文字式 @code{expr} のパターンマッチを行います。 パターン @code{pat} は正規表現の拡張が使用できます。@xref{Regexp}. もし @code{expr} が @code{pat} にマッチするなら @code{1} を返し、 でなければ @code{0} を返します。 @code{RLIKE} は @code{REGEXP} と同義で、@code{mSQL} 互換を提供します。 注意: @strong{MySQL} は C エスケープ構文を文字中に使用しており(@code{\n})、 @code{REGEXP} 中で使用される @code{'\'} 文字はすべて、二重に書かなければ なりません。 @code{MySQL} 3.23.4 @code{REGEXP} は、普通の文字 (not binary) はケース非依存です。 @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} は、文字の型を決定する場合、 カレントのキャラクターセットを使用します。 (ISO-8859-1 Latin1 がデフォルト) @findex NOT REGEXP @item expr NOT REGEXP pat @itemx expr NOT RLIKE pat @code{NOT (expr REGEXP pat)} と同じ. @findex STRCMP() @item STRCMP(expr1,expr2) 文字列が同じなら @code{0} を返します。そうでなければ、最初の引数がソート順で小 さければ @code{-1} を返します。そうでなければ @code{1} を返します。 @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} @code{BINARY} 演算子は、これ以降に続く文字をバイナリにキャストします。 これはたとえフィールドが @code{BINARY} や @code{BLOB} 定義でなくても、 ケース依存でフィールドを比較することが出来る簡単な方法です。 @example mysql> select "a" = "A"; -> 1 mysql> select BINARY "a" = "A"; -> 0 @end example @code{BINARY} は @strong{MySQL} 3.23.0 で登場しました。 @end table @findex Control flow functions @findex Functions, control flow @node Control flow functions, Mathematical functions, Casts, Functions @subsection フロー制御関数 @table @code @findex IFNULL() @item IFNULL(expr1,expr2) @code{expr1} が @code{NULL} でない場合は @code{expr1} を、そうでなければ @code{expr2} を返します。 @code{IFNULL()} はどの文脈で使用されたかにより数値か文字を返します。 @example mysql> select IFNULL(1,0); -> 1 mysql> select IFNULL(0,10); -> 0 mysql> select IFNULL(1/0,10); -> 10 mysql> select IFNULL(1/0,'yes'); -> 'yes' @end example @findex NULLIF() @item NULLIF(expr1,expr2) @code{expr1 = expr2} が真なら、@code{expr1} を返し、そうでなければ @code{NULL} を返します。 @example mysql> select NULLIF(1,1); -> 1 mysql> select NULLIF(1,2); -> NULL @end example 注意: 引数が等しい場合、@code{expr1} は @strong{MySQL} では2回評価されます。 @findex IF() @item IF(expr1,expr2,expr3) @code{expr1} が真 (@code{expr1 <> 0} and @code{expr1 <> NULL}) の場合 @code{expr2} を返し、そうでなければ @code{expr3} を返します。 @code{IF()} はどの文脈で使用されたかにより数値か文字を返します。 @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} は @code{INTEGER} として評価されます。これは浮動小数点を使用する場合、 比較演算も使用すべきであることを意味します。 @example mysql> select IF(0.1,1,0); -> 0 mysql> select IF(0.1<>0,1,0); -> 1 @end example 上の最初の例では、 @code{IF(0.1)} は @code{0} を返します。なぜなら @code{0.1} は 整数値として変換され @code{IF(0)} になり、それをもとにしたテスト結果が 返るからです。 これはあなたの期待に添わないかもしれません。 二番目の場合、 比較は、元の浮動小数点値が非ゼロかどうかテストします。 比較結果は整数として使用されます。 @code{IF()} のデフォルトの戻り値型(一時テーブルに格納される時に問題となり ます)は @strong{MySQL} 3.23 では次のように計算されます: @multitable @columnfractions .7 .3 @item expr2 または expr3 が文字列を返す @tab 文字列 @item expr2 または expr3 が浮動小数点値を返す @tab 浮動小数点 @item expr2 または expr3 が整数を返す @tab 整数 @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 最初の式は @code{value=compare-value} ならば @code{result} を返します。 二つ目の式では、最初の条件[condition] が真ならば、 @code{result} を返します。 もしマッチする result の値がなければ、 @code{ELSE} 以下の result が返ります。 もし @code{ELSE} 部分がなければ、 @code{NULL} が返ります。 @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 数学関数 すべての数学関数はエラーの場合 @code{NULL} を返します。 @table @code @findex - (unary minus) @findex minus, unary (-) @findex unary minus (-) @item - 符号。引数の符号を変更します。 @example mysql> select - 2; -> -2 @end example このオペレーターが @code{BIGINT} とともに使用された場合、 返り値は @code{BIGINT} であることに注意してください! これは @code{-2^63} の値を 持つかもしれない整数を、 @code{-} で使用してはならないことを意味します! @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 この関数は @code{BIGINT} 値とともに使用されると安全です。 @findex SIGN() @item SIGN(X) @code{X} が負数、ゼロ、整数によって、 @code{-1}, @code{0} or @code{1} を 返します。 @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 % 剰余 ( C の @code{%} 演算子のような ). @code{N} を @code{M} で割ったときの余りが返ります。 @example mysql> select MOD(234, 10); -> 4 mysql> select 253 % 7; -> 1 mysql> select MOD(29,9); -> 2 @end example この関数は @code{BIGINT} 値でも安全に使用できます。 @findex FLOOR() @item FLOOR(X) @code{X} より大きくならない整数のうち、最大の整数値を返します. @example mysql> select FLOOR(1.23); -> 1 mysql> select FLOOR(-1.23); -> -2 @end example 返り値は @code{BIGINT} に変換されていることに注意! @findex CEILING() @item CEILING(X) @code{X} より小さくならない整数のうち、最小の整数値を返します. @example mysql> select CEILING(1.23); -> 2 mysql> select CEILING(-1.23); -> -1 @end example 返り値は @code{BIGINT} に変換されていることに注意! @findex ROUND() @item ROUND(X) @code{X} を整数に丸めた値(四捨五入)を返します。 @example mysql> select ROUND(-1.23); -> -1 mysql> select ROUND(-1.58); -> -2 mysql> select ROUND(1.58); -> 2 @end example 返り値は @code{BIGINT} に変換されていることに注意! @findex ROUND() @item ROUND(X,D) @code{X} を @code{D} で指定した少数桁に丸めた値(四捨五入)を返します。 もし @code{D} が @code{0} なら, 結果は小数点無しになるか 少数部分になるでしょう。 @example mysql> select ROUND(1.298, 0); -> 1 @end example @findex EXP() @item EXP(X) 指数関数 : @code{e} (自然対数の底) の @code{X} 乗。 @example mysql> select EXP(2); -> 7.389056 mysql> select EXP(-2); -> 0.135335 @end example @findex LOG() @item LOG(X) 自然対数 @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) 常用対数(10を底とした対数) @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) @code{X} の @code{Y} 乗。 @example mysql> select POW(2,2); -> 4.000000 mysql> select POW(2,-2); -> 0.250000 @end example @findex SQRT() @item SQRT(X) @code{X} の非負の平方根を返します。 @example mysql> select SQRT(4); -> 2.000000 mysql> select SQRT(20); -> 4.472136 @end example @findex PI() @item PI() π @example mysql> select PI(); -> 3.141593 @end example @findex COS() @item COS(X) コサイン @code{X}。@code{X} はラジアン。 @example mysql> select COS(PI()); -> -1.000000 @end example @findex SIN() @item SIN(X) サイン @code{X}。@code{X} はラジアン。 @example mysql> select SIN(PI()); -> 0.000000 @end example @findex TAN() @item TAN(X) タンジェント @code{X}。@code{X} はラジアン。 @example mysql> select TAN(PI()+1); -> 1.557408 @end example @findex ACOS() @item ACOS(X) @code{X} のアークコサインを返します。これはコサインが @code{X} である値で す。@code{X} が @code{-1} から @code{1} の範囲にない場合は @code{NULL} を 返します。 @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) @code{X} のアークサインを返します。これはサインが @code{X} である値です。 @code{X} が @code{-1} から @code{1} の範囲にない場合は @code{NULL} を返し ます。 @example mysql> select ASIN(0.2); -> 0.201358 mysql> select ASIN('foo'); -> 0.000000 @end example @findex ATAN() @item ATAN(X) @code{X} のアークタンジェントを返します。これはタンジェントが @code{X} で ある値です。 @example mysql> select ATAN(2); -> 1.107149 mysql> select ATAN(-2); -> -1.107149 @end example @findex ATAN2() @item ATAN2(X,Y) 2つの変数 @code{X} と @code{Y} のアークタンジェントを返します。両方の引数 の符号が結果の象限を決定するために使用されることを除いて、@code{Y / X} の アークタンジェントの計算と同様です。 @example mysql> select ATAN(-2,2); -> -0.785398 mysql> select ATAN(PI(),0); -> 1.570796 @end example @findex COT() @item COT(X) @code{X} のコタンジェントを返します。 @example mysql> select COT(12); -> -1.57267341 mysql> select COT(0); -> NULL @end example @findex RAND() @item RAND() @itemx RAND(N) @code{0} から @code{1.0} 間のランダムな浮動小数点数値を返します。 もし @code{N} に整数を与えた場合、シードとしてこの値が使用されます。 @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 @code{RAND()} 値を持つフィールドは @code{ORDER BY} 節で使用できません。 @code{ORDER BY} はフィールドを複数回評価するためです。 しかし @strong{MySQL} 3.23 では, 次が可能です: @code{SELECT * FROM table_name ORDER BY RAND()} これは @code{SELECT * FROM table1,table2 WHERE a=b AND c 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 3.22.5 以前の @strong{MySQL} では、@code{MIN()} を @code{LEAST} の代わりに使用できます。 @findex GREATEST() @item GREATEST(X,Y,...) 二つ以上の引数を取り、引数中、最大の値を返します。 引数は @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 3.22.5 以前の @strong{MySQL} では、@code{MAX()} を @code{GREATEST} の代わりに使用できます。 @findex DEGREES() @item DEGREES(X) 引数 @code{X} をラジアンから度に変換して返します。 @example mysql> select DEGREES(PI()); -> 180.000000 @end example @findex RADIANS() @item RADIANS(X) 引数 @code{X} を度からラジアンに変換して返します。 @example mysql> select RADIANS(90); -> 1.570796 @end example @findex TRUNCATE() @item TRUNCATE(X,D) 少数点以下 @code{D} 桁で @code{X} を切り捨てた値を返します。 @code{D} が @code{0} の場合、結果は小数部や微小部を持ちません。 @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 文字列関数 サーバー側のパラメター @code{max_allowed_packet} よりも結果の長さが大きい場合、 文字列関数は @code{NULL} を返します。 @xref{Server parameters}. 文字の位置を扱う関数においては、一番最初の位置は数字の 1 です。 @table @code @findex ASCII() @item ASCII(str) @code{str} の左端の文字の ASCII コード値を返します。 @code{str} が空文字の場合は @code{0} を返します。 @code{str} が @code{NULL} の場合は @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) 文字列 str の左端の文字がマルチバイト文字の場合、文字のASCII コード値を次 の形式で返すことにより、マルチバイト文字のコードを返します: @code{((first byte ASCII code)*256+(second byte ASCII code))[*256+third byte ASCII code...]}. 左端の文字がマルチバイト文字でない場合は、@code{ASCII()} 関数と同じ値を返 します。 @example mysql> select ORD('2'); -> 50 @end example @findex CONV() @item CONV(N,from_base, to_base) 数字を、進数の違う数字に変換します。 数 @code{N} を @code{from_base} 進数から @code{to_base} 進数に 変換した場合の、文字表現を返します。 もし引数が @code{NULL} なら @code{NULL} を返します。 引数 @code{N} は整数として解釈されますが、整数か文字列で指定します。 最小の進数は @code{2} で、最大は @code{36} です。 @code{to_base} が負数なら、@code{N} は符号付きの数になります。 @code{CONV} は 64-bit 精度で動作します。 @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) @code{N} を二進数にした値を返します。@code{N} は longlong 数値です。 これは @code{CONV(N,10,2)} と同じです。 @code{N} が @code{NULL} なら @code{NULL} を返します. @example mysql> select BIN(12); -> '1100' @end example @findex OCT() @item OCT(N) @code{N} の8進数値を表す文字列を返します。@code{N} は longlong 数値です。 これは @code{CONV(N,10,8)} と同じです。@code{N} が @code{NULL} の場合は @code{NULL} を返します。 @example mysql> select OCT(12); -> '14' @end example @findex HEX() @item HEX(N) @code{N} の16進数値を表す文字列を返します。@code{N} は longlong(@code{BIGINT}) 数値です。これは @code{CONV(N,10,16)} と同じです。 @code{N} が @code{NULL} の場合は @code{NULL} を返します。 @example mysql> select HEX(255); -> 'FF' @end example @findex CHAR() @item CHAR(N,...) 引数の ASCII コード値によって与えられた文字からなる文字列を返します。 @code{NULL} は飛ばされます。 @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,...) 引数を結合した結果を返します。引数が @code{NULL} なら @code{NULL} を返します. 2個以上の引数を必要とします。 数値の引数は等価の文字列形式に変換されます。 @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()} は区切り文字つき CONCAT (CONCAT With Separator) を意味 し、@code{CONCAT()} の特殊な形式です。最初の引数は、残りの引数の区切り文字 です。区切り文字は残りの引数と同じような文字列です。区切り文字が @code{NULL} の場合、結果は @code{NULL} になります。関数は区切り文字より後 の @code{NULL} と空文字列を飛ばします。区切り文字は結合される文字列の間に 追加されます。 @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) 文字列 @code{str} の長さ。 @example mysql> select LENGTH('text'); -> 4 mysql> select OCTET_LENGTH('text'); -> 4 @end example 注意: @code{CHAR_LENGTH()} については、マルチバイト文字は一度だけしかカウ ントされません。 @findex LOCATE() @findex POSITION() @item LOCATE(substr,str) @itemx POSITION(substr IN str) @code{str} 内にある @code{substr} 文字列の位置を返します。最初の位置は 1 です。 @code{str} 内に @code{substr} がない時は @code{0} を返します。 @example mysql> select LOCATE('bar', 'foobarbar'); -> 4 mysql> select LOCATE('xbar', 'foobar'); -> 0 @end example この関数はマルチバイトでも安全です。 @findex LOCATE() @item LOCATE(substr,str,pos) 文字列 @code{str} 中に最初に顕れた @code{substr} 文字の位置を返します。 @code{pos} は検索を開始する位置です。 @code{str} に @code{substr} がなければ @code{0} を返します。 @example mysql> select LOCATE('bar', 'foobarbar',5); -> 7 @end example この関数はマルチバイトでも安全です。 @findex INSTR() @item INSTR(str,substr) 文字列 @code{str} 内の最初の文字列 @code{substr} の位置を返します。 これは引数が入れ替わっていることをのぞいて、 2つの引数を与えた @code{LOCATE} と同じです。 @example mysql> select INSTR('foobarbar', 'bar'); -> 4 mysql> select INSTR('xbar', 'foobar'); -> 0 @end example この関数はマルチバイトでも安全です。 @findex LPAD() @item LPAD(str,len,padstr) @code{str} の長さが @code{len} になるまで文字列 @code{str} の始めに @code{padstr} を埋めます。 @example mysql> select LPAD('hi',4,'??'); -> '??hi' @end example @findex RPAD() @item RPAD(str,len,padstr) @code{str} の長さが @code{len} になるまで文字列 @code{str} の終わりに @code{padstr} を埋めます。 @example mysql> select RPAD('hi',5,'?'); -> 'hi???' @end example @findex LEFT() @item LEFT(str,len) 文字列 @code{str} の最初から @code{len} 個の文字を得ます。 @example mysql> select LEFT('foobarbar', 5); -> 'fooba' @end example この関数はマルチバイトでも安全です。 @findex RIGHT() @item RIGHT(str,len) 文字列 @code{str} の最後から @code{len} 個の文字を得ます。 @example mysql> select RIGHT('foobarbar', 4); -> 'rbar' @end example この関数はマルチバイトでも安全です。 @findex SUBSTRING() @findex MID() @item SUBSTRING(str,pos,len) @itemx SUBSTRING(str FROM pos FOR len) @itemx MID(str,pos,len) @code{str} の @code{pos} 位置から @code{len} 文字数分の文字列を返します。 @code{FROM} の違いは ANSI SQL 92 構文です。 @example mysql> select SUBSTRING('Quadratically',5,6); -> 'ratica' @end example この関数はマルチバイトでも安全です。 @findex SUBSTRING() @item SUBSTRING(str,pos) @item SUBSTRING(str FROM pos) 文字列 @code{str} の 位置 @code{pos} 以降の文字を返します。 @example mysql> select SUBSTRING('Quadratically',5); -> 'ratically' mysql> select SUBSTRING('foobarbar' FROM 4); -> 'rbar' @end example この関数はマルチバイトでも安全です。 @findex SUBSTRING_INDEX() @item SUBSTRING_INDEX(str,delim,count) @code{str} から、区切り文字 @code{delim} が @code{count} 個現れた位置から前の 文字列を返します。@code{count} が正の場合は文字列は左から検索され、 @code{count} が負の場合は文字列は右から検索されます。 @example mysql> select SUBSTRING_INDEX('www.mysql.com', '.', 2); -> 'www.mysql' mysql> select SUBSTRING_INDEX('www.mysql.com', '.', -2); -> 'mysql.com' @end example この関数はマルチバイトでも安全です。 @findex LTRIM() @item LTRIM(str) 文字列 @code{str} の最初から空白文字を削除します。 @example mysql> select LTRIM(' barbar'); -> 'barbar' @end example @findex RTRIM() @item RTRIM(str) 文字列 @code{str} の最後から空白文字を削除します。 @example mysql> select RTRIM('barbar '); -> 'barbar' @end example @findex TRIM() @item TRIM([[BOTH | LEADING | TRAILING] [remstr] FROM] str) 全ての @code{remstr} プレフィックスまたはサフィックスを @code{str} から削除した 文字列を返します。@code{BOTH}, @code{LEADING} そして @code{TRAILING} が 使用されない場合、@code{BOTH} が適用されます。@code{remstr} が与えられないと、 空白が削除されます。 @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 この関数はマルチバイトでも安全です。 @findex SOUNDEX() @item SOUNDEX(str) @code{str} からの soundex 文字列を返します。発音が``大体同じ''2つの文字列 は同じ soundex 文字列を持ちます。``標準の'' soundex 文字列は4文字長ですが、 @code{SOUNDEX()} 関数は任意の長さの文字列を返します。@code{SUBSTRING()} を 結果に使用して、``標準の'' soundex 文字列を得ることができます。与えられた 文字列中の非アルファベット文字は無視されます。A-Z の半以外のすべての国際的 なアルファベット文字は母音とみなされます。 @example mysql> select SOUNDEX('Hello'); -> 'H400' mysql> select SOUNDEX('Quadratically'); -> 'Q36324' @end example @findex SPACE() @item SPACE(N) @code{N} 個の空白文字を返します。 @example mysql> select SPACE(6); -> ' ' @end example @findex REPLACE() @item REPLACE(str,from_str,to_str) 文字列 @code{str} 内の全ての文字列 @code{from_str} を @code{to_str} に 置き換えます。 @example mysql> select REPLACE('www.mysql.com', 'w', 'Ww'); -> 'WwWwWw.mysql.com' @end example この関数はマルチバイトでも安全です。 @findex REPEAT() @item REPEAT(str,count) @code{str} を @code{count} 回繰り返します。@code{count <= 0} の場合は 空の文字列を返します。@code{str} または @code{count} が @code{NULL} または、@code{LENGTH(str)*count > max_allowed_packet} の場合は @code{NULL} を返します。 @example mysql> select REPEAT('MySQL', 3); -> 'MySQLMySQLMySQL' @end example @findex REVERSE() @item REVERSE(str) 文字列 @code{str} を反転します。 @example mysql> select REVERSE('abc'); -> 'cba' @end example この関数はマルチバイトでも安全です。 @findex INSERT() @item INSERT(str,pos,len,newstr) @code{str} 中の @code{pos} 位置から @code{len} 長の文字列を @code{newstr} で置き換えます。@code{str} 内の最初の位置は1です。 @example mysql> select INSERT('Quadratic', 3, 4, 'What'); -> 'QuWhattic' @end example この関数はマルチバイトでも安全です。 @findex ELT() @item ELT(N,str1,str2,str3...) @code{N} = @code{1} なら @code{str1} を、@code{N} = @code{2} なら @code{str2} を返します。 @code{N} が @code{1} より小さい場合、または引数の数より大きい場合は @code{NULL} が返されます。 @code{ELT()} は @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,...) @code{str1}, @code{str2}, @code{str3}, @code{...} リスト内の @code{str} のインデックスを 返します。@code{str} が見つからなければ @code{0} を返します。 @code{FIELD()} は @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) @code{str} が @code{strlist} 中にあれば、値 @code{1} から @code{N} を返します。 @code{strlist} は、それぞれの異なる値が ',' で分割された文字列です。最初の 引数が定数文字列で2番目が @code{SET} 型のフィールドの場合@code{FIND_IN_SET} は ビット演算を使用して最適化されます! @code{strlist} が空文字なら @code{0} を返します。 どちらかの引数が @code{NULL} なら @code{NULL} を返します. この関数は最初の引数が ',' を含んだ場合、うまく動かないでしょう。 @example mysql> SELECT FIND_IN_SET('b','a,b,c,d'); -> 2 @end example @findex MAKE_SET() @item MAKE_SET(bits,str1,str2,...) @code{bits} に指定されたビットに対応する文字列のセットを返します。 (文字列が複数の場合、 @samp{,} で区切られます) @code{str1} が ビット 0 に対応し、@code{str2} が ビット 1 に対応し、 @code{str3} が ビット 2 に対応し... となります。 @code{str1}, @code{str2}, @code{...} 中に含まれている @code{NULL} 文字は 結果には追加されません。 @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]]) 'bits' に与えられた数値に対し、 全てのセットされているビットを 'on' で指定された文字で表し、 リセットされているビットを 'off' で指定された文字で表した文字列を返します。 それぞれの文字は 'separator' (デフォルト',') で示された文字で区切られ、 'number_of_bits' (default 64) に与えられた桁数だけのビットを表示します。 @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) @code{str} を現在のキャラクターセットマッピング (デフォルト ISO-8859-1 Latin1) にしたがって小文字に変換します。 この関数はマルチバイトでも安全です。 @example mysql> select LCASE('QUADRATICALLY'); -> 'quadratically' @end example @findex UCASE() @findex UPPER() @item UCASE(str) @itemx UPPER(str) @code{str} を現在のキャラクターセットマッピング (デフォルト ISO-8859-1 Latin1) にしたがって大文字に変換します。 @example mysql> select UCASE('Hej'); -> 'HEJ' @end example この関数はマルチバイトでも安全です。 @findex FILE @item LOAD_FILE(file_name) ファイルを読み込み、ファイルの中身を文字として返します。 ファイルは サーバー上になくてはならず、ファイルをフルパスで指定しなければなりません。 そして、 @strong{file} 権限がなければなりません。 ファイルは全員に 読み込み可能でなければならず、そして、 @code{max_allowed_packet} より 小さいサイズでなければなりません。 このうちどれかの理由で、もしファイルが存在しないか読み込めない場合、 この関数は @code{NULL} を返します。 @example mysql> UPDATE table_name SET blob_column=LOAD_FILE("/tmp/picture") WHERE id=1; @end example @end table @strong{MySQL} は必要とあらば数値を文字列に変換します。 逆も同様に行います: @example mysql> SELECT 1+"1"; -> 2 mysql> SELECT concat(2,' test'); -> '2 test' @end example 明示的に数値を文字列に変換したければ、@code{CONCAT()} に引数として渡して下 さい。 文字列関数は引数としてバイナリ文字列が与えられると、結果の文字列もバイナリ 文字列になります。文字列に変換された数値はバイナリ文字列とみなされます。こ れは比較にだけ影響します。 @findex Date and time functions @findex Functions, date and time @node Date and time functions, Miscellaneous functions, String functions, Functions @subsection 日付と時刻関数 それぞれの型がもつ値の範囲と日と時間の値が記述される有効な形式については @ref{Date and time types}. 日付関数を使用する例: @code{date_col} が最新の30日である全てのレコードを選択します: @example mysql> SELECT something FROM table WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30; @end example @table @code @findex DAYOFWEEK() @item DAYOFWEEK(date) @code{date} の曜日を得ます (@code{1} = 日曜日, @code{2} = 月曜日, ... @code{7} = 土曜日) これは ODBC 標準に従います。 @example mysql> select DAYOFWEEK('1998-02-03'); -> 3 @end example @findex WEEKDAY() @item WEEKDAY(date) @code{date} の曜日を得ます (@code{0} = 日曜日, @code{1} = 月曜日, ... @code{6} = 土曜日) @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) 月の日を返します (@code{1} - @code{31}) @example mysql> select DAYOFMONTH('1998-02-03'); -> 3 @end example @findex DAYOFYEAR() @item DAYOFYEAR(date) 年の日を返します (@code{1}-@code{366}) @example mysql> select DAYOFYEAR('1998-02-03'); -> 34 @end example @findex MONTH() @item MONTH(date) 月を返します (@code{1} - @code{12}) @example mysql> select MONTH('1998-02-03'); -> 2 @end example @findex DAYNAME() @item DAYNAME(date) 曜日の名前を返します。 @example mysql> select DAYNAME("1998-02-05"); -> 'Thursday' @end example @findex MONTHNAME() @item MONTHNAME(date) 月の名前を返します。 @example mysql> select MONTHNAME("1998-02-05"); -> 'February' @end example @findex QUARTER() @item QUARTER(date) @code{date} についての年の四半期を返します。範囲は @code{1} から @code{4} です。 @example mysql> select QUARTER('98-04-01'); -> 2 @end example @findex WEEK() @item WEEK(date) @itemx WEEK(date,first) 引数が一つの場合、@code{date} についての週を返します。範囲は @code{0} から @code{53} (そう、53週の最初というのもありえます)で、日曜日が週の 最初の日です。引数が二つの形式の @code{WEEK()} は、週の開始を日曜日か月曜 日か指定できます。第2引数が @code{0} の場合、週の開始は日曜日です。第2引数 が @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) 年を返します (@code{1000} - @code{9999}). @example mysql> select YEAR('98-02-03'); -> 1998 @end example @item YEARWEEK(date) @itemx YEARWEEK(date,first) データの年と週を返します。第2引数は @code{WEEK()} の第2引数とまったく同じ ように働きます。注意: 年の最初と最後の週では、年が date 引数内の年とは異な ることがあります! @example mysql> select YEARWEEK('1987-01-01'); -> 198653 @end example @findex HOUR() @item HOUR(time) 時を返します (@code{0} - @code{23}) @example mysql> select HOUR('10:05:03'); -> 10 @end example @findex MINUTE() @item MINUTE(time) 分を返します (@code{0}-@code{59}) @example mysql> select MINUTE('98-02-03 10:05:03'); -> 5 @end example @findex SECOND() @item SECOND(time) 秒を返します (@code{0} to @code{59}) @example mysql> select SECOND('10:05:03'); -> 3 @end example @findex PERIOD_ADD() @item PERIOD_ADD(P,N) @code{N} 月を期間 @code{P} (型 @code{YYMM} または @code{YYYYMM}) に追加 します。@code{YYYYMM} を返します。 注意: 期間引数 @code{P} は日付値では@emph{ありません}。 @example mysql> select PERIOD_ADD(9801,2); -> 199803 @end example @findex PERIOD_DIFF() @item PERIOD_DIFF(P1,P2) 期間 @code{P1} と @code{P2} の差の月を返します。@code{P1} と @code{P2} は形 式 @code{YYMM} または @code{YYYYMM} です。 注意: 期間引数 @code{P1} と @code{P2} は日付値では@emph{ありません}。 @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) これら関数は日付の演算に使用します。 これらは @strong{MySQL} 3.22 の 新しい機能です。 @code{ADDDATE()} と @code{SUBDATE()} は @code{DATE_ADD()} , @code{DATE_SUB()} と同義です。 @strong{MySQL} 3.23 では, @code{+} と @code{-} を @code{DATE_ADD()} , @code{DATE_SUB()} の代わりに使用できます. (See example) @code{date} には、@code{DATETIME} か @code{DATE} 型の値を指定します。 この値から演算が開始されます。 @code{expr} には、date から増減させる値を指定します。 @code{expr} が @samp{-} から始まっていれば、負数を示します。 @code{type} はどれぐらいの期間かを示すキーワードです。 @code{EXTRACT(type FROM date)} 関数は、date から 'type' の部分を返します。 以下の表に、@code{type} と @code{expr} の関連を示します: @multitable @columnfractions .18 .3 .42 @item @code{type} @strong{値} @tab @strong{意味} @tab @code{expr} @strong{のフォーマット} @item @code{SECOND} @tab 秒 @tab @code{SECONDS} @item @code{MINUTE} @tab 分 @tab @code{MINUTES} @item @code{HOUR} @tab 時間 @tab @code{HOURS} @item @code{DAY} @tab 日 @tab @code{DAYS} @item @code{MONTH} @tab 月 @tab @code{MONTHS} @item @code{YEAR} @tab 年 @tab @code{YEARS} @item @code{MINUTE_SECOND} @tab 分と秒 @tab @code{"MINUTES:SECONDS"} @item @code{HOUR_MINUTE} @tab 時間と分 @tab @code{"HOURS:MINUTES"} @item @code{DAY_HOUR} @tab 日 と時間 @tab @code{"DAYS HOURS"} @item @code{YEAR_MONTH} @tab 年 と月 @tab @code{"YEARS-MONTHS"} @item @code{HOUR_SECOND} @tab 時間と分 @tab @code{"HOURS:MINUTES:SECONDS"} @item @code{DAY_MINUTE} @tab 日、時、分 @tab @code{"DAYS HOURS:MINUTES"} @item @code{DAY_SECOND} @tab 日、時、分、秒 @tab @code{"DAYS HOURS:MINUTES:SECONDS"} @end multitable @strong{MySQL} は、 @code{expr} フォーマット内のいかなる句読点区切りをも許します。 上の表中の区切り文字は提案する区切り文字です。 もし @code{date} 引数が @code{DATE} 値で、@code{YEAR}, @code{MONTH}, @code{DAY} の部分のみを含む 計算をするなら、結果は @code{DATE} 値が返ります。 それ以外なら @code{DATETIME} 値が 返ります。 @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 もしあなたの指定する interval 値が短すぎるなら( @code{type} キーワードから 類推される値を含んでいない場合)、 @strong{MySQL} は interval 値の一番 左の部分を指定し忘れたものだと仮定します。 例えば、もし @code{type} を @code{DAY_SECOND} に指定した場合、 @code{expr} の値は 日、時、分、秒 からなる物と期待されます。 ここであなたが @code{"1:10"} のような値を指定していたなら、 @strong{MySQL} は、日、時 の部分が忘れ去られて、分、秒 が与えられたと 推定します。 つまり、 @code{"1:10" DAY_SECOND} は @code{"1:10" MINUTE_SECOND} で あると理解されるのです。 これは、@strong{MySQL} が @code{TIME} 値を時刻ではなく経過時間の表現と解釈 する方法に類似しています。 もし、不正な値が使用されたなら、結果は @code{NULL} です. もし @code{MONTH} や @code{YEAR_MONTH} や @code{YEAR} を足し算して、 結果となる日付が新しい月の最大日よりも大きい日になるようなら、 その日は、新しい月の最大日に修正されます。 @example mysql> select DATE_ADD('1998-01-30',Interval 1 month); -> 1998-02-28 @end example 例のように、@code{INTERVAL} と @code{type} キーワードは ケース依存ではありません。 @findex TO_DAYS() @item TO_DAYS(date) 日付 @code{date} を与えると、0年からの日数を返します。 @example mysql> select TO_DAYS(950501); -> 728779 mysql> select TO_DAYS('1997-10-07'); -> 729669 @end example @code{TO_DAYS()} はグレゴリオ歴の開始(1582)より前の値での使用を意図されて いません。歴が変更された時に失われた日を考慮に入れてないからです。 @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()} はグレゴリオ歴の開始(1582)より前の値での使用を意図され ていません。歴が変更された時に失われた日を考慮に入れてないからです。 @findex DATE_FORMAT() @item DATE_FORMAT(date,format) @code{date} 値を @code{format} 文字列に従って整形します。次の指定が @code{format} 文字列で使用できます: @multitable @columnfractions .1 .9 @item @code{%M} @tab 月名 (@code{January}..@code{December}) @item @code{%W} @tab 曜日 (@code{Sunday}..@code{Saturday}) @item @code{%D} @tab 英語サフィックス付き月の日 (@code{1st}, @code{2nd}, @code{3rd}, etc.) @item @code{%Y} @tab 4桁の年 @item @code{%y} @tab 2桁の年 @item @code{%X} @tab 週の年。週の最初の日は日曜日。4桁の数値。'%V' と共に使用されます @item @code{%x} @tab 週の年。週の最初の日は月曜日。4桁の数値。'%v' と共に使用されます @item @code{%a} @tab 省略された曜日名 (@code{Sun}..@code{Sat}) @item @code{%d} @tab 月の日, 数値 (@code{00}..@code{31}) @item @code{%e} @tab 月の日, 数値 (@code{0}..@code{31}) @item @code{%m} @tab 月, 数値 (@code{01}..@code{12}) @item @code{%c} @tab 月, 数値 (@code{1}..@code{12}) @item @code{%b} @tab 省略された月名 (@code{Jan}..@code{Dec}) @item @code{%j} @tab 年の日 (@code{001}..@code{366}) @item @code{%H} @tab 時 (@code{00}..@code{23}) @item @code{%k} @tab 時 (@code{0}..@code{23}) @item @code{%h} @tab 時 (@code{01}..@code{12}) @item @code{%I} @tab 時 (@code{01}..@code{12}) @item @code{%l} @tab 時 (@code{1}..@code{12}) @item @code{%i} @tab 分, 数値 (@code{00}..@code{59}) @item @code{%r} @tab 時刻, 12時間 (@code{hh:mm:ss [AP]M}) @item @code{%T} @tab 時刻, 24時間 (@code{hh:mm:ss}) @item @code{%S} @tab 秒 (@code{00}..@code{59}) @item @code{%s} @tab 秒 (@code{00}..@code{59}) @item @code{%p} @tab @code{AM} or @code{PM} @item @code{%w} @tab 週の日 (@code{0}=Sunday..@code{6}=Saturday) @item @code{%U} @tab 週 (@code{0}..@code{53}), 週のはじまりを 日曜とした場合 @item @code{%u} @tab 週 (@code{0}..@code{53}), 週のはじまりを 月曜とした場合 @item @code{%V} @tab 週 (@code{1}..@code{53}), 週のはじまりは日曜日。'%X' と共に使用されます @item @code{%v} @tab 週 (@code{1}..@code{53}), 週のはじまりは月曜日。'%x' と共に使用されます @item @code{%%} @tab リテラル @samp{%}。 @end multitable 他の全ての文字は解釈されずに結果にコピーされます。 @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 @strong{MySQL} 3.23 では、 @code{%} 文字はフォーマット文字の前に必ず必要とされます。 それより前のバージョンでは、 @code{%} 文字はオプションでした。 @findex TIME_FORMAT() @item TIME_FORMAT(time,format) これは上記の @code{DATE_FORMAT()} のように使用されますが、 @code{format} オプションでは、時,分,秒だけを操作できます。 他のオプションは @code{NULL} or @code{0} を与えます。 @findex CURDATE() @findex CURRENT_DATE @item CURDATE() @itemx CURRENT_DATE 今日の日付を返します。日付の形式は、@code{CURDATE()} が数値または文字列のどち らの文脈で使用されたかに依存して @code{YYYYMMDD} または @code{'YYYY-MM-DD'} で返されます。 @example mysql> select CURDATE(); -> '1997-12-15' mysql> select CURDATE() + 0; -> 19971215 @end example @findex CURTIME() @findex CURRENT_TIME @item CURTIME() @itemx CURRENT_TIME 現在の時刻を @code{HHMMSS} または @code{'HH:MM:SS'} の形式で返します。こ れは @code{CURTIME()} が数値または文字列のどちらの文脈で使用されたかに依 存します。 @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 現在の時刻を返します。数値または文字列のどちらの文脈で使用されたかに依存して @code{YYYYMMDDHHMMSS} または @code{'YYYY-MM-DD HH:MM:SS'} 形式で返されます。 @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) 引数なしで呼び出された場合は、UNIX timestamp (GMT @code{'1970-01-01 00:00:00'} か らの秒数) です。通常は、@code{TIMESTAMP} フィールドを引数として呼び出し、フィールドの 値を秒数で返します。@code{date} はローカル時刻での @code{DATE} 文字列、@code{DATETIME} 文字列、または @code{YYMMDD} または @code{YYYYMMDD} 形式の数値です。 @example mysql> select UNIX_TIMESTAMP(); -> 882226357 mysql> select UNIX_TIMESTAMP('1997-10-04 22:23:00'); -> 875996580 @end example @code{UNIX_TIMESTAMP} が @code{TIMESTAMP} フィールドに使用された場合、 この関数は、暗黙の ``文字から UNIX タイムスタンプ'' 変換をすることなく、 値を得ます。 @findex FROM_UNIXTIME() @item FROM_UNIXTIME(Unix_timestamp) 文脈(数値/文字列)に依存して、@code{'YYYY-MM-DD HH:MM:SS'} または @code{YYYYMMDDHHMMSS} 形式の timestamp 文字列を返します。 @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) @code{format} に従って整形された Unix timestamp 文字列を返します。 @code{format} は @code{DATE_FORMAT()} 関数のエントリに一覧されたのと同じ指 定子を含むことができます。 @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) @code{seconds} 引数を時分秒に変換して返します。関数が文字列文脈または数値 文脈のどちらで使用されたかに依存して、@code{'HH:MM:SS'} または @code{HHMMSS} 形式で値を返します。 @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) @code{time} を秒に変換します。 @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 その他の関数 @table @code @findex DATABASE() @item DATABASE() 現在のデータベース名を返します。 @example mysql> select DATABASE(); -> 'test' @end example もしデータベースが選択されていないなら、@code{DATABASE()} は空文字を返します。 @findex USER() @findex SYSTEM_USER() @findex SESSION_USER() @item USER() @itemx SYSTEM_USER() @itemx SESSION_USER() 現在の @strong{MySQL} ユーザ名を返します。 @example mysql> select USER(); -> 'davida@@localhost' @end example @strong{MySQL} 3.22.11 以降では、この関数はユーザー名とクライアントのホスト名を含みます。 ユーザー名の部分だけ取り出すには次のようにします。 (これはホスト名が含まれていなくとも動くでしょう): @example ysql> select substring_index(USER(),"@@",1); -> 'davida' @end example @findex PASSWORD() @item PASSWORD(str) プレーンテキストのパスワード @code{str} からパスワード文字列を計算します。 これは @code{user} 許可テーブルの @code{Password} フィールドに、 暗号化された @strong{MySQL} パスワードを保存する際に使用されます。 @example mysql> select PASSWORD('badpwd'); -> '7f84554057dd964b' @end example @cindex Password encryption, reversibility of @code{PASSWORD()} 暗号は不可逆です。 @code{PASSWORD()} は UNIX のパスワードが暗号化するのと同じ方法で 暗号化を行うわけではありません。 UNIX のパスワードと @strong{MySQL} のパスワードが同じと思ってはいけません。 UNIX のパスワードファイルに保存される値が @code{PASSWORD()} が返すと 考えてはいけません。 @code{ENCRYPT()} 参照。 @findex ENCRYPT() @item ENCRYPT(str[,salt]) UNIX の @code{crypt()} システムコールで @code{str} を暗号化します。 @code{salt} は2文字の文字列です。 (@strong{MySQL} 3.22.16 で, @code{salt} は2文字以上許されるようになりました。) @example mysql> select ENCRYPT("hello"); -> 'VxuFAJXVARROc' @end example システムで @code{crypt()} が利用できない場合は @code{ENCRYPT()} は常に @code{NULL} を返します。 少なくともいくつかのシステムでは、 @code{ENCRYPT()} は @code{str} 文字中の最初の 8 文字以外は全て無視します。 これは @code{crypt()} システムコールの振る舞いによって決定づけられます。 @findex ENCODE() @item ENCODE(str,pass_str) パスワードとして @code{pass_str} を用いて @code{str} を暗号化します。結果 を復号化するには、@code{DECODE()}を使用します。 結果はバイナリ文字列です。フィールドにそれを保存したい場合は @code{BLOB} フィールド型を使用してください。 @findex DECODE() @item DECODE(crypt_str,pass_str) 暗号化された文字列 @code{crypt_str} をパスワードとして @code{pass_str} を 用いて復号化します。@code{crypt_str} は @code{ENCODE()} から返された文字列 であるべきです。 @findex MD5() @item MD5(string) 文字列を MD5 チェックサムした結果を返します。 値は 32 桁の 16進表示です。 例えばハッシュキーとして使用できるように。 @example mysql> select MD5("testing") -> 'ae2b1fca515949e5d54fb22b8ed95575' @end example これは "RSA Data Security, Inc. MD5 Message-Digest Algorithm". @findex LAST_INSERT_ID([expr]) @item LAST_INSERT_ID([expr]) 最後に @code{AUTO_INCREMENT} フィールドに挿入されて自動的に生成された値を返します。 @xref{mysql_insert_id, , @code{mysql_insert_id()}}. @example mysql> select LAST_INSERT_ID(); -> 195 @end example 最後の作成された ID はそれぞれのコネクション毎にサーバーに維持されます。 これは他のクライアントからは変更できないでしょう。 もし他の非マジック値をもつ @code{AUTO_INCREMENT} フィールド (値が @code{NULL} でも @code{0} でもないということ) を更新しても、これは 変更されません。 @cindex Sequence emulation もし @code{UPDATE} 節内の @code{LAST_INSERT_ID()} の引数に @code{expr} を指定すると、 引数の値は @code{LAST_INSERT_ID()} の値として返ります。 これは シーケンス番号のシミュレーションに使用できます: 最初にテーブルを作成: @example mysql> create table sequence (id int not null); mysql> insert into sequence values (0); @end example そして以下のようにしてシーケンス番号を生成: @example mysql> UPDATE sequence SET id=last_insert_id(id+1); @end example @code{LAST_INSERT_ID()} の呼び出し無しでシーケンス番号を生成することが可能 ですが、この方法でこの関数を使用するユーティリティは、ID 値が最後に自動的 に生成された値としてサーバに管理されます。@strong{MySQL} 内の通常の任意の @code{AUTO_INCREMENT} 値を読み込んで新しい ID を取り出すことができます。例 えば、@code{LAST_INSERT_ID()} (引数無し) は新しい ID を返します。C API 関 数 @code{mysql_insert_id()} もこの値を得るために使用できます。 @findex FORMAT() @item FORMAT(X,D) @code{'#,###,###.##'} のような形式(小数部 @code{X} 桁)で数値 @code{D} を整形 します。 もし @code{D} が @code{0} なら, 結果にはいかなる 小数点も小数部も含まれません。 @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() @strong{MySQL} サーバのバージョンを返します。 @example mysql> select VERSION(); -> '3.23.13-log' @end example 注意: バージョンが @code{-log} で終わる場合はロギングが有効であることを意 味します。 @findex CONNECTION_ID() @item CONNECTION_ID() 接続の接続 ID (@code{thread_id}) を返します。すべての接続は接続自身の一意 な ID を持ちます。 @example mysql> select CONNECTION_ID(); -> 1 @end example @findex GET_LOCK() @item GET_LOCK(str,timeout) @code{timeout} 秒のタイムアウトで、@code{str} と名付けられたロックの獲得を試み ます。ロックを獲得した場合は @code{1}, タイムアウトの場合は @code{0}, エラーの場合(メ モリ不足やスレッドが @code{mysqladmin kill} で殺された場合など)は @code{NULL} が返ります。@code{RELEASE_LOCK} の実行、新しい @code{GET_LOCK} の実行、 スレッドの終了の場合に、ロックは解放されます。この関数はアプリケーション ロックやレコードロックのシミュレートのために使用できます。 これは、同じ名前のロックを行おうとする他のクライアントからのリクエストを ブロックします; 与えられた名前のロックに応じているクライアントは、 協調してロッキングを行うために、その文字列を使用できます。 @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 2つ目の @code{RELEASE_LOCK()} は @code{NULL} を返します。 なぜなら、 @code{"lock1"} は、2つ目の @code{GET_LOCK()} の呼び出し時点で、 自動的に解放されるからです。 @findex RELEASE_LOCK() @item RELEASE_LOCK(str) @code{GET_LOCK} で獲得したロック @code{str} を解放します。ロックが解 放された場合は @code{1}, このスレッドによってロックされていない場合は @code{0} (この場合、ロックは解放されません), @code{str}が存在しない場合は @code{NULL} が返ります。 もし、 @code{GET_LOCK()} をコールして得られなかった場合、 あるいは、既に解放されている場合は、ロックは存在しないでしょう。 @findex BENCHMARK() @item BENCHMARK(count,expr) @code{BENCHMARK()} 関数は @code{expr} で与えられた文を @code{count} 回 繰り返し実行します。 これは @strong{MySQL} のその文の処理がどれぐらい 速いのか知るのに使用されるでしょう。 結果は常に @code{0} です。 想定している使用は、 @code{mysql} クライアントです。 あるクエリの実行時間を知るための使用です。 @example mysql> select BENCHMARK(1000000,encode("hello","goodbye")); +----------------------------------------------+ | BENCHMARK(1000000,encode("hello","goodbye")) | +----------------------------------------------+ | 0 | +----------------------------------------------+ 1 row in set (4.74 sec) @end example 報告された時間は、クライアントでの経過時間です。 サーバー側の CPU 時間では ありません。@code{BENCHMARK()} を何回か実行して、サーバマシンの負荷の重さ を考慮して結果を解釈することを勧めます。 @findex INET_NTOA() @item INET_NTOA(expr) 数値表現に対するネットワークアドレス(4 または 8 バイト) を返します。 @example mysql> select INET_NTOA(3520061480); -> "209.207.224.40" @end example @findex INET_ATON() @item INET_NTOA(expr) ネットワークアドレスに対する数値を表す整数を返します。アドレスは 4 または 8 バイトアドレスです。 @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 @code{GROUP BY} 節の関数 @code{GROUP BY} 節なしで グループ関数を使用するなら、 これは全てのレコードをグループ化することになります。 @table @code @findex COUNT() @item COUNT(expr) @code{SELECT} 文によって得られるレコード 中、値が 非@code{NULL} で あるレコードの数を返します。 @example mysql> select student.student_name,COUNT(*) from student,course where student.student_id=course.student_id GROUP BY student_name; @end example 検索されたレコードの数が、レコード中に @code{NULL} 値を含むかどうかで、 @code{COUNT(*)} で返る値ははいくぶん異なります。 もし @code{SELECT} が一つのテーブルから検索し、かつ、 他のフィールドが検索されることもなく、かつ @code{WHERE} 節が無いならば、 @code{COUNT(*)} は速く答えるために最適化されます。 例えば: @example mysql> select COUNT(*) from student; @end example @findex COUNT(DISTINCT) @findex DISTINCT @item COUNT(DISTINCT expr,[expr...]) 異なる値の数のカウントを返します。 @example mysql> select COUNT(DISTINCT results) from student; @end example @strong{MySQL} では、式のリストを与えることで、別個の式の組合せの数を得る ことができます。ANSI SQL では、すべての式を @code{CODE(DISTINCT ..)} 内で 結合する必要があります。 @findex AVG() @item AVG(expr) @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) @code{expr}.の最小/最大値。 @code{min()} と @code{max()} が文字列引数を取ると、最小/最大の文字列値を返します。 @example mysql> select student_name, MIN(test_score), MAX(test_score) from student GROUP BY student_name; @end example @findex SUM() @item SUM(expr) @code{expr}の合計. 注意: 結果セットが何もレコードを返さない場合は、これは NULL を返します! @findex STD() @findex STDDEV() @cindex Oracle compatibility @cindex Compatibility, with Oracle @item STD(expr) @itemx STDDEV(expr) @code{expt} の標準誘導(standard derivative)。これは @code{ANSI SQL} に対する拡張です。 この関数の @code{STDDEV()} 形式は、Oracle 互換のために提供されました。 @findex BIT_OR() @item BIT_OR(expr) @code{expr} 内の全てのビットの論理 @code{OR}。64 ビット(@code{BIGINT})の精 度で計算されます。 @findex BIT_AND() @item BIT_AND(expr) @code{expr} 内の全てのビットの論理 @code{AND}。64 ビット(@code{BIGINT})の 精度で計算されます。 @end table @strong{MySQL} は @code{GROUP BY} を拡張しています。@code{SELECT} 表現内で @code{GROUP BY} 部に現れないフィールドまたは計算を使用できます。これは @emph{このグルー プのための全ての可能な値} を表しています。この使用により、必要ないフィールドで のソートとグループが避けられるので、高い性能が得られます。例えば、次のク エリでは @code{customer.name} でグループする必要はありません: @example mysql> select order.custid,customer.name,max(payments) from order,customer where order.custid = customer.custid GROUP BY order.custid; @end example ANSI SQL では、@code{GROUP BY} 節に @code{customer.name} を追加する必要があります。 @strong{MySQL} では、ANSI モードで実行していない場合は、name は冗長です。 @code{GROUP BY} 部から省略したフィールドがグループ内で一意でない場合は、こ の機能を使用しないでください! いくつかのケースでは、それが一意でない場合でも、@code{MIN()} と @code{MAX()} を特定のフィールド値を獲得するために使用することができます。 次は、@code{sort} フィールド内の最小の値を含むレコードからの @code{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 注意: @strong{MySQL} 3.22 (またはそれ以前) を使用している場合、または ANSI SQL に従おうとしている場合は、@code{GROUP BY} や @code{ORDER BY} 節で 式を使用できません。式の別名を使用することでこの制限を回避できます: @example mysql> SELECT id,FLOOR(value/100) AS val FROM tbl_name GROUP BY id,val ORDER BY val; @end example @code{MySQL} 3.23 では次を行なうことができます: @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}構文 @example CREATE DATABASE [IF NOT EXISTS] db_name @end example @code{CREATE DATABASE} は与えられた名前のデータベースを作ります。データベースの名前として許される命名規則は、@ref{Legal names}に依ります。 もし、データベースがすでに存在しているにもかかわらず @code{IF NOT EXISTS} を 指定していなかったら、エラーが発生します。 @strong{MySQL}におけるデータベースは、データベース内のテーブルに相当するファイルを含むディレクトリとして実装されます。初期作成後はデータベース内にテーブルは存在せず、@code{CREATE DATABASE}ステートメントは、@strong{MySQL}データディレクトリ下にディレクトリを作成するだけです。 @cindex @code{mysqladmin} @code{mysqladmin}でもデータベースを作成することができます。 @xref{Programs}. @findex DROP DATABASE @node DROP DATABASE, CREATE TABLE, CREATE DATABASE, Reference @section @code{DROP DATABASE}構文 @example DROP DATABASE [IF EXISTS] db_name @end example @code{DROP DATABASE}は、データベース内の全てのテーブルと共にデータベースを破棄します。@strong{このコマンドの使用には万全の注意を払って下さい!} @code{DROP DATABASE}は、データベースディレクトリから削除されたファイルの数を返します。それぞれのテーブルは@file{.MYD}ファイル/@file{.MYI}ファイル/@file{.frm}ファイルに相当することから、通常この値はテーブルの3倍の数となります。 @strong{MySQL} 3.22以降では、データベースが存在しないことに起因するエラーを防ぐために、キーワード @code{IF EXISTS} を使用することができます。 @cindex @code{mysqladmin} @code{mysqladmin}でもデータベースを破棄することができます。 @xref{Programs}. @findex CREATE TABLE @node CREATE TABLE, ALTER TABLE, DROP DATABASE, Reference @section @code{CREATE TABLE}構文 @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}はカレントデータベースに、与えられた名前のテーブルを 作成します。テーブルの名前として許される命名規則は、@xref{Legal names}に 依ります。 カレントデータベースが無い場合や、テーブルが既に存在している場合はエラーが 発生します。 @strong{MySQL} 3.22 以降ではテーブル名は @code{db_name.tbl_name} という形で与える事もできます。 これはカレントデータベースがあるかどうかにに関係なく動作します。 @strong{MySQL} 3.23 では、テーブル作成時に @code{TEMPORARY} キーワードを使用することが できます。 一時テーブルは、もし、コネクションが落ちた場合、自動で消去されます。 一時テーブルの名前はそれぞれの接続ごとです。 これは、二つの違う接続で、同じ名前の一時テーブルを 衝突することなく、使用できるという事です。 さらには、既に存在するテーブルと同名であっても、一時テーブルは使用できます。 (一時テーブルが削除されるまで、実在するテーブルは隠されます) @strong{MySQL} 3.23 以降では、 @code{IF NOT EXISTS} キーワードを使用できます。 これは、もしテーブルが既に存在していた場合、エラーを発生させません。 テーブルの構造が一意かどうかまでは検査しないことに注意。 それぞれのテーブルは、データベースディレクトリにおける以下の複数の ファイルで表されます。これは MyISAM 型 のテーブル場合: @multitable @columnfractions .2 .8 @item @strong{ファイル} @tab @strong{目的} @item @code{tbl_name.frm} @tab テーブル定義(書式)ファイル @item @code{tbl_name.MYD} @tab データファイル @item @code{tbl_name.MYI} @tab インデックスファイル @end multitable フィールドに対する種々の型属性の詳細は、@ref{Column types}を参照のこと。 @itemize @bullet @item @code{NULL}も@code{NOT NULL}も指定されなかった場合、フィールドは@code{NULL}が指定されたものとして扱われます。 @item 整数型のフィールドには付加属性@code{AUTO_INCREMENT}も指定することができます。@code{AUTO_INCREMENT}のフィールドに値@code{NULL}又は@code{0}を挿入した場合、フィールドには@code{value+1}の値がセットされます。@code{value}は、そのテーブル内の当該フィールドにおける現在の最大値です。 @code{AUTO_INCREMENT} は @code{1} からはじまります. @xref{mysql_insert_id, , @code{mysql_insert_id()}}. 削除したレコードが、@code{AUTO_INCREMENT}フィールドの最大値を含んでいた場合、その値は次に再利用されます(ただし、これは ISAM テーブルの場合で、MyISAM テーブルでは起こりません)。 また、テーブル内の全てのレコードを @code{DELETE FROM TABLE} (@code{WHERE}節無しで) を 使用して削除した場合は、始めから採番し直します。 @strong{注意:} 1つのテーブルには1つしか@code{AUTO_INCREMENT}フィールドを指定できません。また、インデックスを指定する必要があります。 @strong{MySQL} 3.23 は auto_increment フィールドが正の数を持っている場合に だけ、正しく動作します。負の数の挿入はとても大きな正の数の挿入とみなされま す。これは、数値が正から負への 'wrap' over する時の精度の問題を回避するた めと、アクシデント的に 0 を含む auto_increment フィールドを得ることがない ことを確実にするために、行なわれます。 @cindex ODBC compatibility @cindex Compatibility, with ODBC @strong{MySQL} をいくつかの ODBC アプリケーションと互換にするために、次の クエリで最後に挿入されたレコードを見つけることができます: @example SELECT * FROM tbl_name WHERE auto_col IS NULL @end example @item @code{TIMESTAMP}フィールドにおける@code{NULL}値は、他のフィールド属性と違った扱われ方をします。定数@code{NULL}を@code{TIMESTAMP}フィールドに格納することはできません。@code{NULL}値の指定は現在時刻をセットすることを意味します。@code{TIMESTAMP}フィールドがこのように振舞うので、通常は@code{NULL}属性や@code{NOT NULL}属性は適用できません。それらを指定しても無視されます。 一方、@strong{MySQL}クライアントからは、より安易に@code{TIMESTAMP}フィールドを利用でき、サーバも@code{TIMESTAMP}フィールドへの@code{NULL}の適用を報告しますが、@code{TIMESTAMP}フィールドは実際には@code{NULL}値を保存することはありません。@code{DESCRIBE tbl_name}を使用して、テーブル定義文を取得することにより、この現象を確認することができます。 @code{TIMESTAMP}フィールドに@code{0}を指定することは、@code{NULL}を指定することと等しくないことに注意してください。なぜなら、@code{0}は@code{TIMESTAMP}の値として不正であるからです。 @item フィールドに対して @code{DEFAULT} 値が指定されない場合は @strong{MySQL} が 自動的にそれを割り当てます。 フィールドが @code{NULL} を値として取り得る場合は、デフォルト値は @code{NULL} です。 フィールドが @code{NOT NULL} として宣言された場合は、デフォルト値はフィー ルド型に依存します: @itemize @minus @item @code{AUTO_INCREMENT} 定義された以外の数値型のフィールドに対しては、 初期値は@code{0}となります。 @code{AUTO_INCREMENT}フィールドでは、デフォルト値は次のシーケンス番号になります。 @item @code{TIMESTAMP} 型以外の日付型と時刻型のフィールドに対しては、 初期値はその型において適切な``ゼロ''値となります。 例外: フィールドがそのテーブル内で最初の@code{TIMESTAMP}フィールドである場合、初期値は現在時刻になります。 @xref{Date and time types}. @item @code{ENUM} 以外の文字列型のフィールドに対しては、初期値は空文字列となります。 @code{ENUM} では、デフォルト値は最初の列挙値です。 @end itemize @item @code{KEY}は、@code{INDEX}の同義語です。 @item @strong{MySQL}では、@code{UNIQUE}キーは固有値しか持つことができません。既に存在するレコードとキーの値が重複するレコードを挿入しようとした場合、エラーが発生します。 @item @code{PRIMARY KEY} はユニーク @code{KEY} で、すべてのキーフィールドは @code{NOT NULL} として定義されなければならないという特別な制限を伴います。 @strong{MySQL} ではキーは @code{PRIMARY} と名付けられます。テーブルは @code{PRIMARY KEY} を一つだけ持つことができます。@code{PRIMARY KEY} を持た ない場合に、アプリケーションがテーブル内の @code{PRIMARY KEY} を尋ねると、 @strong{MySQL} は @code{PRIMARY KEY} として、@code{NULL} フィールドを持た ない最初の @code{UNIQUE} キーを返します。 @item @code{PRIMARY KEY}は複数フィールドインデックスとできます。しかしながら、1つのフィールド定義内では@code{PRIMARY KEY}属性を用いて複合インデックスを定義することができませんので、フィールド定義内における指定は、プライマリ・キーが単独フィールドの場合のみとして下さい。複合フィールドの場合は、@code{PRIMARY KEY(index_col_name,...)}文を使用しなければなりません。 @item @code{PRIMARY} や @code{UNIQUE} キーが1つのフィールドだけからなり、その型が整数の 場合、それを @code{_rowid} としても参照することができます(3.23.11 での新機 能)。 @item インデックスに名前を割り当てない場合、一意な名前を付けるために、@code{index_col_name}内の最初のフィールド名に(@code{_2}, @code{_3}, ...)のようなサフィックスを付加したものが割り当てられます。テーブルが使用しているインデックス名は、@code{SHOW INDEX FROM tbl_name}により確認することができます。 @xref{SHOW, , @code{SHOW}}. @item @cindex @code{NULL} values, and indexes @cindex Indexes, and @code{NULL} values @code{MyISAM} テーブルのみが、@code{NULL} 値をもつフィールドに対して インデックスを持つことが出来ます。 その他のテーブル型の場合、フィールドを @code{NOT NULL} で定義しなくてはなりません。 @item @code{col_name(length)}文を共に指定することで、@code{CHAR}フィールド又は@code{VARCHAR}フィールドの一部分だけをインデックスとして定義できます。これによりインデックスファイルを適度に小さくすることができます。 @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 @code{MyISAM} テーブル型のみが、 @code{BLOB} と @code{TEXT} フィールド上に インデックスを持つことが出来ます。 @code{BLOB} と @code{TEXT} フィールドに インデックスを張る場合、常に、インデックスの長さを指定しなくてはなりません: @example CREATE TABLE test (blob_col BLOB, index(blob_col(10))); @end example @item @code{TEXT}フィールドや@code{BLOB}フィールドで @code{ORDER BY} や @code{GROUP BY} を 使用すると、最初の@code{max_sort_length}バイトだけが使用されます。 @xref{BLOB, , @code{BLOB}}. @item @code{FOREIGN KEY}、@code{CHECK}及び@code{REFERENCES}節は実際には何も行いません。これらの構文は、互換性のためだけに用意されており、他のSQLサーバからのコードの移植を容易にしたり、参照情報と共にテーブルを作成するようなアプリケーションを動作させることを目的としています。 @xref{Missing functions}. @item 全ての@code{NULL}フィールドは、1ビット余計に消費し、直近のバイトに丸められます。 @item レコードの最大長は、以下のようにして求められます: @example レコードの長さ = 1 + (フィールドの長さの合計) + (NULLフィールドの数 + 7)/8 + (可変長フィールドの数) @end example @item @code{table_options} と @code{SELECT} オプションは、 @strong{MySQL} 3.23 以上でのみ実装されます。 テーブル型は: @multitable @columnfractions .20 .80 @item ISAM @tab オリジナルのテーブル @xref{ISAM}. @item MyISAM @tab 新しい、バイナリ互換のテーブル @xref{MyISAM}. @item HEAP @tab このテーブルのデータは、メモリー内にのみ蓄えられる @xref{HEAP}. @item BDB または Berkeley_db @tab トランザクション安全なテーブル @xref{BDB}. @end multitable @xref{Table types}. その他のテーブルオプションを使って、テーブルの振る舞いを最適化します。 たいていの場合は、オプションを明示する必要がありません。 明示的に指定されなかった場合、オプションはすべてのテーブル型に作用します。 @multitable @columnfractions .20 .80 @item @code{AUTO_INCREMENT} @tab あなたがこのテーブルにセットしたい、次の auto_increment 値 @item @code{AVG_ROW_LENGTH} @tab テーブルに含まれるレコードの長さのおおよその平均値。 可変長のレコードを持つ場合にのみ、これをセットします。 @item @code{CHECKSUM} @tab @strong{MySQL} に全てのレコードをチェックさせたい場合、これを 1 にセットします。 (これは更新を遅くさせますが、不整合の生じたテーブルを見つけ出しやすくなります) (MyISAM) @item @code{COMMENT} @tab テーブルの、60文字コメント @item @code{MAX_ROWS} @tab あなたがテーブルに保存したいと考えている最大レコード数。 @item @code{MIN_ROWS} @tab あなたがテーブルに保存したいと考えている最低レコード数 @item @code{PACK_KEYS} @tab より小さいインデックスにしたいなら、これを 1 にします。 これは更新を遅くしますが、読み出しは速くなります (MyISAM, ISAM). @item @code{PASSWORD} @tab @code{.frm} ファイルをパスワード付きで暗号化。 このオプションは、標準の @strong{MySQL} バージョンではなにも行いません。 @item @code{DELAY_KEY_WRITE} @tab テーブルがクローズされるまでキーテーブルの更新を送らせたい場合、1に設定します(MyISAM)。 @item @code{ROW_FORMAT} @tab レコードがどのように格納されるかを定義します(将来のため)。 @end multitable @code{MyISAM} テーブルを使用するならば、@strong{MySQL} は @code{max_rows * avg_row_length} の値を、テーブルがどのくらい大きくなるか の推定に使用します。 もし、上記のオプションをなにも指定しなかった場合、テーブルの最大サイズは 4G になります。(か、あなたの OS が 2G しかサポートしていなければ 2G まで) @code{PACK_KEYS} を使用しない場合、デフォルトは文字列だけをパックし、数値 はパックしません。@code{PACK_KEYS=1} を使用するとさらに数値もパックされま す。 バイナリ数値キーをパックする時、@strong{MySQL} はプレフィックス圧縮を使用 します。これは、同じ数値を多く持つ場合にだけこの大きな恩恵を得るということ を意味します。プレフィックス圧縮は、前のキーの何バイトが次のキーと同じであ るかを示すための余計な1バイトがすべてのキーに必要となることを意味します(注 意: レコードへのポインタは、圧縮の向上のため high-byte-first-order でキー の直後に格納されます)。これは、2つのレコードが同じキー多く持つ場合、後のす べての'同じ'キーは通常2バイト(レコードへのポインタを含む)だけを必要とする ということです。これを、通常のケースと比較してみてください。通常のケースは、 後のキーは'キーの格納サイズ' + ポインタサイズ(通常4)を必要とします。一方、 すべてのキーが全く異なっていると、キーが @code{NULL} 値を持つことができる キーではない場合では、キー毎に1バイトを消費します(この場合、パックされたキー の長さは、キーが @code{NULL} の時にマークのために使用されるのと同じバイト 数で格納されます)。 @item もし @code{CREATE STATEMENT} の後に @code{SELECT} を指定するならば、 @strong{MySQL} は、@code{SELECT} で返ってくる全ての項目を収めるために、 新しいフィールドを作成します。 例えば: @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 これは 3つのフィールドを @code{HEAP} テーブルに作成します。 もしデータをテーブルにコピーしている最中にエラーが起きたなら、 このテーブルは自動的に消去されることに注意してください。 @item @code{RAID_TYPE} オプションは、大規模ファイルをサポートしていない OS 上の 2G/4Gの制限を破る手助けをします。また、@code{RAID} ディレクトリを別の物理 ディスクに置くことにより、IO ボトルネックからさらに速度を得ることができま す。@code{RAID_TYPE} は、@strong{MySQL} を @code{--with-raid} でコンフィグ すれば、どんな OS 上でも働きます。現在、@code{RAID_TYPE} は @code{STRIPED} だけが許されています(@code{1} と @code{RAID0} はこれの別名 です)。 @code{RAID_TYPE=STRIPED} を @code{MyISAM} テーブルに指定すると、 @code{MyISAM} はデータベースディレクトリ中に 00, 01, 02 という名前の @code{RAID_CHUNKS} サブディレクトリを生成します。これらのディレクトリのそ れぞれに、@code{MyISAM} は @code{table_name.MYD} を生成します。データファ イルにデータが書き込まれる時、@code{RAID} ハンドラは最初の @code{RAID_CHUNKSIZE} *1024 バイトを最初のファイルに、次の @code{RAID_CHUNKSIZE} *1024 バイトを次のファイルにマップします。 @end itemize @node Silent column changes, , CREATE TABLE, CREATE TABLE @subsection 暗黙のフィールド定義変更 いくつかのケースにおいて@strong{MySQL}は、@code{CREATE TABLE}ステートメントで与えられたフィールド定義を暗黙の内に変更します (これは @code{ALTER TABLE} で起きるかもしれません) @itemize @bullet @item フィールド長が4未満の@code{VARCHAR}フィールドは@code{CHAR}に変更されます。 @item テーブル内にいくつかの可変長フィールドがある場合、結果的にレコード全体が可変長となります。 その結果、テーブルがいくつかの可変長フィールド(@code{VARCHAR}、@code{TEXT}及び@code{BLOB}) を持つならば、3文字より大きいフィールド長の全ての@code{CHAR}フィールドは、 @code{VARCHAR}フィールドに変更されます。 このことは、フィールドの使用方法には影響しません。 @strong{MySQL}では、@code{VARCHAR}は文字列を格納するための1つの手段に過ぎません。 @strong{MySQL}は、スペース埋めのコンバージョンを行いますし、テーブル操作もより速く行います。 @xref{Table types}. @item @code{TIMESTAMP}フィールドの表示サイズは、2〜14の範囲の偶数でなければなりません。表示サイズを0や14より大きく指定した場合、サイズは14に強制されます。1から13の範囲の奇数の場合、大きい方の偶数値に強制されます。 @item @code{TIMESTAMP} フィールドには @code{NULL} を代入できません; @code{NULL} は 現在の日時をセットします。 @code{NULL} and @code{NOT NULL} 属性は通常の方法では適用されず、それらを 与えた場合は無視されます。 @code{DESCRIBE tbl_name} は常に @code{TIMESTAMP} フィールドに @code{NULL} 値が割り当て られた事を告げます。 @item @strong{MySQL} は他の SQL データベースの使用している型を @strong{MySQL} 型に マップします。 @xref{Other-vendor column types}. @end itemize もし @strong{MySQL} がフィールドの型をあなたが指定したものと違うものにしたかどうかを 知りたい場合、テーブルの作成、alter 後に、 @code{DESCRIBE tbl_name} 構文 を発行します。 @cindex @code{myisampack} @code{myisampack}を使用してテーブルを圧縮した場合、別のフィールド定義変更がある程度起こることがあります。 @xref{Compressed format}. @findex ALTER TABLE @node ALTER TABLE, DROP TABLE, CREATE TABLE, Reference @section @code{ALTER TABLE}構文 @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}は、既存のテーブルの構造変更を可能にします。 例えば、フィールドの追加や削除、インデックスの作成や破棄、既存のフィールド属性の変更、及びフィールドやテーブルそのものの名前の変更です。 また、テーブルのコメントやテーブルの型式を変更することも可能です。 @xref{CREATE TABLE, , @code{CREATE TABLE}}. もし @code{ALTER TABLE} でフィールド定義を変えても @code{DESCRIBE tbl_name} が フィールドを変更していないと示すなら、これは @strong{MySQL} が @ref{Silent column changes}. に述べている理由の一つで変更していない可能性が あります。 例えば、 @code{VARCHAR} フィールドを @code{CHAR} にしようとすると, @strong{MySQL} はそのテーブルに他の可変長のフィールドがあるかぎり、 @code{VARCHAR} のままにしようとします。 @code{ALTER TABLE}はオリジナルのテーブルの一時的なコピーを作成することにより動作します。 コピーへの変更作業が完了すると、オリジナルのテーブルは削除され新しく作られた方の名前が変更されます。これは全ての変更が自動的に新しいテーブルに対して実施されることにより、誤った変更無しに完了します。@code{ALTER TABLE}が実行されている間、オリジナルのテーブルは他のクライアントから読みだしが可能です。このテーブルへの更新や書き込みは、新しいテーブルが準備完了となるまで遅らされます。 @itemize @bullet @item @code{ALTER TABLE}を使うには、そのテーブルに@strong{select}、@strong{insert}、 @strong{delete}、@strong{update}、@strong{create}、それから@strong{drop} 権限が必要です。 @item @code{IGNORE}はANSI SQL92に対する@strong{MySQL}の拡張です。 これは、新しいテーブルのユニークキーで重複があった場合の動作を制御します。 @code{IGNORE}が指定されない場合、コピーは異常終了し、ロールバックされます。 @code{IGNORE}が指定された場合、ユニークキーの重複があったレコードに対し、最初のレコードだけを使用し、他は削除されます。 @item 1つの@code{ALTER TABLE}ステートメントの中で、@code{ADD}、@code{ALTER}、 @code{DROP}、それから@code{CHANGE}節の複合的な発行が可能です。 これは、@code{ALTER TABLE}ステートメント毎に1つだけしかこれらの節を 許さないANSI SQL92に対する@strong{MySQL}の拡張です。 @item @code{CHANGE col_name}、@code{DROP col_name}及び@code{DROP INDEX}はANSI SQL92に対する@strong{MySQL}の拡張です。 @item @code{MODIFY} は @code{Oracle} の @code{ALTER TABLE} 拡張です。 @item オプション語@code{COLUMN}は蛇足であり、記述を省くことが可能です。 @item 他のオプション無しで@code{ALTER TABLE tbl_name RENAME AS new_name}を使用すると、 @strong{MySQL}は@code{tbl_name}に一致するテーブルの名前を単純に変更します。 テンポラリテーブルの作成は必要としません。 @item @code{create_definition}は、@code{CREATE TABLE}における@code{ADD}や@code{CHANGE}と同じ構文を使用します。 @xref{CREATE TABLE, , @code{CREATE TABLE}}. @item @code{CHANGE old_col_name create_definition}節を使用することによりフィールドの名前を変更することができます。 このようなことを行うためには、フィールドの旧名称と新名称、それからそのフィールドの現在の型を指定する必要があります。例えば、ある@code{INTEGER}フィールドを@code{a}から@code{b}に変更する場合、以下のように実行することができます: @example mysql> ALTER TABLE t1 CHANGE a b INTEGER; @end example もしフィールドの名前を変えることなく、型だけを変更したい場合であっても、 この @code{CHANGE} 構文は、たとえ同じ名前であっても、 2つの名前を指定するよう要求します。 例: @example mysql> ALTER TABLE t1 CHANGE b b BIGINT NOT NULL; @end example しかし @strong{MySQL} 3.22.16a からは, @code{MODIFY} を使用して、 名称変更をすることなくフィールドの型を変更することができます。 @example mysql> ALTER TABLE t1 MODIFY b BIGINT NOT NULL; @end example @item @code{CHANGE} や @code{MODIFY} を使用して、フィールドの一部にインデックス が存在するようなフィールドを短くしようとしても(例えば @code{VARCHAR} フィー ルドの最初の10文字上ににインデックスがある場合)、インデックスされた文字数 よりもフィールドを短くすることはできません。 @item @code{CHANGE} や @code{MODIFY} を用いてフィールドの型を変更する場合、 @strong{MySQL}は可能な限り新しい型にデータをコンバートしようと試みます。 @item @strong{MySQL} 3.22以降では、@code{FIRST}又は@code{ADD ... AFTER col_name}を使用して、テーブルのレコード内の指定した位置に、フィールドを追加することができます。 デフォルトでは、フィールドは(そのレコードの)最後に追加されます。 @item @code{ALTER COLUMN}は、フィールドの新たな初期値を指定したり、フィールドの古い初期値を削除したりします。 古い初期値が削除され、フィールドが@code{NULL}を許す場合、新たな初期値は@code{NULL}となります。 @code{NULL}が許されない場合、@strong{MySQL}はある初期値を割り当てます。 割り当てる初期値は、 @ref{CREATE TABLE, , @code{CREATE TABLE}}. で説明されています。 @item @code{DROP INDEX}は、インデックスを削除します。これはANSI SQL92に対する@strong{MySQL}の拡張です。 @item フィールドがテーブルから削除されると、そのフィールドが含まれているインデックスからもそのフィールドが削除されます。 インデックスを構成する全てのフィールドが削除されると、そのインデックスも削除されます。 @item @code{DROP PRIMARY KEY}は、プライマリ・インデックスを削除します。もしプライマリインデックスが存在しなければ、そのテーブルの最初の@code{UNIQUE}インデックスが削除されます。 (@strong{MySQL}は、明示的に@code{PRIMARY KEY}が指定されなければ最初の@code{UNIQUE}キーを@code{PRIMARY KEY}として扱います。) @item @findex mysql_info() C API関数@code{mysql_info()}により、どれだけのレコードがコピーされたか、(@code{IGNORE}が指定されている時は)どれだけのレコードがユニークキーの重複により削除されたかを調べることができます。 @item @cindex Foreign keys @cindex References @code{FOREIGN KEY}、@code{CHECK}及び@code{REFERENCES}節は、実際には 何もしません。これらの構文は、互換性のためだけに用意されており、 他のSQLサーバからのコードの移植を容易にしたり、 参照情報と共にテーブルを作成するようなアプリケーションを動作 させることを目的としています。 @xref{Missing functions}. @end itemize 以下は、@code{ALTER TABLE}の使用例を表す例です。 次に示すように作成されたテーブル@code{t1}から始めます: @example mysql> CREATE TABLE t1 (a INTEGER,b CHAR(10)); @end example テーブル@code{t1}の名前を@code{t2}に変更するには: @example mysql> ALTER TABLE t1 RENAME t2; @end example フィールド @code{a}を @code{INTEGER} から @code{TINYINT NOT NULL} に (名前は同じままで)変更し、 @code{b} を @code{CHAR(10)} から @code{CHAR(20)} に変更しつつ、 名前を @code{b} から @code{c}に変更するには: @example mysql> ALTER TABLE t2 MODIFY a TINYINT NOT NULL, CHANGE b c CHAR(20); @end example @code{TIMESTAMP}を追加し、名前を@code{d}とするには: @example mysql> ALTER TABLE t2 ADD d TIMESTAMP; @end example フィールド@code{d}にインデックスを追加し、フィールド@code{a}をプライマリ・キーとするには: @example mysql> ALTER TABLE t2 ADD INDEX (d), ADD PRIMARY KEY (a); @end example フィールド@code{c}を削除するには: @example mysql> ALTER TABLE t2 DROP COLUMN c; @end example @code{c} という名前の @code{NULL} を許可しない @code{AUTO_INCREMENT} 整数 フィールドを追加し、作成するには: @example mysql> ALTER TABLE t2 ADD c INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD INDEX (c); @end example ここで我々が @code{c} をインデックス指定したのは、 @code{AUTO_INCREMENT} フィールドは インデックスであるべきだからで、 @code{c} を @code{NOT NULL} 指定しているのは インデックスフィールドは @code{NULL} にできないからです。 @code{AUTO_INCREMENT} フィールドを追加した場合、フィールドの値は 自動的にシーケンス番号で埋められます。 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}構文 @example DROP TABLE [IF EXISTS] tbl_name [, tbl_name,...] @end example @code{DROP TABLE}は、1つ又は1つ以上のテーブルを破棄します。テーブルの全てのデータとテーブル定義は@emph{破棄}されますので、このコマンドの使用は慎重に行ってください! @strong{MySQL} 3.22以降では、テーブルが存在しないことに起因するエラーを防ぐために、キーワード @code{IF EXISTS} を使用することができます。 @findex OPTIMIZE TABLE @node OPTIMIZE TABLE, CHECK TABLE, DROP TABLE, Reference @section @code{OPTIMIZE TABLE}構文 @example OPTIMIZE TABLE tbl_name @end example @code{OPTIMIZE TABLE}は、テーブルの大部分を削除したり、可変長となっているテーブル(@code{VARCHAR}、@code{BLOB}もしくは@code{TEXT}フィールドを持つテーブル)に多くの変更を加えた場合に使用すべきです。 削除されたレコードはリンクリストで維持され、次の@code{INSERT}操作は、古いレコード位置を再利用します。 未使用領域を再生するために@code{OPTIMIZE TABLE}を使用することができます。 @code{OPTIMIZE TABLE}は、オリジナルのテーブルの一時的なコピーを作成することにより動作します。 古いテーブルは新しいテーブルに(未使用レコードを除いて)コピーされ、 元のテーブルが削除されてから新しいテーブルの名前が変更されます。 @code{OPTIMIZE TABLE}が実行されている間、オリジナルのテーブルは他のクライアントから読みだしが可能です。 このテーブルへの更新や書き込みは、新しいテーブルが準備完了となるまで遅らされます。 これは全ての変更が自動的に新しいテーブルに対して実施されることにより、誤った変更無しに完了します。 @findex CHECK TABLE @node CHECK TABLE, REPAIR TABLE, OPTIMIZE TABLE, Reference @section @code{CHECK TABLE} 構文 @example CHECK TABLE tbl_name[,tbl_name...] [TYPE = QUICK] @end example テーブルのエラーをチェックします。このコマンドは次のフィールドを持つテーブ ルを返します: @multitable @columnfractions .35 .65 @item Table @tab テーブル名 @item Op @tab 常に 'check' @item Msg_type @tab @code{status}, @code{error}, @code{info}, @code{warning} の一つ。 @item Msg_text @tab メッセージ。 @end multitable 注意: チェックされた各テーブルに対する情報の多くのレコードが得られます。最 後の1レコードは @code{Msg_type status} になり、通常は @code{OK} であるべ きです。@code{OK} が得られない場合は、テーブルの修復を通常通り実行すべきで す。@xref{Table maintenance}。 @code{TYPE=QUICK} が与えられた場合は、@strong{MySQL} は固定長レコードテー ブルのレコードを走査しません。 @code{CHECK TABLE} は @code{MyISAM} テーブルだけで動作し、テーブルに対する @code{myisamchk -m table_name} の実行と同じことです。 @findex REPAIR TABLE @node REPAIR TABLE, DELETE, CHECK TABLE, Reference @section @code{REPAIR TABLE} 構文 @example REPAIR TABLE tbl_name[,tbl_name...] [TYPE = QUICK] @end example @code{REPAIR TABLE} は @code{MyISAM} テーブルだけで動作します。テーブルに @code{myisamchk -r table_name} を実行することと同じです。 壊れたテーブルを修復します。コマンドは次のフィールドを含むテーブルを返しま す: @multitable @columnfractions .35 .65 @item Table @tab テーブル名 @item Op @tab 常に 'repair' @item Msg_type @tab @code{status}, @code{error}, @code{info}, @code{warning} のどれか @item Msg_text @tab メッセージ @end multitable 注意: 修復された各テーブルの情報の多くのレコードを得ることがあります。最後 の1レコードは @code{Msg_type status} になり、通常は @code{OK} であるべき です。@code{OK} が得られなければ、@code{myisamchk -o} でテーブルの修復を試 みるべきです。@code{REPAIR TABLE} はまだ @code{myisamchk} のすべてのオプショ ンを実装していないためです。近い将来、我々はこれをより柔軟にする予定です。 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}構文 @example DELETE [LOW_PRIORITY] FROM tbl_name [WHERE where_definition] [LIMIT rows] @end example @code{DELETE}は、@code{tbl_name}より、@code{where_definition}にて与えられた条件を満たすレコードを削除し、削除されたレコード数を返します。 @code{WHERE}節を指定することなしに@code{DELETE}を発行した場合、全てのレコードが削除されます。 @strong{MySQL}は、これを空テーブルを再作成することで実現しており、これは、全てのレコードを実際に削除するよりもかなり早く動作します。 この場合@code{DELETE}は、影響のあったレコード数として0を返します。 (再作成は、元のデータが格納されているファイルをオープンすることなく実施されますから、@strong{MySQL}は実際に削除されたレコード数を返すことができません。 たとえデータファイルやインデックスファイルが乱されたとしても、テーブル定義ファイル@file{tbl_name.frm}が有効である限り、このような方法でテーブルの再作成が可能となります。) もし全てのレコードを削除している時に、いくつのレコードが消され、いくつのレコードが スピードを犠牲にしているのか、本当に知りたいならば、 @code{DELETE} 構文を以下のように使用します: @example mysql> DELETE FROM tbl_name WHERE 1>0; @end example これは @code{DELETE FROM tbl_name} を @code{WHERE} 節なしで行うよりも、 とても遅いです。なぜなら一度で消そうとするからです。 キーワード@code{LOW_PRIORITY}を指定した場合、そのテーブルを読んでいるクライアントがいなくなるまで@code{DELETE}の実行は遅らせられます。 削除されたレコードはリンクリストで維持され、次の@code{INSERT}操作は、古いレコード位置を再利用します。 ファイルをより小さくしたい場合は、@code{OPTIMIZE TABLE}ステートメントかテーブルの再編成のために@code{myisamchk}ユティリティを使用してください。 @code{OPTIMIZE TABLE}の方が簡単ですが、@code{myisamchk}の方が早く動作します。 @xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}, と @ref{Optimization}. @strong{MySQL}-特化 @code{DELETE} の @code{LIMIT rows} オプションは サーバーに消す最大のレコード数をつげます。これは @code{DELETE} コマンドが あまりに多くの時間を取らないために使用されます。 @code{LIMIT} 値よりも affected row の数が少なくなるまで、 単純に @code{DELETE} コマンドを繰り返すだけです。 @findex SELECT @node SELECT, JOIN, DELETE, Reference @section @code{SELECT}構文 @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}は通常、1つまたは1つ以上のテーブルからレコードを検索して抽出するのに使用されます。 @code{select_expression} は取り出したいフィールドを示します。 @code{SELECT}はまた、テーブルの参照なしに計算によって求められたレコードを取り出すために使用されます。例: @example mysql> SELECT 1 + 1; -> 2 @end example 全てのキーワードの使用は、上記に示すような順序で正確に与えられる必要があります。例えば、@code{HAVING}節は必ず@code{GROUP BY}節の後、@code{ORDER BY}節の前でなければなりません。 @itemize @bullet @item @cindex Aliases, on expressions @cindex Expression aliases @code{SELECT}の表現では、@code{AS}による別名の指定が可能です。別名は、フィールド名の表現として使われ、@code{ORDER BY}及び@code{HAVING}節とともに使用することができます。 例: @example mysql> select concat(last_name,', ',first_name) AS full_name from mytable ORDER BY full_name; @end example @item @code{FROM table_references}節は、(例えば、選択するレコードにより、1つ又はそれ以上の)結合するテーブルのリストを示します。 このリストはまた、@code{LEFT OUTER JOIN}参照を含むことがあります。 @xref{JOIN, , @code{JOIN}}. @item @code{col_name}、@code{tbl_name.col_name}、@code{db_name.tbl_name.col_name}のようにしてフィールドを表すことができます。 @code{SELECT}ステートメント内での列の参照が曖昧でなければ、@code{tbl_name}や@code{db_name.tbl_name}のようなプリフィックスを詳細に記述する必要はありません。 より明示的なフィールドの指定形式をを必要とする曖昧な参照の例は、@ref{Legal names}を参照のこと。 @item @cindex Aliases, for tables @cindex Table aliases テーブル参照は、@code{tbl_name AS alias_name}又は@code{tbl_name 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 @code{LIKE}の表現において、ワイルドカード・キャラクタである@samp{%}や@samp{_} は、これらの通常のワイルドカードとしての意味を抑制するために@samp{\}の後に置かれることにより、定数@samp{%}や@samp{_}の検索に使われます。 @item 出力用に選択されたフィールドは、@code{ORDER BY}節や@code{GROUP BY}節において、フィールド名、フィールドのエイリアス名、又はフィールド番号にて指し示すことができます。フィールド番号は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 逆順で並べたい場合には、 @code{ORDER BY} 節の中で、あなたが並べたいと思っている フィールドの名前の後ろに、 @code{DESC} (descending) キーワードを 追加します。 デフォルトは昇順です; これは @code{ASC} キーワードを指定したことになります。 @item @code{HAVING}節は、@code{select_expression}においてどのフィールドの名前やエイリアス名でも指し示すことができます。 これは最後に適用され、クライアントにアイテムが送られる直前に実行されるので、最適化されません。 @code{WHERE}節で書くべきものに@code{HAVING}を用いてはいけません。 例えば、次のように書いてはいけません: @example mysql> select col_name from tbl_name HAVING col_name > 0; @end example その代わりに、次のように書いてください: @example mysql> select col_name from tbl_name WHERE col_name > 0; @end example @strong{MySQL} 3.22.5以降では、次のようにクエリを記述することができます: @example mysql> select user,max(salary) from users group by user HAVING max(salary)>10; @end example @strong{MySQL}の古いバージョンでは、この代わりに次のように記述できます: @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}, @code{HIGH_PRIORITY} は ANSI SQL92 に対する @strong{MySQL} 拡張です。 @item @code{HIGH_PRIORITY} は、テーブルの更新よりも @code{SELECT} を優先させます。 これは一度で完了する、とても速いクエリにのみ適用すべきです。 もしリードロックされているテーブルがあったとし、 たとえ update 文がこのテーブルの解除を待っていたとしても、 @code{SELECT HIGH_PRIORITY} クエリは実行されます。 @item @code{SQL_BIG_RESULT} は @code{GROUP BY} や @code{DISTINCT} と共に使用する 事ができ、結果セットが多くのレコードを持つことをオプティマイザに知らせます。 この場合、必要なら @strong{MySQL} はディスクベースの一時テーブルを直接使用 します。@code{MySQL} はこの場合、@code{GROUP BY} 要素上のキーで一時テーブ ルを行なう代わりにソートを行なうことを選択します。 @item @code{SQL_SMALL_RESULT} (@strong{MySQL} 固有のオプション) は @code{GROUP BY} か @code{DISTINCT} と共に使用する事ができ、 結果セットが小さくなることをオプティマイザに知らせます。この場合、 @strong{MySQL} はソートする代わりに、速い一時テーブルを結果の保存のた めに使用します。 @strong{MySQL} 3.23 では、これは通常必要ではありません。 @item @code{STRAIGHT_JOIN}は、@code{FROM}節にて記述されたテーブルの順序に従って結合するよう、オプティマイザに強制します。オプティマイザが、テーブルを最適な順序で結合しない場合に、クエリのスピードアップのためにこれを使用することが可能です。 @xref{EXPLAIN, , @code{EXPLAIN}}. @item @code{LIMIT} 節は、 @code{SELECT} 構文で返されるレコード数を指定するのに 使用されます。 @code{LIMIT} は一つか二つの数字の引数を取ります。 引数が2つ与えられたならば、最初の引数は最初のレコードからのオフセットを示し、2つめの引数は返すレコードの最大数を示します。 初めのレコードのオフセットは0です(1ではありません)。 @example mysql> select * from table LIMIT 5,10; # 6〜15行目を返す @end example もし引数が一つなら、返すべきレコードの最大行数を指定したことになります。 @example mysql> select * from table LIMIT 5; # 最初の5行を取り出す @end example いいかえれば、@code{LIMIT n} は @code{LIMIT 0,n} と同じです。 @item @tindex /etc/passwd @code{SELECT}の書式、@code{SELECT ... INTO OUTFILE 'file_name'}は、選択されたレコードをファイルに書き込みます。 ファイルはサーバ機に作成され、既に存在するファイルであってはなりません(@file{/etc/passwd}のようなファイルの破壊を防止します)。 @code{SELECT ... INTO OUTFILE}は、@code{LOAD DATA INFILE}の逆です。@code{export_options}の構文は、@code{LOAD DATA INFILE}ステートメントの一部で使われる@code{FIELDS}節や@code{LINES}節と同じような構成です。 @xref{LOAD DATA, , @code{LOAD DATA}}. @code{INTO OUTFILE}を使うとき、エスケープ・キャラクタ、@code{ASCII 0} (nul)、そして全てのターミネータ・キャラクタは、デフォルトでエスケープされることに気をつけてください。 @xref{LOAD DATA, , @code{LOAD DATA}}. 結果として取り出されるテキストファイルでは、 以下に示す文字が @code{ESCAPED BY} 指定の文字によってエスケープされます: @itemize @bullet @item @code{ESCAPED BY} 文字自身 @item @code{FIELDS TERMINATED BY} の最初の文字 @item @code{LINES TERMINATED BY} の最初の文字 @end itemize さらに、 @code{ASCII 0} は、@code{ESCAPED BY} 0 (@code{ASCII 48}) にコンバートされます。 いかなる @code{FIELDS TERMINATED BY}, @code{ESCAPED BY}, @code{LINES TERMINATED BY} 指定されている文字も、エスケープしなければならない理由は、 テキストファイルを読み返せれるようにするためなのです。 @code{ASCII 0} はいくつかのページャーでも見れるようにするために エスケープされるのです。 結果のファイルは SQL の文を含んでいないので、何もエスケープする必要はありません。 @end itemize @findex DUMPFILE @code{INTO OUTFILE} の代わりに @code{INTO DUMPFILE} を使用すると、 @strong{MySQL} はファイルに1レコードだけを書きます。フィールドや行の終端 とすべてのエスケープを含みません。これはファイル内に BLOB を格納したい場合 に便利です。 @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} 構文 @strong{MySQL}は、以下に示す@code{SELECT}ステートメントにおける@code{JOIN}構文をサポートします: @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 上に示す最後の@code{LEFT OUTER JOIN}構文は、ODBCとの互換性のためだけに存在します。 @itemize @bullet @item table referenceは、@code{tbl_name AS alias_name}や@code{tblname 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}と@code{,} (コンマ)は、同義語です。どちらも使用されるテーブル間の直積をとります。通常は@code{WHERE}条件にて、テーブルがどのようにリンクされるべきかを定義します。 @item @code{ON}条件節は、@code{WHERE}節で使用されるような条件文の書式です。 @item もし、@code{LEFT JOIN} の @code{ON} や @code{USING} において 右側のテーブルにマッチするレコードが無かった場合、 全てのフィールドが@code{NULL}である1つのレコードが、右側のテーブルとして使用されます。 この事実は、あるテーブルについて、他のテーブルに対応するレコードが存在しないレコードを探すということに利用できます: @example mysql> select table1.* from table1 LEFT JOIN table2 ON table1.id=table2.id where table2.id is NULL; @end example この例は、@code{table1}の内、@code{id}の値が@code{table2}に存在しない全てのレコードを検索します。(即ち、@code{table2}内のレコードと一致しない@code{table1}の全てのレコード。) もちろん、この場合の@code{table2.id}は、@code{NOT NULL}と定義されているものと仮定します。 @item @code{USING} @code{(column_list)}節のフィールド名リストは、両方のテーブルに存在しなければなりません。@code{USING}節が次のように: @example A LEFT JOIN B USING (C1,C2,C3,...) @end example 定義されることは、@code{ON}式がこのように定義されるのと同義です: @example A.C1=B.C1 AND A.C2=B.C2 AND A.C3=B.C3,... @end example @item 同じフィールド名を持つ2つのテーブルの @code{NATURAL [LEFT] JOIN} は、 @code{USING} 節を伴った @code{INNER JOIN} や @code{LEFT JOIN} と 同じとして定義されます。 @item @code{STRAIGHT_JOIN}は、右側のテーブルの前に、常に左側のテーブルを読むことを除けば、@code{JOIN}と全く同じことです。これは、結合オプティマイザが、不当な順序でテーブルを出力するようなまれな事態に使用できます。 @item @strong{MySQL} 3.23.12 から、テーブルから情報を取り出す時に、 @strong{MySQL} がどのインデックスを使用すべきかというヒントを与えることが できるようになりました。これは、@strong{MySQL} が間違ったインデックスを使 用していることを @code{EXPLAIN} が示す場合に有用です。@code{USE INDEX (key_list)} を指定することによって、テーブルからレコードを見つけるために、 指定されたインデックスの一つだけを使用するように @strong{MySQL} に伝えるこ とができます。別の構文 @code{IGNORE INDEX (key_list)} は、@strong{MySQL} に特定のインデックスを使用しないように伝えるために使用できます。 @end itemize 例: @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}構文 @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}は、既存のテーブルに新しいレコードを挿入します。 @code{INSERT ... VALUES}書式は、値の明示指定を基本としてレコードを挿入します。 @code{INSERT ... SELECT}書式は、他の表(複数可)から抽出したレコードを挿入します。 複数の値リストを用いる@code{INSERT ... VALUES}書式は、@strong{MySQL} 3.22.5以降でサポートされています。 @code{col_name=expression}構文は、@strong{MySQL} 3.22.10以降でサポートされています。 @code{tbl_name}は、レコードを挿入するテーブルです。フィールド名リストは、後続の値定義ステートメントのフィールドを指し示します。 @itemize @bullet @item もしいかなるフィールドも @code{INSERT ... VALUES} や @code{INSERT ... SELECT} などで 明示しなければ、全てのフィールドの値が @code{VALUES()} の中に与えられなくてはなりません。 テーブル内のフィールド順が不明な場合、これを調べるために@code{DESCRIBE tbl_name}を使用して下さい。 @item テーブル内の一部のフィールドしか指定しない場合、指定されなかったフィールドには、それぞれの初期値が指定されます。初期値の割当ては、@ref{CREATE TABLE, , @code{CREATE TABLE}}. で述べられています。 @item @code{NULL}を@code{TIMESTAMP}フィールドに挿入した場合、フィールドには現在時刻がセットされます。他の値を挿入した場合、指定された値が単純にセットされます。 @item @code{expression}は、値リスト内で先頭に近い方のフィールドを参照しなければなりません。 例えば、次のように記述できます: @example mysql> INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2); @end example しかし、次のようには記述できません: @example mysql> INSERT INTO tbl_name (col1,col2) VALUES(col2*2,15); @end example @item キーワード@code{LOW_PRIORITY}を指定した場合、@code{INSERT}の実行はそのテー ブルから値を読み込むクライアントがいなくなるまで遅らされます。この場合、ク ライアントは insert 文が完了するまで待たされます。テーブルが頻繁に使用され る場合、長い時間かかります。これはクライアントを一度に継続させる @code{INSERT DELAYED} と対称的です。 @item もし @code{IGNORE} キーワードを @code{INSERT} に 値とともに 与えるなら、 テーブル内の @code{PRIMARY} や @code{UNIQUE} キーにすでに存在する重複した ものは無視され、挿入されません。 多重行の値を含むレコードの @code{INSERT} にキーワード @code{IGNORE} を指定しない場合、 テーブルの @code{PRIMARY} キーや @code{UNIQUE} キーに重複が起こる際に、 挿入処理が異常終了します。 @code{IGNORE} を指定した場合、重複するキー値を持つレコードは挿入されません。 C API 関数 @code{mysql_info()} により、テーブルにいくつのレコードが挿入されたか チェックすることができます。 @item @strong{MySQL}が、@code{DONT_USE_DEFAULT_FIELDS}オプションにより制限されていた場合、@code{NULL}値を許さない全てのフィールドに明示的に値をしないと@code{INSERT}ステートメントは、エラーを生成します。 @xref{configure options, , @code{configure} options}. @item 以下の条件は、@code{INSERT INTO ... SELECT}ステートメントのために用意されています: @itemize @minus @item クエリーは、@code{ORDER BY}節を含むことができません。 @item @code{INSERT}ステートメントのターゲットとなるテーブルは、クエリー内@code{SELECT}部の@code{FROM}節に指定できません。なぜなら、挿入先のテーブルからの@code{SELECT}はANSI SQLで禁じられているからです。(問題は、@code{SELECT}が実行中に挿入したレコードを抽出することが可能であることです。副問い合わせ節を使用するときに、このような状況で混乱しやすくなります!) @item @code{AUTO_INCREMENT}フィールドは、通常通り動作します。 @end itemize @end itemize @findex mysql_info() 多重の値リストを持つ @code{INSERT ... SELECT ...} 又は @code{INSERT ... VALUES()} ステートメントを使用する場合、クエリーに関する情報を得るために C API関数 @code{mysql_info()} を使用することができます。 その情報の書式は以下に示す文字列のようになります: @example Records: 100 Duplicates: 0 Warnings: 0 @end example @code{Duplicates}は、既に存在するユニークインデックスの値と重複することにより、挿入できなかったレコード数を表します。 @code{Warnings}は、挿入されたフィールドが何らかの疑わしい値であったという数を表します。警告は、次のような条件の下で発生します: @itemize @bullet @item @code{NOT NULL}定義されたフィールドへの@code{NULL}の挿入。フィールドには初期値が設定されます。 @item 数値フィールドの範囲を超える値のセット。値は範囲内の限界値に補正されます。 @item 数値フィールドへの @code{`10.34 a'} のような値のセット。引きずっているゴミは取り除かれ、残りの数値部分が挿入されます。値が数値として判断できなかった場合、フィールドには @code{0} がセットされます。 @item @code{CHAR}、@code{VARCHAR}、@code{VARCHAR}、@code{TEXT}又は@code{BLOB}フィールドへの最大長を超える文字列の挿入。値はフィールドの最大長に切り捨てられます。 @item 日付又は時刻フィールドへのフィールド属性に反した挿入。その属性に適した``ゼロ''値がセットされます。 @end itemize @findex INSERT DELAYED @findex DELAYED @code{INSERT} 構文の @code{DELAYED} オプションは @strong{MySQL} 独自の オプションで、これは @code{INSERT} が完全に終了することを待てない クライアントを持つ場合に、とても役立ちます。 これは、ロギングのために @strong{MySQL} を使用する時の一般的な問題で、完了 に長い時間がかかる @code{SELECT} ステートメントも定期的に実行できます。 @code{DELAYED} は @strong{MySQL} 3.22.15 で導入されました。 これは ANSI SQL92 に対する @strong{MySQL} 拡張です。 @code{INSERT DELAYED} を使用する時、クライアントは一度 ok となり、テーブル が他のスレッドで使用中でない時にレコードが挿入されます。 @code{INSERT DELAYED} を使用して得られるほかの利益は、 多くのクライアントからの insert が同時に束ねられ、一つのブロックで 書かれることです。 これは多くの別々の insert を実行するより とても速くなります。 現在、キューイングされたレコードは、それらがテーブルに代入されるまで メモリーに保持されているだけです。 これは、もし @code{mysqld} を 強引な方法 (@code{kill -9}) でキルしたり、 @code{mysqld} が予期せず 死んだ場合、キューイングされているレコードはディスクに書かれず失われます! @code{DELAYED} オプションを @code{INSERT} や @code{REPLACE} で使用する場合、 以下のことがおきます。 ここで ``スレッド'' とは @code{INSERT DELAYED} コマンドを受けたスレッドをさし、 ``ハンドラー'' とは特定のテーブルのための全ての @code{INSERT DELAYED} 構文を操作するスレッドを指します。 @itemize @bullet @item スレッドがあるテーブルに対し @code{DELAYED} 構文を実行するとき、 そのテーブルに対する全ての @code{DELAYED} 構文 を処理するためにハンドラースレッドが作成されます。 もしそのようなハンドラーが存在していない場合には。 @item そのスレッドは、そのハンドラーが @code{DELAYED} ロックを既に持っているか どうかをチェックします; もし持っていないなら、そうするように ハンドラーに告げます。 たとえ他のスレッドが @code{READ} か @code{WRITE} ロックをそのテーブルに 持っていたとしても、 @code{DELAYED} ロックを得ることができます。 しかし、そのハンドラーは全ての @code{ALTER TABLE} ロックか @code{FLUSH TABLES} を待ちます。 そのテーブル構造が最新であるのを 確実にするために。 @item スレッドは @code{INSERT} ステートメントを実行しますが、レコードをテーブル に書く代わりに、ハンドラスレッドによって管理されるキューに最後のレコードの コピーを置きます。文法エラーはスレッドによって通知され、クライアントプログ ラムに報告されます。 @item クライアントは結果行の重複数や @code{AUTO_INCREMENT} の値を 報告できません; それはサーバーから得ることができません。 なぜなら、 @code{INSERT} はインサートオペレーションが完全に終了する前に 返るからです。 もし C API を使用しているなら、 @code{mysql_info()} 関数は 同様の理由によりなにも返しません。 @item 更新ログは、レコードがそのテーブルに insert されたとき、そのハンドラースレッド によって更新されます。 複数レコードの挿入の場合、 更新ログは最初の行が 挿入されたときに更新されます。 @item それぞれの @code{delayed_insert_limit} レコードが書かれた後、そのハンドラーは いかなる @code{SELECT} 文もまだ延期されていないかを確認します。 もしそうなら、続ける前にこれらに対して実行を可能にします。 @item ハンドラーのキュー内にレコードがなくなったとき、テーブルはアンロックされます。 もし新しい @code{INSERT DELAYED} コマンドが @code{delayed_insert_timeout} 秒以内に 受け付けられなければ、ハンドラーは終了します。 @item もし、特定のハンドラーのキュー内に @code{delayed_queue_size} 以上のレコードが 既に延期されているならば、そのスレッドは、キューに余裕がある間待ちます。 これは @code{mysqld} サーバーが delayed されたキューに全ての メモリーを確実に使用しないようにするのに役立ちます。 @item そのハンドラースレッドは @strong{MySQL} プロセスリストの @code{Command} 項 内に、 @code{delayed_insert} と共に表示されます。 これは @code{FLUSH TABLES} コマンドか @code{KILL thread_id} を実行することで、 kill できるでしょう。 しかし、これらは、終了する前に、キュー内の全てのレコードをテーブルに 保存しようとします。 この間、このスレッドは、他のスレッドから来たいかなる 新しい @code{INSERT} コマンドも受け付けません。 もし、この後に @code{INSERT DELAYED} コマンドを実行するなら、 新しいハンドラースレッドが作成されます。 @item 上記のことは、もし @code{INSERT DELAYED} コマンドが既に走っているなら、 @code{INSERT DELAYED} コマンドは、普通の @code{INSERT} コマンドよりも高い 優先度を持つということです! 他の update コマンドは @code{INSERT DELAY} キューが空になるまで、 あるいは誰かが @code{KILL thread_id} や @code{FLUSH TABLES} を実行して ハンドラーをキルするまで、 待たされます。 @item 以下のステータス変数は @code{INSERT DELAYED} コマンドについての情報を 与えます: @multitable @columnfractions .35 .65 @item @code{Delayed_insert_threads} @tab ハンドラースレッドの数 @item @code{Delayed_writes} @tab @code{INSERT DELAYED} で書かれるレコード数 @item @code{Not_flushed_delayed_rows} @tab 書き込みを待つレコード数 @end multitable これらの変数は @code{SHOW STATUS} 構文を発行したり @code{mysqladmin extended-status} コマンドを実行することで見れます. @end itemize 注意: @code{INSERT DELAYED} は、テーブルが使用中でない場合、通常の INSERT よりも遅くなります。@code{INSERT DELAYED} を使用する各テーブルにつ いて別のスレッドを操作するサーバの、追加のオーバーヘッドもあります。これは、 確実にそれを必要とする時にだけ @code{INSERT DELAYED} を使用すべきことを意 味します! @findex REPLACE @node REPLACE, LOAD DATA, INSERT, Reference @section @code{REPLACE}構文 @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}は、テーブル中の古いレコードがユニークインデックス上の 新しいレコードと同じ値を持つ場合に、新しいレコードを挿入する前に、 古いレコードを削除するということを除けば、@code{INSERT}と全く同じように 動作します。 @xref{INSERT, , @code{INSERT}}. @findex LOAD DATA INFILE @node LOAD DATA, UPDATE, REPLACE, Reference @section @code{LOAD DATA INFILE}構文 @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 @code{LOAD DATA INFILE}ステートメントは、テキストファイルからテーブルへと、 レコードを高速に読み込みます。 @code{LOCAL} キーワードが指定されれば、ファイルは クライアント・ホストから読み込まれます。 @code{LOCAL}が指定されなければ、ファイルはサーバに位置する必要があります (@code{LOCAL}は、@strong{MySQL} 3.22.6以降で利用できます)。 セキュリティ上の理由から、サーバからテキストファイルを読み出す時は、 ファイルがデータベースディレクトリに存在するか、 全てに読み込み権限がある必要があります。 また、サーバファイルで @code{LOAD DATA INFILE} を使用するには、 データベースの @strong{file} 権限も持たなければなりません。 @xref{Privileges provided}. もし @code{LOW_PRIORITY} を指定した場合、@code{LOAD DATA} 構文は そのテーブルから他のクライアントが読み込みを行っている間、 遅らされます。 @code{LOCAL} 使用をすると、クライアント・ホストからサーバ・ホストへ ファイルの内容が転送される分、多少遅くなるでしょう。 いうならば、ローカルのファイルを読み込むのに、 @strong{file} 権限は必要ないということです。 @cindex @code{mysqlimport} @code{mysqlimport}ユティリティは、データファイルの読み込みに使用することができます。; これは、サーバに@code{LOAD DATA INFILE}コマンドを送信することによって処理を実現しています。 @code{--local}オプションは、@code{mysqlimport}に、クライアント・ホストからデータファイルを読み込ませます。 クライアントとサーバが圧縮プロトコルをサポートしていれば、低速なネットワークでより良いパフォーマンスを得るために、@code{--compress}オプションを指定することができます。 サーバ・ホストにファイルを置く場合、サーバは、以下のルールを使用します: @itemize @bullet @item 完全なパスでファイル名が与えられた場合、サーバはパス名をそのまま使用します。 @item 1つ又は複数の構成要素から成る相対パスと共にファイル名が与えられた場合、サーバは、サーバのデータディレクトリ以下からファイルを探します。 @item ファイル名だけが単に与えられた場合、サーバは、 カレントのデータベースディレクトリを探します。 @end itemize これらのルールは、ファイルが @file{myfile.txt} のように与えられれば データベースディレクトリからファイルが読み出され、 @file{./myfile.txt} のように与えられれば、現在選択しているデータベースのデータディレクトリから ファイルが読み出されるという意味であることに注意して下さい。 例えば、以下の @code{LOAD DATA} 文は、@file{data.txt} ファイルを @code{db1} データベースディレクトリから読みます。 なぜなら、@code{db1} は 現在選択されているデータベースだからです。 たとえ、@code{db2} データベース のテーブルに、ファイルから読み込んだデータを挿入するとしても。: 以下に示すような構文では、ファイルは @code{db1} データベースディレクトリ から読まれます。@code{db2} ではありません: @example mysql> USE db1; mysql> LOAD DATA INFILE "data.txt" INTO TABLE db2.my_table; @end example @code{REPLACE} と @code{IGNORE} キーワードは、すでに存在するユニークキーに 重複しているレコードの入力に対する制御です。 @code{REPLACE} 指定の場合、同じユニークキーを持つ既存のレコードは新しいレコードで 置き換えられます。 @code{IGNORE} 指定の場合、既存のレコードのユニークキーと重複するキーをもつ新しいレコードは 飛ばされます。 もし、どちらも指定しなかった場合、重複したキーが見つかった場合 エラーが発生し、テキストファイルは無視されます。 @code{LOCAL} キーワードを使用してデータをローカルからロードする場合、 サーバーは操作の途中で転送をとめる方法を知りません。 それでデフォルトの動作としては @code{IGNORE} が指定されたのと 同じになります。 @code{LOAD DATA INFILE}は、@code{SELECT ... INTO OUTFILE}の逆です。 @xref{SELECT, , @code{SELECT}}. データベースからファイルへデータを書き込むには、@code{SELECT ... INTO OUTFILE}を使用します。 ファイルからデータベースに読み戻すには、@code{LOAD DATA INFILE}を使用します。 @code{FIELDS}と@code{LINES}節の構文は両方のコマンドとも同じです。 どちらの節もオプションですが、両方を指定する場合は、@code{FIELDS}は、@code{LINES}より先に指定しなければなりません。 @code{FIELDS}節を指定した場合、その段落(@code{TERMINATED BY}、@code{[OPTIONALLY] ENCLOSED BY}及び@code{ESCAPED BY})は、少なくとも1つを指定しなければならないことを除いて、それらもまたオプションとなります。 @code{FIELDS}節を指定しなかった場合、初期値は以下のように記述したのと等価となります: @example FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' @end example @code{LINES}節を指定しなかった場合、初期値は以下のように記述したのと等価となります: @example LINES TERMINATED BY '\n' @end example 言い換えると、@code{LOAD DATA INFILE} の初期値は、出力へ書き込む際に以下のように振舞います: @itemize @bullet @item 改行をレコードの境界とみなす @item タブ文字によってフィールドを区切る @item クォート文字でフィールドを囲んでいないものとする @item タブ文字や改行文字及び@samp{\}の前に@samp{\}があることにより、それらをフィールド値の一部のリテラル文字であるとして処理する。 @end itemize 逆に、@code{LOAD DATA INFILE}の初期値は、入力を読み込む際に以下のように振舞います: @itemize @bullet @item フィールド間にタブ文字を書く @item いずれのクォート文字でもフィールドを囲まない @item @samp{\}の使用により、フィールド値の中で使用するタブ文字や改行文字、@samp{\}をエスケープする @item レコードの終りに改行文字を書く @end itemize @code{FIELDS ESCAPED BY '\\'}と書いた場合、単一のバックスラッシュとして読み出される値とするために、2つのバックスラッシュを指定しなければならないことに注意して下さい。 @code{IGNORE number LINES} オプションはファイルの先頭にあるレコードを無視するのに 使用されます: @example mysql> LOAD DATA INFILE "/tmp/file_name" into table test IGNORE 1 LINES; @end example データベースからファイルへデータを書き、それから後でそのファイルからデータベースへデータを読み戻すために、@code{SELECT ... INTO OUTFILE}と対に@code{LOAD DATA INFILE}を使う場合、双方のフィールドとレコードの取扱いに関するオプションは、一致しなければなりません。さもなければ、@code{LOAD DATA INFILE}は適切にファイルを処理しないでしょう。 フィールドをコンマで区切ってファイルへ書き出すために、@code{SELECT ... INTO OUTFILE}を使用するとすれば: @example mysql> SELECT * FROM table1 INTO OUTFILE 'data.txt' FIELDS TERMINATED BY ',' FROM ... @end example コンマ区切りファイルから読み戻すため、正しいステートメントはこうなるでしょう: @example mysql> LOAD DATA INFILE 'data.txt' INTO TABLE table2 FIELDS TERMINATED BY ','; @end example その代わりとして次に示すようなステートメントでファイルを読み込もうとしても、正しく動作しないでしょう。なぜなら、これは、@code{LOAD DATA INFILE}に対してフィールドの間にタブを探すよう指示するからです: @example mysql> LOAD DATA INFILE 'data.txt' INTO TABLE table2 FIELDS TERMINATED BY '\t'; @end example おそらく、それぞれの入力行は単一のフィールドとして処理されるでしょう。 @code{LOAD DATA INFILE}は外部ソースからもファイルを読み出すことができます。 例えば、dBASEフォーマットのファイルは、フィールドをコンマで区切られ、ダブルクォーテーションで囲まれています。 レコードが改行文字で区切られているとしたら、次に示すフィールド及びレコードの取扱オプションを指定したコマンドが、このようなファイルを読み込むのに使用できます。 @example mysql> LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; @end example いくつかのフィールド及びレコードの取扱オプションに、空文字列(@code{''})を指定することがあります。空でないなら、@code{FIELDS [OPTIONALLY] ENCLOSED BY}と@code{FIELDS ESCAPED BY}の値は単一の文字でなければなりません。@code{FIELDS TERMINATED BY}と@code{LINES TERMINATED BY}は2つ以上の文字となるでしょう。例えば、リターン文字と改行文字のペアで区切られたレコードを書き込んだり、このようなレコードを含んだファイルを読み込んだりするには、@code{LINES TERMINATED BY '\r\n'}節を指定します。 @code{FIELDS [OPTIONALLY] ENCLOSED BY}は、フィールドの引用符を制御します。出力の際(@code{SELECT ... INTO OUTFILE})、@code{OPTIONALLY}語を省いたなら、全てのフィールドは@code{ENCLOSED BY}文字で囲まれます。このような出力(フィールド区切りにコンマを使用)の例を次に示します: @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 @code{OPTIONALLY}を指定すれば、@code{ENCLOSED BY}文字は、 @code{CHAR}フィールドと@code{VARCHAR}フィールドのみ囲むのに使用されます: @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 フィールド値の中における@code{ENCLOSED BY}文字の出現は、@code{ESCAPED BY}文字をその前に置くことによりエスケープされることに注意して下さい。@code{ESCAPED BY}値に空を指定すると、@code{LOAD DATA INFILE}により正しく読み込めない出力を生成するでしょう。例えば、このようにエスケープ文字を空にした場合、以下に示すような出力となります。4行目の2つ目のフィールドに、(誤って)フィールドを区切るかのようなクォートに続くコンマを含んでいることに注視して下さい: @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 入力において、@code{ENCLOSED BY}文字が指定されており、それがフィールド値の両端に現れた場合、その文字は取り去られます。(これは、@code{OPTIONALLY}が指定されたかどうかに拘らず、当てはまります;@code{OPTIONALLY}は入力解析には効果がありません。) @code{ESCAPED BY}文字を前置きされた@code{ENCLOSED BY}文字の出現は、現在のフィールド値の一部として処理されます。具体的には、あるフィールドがそれ自身、た@code{ENCLOSED BY}文字で始まっている場合、フィールドらの内部で発生する2重の@code{ENCLOSED BY}文字は、単一の@code{ENCLOSED BY}文字として処理されます。 例えば、@code{ENCLOSED BY '"'}が指定されると、引用符は以下のように操作されます: @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}は、特殊文字をどのように書き込んだり読み込んだりするかを制御します。 @code{FIELDS ESCAPED BY}文字が空でない場合、出力において次のような文字(文字列)のプリフィックスに使用されます: @itemize @bullet @item @code{FIELDS ESCAPED BY}文字 @item @code{FIELDS [OPTIONALLY] ENCLOSED BY}文字 @item @code{FIELDS TERMINATED BY}値と@code{LINES TERMINATED BY}値の最初の文字 @item ASCII 0 (エスケープ文字の後に続いて実際に書かれる文字はASCII @code{'0'}で、'ゼロ値'バイトではありません) @end itemize @code{FIELDS ESCAPED BY}文字が空であれば、どの文字もエスケープされません。 特に、フィールド値が上に示した文字を含んでいるならば、エスケープ文字に空を指定するのはあまり良い考えとは言えないでしょう。 入力において、@code{FIELDS ESCAPED BY}文字が空でない場合、この文字の出現は取り去られ、後続の文字はフィールド値の一部としてそのまま受け取られます。 例外は、エスケープされた@samp{0}や@samp{N}です(例えば、エスケープ文字が@samp{\}である時の@code{\0}や@code{\N})。 これらのシーケンスは、ASCII 0('ゼロ値'バイト) 、@code{NULL}として処理されます。@code{NULL}操作の規則は下を参照して下さい。 @samp{\}-escape syntaxに関するこれ以外の情報は、@ref{Literals}参照。 フィールドとレコード操作オプションが確実に相互作用する事例: @itemize @bullet @item @code{LINES TERMINATED BY}が空文字列で@code{FIELDS TERMINATED BY}が空でない場合、各レコードもまた@code{FIELDS TERMINATED BY}で終らせられます。 @item @code{FIELDS TERMINATED BY}と@code{FIELDS ENCLOSED BY}値が両方とも空(@code{''})の時、(区切られない)固定長行フォーマットが使用されます。 固定長行フォーマットでは、フィールド間に区切り文字列が使用されません。 その代わり、フィールド値は、フィールドの``表示''幅を使って書き込まれたり、読み込まれます。 例えば、あるフィールドが@code{INT(7)}で定義されている場合、フィールドの値は7文字の桁を使って書き込まれます。 入力においてフィールドは、7文字の読み込みにより得られます。 固定長行フォーマットはまた、@code{NULL}値の操作に好んで用いられます;下を参照のこと。 注意: マルチバイト文字セットを使用している場合は固定長フォーマットは働きま せん。 @end itemize @code{FIELDS}と@code{LINES}オプションによる@code{NULL}値の多様な取扱い: @itemize @bullet @item @code{FIELDS}と@code{LINES}の初期値のために、出力時に@code{NULL}は@code{\N}として書き込まれ、入力時に@code{\N}は@code{NULL}として読み込まれます(当然のことながら、@code{ESCAPED BY}文字は@samp{\}とします)。 @item @code{FIELDS ENCLOSED BY}が空で無い時、定数@code{NULL}のフィールド値は@code{NULL}値として読み込まれます(これは、文字列@code{'NULL'}として読み込まれる@code{FIELDS ENCLOSED BY}文字列で囲まれた@code{NULL}とは異なります)。 @item @code{FIELDS ESCAPED BY}が空の時、@code{NULL}は@code{NULL}として書き込まれます。 @item 固定長行フォーマット(@code{FIELDS TERMINATED BY}と@code{FIELDS ENCLOSED BY}がいずれも空の場合に起こります)において、@code{NULL}は、空白文字列として書き込まれます。 これは、ファイル内では、@code{NULL}値と空白値の見分けがつかないということを示していることに注意して下さい。ファイルからデータを読み戻す時に両者を区別しなければならない場合、固定長行フォーマットは使用すべきではありません。 @end itemize キーワード@code{REPLACE}と@code{IGNORE}は、ユニーク・キー値が重複するレコードが存在する入力レコードの取扱いを制御します。 @code{REPLACE}を指定した場合、同じユニーク・キー値を持つ新しいレコードは、既に存在する同じユニーク・キーであるレコードを置き換えます。 @code{IGNORE}を指定した場合、既に存在するレコードのユニーク・キー値と重複する入力レコードは、スキップされます。 いずれのオプションも指定していない場合、重複キーが発見された時点でエラーが発生し、テキストファイルの残りは無視されます。 @code{LOAD DATA INFILE}でサポートされないケース: @itemize @bullet @item 固定長行(@code{FIELDS TERMINATED BY}と@code{FIELDS ENCLOSED BY}の両方が空)と@code{BLOB}フィールド。 @item あるセパレータを他と同じかもしくは他のプリフィックスとした場合、@code{LOAD DATA INFILE}は、正しい入力処理ができないでしょう。 例えば、以下の@code{FIELDS}節は問題の原因となります: @example FIELDS TERMINATED BY '"' ENCLOSED BY '"' @end example @item @code{FIELDS ESCAPED BY}が空で、フィールド値に、@code{FIELDS ENCLOSED BY}値や@code{LINES TERMINATED BY}値の後に@code{FIELDS TERMINATED BY}値がくるようなものを含む場合、フィールドや行の読み込みが早めに打ち切られてしまいます。 これは、@code{LOAD DATA INFILE}が、フィールドやレコードの終了位置を正しく決められないことにより発生します。 @end itemize 次の例は、@code{persondata}テーブルの全てのフィールドを読み込みます: @example mysql> LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata; @end example フィールドリストが指定されていませんから、@code{LOAD DATA INFILE}は、入力レコードがテーブルのそれぞれのフィールドを含むものと想定します。 @code{FIELDS}と@code{LINES}の初期値が使用されます。 テーブルの一部のフィールドのみ読み込みたい場合、フィールドリストを指定します: @example mysql> LOAD DATA INFILE 'persondata.txt' INTO TABLE persondata (col1,col2,...); @end example テーブル内のフィールド順と入力ファイルのフィールド順が異なる場合にも、@strong{MySQL}にテーブルのフィールドと入力フィールドの対応を教えるために、フィールドリストを指定しなければなりません。 入力レコードのフィールド数の方が少ない場合、入力フィールド値が与えられないフィールドは、初期値が設定されます。 初期値の割当てについては、@ref{CREATE TABLE, , @code{CREATE TABLE}}. で述べられています。 空のフィールド値は変換されます: @itemize @bullet @item 文字型の場合、 フィールドの値は空文字にセットされます。 @item 数値型の場合、フィールドの値は @code{0} にセットされます。 @item 日付と時刻の型の場合、 フィールドの値は ``zero'' の意味する値がセットされます。 @xref{Date and time types}. @end itemize @code{TIMESTAMP} フィールドは、フィールド値に @code{NULL} 値が指定されていた場合もしくは、 フィールドリストが指定されている時に @code{TIMESTAMP} フィールドがそのリストから除外されていた場合 (最初の@code{TIMESTAMP}フィールドのみ)、現在時刻が設定されるだけです。 入力レコードのフィールド数の方が多い場合、余分なフィールドは無視され、警告の数が増やされます。 @code{LOAD DATA INFILE}は全ての入力を文字列と文字列とみなすことから、@code{INSERT}ステートメントでできるような@code{ENUM}フィールドや@code{SET}フィールドへの数値の指定はできません。全ての@code{ENUM}及び@code{SET}値は文字列として与えられなければいけません! @findex mysql_info() @code{LOAD DATA INFILE}クエリの終了時、クエリの情報を得るためにC API関数@code{mysql_info()}を使用することができます。情報の書式は以下に示すようなものです: @example Records: 1 Deleted: 0 Skipped: 0 Warnings: 0 @end example @code{LOAD DATA INFILE} が、入力レコードのフィールド数の過不足があった時にも 警告を引き起こす事を除けば、@code{INSERT} ステートメント (@xref{INSERT, , @code{INSERT}}. ) により値が挿入される時に 警告が発生するのと同じ状況下で、警告が発生します。 警告はどこにも保存されません; 警告の数は全てうまくいった場合にだけ 使用できます。 もし警告を知りたい、その警告の理由を知りたいのなら、 一つ方法があります。 @code{SELECT ... INTO OUTFILE} を使用して 他のファイルに落とし、オリジナルのファイルと比べます。 @code{INSERT}と比較した@code{LOAD DATA INFILE}の効率や@code{LOAD DATA INFILE}の高速化についてのより詳しい情報は、@xref{Insert speed}を参照のこと。 @findex UPDATE @node UPDATE, USE, LOAD DATA, Reference @section @code{UPDATE} 構文 @example UPDATE [LOW_PRIORITY] [IGNORE] tbl_name SET col_name1=expr1,col_name2=expr2,... [WHERE where_definition] [LIMIT #] @end example @code{UPDATE} はテーブルに存在するレコードのフィールドを、新しい値に更新します。 @code{SET} 節はどのフィールドをどういった値にすべきかを示します。 @code{WHERE} 節が与えられた場合、更新すべきレコードを特定することになります。 それ以外は、全てのレコードを更新します。 @code{LOW_PRIORITY} キーワードを指定した場合、@code{UPDATE} の実行は、 テーブルを読んでいるクライアントがなくなるまで、遅らされます。 @code{IGNORE} キーワードを指定した場合は、update 文は、 update 中に二重キーのエラーを得たとしても、異常終了しません。 Rows that would cause conflicts will not be updated. 表記中の @code{tbl_name} からのフィールドをアクセスすると、@code{UPDATE} は現在のフィールド値を使用します。例えば、次のステートメントは @code{age} フィールドにその現在値より1大きい値を設定します: @example mysql> UPDATE persondata SET age=age+1; @end example @code{UPDATE} は左から右に評価されます。例えば、以下の文は @code{age} フィールドを 2倍にし、そのあと1増やします: @example mysql> UPDATE persondata SET age=age*2, age=age+1; @end example もしフィールドに現在もっている値を指定した場合、@strong{MySQL} はそれを通知し、 値は更新しません。 @findex mysql_info() @code{UPDATE} は変更されたレコード数を返します。 @strong{MySQL} 3.22 以上では、C API 関数 @code{mysql_info()} が マッチし更新されたレコード数を返します。また @code{UPDATE} 中に起きた ワーニングの数も返します。 @strong{MySQL} 3.23 では、 @code{LIMIT #} で指定した数だけレコードを変更 できます。 @findex USE @node USE, FLUSH, UPDATE, Reference @section @code{USE} 構文 @example USE db_name @end example @code{USE db_name} 構文は、 @strong{MySQL} に @code{db_name} データベースを この後のクエリのデフォルトのデータベースにするように指示します。 指定されたデータベースは、セッションの最後まで、あるいは、他の @code{USE} 構文 が発行されるまで残ります: @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 @code{USE} 構文で特定のデータベースをカレントにしても、 他のデータベースのテーブルからアクセスすることを妨げません。 以下は @code{db1} データベースの @code{author} テーブルと、 @code{db2} データベースの @code{editor} テーブルにアクセスする例です: @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 @code{USE} 構文は Sybase の互換のために提供されています。 @cindex @code{mysqladmin} @findex FLUSH @node FLUSH, KILL, USE, Reference @section @code{FLUSH} 構文 (キャッシュのクリア) @example FLUSH flush_option [,flush_option] @end example @code{FLUSH} コマンドで @strong{MySQL} が使用している内部キャッシュの いくつかをきれいに消すことができます。 @code{FLUSH} を実行するには、 @strong{reload} 権限がなければなりません。 @code{flush_option} には以下の内一つが指定できます: @multitable @columnfractions .15 .85 @item @code{HOSTS} @tab ホストキャッシュテーブルを空にします。あなたのホストの IP アドレスを変えたり、@code{Host ... is blocked} というエラーメッセージが 出る場合はホストテーブルキャッシュを一度空にしなくてはなりません。 (指定したホストに対して @code{max_connect_errors} 以上の接続エラーが出る場合、 @strong{MySQL} は何か起きたと 推定し、そのホストからのいかなる接続要求も拒否します。ホストテーブルキャッシュの消去は、 再び接続を許すようにします。@xref{Blocked host}.) @code{mysqld} を @code{-O max_connection_errors=999999999} 開始し、このエラーメッセージを 回避できます @item @code{LOGS} @tab 標準のログファイルと更新ログファイルを 一度閉じて再び開きます。 もし更新ログファイルを拡張子無しで指定している場合、新しい更新ログファイルの 拡張子の番号は、一つ前のファイルより 1 増やした数になります。 ファイル名に拡張を使用した場合、@strong{MySQL} は更新ログファイルを閉じて開きます。 @xref{Update log}. @item @code{PRIVILEGES} @tab @code{mysql} データベースの許可テーブルから、 権限情報を再読込します。 @item @code{TABLES} @tab 全ての開いているテーブルを閉じます。 @item @code{TABLES WITH READ LOCK} @tab Closes all open tables and locks all tables for read until one executes @code{UNLOCK TABLES}. @item @code{STATUS} @tab ほとんどのステータス変数を 0 にします。 @end multitable 上に示したコマンドは、@code{mysqladmin} を使用しても実行できます。 @code{mysqladmin} の引数はそれぞれ、 @code{flush-hosts}, @code{flush-logs}, @code{reload}, @code{flush-tables} と なります。 @code{FLUSH} コマンドを実行するには、@strong{reload} 権限がなければなりません。 @cindex @code{mysqladmin} @findex KILL @node KILL, SHOW, FLUSH, Reference @section @code{KILL} 構文 @example KILL thread_id @end example @code{thread_id} には、@code{mysqld} に接続して走っているスレッドの ID を 空白で区切って指定します。 @code{SHOW PROCESSLIST} コマンドで走っているスレッドを知ることができ、 @code{KILL thread_id} コマンドでスレッドを KILL できます。 もし @strong{process} 権限があるなら、全てのスレッドを確認し、KILL 出来ます。 そうでなければ、自分のスレッドだけを、 確認し、KILL する事ができます。 @code{mysqladmin processlist} と @code{mysqladmin kill} をスレッドの 検査と KILL に使用できます。 @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} 構文 (テーブルやフィールドなどについての情報を得る) @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 STATUS [LIKE wild] or SHOW VARIABLES [LIKE wild] or SHOW [FULL] PROCESSLIST or SHOW TABLE STATUS [FROM db_name] [LIKE wild] or SHOW GRANTS FOR user @end example @code{SHOW} はデータベース、テーブル、フィールド、サーバーについての情報を与えます。 @code{LIKE wild} が使用された場合、@code{wild} 文字列は通常の SQL ワイルドカード (@samp{%} と @samp{_}) です。 @code{tbl_name FROM db_name} の代わりに、@code{db_name.tbl_name} が使用できます。 これら二つは同じです: @example mysql> SHOW INDEX FROM mytable FROM mydb; mysql> SHOW INDEX FROM mydb.mytable; @end example @code{SHOW DATABASES} は @strong{MySQL} サーバー上のデータベースを示します。 @code{mysqlshow} コマンドでも同じ情報が得られます。 @code{SHOW TABLES} は指定されたデータベースのテーブルを一覧表示します。 @code{mysqlshow db_name} コマンドでも同じ情報が得られます。 @strong{NOTE}: もしユーザーにテーブルに対する権限が無い場合、 テーブルは @code{SHOW TABLES} や @code{mysqlshow db_name} の要求で 表示されません。 @code{SHOW COLUMNS} は与えられたテーブルのフィールドを表示します。 もしそのフィールドの型が、あなたが @code{CREATE TABLE} 構文実行時に与えたものと 違う場合は、 @strong{MySQL} は、フィールドの型をときおり変更することが あることに注意してください。 @xref{Silent column changes}. @code{DESCRIBE} 文は @code{SHOW COLUMNS} と似たような情報を提供します。 @xref{DESCRIBE, , @code{DESCRIBE}}. @code{SHOW TABLE STATUS} (バージョン 3.23 の新機能) は @code{SHOW STATUS} のようですが、それぞれのテーブルについてより多くの情報を提供します。 @code{mysqlshow --status db_name} コマンドを実行しても同じものが得られます。 以下の項目が返ってきます: @multitable @columnfractions .30 .70 @item @strong{項目} @tab @strong{意味} @item @code{Name} @tab テーブル名 @item @code{Type} @tab テーブルの種類 (BDB, ISAM, MyISAM or HEAP) @item @code{Row_format} @tab レコードの保存形式 (Fixed, Dynamic, or Compressed) @item @code{Rows} @tab レコード数 @item @code{Avg_row_length} @tab レコードの平均長 @item @code{Data_length} @tab データファイルの大きさ @item @code{Max_data_length} @tab データファイルの最大値 @item @code{Index_length} @tab インデックスファイルの大きさ @item @code{Data_free} @tab 割り当てられたが使用されていないバイト数 @item @code{Auto_increment} @tab 次の autoincrement 値 @item @code{Create_time} @tab テーブル作成時刻 @item @code{Update_time} @tab 一番最後に更新された時刻 @item @code{Check_time} @tab 一番最後にチェックされた時刻 @item @code{Create_options} @tab @code{CREATE TABLE} で使用された拡張オプション @item @code{Comment} @tab テーブル作成時につけられたコメント (あるいは、なぜこのテーブルに@strong{MySQL} がアクセスできないかのいくつかの情報). @end multitable @code{SHOW FIELDS} は @code{SHOW COLUMNS} の別名として使用され、 @code{SHOW KEYS} は @code{SHOW INDEX} の別名として使用されます。 テーブルのフィールドやインデックスは @code{mysqlshow db_name tbl_name} か @code{mysqlshow -k db_name tbl_name} でも見れます。 @code{SHOW INDEX} は ODBC でいう @code{SQLStatistics} に近い形式で、インデックスの情報を表示します。 以下の項目が返ります: @multitable @columnfractions .35 .65 @item @strong{項目} @tab @strong{意味} @item @code{Table} @tab テーブル名 @item @code{Non_unique} @tab インデックスが重複を含まないなら 0 @item @code{Key_name} @tab インデックス名 @item @code{Seq_in_index} @tab インデックスの項目番号。1 から始まります。 @item @code{Column_name} @tab フィールド名。 @item @code{Collation} @tab いかにこのフィールドがインデックス中でソートされるか. @strong{MySQL} では, これは @code{A} (Ascending) か @code{NULL} (Not sorted) になります。 @item @code{Cardinality} @tab インデックス中のユニークな値の数。 これは @code{isamchk -a} の実行で更新されます。 @item @code{Sub_part} @tab もしこのフィールドがインデックスに一部分だけ使用している場合、そのインデックスに使用しているキャラクター数をしめす。 もしキー全体がインデックスされているなら @code{NULL} 。 @end multitable @cindex @code{mysqladmin} @code{SHOW STATUS} は @code{mysqladmin extended-status} と同様に、サーバからのステー タス情報を与えます。出力は次とは異なるかもしれません: @example +--------------------------+--------+ | Variable_name | Value | +--------------------------+--------+ | Aborted_clients | 0 | | Aborted_connects | 0 | | Connections | 17 | | Created_tmp_tables | 0 | | Delayed_insert_threads | 0 | | Delayed_writes | 0 | | Delayed_errors | 0 | | Flush_commands | 2 | | Handler_delete | 2 | | Handler_read_first | 0 | | Handler_read_key | 1 | | Handler_read_next | 0 | | Handler_read_rnd | 35 | | Handler_update | 0 | | Handler_write | 2 | | Key_blocks_used | 0 | | Key_read_requests | 0 | | Key_reads | 0 | | Key_write_requests | 0 | | Key_writes | 0 | | Max_used_connections | 1 | | Not_flushed_key_blocks | 0 | | Not_flushed_delayed_rows | 0 | | Open_tables | 1 | | Open_files | 2 | | Open_streams | 0 | | Opened_tables | 11 | | Questions | 14 | | Slow_launch_threads | 0 | | Slow_queries | 0 | | Threads_connected | 1 | | Threads_running | 1 | | Uptime | 149111 | +--------------------------+--------+ @end example 上に示したステータス変数は以下に示すの意味を持ちます: @multitable @columnfractions .35 .65 @item @code{Aborted_clients} @tab クライアントが接続を閉じる前に死んでしまったために中断されたコネクション数。 @item @code{Aborted_connects} @tab @strong{MySQL} サーバーに接続を試みて失敗した数 @item @code{Bytes_received} @tab クライアントから受信したバイト数 @item @code{Bytes_sent} @tab クライアントに送信したバイト数 @item @code{Connections} @tab @strong{MySQL} サーバーに接続を試みた数 @item @code{Created_tmp_tables} @tab ステートメント実行中に暗黙のうちに作成された一時テーブルの数 @item @code{Delayed_insert_threads} @tab 使用中の delayed insert ハンドラースレッドの数 @item @code{Delayed_writes} @tab @code{INSERT DELAYED} で書かれたレコード数 @item @code{Delayed_errors} @tab @code{INSERT DELAYED} で書かれたレコードでなんらかのエラーのあったレコード数 (たぶん @code{duplicate key}). @item @code{Flush_commands} @tab @code{FLUSH} コマンドの実行回数 @item @code{Handler_delete} @tab テーブルからレコードを削除するためのリクエスト数 @item @code{Handler_read_first} @tab テーブル中の最初のレコードを読むためのリクエスト数。 @item @code{Handler_read_key} @tab キーに基づいてレコードを読むためのリクエスト数。 @item @code{Handler_read_next} @tab キー順で次のレコードを読むためのリクエスト数。 @item @code{Handler_read_rnd} @tab 固定位置に基づいてレコードを読むためのリクエスト数。 @item @code{Handler_read_rnd_next} @tab データファイルの次のレコードを読む要求の数。 多くのテーブルスキャンを行なう場合、これは高くなります - 通常、これはテー ブルが正しくインデックスされていないか、存在するインデックスを有利に使うよ うにクエリが書かれていないことを示唆します。 @item @code{Handler_update} @tab テーブルのレコードを更新するための要求数 @item @code{Handler_write} @tab テーブルにレコードを挿入するためのリクエスト数 @item @code{Key_blocks_used} @tab キーキャッシュ中で使用されたブロック数 @item @code{Key_read_requests} @tab キャッシュからキーブロックを読み込んだリクエスト数 @item @code{Key_reads} @tab Disk から物理的にキーブロックを読んだ回数 @item @code{Key_write_requests} @tab キャッシュにキーブロックを書き込んだリクエスト数 @item @code{Key_writes} @tab Diskに物理的にキーブロックを書き込んだ回数 @item @code{Max_used_connections} @tab 最大同時接続数 @item @code{Not_flushed_key_blocks} @tab キーキャッシュ中にあるキーブロックで、変更されたもののいまだDiskに書き出されていないキーブロック数 @item @code{Not_flushed_delayed_rows} @tab @code{INSERT DELAY} クエリで書き出しを待っているレコード数 @item @code{Open_tables} @tab オープンされているテーブル数 @item @code{Open_files} @tab オープンされているファイル数 @item @code{Open_streams} @tab 開いているストリーム数 (主にログに使用される) @item @code{Opened_tables} @tab オープンされたテーブル数 @item @code{Questions} @tab サーバーに送られたクエリの数 @item @code{Slow_launch_threads} @tab 接続に @code{slow_launch_time} 以上を要したスレッド数 @item @code{Slow_queries} @tab @code{long_query_time} 以上に時間のかかったクエリの数 @item @code{Threads_cached} @tab スレッドキャッシュ内のスレッド数 @item @code{Threads_connected} @tab 現在開いている接続数 @item @code{Threads_running} @tab スリープしていないスレッドの数 @item @code{Uptime} @tab サーバーが走っている秒数 @end multitable 上についてのいくつかコメント: @itemize @bullet @item もし @code{Opened_tables} が大きければ、 @code{table_cache} 変数が小さすぎる のでしょう。 @item もし @code{key_reads} が大きければ、 @code{key_cache} が少なすぎるでしょう。 キャッシュヒットレートは @code{key_reads}/@code{key_read_requests} で計算できます。 @item もし @code{Handler_read_rnd} が大きければ、 @strong{MySQL} にテーブルをスキャンさせるような多くのクエリ や、 キーを使用しない JOIN がもてます。 @end itemize @code{SHOW VARIABLES} は @strong{MySQL} システム変数のいくつかの値を示します。 @code{mysqlshow variables} コマンドでも同じ情報が得られます。 もし標準値が適さないなら、ほとんどの変数を @code{mysqld} 起動時に コマンドラインのオプションとして与えることにより、変更できます。 出力は以下のようになりますが、フォーマットや数はいくぶん違うでしょう: @example +------------------------+--------------------------+ | Variable_name | Value | +------------------------+--------------------------+ | back_log | 5 | | connect_timeout | 5 | | basedir | /my/monty/ | | datadir | /my/monty/data/ | | delayed_insert_limit | 100 | | delayed_insert_timeout | 300 | | delayed_queue_size | 1000 | | join_buffer_size | 131072 | | flush_time | 0 | | interactive_timeout | 28800 | | key_buffer_size | 1048540 | | language | /my/monty/share/english/ | | log | OFF | | log_update | OFF | | long_query_time | 10 | | low_priority_updates | OFF | | max_allowed_packet | 1048576 | | max_connections | 100 | | max_connect_errors | 10 | | max_heap_table_size | 16777216 | | max_delayed_threads | 20 | | max_join_size | 4294967295 | | max_sort_length | 1024 | | max_tmp_tables | 32 | | net_buffer_length | 16384 | | port | 3306 | | protocol-version | 10 | | record_buffer | 131072 | | skip_locking | ON | | slow_launch_time | 2 | | socket | /tmp/mysql.sock | | sort_buffer | 2097116 | | table_cache | 64 | | thread_stack | 131072 | | tmp_table_size | 1048576 | | tmpdir | /machine/tmp/ | | version | 3.23.0-alpha-debug | | wait_timeout | 28800 | +------------------------+--------------------------+ @end example @xref{Server parameters, ,Server parameters}. @findex Threads @findex PROCESSLIST @code{SHOW PROCESSLIST} はどのスレッドが走っているかを表示します。 @code{mysqlshow processlist} コマンドでも同じ情報が得られます。 もし @strong{process} 権限があるなら、全てのスレッドがみれます。 しかし権限がないなら、自分のスレッドしか見れません。 @xref{KILL, , @code{KILL}}. @code{FULL} オプションを使用しない場合、各クエリの最初の100文字だけが表示 されます。 @code{SHOW GRANTS FOR user} はユーザの許可を複製するために発行する必要があ る grant コマンドをリストします。 @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} 構文 (@code{SELECT}についての情報を得る) @example EXPLAIN tbl_name or EXPLAIN SELECT select_options @end example @code{EXPLAIN tbl_name} は、 @code{DESCRIBE tbl_name} や @code{SHOW COLUMNS FROM tbl_name} と同義です。 もし @code{EXPLAIN} をともなって @code{SELECT} 構文を実行した場合、 @strong{MySQL} はこの @code{SELECT} がいかに動作するかを説明し、 いかにテーブルが結合されるかの情報を与えます。 @code{EXPLAIN} の情報を元に、インデックスを使用した速い @code{SELECT} を 得るためにテーブルにインデックスを加えなくてはならないという事がわかります。 テーブル結合の最適化もオプションによって見ることができます。 @code{SELECT} 構文での結合を強制的に最適化するには @code{STRAIGHT_JOIN} 節を加えます。 単純ではない join のために、@code{EXPLAIN} は @code{SELECT} 文で使用されている それぞれのテーブルの情報を返します。 テーブルは読まれる順に表示されます。@strong{MySQL} は one-sweep multi-join method を用いた全ての join を解決します。これは @strong{MySQL} は最初のテーブルから 一レコード読み込み、二つ目のテーブルからマッチしたレコードを探し、そして三番目を探すということです。 全てのテーブルが処理される時、選択されたフィールドを出力し、テーブルの一覧は よりマッチするレコードをもつテーブルを見つけるまで back-track されます。 次のレコードはこのテーブルから読まれ、次のテーブルから処理を続けます。 @code{EXPLAIN} の出力は以下のフィールドを含みます: @table @code @item table 出力レコードが参照されるテーブル @item type  join タイプ. 様々なタイプの説明は後述します @item possible_keys @code{possible_keys} 項目は、@strong{MySQL} がテーブルからレコードを見つけるために どのインデックスを使用する事ができたかを示します。 注意: このフィールドはテーブルの順にまったく依存しません。これは、 possible_keys 内のいくつかのキーは、生成されたテーブル順での実行に使用でき ないことを意味します。 この項目が空なら、関連した インデックスは無いということです。この場合、あなたは @code{WHERE} 節を 調べることによって、クエリの性能を向上させることができるかもしれません。 もしそれがインデックスに適合したフィールドを参照しているならば。 仮にそうだとすると、適切なインデックスを作成し、 @code{EXPLAIN} でクエリを もう一度チェックしてみてください。 テーブルがどんなインデックスを持っているかみるには、@code{SHOW INDEX FROM tbl_name} とします。 @item key    @code{key} 項目は、 @strong{MySQL} が使用すると実際に決めたキーを示します。 どのインデックスも選ばれなかったならば、キーは @code{NULL} です。 @strong{MySQL} が間違ったインデックスを選択する場合、たいていは @strong{MySQL} に他のインデックスを使用するように強制することができます。 @code{myisamchk --analyze} の使用、@xref{myisamchk syntax}、または @code{USE INDEX/IGNORE INDEX} の使用によって。@xref{JOIN}。 @item key_len @code{key_len} 項目は、@strong{MySQL} が使用すると決めたキーの長さを示します。 もし @code{key} が @code{NULL} なら、長さは @code{NULL} です。 注意: これは@strong{MySQL} がマルチパートキーのいくつのパートを実際に使用 するかを示します。 @item ref    @code{ref} 項目は、テーブルからレコードを select するために、どのフィールドや定数が @code{key} と共に使用されたかを示します。 @item rows    @code{rows} フィールドは、@strong{MySQL} がクエリを実行するために検査する 必要があると考えているレコードの数を示します。 @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} optimisation 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 join type は以下のものがあります。良い物から順に書いています: @cindex System table @cindex Table, system @table @code @item system テーブルが一レコードだけ持っている (= system table). これは @code{const} join type の特別な場合です。 @cindex Constant table @cindex Table, constant @item const テーブルは、最もマッチするレコードを1つもっており、これはクエリの 最初に読まれます。 1 つのレコードであるため、このレコード中のフィールドの値は オプティマイザーによって常数としてみなされます。 1回だけ読まれるので、@code{const} テーブルはとても速いです! @item eq_ref 前のテーブルのそれぞれのレコードと結合する際、このテーブルから1レコード読まれます。 これは join では @code{const} よりも良い形です。 インデックスの全てのパートが join で使用され、かつ、インデックスが @code{UNIQUE} か @code{PRIMARY KEY} であるときに、これは使用されます。 @item ref    インデックスの値に合ったすべてのレコードは、前のテーブルからレコードと結合するために、 このテーブルから読まれるでしょう。 もしその join がキーの一番左の接頭部分だけを使用するならば、 あるいは、 もしそのキーが @code{UNIQUE} や @code{PRIMARY KEY} でなければ (言い換えるなら、もし join がキーの値を元に一つだけの、レコードを選択できなければ)、 @code{ref} は使用されます。 もしそのキーがいくつかのマッチするレコードに使用されるだけなら、 join は良い形です。 @item range 示された範囲内にあるレコードのみが検索されます。 @code{ref} 項目はどのインデックスが使用されているか示します。 @item index @code{ALL} と同じですが、インデックスツリーが走査される場合のみを除きます。 これは、インデックスファイルはデータファイルよりも小さいため、通常 @code{ALL} より速いです。 @item ALL 前のテーブルのレコードとのそれぞれの結合において、全テーブルが走査されます。 もしそのテーブルが最初のテーブルで @code{const} 状態ではないなら、通常 これは良くありません。他の状態では@strong{とても}悪くなります。 これは普通、レコードががより早いテーブルからから定数値に基づいて検索することができるように、 インデックスを追加することにより @code{ALL} を避けることが可能です。 @end table @code{EXPLAIN} 出力の @code{rows} フィールド内のすべての値を増やすことによ り、join がどのように良くなるかの良い表示を得ることができます。これは、 @strong{MySQL} がクエリ実行の検査をする必要があるレコードのおおよその数を 知らせます。この数は @code{max_join_size} 変数でのクエリを制限する時にも使 用します。 @xref{Server parameters}. 以下の例は、@code{EXPLAIN} が提供する情報を元に、いかに @code{JOIN} が最適化 できるかの例です。 以下のような @code{EXPLAIN} で検査する @code{SELECT} 構文があるとします: @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 この例では、以下のように仮定します: @itemize @bullet @item フィールドは以下のように定義されています: @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 テーブルは以下のインデックスを持ちます: @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 @code{tt.ActualPC} の値は、いちように分布して(配置されて)いません。 @end itemize 最初、いかなる最適化も行われていない状態では、@code{EXPLAIN} 構文は 以下の情報を提示します: @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 それぞれのテーブルで、@code{type} が @code{ALL} になっています。 これは @strong{MySQL} が全てのテーブルを全結合することを示します! それぞれのテーブル内の行数分から作った物が調べられるので、とても長い時間がかかります! この場合、@code{74 * 2135 * 74 * 3872 = 45,268,558,720} 行調べることになります。 テーブルが肥大化したときにかかる時間を考えてください.... 一つ問題があります。(まだ) @strong{MySQL} がフィールドのインデックスを効果的に 使用できていません。 この例の場合では、@code{VARCHAR} と @code{CHAR} は、それらが同じ長さで定義されていれば、 変わりがありません。 @code{tt.ActualPC} は @code{CHAR(10)} と定義されており、 @code{et.EMPLOYID} は @code{CHAR(15)} です。これらの長さは違います。 この不釣り合いを修正するにあたり、@code{ALTER TABLE} を使って @code{ActualPC} の長さを 10 文字から 15 文字にします: @example mysql> ALTER TABLE tt MODIFY ActualPC VARCHAR(15); @end example これで @code{tt.ActualPC} and @code{et.EMPLOYID} は両方とも @code{VARCHAR(15)} になりました。 @code{EXPLAIN} 構文を実行し直すと、以下を提示します: @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 まだ完全ではありませんが、よりよくなっています(@code{rows} 値の 生成量は 74 より小さくなります)。この場合、実行は数秒でしょう。 @code{tt.AssignedPC = et_1.EMPLOYID} と @code{tt.ClientID = do.CUSTNMBR} の比較において、フィールドの長さの違いを排除することができます: @example mysql> ALTER TABLE tt MODIFY AssignedPC VARCHAR(15), MODIFY ClientID VARCHAR(15); @end example これで @code{EXPLAIN} は以下を出力します: @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 これは ``ほとんど'' 最良に近いです。 残る問題は、デフォルトでは、@strong{MySQL} は @code{tt.ActualPC} フィールド内の値が まんべんなく分布していると想定しており、この @code{tt} テーブルの場合には適合しません。 幸運にも、これを @strong{MySQL} に教えるのはとても簡単です: @example shell> myisamchk --analyze PATH_TO_MYSQL_DATABASE/tt shell> mysqladmin refresh @end example これで join は ``完璧'' です。 @code{EXPLAIN} は以下の結果を示します: @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 @code{EXPLAIN} の出力中の @code{rows} 項目は、 @strong{MySQL} JOIN オプティマイザー による、``推測'' です; クエリの最適化のために、この数値が実際に近いかどうかをチェックすべきです。 そうでなければ、@code{SELECT} ステートメントで @code{STRAIGHT_JOIN} を使用 し、@code{FROM} 節に異なる順でテーブルを並べることで、良いパフォーマンスを 得られます。 @findex DESC @findex DESCRIBE @node DESCRIBE, COMMIT, EXPLAIN, Reference @section @code{DESCRIBE} 構文 (フィールドについての情報を得る) @example @{DESCRIBE | DESC@} tbl_name @{col_name | wild@} @end example @code{DESCRIBE} はフィールドについての情報を与えます。 @code{col_name} はフィールドはフィールド名または文字列です。 文字列は SQL @samp{%},@samp{_} ワイルドカードを含めます。 もしフィールドの型があなたが @code{CREATE TABLE} 文で与えた物と違っているなら、 これは @strong{MySQL} がフィールドの型を変更していることに注意してください。 @xref{Silent column changes}. @cindex Oracle compatibility @cindex Compatibility, with Oracle このコマンドは Oracle の互換のためにあります。 @code{SHOW} 構文は似たような情報を提供します。 @xref{SHOW, , @code{SHOW}}. @findex BEGIN @findex COMMIT @findex ROLLBACK @node COMMIT, LOCK TABLES, DESCRIBE, Reference @section @code{BEGIN/COMMIT/ROLLBACK} 構文 デフォルトでは @strong{MySQL} は @code{autocommit} モードで動作します。こ れは、更新を実行するとすぐに @strong{MySQL} が更新をディスクに格納すること を意味します。 もし @code{BDB} 型のテーブルを使用するなら, 以下のコマンドで @strong{MySQL} を @code{autocommit} モードではない状態にすることができます: @example SET AUTOCOMMIT=0 @end example この後、ディスクに変更を格納するためには @code{COMMIT} を使用し、また、変 更を無視するためには @code{ROLLBACK} する必要があります。 If you want to switch from @code{AUTOCOMMIT} mode for one serie of statements, you can use the @code{BEGIN} statement. @example BEGIN; SELECT @@A:=SUM(salary) FROM table1 WHERE type=1; UPDATE table2 SET summmary=@@A WHERE type=1; COMMIT; @end example 注意: トランザクション安全テーブルを使用していない場合は、@code{autocommit} モードのステータスには依存せずに、変更はすぐに格納されます。@xref{Table types}. @findex LOCK TABLES @findex UNLOCK TABLES @node LOCK TABLES, SET OPTION, COMMIT, Reference @section @code{LOCK TABLES/UNLOCK TABLES} 構文 @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} はカレントのスレッドのためにテーブルをロックします。 @code{UNLOCK TABLES} はこのスレッドの全てのロックを解除します。 カレントスレッドによってロックされた全てのテーブルは、 スレッドが他の @code{LOCK TABLES} を発行した場合やサーバーが接続を閉じた場合、 自動で解除されます。 スレッドがテーブルに @code{READ} ロックを持つ場合、そのスレッド(と他の全てのスレッド)は テーブルからの読み込みだけができます。スレッドがテーブルに @code{WRITE} ロックを持つ場合、 このスレッドだけがテーブルの @code{READ} と @code{WRITE} ができます。 他のスレッドはブロックされます。 @code{READ LOCAL} と @code{READ} の違いは、@code{READ LOCAL} は、ロックが 保持されている間にコンフリクトしない @code{INSERT} ステートメントを実行で きることです。ただし、これはロックを保持している間に @strong{MySQL} の外で データベースファイルを操作しようとする場合は使用できません。 それぞれのスレッドはそれらが全てのロックを得るまで待ちます(タイムアウト無し)。 @code{WRITE} ロックは普通、できる限り更新を行わせるため、 @code{READ} ロックよりも優先順位が高くなっています。 これはあるスレッドが @code{READ} ロックをかけ、それ以外のスレッドが @code{WRITE} を 要求した場合、 @code{READ} は、@code{WRITE} スレッドがロックをし、それを解除するまで 待つということです。 @code{LOW_PRIORITY WRITE} を使用すれば、 @code{WRITE} ロックを待っているスレッドに @code{READ} ロックを得させることができます。 @code{LOW_PRIORITY WRITE} は @code{READ} ロックをしているスレッドが一つもないと わかっている場合に使用すべきです。 @code{LOCK TABLES} を使用するとき、使用しようとする全てのテーブルをロッ クすべきです! そしてクエリで使用しようとしているのと同じエイリアスを使わなければなりません! もしクエリで並列に複数回テーブルを使用するなら(alias をともなって)、 それぞれの alias をロックすべきです! このポリシーはテーブルロックをデッドロックフリーにすることを確かにします。 @code{INSERT DELAYED} で使用しているいかなるテーブルも、ロックすべきではありません。 この場合 @code{INSERT} は別のスレッドで行なわれるからです。 通常、全ての単一の @code{UPDATE} 構文においては、テーブルをロックする必要はありません; スレッドは、他のスレッドが現在実行している SQL 文に干渉することができません。 これらはテーブルをロックした方がよい、まれな場合です: @itemize @bullet @item テーブルをまとめて多くの操作を実行しようとする場合、使用しようとしているテー ブルをロックするととても速くなります。もちろん、他のスレッドは @code{READ} ロッ クされたテーブルの更新はできませんし、他のスレッドは @code{WRITE} ロックされた テーブルを読むことはできません。 @item @code{MySQL} はトランザクション環境をサポートしないため、他のスレッドが @code{SELECT},@code{UPDATE}の間に来ないことを保証したい場合は、 @code{LOCK TABLES} を使用する必要があります。 次の例は安全のためには @code{LOCK TABLES} を必要とします: @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 @code{LOCK TABLES} を使用しない場合、@code{SELECT} の実行と @code{UPDATE} の 実行を行う間に、他のスレッドが新しい @code{trans} 行を挿入する隙ができます。 @end itemize 増加更新 (@code{UPDATE customer SET value=value+new_value}) または @code{LAST_INSERT_ID()} 関数の使用により、多くの場合 @code{LOCK TABLES} を回避 できます。 いくつかの場合、ユーザレベルロック: @code{GET_LOCK()} と @code{RELEASE_LOCK()} の使用 によっても解決できます。これらのロックはサーバ内のハッシュテーブル内に保 持され、高速のため @code{pthread_mutex_lock()} で実装されました。 @xref{Miscellaneous functions}. ロックポリシーのさらなる情報については @ref{Internal locking} を見てくださ い。 @findex SET OPTION @node SET OPTION, GRANT, LOCK TABLES, Reference @section @code{SET OPTION} 構文 @example SET [OPTION] SQL_VALUE_OPTION= value, ... @end example @code{SET OPTION} はサーバやクライアントの操作に影響する様々なオプションを設定します. 現在のセッションが終わるか,またはあなたが異なった値にオプションを設定するまで, 設定されたオプション値は残っています. @table @code @item CHARACTER SET character_set_name | DEFAULT これは指定されたマッピングに従って、すべての文字列をクライアントからクライアントにマップします. 現在、@code{character_set_name} に指定できるオプションは @code{cp1251_koi8} だけですが, @strong{MySQL} のソース中にある @file{sql/convert.cc} ファイルを編集することによって, 容易に新しいマッピングを加えることができます. 標準のマッピングに戻すには、 @code{character_set_name} に @code{DEFAULT} を指定します。 @code{CHARACTER SET} オプションを設定するための構文は、 他のオプションを設定する構文と異なっていることに注意してください. @item PASSWORD = PASSWORD('some password') @cindex Passwords, setting 現在のユーザのパスワードを設定します。いかなる非匿名のユーザも、 自分自身パスワードを変えることができます! @item PASSWORD FOR user = PASSWORD('some password') @cindex Passwords, setting 現在ログインしているホストの特定ユーザのパスワードを設定します。 @code{mysql} データベースにアクセスができるユーザーだけが実行できます。 ユーザは @code{user@@hostname} 形式で与えなくてはなりません。 ここで @code{user} と @code{hostname} は、@code{mysql.user} テーブルの @code{User}, @code{Host} フィールドに登録されていなくてはなりません。 例えば、@code{User} と @code{Host} フィールドが @code{'bob'} と @code{'%.loc.gov'} ならば、以下のようにします: @example mysql> SET PASSWORD FOR bob@@"%.loc.gov" = PASSWORD("newpass"); または mysql> UPDATE mysql.user SET password=PASSWORD("newpass") where user="bob' and host="%.loc.gov"; @end example @item SQL_AUTO_IS_NULL = 0 | 1 @code{1} (デフォルト) を設定すると、次のようにして、auto_increment レコー ドを持つテーブルで、最後に挿入されたレコードを見つけることができます: @code{WHERE auto_increment_column IS NULL}。これは、Access のようないくつ かの ODBC プログラムによって使用されます。 @item SET AUTOCOMMIT= 0 | 1 @code{1} を設定すると、テーブルへのすべての変更はすぐに行なわれます。 To start an multi command transaction you have to use the @code{BEGIN} statement. @xref{COMMIT}. @code{0} を設定すると、そのトランザクションを許可/破棄するために、 @code{COMMIT} / @code{ROLLBACK} を使用する必要があります。@xref{COMMIT}。 注意: 非 @code{AUTOCOMMIT} モードから @code{AUTOCOMMIT} モードに変更する時、 @strong{MySQL} はすべてのオープントランザクションを自動的に @code{COMMIT} します。 @item SQL_BIG_TABLES = 0 | 1 @cindex The table is full @code{0} の場合、全ての一時テーブルはメモリーではなくディスクに書き出されます。 これは少し遅くなりますが、多くの一時テーブルを必要とする大きな @code{SELECT} を 実行しても、@code{The table tbl_name is full} エラーが出なくなります。 新しい接続におけるこの値のデフォルト値は @code{1} (メモリーに一時テーブルを作る) です。 @item SQL_BIG_SELECTS = 0 | 1 @code{1} の場合、とても時間のかかる @code{SELECT} が実行された場合、 @strong{MySQL} はそれを中止します。 これはあまり芳しくない(間違った) @code{WHERE} 構文が発行されたときに役立ちます。 @code{max_join_size} 行以上を検討するような @code{SELECT} が 大きなクエリと定義されます。 新しい接続におけるこの値のデフォルト値は @code{0} です。 (全ての @code{SELECT} 構文を許します) @item SQL_BUFFER_RESULT = 0 | 1 @code{SQL_BUFFER_RESULT} は一時ファイルに置かれる @code{SELECT} からの結果 を強制的に置きます。これは @strong{MySQL} がテーブルロックを早く解放する手 助けをし、クライアントへ結果セットを送信するために長い時間が掛かる場合に役 立ちます。 @item SQL_LOW_PRIORITY_UPDATES = 0 | 1 @code{1} の場合、全ての @code{INSERT}, @code{UPDATE}, @code{DELETE}, @code{LOCK TABLE WRITE}構文は、 対象となるテーブルを処理中の @code{SELECT} や @code{LOCK TABLE READ} がなくなるまで待ちます。 @item SQL_MAX_JOIN_SIZE = value | DEFAULT おそらく @code{value} よりも多いレコードの組合せを試験する必要があるような @code{SELECT} を許可しません。この値を設定することで、キーが使用されないで あろう @code{SELECT} と長い時間が掛かるであろう @code{SELECT} を捕捉できま す。これを @code{DEFAULT} 以外の値に設定すると、@code{SQL_BIG_SELECTS} フ ラグをリセットします。@code{SQL_BIG_SELECTS} フラグを再び設定すると、 @code{SQL_MAX_JOIN_SIZE} 変数は無視されます。@code{-O max_join_size=#} で @code{mysqld} を起動することで、この変数のデフォルト値を設定できます。 @item SQL_SAFE_MODE = 0 | 1 @code{1} に設定すると、@code{WHERE} 節内でキーや @code{LIMIT} を使用しない で @code{UPDATE} または @code{DELETE} を行なおうとした場合に @strong{MySQL} がアボートします。これは、手で SQL コマンドを生成する時の間 違った更新の捕捉を可能にします。 @item SQL_SELECT_LIMIT = value | DEFAULT @code{SELECT} 構文から返されるレコードの最大値。 もし @code{SELECT} に @code{LIMIT} 節を使用している場合、@code{LIMIT} は @code{SQL_SELECT_LIMIT} の値より優先されます。 新しい接続におけるこの値の標準値は ``unlimited''. もしリミットを変えているならば、@code{SQL_SELECT_LIMIT} に @code{DEFAULT} を指定することにより、標準値に戻すことができます。 @item SQL_LOG_OFF = 0 | 1 この値が @code{1} の場合、もしクライアントが @strong{process} 権限を持っているならば、 このクライアントのログが行われません。 これは更新ログに影響しません! @item SQL_LOG_UPDATE = 0 | 1 @code{0} の場合、もしクライアントが @strong{process} 権限を持っているならば、 このクライアントの更新ログの記録は行われません。 これは通常のログには影響しません! @item TIMESTAMP = timestamp_value | DEFAULT クライアントに時間を設定します。 もしレコードのリストアに更新ログを使用する場合、オリジナルのタイムスタンプを得るために使用します。 @item LAST_INSERT_ID = # @code{LAST_INSERT_ID()} からの返り値を設定します。 テーブルを更新するコマンド中に @code{LAST_INSERT_ID()} を使用した場合、 これは更新ログに保存されます。 @item INSERT_ID = # @code{AUTO_INCREMENT} 値を挿入する時、 @code{INSERT} コマンドに従って使用される値をセットします。 これは更新ログによって使用されます。 @end table @findex GRANT @findex REVOKE @node GRANT, CREATE INDEX, SET OPTION, Reference @section @code{GRANT} と @code{REVOKE} 構文 @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} は @strong{MySQL} 3.22.11 以上で実装されています; 前の @strong{MySQL} バージョンでは、@code{GRANT} ステートメントは何も行ないま せん。 @code{GRANT} と @code{REVOKE} コマンドセットの主な目的は、システム管理者 が @strong{MySQL} ユーザに次の4つの権限レベルの権利を与えたり取り消すこ とをできるようにすることです: @table @strong @item Global レベル Global 権限は与えられたサーバ上の全てのデータベースに適用します。これらの権限は @code{mysql.user} テーブル内に格納されます。 @item Database レベル Database 権限は与えられたデータベース内の全てのテーブルに適用します。こ れらの権限は @code{mysql.db} テーブルと @code{mysql.host} テーブル内に格納されます。 @item Table レベル Table 権限は与えられたテーブル内の全てのフィールドに適用します。これらの権限は @code{mysql.tables_priv} テーブル内に格納されます。 @item Column レベル Column 権限は与えられたテーブル内の一つのフィールドに適用します。これらの権限は @code{mysql.column_priv} テーブル内に格納されます。 @end table @code{GRANT} の動作例は → @ref{Adding users}. @code{GRANT} と @code{REVOKE} ステートメントにおいて @code{priv_type} には 以下が指定できます: @example ALL PRIVILEGES FILE RELOAD ALTER INDEX SELECT CREATE INSERT SHUTDOWN DELETE PROCESS UPDATE DROP REFERENCES USAGE @end example @code{ALL} は @code{ALL PRIVILEGES} の同義語です. @code{REFERENCES} はまだ実行されません。 @code{USAGE} は ``no privileges'' と同義です. これはなんの権限も持たないユーザーを作る場合に使用します. ユーザーから権限許可を取り除くには、@code{GRANT OPTION} オプションの値に @code{priv_type} を指定します: @example REVOKE GRANT OPTION ON ... FROM ...; @end example テーブルに対する許可のために指定できる @code{priv_type} は次のフィールドだけです: @code{SELECT},@code{INSERT}, @code{UPDATE}, @code{DELETE}, @code{CREATE}, @code{DROP}, @code{GRANT}, @code{INDEX}, @code{ALTER}. フィールドに対する許可のために指定できる @code{priv_type} は次のフィールドだけです (これは @code{column_list} 節を使用する場合に適用されます): @code{SELECT}, @code{INSERT}, @code{UPDATE}. @code{WITH GRANT OPTION} 節は、@code{GRANT} 構文を使用して 他のユーザーに権限を与えることができるようにします。 @code{ON *.*} を使用してグローバル権限を設定できます。 @code{ON db_name.*} を使用してデータベース権限を設定できます。@code{ON *} を 指定すると、現在のデータベースの権限を設定できます。 (@strong{警告:} 現在のデータベースを持たない状態で @code{ON *} を指定した場合、 global 権限に影響します!) ユーザへの権利の供与を他のホストから適応するために、@strong{MySQL} は @code{user_name} の値を @code{user@@host} の形で書けるようにしています。 特殊文字(@samp{%} のような)で @code{user_name} の値を指定したい場合、 ユーザやホスト名をクォートできます; (例えば @code{'test-user'@@'test-hostname'})。 ホスト名にワイルドカードを使用できます。例えば、@code{user@@"%.loc.gov"} は @code{loc.gov} ドメインの全てのホストの @code{user} を与え、 @code{user@@"144.155.166.%"} は @code{144.155.166} クラスCサブネットの あらゆるホストの @code{user} となります。 単に @code{user} と書くと @code{user@@"%"} と同じです. @strong{注意:} もし匿名ユーザーからの @strong{MySQL} サーバーへの接続を 許す場合(デフォルトです)、全てのローカルユーザー @code{username@@localhost} を加えるべきです。 なぜなら、匿名ユーザーは同じマシンから @strong{MySQL} サーバーに入ろうとした場合に 使用されるからです! 匿名ユーザーは @code{mysql.user} ユーザーテーブルに、 @code{User=''} として登録されています。 これを確認するには、以下のようにします: @example mysql> SELECT Host,User FROM mysql.user WHERE User=''; @end example さしあたり, @code{GRANT} はホスト名、テーブル名、データベース名、フィールド名に 最大60文字まで使用できます。ユーザー名は最大16文字までです。 テーブル/フィールドの権限は global(ユーザとデータベース)権限と @code{GRANT} 権限と @code{OR} されます。例えば、ユーザが @code{mysql.user} テーブル内の global @strong{select} 権限を持っている場合、 これはデータベースやテーブル/フィールドレベル内のエントリでは拒否できません。 フィールドの権利は次のように計算できます: @example global privileges OR (database privileges AND host privileges) OR table privileges OR column privileges @end example 多くの場合、異なる権限レベルの一つでユーザに権利を与えるので、人生は通常 上述のようには複雑ではありません。:) アクセス制限のチェックの詳細は→@ref{Privilege system}. ユーザへの権利の供与を他のホストから適応するために、@strong{MySQL} はユー ザ名が形式 @code{user@@host} で指定できることをサポートします。簡単な形 式 @code{user} は @code{user@@%} の同義語です。特殊文字(@code{.} のよう な)でホスト名を指定したい場合、@code{"user"@@"hostname"} 構文を使用でき ます。 ユーザとホスト名の組が存在しない場合、エントリは @code{mysql.user} テー ブルに追加され、@code{DELETE} コマンドで削除されるまでそこに残ります。 いうならば @code{GRANT} は @code{user} テーブルの登録を作りますが、 @code{REVOKE} はそれらを削除できません; そうするには @code{DELETE} を使用しなくてはなりません。 @cindex Passwords, setting @strong{MySQL} 3.22.12 以上では、 新しいユーザーが作成された場合、あるいは、あなたがグローバルな権限を許可されている場合、 ユーザーのパスワードは @code{IDENTIFIED BY} 節を使用して設定できます。 すでにユーザーにパスワードがある場合、新しく設定されたパスワードに置き換えられます。 @strong{警告:} もし新しいユーザーを作っても @code{IDENTIFIED BY} 節を指定しなければ、 そのユーザーはノーパスワードです。 これは危険です。 パスワードは @code{SET PASSWORD} コマンドでも設定できます。 @xref{SET OPTION, , @code{SET OPTION}}. データベースに権限を @code{GRANT} する場合、@code{mysql.db} テーブル内の エントリは必要な場合に生成されます。全てのデータベース権限が @code{REVOKE} で削除された時、このエントリは削除されます。 ユーザがテーブルに何も権限を持っていない場合、テーブルの一覧要求時(例え ば、@code{SHOW TABLES} ステートメントで)には、テーブルは現れません。 @code{WITH GRANT OPTION} 節は、他のユーザーに、自分が持っている権限を与えることができます。 @strong{権限許可}を他に与える場合は注意してください。 あなたと許可を与えるユーザーが違う権限を持っている場合、 与えられる権限の許可は、二つを合わせた物になります! 自分自身が持っていない権限を他のユーザーに与えることはできません; @strong{権限許可}はあなたが所有する権限の許可だけを与えることができます。 あなたがユーザーに格別の権限レベルを与えた場合、既にユーザーが持っているいかなる権限 (あるいは 将来持つ権限) はそのユーザーによっても許可が与えられます。 あなたがデータベースに対する @strong{insert} 許可をあるユーザーに与えたと仮定します。 もし、データベースに対する @strong{select} 権限を与えたり、 @code{WITH GRANT OPTION} を行うと、ユーザーは @strong{select} 権限だけでなく @strong{insert} も得ることになります。 もし @strong{update} 権限をユーザーに与えると、そのユーザーは @strong{insert}, @strong{select}, @strong{update} が可能です。 @strong{alter} 権限を一般ユーザに与えるべきではありません。この場合 ユーザはテーブルをリネームでき、この方法で権限を回ることを試みることがで きます! 注意:もし table/column 権限を一人のユーザーにだけ与えた場合、 @strong{MySQL} は全てのユーザーに対してテーブルとフィールドの承認権限を検討します。 これは @strong{MySQL} を少し遅くします。 @code{mysqld} 開始時、全ての権限はメモリに読み込まれます。データベース、 テーブル、フィールド権限は一度効果を得ます。ユーザレベル権限はユーザ再接続時に 効果を得ます。 これらの許可テーブルを @code{GRANT} や @code{REVOKE} を使って変更しても サーバーにはすぐに反映されません。 もしこれらの許可テーブルを手動で変更した場合(@code{INSERT}, @code{UPDATE}, 等で変更した場合)、 @code{FLUSH PRIVILEGES} 構文を実行するか、@code{mysqladmin flush-privileges} を実行して サーバーに許可テーブルの再読み込みを行わせなくてはなりません。 @xref{Privilege changes}. @code{ANSI SQL GRANT} と @strong{MySQL} @code{GRANT} との大きな違いは: @itemize @bullet @item ANSI SQL はグローバルとデータベースレベル承認を持たず、ANSI SQL は @strong{MySQL} がサポートする全ての権限をサポートしません。 @item ANSI SQL でテーブルを破棄する時、そのテーブルの全ての権限は破棄さ れます。@code{ANSI SQL} で権限を取り消す場合、この権限に基づいて承認され た全ての権限も取り消されます。@code{MySQL} では、全ての権限は明示的な @code{REVOKE} コマンドまたは @strong{MySQL} 権限テーブルの操作によっての み破棄されます。 @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} 構文 @example CREATE [UNIQUE] INDEX index_name ON tbl_name (col_name[(length)],... ) @end example @code{CREATE INDEX} 構文は @strong{MySQL} 3.22 より以前のバージョンではなにもしません。 3.22 以降で、@code{CREATE INDEX} はインデックスの作成のために @code{ALTER TABLE} を呼びだしています。 @xref{ALTER TABLE, , @code{ALTER TABLE}}. 通常、テーブル内の全てのインデックスは @code{CREATE TABLE} で テーブルを作るときに一度に作成されます。 @xref{CREATE TABLE, , @code{CREATE TABLE}}. @code{CREATE INDEX} は既に存在するテーブルに対し、インデックスを追加します。 フィールドを @code{(col1,col2,...)} として指定すると、複数フィールドインデックスを作成します。 インデックスの値は、与えられたフィールドの値を連結して、構成されます。 @code{CHAR} と @code{VARCHAR} フィールドでは、インデックスはフィールドの一部分だけを使用して 作成されます。これは @code{col_name(length)} 構文を使用します。 (@code{BLOB} と @code{TEXT} 節では length が必要です)。 最初の10文字をインデックスとして使用するには、この構文は以下のようにして使用します(@code{name} フィールドにインデックスを作ります): @example mysql> CREATE INDEX part_of_name ON customer (name(10)); @end example フィールドの一部分だけをインデックスに使用すれば、インデックスファイルをはるかに小さくすることができます。 ほとんどの名前が最初の10文字において通常異なるので、 このインデックスは @code{name} フィールド全部を使用して創り出したインデックスに比べて 遅くなることはありません。また、多くのディスクスペースを節約でき、 @code{INSERT} を速くするのです! @strong{MySQL} version 3.23.2 以上で @code{MyISAM} 型のテーブルを使用している場合、 @code{NULL} 値をもつフィールドや、 @code{BLOB}/@code{TEXT} フィールドに対して インデックスを張ることが可能です。 @strong{MySQL} がどのようにしてインデックスを使用するかは →  @ref{MySQL indexes, , @strong{MySQL} indexes}. @findex DROP INDEX @node DROP INDEX, Comments, CREATE INDEX, Reference @section @code{DROP INDEX} 構文 @example DROP INDEX index_name ON tbl_name @end example @code{DROP INDEX} は @code{index_name} という名前のインデックスをテーブル @code{tbl_name} から破棄します。 @code{DROP INDEX} は @strong{MySQL} 3.22 より以前のバージョンではなにもしません。 3.22 以降で、@code{DROP INDEX} はインデックスの破棄のために @code{ALTER TABLE} を呼びだしています。 @xref{ALTER TABLE, , @code{ALTER TABLE}}. @findex Comment syntax @node Comments, CREATE FUNCTION, DROP INDEX, Reference @section コメント 構文 @strong{MySQL} は @code{# 行末まで} , @code{-- 行末まで} そして @code{/* 行中または複数行 */} コメント書式をサポートします: @example mysql> select 1+1; # このコメントは行末まで続く mysql> select 1+1; -- このコメントは行末まで続く mysql> select 1 /* これは行中コメント */ + 1; mysql> select 1+ /* これは 複数行コメント */ 1; @end example @code{--} コメントスタイルは @code{--} の後ろに最低一つのスペースが 必要であることに注意! サーバーはコメント構文を理解しますが、 @code{mysql} クライアントが @code{/* ... */} コメントを分析するにはいくつか制限があります: @itemize @bullet @item シングルクウォートとダブルクオート文字は引用文字列のトークンの開始を 示します。たとえコメントの中であっても。 もしコメントの中でクオートが二つ目のクオートにマッチしなかった場合、 パーサーはコメントが終了していないと認識します。 @code{mysql} を対話モードで実行している場合、 プロンプトが @code{mysql>} から @code{'>} か @code{">} に変わります。 @item セミコロンは SQL 構文の終了を示し、これに続く文字は次の構文の開始と なります。 @end itemize これらの制限は @code{mysql} を対話モードで実行している場合と、 @code{mysql} にファイルを読み込ませている場合 ( @code{mysql < some-file} ) の 両方で現れます。 @strong{MySQL} は ANSI SQL コメントの @samp{--} をサポートしません。 @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} 構文 @example CREATE [AGGREGATE] FUNCTION function_name RETURNS @{STRING|REAL|INTEGER@} SONAME shared_library_name DROP FUNCTION function_name @end example ユーザー定義関数 (UDF : user-definable functions) は @strong{MySQL} に新しい関数を持たせれる拡張方法です。 これは @strong{MySQL} のネイティブ(埋め込み)関数 (@code{ABS()}, @code{CONCAT()} のような)と同じように動作します。 @code{AGGREGATE} は @strong{MySQL} 3.23 の新しいオプションです。 @code{AGGREGATE} 関数は、@code{SUM} や @code{COUNT()} のようなネイティブな @strong{MySQL} @code{GROUP} 関数のように正確に動作します。 @code{CREATE FUNCTION} は、関数名、型、共有ライブラリ名を、 @code{mysql.func} システムテーブルに、保存します。 関数の作成、破棄を行うには、 @code{mysql} データベースに対して、 @strong{insert} , @code{delete} 権限がなければなりません。 全ての関数はサーバーの起動時に読み込まれます。 ただし @code{--skip-grant-tables} オプションを @code{mysqld} につけていなければ。 この場合、UDF の初期化は飛ばされ、UDF で作った関数は使用できません。 (関数は @code{CREATE FUNCTION} でロードされ、 @code{DROP FUNCTION} で削除されます) ユーザー定義関数に関するさらなる情報は → @ref{Adding functions}. UDF メカニズムで動かすためには、関数は C か C++ で書かれていなければなりません。 かつ、あなたのオペレーティングシステムがダイナミックローディングを サポートしていなければなりません。さらに @code{mysqld} はスタティックではなく ダイナミックでコンパイルされていなければなりません。 @cindex Keywords @cindex Reserved words @cindex Reserved words, exceptions @node Reserved words, , CREATE FUNCTION, Reference @section Is @strong{MySQL} picky about reserved words? 共通の問題は、フィールドの名前を、 @code{TIMESTAMP} とか @code{GROUP} とかの @strong{MySQL} に埋め込まれているデータ型や関数名と同名にして、 テーブルを作った場合に起こります。 このようなことは行えます(例えば @code{ABS} はフィールド名にできます)。 しかし、関数として使用する場合、 この名前がフィールド名として使用されているなら、 関数名と @samp{(} の間の空白は許されません。 以下の語は @strong{MySQL} に予約されています。 これらのほとんどは、 ANSI SQL92 によって、 テーブル、フィールド名としての使用は禁止されています。(例えば @code{group})。 またいくつかの語は @strong{MySQL} が必要とし、 @code{yacc} パーサーで 使用しているので予約されています。 @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 以下は ANSI SQL ではフィールド、テーブル名としての使用を禁止されていますが、 @strong{MySQL} では許可されています。 これは、これらの名前は凄く自然な名前で、多くの人がこれらを既に名前として 使用しているからです。 @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 With MySQL you can currently (version 3.23.6) 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}. @code{ALTER TABLE} 文を使用すれば、テーブルを違う形式に変更できます。 @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:: @end menu @node MyISAM, ISAM, Table types, Table types @section MyISAM tables @code{MyISAM} は、@strong{MySQL} 3.23 でのデフォルトのテーブル形式です. これは @code{ISAM} コードを基にし、多くの便利な拡張機能を持っています。 インデックスは @code{.MYI} (MYindex) 拡張子のつくファイルに保存され、 データは、 @code{.MYD} (MYData) 拡張子のつくファイルに保存されます。 @code{myisamchk} ユーティリティを使用して、 @code{MyISAM} テーブルの 検査・修復が可能です。 @xref{Crash recovery}. The following is new in @code{MyISAM}: @itemize @bullet @item あるスレッドが読み込み中のテーブルに対し、違うスレッドが 同じテーブルに、新しい行を @code{INSERT} できます。 削除はなしで You can @code{INSERT} new rows in a table without deleted rows, while other threads are reading from the table. @item 大ファイル (63 bit) のサポート。 ただし、filesystems/operating systems が巨大ファイルをサポートしている場合。 @item 全データは、下位バイトが先にかかれます。 これは、データを、マシン・OS 非依存にしました。 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 全数値キーは高位バイトが先に書かれます。 これはインデックスの圧縮率を 良くします。 @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} と @code{TEXT} フィールドにインデックスが張れます @item @code{NULL} 値をインデックスの張られたフィールドに許します. This takes 0-1 bytes/key. @item 現在、キーの最大長はデフォルトで 500 です。 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} は @code{BLOB} と @code{VARCHAR} フィールドをパックすることが可能です。 @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 @menu * Key space:: Space needed for keys * 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. このフォーマットは、最も単純、かつ、安全なフォーマットです。 これは, Disk 上に作られるテーブルの中で、最も速いフォーマットでもあります。 これはディスク上のデータを見つけやすいからです。 When looking up something with an index and static format it is very simple, just multiply the row number with the row length. Also when scanning a table it is very easy to read a constant number of records with each disk read. 安全、というのは、次の様なことです。 もし仮に、静的(固定長) MyISAM ファイルに書き込み中に、 あなたのコンピュータがクラッシュした場合、 @code{myisamchk} は、それぞれのレコードの開始点と終了点を安易に見つけることが出 来ます。 So it can usually reclaim all records except the partially written one. MySQL では、常に、全てのインデックスが再構築できることに注意してください。 @itemize @bullet @item 全ての @code{CHAR}, @code{NUMERIC}, @code{DECIMAL} フィールドは、そのフィールド 長に足りない部分にはスペースが埋められます。 @item とても速い @item キャッシュしやすい。 @item クラッシュの後再構築しやすい。なぜならレコードが固定された位置に割り当てられてい るから。 @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 通常、動的テーブルよりも多くのディスク容量が必要。 @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}. この形式は少し複雑です。 なぜならそれぞれのレコードが、レコードがどのぐらいの 長さを持っているかを記録するヘッダーを持っているからです。 One record can also end up at more than one location when it is made longer at an update. @code{OPTIMIZE table} か @code{myisamchk} を使用して、テーブルの フラグメンテーションを修正することが可能です。 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 全ての文字フィールドが動的になります(ただし4byteより短い物は除きます) @item それぞれのレコードの先頭には、フィールドの状態を表すビット・マップがきます。 このビットは、どの文字型フィールドが空文字(@code{''})なのか、 どの数値フィールドがゼロなのかを示します。 (これはフィールドの値が @code{NULL} 値とは違います)。 もし、文字型フィールドの文字列の長さ(後に続く空白は取り除かれる)が ゼロ で あったり、あるいは、数値フィールドの値が ゼロ であった場合は、 そのフィールドはビット・マップにマークされ、値はディスクには保存されません。 空文字ではない場合は、文字列のバイト数がビット・マップに記録され、 文字列自身がフィールドに保存されます。 @item 通常、固定長のテーブルよりも少ないディスク容量ですみます @item それぞれのレコードは、要求されただけのスペースを使用します。 もしあるレコードが大きくなると、要求された分、それを多くの断片に分けます。 この結果、レコードのフラグメンテーションが発生します。 @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 期待されるレコードの長さは: @example 3 + (フィールド数 + 7) / 8 + (char フィールドの数) + 数値フィールドをパックしたサイズ + 文字の長さ + (NULL フィールドの数 + 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 これは読み込み専用の型で、オプションツールの @code{myisampack} で作成されます。 (@code{pack_isam} for @code{ISAM} tables). @code{myisampack} and @code{pack_isam} are available to all customers that have bought a @strong{MySQL} license or @code{MySQL} support for their internal use. @itemize @bullet @item The uncompress code exists in all @strong{MySQL} distributions so that even customers who don't have @code{myisampack} 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 as temporary tables! @strong{MySQL} 内部 HEAP テーブルは、100% ダイナッミック・ハッシングを 使用しておいます(オーバーフローエリア無しに)。 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.11 or newer which can be downloaded from @uref{http://www.mysql.com/download_3.23.html}; or also from Sleepycat's download page at @uref{http://www.sleepycat.com/download.html}. 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. 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 チュートリアル @menu * Connecting-disconnecting:: Connecting to and disconnecting from the server * Entering queries:: Entering queries * Examples:: Examples * 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 この章では、 @code{mysql} クライアントプログラムの使用の仕方と 単純なデータベースの作成と使用の仕方を例題としてとり上げます。 @code{mysql} (``terminal monitor'' や ``monitor'' として参照されます)は @strong{MySQL} サーバーに接続できる対話モードのプログラムで、 クエリの実行や結果の表示が可能です。 @code{mysql} はバッチモードも可能です: クエリをまずファイルに書いておき、 そしてそのファイルを @code{mysql} に実行させます。 どちらの方法でも @code{mysql} はこの章の説明でカバーされます。 @code{mysql} の提供するオプションを見るには、 @code{--help} オプションを 実行します: @example shell> mysql --help @end example この章では @code{mysql} が既にあなたのマシンにインストールされているものとし、 また @strong{MySQL} サーバーに接続可能であるとします。 もしそうでないなら、 あなたの @strong{MySQL} 管理者に連絡を取ってください。 (もし@emph{あなた自身が}管理者なら、このマニュアルの他のセクションを参照してください。) 本章ではデータベース設定の全体のプロセス、データベースの使用について述べます。 もしあなたが既に存在しているデータベースにアクセスする事だけに興味があるなら、 この章のデータベース、テーブルの作成方法の説明を読み飛ばしてもかまいません。 この章が本質的にはチュートリアルであるので、多くの詳細は、かならず違う章にあります。 ここに書かれている事柄で、 さらに詳しい情報についてはマニュアルの適切なセクションを調べて下さい。 @node Connecting-disconnecting, Entering queries, Tutorial, Tutorial @section サーバーへの接続と切断 サーバーに @code{mysql} コマンドから接続するためには、通常、 @strong{MySQL} ユーザ名、パスワードを指定する必要があるでしょう。 もしあなたがログインしている以外のマシンの上でサーバーが走っていれば、 あなたは、ホスト名を明示する必要があるでしょう。 まずあなたの管理者に問い合わせて、あなたが使うべき接続のためのパラメーターを見つけ出して下さい。 (すなわち、どのようなホスト、ユーザー名とパスワードを使うべきなのか。) 適切なパラメーターを知っていれば、あなたは、以下のようにして接続できます: @example shell> mysql -h host -u user -p Enter password: ******** @end example @code{********} とかかれている部分にはあなたのパスワードを入れます; @code{mysql} が @code{Enter password:} プロンプトを出したときに。 きちんと動けば、いくつかの情報と @code{mysql>} プロンプトが現れます: @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 このプロンプトは @code{mysql} がコマンド入力を待っている状態を示します。 いくつかの @strong{MySQL} インストレーションでは、ローカルホストで 実行されているサーバーに、ユーザーに``匿名''(名前無し)の接続を許しています。 もしあなたのマシンがこの場合に当てはまるなら、@code{mysql} をオプション無しで 起動すべきです: @example shell> mysql @end example 接続が成功した後、 @code{mysql>} プロンプトで、@code{QUIT} とタイプすれば いつでも接続を切ることができます: @example mysql> QUIT Bye @end example control-D で切断してもかまいません。 以下のセクションでのほとんどの例では、あなたがサーバーに接続しているものと しています。その場合は @code{mysql>} プロンプトによって、それを示しています。 @node Entering queries, Examples, Connecting-disconnecting, Tutorial @section クエリの入力 前のセクションで述べたように、あなたがサーバーとつながっていることを確かめて下さい。 この状態ではまだどんなデータベースも選択していない状態です。しかしそれはかまいません。 ここでは、テーブルの作成やデータの入力、取り出しよりも、 いかにクエリを発行するかに重点を置きます。 このセクションでは、あなた自身を @code{mysql} の動きに慣れさせるために、 あなたがやってみることができるであろう、いくつかのクエリを使用して、 コマンド入力の基本的な原則を述べます。 サーバーのバージョン、今日の日付をサーバーに問い合わせる、単純なコマンド がここにあります。 以下のように @code{mysql>} プロンプトの後に入力し RETURN キーを押してみてください: @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 このクエリは、@code{mysql} のいくつかの事を説明しています: @itemize @bullet @item 通常、コマンドは、セミコロンで終わる SQL ステートメントから、構成されます。 (セミコロンが必要とされないいくつかの例外があります。 以前に述べた @code{QUIT} はそのうちの一つです。後で他も出てきます。) @item コマンドを発行すると、@code{mysql} はそれをサーバーに送り、結果を表示します。 その後、 @code{mysql>} プロンプトを出し、他のコマンドが受け付けれる状態であると 示します。 @item @code{mysql} はクエリの結果を表にして出します。 最初の行は項目のラベル名です。 その下の行に、クエリの結果が続きます。 通常、項目のラベル名はデータベースのテーブルから あなたが取り出したフィールド名になります。 テーブルのフィールド名以外の式を あなたが検索したのなら(ちょうど例のように)、@code{mysql} は与えられた式自身を 項目のラベル名として表示します。 @item @code{mysql} は何レコード(rows)返ってきたかを示し、実行にどれくらいの時間が かかったかも示します。 これはおおざっぱなサーバーのパフォーマンスを示します。 これらの値は wall clock time (CPU や マシンタイムではなく) を使用しており、さらに、 サーバーの負荷、およびネットワーク待ち時間といった要因にも影響されるので、 不正確です。 (この章の他の例題においては ``rows in set'' の行は省きます。) @end itemize キーワードは、いかなる大文字小文字でも記述できます。 以下に示すクエリは同じです: @example mysql> SELECT VERSION(), CURRENT_DATE; mysql> select version(), current_date; mysql> SeLeCt vErSiOn(), current_DATE; @end example 以下のクエリは、@code{mysql} を簡単な計算機として使用した例です: @example mysql> SELECT SIN(PI()/4), (4+1)*5; +-------------+---------+ | SIN(PI()/4) | (4+1)*5 | +-------------+---------+ | 0.707107 | 25 | +-------------+---------+ @end example 今までは見てきたたコマンドは、比較的短い、一行のの文です。 あなたは一行に複数、文を書くことが出来ます。 それぞれの文の終わりにはセミコロンを付けます: @example mysql> SELECT VERSION(); SELECT NOW(); +--------------+ | version() | +--------------+ | 3.22.20a-log | +--------------+ +---------------------+ | NOW() | +---------------------+ | 1999-03-19 00:15:33 | +---------------------+ @end example コマンドは一行にかく必要もありません。 複数行にわたる長いコマンドでも問題ありません。 @code{mysql} はセミコロンで、一文の終わりと見なします。 その行の最後を文の最後とは 見なしません。 (いうなれば、@code{mysql} は自由な入力を許し、セミコロンが現れるまでは それらの入力された行を実行しません) 複数行にまたがった文の例です: @example mysql> SELECT -> USER() -> , -> CURRENT_DATE; +--------------------+--------------+ | USER() | CURRENT_DATE | +--------------------+--------------+ | joesmith@@localhost | 1999-03-18 | +--------------------+--------------+ @end example この例では、複数にまたがるクエリにおいて、最初の行の入力のあと、 いかにプロンプトが @code{mysql>} から @code{->} に変わるかを示しています。 これは @code{mysql} が、まだ文が終わっておらず、残りの部分の入力を待っている ことを示します。 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. 入力中にコマンドの実行を取りやめようと思った場合、 @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. 以下の表に、 @code{mysql} のプロンプトとその状態の説明を示します: @multitable @columnfractions .10 .9 @item @strong{プロンプト} @tab @strong{意味} @item @code{mysql>} @tab 新しいコマンドの待状態 @item @code{@ @ @ @ ->} @tab 複数行にまたがるコマンドの、次の行の入力を待っている状態。 @item @code{@ @ @ @ '>} @tab シングルクオート (@samp{'}) で始められた文字の、次の行の入力を待っている状態。 @item @code{@ @ @ @ ">} @tab ダブルクオート (@samp{"}) で始められた文字の、次の行の入力を待っている状態。 @end multitable あなたが文をセミコロンで終わらすことを忘れて実行した場合に、 複数行の入力待ちが起こります。 この場合、 @code{mysql} は 次の入力を待ちます: @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:: * example-Maximum-row:: * example-Maximum-column-group:: * example-Maximum-column-group-row:: * example-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> 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 日付の計算 @strong{MySQL} はいくつかの日付の計算を行う関数を提供します。 例えば、年の計算や日付の部分を取り出したり。 ペットの年齢が何才なのかを知るためには、現在の日付と誕生日との差を計算 します。 このためには、二つの日付を日数に直し、差を取り、そして 365 (年の日数) で割ります: @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 クエリは動きましたが、改良したいくつかのことがあります。 第1に、この結果は、もしレコードにいくつかの順番を与えれば、簡単に並び換えが 出来そうなこと。 第2に、年齢欄の見出しは、このままではなんなのか分かりません。 最初の問題は @code{ORDER BY name} 節を加えることで name 順で並び換えが出来ます。 二つ目の問題に対しては、違う見出しを出力に現れるように、欄の見出しを 扱います (これを フィールドのエイリアス と呼びます) : @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 @code{name} ではなく @code{age} で並び換えるには、 @code{ORDER BY} 節を 以下のように変えます: @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 似たクエリが、既に死んでしまった動物の、死んだ時点の年齢を調べるのにも 使用できます。 どの動物が死んでいるかどうかは、@code{death} 値が @code{NULL} か どうかで判断します。 これらの値が 非@code{NULL} ならば、 @code{death} と @code{birth} の差の計算を行います: @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 このクエリでは、 @code{death != NULL} ではなく @code{death IS NOT NULL} を 使用します。 なぜなら、 @code{NULL} は特別な値だからです。 これは後で解説します。 @xref{Working with NULL, , Working with @code{NULL}}. もしあなたが翌月誕生日の動物を知りたいとします。 この種の計算では、 年と日が関係ありません。 @code{birth} フィールドの月だけを単に 取り出したくなるでしょう。 @strong{MySQL} は日付の部分を取り出すいくつかの関数を 提供します。 @code{YEAR()}, @code{MONTH()}, @code{DAYOFMONTH()} など。 ここでは @code{MONTH()} がいいでしょう。 これがどのように動くか確かめるには、 @code{birth} と @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 来月誕生日を迎える動物を見つけるのは簡単です。 現在4月だとします。 すると、5月生まれの動物を探します: @example mysql> SELECT name, birth FROM pet WHERE MONTH(birth) = 5; +-------+------------+ | name | birth | +-------+------------+ | Buffy | 1989-05-13 | +-------+------------+ @end example もし現在が12月なら、ちょっと困るかもしれません。 月の数字 (@code{12}) に 1 を足して 13 月生まれの動物を探すわけにはいきません。 かわりに1月生まれの 動物を探します。 現在が何月なのかを気にすることなく、動作するクエリを書くことが可能です。 この方法では、あなたは月の数字をクエリに使用することがありません。 @code{DATE_ADD()} 関数は与えた日付からある時間を足すことが可能です。 もし現時点 @code{NOW()} の値に 1ヶ月 足し、 @code{MONTH()} で月の 部分を取り出し、その結果を、誕生月を調べるために使用します: @example mysql> SELECT name, birth FROM pet -> WHERE MONTH(birth) = MONTH(DATE_ADD(NOW(), INTERVAL 1 MONTH)); @end example 同じことができる別の方法として、剰余関数 を使用した結果に 1 を足す方法があります。 (もし今月が12月なら、剰余関数 (@code{MOD}) を使用した結果は @code{0} になります): @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 @code{NULL} 値の振る舞い あなたがそれに慣れるまでは、@code{NULL} 値には驚くかもしれません。 概念的に、@code{NULL} 値は ``値無し'' か ``未知な値'' を意味し、 他の値よりもいくぶん異なって扱われます。 @code{NULL} の評価の際には、数値の比較演算子 @code{=}, @code{<}, @code{!=} を 使用することは出来ません。 あなた自身これをデモするために、以下のようにしてみてください: @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 確実にこれらの比較からいかなる意味がある結果も受け取りません。 この代わりに、 @code{IS NULL} , @code{IS NOT NULL} 演算子を使用します: @example mysql> SELECT 1 IS NULL, 1 IS NOT NULL; +-----------+---------------+ | 1 IS NULL | 1 IS NOT NULL | +-----------+---------------+ | 0 | 1 | +-----------+---------------+ @end example @strong{MySQL} では, 0 は false(偽) で、1 が true(真)です。 この @code{NULL} の特別な扱いはなぜなのか。 前のセクションを見てください。 どの動物がもはや生きていないことを決定づけるためには、 @code{death != NULL} ではなく @code{death IS NOT NULL} の使用が 必要とされるのです。 @node Pattern matching, Counting rows, Working with NULL, Retrieving data @subsubsection パターン・マッチ @strong{MySQL} は標準SQLのパターン・マッチを提供します。 また、拡張された正規表現を基にした形式のパターン・マッチ、 これは @code{vi}, @code{grep} and @code{sed} など UNIX のユーティリティに 使用されている物と似ていますが、これも提供します。 SQL パターン・マッチは、 @samp{_} でいかなる1文字とも一致し、 @samp{%} であらゆる0こ以上の文字列に一致します。 @strong{MySQL} では、デフォルトで SQL パターンはケース非依存です。 いくつか例を以下に示します。 SQLパターンを使用する場合、 @code{=} や @code{!=} を使用しないように注意してください。 @code{LIKE} か @code{NOT LIKE} を代わりに使用します。 @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 @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 @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 5文字の名前を見つけるには, @samp{_} パターン文字を使用して: @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 @strong{MySQL} では他のパターン・マッチの形も提供されます。正規表現の拡張を使用して。 これらのパターン・マッチをテストする際には、@code{REGEXP} と @code{NOT REGEXP} 演算子(あるいは@code{RLIKE}, @code{NOT RLIKE} 演算子。これらは同義です) を使用します。 拡張正規表現のいくつかの特徴: @itemize @bullet @item @samp{.} はいかなる一文字とも一致します。 @item @samp{[...]} は、かっこ内にある文字と一致します。 例えば、@samp{[abc]} は @samp{a}, @samp{b} あるいは @samp{c} にマッチします。 文字を範囲指定する場合にはダッシュを使用します。 @samp{[a-z]} はいかなる 小文字のアルファベット文字にも一致し、 @samp{[0-9]} はいかなる数字にも 一致します。 @item @samp{*} は、先に指定されている文字 0 個以上にマッチします。 例えば、@samp{x*} は 文字 @samp{x} がいくつも連続している物にマッチし、 @samp{[0-9]*} はいかなる数値ともマッチし、 @samp{.*} はあらゆる文字列に 一致します。 @item 正規表現はケース依存です。 しかし大文字小文字どちらでもマッチさせたい場合、 文字クラスを使用できます。 例えば、 @samp{[aA]} は大文字小文字の @samp{a} に マッチし、@samp{[a-zA-Z]} は大文字小文字のいかなるアルファベット文字にもマッチします。 @item パターンは、テストされた値の中のどこかにある場合、マッチします。 (SQL patterns match only if they match the entire value). @item 値のはじめ、あるいは終わりに位置を指定してマッチさせたい場合は、 パターンの初めにマッチさせる場合は @samp{^} を使用し、 パターンの終わりにマッチさせる場合は @samp{$} を使用します。 (これらはアンカーと呼ばれます) @end itemize 以下は拡張された正規表現がどう動くかの例です。 上に示した @code{LIKE} のクエリは @code{REGEXP} で以下のように書き換えれます: @samp{b} で始まる名前をみつけるには、@samp{^} で名前の頭にマッチさせ、 かつ @samp{[bB]} として、大文字小文字にもマッチさせます: @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 @samp{fy} で終わる名前を見つけるには、 @samp{$} を使用して名前の 最後にマッチさせます: @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 @samp{w} を含む名前を見つけるには、@samp{[wW]} を使用して 大文字小文字にマッチさせます: @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 正規表現はもし値中のどこかにでもあればマッチするため、 SQL パターンのように、パターンの前後にワイルドカードを書く必要はありません。 5文字の名前を見つけるには、@samp{^} と @samp{$} を使用して名前の初めと終わりに マッチさせ、その間に @samp{.} を5個入れます: @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 前のクエリは @samp{@{n@}} ``@code{n}回繰り返し'' オペレーターで 書換え可能です。 @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 データベースとテーブルの情報を得る データベースやテーブルの名前が何であったか、あるいはテーブルの構造はどうであったか、 (なんというフィールドがあったのか)忘れてしまった場合。 @strong{MySQL} ではいくつかのデータベースとテーブルの情報を提供する文を通じて この問題を処理します。 あなたは既に @code{SHOW DATABASES} を知っているはずで, これはサーバーが 管理するデーターベースの一覧を表示します。 現在選択しているデータベースが 何であるかを知るには、@code{DATABASE()} 関数を使用します: @example mysql> SELECT DATABASE(); +------------+ | DATABASE() | +------------+ | menagerie | +------------+ @end example もしデータベースをまだ何も選択していなければ、結果はブランクです。 データベースに含まれるテーブルを見つけるには(たとえば、あなたがテーブル名を 知らない場合)、このコマンドを使用します: @example mysql> SHOW TABLES; +---------------------+ | Tables in menagerie | +---------------------+ | event | | pet | +---------------------+ @end example もしテーブルの構造を知りたいなら、@code{DESCRIBE} コマンドが便利です; これはテーブルのそれぞれのフィールドについての情報を表示します。 @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} はフィールド名を示し、@code{Type} はフィールドのデータ型、 @code{Null} はこのフィールドが @code{Null} 値を含むかを示し、 @code{Key} はこのフィールドがインデックス化されているかを示し、 @code{Default} はフィールドのデフォルトの値を示します。 もしテーブルにインデックスを持っているなら、 @code{SHOW INDEX FROM tbl_name} がそれらの情報を示します。 @node Batch mode, Twin, Getting information, Tutorial @section @code{mysql} のバッチモードでの使用 前のセクションでは、@code{mysql} を対話モードで使用し、クエリの入力と 結果を表示しました。 @code{mysql} はバッチモードでも実行可能です。 これを行うには、あなたが実行したいコマンドをファイルに書いておき、 そのファイルから入力を読み込むようにして @code{mysql} を実行します: @example shell> mysql < batch-file @end example もし接続パラメターを指定する必要がある場合は、以下のようになるでしょう: @example shell> mysql -h host -u user -p < batch-file Enter password: ******** @end example この方法で @code{mysql} を使用するとき、あなたはスクリプトファイルを 作成し、それを実行することになるでしょう。 なぜスクリプトを使用するのか? それには以下の理由があります: @itemize @bullet @item もし繰り返しクエリを実行する場合(毎日とか毎週とか)、スクリプトを書くことで、 その実行の度にあなたがコマンドをタイプすることを省くことが可能です。 @item もし既にあるクエリに似た新しいクエリを書く場合、それらをコピーし スクリプトファイルを編集できます。 @item バッチモードはクエリの開発中や複数にまたがるコマンドには役に立ちます。 もしコマンドが間違っていたとしても全てを打ち直す必要がありません。 エラーを修正するためにスクリプトを編集し、再び @code{mysql} に実行させます。 @item もし多くの出力を出すようなクエリの場合、ページャーを使用して出力を見ることが 出来ます。 出力がスクロールして画面から見えなくなるよりいいでしょう: @example shell> mysql < batch-file | more @end example @item あなたはより処理を行うために、結果をファイルに書き出すことが可能です: @example shell> mysql < batch-file > mysql.out @end example @item あなたは、他人へのあなたのスクリプトを配布することができます。これにより、ほかの人たちも コマンドを実行することができます。 @item いくつかの状況では、対話モードでは使用に耐えません。 たとえば、クエリを @code{cron} ジョブとして実行する場合。 この場合、バッチモードでなければなりません。 @item 端末が正しく扱えない文字を @code{mysql} コマンドに渡す場合。 たとえば、EUC-JP, Shift_JIS の漢字文字などは、端末や環境によっては直接入力できない場合もあるでしょう。 @end itemize @code{mysql} をバッチモードで使用するか、対話モードで使用するかで、 デフォルトの出力形式が変わります。 例えば、 @code{SELECT DISTINCT species FROM pet} の 出力は対話モードでは次のようになります: @example +---------+ | species | +---------+ | bird | | cat | | dog | | hamster | | snake | +---------+ @end example しかし、バッチモードでは: @example species bird cat dog hamster snake @end example もしバッチモードでも対話モードのような出力を得たい場合には、@code{mysql -t} とします。 出力中に、実行したコマンドを表示させるならば、@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 @strong{MySQL} サーバーファンクション @menu * Languages:: @strong{MySQL} がサポートしている言語は? * Table size:: @strong{MySQL} はテーブルをどれくらい大きくできるか? @end menu @cindex Which languages @strong{MySQL} supports @cindex Language support @node Languages, Table size, Server, Server @section @strong{MySQL} がサポートしている言語は? @code{mysqld} は次の言語でエラーメッセージを提供できます: チェコ語, オラ ンダ語, 英語(デフォルト), Estonia, フランス語, ドイツ語, ノルウェー語, 新ノルウェー 語,ポーランド語, ポルトガル語, スペイン語そしてスウェーデン語。 ある言語で @code{mysqld} を開始するためには @code{--language=lang} また は @code{-L lang} スイッチの一つを使います: @example shell> mysqld --language=swedish @end example or: @example shell> mysqld --language=/usr/local/share/swedish @end example 言語名は全て小文字であることに注意してください。 言語ファイルは(デフォルトでは)次の場所にあります。 @file{@var{mysql_base_dir}/share/@var{LANGUAGE}/}. エラーメッセージファイルを更新したい場合は、 @file{errmsg.txt} ファイルを編集し、 @file{errmsg.sys} ファイルを作成するために以下のように実行します: @example shell> comp_err errmsg.txt errmsg.sys @end example もし @strong{MySQL} を新しいものにアップグレードしたなら、以前修正した部分と同じところに、 新しい @file{errmsg.txt} ファイルに修正をほどこしてください。 @menu * Character sets:: データとソートに使用されるキャラクターセット * Adding 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 データとソートに使用されるキャラクターセット デフォルトでは、@strong{MySQL} は ISO8859-1 (Latin1) キャラクターセットを使用し ます。これは USA と西ヨーロッパで使用されるキャラクターセットです。 キャラクターセットは名前として許される文字と、@code{ORDER BY} と @code{GROUP BY} コマンドによってソートされる方法を決定します。 キャラクターセットは、名前として使用してもよい文字と @code{SELECT} 構文中の @code{ORDER BY} と @code{GROUP BY} コマンドを用いたソート方法を決定します。 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 新しいキャラクターセットの追加 @enumerate @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} ファイルを @strong{MySQL} のソースディレクトリ以下に作成します。 @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 必要な定義されるものを調べるために、既存の @file{ctype-*.c} ファイルの一つを見てく ださい。このファイル中で使用する配列の名前は、 @code{ctype_MYSET}, @code{to_lower_MYSET} のようにしなければいけないことに注意してください。 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[]} と @code{to_upper[]} は、それぞれのキャラクターセットに於ける 大文字、小文字の対応を定義した、単純な配列です。 例えば: @example to_lower['A'] should contain 'a' to_upper['a'] should contain 'A' @end example @code{sort_order[]} は文字がどのようにソートされるべきかのマップです。多くのセッ トでは、これは @code{to_upper[]} と同じです (ケース非依存ソート)。 @strong{MySQL} は @code{sort_order[character]} の値を元に文字をソートします。 For more complicated sorting rules, see the discussion of string collating below. @code{ctype[]} は各文字を説明するビットの配列で、1かたまりのビット列が1文字を定義します。 ( @code{to_lower[]}, @code{to_upper[]},@code{sort_order[]}は、文字の値でインデックスされますが、 @code{ctype[]}は文字の値+1 でインデックスされます。 これは EOF を操作するためにずいぶん前から使われているので、この方法を使用しています。) @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 それぞれの文字に対する @code{ctype[]} は、文字を確定するために ビット列と組になっていなければなりません。 たとえば、@code{'A'} は大文字定義 (@code{_U}) と 16進定義 (@code{_X}) 両方ともに 属するので、@code{ctype['A'+1]} は以下の値を含まなくてはなりません: @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 @code{CHARSETS_AVAILABLE} リストと @code{configure.in} の中の @code{COMPILED_CHARSETS} リスト にキャラクターセット名を追加します。 @item configureとコンパイルをしなおし、テストしてください。 @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 マルチバイト文字のサポート 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 @strong{MySQL} はテーブルをどれくらい大きくできるか? @strong{MySQL} 3.22 のテーブルサイズの制限は 4G です。 @strong{MySQL} 3.23 の新しい @code{MyISAM} では、最大のテーブルサイズは 800万テラバイト (2 ^ 63 bytes) です. しかし、それとは別に OS 自身のファイルサイズの制限があります。 例えばいくつかの OS では以下のようになっています: @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 これは、通常、@strong{MySQL} のテーブルサイズは オペーレーティングシステムによって制限されるということです。 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 もし大きなテーブルをリードオンリーで使用するなら、@code{myisampack}を使って複数のテーブルを結合したうえで圧縮することができます。@code{myisampack}は少なくとも 50% テーブルを圧縮することができ、その結果、大きなテーブルを使用することができます。 @xref{myisampack, , @code{myisampack}}. 他の方法として、"同じような"テーブルを一つにできる MERGE ライブラリーを含む方法があります。 ("同じような" とは、同じ項目情報をもって全てのテーブルが作られている状態をさします) MERGE はインデックスをサポートしていないため、同種のテーブルしか走査できません。 これにインデックスの機能を近い将来追加する予定です。 @cindex Replication @node Replication, Performance, Server, Top @chapter Replication in MySQL @menu * Replication Intro:: Introduction * Replication Implementation:: * Replication HOWTO:: HOWTO * Replication Features:: Replication Features. Replication Features. Replication Features. Replication Features. Replication Features. Replication Features. 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. @item Set up special replication user(s) on the master with the @code{FILE} privilege and permission to connect from all the slaves @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= master-user= master-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 :-) . @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 sp cify 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-ignore-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- o-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 @end multitable @cindex Performance @cindex Optimization @node Performance, MySQL Benchmarks, Replication, Top @chapter 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 最適化 概要 システムを速くするための最も重要な部分は、もちろん基礎的な設計です。 You also need to know what kinds of things your system will be doing, and what your bottlenecks are. 主なボトルネックは: @itemize @bullet @item Disk シーク : 一片のデータを見つけるためには、ディスクに時間がかかります。 1999年の最新型のディスクでは、このための平均時間は、10msよりも通常より小さいです。 したがって、我々は、理論上は 1秒で約1000 シークすることができます。 この時間は、一つのテーブルであるならば、データの増加と共にディスクアクセスの時間が 少しずつ増加することになり、とても最適化するのは難しくなっていきます。 これを最適化する方法は、データを 1個以上のディスクに分散する事です。 @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 : データをメイン・メモリーの中に入れた(または既にメモリに存在している)場合に、 結果を得るためには、それを処理する必要があります。 メモリー容量よりも小さなテーブルを持っている場合、これは、制限の要因となります。 小さいテーブルでは、スピードは、通常問題にはなりません。 @item Memory bandwidth : CPU がキャッシュに収まらないようなデータを要求した場合、メイン・メモリー のバンド幅はボトルネックになります。 これはほとんどのシステムで分かりにくいボトルネックとなりますが、 誰かはそれを知っているべきです。 @end itemize @node System, Data size, Optimize Basics, Performance @section システム、コンパイル時、スタートパラメターのチューニング 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. 使うべき OS はとても重要です! 複数の CPU を持つマシンでは、 Solaris (なぜなら、Solaris のスレッドはとても素晴らしく動作するから)、 あるいは、Linux ( kernel 2.2 は良い SMP をサポートしているから) を 使用すべきです。 32bit マシンの Linux では、2G bytes のファイルサイズの 制限があります。 これは新しいファイルシステム (XFS) のリリース時に なくなって欲しいものです。 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 充分 RAM があるならば、全ての swap を外してもよいでしょう。 いくつかのシステムでは、たとえメモリーが空いていても、 swap を使用する場合があります。 @item 外部のロックを避けるため、@code{--skip-locking} @strong{MySQL} オプション を使用します。 Note that this will not impact @strong{MySQL}'s functionality as long as you only run one server. @code{myisamchk} を実行する前に、サーバーを止めることを忘れないでください。 On some system this switch is mandatory because the external locking does not work in any case. MIT スレッドでコンパイルする時は @code{--skip-locking} がデフォルトです。 これは全てのプラットフォームで MIT スレッドが @code{flock()} を完全にサポートし ていないためです。 @code{--skip-locking} が使用できないただ一つの状態は、 もしあなたが複数の @strong{MySQL} @emph{サーバー} (クライアントではない) を 同じデータに対して走らせている場合です。 Or run @code{myisamchk} on the table without first flushing and locking the @code{mysqld} server tables first. たとえ @code{--skip-locking} を使用していても、 @code{LOCK TABLES} / @code{UNLOCK TABLES} の使用は可能です。 @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 MySQL の速度に影響するコンパイルとリンク方法 次のテストの多くは Linux 上で @strong{MySQL} ベンチマークで行われました。 しかし、これらは他の OS についてもいくつかの指標を与えます。 @code{-static} でのリンク時に最速の実行形式を得ます。 TCP/IP の代わりに Unix ソケットをデータベースへの 接続に使用することも、より良い性能を与えます。 Linux では、@code{pgcc} と @code{-O6} でコンパイルした時に最速のコードを得られます。 このオプションで @file{sql_yacc.cc} をコンパイルすると、@code{gcc/pgcc} は 全ての関数をインラインにするために多くのメモリを必要とするので、200M のメモリが必要です。 @code{libstdc++} ライブラリの増加を避けるためには、 @strong{MySQL} の configure 時に @code{CXX=gcc} も設定すべきです。 より良いコンパイラー、そしてコンパイラーのオプションは、10-30% の 速度の向上をもたらします。 これはあなた自身が MySQL をコンパイルする 時に重要なことです! Intel では、例えば pgcc か Cygnus CodeFusion compiler で最速となります。 我々は 新しい Fujitsu コンパイラーでもテストしましたが、 @strong{MySQL} を最適化オプションでコンパイルするには、 まだ完全なバグ・フリーではありませんでした。 Here is a list of some mesurements that we have done: @itemize @bullet @item @code{pgcc} を使用して @code{-O6} で全てをコンパイルすると、 @code{gcc} 2.95.2 より古いバージョンでは、 @code{mysqld} サーバーは 11% 速くなります。 @item 動的リンク(@code{-static}) 無し)の場合、結果は 13% 遅くなります。 Note that you still can use a dynamic linked MySQL library. It is only the server that is critical for performance. @item (localhost への接続に) Unix ソケットの代わりに TCP/IP を使用すると、結果は 7.5% 遅くなります。 @item SPARCstation 10 では、@code{gcc} 2.7.3 は Sun Pro C++ 4.2 より 13% 速くなります。 @item シングルプロセッサの Solaris 2.5.1 では、mit-pthreads は Solaris ネイティブスレッドより 8-12% 遅くなります。 With more load/CPUs the difference should get bigger. @end itemize TCX により配布されている @strong{MySQL}-Linux 配布は @code{pgcc} でコンパイルされて いますが、 but we had to go back to regular gcc because of a bug in 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 pgcc. The Linux binary is linked statically. @node Disk issues, Server parameters, Compile and link options, System @subsection Disk の問題 @itemize @bullet @item 前に述べたディスクシークが大きなボトルネックです。 この問題は、データが効果的に キャッシングが不可能になるほど、大きくなり始めるときに、だんだん明白になってきます。 For large databases, where you access data more or less randomly, you can count on that you will need at least one disk seek to read and a couple of disk seeks to write things. この問題を少なくするには、diskシーク時間の少ないディスクを 使用します。 @item 利用できるディスクスピンドルの数を増やします(それによってディスクシーク のオーバーヘッドは縮小します)。 これは違うディスクにシンボリックリンクをはったり、ストライプを行うことで 可能です。 @table @strong @item symbolic link の使用 これは通常のデータディレクトリから、違うディスクへ、 インデックスやデータファイルをシンボリック・リンクすることです。 これは シーク と リード を速くします。 (もしそのディスクが 他に使用されていなければ). @xref{Symbolic links}. @item Striping ストライピングは、複数のディスクに対して、まずデータの最初のブロックを 1番目の disk に書き、2番目のブロックを2つ目のdiskに書き、順次 N 番目 (N は disk の数) まで順に書いていきます。 これは、もしデータがストライプの サイズよりも小さければ、よりよいパフォーマンスを得ることが出来ます。 ストライピングは、OS や ストライプのサイズにとても依存していることに注意してください。 そのため、あなたのアプリケーションのベンチマークがストライプサイズによって 変わるでしょう。 @xref{Benchmarks}. ストライピングのスピードの違いは、@strong{とても} パラメターに依存しています。 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 信頼性のため、あなたは RAID 0+1 (striping + mirroring) を使用したいと 思うかもしれません。 しかしこれは N 個のドライブのデータを収めるのに 2*N 個のドライブが必要となります。 これはもし資金があるならば一番よい方法でしょう! しかし、能率的にそれを 取り扱うために、ボリューム・マネージメント・ソフトウェアに投資する必要が あってもよいです。 @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 データベースに使用しているファイルシステムの mount パラメターを変更しても 良いでしょう。 一つの簡単な方法としては、noatime オプションでファイルシステムを マウントします。 これは inode にある最後にアクセスした時間の更新を スキップします。 これでいくらか ディスクシークを避けることができるでしょう。 @end itemize @menu * Symbolic links:: Using symbolic links for databases and tables @end menu @node Symbolic links, , Disk issues, Disk issues @subsubsection データベースとテーブルにシンボリックリンクを使用する テーブルとデータベースのファイルを MySQL のデータベースディレクトリーから 違う場所に移動し、 それに対してシンボリックリンクを張ることができます。 これは例えばディスク容量が少なくなって、データベースを移動したい場合にそうしたくなるでしょう。 @strong{MySQL} が、テーブルがシンボリックリンクであることに気づいた場合、 symlink を解析し、代わりにその実体のテーブルを使用します。 これは @code{realpath()} コールをサポートする全てのシステムで働きます(少 なくとも Linux と Solaris は @code{realpath()} をサポートします!)。 @code{realpath()} をサポー トしないシステム上では、symlink とテーブルを 同時に使用すべきでありません! テーブルはテーブルの更新後に矛盾する事になるでしょう。 @strong{MySQL} はデフォルトではデータベース同士のリンクをサポートしません。 が、データベース間のシンボリックリンクを作成しない限り、これは正常に働くでしょう。 @strong{MySQL} データディレクトリに @code{db1} データベースがあるとして、 仮に @code{db2} を @code{db1} のシンボリックリンクにしたとします: @example shell> cd /path/to/datadir shell> ln -s db1 db2 @end example すると、@code{db1} 中の @code{tbl_a} テーブルは @code{db2} の @code{tbl_a} テーブルとして見えます。 もしあるスレッドが @code{db1.tbl_a} を更新し、他のスレッドが @code{db2.tbl_a} を 更新した場合、 問題が発生します。 こういった使用をどうしてもしたい場合、@file{mysys/mf_format.c} を以下のように変更します: @example if (!lstat(to,&stat_buff)) /* Check if it's a symbolic link */ if (S_ISLNK(stat_buff.st_mode) && realpath(to,buff)) @end example Change the code to this: @example if (realpath(to,buff)) @end example @cindex Startup parameters @node Server parameters, Table cache, Disk issues, System @subsection サーバーパラメーターのチューニング @code{mysqld} サーバーが使用している現在のバッファサイズを次で得ることができます: @example shell> mysqld --help @end example この結果、全ての @code{mysqld} オプションと次のようなコンフィグ可能変数のリスト を得られます。出力結果にはデフォルト値が含まれ、以下のように表示されます: @example Possible variables for option --set-variable (-O) are: back_log current value: 5 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 net_buffer_length current value: 16384 query_buffer_size current value: 0 record_buffer current value: 131072 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 もし @code{mysqld} サーバーを走らせているなら、以下のコマンドでも変数の値を見ることができます: @example shell> mysqladmin variables @end example これらのオプションは以下のように決めてください。 buffer size, buffer length, stack size は byte 単位で与えます。 これらの値の後ろに @samp{K} や @samp{M} を追加すると、キロバイト、メガバイトになります。 例えば、@code{16M} は16メガバイトを示します。大文字小文字の区別はなく、 @code{16M} と @code{16m} は同じ意味になります。 稼働中のサーバーの統計情報は @code{SHOW STATUS} で参照できます. @xref{SHOW}. @table @code @item @code{ansi_mode}. もし @code{mysqld} が @code{--ansi} オプションで起動されているなら、@code{ON}. @xref{Ansi mode}. @item @code{back_log} @strong{MySQL} が持てる未解決の接続要求の数です。これは @strong{MySQL} スレッドが@strong{ものすごく}多くの接続要求をとても短い時間に得た時に、働き ます。接続のチェックと新しいスレッドの開始はメインスレッドにすこし時間 (しかしほんのわずか)がかかります。back_log は、@strong{MySQL} が瞬間的に新 しい要求への回答を停止する前に、この短い時間の間にスタックできる接続数です。 短い期間に多くの接続を期待する場合にだけ、これを増加する必要があります。 いいかえるなら、これは TCP/IP 接続の入力 listen キューのサイズです。 オペレーティングシステムはこのキューの大きさを制限しています。 UNIX システムコール @code{listen(2)} のマニュアルページに、さらに詳細があります。 この値を最大限にしたい場合、お使いのOSのドキュメントを見てください。 @code{back_log} をこのOSの制限値より多く取ってもは全く効果ありません。 @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{concurrent_inserts} もし @code{ON} (これはデフォルトです) なら、@code{MySQL} は、 @code{SELECT} クエリが実行されている @code{MyISAM} テーブルに対して、 同時に @code{INSERT} が使用できるようにします。 このオプションは @code{mysqld} のオプションに @code{--safe} か @code{--skip-new} を 指定することで @code{OFF} にできます。 @item @code{connect_timeout} @code{mysqld} サーバーが接続パケットを待つ秒数。 (@code{Bad handshake} を返すまでの秒数) @item @code{delayed_insert_timeout} どれぐらい @code{INSERT DELAYED} スレッドが @code{INSERT} 文を待つべきか。 @item @code{delayed_insert_limit} @code{delayed_insert_limit} 個のレコードを挿入した後、 @code{INSERT DELAYED} ハンドラーは 待たされている @code{SELECT} 文がないかチェックします。 もしあるなら、 挿入を続ける前にそれらの実行を許します。 @item @code{delay_key_write} もし enabled であれば(これがデフォルト)、@strong{MySQL} は @code{CREATE TABLE} 文の @code{DELAY_KEY_WRITE} オプションを尊重します。 @code{DELAY_KEY_WRITE}オプションを指定されて作られたテーブルのキーバッファは、 毎回のインデックスの更新にはフラッシュされず、ただテーブルが閉じられたときにだけ フラッシュされます。 これはキーの書き出しを速くしますが、もしこれを使用するなら、 全てのテーブルを @code{myisamchk --fast --force} で自動的に検査するようにすべきです。 もし @code{mysqld} を @code{--delay-key-write_for_all_tables} オプション付きで 起動した場合、これは、全てのテーブルが @code{delay_key_write} オプション指定されて 作成されたものとして扱われる事に注意してください。 このフラグは、@code{mysqld} を @code{--skip-new} や @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} これがもし、非ゼロにセットされたなら、毎 @code{flush_time} 秒ごとに 全てのテーブルが閉じられます。 (リソースの解放とDiskへのsyncのために) @item @code{init_file} サーバー起動時に、@code{--init-file} オプションに与えたファイルの名前です。 このファイルには、サーバー起動時に実行したい SQL 文を書いておきます。 @item @code{interactive_timeout} The number of seconds the server waits for activity on an interactive connection before closing it. インタラクティブ クライアントを作るには、 C API @code{mysql_real_connect()} に @code{CLIENT_INTERACTIVE} オプションを セットします。 See also @code{wait_timeout}. @item @code{join_buffer_size} このバッファは(インデックス無しの)完全な結合に使用されます。それは2つの テーブル間の完全な結合ごとに1回割り当てられます。インデックスの追加がで きない時、より速い完全な結合を得るために、これを増加してください。通常、 速い結合を得る一番良い方法は、インデックスを追加することです。 @c Make texi2html support index @anchor{Index cache size}. Then change @c some xrefs to point here @item @code{key_buffer_size} インデックス・ブロックはバッファされ、そして全てのスレッドに共有されます。 @code{key_buffer_size} はインデックス・ブロックのためのバッファ・サイズです。 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 a lot of rows 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} もしあるクエリがこの値(秒)より時間がかかれば、@code{Slow_queries} カウンター が増やされます。 @item @code{max_allowed_packet} 一つのパケットの最大サイズ。メッセージバッファは @code{net_buffer_length} バイトに初期化されますが、 @code{max_allowed_packet}まで大きくすることができます。このデフォルト値は、 大きなパケット、間違ったパケットをを受けるには小さい値です。 大きな @code{BLOB} を使用している場合は、これを増加する必要があります。使用した い最大の @code{BLOB} と同じくらい大きくするべきです。 @item @code{max_connections} 許される同時クライアントの数。これを増加する場合は、@code{mysqld} が持つファイ ルディスクリプタの数を増やす必要があるでしょう。 後述のファイルデスクリプターの制限の説明を参照のこと。 @xref{Too many connections}. @item @code{max_connect_errors} もしあるホストからの接続中断がこの値を以上になった場合、これ以後、 そのホストからの接続を拒絶します。@code{FLUSH HOSTS} コマンドで ホストの拒否を解除できます。 @item @code{max_delayed_threads} この値を超えて @code{INSERT DELAYED} を扱うスレッドを起動できません。 もし全ての @code{INSERT DELAYED} スレッドが使用されていて、さらに新しいテーブルに データを挿入しようとすると、そのレコードは @code{DELAYED} が与えられていない 場合と同様に挿入されます。 @item @code{max_join_size} @code{max_join_size} より多いレコードを触るとエラーが返ります。長い時間をかけて 百万行を返すような @code{WHERE} なしの結合を作成するようなユーザを持って いる場合にこれを設定してください。 @item @code{max_heap_table_size} Don't allow creation of heap tables bigger than this. @item @code{max_sort_length} @code{BLOB} または @code{TEXT} 項目上でソートする時に使用するバイト数。 (最初の @code{max_sort_length} バイトだけがそれぞれの値で使用でき、残りは無視されます) @item @code{max_tmp_tables} (このオプションはまだなにも行いません). クライアントが同時にオープンできるテーブル数の最大値。 @item @code{max_write_lock_count} After this many write locks, allow some read locks to run in between. @item @code{net_buffer_length} 通信バッファがクエリ間でこのサイズにリセットされます。これは通常は変更す べきではありませんが、とても小さなメモリしかない場合は、これを期待される クエリのサイズに設定してください。 ( これは、クライアントから送られてくるSQL文の長さ分あればいいでしょう。 もし構文がこの値をこえた場合、バッファは自動的に大きくなります。 ただし @code{max_allowed_packet} バイトまでです) @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{record_buffer} 順序スキャンを行う各スレッドが、スキャンするテーブル毎に、このサイズのバッ ファを割り当てます。多くの順序スキャンを行う場合は、これを増加させてくだ さい。 @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} これは、 @code{PROCESS_PRIV} 権限を持っていないユーザーが @code{SHOW DATABASES} する事を阻止します。 もし、他人のデータベースや テーブルを見ようとする人がいる事を、あなたが心配するならば、 これはセキュリティを強化できます。 @item @code{sort_buffer} ソートを行う必要がある各スレッドがこのサイズのバッファを割り当てます。よ り速い @code{ORDER BY} または @code{GROUP BY} のためにはこれを増やしてく ださい。 @xref{Temporary files}. @item @code{table_cache} 全てのスレッドについてのオープンテーブルの数。これを増加する場合は、 @code{mysqld}が要求するオープンファイルディスクリプタの数も 増加することに注意しないといけません。 @strong{MySQL} はユニークテーブル毎に2つのファイルディスクリプタを必要と します。 後述のファイルデスクリプターの制限の説明を参照のこと。 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. テーブルキャッシュがどのように働くかはこちらを参照 @ref{Table cache}. @item @code{tmp_table_size} メモリー内の 一時テーブルがこの値を超えようとした場合、@strong{MySQL} は 自動的に、これを、disk ベースの @code{MyISAM} テーブルに変換します。 多くの先進的な @code{GROUP BY} クエリを行う場合は、 この @code{tmp_table_size} を増加してください。 @item @code{thread_stack} 各スレッドのスタックの大きさ。@code{crash-me} によって検出される多く の制限がこれに依存します。デフォルトでは、通常のオペレーションに対して 十分とってあります。 @xref{Benchmarks}. @item @code{wait_timeout} サーバーがコネクションを閉じるまでにアクティブなコネクションを待つ秒数。 @code{interactive_timeout} も参照のこと。 @end table @strong{MySQL} はとてもスケーラブルなアルゴリズムを使用します。そのため 通常はとても少ないメモリで動作し、またより良い性能を得るために @strong{MySQL} に多くのメモリを与えることができます。 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. 多くのメモリ(>=256M)と多くのテーブルを持っていて、適度のクライアント数で最大性能を得た い場合、次のようなものを使用します: @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 多くの接続で少ないメモリしかない場合、次のようなものを使用します: @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 もしとても多くの接続があり、@code{mysqld} が各接続に対して少ないメモリーで 動作するように設定されていれば、スワップの読み書きによるパフォーマンスの低下がおきます。 もちろん十分なメモリーがあれば、全ての接続にたいして @code{mysqld} のパフォーマンス良くなります。 @code{mysqld} へのオプションを変更する場合、そのサーバのインスタンスにだけに 有効であることに注意して下さい。 パラメータ変更の効果を見るには、このようにします: @example shell> mysqld -O key_buffer=32m --help @end example @code{--help} オプションは最後につけてください。 その他のオプションを --help の後につけると、そのオプションは反映されません。 @cindex Table cache @findex table_cache @node Table cache, Creating many tables, Server parameters, System @subsection @strong{MySQL} はどのようにテーブルのオープン & クローズを行なうか? @code{table_cache} , @code{max_connections} , @code{max_tmp_tables} は サーバーが開いた状態にしておく事が出来るファイルの最大数に影響します。 もしこれらの変数のうちの一つ、あるいは複数を増加させるなら、 あなたのオペレーティング・システムの、1 プロセスあたりに開かれる ファイル・デスクリプタ の最大値を増やすことになるかもしれません。 多くのシステムではこの制限を増やすことが可能です。 これをどうやって行うかは、あなたの使用している OS のドキュメントを見てください。 制限値の変更方法は、システムによってまちまちだからです。 @code{table_cache} は @code{max_connections} に関連します。 例えば 200 のコネクションを同時に開けるなら、少なくとも @code{200 * n} の テーブル・キャッシュが必要です。 ここで @code{n} は join におけるテーブルの 最大数です。 オープンテーブルのキャッシュは最大で @code{table_cache} まで大きくなります(デ フォルトは 64, @code{mysqld} のオプション @code{-O table_cache=#} で変更可能)。 キャッシュが一杯になって、他のスレッドがテーブルのオープンを試みた時、 または @code{mysqladmin refresh} @code{mysqladmin flush-tables} を使用した場合を除いて、テーブルはクローズされません。 キャッシュがいっぱいになった場合、サーバーは以下の処置を取って キャッシュを使用できるように配置します: @itemize @bullet @item 現在使われていないテーブルが解放されます。もっとも使用されていないテーブルからから順に。 @item もしキャッシュが一杯でテーブルを解放することが出来ず、さらに新しいテーブルの オープン要求がある場合、キャッシュは一時的な拡張を必要とします。 @item もしそのキャッシュが一時拡張に配置されていて、かつ、テーブルが使用状態から 未使用状態に移行した場合、そのテーブルは閉じられ、キャッシュから解放されます。 @end itemize テーブルは各同時アクセスに (再び) オープンされます。これは、同じテーブルで2つのスレッ ドが実行されている場合、または同じクエリで(@code{AS} で)テーブルを2回アクセス する場合、テーブルは2回オープンする必要があることを意味します。最初のテーブルのオー プンは2つのファイル記述子を使用し、続くテーブルの各使用は1つだけのファイル記述 子を使用します。 @node Creating many tables, Open tables, Table cache, System @subsection Drawbacks of creating large numbers of tables in the same database もしたくさんのファイルが一つのディレクトリにある場合、オープン、クローズ、 作成操作は遅くなるでしょう、 もし @code{SELECT} 文を多くのテーブルに対し 実行した場合、テーブルキャッシュが一杯ならば、このオーバーヘッドは多くなるでしょう。 なぜなら、それぞれのテーブルにつきオープンし、クローズしなくてはならないからです。 このオーバーヘッドを緩和するには、テーブルキャッシュを大きくします。 @node Open tables, Memory use, Creating many tables, System @subsection 何故そんなに多くのテーブルをオープンするのか? @code{mysqladmin status} を実行すると、次のようなものが得られます: @example Uptime: 426 Running threads: 1 Questions: 11082 Reloads: 1 Open tables: 12 @end example 確かにたった6個しかテーブルがないのに、このような結果が出るので少々戸惑われるかもしれません。 @strong{MySQL} はマルチスレッドなので、同じテーブルで一度に多くのクエリを持て ます。同じファイル上で異なる状態を持つ2つのスレッドで、問題を最小化する ため、同時に動作する各スレッドのためテーブルを再びオープンします。これはいくつ かのメモリとデータファイルについての一つの拡張ファイル記述子を使用します。 インデックスファイル記述子は全てのスレッド間で共有されます。 @cindex Memory use @node Memory use, Internal locking, Open tables, System @subsection MySQL はどのようにメモリを使用するのか? 以下に @code{mysqld} サーバーがどのようにメモリーを使用するか、いくつか示します。 サーバーに与える変数名は、サーバーのメモリーの使用方に関連した名前となっています。 @itemize @bullet @item キーバッファ (変数 @code{key_buffer}) は全てのスレッドで共有され、 残りは必要時に割り当てられます。 @xref{Server parameters}. @item 各接続はいくつかのスレッド空間を使用します; スタック (64K, 変数 @code{thread_stack}), 接続バッファ(variable @code{net_buffer_length}), 結果バッファ(variable @code{net_buffer_length})。接続バッファと結果バッファは必要となった時、 動的に最大 @code{max_allowed_packet} まで増えます。 クエリが走っている時、そのクエリの文字のコピーが割り当てられます。 @item 全てのスレッドは同じベースメモリを共有します。 @item まだ memory-mapped を使用していません (圧縮テーブルは除きますが、これは別の話)。 これは 4GB の 32bit メモリ空間は多くの大きなテーブルを扱うには小さいためです。 64bit アドレス空間を持つシステムを我々が手に入れた時、我々は mmemory-mapping を通常にサポートします。 @item テーブルを越えて順次スキャンを行なう各要求は、読み込みバッファを割り当てます (変数 record_buffer) @item 全ての結合は1パスで行なわれ、多くの結合は一時テーブルを使用せずに行なわ れます。多くの一時テーブルはメモリベース(HEAP)のテーブルです。大きなレコー ドサイズ (= 全フィールド長の合計) を持つ一時テーブルまたは、@code{BLOB} を含む テーブルはディスク上に置かれます。 @strong{MySQL} 3.23.2 以前での問題は、HEAP テーブルが @code{tmp_table_size} のサイズを越えると、エラー @code{The table tbl_name is full} が出ることです。将来我々は、必要時にメモリ (HEAP) テーブルをディスクベー ス (NISAM) テーブルに自動的に変更することにより、これを修正します。この 問題を回避するため、@code{mysqld} への @code{tmp_table_size} オプションま たはクライアント側で SQL オプション @code{SQL_BIG_TABLES} で増加できます。 @xref{SET OPTION, , @code{SET OPTION}}. @strong{MySQL} 3.20 では、一時テーブルの最大サイズは @code{recordbuffer*16} でした。そのため、このバージョンを使用していると、 @code{recordbuffer} を追加する必要があります。 @code{mysqld} を @code{--big-tables} で 開始することで、常に一時テーブルをディスク上に格納できます。しかしこれは 多くの複雑なクエリの速度に影響します。 @item ほとんどのリクエストは、1,2個の一時ファイルとわずかなソートバッファへの割り当てを行います。 @xref{Temporary files}. @item 変形と演算時に使用されるほとんど全てのメモリはローカルメモリストア内で行 なわれます。小さな項目に必要とされるメモリオーバーヘッドはなく、通常の遅 いメモリ割り当て/解放が回避されます。メモリは予期しない大きな文字列にだ け割り当てられます(これは @code{malloc()} と @code{free()} で行なわれます)。 @item 各インデックスファイルは一度オープンされ、データファイルは各同時実行スレッ ド毎に一度オープンされます。各同時スレッドには、テーブル構造、各フィールドの構造そし て @code{3 * n} のサイズのバッファが割り当てられます。 ( @code{n} は @code{BLOB} 型のフィールドの長さを含めない、一レコードの最大長です ) @code{BLOB} は 5 から 8 バイト + @code{BLOB} データの長さを使用します。 @item @code{BLOB} を持つ各テーブルでは、より大きな @code{BLOB} の読み込みでバッファ は動的に拡大されます。テーブルのスキャンをする場合、割り当てられたバッファは最 も大きい @code{BLOB} と同じ大きさになります。 @item 全ての使用されているテーブルのテーブルハンドラーはキャッシュ内に保存され、 FIFO として管理されます。 通常、キャッシュは 64 個のテーブルです。テーブルが 2 つの実行しているス レッドで同時に使用される場合、キャッシュ内にテーブルの 2 つのエントリが あります。 @xref{Table cache}. @item @code{mysqladmin refresh} は使用されていない全てのテーブルをクローズし、 使用されている全てのテーブルを、実行中スレッドが終った時にクローズするよ うにマークします。これは多くの使用メモリを解放するのに有効です。全てのロ グファイルもクローズと再オープンされます。 @end itemize @strong{mysqld} 実行時、@code{ps} や他のプログラムは、それが多くのメモリ を使用していると報告するでしょう。これは異なったメモリアドレス上のスレッ ドスタックによって発生します。例えば、Solaris ps はスタック間の未使用メ モリを使用メモリとして計算します。'swap -s' で有効なスワップをチェックす ることでこれを確かめられます。我々は市販のメモリリーク検出プログラムで @code{mysqld} をテストしました。そのため、メモリリークは全くありません。 @node Internal locking, Table locking, Memory use, System @subsection @strong{MySQL} はどのようにテーブルをロックするか @strong{MySQL} の全てのロックはデッドロックフリーです。これは、常にクエ リ開始時に一度ロックを必要とする全てを要求し、常に同じ順でテーブルをロッ クすることで管理されます。 @strong{MySQL} が使用する @code{WRITE} ロックは次のように働きます: @itemize @bullet @item テーブル上にロックがない場合 write ロックを置きます。 @item そうでなければ write ロックキューにロックを置きます。 @end itemize @strong{MySQL} の @code{READ} ロックは次のように動きます: @itemize @bullet @item テーブル上に write ロックがない場合 read ロックを置きます。 @item そうでなければ read ロックキューにロックを置きます。 @end itemize ロックが解放されたとき、最初に write ロックキュー内のスレッドに、その後 read ロックキュー内のスレッドにロックを与えます。 これは、同じテーブルで多くの更新をする場合、@code{SELECT} 構文は update がなくなるまで待たされることを意味します。 同じテーブルで多くの @code{INSERT} と多くの @code{SELECT} を行う場合、これを解決するに は、他のテーブルに行を挿入して、たまに、その一時テーブルから全てのレコー ドをもう一方のテーブルに update します。 これは次のコードで行えます: @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 決まりきった検索に優先権を与えるため、@code{INSERT} 構文で @code{LOW_PRIORITY} か @code{HIGH_PRIORITY} オプションが使用できます。 @xref{INSERT, , @code{INSERT}}. 一つのキューだけを使用するように @file{mysys/thr_lock.c} 内のロックコードを変更 することもできます。この場合、いくつかのアプリケーションのために、 write ロックは read ロックと同じ優先順位にします。 @node Table locking, , Internal locking, System @subsection テーブル・ロッキングの問題 @strong{MySQL} のテーブル・ロッキングのコードはデッドロック・フリーです。 @strong{MySQL} はとても速いロックスピードを得るために、 (レコードのロックやフィールドのロックの代わりに) テーブルのロックを使用します。 大きなテーブルには、 テーブルのロックはレコードのロックよりはるかに良いですが、 いくつかの落とし穴があります。 @strong{MySQL} 3.23.7 以上では、あるスレッドが @code{MyISAM} テーブルを読んでいる最中に、 同じテーブルにレコードを挿入する事ができます。 これは現在、削除がない場合にのみ動きます。 テーブルのロックはたくさんのスレッドが同時にあるテーブルから読み出すのを可能にしますが、 もしあるスレッドがあるテーブルに対し書込み要求を出す場合、 それはまず最初に排他的なアクセスを得なければなりません. その更新の間、更新が完了するまで、この特定のテーブルにアクセスしようとする 他の全てのスレッドが待たされることになります。 通常データベースの更新は @code{SELECT} よりも重要とされるため、 テーブルを更新する全てのスレッドが、テーブルから情報を検索するスレッドよりも 高い優先順位を持ちます。 これは ある特定のテーブルに対して、多くの重いクエリが発行され た場合に、 更新が不完全に終わらないことを確実にするためです。 @strong{MySQL 3.23.7} から、@code{max_write_lock_count} 変数が使用できます。 これは、一つのテーブルに対して、指定された回数だけ INSERT が行われた後に、 @code{SELECT} を発行するようにします。 この1つの主な問題が以下です: @itemize @bullet @item あるクライアントが実行に長い時間のかかる @code{SELECT} を発行。 @item その後に、他のクライアントが、使用されているテーブルに対し @code{UPDATE} を発行; このクライアントは先の @code{SELECT} が完了するまで待ちます @item さらに他のクライアントが同じテーブルに対して @code{SELECT} 構文を発行; @code{UPDATE} は @code{SELECT} よりも高い優先度を持つので、 この @code{SELECT} は先の @code{UPDATE} が完了するまで待ちます。 これは一番最初の @code{SELECT} が 終了するまで待たされます! @end itemize この問題のいくつかの可能な解決は以下の通りです: @itemize @bullet @item @code{SELECT} 構文を速く実行できるように試みます; これを行うにあたり、 いくつかのサマリーテーブルを作成しなければならないかもしれません. @item @code{mysqld} を @code{--low-priority-updates} オプションで起動。 これは全てのあるテーブルを更新する構文に対して、 @code{SELECT} 構文よりも 低い優先度を与えます。 この場合、前述のシナリオ中の最後の @code{SELECT} 構文は @code{INSERT} 構文が完了する前に実行されます。 @item @code{LOW_PRIORITY} 属性指定を用いて、 @code{INSERT},@code{UPDATE},@code{DELETE} 構文 に低い優先度を与えることも出来ます。 @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 SQL コマンドの @code{SET SQL_LOW_PRIORITY_UPDATES=1} を使用して、 ある特定のスレッドからの全ての更新を、低い優先度に指定する事ができます。 @xref{SET OPTION, , @code{SET OPTION}}. @item @code{HIGH_PRIORITY} 属性を用いて、特定の @code{SELECT} がとても重要であると 指定することが可能です。. @xref{SELECT, , @code{SELECT}}. @item もし @code{INSERT} と @code{SELECT} をあわせて使用した場合に問題が起きた場合、 新しい @code{MyISAM} テーブルに切り替えます。 これは @code{SELECT} と @code{INSERT} を同時に行えます。 @item もし @code{INSERT} と @code{SELECT} 構文を主に混在させるのなら、 @code{INSERT} の @code{DELAYED} 属性指定はこの問題を解決させるでしょう。 @xref{INSERT, , @code{INSERT}}. @item もし @code{SELECT} と @code{DELETE} で問題があるなら、 @code{DELETE} の @code{LIMIT} オプションが助けになるでしょう。 @xref{DELETE, , @code{DELETE}}. @end itemize @node Data size, MySQL indexes, System, Performance @section 可能な限りデータを小さくする 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}. 以下に挙げるテクニックを使用すれば、テーブルでのパフォーマンスの向上、 保存領域の縮小化が可能でしょう: @itemize @bullet @item 可能ならば、一番小さな型を使用します。 @strong{MySQL} は ディスクとメモリーを節約する多くの型を持っています。 @item より小さな整数型を可能ならば使用します。 例えば、 @code{MEDIUMINT} は @code{INT} より良いでしょう。 @item 可能ならフィールドを @code{NOT NULL} に定義してください。これは全てをより速くし、 各フィールド毎に1ビットを節約します。 Note that if you really need @code{NULL} in your application you should definitely use it. Just avoid haveing it on all columns by default. @item 可変長のフィールド (@code{VARCHAR}, @code{TEXT}, @code{BLOB}) を持たない場合は、 固定サイズレコード形式が使用されます。 これはかなり速いです。しかしあいにくいくらかの領域を浪費します。 @xref{MyISAM table formats}. @item それぞれのテーブルは可能な限り短いプライマリ・インデックスを持つべきです。 これは1レコードを一意にし、効率的にします。 @item それぞれのテーブルについて、どのテーブルの形式を使用するかを 決めます。 @xref{Table types}. @item 本当に必要な物にだけインデックスを作成します。 インデックスは検索には良いですが、より速く保存したい場合には良くありません。 もしテーブルをフィールドの組み合わせでサーチすることがほとんどであれば、 それらにインデックスを作成します。 最初のインデックスの部分は、もっとも 使用されるフィールドにすべきです。 If you are ALWAYS using many columns you should use the column with more duplicates first to get better compression of the index. @item もしインデックスが頭からの何文字かで一意性を持っているなら、この部分にだけ インデックスを張る方が良いでしょう。 @strong{MySQL} は文字列フィールドの 一部分に対してのインデックスをサポートします。 短いインデックスは、ディスクスペースを節約するだけでなく、 インデックスのキャッシュに収まりやすくなることにより、ディスク・シークも少なくなるので、 速くなります。 @xref{Server parameters}. @item いくつかの状況下で、とてもよく走査されるテーブルを2つに分割することは、 利益になることがあります。 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 MySQL はどのようにインデックスを使用するか? Indexes are used to find rows with a specific value of one column fast. インデックスがない場合、@strong{MySQL} は、そのレコードが見つかるまで、 最初のレコードからテーブルをなめていきます。 大きなテーブルでは多くの 手間がかかります。 もし問い合わせの中にインデックスを持ったフィールドが ある場合、@strong{MySQL} は全てのデータをみることなく、データの途中の位置を速く 得ることができます。 もしあるテーブルが1000レコード持っていたとすると、 順番に頭からなめていくことに比べて、これは少なくとも100倍速いことに なります。 Note that is you need to access almost all 1000 rows it is faster to read sequentially because we then avoid disk seeks. 全ての @strong{MySQL} インデックス, @code{PRIMARY}, @code{UNIQUE} そして @code{INDEX()} は B tree に格納されます。文字列は自動的に始めと終りの空白が圧縮されます。 @xref{CREATE INDEX, , @code{CREATE INDEX}}. Indexes are used to: @itemize @bullet @item @code{WHERE}節にマッチした行の素早い検索 @item join を実行したときの他のテーブルからの行の検索 @item 与えられたフィールドの @code{MAX()} や @code{MIN()} 値の割り出し @item テーブルをソートかグループ化する場合で、ソート(グループ化)が一番左(接頭部)の キーを使用して行われる場合(例えば @code{ORDER BY key_part_1,key_part_2 })。 もし @code{DESC} 指定があれば、全てのキーは逆順に読まれます。 The index can also 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 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 データファイルを参照することなく値を検索する場合。 もし使用する全てのフィールドが数値でかつ、一番左から(接頭部から)キーを形成する場合、 値はインデックスツリーから検索され、これはとても速くなります。 @end itemize 以下のような @code{SELECT} 文を発行したとします: @example mysql> SELECT * FROM tbl_name WHERE col1=val1 AND col2=val2; @end example もし @code{col1} と @code{col2} に複数フィールドインデックスが定義されている場合、 すぐに思ったとおりの結果が得られます。 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 もしテーブルが複数フィールドインデックスを持つなら、インデックスの接頭部一番左の部分 がレコードを見つけるための最適化に使用されます。例えば、3つのフィールド @code{(col1,col2,col3)} に対して一つのインデックスを持っていたとします。 すると、これは @code{(col1)}, @code{(col1,col2)} , @code{(col1,col2,col3)} でインデックスがサーチされます。 もし一番左に指定しているフィールドがインデックスを作成していないなら、 @strong{MySQL} は部分的なインデックスを使用しません。 以下のような @code{SELECT} 文を発行したとします: @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 もしインデックスが @code{(col1,col2,col3)} にあるならば、 上に示した最初のクエリだけがインデックスを使用します。二番目三番目のクエリは インデックスを持つフィールドを発動しますが、 @code{(col2)} と @code{(col2,col3)} は、@code{(col1,col2,col3)} の 接頭部一番左に指定されていません。 @findex LIKE, and indexes @findex LIKE, and wildcards @cindex Indexes, and @code{LIKE} @cindex Wildcards, and @code{LIKE} @strong{MySQL} は、もし @code{LIKE} がワイルドカードから始まっていなくて、 ある種固定された文字で始まっているなら、 @code{LIKE} の評価にインデックスを使用します。 例えば、以下の @code{SELECT} 文はインデックスを使用します: @example mysql> select * from tbl_name where key_col LIKE "Patrick%"; mysql> select * from tbl_name where key_col LIKE "Pat%_ck%"; @end example 一つ目の文は、@code{"Patrick" <= key_col < "Patricl"} となるレコードだけ、考慮されます。 二つ目の文は、@code{"Pat" <= key_col < "Pau"} となるレコードだけ、考慮されます。 以下の @code{SELECT} 文はインデックスを使用しません: @example mysql> select * from tbl_name where key_col LIKE "%Patrick%"; mysql> select * from tbl_name where key_col LIKE other_col; @end example 最初の文は、@code{LIKE} がワイルドカード文字で始まっています。 二つ目の文は、@code{LIKE} が定数ではありません。 @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} は通常、一番少ないレコード数を見つけるインデックスを使用します。 インデックスは、以下に示す演算子を用いて比較できるフィールドに対して、使用されます: @code{=}, @code{>}, @code{>=}, @code{<}, @code{<=}, @code{BETWEEN} そして @code{'something%'} の様に頭にワイルドカードがない @code{LIKE}。 @code{WHERE} 節内の全ての @code{AND} にかからないインデックスは、 全くクエリの最適化に使用されません。 In other words: To be able to use an index, a prefix of the index must be used in every @code{AND} group. 以下の @code{WHERE} 節はインデックスを使用します: @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 以下の @code{WHERE} 節はインデックスを@strong{使用しません}: @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 @node Query Speed, Tips, MySQL indexes, Performance @section データをアクセス・更新するクエリの速度 最初に、全てのクエリに影響する一つの事柄をのべます: より複雑な権限の設定を行うと、オーバーヘッドが多くなります。 もしあなたがいかなる @code{GRANT} 文も行っていなければ、 @strong{MySQL} はパーミッションの検査を少ししか最適化しないでしょう。 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. もし @strong{MySQL} 関数のあるものが確実に問題を引き起こしているのならば、 常に @strong{MySQL} クライアント側は以下のようになります: @example mysql> select benchmark(1000000,1+1); +------------------------+ | benchmark(1000000,1+1) | +------------------------+ | 0 | +------------------------+ 1 row in set (0.32 sec) @end example 上の例では @strong{MySQL} は 1,000,000 @code{+} 式を 0.32 秒で実行できています (たんなる @code{PentiumII 400MHz} マシンで)。 全ての @strong{MySQL} 関数は最適化されていますが、 いくつかは例外があるかもしれません。 @code{benchmark(loop_count,expression)}はあなたのクエリの 問題を見つけるためのとてもよいツールです。 @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 クエリの性能評価 ほとんどの場合、ディスク・シークを数えることでだいたいのパフォーマンスを予測できます。 小さなテーブルでは、通常、1回のディスク・シークでレコードを見つけれるでしょう (インデックスがたぶんキャッシュされるので)。 大きなテーブルでは、 おおよその予測として、(B++ ツリーインデックスを使用している場合)、 @code{log(row_count) / log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) + 1} シーク、1レコードを見つけるのに必要となるでしょう。 @strong{MySQL} では、インデックス・ブロックは通常 1024 バイトで、 データ・ポインターは通常 4 バイトです。 これは、 インデックス長が 3 (medium integer) 、データが 500,000 レコードあるテーブルでは、 @code{log(500,000)/log(1024/3*2/(3+4)) + 1} = 4 シークとなります。 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. 書き込み時には、上の場合、新しいインデックスを書き込める場所を 探し出すのに、4 シークかかり、さらに、通常、インデックスを更新し、 レコードを書くのに 2 シーク必要です。 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 @code{SELECT} クエリの速度 通常、遅い @code{SELECT ... WHERE} を速くするには、 まず最初にインデックスがあるかどうかをチェックします。@xref{MySQL indexes, , @strong{MySQL} indexes}. 違うテーブルを参照する場合には、普通はインデックスをともなうべきです。 @code{EXPLAIN} コマンドを使用すれば、@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 インデックスとデータをインデックス順に従ってソートするには、 @code{myisamchk --sort-index --sort-records=1} を使用します (もし 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. しかし、このソート方法は最適状態では書かれず、また大きなテーブルでは 多くの時間がかかることに注意してください! @end itemize @cindex Optimizations @node Where optimizations, LEFT JOIN optimization, SELECT speed, Query Speed @subsection MySQL はどのように @code{WHERE} 節を最適化するか? @code{WHERE} の最適化は、@code{WHERE} がほとんど @code{SELECT} で使用されるため、 @code{SELECT} に置かれています。 しかし、同じ最適化は @code{DELETE} や @code{UPDATE} 文でも使用されます。 このセクションの最適化の説明はまだ不十分です。 なぜなら、 @strong{MySQL} はとても多くの最適化を行っており、 それら全てについての説明を書ける時間が、我々はとれません。 @strong{MySQL}による最適化のいくつかを以下に示します: @itemize @bullet @item 括弧の除去 (全ての不必要な括弧は削除されます): @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 定数の保持: @example (a b>5 AND b=c AND a=5 @end example @item 定数条件の除去 (定数保持のために必要とされます): @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 インデックスに使用される全ての表現は一度だけ評価されます。 @item 一つのテーブル上の @code{WHERE} がない @code{CONST(*)} は、テーブルから 直接取り出されます。これはまた同じ条件下での任意の @code{NOT NULL} 表現 のためにも行われます。 @item 不当な定数表現は早く検出されます。 @strong{MySQL} は不可能な @code{SELECT} 構文を素早く見つけ、0 行を結果として返します。 @item @code{GROUP BY} または group 関数 (@code{COUNT()}, @code{MIN()}...) を使用しない場合は、 @code{HAVING} は @code{WHERE} とマージされます。 @item 各サブ結合についての速い @code{WHERE} 評価を得るために、また、可能な限り 早くレコードをスキップするために、各サブ結合についてより簡単な @code{WHERE} が構築されます。 @cindex Constant table @cindex Table, constant @item 全ての定数テーブルをクエリー中の他のテーブルより先に読みます。 定数テーブルは次です: @itemize @minus @item 0 または 1 行のテーブル。 @item @code{WHERE} 節で @code{UNIQUE} インデックスや @code{PRIMARY KEY} が使用されたテーブルで、 かつ、全てのインデックスが定数式で使用されていて、 かつ、インデックスのパートが @code{NOT NULL} で定義されているテーブル。 @end itemize 以下のテーブルのように定数だけを使用するテーブル: @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 テーブルを結合するために最良の結合の組合せを見つけます。全ての可能性を試して 。 @code{ORDER BY} または @code{GROUP} 内の全てのフィールドが同じテーブルの場合は、 このテーブルは結合時に最初に優先されます。 @item @code{ORDER BY} 節と @code{GROUP BY} 節がある場合、または @code{ORDER BY} か @code{GROUP BY} が結合キュー 内の最初のテーブルではない他のテーブルからの項目を含む場合、一時テーブルが生成されます。 @item もし @code{SQL_SMALL_RESULT} を使用するなら, @strong{MySQL} はメモリー内の一次テーブルを 使用します @item @code{DISTINCT} は、全てのフィールドに対する @code{GROUP BY} に変換されるため、 @code{ORDER BY} と合わした @code{DISTINCT} は多くの場合で一時テーブルが 必要になります。 @item 各テーブルのインデックスはクエリされ、得られる行の 30% 未満の幅しかない最良のインデックスが使用されます。 そのようなインデックスが見つけられない場合、素早いテーブルの走査(quick table scan)が使用されます。 @item 同じように、@strong{MySQL} はデータファイルを等しく調べはしないインデックスから レコードを読むことが可能です。もし全てのフィールドが数値型のインデックスなら、 インデックスツリーだけがクエリの解決に使用されます。 @item 各レコードが出力される前に、@code{HAVING} 節に適合するものをスキップします。 @end itemize 以下はとても速いクエリの例です: @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 以下のクエリはインデックスツリーのみを使用します(インデックス化されているフィールドは 数値型と仮定します): @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 以下のクエリは、ソートされた行の検索にインデックスを使用します: @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 MySQL はどのように @code{LEFT JOIN} を最適化するか? @code{A LEFT JOIN B} は @strong{MySQL} に以下のように組みこまれています: @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 テーブル @code{A} が @code{LEFT JOIN} 条件中に使用される全てのテーブル (ただし @code{B} は除く)に依存すると、セットされます。 @item 全ての @code{LEFT JOIN} 条件が @code{WHERE} 節に移動されます。 @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 全ての @code{WHERE} 節の最適化が行われます。 @item @code{WHERE} 節にマッチするレコードが @code{A} にあり、 @code{LEFT JOIN} 条件にマッチするレコードが @code{B} にない場合、 全てのフィールドが @code{NULL} にセットされた @code{B} のレコードが 作成されます。 @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 MySQL はどのように @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 もし @code{LIMIT} を使用して限定した数だけ select を行うなら、 @strong{MySQL} は、 ある場合、テーブルを全て走査するよりも、インデックスを使用しようとします。 @item もし @code{LIMIT #} を @code{ORDER BY} と共に使用するなら, @strong{MySQL} は 最初の @code{#} 行を見つけたらすぐに、全テーブルのソートは行わずに、 ソートを終わらせます。 @item @code{LIMIT #} を @code{DISTINCT} と共に使用するなら, @strong{MySQL} は @code{#} 個の一意なレコードを見つけた時点で終わります。 @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 @strong{MySQL} は、最初の @code{#} 行をクライアントに送ったあと直に、 クエリを中断します。 @item @code{LIMIT 0} は常に素早く空の結果を返します。 これはクエリのチェックや結果として得られるフィールドの型を得るために利用できます。 @item 一時テーブルの大きさは、クエリを解決するためにどれぐらいのスペースがいるかを 計算するのに、@code{LIMIT #} を使用します。 @end itemize @node Insert speed, Update speed, LIMIT optimization, Query Speed @subsection @code{INSERT} クエリの速度 レコードを挿入する時間はおおよそ次からなります: @itemize @bullet @item 接続: (3) @item クエリをサーバへ送信: (2) @item クエリの解析: (2) @item レコードの挿入: (1 x size of record) @item インデックスの挿入: (1 x number of indexes) @item クローズ: (1) @end itemize ここで (数字) は比例時間です。これは、テーブルのオープンにかかる初期オーバーヘッ ド(これは同時に動作する各クエリ毎に1回行なわれます)は考慮されていません。 テーブルのサイズはインデックスの挿入を N log N で遅くします (B-tree)。 INSERT を速くするいくつかの方法: @itemize @bullet @item もし同じクライアントから多くのレコードを同時にインサートするなら、 複数の値が書ける @code{INSERT} 文を使用します。 これは個々に @code{INSERT} 文 を発行する場合に比べて、とても速くなります。 @item もし違うクライアントから多くのレコードを同時にインサートするなら、 @code{INSERT DELAYED} 文の使用で、より速くなるでしょう。 @xref{INSERT, , @code{INSERT}}. @item @code{MyISAM} では、複数の @code{SELECT} が走っているテーブルに対して、 同時に、レコードを挿入できます。 ただしそのテーブルに対して レコードの削除がない場合に。 @item テキストファイルからテーブルにデータをいれる場合は、 @code{LOAD DATA INFILE} を 使用します。 これはたくさんの @code{INSERT} 文の発行に比べて通常 20倍 程度 速くなります @xref{LOAD DATA, , @code{LOAD DATA}}. @item テーブルが多くのインデックスを持っている場合、ある方法で、 @code{LOAD DATA INFILE} の 実行を速くすることが可能です。 以下の手順で行います: @enumerate @item Optionally create the table with @code{CREATE TABLE}. For example using @code{mysql} or Perl-DBI. @item @code{FLUSH TABLES} の実行。 あるいは @code{mysqladmin flush-tables} コマンドの実行。 @item @code{myisamchk --keys-used=0 -rq /path/to/db/tbl_name} の使用。 これは指定されたテーブルから全てのインデックスを削除します。 @item そのテーブルに @code{LOAD DATA INFILE} を使用してデータを入れます. これはいかなるインデックスも更新しないでしょうし、そのため、速くもなるでしょう。 @item もし @code{myisampack} をお持ちで、テーブルを圧縮したいなら、 @code{myisampack} を実行します. @xref{Compressed format}. @item @code{myisamchk -r -q /path/to/db/tbl_name} でインデックスを再構築. これは disk に書き込む前にインデックスをメモリに作成します。 これは多くのディスクシークを避けることが出来るのでとても速くなります。 でき上がったインデックスツリーは、バランスのよいものになります。 @item @code{FLUSH TABLES} の実行。 あるいは @code{mysqladmin flush-tables} コマンドの実行。 @end enumerate この手順は、将来の MySQL の @code{LOAD DATA INFILE} に組み込むかもしれません。 @item テーブルをロックすることで、挿入を速くすることも可能です: @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 主な速度差は、全ての @code{INSERT} 構文でインデックスバッファが一度だけディスクにフ ラッシュされることです。通常は @code{INSERT} 構文があるのと同じくらい多くのインデッ クスバッファフラッシュがあります。単一構文の全てのレコードは、ロックなしで挿入できます。 ロックも複数接続テストの合計時間を低くしますが、いくつかのスレッドの最大 待ち時間は上がります(ロックを待っているから)。 例えば: @example thread 1 does 1000 inserts thread 2, 3, and 4 does 1 insert thread 5 does 1000 inserts @end example ロックを使用しない場合、2, 3 そして 4 は 1 と 5 の前に終ります。ロックを 使用する場合、2,3,4 は 1 や 5 の前に終わることはおそらくありませんが、合 計時間は約 40 % 速くなります。 @code{INSERT}, @code{UPDATE} , @code{DELETE} は、 @strong{MySQL} ではとても速いので、 1 行で約 5 つ以上、値を 挿入・更新 をする操作に対して、 ロックを追加すれば、全般的により良い性能が得られます。 とても多い insert を行なう場合、 他のスレッドにそのロックしたテーブルへのアクセスを与えるために 、 だいたい 1000 レコードごとに一度、@code{UNLOCK TABLES} した後に @code{LOCK TABLES} を行います。 これでもまだ良い性能が得られます。 もちろん @code{LOAD DATA INFILE} はとても速いです。 @end itemize @code{LOAD DATA INFILE} と @code{INSERT} を共に速くするためには、 キーバッファを増やします。 @xref{Server parameters}. @node Update speed, Delete speed, Insert speed, Query Speed @subsection @code{UPDATE} クエリの速度 @code{UPDATE} クエリは @code{SELECT} クエリのように最適化されますが、 書き込みのオーバーヘッドが加わります。 書き込み速度は、更新されるデータの大きさ、更新されるインデックス数に 依ります。 変更されないインデックスは更新されません。 Also another way to get fast updates is to delay updates and then do many updates in a row later. 一文で多くの更新を行えば、もしテーブルがロックされていれば、 一文で一個づつ更新するよりも、とても速くなります。 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 @code{DELETE} クエリの速度 1レコードを削除する時間は、ちょうどインデックスの数に比例します。 より速くレコードを削除したいなら、インデックス・キャッシュを 増やします。 @xref{Server parameters}. テーブル中からレコードの大きな部分を消すよりも、 全てのレコードを消すほうが、とても速いです。 @node Tips, Benchmarks, Query Speed, Performance @section 最適化に関するその他の助言 Unsorted tips for faster systems: @itemize @bullet @item コネクションオーバーヘッドを避けるために、データベースに対して、 逐次コネクションを落とさないように、常に接続を保ちます。 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 あなたのクエリがテーブルのインデックスを使用しているか、いつもチェックします。 @strong{MySQL} では @code{EXPLAIN} コマンドでこれが行えれます。 @xref{EXPLAIN, Explain, Explain, manual}. @item たくさん変更されるようなテーブルに対して、複雑な @code{SELECT} クエリを 避けるように試みます。 これはテーブル・ロックの問題を避けるためです。 @item 新しい @code{MyISAM} テーブルでは、あるテーブルにレコードが挿入(削除は無しで) されている最中に、同時に、同じテーブルからデータを読むことが可能です。 これがあなたにとって重要項目であるなら、 レコードの削除の必要のない方法や、多くのレコードを削除した後に @code{OPTIMIZE TABLE} を 実行することを、考慮すべきです。 @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 where hash='calculated hash on col1 and col2' and col_1='constant' and col_2='constant' and ..} @item 多くの変更がなされるテーブルに対しては、全ての @code{VARCHAR} や @code{BLOB} フィールドを避けるように試みるべきです。 You will get dynamic row length as soon as you are using a single @code{VARCHAR} or @code{BLOB} columns. @xref{Table types}. @item 通常、あるテーブルを違うテーブルに分けることは、レコードが大きくなる ために役立ちません。 レコードにアクセスする際、そのレコードの最初のバイトを見つけるための ディスク・シークが、一番かかります。 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 もし、多くのレコードからの情報を元にした計算(あるもののカウントとか)を しょっちゅう行う必要があるなら、新しいテーブルを用意し、逐次カウンターを 更新した方が多分良いでしょう。 @code{UPDATE table set count=count+1 where index_column=constant} の更新は とても速いです! これは、@strong{MySQL} のようなテーブル・ロッキング (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 もしたくさんの大きなテーブルから統計を収集する必要があるなら、 全テーブルを走査する代わりに、サマリーテーブルを使用します。 Maintaing the summarys 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 changes (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 フィールドにはデフォルト値があるという事を利用して下さい。 値がデフォルトとは違う場合に限り、値を挿入します。 これは @strong{MySQL} が必要とする分析を少なくし、インサートの速度が向上します。 @item ある場合では、BLOB にデータをパックして保存するのが便利です。 この場合、BLOB に入れた値を パック・アンパック するためのコードを あなたのアプリケーションに組み込まなくてはなりません。 しかしこれは、多くのアクセスを抑制するでしょう。 これは、静的(固定長)テーブル構造に適しないデータを持っている場合に 実用になります。 @item 通常、あなたは全てのデータを冗長の無いように(データベース理論で 第3正規形 , 3rd Normal Form , 3NF と呼ばれる) しようとするかもしれませんが、しかし、よりスピードを求める場合は、 重複やサマリーテーブルの作成をおそれてはいけません。 @item ストアド・プロシージャ や UDF (ユーザー定義関数) はよりパフォーマンスを得る ためにはよい方法かもしれません。 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 データをすぐには書く必要がないとき、@code{INSERT /*! DELAYED */} を使用します。 これは、一回のディスクへの書き込みで、多くのレコードがかかれるので、 速くなります。 @item SELECT がより重要な場合、@code{INSERT /*! LOW_PRIORITY */} を使用します。 @item キューを無視して SELECT を優先的に行いたいときは @code{SELECT /*! HIGH_PRIORITY */} を使用します。 これは、たとえ誰かが書き込みを待っていたとしても、その SELECT は 実行されます。 @item 複数行 @code{INSERT} 文の使用。 これは多くのレコードを一つの SQL コマンドで 挿入することが出来ます。 (多くの SQL サーバーがこれをサポートしています) @item 大きなデータの読み込みには @code{LOAD DATA INFILE} を使用します。 This if faster than normal inserts and will be even faster when @code{myisamchk} is integrated in @code{mysqld}. @item 一意の値を作るために、 @code{AUTO_INCREMENT} を使用します。 @item 動的テーブルフォーマットの使用時には、フラグメンテーションを避けるために、 @code{OPTIMIZE TABLE} を時々使用します。 @xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}. @item 可能ならば @code{HEAP} テーブルをスピードアップのために使用します. @xref{Table types}. @item 通常の Web サーバーの設定ならば、イメージはファイルに保存すべきです。 データベースには、それらファイルの参照(パスとか)のみを入れます。 この主な理由は、通常の Web サーバーはデータベースよりもコンテンツを よりよくキャッシュしてくれるからです。 それでファイルを使用するなら、 速いシステムをより簡単に得ることができます。 @item 重要でないデータで、よくアクセスされる物は、メモリテーブルにいれます。 (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. 名前は単純にしてください(customer テーブルでは @code{customer_name} の かわりに @code{name} を使うとか)。 他の SQL サーバーへの移植を考慮するなら、 名前は 18 文字より短くすべきです。 @item もし本当にハイ・スピードが必要なら、SQL サーバーがサポートしている物とは 違う、ローレベルのデータ保存のインターフェースに注目すべきです。 例えば、 @strong{MySQL} @code{MyISAM} を直接アクセスすることは、 SQL インターフェースを介してアクセスするよりも、2〜5倍速くなるでしょう。 これを可能にするには、そのデータは、アプリケーションと同じマシン上になくてはならず、 通常、一つのプロセスだけでアクセスされるべきです。 (なぜなら、外部ファイルロックは、とても遅いから)。 上の問題は、@strong{MySQL} サーバー内の @code{MyISAM} のローレベルのコマンドの 導入で解決できるでしょう。 (これはよりよいパフォーマンスを得ることの出来る、 簡単な方法の一つです)。 By carefully designing the database interface it should be quite easy to support this types of optimisations. @item 多くの場合、データベースからデータをアクセスする方が(接続を維持していれば)、 テキストファイルからデータをアクセスするよりも速いです。 なぜなら、 データベースはテキストファイルよりもコンパクトになり(数値データの場合)、 このため、ディスクアクセスが少なくなるからです。 また、行や項目を見つけるために、テキストファイルを解析する必要も省けます。 @item 複製もスピードアップに使用できるでしょう。 @xref{Replication}. @item @code{DELAY_KEY_WRITE=1} が定義されたテーブルは、インデックスの更新が速くなります。 これはそのインデックス・ファイルが閉じられるまでディスクに記録されないからです。 したがって、なにかが途中で @code{mysqld} をキルしてもテーブルが大丈夫なようにするため、 @code{mysqld} を起動する前には、@code{myisamchk} をそれらのテーブルに対して実行すべきです。 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/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 @code{MySQL} は、レコードのデータとインデックスを別のファイルに保存します。 他の多くの(ほとんど全て)データベースでは、同じファイルにデータとインデックスを 混在させて保存します。 我々は、最近のシステムには、@strong{MySQL} の選択の方が 良いと信じています。 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 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 You can't use only the index table to retrieve data for a query. @item The index data is harder to cache. @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 belive 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/crash-me-choose.htmy} 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/benchmark.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? @strong{MySQL} の初期の開発期には、@strong{MySQL} は我々のもっとも大口の顧客に合うように 機能が作成されました。 彼らは、いくつかのスウェーデン最大手の小売り業者 のために、倉庫に入れている(商品)データを取り扱います。 我々は、すべての店から、全ボーナス・カード取扱高の、その週間まとめを得ます。 そして、その店のオーナにとって有益な情報、その店の広告キャンペーンが お客にどの程度影響を及ぼすか、を提供することが、我々に求められています。 そのデータは、とても大きくて (約700万/月 回の取り扱い)、 我々はその顧客に提供する必要のあるデータを 4〜10年分、持っています。 我々は、カスタマーから、彼らがこのデータからできる新しいレポートに ”即時に”アクセスしたいという、要求を受けました。 我々はこれを、全ての月ごとの情報を圧縮した 'transaction' テーブルに 保存することで解決しました。 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. そのレポートは Web ページで、これは小さな perl スクリプトで動的に 作成されます。 この perl script は Web Page を分析し、SQL 文を 実行し、結果を挿入します。 We would have used PHP or mod_perl instead but they were not available at that time. 画像データのために、我々は簡単なツールを @code{C} でかきました。 これは SQL のクエリの結果を元に(結果にいくつか処理をして) GIF を提供します。 これも動的に perl スクリプト(@code{HTML} ファイルを分析する)から実行されます。 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. 我々はこれらを Sun Ultra SPARCstation (2x200 Mz) で扱っていますが、 なんの問題もありません。 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. 現在、我々はバイナリ互換のデータベースフォーマットを持っており (new in 3.23) 、我々はこれをアプリケーションのいくつかの部分に使用しはじめる事でしょう。 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 @strong{MySQL} ベンチマークスイート ここには @strong{MySQL} ベンチマークスイート(と @code{crash-me})の 技術上の解説が書かれるはずですが、まだ書かれていません。 現在、ベンチマークのコードと結果はソースの中の @file{sql-bench} ディレクトリにあります。 (もちろん Web ページ @uref{http://www.mysql.com/crash-me-choose.htmy} にも) なんの SQL 実装のパフォーマンスが良いのか悪いのかを、どんなユーザーに対しても 示すのがベンチマークです。 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 bechmarks are supposed to show what a standard installation can do for a single client. @code{crash-me} は、データベースがサポートする機能、能力、制限について、 実際にクエリを走らせて確認します。 例えば、以下のような事について調べます: @itemize @bullet @item サポートしている項目の型はなにか @item サポートするインデックスの最大数は @item どのような関数があるのか @item 受けれるクエリの大きさはどこまでか @item @code{VARCHAR} 型はどこまで大きくできるのか @end itemize @node Tools, Maintenance, MySQL Benchmarks, Top @chapter @strong{MySQL} ユーティリティ @menu * Programs:: 実行ファイルが行なうことは? * mysql:: コマンドラインツール * 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:: * myisampack:: The @strong{MySQL} compressed read-only table generator @end menu @cindex Environment variables @node Programs, mysql, Tools, Tools @section 様々な @strong{MySQL} プログラムの概要 サーバと通信する @code{mysqlclient} ライブラリを使用している全ての @strong{MySQL} クライアントは次の環境変数を使用します: @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 デフォルトのソケット; @code{localhost} への接続に使用される @item @code{MYSQL_TCP_PORT} @tab デフォルトの TCP/IP ポート @item @code{MYSQL_PWD} @tab デフォルトのパスワード @item @code{MYSQL_DEBUG} @tab デバッグオプション @item @code{TMPDIR} @tab 一時 tables/files が作成されるディレクトリ @end multitable @code{MYSQL_PWD} の使用は安全ではありません。 @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 @file{mysql} クライアントは、@code{MYSQL_HISTFILE} 環境変数に 指定されているファイルにコマンドラインの履歴を書き出します。 デフォルトの履歴ファイルは、 @file{$HOME/.mysql_history} で、@code{$HOME} は @code{HOME} 環境変数の値です。 @xref{Environment variables}. 全ての @strong{MySQL} プログラムは多くの様々なオプションを持ちます。種々 のオプションの完全な説明を得るにはスイッチ @code{--help} を使用してください。例 えば@code{mysql --help} を試してください。 オプションファイルで、全ての標準クライアントのデフォルトのオプションを 変更することが可能です。 @ref{Option files}. @strong{MySQL} プログラムを以下に示します: @table @code @cindex @code{myisamchk} @item myisamchk @strong{MySQL} テーブルをチェック, 最適化そして修復します。 @code{myisamchk} には多くの機能があるので、一章割り当てて説明しています。 @xref{Maintenance}. @cindex @code{make_binary_release} @item make_binary_release コンパイルされた @strong{MySQL} のバイナリリリースを作成します。これは他 の MySQL ユーザの利便のために、ftp で @code{ftp.tcx.se} の @file{/pub/mysql/Incoming} に送ることができます。 @cindex @code{msql2mysql} @item msql2mysql @code{mSQL} プログラムを @strong{MySQL} に変換するシェルスクリプト。全て のケースで処理できるわけではありませんが、変換時に良いスタートを与えます。 @cindex Scripts @cindex @code{mysql} @item mysql @code{mysql} は簡単な SQL シェル (GNU @code{readline} つき) です。これは対話的な使用や 非対話型問い合わせをサポートします。対話的に使用されると、ASCII テーブル 形式で結果が与えられます。フィルタとして使用されると、出力はタブで区切ら れます(これは起動時のオプションで他のものに変更できます)。 あなたは以下のように簡単にスクリプトを実行できます: @example shell> mysql database < script.sql > output.tab @end example クライアントのメモリが十分でないことによる問題がある場合は、 @code{--quick} スイッチを使用してください! これは結果を取り出すのに @code{mysql_store_result()} の代わりに @code{mysql_use_result()} を使用 するように @code{mysql} に強制させます。 @cindex @code{mysqlaccess} @item mysqlaccess ホスト, ユーザそしてデータベースの組合せで権限をチェックするためのスクリ プト。 @cindex @code{mysqladmin} @item mysqladmin 管理ユーティリティ。データベースの作成/破棄。reload (新しいユーザの読み 込み) と refresh (ディスクへのテーブルのフラッシュ, ログファイルの再オー プン)。サーバのバージョンと処理と状態情報も与えます。 @xref{mysqladmin, , @code{mysqladmin}}. @cindex @code{mysqlbug} @item mysqlbug @strong{MySQL} バグレポートスクリプト。 このスクリプトは @strong{MySQL} メーリングリストにバグレポートを出す際、 常に使用します。 @cindex @code{mysqld} @item mysqld SQL デーモン。これは常に実行されてます。 @cindex @code{mysqldump} @item mysqldump @strong{MySQL} データベースの SQL ステートメントまたはタブで区切られたテ キストのファイルにダンプします。Igor Romanenko によって独創的にエンハン スされたフリーウェア。 @xref{mysqldump, , @code{mysqldump}}. @cindex @code{mysqlimport} @item mysqlimport 一つまたは複数のテキストファイルをそれぞれのテーブルに読み込みます。@code{LOAD DATA INFILE} でサポートされる全ての形式を使用できます。 @xref{mysqlimport, , @code{mysqlimport}}. @cindex @code{mysqlshow} @item mysqlshow データベース, テーブル, 項目そしてインデックスについての情報を表示します。 @cindex @code{mysql_install_db} @item mysql_install_db @strong{MySQL} 承認テーブルをデフォルトの権限で作成します。これは通常、最 初の @strong{MySQL} リリースを新しいシステム上にインストールする時に一回 だけ実行されます。 @cindex @code{replace} @item replace @code{msql2mysql} で使用されるバイナリ。ファイル内または標準入力上の文字列を変 換するユーティリティプログラム。より長い文字列に最初に適合するため有限状 態マシンを使用します。文字列を交換するために使用できます。例えば、 @code{a} と @code{b} を与えられたファイル内で交換します: @example shell> replace a b b a -- file1 file2 ... @end example @cindex @code{safe_mysqld} @item safe_mysqld @code{mysqld} デーモンをいくつかの安全な機能で開始します。エラー時には再起動し、 実行時情報をログファイルへ記入します。 @end table @cindex Scripts @cindex @code{mysql} @node mysql, mysqladmin, Programs, Tools @section コマンドラインツール ( @code{mysql} ) @code{mysql} はシンプルな SQL shell です(GNU @code{readline} を持っています). これは対話モードと、非対話モードを持っています。 対話モードで使用された場合、 クエリの結果は ASCII テーブルのフォーマットで与えられます。 非対話モードで使用された場合(例えばフィルターとして)、結果はタブ区切りの フォーマットで返ります。 (出力フォーマットはコマンドラインのオプションで変更できます) 以下のようにしてスクリプトを実行できます: @example shell> mysql database < script.sql > output.tab @end example もしクライアントでメモリー不足の問題が出た場合、@code{--quick} オプションを 使用します! これは @code{mysql} に、結果セットを取得する際に、 @code{mysql_store_result()} ではなく @code{mysql_use_result()} を 使用させます。 @code{mysql} の使用はとても簡単です: @code{mysql database} や @code{mysql --user=user_name --password=your_password d atabase} のようにしてはじめます。 SQL 文を入力し、一文を @samp{;}, @samp{\g} or @samp{\G} で終え、 return/enter を押します。 @code{mysql} は以下のオプションをサポートします: @table @code @item -?, --help help を表示して終了 @item -A, --no-auto-rehash 自動リハッシュをしない。 テーブルとフィールドの取得には 'rehash' を使用しなくては なりません。 これは @code{mysql} の起動を速くします。 @item -B, --batch 結果をタブ区切り、1レコードは1行で出力します。 history ファイルは使用しません。 @item -C, --compress サーバー・クライアント間の通信を圧縮します @item -#, --debug[=...] デバッグログ。 デフォルトは 'd:t:o,/tmp/mysql.trace' @item -D, --database=.. 使用するデータベース。 これは @code{my.cnf} ファイルが便利です @item -e, --execute=... コマンドを実行して終了。 (Output like with --batch) @item -E, --vertical 垂直にレコードを出力します。 このオプションを指定していなくても、 SQL 文を @code{\G} で終了した場合、同じように垂直に出力します。 @item -f, --force SQL エラーがおきたとしても、処理を続けます @item -i, --ignore-space 関数名の後ろについたスペースを無視します @item -h, --host=... 指定したホストに接続します @item -H, --html 結果を HTML フォーマットで返します @item -L, --skip-line-numbers エラーの起きた行の番号を書きません。 これはエラーメッセージを含んだ結果を 比較する場合に便利です。 @item -n, --unbuffered それぞれのクエリ毎にバッファをフラッシュします @item -N, --skip-column-names 結果に、フィールド名を書き出しません。 @item -O, --set-variable var=option 変数に値をセットします。 @code{--help} lists variables @item -o, --one-database デフォルトのデータベースのみ更新します。 これは update ログファイルを 使用して更新する場合、他のデータベースの更新を避けたい時に便利です。 @item -p[password], --password[=...] サーバーに接続する際のパスワード。 もしパスワードがコマンドラインに 指定されていなかった場合、tty 上でパスワードが問い合わされます。 @code{-p} を使用する場合、このオプションとパスワードの間には スペースが不要だということに注意してください。 @item -P --port=... 接続に使用する TCP/IP ポート番号 @item -q, --quick 結果をキャッシュせず、一レコードづつ出力します。 これはもし出力を中止した場合、サーバーを遅くします。 ヒストリファイルは使用しません。 @item -r, --raw エスケープ処理をしないで値を書き出します。 @code{--batch} とともに使用されます @item -s, --silent 静粛モード @item -S --socket=... 接続に使用する ソケットファイル @item -t --table 表の形式で出力します。 これは batch モード以外でのデフォルトです。 @item -T, --exit-info Only used when debugging. --exit-info=0 will print some usage information one exit. @item -u, --user=# ログインユーザー名 @item -U, --safe-updates[=#], --i-am-a-dummy[=#] キーを使用する @code{UPDATE} and @code{DELETE} のみを行います。 これは後述します。 このオプションをもし @code{my.cnf} に書いている場合は、 @code{--safe-updates=0} でこのオプションをリセットできます。 @item -v, --verbose 冗長出力。 (-v -v -v は表形式の出力を与える) @item -V, --version バージョンを表示して終了 @item -w, --wait もし接続が落ちた場合、中断しないで、待って、再試行します。 @end table もしコマンドラインで 'help' と打った場合、@code{mysql} はサポートする コマンドを表示します: @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 @code{status} コマンドは、今使用している 接続とサーバーについての情報をいくつか表示します。 もし @code{--safe-updates} モードで使用している場合、 @code{status} は あなたのクエリに影響する @code{mysql} 変数の値を表示します。 初心者に便利な起動オプション(@strong{MySQL} 3.23.11 で導入されました)は、 @code{--safe-mode} (あるいは @code{--i-am-a-dummy}) で、 これは @code{DELETE FROM table_name} を @code{WHERE} 節を忘れて 実行しようとした場合のためにあります。 このオプションが使用されると、 @code{mysql} は接続時に @strong{MySQL} サーバーに 以下のようなコマンドを送ります: @example SET SQL_SAFE_UPDATES=1,SQL_SELECT_LIMIT=#select_limit#, SQL_MAX_JOIN_SIZE=#max_join_size#" @end example ここで @code{#select_limit#} と @code{#max_join_size#} は変数で これらは @code{mysql} コマンドからセット可能です。 @xref{SET OPTION, @code{SET}}. この効果は: @itemize bullet @item もし @code{WHERE} 節でキーを使用していなければ、@code{UPDATE} や @code{DELETE} は許可されません。 しかし、 @code{LIMIT} を使用すれば @code{UPDATE/DELETE} を 強制実行できます: @example UPDATE table_name SET not_key_column=# WHERE not_key_column=# LIMIT 1; @end example @item 全ての多きな結果は自動的に @code{#select_limit#} レコードまでに抑えられます。 @item 評価に @code{#max_join_size} 以上の行を必要とするであろう @code{SELECT} は 中断されます。 @end itemize @node mysqladmin, mysqldump, mysql, Tools @section @strong{MySQL} サーバーの管理 ( @code{mysqladmin} ) 管理オペレーションを実行するためのユーティリティ。シンタックスは: @example shell> mysqladmin [OPTIONS] command [command-option] command ... @end example @code{mysqladmin --help} によって、オプションの一覧を手にいれることができます。 現在の @code{mysqladmin} は以下のコマンドをサポートします: @multitable @columnfractions .3 .7 @item create databasename @tab データベースの作成 @item drop databasename @tab データベースとテーブルの全削除。 @item extended-status @tab サーバーから拡張ステータスを取得。 @item flush-hosts @tab キャッシュされている全ホストをフラッシュ。 @item flush-logs @tab 全てのログをフラッシュ @item flush-tables @tab 全てのテーブルをフラッシュ @item flush-privileges @tab 許可テーブルの再読み込み (reload と同じ) @item kill id,id,... @tab mysql スレッドの kill. @item password new-password @tab 古いパスワードを new-password に変更 @item ping @tab mysqld が生きているかチェック @item processlist @tab 現在活動中の mysql スレッドを表示 @item reload @tab 許可テーブルの再読み込み @item refresh @tab 全テーブルをフラッシュし、ログファイルを一度閉じて開きます。 @item shutdown @tab サーバーをダウンさせます。 @item slave-start @tab Start slave replication thread @item slave-stop @tab Stop slave replication thread @item status @tab サーバーから短いステータスを得ます。 @item variables @tab 変数の表示 @item version @tab サーバーからバージョンを得ます。 @end multitable 全てのコマンドは、ユニークなプレフィックスで省略可能です。 例えば: @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 @code{mysqladmin status} コマンドの結果は、以下の項目を持ちます: @multitable @columnfractions .3 .7 @item Uptime @tab @strong{MySQL} サーバーの起動秒数 @item Threads @tab 稼働中のスレッド数 (clients) @item Questions @tab @code{mysqld} が開始してからのクライアントからのクエリ数 @item Slow queries @tab @code{long_query_time} 秒より時間のかかったクエリの数 @item Opens @tab @code{mysqld} が開いたテーブル数 @item Flush tables @tab @code{flush ...}, @code{refresh} and @code{reload} コマンドの実行回数 @item Open tables @tab 現在開かれているテーブルの数 @item Memory in use @tab mysqld のコードによって直接割り当てられたメモリ (only available when @strong{MySQL} is compiled with --with-debug) @item Max memory used @tab mysqld のコードによって直接割り当てられる最大メモリー量 (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 @strong{MySQL} データベースとテーブルから、構造とデータをダンプ ( @code{mysqldump} ) データベース、あるいは、 バックアップ、他のSQLサーバーへのデータを移動を目的としたデータのまとまり、 これらをダンプするためのユーティリティ。 ダンプは、テーブルの作成のための SQL 文を含みます。 @example shell> mysqldump [OPTIONS] database [tables] OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...] OR mysqldump [OPTIONS] --all-databases [OPTIONS] @end example もしテーブルを指定せず、@code{--databases} や @code{--all-databases} を 使用しなかったなら、データベースの全てのテーブルがダンプされます。 @code{mysqldump --help} によって、オプションの一覧を手にいれることができます。 もし @code{mysqldump} を @code{--quick} や @code{--opt} なしで実行するならば、 @code{mysqldump} は結果を表示する前に、結果をメモリに全てロードすることに 注意してください。 これは大きなデータベースをダンプする際に問題になるでしょう。 @code{mysqldump} は以下のオプションをサポートします: @table @code @item --add-locks テーブルのダンプの前に @code{LOCK TABLES} 文を追加し、 テーブルのダンプ後に @code{UNLOCK TABLE} 文を追加します。 ( あとで @strong{MySQL} に挿入するときにこれは速くなります ). @item --add-drop-table テーブルの create 文の前に、@code{drop table} 文を追加します。 @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 キーワード(予約語) と同じ名前をもつフィールドの作成を許します。 これは、それぞれのフィールドの前に、テーブル名を付け足します。 @item -c, --complete-insert 完全な INSERT 文(フィールド名を書いた文) を使用します。 @item -C, --compress もしサーバーとクライアントの双方が圧縮をサポートしているならば、 両者の間で行われる通信を全て圧縮します。 @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 @code{INSERT DELAYED} コマンドを使用してレコードを INSERT します。 @item -e, --extended-insert 新しいマルチライン @code{INSERT} 構文を使用します。(これはあとで挿入する際、 よりコンパクトかつ速くなります。) @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=... これらのオプションは @code{-T} とともに使用され、 @code{LOAD DATA INFILE} と同様の意味をなします。 @xref{LOAD DATA, , @code{LOAD DATA}}. @item -F, --flush-logs ダンプする前に、 @strong{MySQL} サーバーのログファイルをフラッシュします。 @item -f, --force, ダンプの途中で SQL エラーが発生しても、ダンプを続けます。 @item -h, --host=.. 指定されたホストの @strong{MySQL} サーバーからダンプします。 デフォルトのホストは @code{localhost}. @item -l, --lock-tables. ダンプを開始するとき全てのテーブルをロックします。 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 テーブルの作成情報( @code{CREATE TABLE} 文) を書き出しません。 @item -d, --no-data テーブル内のレコードを書き出しません。 これはテーブルの構造だけを取り出したいときにとても便利です! @item --opt @code{--quick --add-drop-table --add-locks --extended-insert --lock-tables} と同じ. @strong{MySQL} サーバーから読み出す時間を最短にしてくれます。 @item -pyour_pass, --password[=your_pass] サーバーに接続する際のパスワードを与えます。 もし @samp{=your_pass} 部分を与えなかった場合は、 @code{mysqldump} はパスワードのプロンプトをだします。 @item -P port_num, --port=port_num サーバーに接続する際に使用する TCP/IP ポート番号。 (これは @code{localhost} 以外のホストへの接続に使用されます。 @code{localhost} の場合は、Unix ソケットが使用されます。) @item -q, --quick クエリをバッファにため込みません。stdout に直接出します。 @code{mysql_use_result()} をこれに使用しています。 @item -S /path/to/socket, --socket=/path/to/socket @code{localhost} に接続する際のソケットファイルの指定 (デフォルトは /tmp/mysql.sock ) @item --tables Overrides option --databases (-B). @item -T, --tab=path-to-some-directory 与えられたテーブル毎に、 SQL CREATE 文を含む @code{table_name.sql} ファイル、 データを含む @code{table_name.txt} ファイルを作成します。 @strong{NOTE}: これは @code{mysqld} デーモンが走っているマシン上で @code{mysqldump} を 実行する場合にだけ、動作します。 @code{.txt} ファイルのフォーマットは、 @code{--fields-xxx} と @code{--lines--xxx} オプションに従います。 @item -u user_name, --user=user_name サーバーに接続する際の @strong{MySQL} ユーザー名。 デフォルトでは、Unix のログイン名になります。 @item -O var=option, --set-variable var=option 変数の値をセット。 可能な変数は後で示しします。 @item -v, --verbose 冗長モード。 プログラムが何を行っているかより表示します。 @item -V, --version バージョンを示して終了。 @item -w, --where='where-condition' 選択されたレコードのみをダンプ: クオートは必須です! @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 @code{mysqldump} の普通の使用はデータベースのバックアップでしょう。 @xref{Backup}. @example mysqldump --opt database > backup-file.sql @end example 他の @strong{MySQL} サーバーへデータベースをコピーする場合にも便利です: @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 テキストファイルからデータを取り込む ( @code{mysqlimport} ) @code{mysqlimport} は、@code{LOAD DATA INFILE} SQL 構文を、 コマンドラインインターフェースで提供します。 @code{mysqlimport} のオプションのほとんどが、 @code{LOAD DATA INFILE} への同じオプションに対応します。 @xref{LOAD DATA, , @code{LOAD DATA}}. @code{mysqlimport} の実行は以下のようにします: @example shell> mysqlimport [options] database textfile1 [textfile2....] @end example @code{mysqlimport} は、コマンドラインの引数に与えられたファイル名の拡張子を取り、 拡張子を取った後の名前を、ファイルの内容を取り込むテーブルの名前とします。 例えば、@file{patient.txt}, @file{patient.text}, @file{patient} という ファイルは全て、@code{patient} とという名前のテーブルに取り込まれます。 @code{mysqlimport} は以下のオプションをサポートします: @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 クライアントとサーバーの両方が圧縮をサポートしているなら、 クライアント・サーバー間でやり取りされる全ての情報を圧縮します。 @item -#, --debug[=option_string] プログラムのトレース(デバッグ) @item -d, --delete テキストファイルを取り込む前にテーブルを空にします。 @item --fields-terminated-by=... @itemx --fields-enclosed-by=... @itemx --fields-optionally-enclosed-by=... @itemx --fields-escaped-by=... @itemx --lines-terminated-by=... これらのオプションは、@code{LOAD DATA INFILE} の対応する文節と同じ意味になります。 @xref{LOAD DATA, , @code{LOAD DATA}}. @item -f, --force エラーを無視します。例えば、テキストファイルを取り込むテーブルがない場合、 残りのファイルの処理に移ります。 @code{--force} がなければ、 テーブルがなければ @code{mysqlimport} は終了します。 @item --help ヘルプを表示して終了。 @item -h host_name, --host=host_name 名前を指定された @strong{MySQL} サーバーにデータを取り入れます。 デフォルトでは @code{localhost}. @item -i, --ignore @code{--replace} オプションの説明を見てください。 @item -l, --lock-tables それぞれのテキストファイルを処理する前に、書き込まれる @strong{全ての}テーブルをロックします。 これは確実に、すべてのテーブルをサーバ上で同期させます。 @item -L, --local クライアントからの入力ファイルを読みます。 デフォルトでは、@code{localhost} に接続した場合、テキストファイルは サーバー上にあると仮定されます。(@code{localhost} はデフォルト値) @item -pyour_pass, --password[=your_pass] サーバーに接続するときに使用するパスワード。 もし @samp{=your_pass} のところにパスワードを書かなければ、 @code{mysqlimport} はパスワードのためのプロンプトをだします。 @item -P port_num, --port=port_num ホストに接続するための TCP/IP ポート番号。 (これは @code{localhost} を除くホストへの接続に使用します。 @code{localhost} へは、UNIX ソケットを使用します。) @item -r, --replace @code{--replace} と @code{--ignore} オプションは、 入力されているレコードのユニークキーの値が、 既に存在しているレコードのユニークキーの値と同じ場合、 その入力されているデータの取り扱いを決定します。 もし @code{--replace} が指定されているなら、 既にあるレコードは新しく読まれたレコードに置き換えられます。 もし @code{--ignore} が指定されているなら、 入力された物は無視されます。 どちらのオプションも指定していない場合、 キーの値が重なっているとエラーを発し、 テキストファイルの残りの部分は無視されます。 @item -s, --silent 静粛モード。エラーだけ出力します。 @item -S /path/to/socket, --socket=/path/to/socket @code{localhost} への接続時に使用するソケットファイルを指定します。 @item -u user_name, --user=user_name サーバーの接続に使用する @strong{MySQL} ユーザー名の指定。 デフォルトは、Unix のログイン名。 @item -v, --verbose 冗長モード。プログラムがしている事について多く出力します。 @item -V, --version バージョンを表示して終了。 @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}) @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 @strong{MySQL} の圧縮された読み込み専用テーブルジェネレータ ( @code{myisampack} ・ @code{pack_isam} ) @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. @code{myisampack} は、 1 @strong{MySQL} ライセンス以上または @strong{MySQL} サポートを注文した時に得 られる特別なユーテリティです。これらはバイナリだけの配布のため、 いくつかのプラットフォーム上でだけに有効です。 In the following we only talk about @code{myisampack}, but everything is also true for @code{pack_isam}. @code{myisampack} はテーブル内の各項目を別々に圧縮するように働きます。展開のため の情報は、テーブルがオープンされた時にメモリに読まれます。これは、正確に1レコー ドだけを展開する必要があるような、個々のレコードへのアクセス時にとても良 い性能を与えます。MSDOS 上の Stacker 使用時のように、ディスクブロックは そんなに大きくありません。 通常、@code{myisampack} はデータファイルを 40〜70% にパックします。 @strong{MySQL} は圧縮されたテーブルでメモリマップ (@code{mmap()}) を使用します。 @code{mmap()} が働かない場合は、通常のファイルの読み書きを使用します。 現在 @code{myisampack} には2つの制限があります: @itemize @bullet @item パック後、テーブルは読み込み専用になります。 @item @code{myisampack} can also pack @code{BLOB} or @code{TEXT} columns. The older @code{pack_isam} could not do this. @end itemize これらの制限の修正は TODO にありますが、優先度は低いです。 @code{myisampack} は以下のようにして起動します: @example shell> myisampack [options] filename ... @end example それぞれのファイル名はインデックスファイル(@file{.MYI})の名前です。 もしデータディレクトリにカレントディレクトリを移動していないなら、 ファイルのパスを指定しなくてはなりません。@file{.MYI} 拡張子は 省略することが可能です。 @code{myisampack} は以下のオプションをサポートします: @table @code @item -b, --backup @code{tbl_name.OLD} としてバックアップを作成します. @item -#, --debug=debug_options デバック出力。@code{debug_options} は @code{'d:t:o,filename'}. @item -f, --force 一時ファイルが存在していようが、サイズが大きくなろうが、強制的にテーブルを パックします。 @code{myisampack} はテーブルを圧縮している間、 一時ファイルを @file{tbl_name.TMD} という名前で作成します。 もし @code{myisampack} を途中で kill した場合、 @file{.TMD} ファイルが消されて いない事があります。通常、@code{myisampack} は @file{tbl_name.TMD} ファイルが 既に存在する場合はエラーで終了します。 @code{--force} を使用すると、 @code{myisampack} はそのような場合でもテーブルをパックします。 @item -?, --help ヘルプメッセージを出力して終了。 @item -j big_tbl_name, --join=big_tbl_name 全てのテーブルをコマンドラインで指定した @code{big_tbl_name} 一つに まとめます。結合される全てのテーブル定義は同じでなければなりません (同じ項目名、同じ項目型、同じインデックス、等) @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.ISD -rw-rw-r-- 1 monty my 53248 Apr 17 19:00 station.ISM -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.ISD -rw-rw-r-- 1 monty my 55296 Apr 17 19:04 station.ISM -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 @strong{MySQL} installation @menu * Table maintenance:: Using @code{myisamchk} for 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 テーブルのメンテナンス、クラッシュからの修復のための @code{myisamchk} 使用 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}. MyISAM テーブル (@code{.MYI} and @code{.MYD}) の検査・修復には @code{myisamchk} を 使用します。 ISAM テーブル (@code{.ISM} and @code{.ISD}) の検査・修復には @code{isamchk} を 使用します。 @xref{Table types}. 以下の文は @code{myisamchk} について述べていますが、@code{isamchk} にもすべて 当てはまります。 @code{myisamchk} ユーティリティは、データベースのテーブルの情報を得たり、 チェックしたり、テーブルの修復や最適化に使用します。 以下のセクションでは、 @code{myisamchk} の起動方法(オプションの説明も含む)、 テーブルの保守スケジュールのたて方、 @code{myisamchk} の色々な機能の使い方を述べます。 もし @code{mysqld} を @code{--skip-locking} で走らせているなら、 (これは Linux など、いくつかのシステムでデフォルトです)、 @code{mysqld} があるテーブルを使用しているとき、あなたは同じテーブルに対して @code{myisamchk} で確実に検査できません。もし @code{myisamchk} 中に、 だれも @code{mysqld} を通してそのテーブルをアクセスしないのが確実なら、 テーブルを検査する前に @code{mysqladmin flush-tables} を行うべきです。 そうでない場合、テーブルの検査中は @code{mysqld} を落とすべきです。 もし @code{mysqld} がテーブルを更新中に @code{myisamchk} を実行した場合、 テーブルが変更された旨のワーニングがでるでしょう。 もし @code{--skip-locking} を使用していないなら、いつでも @code{myisamchk} は 使用できます。これを実行している間、全てのテーブルを更新するクライアントは @code{myisamchk} が準備できるまで待ちます。 もし @code{myisamchk} をテーブルの修復、最適化に使用するなら、その最中に、 @code{mysqld} がそのテーブルを絶対に使用しないようにしなければ なりません。これは @code{--skip-locking} を使用している場合に起こりえます。 もし @code{mysqld} をダウンさせていないなら、最低 @code{myisamchk} 実行前に、 @code{mysqladmin flush-tables} を実行すべきです。 テーブルの修復と最適化のために、ほとんどの場合、 @code{OPTIMIZE TABLES} コマンドが使用できます。しかしこれは @code{myisamchk} に比べて、 遅くて確実でもありません。(fatal error発生時の場合)。これは その反面、使用方法が簡単でテーブルのフラッシュを気にかける必要がありません。 @xref{OPTIMIZE TABLE, , @code{OPTIMIZE TABLE}}. @menu * myisamchk syntax:: @code{myisamchk} 起動構文 * myisamchk memory:: @code{myisamchk} メモリ使用 @end menu @node myisamchk syntax, myisamchk memory, Table maintenance, Table maintenance @section @code{myisamchk} 起動構文 @code{myisamchk} は以下のようにして起動します: @example shell> myisamchk [options] tbl_name @end example @code{options} に、あなたが @code{myisamchk} にさせたいことを指定します。 その説明は後述します。(@code{myisamchk --help} と実行すれば、オプションの一覧が取れます)。 オプションがなければ、 @code{myisamchk} は単にテーブルを検査するだけです。 より多くの情報を得たい、あるいは、 @code{myisamchk} に誤り訂正の行動を取らせる事については、後述します。 @code{tbl_name} は検査したいテーブル名です。 もしどこか違うディレクトリにあるデータベースに対して @code{myisamchk} を走らせたいなら、 @code{myisamchk} にはファイルがどこにあるかわからないので、 ファイルのパスを指定しなければなりません。 実際、 @code{myisamchk} はあなたが使用しているファイルがデータベースのディレクトリにあるかどうかは考慮しません; ほかの場所にデータベーステーブルのファイルをコピーし、そのコピーしたファイルに対して 回復操作を実行することができます。 @code{myisamchk} コマンドラインには、複数のテーブル名が指定できます。 また、インデックスファイル名(@file{.MYI} 接尾語のついたファイル)も指定でき、 さらに @file{*.MYI} とすれば、ディレクトリ内の全てのテーブルが指定できます。 例えば、現在のカレントディレクトリがデーターベースディレクトリならば、 そのディレクトリ内の全てのテーブルは、以下のようにして検査できます: @example shell> myisamchk *.MYI @end example データベースディレクトリに入っていない場合、 パスを指定することにより全てのテーブルが検査できます: @example shell> myisamchk /path/to/database_dir/*.MYI @end example @strong{MySQL} データディレクトリのパスにワイルドカードを使用することにより、 データベースの全てのテーブルも検査できます: @example shell> myisamchk /path/to/datadir/*/*.MYI @end example @code{myisamchk} は以下のオプションを持ちます: @table @code @item -a, --analyze キーの分布(配置)を分析します。 これは @strong{MySQL} のいくつかの結合を速くします。 @item -#, --debug=debug_options デバッグログの出力。 @code{debug_options} はよく @code{'d:t:o,filename'} とされます。 @item -d, --description テーブルに関するいくらかの情報を表示します @item -e, --extend-check テーブルを非常に徹底的に検査します。 極端な場合にだけで必要とされます。 通常 @code{myisamchk} は、このオプションなしで全てのエラーを見つけるはずです。 @item -f, --force 古い一時的なファイルを上書きします。 @code{myisamchk} を @code{-r} なしで走らせてテーブルを検査しているときに、 @code{-f} を使用するならば、 @code{myisamchk} はチャックでエラーが出たテーブルに対して、 自動的に @code{-r} を伴って、検査を再開します。 @item --help ヘルプを表示して終了。 @item -i, --information 検査されたテーブルの統計情報を表示。 @item -k #, --keys-used=# @code{-r} と共に使用します。 NISAM テーブルハンドラーに最初の @code{#} インデックスだけを更新するように指示します。 If you are using MyISAM tells which keys to use, where each binary bit stands for one key (First key is bit 0). これはインサートを速くします! 非アクティブになったインデックスは、@code{myisamchk -r} を使用すれば再びアクティブになります。 @item -l, --no-symlinks 修復時にシンボリックリンクを追いません。 通常、@code{myisamchk} はシンボリックリンクが指し示すテーブルも修復します。 @item -q, --quick @code{-r} と共に使用され、修復を早く行います。 通常、オリジナルのデータファイルは検査されません; 二回 @code{-q} を指定すると、強制的にオリジナルのデータファイルも使用します。 @item -r, --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). @item -o, --safe-recover 修復モード。 古い修復方法を使用します (reads through all rows in order and updates all index trees based on the found rows); これは @code{-r} よりも遅いですが、 @code{-r} が扱えないものも扱えます。 Normally one should always first repair with @code{-r} and only if this fails use @code{-o}. @item -O var=option, --set-variable var=option 変数に値を入れます。可能な変数は後述します。 @item -s, --silent 静粛モード。 エラーのみを出力します。 二度 @code{-s} を指定すると(@code{-ss})、@code{myisamchk} は ほとんど出力をしなくなります。 @item -S, --sort-index インデックスブロックのソート。 これは、アプリケーションでの ``read-next'' を速くします。 @item -R index_num, --sort-records=index_num インデックスに従ってソート。 これはあなたのデータをよりよく配置し、このインデックスへの @code{SELECT}, @code{ORDER BY} オペレーションを速くします。 (この操作の最初のソートは非常に遅くなるかもしれません!) テーブルのインデックスの番号をみつけるには @code{SHOW INDEX} を使用しますが、 これは @code{myisamchk} がテーブルのインデックスを見つけるのと同じ順序で行います。 インデックス番号は 1 から始まります。 @item -u, --unpack @code{pack_isam} でパックされたテーブルをアンパックします。 @item -U, --update-status 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{--fast} 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 -v, --verbose 冗長モード。より多く情報を出力します。 @code{-d} と @code{-e} オプションと共に使用できます。 @code{-v} を複数指定すると(@code{-vv}, @code{-vvv})、もっと出力が多くなります! @item -V, --version @code{myisamchk} バージョンを表示して終了。 @item -w, --wait テーブルがロックされていたら待ちます。 @end table @code{--set-variable} (@code{-O}) オプションで可能な変数: @example key_buffer_size current value: 16776192 read_buffer_size current value: 262136 write_buffer_size current value: 262136 sort_buffer_size current value: 2097144 sort_key_blocks current value: 16 decode_bits current value: 9 @end example @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 at time. @node myisamchk memory, , myisamchk syntax, Table maintenance @section @code{myisamchk} メモリ使用 @code{myisamchk} を走らす上でメモリーの配分は重要です。 @code{myisamchk} は @code{-O} オプションで定義した以上のメモリは使用しません。 とても大きなファイルのたいして @code{myisamchk} をかけたいなら、 メモリーをどれくらい使用するかを最初に決めなくてはなりません。 デフォルトは固定で約 3M だけを使用します。大きな値を使用することで、 @code{myisamchk} をより速く動作できます。 例えば、32MBytesのRAMがあるなら、以下のように指定できます (他のオプションも指定して): @example shell> myisamchk -O sort=16M -O key=16M -O read=1M -O write=1M ... @end example @code{-O sort=16M} の使用は多くの場合おそらく十分でしょう。 しかし、@code{myisamchk} は @code{TMPDIR} 内に一時ファイルを使用します。 @code{TMPDIR} がメモリファイルシステムを指している場合は、簡単に out of memory エラーを得るでしょう。 If this happens, set @code{TMPDIR} to point at some directory with more space and restart @code{myisamchk} @node Maintenance regimen, Table-info, Table maintenance, Maintenance @section テーブルの保守体制の設定 問題が発生するまで待つより、定期的にテーブルを検査する方がよりよい考えです。 保守目的には、@code{myisamchk -s} でテーブルを検査するのがよいでしょう。 @code{-s} オプションはサイレントモードなので、エラーが起きた場合にだけメッセージを出力します。 @tindex .pid (process ID) file サーバーを開始するときにテーブルを検査するのもよい考えです。 例えば、更新最中にマシンがリブートされたなら、全てのテーブルに関して その影響がないか検査する必要があります。(これは``expected crashed table''です) リブート後にもし古い @file{.pid} ファイル(プロセスID) があるならば、 24時間以内に変更されたテーブルに対して @code{myisamchk} を走らせて検査させるように、 @code{safe_mysqld} にテストを追加しても構いません。 (@file{.pid} ファイルは @code{mysqld} 起動時に作られ、通常修了時に消されます。 スタート時に @file{.pid} ファイルが存在するなら @code{mysqld} が異常終了したことを示します。) 良いテストは、@file{.pid} ファイルの作成時間以降に変更された 全てのテーブルを検査するテストです。 通常のシステム運用中にもテーブルを検査すべきです。 TcX では、週に一度、 @code{cron} を使用して重要なテーブルを検査しています。 @file{crontab} ファイルには以下のように記述します: @example 35 0 * * 0 /path/to/myisamchk -s /path/to/datadir/*/*.MYI @end example これは壊れたテーブルの情報を出力しますので、必要とあらば検査、修復が行えるわけです。 予想外の事故で壊れたテーブル(ハードウェアのトラブルが原因で崩壊)を除き、 2,3年間、テーブルは壊れたことはありません(これは本当に本当です)。 ので、一週間に一度のチェックでも十分です。 24時間以内に変更された全てのテーブルに対して、 @code{myisamchk -s} を毎晩実行する事を勧めます。 そうすれば、あなたは我々と同じぐらいに @strong{MySQL} を 信頼することになります。 @node Table-info, Crash recovery, Maintenance regimen, Maintenance @section テーブル情報取得 テーブルから詳細/統計を得るためには、次の方法を使用します。後でさらに詳細な情 報をいくつか説明します。 @table @code @item myisamchk -d tbl_name @code{myisamchk} を ``describe mode'' で実行し、テーブルの説明記述を作ります。 @code{--skip-locking} を指定して @strong{MySQL} サーバーを起動した場合、 @code{myisamchk} は myisamchk 実行中に更新されたテーブルについてエラーを報告します. しかし @code{myisamchk} は describe mode ではテーブルを変えないので、 データを破壊する危険性はありません。 @item myisamchk -d -v tbl_name @code{myisamchk} がしていることに関する、より多くの情報を作り出すには、 @code{-v} をつけて冗長モードで走らせるようにします。 @item myisamchk -eis tbl_name テーブルから最も重要な情報だけを示します。 テーブル全体を読まなければならないので、遅いです。 @item myisamchk -eiv tbl_name @code{-eis} と似ているが、何を行っているかを表示します。 @end table @code{myisamchk -d} 出力の例: @example ISAM file: company.MYI Data records: 1403698 Deleted blocks: 0 Recordlength: 226 Record format: Fixed length 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 @code{myisamchk -d -v} 出力の例: @example ISAM file: company.MYI Isam-version: 2 Creation time: 1996-08-28 11:44:22 Recover time: 1997-01-12 18:35:29 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 Record format: Fixed length table description: Key Start Len Index Type Root Blocksize Rec/key 1 2 8 unique double 15845376 1024 1 2 15 10 multip. text packed stripped 25062400 1024 2 3 219 8 multip. double 40907776 1024 73 4 63 10 multip. text packed stripped 48097280 1024 5 5 167 2 multip. unsigned short 55200768 1024 4840 6 177 4 multip. unsigned long 65145856 1024 1346 7 155 4 multip. text 75090944 1024 4995 8 138 4 multip. unsigned long 85036032 1024 87 9 177 4 multip. unsigned long 96481280 1024 178 193 1 text @end example @code{myisamchk -eis} 出力の例: @example Checking ISAM file: company.MYI 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 Recordblocks: 1403698 Deleteblocks: 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 @code{myisamchk -eiv} 出力の例: @example Checking ISAM file: company.MYI Data records: 1403698 Deleted blocks: 0 - check file-size - check delete-chain 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 Recordblocks: 1403698 Deleteblocks: 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 上で使用されたテーブルのデータファイルサイズをここに示します: @example -rw-rw-r-- 1 monty tcx 317235748 Jan 12 17:30 company.ISD -rw-rw-r-- 1 davida tcx 96482304 Jan 12 18:35 company.ISM -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.MYI @end example @code{myisamchk} が生成する情報の説明を以下に示します。 ``keyfile'' はインデックスファイルです。 ``Record'' と ``row'' は同義です。 @table @code @item ISAM file ISAM (index) ファイルの名前 @item Isam-version ISAM 形式のバージョン。現在は常に 2 。 @item Creation time データファイルが生成された時。 @item Recover time インデックス/データファイルが最後に再構築された時。 @item Data records レコード/行の数。 @item Deleted blocks 予約された領域をまだ持っている削除ブロック数。 このスペースを最小にするために自分のテーブルを最適化することができます。 @xref{Optimization}. @item Datafile: Parts 動的なレコード形式にいくつのデータブロックがあるかを表示します。 分割なしで最適化されたテーブルでは @code{Data records} と同じです。 @item Deleted data 改善されていない削除データのバイト数。 このスペースを最小にするために自分のテーブルを最適化することができます。 @xref{Optimization}. @item Datafile pointer データファイルポインタの大きさ(バイト数)。これは普通 2, 3, 4 または 5 バ イトです。多くのテーブルは 2 バイトで管理されますが、これはまだ @strong{MySQL} から制御できません。固定テーブルではこれはレコードアドレ スです。動的テーブルではこれはバイトアドレスです。 @item Keyfile pointer データファイルポインタのバイト数。これは普通 1, 2 または 3 バイトです。 多くのテーブルは 2 バイトで管理されますが、これは @strong{MySQL} では自動的に 計算されます。これは常にブロックアドレスです。 @item Max datafile length テーブルのデータファイル (@code{.MYD} ファイル) が獲得できる長さ (バイト数)。 @item Max keyfile length テーブルのキーファイル (@code{.MYI} ファイル) が獲得できる長さ (バイト数)。 @item Recordlength 各レコード/行が使用する領域の大きさ(バイト数)。 @item Record format 各テーブルの行が持つ形式。この例では @code{Fixed length} を使用します。 他の値で可能な物は@code{圧縮}、@code{パック}します。 @item table description テーブル内の全てのキーのリスト。各キーについて、いくつかの低レベル情報が提供さ れます: @table @code @item Key このキー番号。 @item Start このインデックス部が開始するレコード/行内の位置。 @item Len インデックス部の長さ。パックされた数値では、これは常に項目の完全な長さになります。 文字型においては、文字型の項目の頭の部分にインデックスがつく事になりますので、 インデックス項目の最大長さよりもこの値は短くなるでしょう。 @item Index @code{unique} or @code{multip.} (multiple). このインデックス内では1つの値が複数 回存在し得ます。 @item Type このインデックス部が持つデータ型。 これは NISAM データ型で、 @code{packed}, @code{stripped} か @code{empty} オプションを持ちます。 @item Root ルートインデックスブロックのアドレス。 @item Blocksize 各インデックスブロックのサイズ。これはデフォルトでは 1024 ですが、コンパ イル時に変更できます。 @item Rec/key これはオプティマイザによって使用される統計値です。このキーの値ごとのレコー ド数を知らせます。ユニークキーは常に1の値を持ちます。これはテーブルがロードさ れた(または大きく変更された)後に @code{myisamchk -a} で更新されます。これ が全く更新されない場合はデフォルト値の 30 が与えられます。 @end table @item 上の最初の例では、9番目のキーは2つの部分をもったマルチパートキーです。 @item Keyblocks used 使用されたキーブロックのパーセンテージ。このテーブルは @code{myisamchk} で再配置 されるため、値はとても高くなります (理論的な最大にとても近くなります)。 @item Packed @strong{MySQL} は一般の接尾辞でキーのパックを試みます。これは @code{CHAR}/@code{VARCHAR}/@code{DECIMAL} キーでだけ使用できます。名前の ような長い文字列では、これは使用領域を顕著に減らします。上の三番目の例では4番目 のキーが10文字長で、領域の60%の減少を得ます。 @item Max levels このキーの Btree の深さ。長いキーを持つ大きなテーブルは高い値を得ます。 @item Records テーブルが持っている行数。 @item M.recordlength 平均の行長。固定テーブルでは、これはレコード長です。 @item Packed @strong{MySQL} は文字列の最後から空白を除きます。これによって節約された パーセンテージを @code{Packed} は示します。 @item Recordspace used データファイルが使用されたパーセンテージ。 @item Empty space データファイルが使用されていないパーセンテージ。 @item Blocks/Record レコード毎のブロック数 (i.e., 断片化レコードの構成数)。 これは固定形式テーブルでは常に1です。この値は可能な限 り 1.0 に留まります。これが大きすぎる場合は、@code{myisamchk} でテーブルを再配置できます。 @xref{Optimization}. @item Recordblocks 使用されたブロック (links) 数。固定型式ではこれはレコード数と同じです。 @item Deleteblocks 削除されたブロック (links) 数。 @item Recorddata データファイル中にある実際のユーザデータのバイト数。 @item Deleted data データファイル中にある削除された(unused)データのバイト数。 @item Lost space レコードがより短い長さに更新された場合、いくつかの領域が失われます。これ はそのような消失の全ての合計です。in bytes. @item Linkdata 動的形式の使用時、ブロックはポインタ(4〜7バイト)にリンクされます。@code{Linkdata}は そのポインタの全ての合計です。 @end table テーブルが @code{pack_isam} で圧縮されているなら、@code{myisamchk -d} は それぞれのテーブルコラムに関する追加情報を出力します。 @ref{myisampack, ,@code{myisampack}}. を参照してください。 この情報例と説明記述の意味があります。 @node Crash recovery, Log files, Table-info, Maintenance @section Using @code{myisamchk} for crash recovery @strong{MySQL} がデータ格納に使用するファイル形式は、 広範囲にわたってテストされました。が、データベースのテーブルが 破壊されるかもしれない外的状況があります: @itemize @bullet @item @code{mysqld} プロセスが書き込み再中に killed された場合 @item 予期せぬコンピュータの停止(例えば電源が切られた場合) @item ハードウェアエラー @end itemize 本節では、@strong{MySQL} のデータの扱い方、検査の方法を述べます。 もしテーブルがたくさんダメになるのであれば、 あなたは、この理由を見つけるよう試みるべきです! @xref{Debugging server}. 破壊からの修復をする場合、”データベース内のそれぞれのテーブル @code{tbl_name} は、 データベースディレクトリ内にある三つのファイルに一致する”、これを理解する事は とても重要です: @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 これら三つのファイルは様々な方法で破壊を受ける事がありますが、 この場合最も問題が起こりやすいのは、データファイルとインデックスファイルです。 @code{myisamchk} は @file{.MYD} ファイル(データ)のコピーを一行一行おこないます。 この修理過程の最後に、古い @file{.MYD} ファイルを消し、新しいファイルをオリジナルの名前に変更します。 もし @code{--quick} オプションを使用したなら、@code{myisamchk} は @file{.MYD} ファイルの一時ファイルを作りません。そのかわり、@file{.MYD} ファイル が正しいと仮定して新しいインデックスファイルだけを作ります。 この時 @file{.MYD} ファイルはいじりません。 この場合、@code{myisamchk} は自動で @file{.MYD} ファイルの間違いを検出して 修復を中止するので、安全です。 @code{myisamchk} に二つ @code{--quick} オプションを指定することもできます。 この場合、@code{myisamchk} はいくつかのエラー(キーの重複とか)では中止はしません。 かわりに @file{.MYD} ファイルを変更します。 通常の修理を実行するためにディスクのスペースの空きが少ししか無い場合に限って、 @code{--quick} の二回指定が役に立ちます。 この場合,あなたは @code{myisamchk} を走らせる前にバックアップを 少なくともとるべきです。 @menu * Check:: テーブルのエラーチェック方法 * Repair:: テーブルの修復方法 * Optimization:: テーブルの最適化 @end menu @cindex Checking tables for errors @node Check, Repair, Crash recovery, Crash recovery @subsection テーブルのエラーチェック方法 テーブルをチェックするには,以下のコマンドを使用してください: @table @code @item myisamchk tbl_name これはすべての誤りの99.99%を見つけます。 これが見つけることができない物は、データファイルの破壊@strong{だけ}です (これは非常にまれ)。もしテーブルをチェックしたいなら、オプションなしで @code{myisamchk} を走らすか、@code{-s} or @code{--silent} オプションをつけます。 @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 これは全てのデータを完璧に徹底的にチェックします。 (@code{-e} は ``extended check'' の意)。 全てのキーについて、それらがさす行が正しいかを確認するために、 読み込みチェックを行います。 これはたくさんのキーがある大きなテーブルでは、凄く時間がかかります。 @code{myisamchk} は通常、最初のエラーが見つかった時点で止まります。 もしより情報が得たいなら、@code{--verbose} (@code{-v}) オプションを加えます。 これは @code{myisamchk} をエラーが20個出るまで動作させ続けます。 普通に使用する場合は、@code{myisamchk} だけで十分です。(テーブル名以外の引数は一切無し) @item myisamchk -e -i tbl_name 前のコマンドと似ていますが、 @code{-i} オプションは @code{myisamchk} にいくらかの 統計情報を出させるようにします。 @end table @node Repair, Optimization, Check, Crash recovery @subsection テーブルの修復方法 テーブル破壊の兆しとして、クエリが予期せず中断したり、以下のようなエラーが出たりします: @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 これらの場合、あなたは自分のテーブルを修理しなければなりません。 @code{myisamchk} はほとんどの問題を見つけ出し修正します。 修復過程は以下で記述する最大4つの段階を踏みます。 これを始める前に、あなたはデータベースディレクトリに @code{cd} して テーブルファイルのパーミッションを確認すべきです。 これらファイルは @code{mysqld} を実行しているUnixユーザーが読み込み可能 であるようにしてください(検査のするのにあなたにファイルのアクセス権も必要)。 もしファイルの変更をする必要があるならば、ファイルへの書き込み許可も必要です。 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: テーブルをチェックする} @code{myisamchk *.MYI} (時間がかかってもよいなら @code{myisamchk -e *.MYI}) を実行します。 @code{-s} (silent) オプションは不要な情報の出力をおさえます。 If the mysqld server is done you should use the --update option to tell @code{myisamchk} to mark the table as 'checked'. @code{myisamchk} がエラーを返した場合にだけ、テーブルを修復する必要があります。 この場合、Stage 2 へ進みます。 チェック時に奇妙なエラー(@code{out of memory} エラーのような) が起きた場合、 あるいは @code{myisamchk} が落ちた場合、Stage 3 に進んでください。 @noindent @strong{Stage 2: 簡単で安全な修復} まず最初に @code{myisamchk -r -q tbl_name} を試みてください (@code{-r -q} は ``quick recovery mode''の意)。 これはデータファイルに触れないでインデックスファイルの修理を試みます。 もしデータファイルが全てとデータファイル中の正しい場所での削除リンクポイントを 含んでいるなら、これは動作してテーブルを修復します。 成功後、次のテーブルの修復に進んでください。 失敗した場合は、以下の手順で試みてください: @enumerate @item 続ける前にデータファイルをバックアップしてください。 @item @code{myisamchk -r tbl_name} を使用します(@code{-r} は ``recovery mode''の意)。 これは不正なレコードと削除されたレコードをデータファイルから消去し、 インデックスファイル(.MYI)を再構築します。 @item 上記が失敗した場合、@code{myisamchk --safe-recover tbl_name} を使用して下さい。 Safe recovery モードは古い方法を使用して修復します。 これは普通の修復モードでは行わない操作をいくつかもっています。(遅いですが) @end enumerate チェックまたは修復時に、メモリ不足のような妙なエラーがでた場合、または @code{myisamchk} がクラッシュした場合は、Stage 3 に進んでください。 @noindent @strong{Stage 3: 難しい修復} インデックスファイル(.MYI)の最初の 16K ブロックが破壊された場合、 または不正な情報を含む場合、またはインデックスファイルがない場合にだけ、 本修復段階を経ます。 この場合、新しいインデックスファイルファイルを作成する必要があります。 次のようにしてください: @enumerate @item データファイル .MYD ファイルをどこか安全場所に移動します。 @item 新しい空のデータとインデックスファイルを作るために、 テーブルディスクリプタファイルを使用します: @example shell> mysql db_name mysql> DELETE FROM tbl_name; mysql> quit @end example @item 古いデータファイルを新しく作ったデータファイルにコピーします。 (古いデータファイルを move してはいけません;なんら頭の問題が起きます) @end enumerate Stage 2 に戻ってください。 @code{myisamchk -r -q} は既に動作します。 (これは無限ループにはなりません). @noindent @strong{Stage 4: とても難しい修復} これは、ディスクリプタファイル(.frm)もクラッシュした場合にだけ発生します。 これは発生することはありません。なぜならディスクリプタファイルは テーブルが生成された後に書かれることはないからです。 @enumerate @item ディスクリプタファイルをバックアップからリストアして、Stage 3 に戻ってください。 インデックスファイルのリストアもできます。そして Stage 2 に戻ってください。 後者の場合、@code{myisamchk -r} で開始すべきです。 @item バックアップを持っていなくても、テーブルがどのように作成されたかを正確に知って いれば、他のデータベース内にテーブルのコピーを生成します。 新しいデータファイルを削除し、先ほど作ったデータベースの中の ディスクリプタファイルとインデックスファイルを、壊れたデータベース内に 移動します。これは新しいディスクリプタファイルとインデックスファイルを 与えることになりますが、データファイルはそのまま残っています。 Stage 2 に進み、インデックスファイルの修復を行ってください。 @end enumerate @node Optimization, , Repair, Crash recovery @subsection テーブルの最適化 断片化されたレコードの結合と、 レコードの削除と更新から生じる無駄なスペースの排除、 これら行うには、修復モード(recovery mode)で @code{myisamchk} を実行します: @example shell> myisamchk -r tbl_name @end example SQL @code{OPTIMIZE TABLE} でも同様にテーブルを最適化できます。 @code{OPTIMIZE TABLE} は簡単ですが、 @code{myisamchk} の方が速いです。 @code{myisamchk} には、あなたがテーブルの性能を向上させるのに使用することができる 他の多くのオプションがあります: @table @code @item -S, --sort-index インデックスツリーブロックのソート。降順にソートします。 これはシーク(seek)を最適化し、キーを使用したテーブルの走査(scan)を速くします。 @item -R index_num, --sort-records=index_num インデックスによるソート。これはあなたのデータをより良く配置し、 このインデックスを使用した @code{SELECT} , @code{ORDER BY} 操作を速くします。 (最初にこれを実行してソートするときは時間がとてもかかります!) テーブルのインデックス番号を見つけるために、 @code{SHOW INDEX} を使用します。 これは @code{myisamchk} が行うのと同様の順でテーブルのインデックスを表示します。 インデックス番号は 1 から開始されます。 @item -a, --analyze テーブル内のキー配置の分析。 このテーブルからレコードを取得する際に、 結合(join)のパフォーマンスを向上させます。 @end table For a full description of the option see @ref{myisamchk syntax}. @node Log files, , Crash recovery, Maintenance @section Log file maintenance @strong{MySQL} をログファイルとともに使用する場合、 あなたは、時々古いログファイルを リムーブ/バックアップ し、 @strong{MySQL} に新しいファイルにログを取るように指示したいと思うことでしょう。 @xref{Update log}. @code{Redhat} Linux においては、@code{mysql-log-rotate} スクリプトを これに使用できます。 もし RPM ディストリビューションの @strong{MySQL} を インストールしたなら、このスクリプトは自動でインストールされているはずです。 他のシステムでは、自分自身で短いスクリプトをインストールします。 @code{cron} でログファイルを扱うようにします。 @code{mysqladmin flush-logs} コマンドか @code{FLUSH LOGS} SQL文で、 @strong{MySQL} に新しいログファイルを使用させることが出来ます。 もしあなたが @strong{MySQL} 3.21 を使用しているなら、 @code{mysqladmin refresh} を使用しなくてはなりません。 上記のコマンドは、以下のように動作します: @itemize @bullet @item もし通常のログ (@code{--log}) が使用されているならば、このログファイルを 一度閉じてから再び開きます。 (@file{mysql.log} がデフォルトのログファイル). @item もし更新ログ (@code{--log-update}) を使用しているなら、 更新ログを閉じ、新しいログファイルを開きます。そのさい、 ログファイルについている番号は増えます。 @end itemize もし更新ログだけを使用しているなら、あなたは、ログを flush するだけでよくて、 その時、バックアップのため古い更新ログファイルを移動します。 もし普通のログを使っていれば、あなたは以下のようにすることができます: @example shell> cd mysql-data-directory shell> mv mysql.log mysql.old shell> mysqladmin flush-tables @end example こうしておいて、@file{mysql.old} をバックアップし削除します。. @node Adding functions, Adding procedures, Maintenance, Top @chapter @strong{MySQL} への新しい関数の追加 @strong{MySQL}に新しい関数を追加するには2つの方法があります: @itemize @bullet @item ユーザ定義関数(UDF:user-definable function)インタフェースを通して関数を追加できます。 ユーザ定義関数は、@code{CREATE FUNCTION} と @code{DROP FUNCTION} ステー トメントを使用して、動的に追加、削除されます。 @xref{CREATE FUNCTION, , @code{CREATE FUNCTION}}. @item ネイティブ(ビルトイン) @strong{MySQL} 関数として関数を追加できます。 ネイティブ関数は @code{mysqld} サーバに統合され、恒久的に有効になります。 @end itemize それぞれの方法には、有利な点と不利な点があります: @itemize @bullet @item ユーザ定義関数を書く場合、サーバ自身に追加するオブジェクトファイルをイン ストールする必要があります。関数をサーバに統合する場合あそれを行なう必要 はありません。 @item UDF をバイナリ @strong{MySQL} 配布に追加することができます。ネイティブ関 数はソース配布の変更が必要です。 @item @strong{MySQL} 配布をアップグレードする場合、前にインストールされた UDF の使用を継続できます。ネイティブ関数では、アップグレードの度に変更を繰り 返す必要があります。 @end itemize 新しい関数を追加するためにどちらの方法を使用しても、@code{ABS()} や @code{SOUNDEX()} のようなネイティブ関数と同じように使用することができま す。 @menu * Adding UDF:: 新しいユーザ定義関数の追加 * Adding 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 新しいユーザ定義関数の追加 @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 UDF 機構が動作するためには、関数は C か C++ で書かれる必要があり、OS が 動的ローディングをサポートする必要があります。@strong{MySQL} ソース配布 は @file{sql/udf_example.cc} を含んでいて、これは5つの新しい関数を定義 しています。UDF の呼び出し方法がどのように働くかはこのファイルを参考にし てください。 SQL ステートメントで使用したいそれぞれの関数について、対応する C (または C++) 関数を定義すべきです。下の説明では、名前 ``xxx'' がサンプル関数名と して使用されています。SQL と C/C++ 使用法を distinquish するために、 @code{XXX()} (大文字) は SQL 関数呼び出しを表わし、@code{xxx()} (小文字) は C/C++ 関数呼び出しを表わします。 @code{XXX()} のインタフェースを実装するために書く C/C++ 関数は: @table @asis @item @code{xxx()} (必要) メイン関数。これは関数結果が計算されるところです。SQL 型と C/C++ 関数の 戻り値型の対応は次に示します: @multitable @columnfractions .2 .8 @item @strong{SQL 型} @tab @strong{C/C++ 型} @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()} (オプション) @code{xxx()} の初期化関数。これは次のように使用されます: @itemize @bullet @item @code{XXX()} の引数の数のチェック @item 引数が要求される型かどうかのチェック、また、メイン関数が呼ばれる時に望む 型に引数を強制するように @strong{MySQL} に伝える @item メイン関数が必要とするメモリの割り当て @item 結果の最大長の指定 @item (@code{REAL} 関数では) 小数部の最大桁数の指定 @item 結果が @code{NULL} になり得るかどうかの指定 @end itemize @item @code{xxx_deinit()} (オプション) @code{xxx()} の終了関数(deinitialization function)。これは初期化関数によっ て割り当てられたメモリを解放すべきです。 @end table SQL ステートメントが @code{XXX()} を呼び出すとき、@strong{MySQL} は引数 チェックやメモリ割り当てのように、必要なセットアップを行なわせるために、 初期化関数 @code{xxx_init()} を呼び出します。@code{xxx_init()} がエラー を返す場合、SQL ステートメントはエラーメッセージと共に異常終了し、メイン 関数と終了関数は呼び出されません。そうでなければ、メイン関数 @code{xxx()} が各行毎に呼び出されます。全ての行が処理された後、終了関数 @code{xxx_deinit()} が、必要な掃除を行なうために、呼び出されます。 全ての関数はスレッド安全でなくてはいけません(メイン関数だけでなく、初期 化関数と終了関数も同様です)。これは変更されうるグローバル変数や静的変数 を割り当てることは許されないことを意味します! メモリが必要な場合は、 @code{xxx_init()} で割り当て、@code{xxx_deinit()} でそれを解放すべきです。 @node UDF calling sequences, UDF arguments, Adding UDF, Adding UDF @subsection UDF 呼び出しシーケンス メイン関数は下に示すように宣言されるべきです。戻り値型と引数は、 @code{CREATE FUNCTION} ステートメントで、SQL 関数 @code{XXX()} の戻り値 を@code{STRING}, @code{INTEGER}, @code{REAL} のどれに宣言するかに依存し て異なることに注意してください: @noindent @code{STRING} 関数では: @example char *xxx(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error); @end example @noindent @code{INTEGER} 関数では: @example long long xxx(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); @end example @noindent @code{REAL} 関数では: @example double xxx(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error); @end example 初期化と終了関数は次のように宣言します: @example my_bool xxx_init(UDF_INIT *initid, UDF_ARGS *args, char *message); void xxx_deinit(UDF_INIT *initid); @end example @code{initid} 引数は3つの関数全てに渡されます。これは @code{UDF_INIT} 構造体を示し、関数間で情報を伝達するために使用されます。@code{UDF_INIT} 構造体のメンバは下に一覧します。初期化関数は変更したい全てのメンバを埋め るべきです。(メンバにデフォルトを使用するには、未変更のままにしてくださ い。) @table @code @item my_bool maybe_null @code{xxx()} が @code{NULL} を返す場合、@code{xxx_init()} は @code{maybe_null} を @code{1} に設定すべきです。デフォルト値は、引数のい ずれかが @code{maybe_null} として宣言された場合、@code{1} です。 @item unsigned int decimals 小数部の桁数。デフォルト値はメイン関数に渡される引数の小数部の最大桁数で す。(例えば、関数に @code{1.34}, @code{1.345}, @code{1.3} が渡された場合、 デフォルトは 3 です。@code{1.345} が 3 桁の小数部を持つためです。) @item unsigned int max_length 文字列結果の最大長。デフォルト値は関数の戻り値型に依存して異なります。文 字列関数では、デフォルトは最も長い引数の長さです。整数関数では、デフォル トは 21 桁です。実数関数では、デフォルトは 13 に @code{initid->decimals} で示される小数部の桁数を加えたものです。(数値関数では、長さは符号と小数 点文字を含みます。) @item char *ptr それ自身の目的のために関数が使用できるポインタです。例えば、関数は割り当 てたメモリを関数間で伝達するために、@code{initid->ptr} を使用できます。 @code{xxx_init()} では、メモリを獲得し、このポインタに割り当てます: @example initid->ptr = allocated_memory; @end example @code{xxx()} と @code{xxx_deinit()} では、@code{initid->ptr} を参照して、 メモリを使用または解放します。 @end table @node UDF arguments, UDF return values, UDF calling sequences, Adding UDF @subsection 引数処理 @code{args} 引数は次に示すメンバを持つ @code{UDF_ARGS} 構造体へのポイン タです: @table @code @item unsigned int arg_count 引数の数。関数が特定の引数の数で呼び出されることを期待する場合は、初期化 関数でこの値をチェックしてください。例えば: @example if (args->arg_count != 2) @{ strcpy(message,"XXX() requires two arguments"); return 1; @} @end example @item enum Item_result *arg_type 引数の型。可能な型の値は @code{STRING_RESULT}, @code{INT_RESULT}, @code{REAL_RESULT} です。 引数が与えられた型であることと、そうでない場合エラーを返すことを確実にす るために、初期化関数で @code{arg_type} 配列をチェックしてください。例え ば: @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 関数の引数が特定の型を要求するための代案として、初期化関数を使用して、 @code{arg_type} 要素を求める型に設定できます。これは @strong{MySQL} に @code{xxx()} の各呼び出しにこれらの型を引数に強制するようにさせます。例 えば、最初の2つの引数に文字列と整数を強制するように指定するには、 @code{xxx_init()} で次を行なってください: @example args->arg_type[0] = STRING_RESULT; args->arg_type[1] = INT_RESULT; @end example @item char **args @code{args->args} は、関数が呼ばれる時の引数の一般的な特性について、情報 を初期化関数に伝達します。定数引数 @code{i} について、 @code{args->args[i]} は引数値のをポイントします。(値への正しいアクセス方 法については後述。)非定数引数について、@code{args->args[i]} は @code{0} です。定数引数は定数だけを使用する表現で、@code{3}, @code{4*7-2}, @code{SIN(3.14)} などです。非定数引数は行から行に変更される値を参照する 表現で、項目名や非定数引数で呼び出される関数などです。 メイン関数のそれぞれの呼び出しについて、@code{args->args} は現在処理され ている行に渡される実際の引数を含んでいます。 関数は次のように引数 @code{i} を参照できます: @itemize @bullet @item @code{STRING_RESULT} 型の引数は、バイナリデータまたは任意の長さのデータ の処理を許すため、文字列ポインタ+長さとして与えられます。文字列内容は @code{args->args[i]} として有効で、文字列長は @code{args->lengths[i]} で す。文字列は NULL 終端とみなすべきではありません。 @item @code{INT_RESULT} 型の引数について、@code{args->args[i]} を @code{long long} 値にキャストする必要があります: @example long long int_val; int_val = *((long long*) args->args[i]); @end example @item @code{REAL_RESULT} 型の引数について、@code{args->args[i]} を @code{double} 値にキャストする必要があります: @example double real_val; real_val = *((double*) args->args[i]); @end example @end itemize @item unsigned long *lengths 初期化関数では、@code{lengths} 配列は各引数についての最大文字列長を示し ます。メイン関数の各呼び出しについては、@code{lengths} は、現在処理され ている行に渡される任意の文字列引数の実際の長さを含んでいます。 @code{INT_RESULT}, @code{REAL_RESULT} 型の引数については、@code{lengths} はまだ引数の最大長を含んでいます(初期化関数については)。 @end table @node UDF return values, UDF compiling, UDF arguments, Adding UDF @subsection 戻り値とエラー処理 初期化関数は、エラーが無い場合は @code{0} を、そうでなければ @code{1} を 返すべきです。エラーが発生する場合は、@code{xxx_init()} は NULL 終端エラー メッセージを @code{message} パラメータに格納すべきです。このメッセージは クライアントに返されます。メッセージバッファは @code{MYSQL_ERRMSG_SIZE} 文字長ですが、80 文字より小さく保つように試みるべきです。標準的な端末画 面の幅にフィットするようにです。 メイン関数 @code{xxx()} の返す値は @code{long long} と @code{double} 関 数については関数値です。文字列関数については、@code{result} と @code{length} 引数で文字列が返されます。@code{result} は少なくとも 255 バイト長のバッファです。これらに内容と戻り値の長さを設定してください。例 えば: @example memcpy(result, "result string", 13); *length = 13; @end example 文字列関数は通常は結果をポイントする値を返します。 メイン関数で @code{NULL} 値の戻り値を示すには、@code{is_null} を @code{1} に設定してください: @example *is_null = 1; @end example メイン関数でエラーの戻り値を示すには、@code{error} パラメータを @code{1} に設定します: @example *error = 1; @end example @code{xxx()} が任意の行について @code{*error} に @code{1} を設定する場合、 関数値は現在の行についてと、その後の @code{XXX()} が呼び出されるステート メントによって処理される任意の行について @code{NULL} です。(@code{xxx()} は続く行については呼び出しさえされません。) @strong{注意:} 3.22.10 より 前の @strong{MySQL} バージョンでは、@code{*error} と @code{*is_null} の 両方に設定すべきです: @example *error = 1; *is_null = 1; @end example @node UDF compiling, , UDF return values, Adding UDF @subsection ユーザ定義関数のコンパイルとインストール UDF を実装するファイルはサーバが動作するホスト上でコンパイルされインストー ルされないければなりません。この処理はサンプル UDF ファイル @file{udf_example.cc} について次に説明します。これは @strong{MySQL} ソー ス配布に含まれています。このファイルは次の関数を含みます: @itemize @bullet @item @code{metaphon()} は文字列引数の metaphon 文字列を返します。これは時には soundex 文字列ですが、さらに英語用に調整されています。 @item @code{myfunc_double()} は引数の文字の ASCII 値の合計を引数の長さの合計で 割った値を返します。 @item @code{myfunc_int()} は引数の長さの合計を返します。 @item @code{lookup()} はホスト名の IP 番号を返します。 @item @code{reverse_lookup()} は IP 番号のホスト名を返します。この関数は文字列 @code{"xxx.xxx.xxx.xxx"} または4つの数値とともに呼ばれます。 @end itemize 動的ロード可能ファイルは、次のような何らかのコマンドを使用して、共有オブ ジェクトファイルとしてコンパイルされるべきです: @example shell> gcc -shared -o udf_example.so myfunc.cc @end example @strong{MySQL} ソースツリーの @file{sql} ディレクトリ内で次のコマンドを 実行することにより、システムのコンパイラオプションを簡単に正しく見つけ出 すことができます: @example shell> make udf_example.o @end example @code{make} が表示するものに似たコンパイルコマンドを実行すべきですが、行 末近くの @code{-c} オプションを取り除いて、@code{-o udf_example.so} を行 末につけてください。(いくつかのシステムでは、コマンドに @code{-c} を残す 必要があります。) UDF を含む共有オブジェクトをコンパイルすると、それをインストールしてその ことを @strong{MySQL} に知らせる必要があります。@file{udf_example.cc} か らの共有オブジェクトのコンパイルは、@file{udf_example.so} のような何かの ファイル名を提供します(実際の名前はプラットフォームによって変わります)。 このファイルを @file{/usr/lib} のような @code{ld} が探すどこかのディレク トリにコピーしてください。多くのシステムでは、@code{LD_LIBRARY} または @code{LD_LIBRARY_PATH} 環境変数を設定して、UDF 関数ファイルがあるディレ クトリを示すことができます。@code{dlopen} マニュアルページはシステム上で 使用すべき変数を教えてくれます。これを @code{mysql.server} または @code{safe_mysqld} に設定し、@code{mysqld} を再起動すべきです。 ライブラリがインストールされた後、@code{mysqld} に新しい関数について次の コマンドで通知すべきです: @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 関数は @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 @code{CREATE FUNCTION} と @code{DROP FUNCTION} ステートメントは @code{mysql} データベース内のシステムテーブル @code{func} を更新します。 関数の名前、型、共有ライブラリ名はテーブルに保存されます。作成と破棄機能 のためには、@code{mysql} データベースに @strong{insert} と @strong{delete} 権限を持つ必要があります。 既に生成してある関数を追加するために @code{CREATE FUNCTION} を使用すべき ではありません。関数の再インストールが必要な場合は、@code{DROP FUNCTION} でそれを削除し、それから @code{CREATE FUNCTION} で再インストールすべきで す。例えば、関数の新しいバージョンの再コンパイルをした場合、 @code{mysqld} が新しいバージョンを得るために、これを行なう必要があるでしょ う。そうでなければ、サーバは古いバージョンの使用を継続します。 @code{mysqld} を @code{--skip-grant-tables} オプションで起動しなくても、 有効な関数はサーバの開始毎に再読み込みされます。この場合、UDF 初期化は飛 ばされ、UDF が無効になります。(有効な関数は @code{CREATE FUNCTION} でロー ドされているもので、@code{DROP FUNCTION} で削除されていないものです。) @cindex Adding native functions @cindex Native functions, adding @cindex Functions, native, adding @node Adding native function, , Adding UDF, Adding functions @section 新しいネイティブ関数の追加 ネイティブ関数を追加するためのプロシジャを以下に示します。バイナリ配布に はネイティブ関数を追加できないことに注意してください。プロシジャは @strong{MySQL} ソースコードの変更を必要とするためです。@strong{MySQL} を ソース配布から自分でコンパイルする必要があります。また、@strong{MySQL} の他のバージョンに移行する場合(例えば、新しいバージョンがリリースされた 時)、新しいバージョンでこのプロシジャを繰り返す必要があります。 新しいネイティブ @strong{MySQL} 関数を追加するためには、次のステップに従っ てください: @enumerate @item @code{sql_functions[]} 配列内で関数名を定義している @file{lex.h} に1行 追加してください。 @item @file{sql_yacc.yy} に2行追加してください。一つは、@code{yacc} が定義す べきプリプロセッサシンボルを指示します(これはファイルの先頭に追加すべき です)。それから関数パラメータを定義し、これらのパラメータとともに ``item'' を @code{simple_expr} パース規則に追加します。例えば、これがど のように動作するかを見るには、@file{sql_yacc.yy} 内の @code{SOUNDEX} の 全ての出来事をチェックしてください。 @item @file{item_func.h} 内で、関数が数値または文字列のどちらを返すかに依存し て、@code{Item_num_func} または @code{Item_str_func} から継承するクラス を宣言してください。 @item @file{item_func.cc} 内で、数値または文字列のどちらの関数を定義するかに依 存して、次の宣言の一つを追加してください: @example double Item_func_newname::val() longlong Item_func_newname::val_int() String *Item_func_newname::Str(String *str) @end example @item おそらく次の関数も定義すべきです: @example void Item_func_newname::fix_length_and_dec() @end example この関数は与えられた引数に基づいて少なくとも @code{max_length} を計算す べきです。@code{max_length} は関数が返し得る文字の最大数です。この関数は、 メイン関数が @code{NULL} 値を返すことがない場合は、@code{maybe_null = 0} も設定すべきです。関数は、引数の @code{maybe_null} 変数をチェックするこ とで、関数の任意の引数が @code{NULL} を返しうるかどうかをチェックできま す。 @end enumerate 全ての関数はスレッド安全である必要があります。 文字列関数については、次のいくつかの追加検討事項があります: @itemize @bullet @item @code{String *str} 引数は、結果を保持するために使用される文字列バッファ を提供します。 @item 関数は結果を保持する文字列を返すべきです。 @item 全ての現在の文字列関数は、絶対に必要でない限り、メモリ割り当てを避けるよ うに試みてください! @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 @strong{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} は @strong{MyODBC} プログラムで ODBC 機能を提供します。 @node Which ODBC OS, ODBC administrator, ODBC, ODBC @section Operating systems supported by @strong{MyODBC} @strong{MyODBC} は 32-bit ODBC (2.50) level 0 driver で、 ODBC 化されたアプリケーションが @strong{MySQL} に接続する場合に使用します。 @strong{MyODBC} は、Windows95, Windows98, NT とほとんどの Unix で動きます。 通常、@strong{MyODBC} は Windows マシンにだけ、インストールします。 、あなたのプログラムが ColdFusion のようにデータベースへの接続に ODBC だけを使用する場合に限り、UNIX に @strong{MyODBC} が必要です。 @strong{MyODBC} はパブリック・ドメインで、最新の物は以下にあります: @uref{http://www.mysql.com/download_myodbc.html}. 日本語文字コードに対応させた物は: @uref{http://www.SoftAgency.co.jp/}. もし、UNIX に @strong{MyODBC} をインストールしたいなら、 @strong{ODBC} マネージャーも必要でしょう。 @strong{MyODBC} は UNIX の ODBC マネージャー でも動作することが知られています。 @strong{MySQL} useful links page の @strong{ODBC}-related links 節に、見つけることができます。 @xref{Useful Links}. Windows/NT の場合、@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, one cannot in this case install new ODBC drivers with Microsoft's ODBC setup program. :( これを解決するには、一度 ’セーフモード’でコンピュータを立ち上げ直し、 (windows リブート時に、F8キーを押すことで、セーフモードの選択が可能です) @strong{MyODBC} をインストールして、リブートします。 @itemize @bullet @item Windows マシンから UNIX に ODBC アプリケーションを使用して接続するには、 まず最初に Windows マシンに @strong{MyODBC} をインストールしなくては なりません。 @item UNIX 上の @strong{MySQL} サーバーに対して、ユーザーと Windows マシンの アクセス許可を与えます。 これは、 @code{GRANT} コマンドで可能です。 @xref{GRANT,,@code{GRANT}}. @item ODBC DSN を以下のようにして作成しなくてはなりません: @itemize @bullet @item Windows マシンのコントロールパネルを開く @item ODBC アイコンをダブルクリック @item "ユーサーDSN" をクリック @item "追加..." ボタンをクリック @item 新しいデータソース の画面から、@strong{MySQL} を選び、完了ボタンをクリック。 @item TCX @strong{MySQL} Driver のデフォルト設定が現れます。 @xref{ODBC administrator}. @end itemize @item アプリケーションを起動し、コントロールパネルで設定した ODBC DSN を選びます @end itemize MyODBC の設定画面には、@strong{MySQL} 接続時のオプションがいくつか 設定できるようになっています。 もし問題がある場合は、これらを試します。 @node ODBC administrator, ODBC Problems, Which ODBC OS, ODBC @section ODBC 管理プログラムの各種項目を埋めるには? Windows95 上のサーバ名の記述には3つの可能性があります: @itemize @bullet @item サーバの IP アドレスの使用 @item ファイル @file{\windows\lmhosts} への次の情報の追加: @example ip hostname @end example 例えば: @example 194.216.84.21 my @end example @item DNS を使用するように設定します。 @end itemize @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 @code{Windows DSN name} 項目の値は、あなたのwindows ODBC setup における 一意の名前です。 ODBC setup 画面で、@code{Server}, @code{User}, @code{Password}, @code{Port} フィールドを設定する必要はありません。 しかし、ここで設定をすると、後でサーバーに接続する際に、 設定した値がデフォルト値として使用されます。 使用時に値を変更するオプションはあります。 ポート番号が設定されていないなら、デフォルトポート (@value{default_port}) が使用されます。 もしオプションを @code{Read options from C:\my.cnf} にすると, @code{client} と @code{odbc} グループは @file{C:\my.cnf} ファイルから読まれます。 @code{mysql_options()} で使用できる全てのオプションが利用可能です。 @xref{mysql_options}. @node ODBC Problems, MyODBC clients, ODBC administrator, ODBC @section @strong{MyODBC}での問題をどのように報告すべきか? @strong{MyODBC} は以下でテストされました: 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. @strong{MyODBC} で動作する他のアプリケーションについても知っているなら、 @email{myodbc@@lists.mysql.com} までメールをください! 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 @strong{MyODBC}で動作することが知られているプログラム 多くのプログラムが @strong{MyODBC} で動作します。これらは我々自身がテストしたか、 または何人かの他のユーザから動作するという確証を得たものです: @table @asis @item @strong{Program} @strong{Comment} @item Access Access を動作させるには: @itemize @bullet @item テーブルにプライマリキーを設定しなければなりません。 @item 更新可能なテーブルの全てに、timestamp を持たせなければなりません。 @item ダブルフロート型だけが(実数に)使用できます。Accessではシングルフロートと比較は失敗します。 @item @strong{MySQL} に接続する際は、'Return matching rows' オプションをセットします。 @item NT 上の Access は @code{BLOB} フィールドを @code{OLE OBJECTS} と認識します。 もし @code{MEMO} フィールドを代わりに使用したいなら、 @code{ALTER TABLE} を使って、 @code{TEXT} 型にフィールドを変更しなくてはなりません。 @item Access は @code{DATE} フィールドをいつも正しく扱うことが出来ません。 もしこれらの問題があった場合、フィールド型を @code{DATETIME} に変えてください。 @end itemize @item アクセスは、@strong{MySQL} が理解できない間違った SQL クエリを 作成するかもしれません。 これはアクセスのメニューから @code{"Query|SQLSpecific|Pass-Through"} を選択すれば 直すことが可能です。 @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/download_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 動作。Some tips: @itemize @bullet @item 日付に問題が起きた場合、@code{CONCAT()} 関数を使用し、文字として SELECT してみてください。 例えば: @example select CONCAT(rise_time), CONCAT(set_time) from sunrise_sunset; @end example この方法で文字として返ってきた値を、Excel97 で時間として扱うようにすべきです。 この例の @code{CONCAT()} の目的は、フィールドの型が文字列であると ODBC をだますことです。 @code{CONCAT()} がなければ、ODBC はフィールドの型が日付とわかるので、 Excel が今度はそれを理解できなくなります。 これは Excel のバグです。なぜなら文字を自動で日付に直すのですから。 これは単にテキストファイルの情報を扱う場合ならばいいのですが、 各項目の型を知らせる ODBC 接続の情報を扱う場合は、とても愚かな方法です。 @end itemize @item odbcadmin ODBC のテストプログラム. @item Delphi DBE 3.2 以上を必ず使用してください。 @strong{MySQL} に接続する際には、'Don't optimize column width' オプションをセットします。 ODBCエントリとBDEエントリの両方をセットアップするおりに役に立つであろう Delphi のコード例を示します ( BDE は Delphi Super Page から無償で得られる BDE Alias Editor が必要です)。 : (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 BDE 3.0で,テストされました。唯一の知られた問題は、 テーブルスキーマが変化する時、クエリフィールドが更新されないことです。 BDE は、index PRIMARY だけを認識し、プライマリーキーは認識していないように思えます。これはさほど問題ではないですが。 @item Visual Basic テーブルの更新を可能にするため、テーブルにプライマリーキーを作成しなくてはなりません。 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 @code{AUTO_INCREMENT} フィールドの値を ODBC で得る方法 共通の問題は、@code{INSERT} で自動的に生成されるIDの値を得ることです。 ODBCでは、以下のようにします( 例中の @code{auto} が @code{AUTO_INCREMENT} フィールドです): @example INSERT INTO foo (auto,text) VALUES(NULL,'text'); SELECT LAST_INSERT_ID(); @end example もしくは、他のテーブルにIDを挿入するだけなら以下のようにします: @example INSERT INTO foo (auto,text) VALUES(NULL,'text'); INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text'); @end example いくつかのODBCアプリケーション(少なくともDelphiとAccess)は、 新しく挿入された行を見つけるのに、以下のクエリが使用できます: @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 もし @strong{MyODBC} 使用時に難しい問題にあたった場合、 ODBC マネージャのログファイル (ODBCADMIN からリクエストしたときのログ) と @strong{MyODBC} のログを取り始めるべきです。 これはいかなる問題にも解決の糸口になるはずです。 @strong{MyODBC} ログを取るには、 @strong{MyODBC} connect/configure 画面の 'Trace MyODBC' オプションをチェックします。 ログは @file{C:\myodbc.log} に書き出されます。 このオプションを使用するに当たり、 @code{MYSQL2.DLL} ではなく、 @code{MYSQL.DLL} を使用しなくてはなりません! MyODBC が @strong{MySQL} サーバーに送っているクエリを確認します; これは @file{myodbc.log} ファイル中に、@code{>mysql_real_query} と いう文字列が含まれている行です。 また、MyODBC か @strong{MySQL} のエラーを見つけるためには、 同じコマンドを、@code{mysql} コマンドや @code{admndemo} でも試すべきです。 もし、問題を発見したなら、関係する行を(最大40行) @email{myodbc@@lists.mysql.com} に 送ってください。 MyODBC や ODBC のログファイル全てを送らないように してください! もし問題を見つけることが出来なかった場合、MyODBC ログファイル、 ODBC ログファイル、問題の説明する README ファイルを含んだ アーカイブ(tar か zip) を作成します。 これを @uref{ftp://www.mysql.com/pub/mysql/secret}. に送ります。 TCX だけが、アップロードされたファイルにアクセスできます。 もし問題を見るためのプログラムも作っているなら、それも同時に送ります。 もしそのプログラムが他の SQL サーバーで動くなら、 他の SQL サーバーで同じことをした場合の ODBC ログファイルを作成すべきです。 多くの情報をあなたが提供すれば、我々は問題を解決しやすくなることを 念頭においてください。 @node Common programs, Problems, ODBC, Top @chapter いくつかの一般的なプログラムでの @code{MySQL} の使用 @menu * Apache:: Apache での MySQL の使用 @end menu @node Apache, , Common programs, Common programs @section Apache での MySQL の使用 Contrib には、 @strong{MySQL} データベースに登録しているユーザーで 認証が出来るようになるプログラムと、 ログを @strong{MySQL} テーブルに書き込むプログラムが 含まれています。 @xref{Contrib}. 以下のように Apache の設定ファイルに記述すれば、 Apache のログのフォーマットを、@code{MySQL} に読みやすい物に変更できます: @example LogFormat \ "\"%h\",%@{%Y%m%d%H%M%S@}t,%>s,\"%b\",\"%@{Content-Type@}o\", \ \"%U\",\"%@{Referer@}i\",\"%@{User-Agent@}i\"" @end example こうすれば、@strong{MySQL} で、以下のようにできます: @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 問題とよくあるエラー @menu * What is crashing:: How to determinate what is causing problems * Crashing:: What to do if @strong{MySQL} keeps crashing * 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 @menu * Crashing:: What to do if @strong{MySQL} keeps crashing @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, Common errors, What is crashing, Problems @subsection @strong{MySQL} がクラッシュする場合に行うこと 全ての @strong{MySQL} バージョンはリリースの前に多くのプラットフォームで テストされます。 これは @strong{MySQL} にいかなるバグもないということを 意味しますが、発見するのが困難で、わずかなバグがあるかもしれません。 もし問題があった場合、何がシステムをクラッシュしているかを見つけようとする事は、 問題を早く修正するためのより良い機会でもあります。 まず最初に, その問題で @code{mysqld} デーモンが死ななければならないかどうかか, また はその問題がクライアントで処理しなければならないかどうかを調べるべきです。 @code{mysqladmin version} を実行することにより、 @code{mysqld} サーバーが どれぐらい稼働していたかわかります。 もし @code{mysqld} が死んでいたなら、 を実行することによってあるのかをチェックすることができます. mysqldが死んだなら、 その原因を @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 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 何かがクラッシュする理由を知るのは非常に難しいので、まず、他の人で動くも のがあなたでクラッシュするのかどうかをチェックしてください。次のことを行っ てください。 @itemize @bullet @item @code{mysqld} デーモンを @code{mysqladmin shutdown} で停止し, 全てのテーブルで @code{myisamchk --silent --force */*.MYI} を実行し、そして @code{mysqld} デーモンを 再起動します. これはきれいな状態から開始することになります。 @xref{Maintenance}. @item @code{mysqld --log} を使用し、ログの情報から特定のクエリがサーバーをキルしているかを 見つけ出してください。 95% のバグは特定のクエリに関係があります! 通常これは、 @strong{MySQL} が再起動される前の、ログファイルの最後のクエリの一つです。 これを、以下の手順で確認することも出来ます: @itemize @bullet @item @strong{MySQL} デーモンを ( @code{mysqladmin shutdown} で) 停止。 @item @strong{MySQL} データベースディレクトリをバックアップ。 (As the server is stopped, you can just copy the files to some other directory) @item 全てのテーブルが正しいのかを、@code{myisamchk -s */*.MYI} でチェック。 もしテーブルが壊れているようなら、 @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 ログファイルを @strong{MySQL} データディレクトリから削除 (か 移動)。 @item @code{safe_mysqld --log-update} か @code{safe_mysql --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 ベンチマークを試しましたか? これは @strong{MySQL} をより良くテストしま す。あなたのアプリケーションをシミュレートするコードを追加することもでき ます。ベンチマークはソース配布では @strong{MySQL} インストールディレクト リ配下の @file{bench} ディレクトリに、バイナリ配布では @file{sql-bench} ディレクトリに見つけられます。 @item @code{fork_test.pl} と @code{fork2_test.pl} を試します。 @item エラーがないか、@file{mysql-data-directory/'hostname'.err} ファイルを確認します。 @item デバッグ用に @strong{MySQL} をコンフィグすると、何かが悪くなる場合にエラー を見つけ出すのがより簡単になります。@code{configure} に @code{--with-debug} オプションをつけて @strong{MySQL} を再コンフィグし、 再コンパイルしてください。@xref{Debugging server}. @item デバッグ用に @strong{MySQL} をコンフィグすると、いくつかのエラーを検出で きる安全なメモリ割り当てを含めます。これは何が起きているかについての多く の出力も提供します。 @item あなたの OS の最新のパッチを適用しましたか? @item @code{--skip-locking} オプションを @code{mysqld} に使用してください。い くつかのシステム上では、@code{lockd} ロックマネージャは正しく動きません; @code{--skip-locking} オプションは @code{mysqld} に外部ロッキングを使用 しないように伝えます。(これは同じデータ上で2つの @code{mysqld} サーバを 動すことができず、@code{myisamchk} の使用時に注意しなければいけないことを 意味します。しかし、テストとしてこのオプションを試すことは指示できます。) @item @code{mysqld} が動いているのに応答がないように見えた時 @code{mysqladmin -u root processlist} を試しましたか? 時々 @code{mysqld} はそう思えても死んでいません。問題は全ての接続が使用中であ ることか、いくつかの内部ロック問題があることです。@code{mysqladmin processlist} は通常これらの場合でも接続を作ることができ、現在の接続数と それらの状態についての有用な情報を提供できます。 @item 別のウィンドウで、統計出力のためにコマンド @code{mysqladmin -i 5 status} をクエリ中、行ってください。 @item 次を試してください: @enumerate @item @code{gdb} (または他のデバッガ) から @code{mysqld} を開始してください。 @item あなたのテストスクリプトを実行してください。 @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 @strong{MySQL} にクラッシュまたは間違った振る舞いをさせるあなたのアプリ ケーションのシミュレートを Perl スクリプトで試みてください。 @item または通常のバグレポートを送ってください。@xref{Bug reports}。しかし通常 よりもさらに詳細にしてください。@strong{MySQL} は多くの人のために働いて いるため、クラッシュはあなたのコンピュータだけに存在する何か(例えば、あ なたの特別なシステムライブラリに関連したエラー)から生じていると思われま す。 @item もし可変長のレコードを扱うテーブルで問題があった場合、 もし、@code{BLOB/TEXT} フィールドは使用しておらず、@code{VARCHAR} フィールド だけ使用しているなら、全ての @code{VARCHAR} フィールドを @code{ALTER TABLE} で @code{CHAR} に変更してみてください。 これは @strong{MySQL} に固定長レコードを使用させるようにします。 固定長レコードは少し余分な領域をとりますが、よりエラーに対して 強くなります。 現在の可変長のレコードのコードは TCX で少なくとも3年以上問題なく 使用されています。 しかし可変長のレコードはよりエラーの傾向があり、 上記の事柄を試すことは良いアイデアです! @end itemize @node Common errors, Full disk, Crashing, Problems @section @strong{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 * 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} エラー このセクションは @code{Lost connection to server during query} エラーに関することもカバーします。 @code{MySQL server has gone away} エラーのもっとも一般的な理由は、サーバ がタイムアウトで接続をクローズしたことです。デフォルトでは、何も起きない 場合、サーバは 8 時間後に接続をクローズします。 この時間は mysqld 起動時の @code{wait_timeout} 変数に与えることにより、変更できます。 @code{mysqladmin version} を実行することで @strong{MySQL} が死んでいるかどうか、 また uptime はどれぐらいか、チェックできます。 スクリプトの場合は、自動的に再接続するためにクライアントからクエリを再発 行する必要があります。 この場合、通常これらのエラーコードを得ます: (OS 依存です): @multitable @columnfractions .3 .7 @item @code{CR_SERVER_GONE_ERROR} @tab クライアントがサーバーに問い合わせを送ることができなかった @item @code{CR_SERVER_LOST} @tab クライアントがサーバーに書き込みを行ったときにはエラーは無かったけれども、問い合わせに対して完全に回答が返ってこない @end multitable 間違っているか大きすぎるクエリをサーバに送った場合にもこのエラーが発生し ます。@code{mysqld} が間違ったブロックを得た場合、クライアントの何かが間違った と見なし、接続をクローズします。大きなクエリが必要な場合、例えば大きな @code{BLOB} で働かせる場合は、@code{mysqld} をオプション @code{-O max_query_size=#} (デフォルト 1M) で起動することでクエリ制限を増加できます。拡張メモリ は要求によって割り当てられます。そのため、@code{mysqld} は大きなクエリを発行し た時や大きな結果行を返す必要のある時だけ、多くのメモリを使用します! @node Can not connect to server, Blocked host, Gone away, Common errors @subsection @code{Can't connect to [local] MySQL server} エラー UNIX 上の @strong{MySQL} クライアントは @code{mysqld} サーバに2つの異なる方法で接続できま す: Unix ソケット, これはファイルシステム上のファイル(デフォルト @file{/tmp/mysql.sock})を通して接続します。または TCP/IP, これはポート番 号を通して接続します。Unix ソケットは TCP/IP よりも速いですが、サーバと 同じコンピュータから接続する時しか使えません。Unix ソケットは、ホスト名 を指定しない場合か、特別なホスト名 @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. (2002) @code{Can't connect to ...} エラーは、通常、@strong{MySQL} サーバーが システム上に走っていないか、あなたが、間違ったソケットファイルや TCP/IP ポートを使用して @code{mysqld} に接続しようとする場合におきます。 Start by check サーバー上に @code{mysqld} というプロセスが走っているか ( @code{ps} を使用して。 Windows の場合はタスクマネージャでみて) 確認することから開始してください! @xref{Starting server}. @code{mysqld} プロセスが走っているなら、違う接続を試すことでサーバーを 確認することができます(もちろん、ポート番号とソケットのパスはあなたが セットアップしたものとは違うでしょう): @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 @code{hostname} コマンドはフォワードクオートでなくバッククオテーションで 囲んでいることに注意してください; これは @code{ホスト名} (カレントのホスト名) を @code{mysqladmin} コマンドに与えます。 @code{Can't connect to local MySQL server} エラーが起こりうる理由として: @itemize @bullet @item @code{mysqld} is not running. @item MIT-pthreads を使用するシステム上で実行している。 ネイティブスレッドを持たないシステム上で実行している場合 @code{mysqld} は MIT-pthreads パッケージを使用します。 @xref{Which OS}. MIT-pthreads スレッドはソケットをサポートしません。 そのため、サーバに接続する時は常にホスト名を与える必要があります。 サーバーへの接続をチェックするために、以下を試してください: @example shell> mysqladmin -h `hostname` version @end example @item 誰かが @code{mysqld} が使用する unix ソケット を削除した (default @file{/tmp/mysqld.sock}). だれかが @code{cron} で @strong{MySQL} ソケットを削除しているかもしれません。(例えば @file{/tmp} ディレクトリから古いファイルを削除するようなクローンで)。 いつでも @code{mysqladmin version} を実行して @code{mysqladmin} が使用するソケットが本当に存在するかをチェックできます。 この場合の修正は、@file{mysqld.sock} を消さないように @code{cron} を変更するか、またはソケットをどこか他の場所に移すことです。 @strong{MySQL} を ./configure する場合にソケットを指定するには以下のようにします: @example shell> ./configure --with-unix-socket-path=/path/to/socket @end example また、@code{safe_mysqld} を @code{--socket=/path/to/socket} オプションを指定して起動しても構いませんし、 @code{MYSQL_UNIX_PORT} 環境変数をセットして @strong{MySQL} クライアントを実行してもかまいません。 @item @code{--socket=/path/to/socket} オプションで @code{mysqld} サーバーを起動できます。 もしサーバーのソケットのパスを変えた場合、@strong{MySQL} クライアントに、新しいパスを教えなければなりません。 この場合、 @code{MYSQL_UNIX_PORT} 環境変数に設定することにより可能です。 ソケットのテストをする場合、以下のようにします: @example shell> mysqladmin --socket=/path/to/socket version @end example @item Linux を使用していてスレッドが一つ死んだとき(コアダンプした)。 この場合、他の @code{mysqld} スレッドをキルしなければなりません。 たとえば、@code{mysql_zap} スクリプトを、新しく @strong{MySQL} サーバーを 起動する前に実行します。 @xref{Crashing}. @end itemize もし @code{Can't connect to MySQL server on some_hostname} エラーの場合, 何が問題なのかを見つけるために、以下の手順を踏みます: @itemize @bullet @item もし @code{telnet your-host-name tcp-ip-port-number} を実行すると サーバーがアップするなら、 @code{RETURN} を何回かたたいてください。 もしこのポートで @strong{MySQL} サーバーが走っているなら、 走っている @strong{MySQL} サーバーのバージョンナンバーを含んだ レスポンスが得られるはずです。 もし @code{telnet: Unable to connect to remote host: Connection refused} のような エラーになったならば、このポートを使用しているサーバーはありません。 @item ローカルのマシンの @code{mysqld} デーモンに接続してみてください。 @code{mysqld} が使用するように指定された TCP/IP ポートをチェックしてください。 (@code{mysqladmin variables} で得られる @code{port} 変数) @item @code{mysqld} サーバーが @code{--skip-networking} オプションで起動されていないか 確認してください。 @end itemize @node Blocked host, Too many connections, Can not connect to server, Common errors @subsection @code{Host '...' is blocked} エラー 以下のエラーの場合: @example Host 'hostname' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts' @end example これは @code{mysqld} が多くの @code{'hostname'} ホストからの接続エラー(@code{max_connect_errors}) を受けた場合に発生します。 この @code{max_connect_errors} 大量発生後、@code{mysqld} は何か(クラッカーによるサーバーへのアタックなど)が起こったと判断し、このホストからの接続をいっさい拒否するようにします。 これを解除するには、@code{mysqladmin flush-hosts} コマンドを実行します。 デフォルトでは、10回の接続エラーが発生した場合に、@code{mysqld} はそのホストを拒否します。 この値は以下のようにして簡単に変更できます: @example shell> safe_mysqld -O max_connect_errors=10000 & @end example もしこのエラーがあるホストに対して発生するならば、まず最初にそのホストからの TCP/IP 接続に不具合がないかチェックしてください。 もし TCP/IP 接続が動作していないようなら、 @code{max_connect_errors} 値を増やすことはよくないことです! @node Too many connections, Out of memory, Blocked host, Common errors @subsection @code{Too many connections} エラー もし @strong{MySQL} に接続しようとして @code{Too many connections} となった場合、 これは既に @code{max_connections} 分、クライアントから @code{mysqld} サーバーへの 接続が行われています。 もしデフォルトの100よりも多い接続を必要とするならば、 @code{max_connections} 変数に多くの値を与えて、@code{mysqld} を リスタートしなくてはなりません。 実際は、@code{mysqld} は (@code{max_connections}+1) 個のクライアントからの接続を許しています。 最後の1個は、 @code{process} 権限をもつユーザーのために取ってあります。 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} エラー クエリを行って、次のエラーのようなものを得た場合: @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 エラーは @strong{MySQL} クライアント @code{mysql} に関係することに注意してください。エ ラーの理由は単純で、クライアントが結果全体を格納するのに十分なメモリを持っ ていないことです。 この問題を解決するにあたり、まず最初にクエリーが正しいか確認してください。 そのクエリーは大量の結果を返すものでしょうか? もしそうなら、@code{mysql --quick} を使用してください。 これは結果を取り出すために @code{mysql_use_result()} を使用します。 これはクライアントのロード不足を補います(サーバーより多い領域は取れません)。 @node Packet too large, Full table, Out of memory, Common errors @subsection @code{Packet too large} エラー @strong{MySQL} クライアントが @code{max_allowed_packet} よりも大きなブロックを @code{mysqld} サーバーから得た時、@code{Packet too large} エラーを発します。 @code{mysql} クライアントを使用する場合、@code{mysql --set-variable=max_allowed_packet=8M} でクライアントを開始することで、バッファを大きく設定できます。 もし(@code{DBI} のように)最大パケットサイズを指定できないクライアントを使用している場合、 パケットサイズを指定してサーバーを立ち上げ直します。 これは @code{mysqld} のオプションの @code{max_allowed_packet} に大きな値を設定することで行います。 例えば、 @code{BLOB} 型の許容範囲いっぱいのデータをテーブルに入れる場合、 @code{--set-variable=max_allowed_packet=24M} オプションを指定してサーバーを起動する必要があります。 @cindex The table is full @node Full table, Commands out of sync, Packet too large, Common errors @subsection @code{The table is full} エラー このエラーは、古い @strong{MySQL} バージョンにおいて、 メモリ内一時テーブルが @code{tmp_table_size} よりも大きくなっ た時に発生します。この問題を回避するために、@code{mysqld} のオプション @code{-O tmp_table_size=#} で増加、または、SQL オプション @code{SQL_BIG_TABLES} を問題のクエリの前に使用できます。@xref{SET OPTION, , @code{SET OPTION}}. @code{mysqld} を @code{--big-tables} オプション指定して起動します。 これは全てのクエリーに対して @code{SQL_BIG_TABLES} を使用するのと同じです。 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 @code{Commands out of sync; You can't run this command now} をクライアン トコード中で得た場合、クライアント関数を間違った順番で呼び出しました! これは例えば、@code{mysql_use_result()} を使用していて、@code{mysql_free_result()} を行う前に新しいクエリの実行を試みた場合に発生します。これはまた、データ を返す2つのクエリの実行を、間に @code{mysql_use_result()} や @code{mysql_store_result()} 無しで試みた場合にも発生します。 @node Ignoring user, Cannot find table, Commands out of sync, Common errors @subsection @code{Ignoring user} エラー 以下のエラーの場合: @code{Found wrong password for user: 'some_user@@some_host'; Ignoring user} これは @code{mysqld} の開始または 'reload' 時に @code{user} テーブル内に正しいパスワー ドを持たないエントリを見つけたことを意味します。 これは単にエントリが許可システムに拒否されているだけです。 起こり得ることとその解決: @itemize @bullet @item 新しいバージョンの @code{mysqld} を、古いバージョン用の @code{user} テーブルで走らせているのかもしれません。 @code{mysqlshow mysql user} を行うことによってこれを検証できます。 パスワードフィールドが 16 文字よりも短いかどうかをチェックしてください。 もしそうなら、これを修正するために、@code{scripts/add_long_password} スクリプトを実行してください。 @item ユーザーが古いパスワード(最大8文字) を使用していて、@code{mysqld} を @code{--old-protocol} オプションで起動していないのかもしれません。 新しいパスワードで @code{user} テーブル内のユーザを更新するか、@code{--old-protocol} 付きで @code{mysqld} を再起動してください。 @item @findex PASSWORD() @code{user} テーブルのパスワードを、@code{PASSWORD()} 関数を使用しないで登録したのかもしれません。 この場合、@code{user} テーブルのパスワードを、@code{mysql} を使用して更新します。 @code{PASSWORD()} 関数は以下のようにして使用します: @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 もし @code{Table 'xxx' doesn't exist} か @code{Can't find file: 'xxx' (errno: 2)} エラーが出た場合、使用しているデータベースに @code{xxx} という名前のテーブルが 見付からなかったことを示します データベースとテーブルの保存に、@strong{MySQL} はディレクトリとファイルを使用し、 データベースとテーブルの名前は@strong{ケース依存}です! (Win32 ではデータベースとテーブル名はケース非依存です。 クエリ中のテーブルに対する問い合わせは全て、同じケースで書かなくてはなりません!) @code{SHOW TABLES} を使用してデータベースのテーブルを確認できます. @xref{SHOW, , @code{SHOW}}. @cindex Full disk @cindex Disk full @node Full disk, Multiple sql commands, Common errors, Problems @section @strong{MySQL} はフルディスクをどのように扱うか? @noindent ディスクフルが起きた場合 @strong{MySQL} は次のことを行います: @itemize @bullet @item 現在の行を書くのに十分な領域があるかどうかを1分毎に1回チェックします。十 分なディスクがある場合は、何も起きなかったように継続します。 @item 6分毎にログファイルにディスクフルを警告するエントリを書き出します。 @end itemize @noindent この問題の場合、以下のようにします: @itemize @bullet @item 継続するためには、全てのレコードを挿入するのに十分な領域を解放する必要が あります。 @item スレッドをアボートするためには、@code{mysqladmin kill} をスレッドに送る 必要があります。スレッドは次に(1分)ディスクをチェックした時にアボートし ます。 @item 他のスレッドが ``disk full'' が発生したテーブルで待たされることに注意して ください。多くの ``locked'' スレッドがある場合、disk full を待つ一つのスレッ ドを kill することで、他のスレッドの継続を許します。 @end itemize @node Multiple sql commands, Temporary files, Full disk, Problems @section テキストファイルから SQL コマンドを実行 @code{mysql} クライアントは以下のようにして対話的に使用します: @example shell> mysql database @end example しかし SQL コマンドをファイルに書いておき、それを @code{mysql} に読み込ませることができます。 テキストファイル @file{text_file} に実行したいコマンドを書いておき、 以下のようにして @code{mysql} を起動します: @example shell> mysql database < text_file @end example テキストファイルの先頭に @code{USE db_name} 構文を書くこともできます。 この場合、データベース名をコマンドラインに与える必要は無く、以下のようにできます: @example shell> mysql < text_file @end example @xref{Programs}. @node Temporary files, Problems with mysql.sock, Multiple sql commands, Problems @section @strong{MySQL} が一時ファイルを格納する場所 @strong{MySQL} は一時ファイルを格納する場所として @code{TMPDIR} 環境変数の値を 使用します。@code{TMPDIR} を設定していなければ、@strong{MySQL} はシステムのデフォ ルトを使用します。通常は @file{/tmp} または @file{/usr/tmp} です。@code{TMPDIR} が小さ すぎる場合、@code{safe_mysqld} を編集して、十分な領域がある他のディレクトリを指 すように @code{TMPDIR} を設定すべきです! @code{--tmpdir} オプションを @code{mysqld} に与えることで、一時ファイルディレクトリを指定することも可能です。 @strong{MySQL} は全ての一時ファイルを ``隠しファイル'' として生成します。 これは @code{mysqld} が終了した場合に、一時ファイルが削除されないことを確実にし ます。隠しファイルを使用する '悪い' 側面は、小さすぎる一時ディスクを一杯 にする大きな一時ファイルを見つけられないことです。 ソート時 (@code{ORDER BY} または @code{GROUP BY})、@strong{MySQL} は通常一つまたは二つ の一時ファイルを使用します。必要な最大のディスク容量は: @example (length of what is sorted + sizeof(database pointer)) * number of matched rows * 2 @end example @code{sizeof(database_pointer)} は通常4ですが、将来本当に大きなテーブル のために大きくなることもあります。 いくつかの @code{SELECT} クエリは一時的な SQL テーブルも生成します。これらは隠 しファイルではなく、@file{SQL_*} という名前です。 @code{ALTER TABLE} , @code{OPTIMIZE TABLE} は一時テーブルをオリジナルテーブルと同じディレクトリ 内に生成します。 @node Problems with mysql.sock, Error Access denied, Temporary files, Problems @section @file{/tmp/mysql.sock} を削除から守る方法 もし誰かに @strong{MySQL} のソケットファイル @file{/tmp/mysql.sock} が消されるなら、 ほとんどの Unix がそうであるように、 @file{/tmp} に @code{sticky} ビットをたてて保護します。 @code{root} でログインして、以下のようにします: @example shell> chmod +t /tmp @end example これはファイルのオーナーとスーパーユーザー(@code{root}) のみが、 @file{/tmp} のファイルを消すことができます。 @code{sticky} ビットが立っているか確認するには、 @code{ls -ld /tmp} を行います。 パーミッションの最後のビットが @code{t} ならば、セットされています。 @node Error Access denied, Changing MySQL user , Problems with mysql.sock, Problems @section @code{Access denied} エラー @xref{Privileges}. @xref{Access denied}. @node Changing MySQL user , Resetting permissions, Error Access denied, Problems @section 一般ユーザで @strong{MySQL} を動かす方法 @code{mysqld} (@strong{MySQL} サーバ) は誰でも開始し実行することができます。 @code{mysqld} をユーザ @code{user_name} で実行するように変更するためには、次を行なう必要が あります: @enumerate @item サーバーを止めます (use @code{mysqladmin shutdown}). @item @code{user_name} が読み書きできるように、データベースディレクトリとその中のファイルのパーミッションを変更します。(これは Unix @code{root} ユーザーで実行する必要があるでしょう): @example shell> chown -R user_name /path/to/mysql/datadir @end example @strong{MySQL} データベースディレクトリのディレクトリーやファイルがシンボリックリンクの場合、 これらリンクの先のディレクトリとファイルも変更します。@code{chown -R} はシンボリックリンク先を変更してくれません。 @item ユーザ @code{user_name} でサーバを起動します。または @strong{MySQL} 3.22 以降を使用する 場合は、@code{mysqld} を Unix @code{root} で起動し @code{--user=user_name} スイッチを使用します。 @code{mysqld} は、接続を許可する前に、与えられた Unix user @code{user_name} で実行するように切り替えます。 @item システム再起動時、 @code{mysql.server} を使用して @code{mysqld} を起動する場合、ユーザ @code{user_name} への @code{su} を行なうようにまたは @code{--user} スイッチを使用して @code{mysqld} を起動するように @code{mysql.server} を 変更すべきです。 (No changes to @code{safe_mysqld} are necessary.) @end enumerate この時点で、あなたの @code{mysqld} プロセスは Unix user @code{user_name} で正常に動作します。 一つのことは変わりません。それは権限許可テーブルです。デフォルト (パーミッションテーブルインストールスクリプト@code{mysql_install_db}実行後の権限) では、@code{mysql}データベースへのアクセスやデータベースの作成、破棄はユーザ @strong{MySQL} user @code{root} だけです。 これを変更しないと、それはそのままです。 @code{root} 以外のUnix userでログインしている時でも、あなたは @strong{MySQL} @code{root} user としてアクセスは可能です - ただプログラムに @code{-u root} をクライアントプログラムにオプション指定するだけです。 @strong{MySQL} に @code{root} としてアクセスするには、 コマンドラインで @code{-u root} を使用するだけでいいことに注意してください。 Unix @code{root} user や @strong{MySQL} を走らせている Unix ユーザーである必要は@emph{ない}ことに注意してください。 @strong{MySQL} のアクセスパーミッションと@strong{MySQL} のユーザは、 UNIX ユーザとは完全に別のものです。UNIX ユーザに関係するのは、クライアン トに @code{-u} オプションを使用しない場合だけです。この場合、クライアントは @strong{MySQL} へのログインを、あなたの UNIX ログイン名で試みます。 あなたの UNIX マシンそれ自身が安全でない場合は、少なくとも @strong{MySQL} ア クセステーブルの @strong{MySQL} @code{root} ユーザにはパスワードを設定すべきです。 どこかの誰かが @code{mysql -u root db_name} を行ない、彼が望むことの全てを実行できてしまうからです。 @node Resetting permissions, File permissions , Changing MySQL user , Problems @section 忘れたパスワードをリセットする もし @strong{MySQL} の @code{root} ユーザーのパスワードを忘れた場合、 これを以下のようにして入れ直すことが可能です。 @enumerate @item @code{mysqld} サーバーを @code{kill} で落とす。 (@code{kill -9} ではありません!) PID 番号は通常 @strong{MySQL} データディレクトリに @code{.pid} ファイルとして 書かれています: @example kill `cat /mysql-data-directory/hostname.pid` @end example これを、 UNIX @code{root} ユーザーか、@strong{MySQL} サーバーを実行した ユーザーで行います。 @item @code{mysqld} を @code{--skip-grant-tables} オプションで起動。 @item @code{mysql -h hostname mysql} で@code{mysqld} サーバーに接続し、 @code{GRANT} コマンドでパスワードを変更します。 @xref{GRANT,,@code{GRANT}}. @code{mysqladmin -h hostname -u user password 'new password'} でも変更可能です。 @item 許可テーブルを読み込みます: @code{mysqladmin -h hostname flush-privileges} か、SQL 文の @code{FLUSH PRIVILEGES} を実行します。 @end enumerate @node File permissions , Not enough file handles, Resetting permissions, Problems @section ファイルパーミッションの問題 ファイルパーミッションの問題がある場合、 例えば、テーブルの生成時に @code{mysql} が次を出力する場合: @example ERROR: Can't find file: 'path/with/filename.frm' (Errcode: 13) @end example @tindex UMASK environment variable @tindex Environment variable, UMASK これは @code{UMASK} 環境変数が @code{mysqld} 起動時に間違ってセットされていると考えられます。 デフォルトの umask は @code{0660} です. これは以下のようにして @code{safe_mysqld} 立ち上げ時に変更できます: @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 @code{ERROR '...' not found (Errcode: 23)}, @code{Can't open file: ... (errno: 24)} や @code{errcode 23} @code{errno 24} のエラーを @strong{MySQL} から得た場合、 これは @strong{MySQL} に十分なファイル記述子が割り当てられなかったことを意味します。 @code{perror #} はさらに読みやすい形式のエラーメッセージを与えます: @example shell> perror 23 File table overflow shell> perror 24 Too many open files @end example これは @code{mysqld} が多くのファイルを開こうとしたことに起因します。 @code{mysqld} に一度に開くファイル数を多く開かないようしたり、あるいは、 @code{mysqld} が扱えるファイル記述子の数を与えたりできます。 @code{mysqld} が一度に開くファイルの数を少なくするには、@code{-O table_cache=32} オプション(デフォルトは64)を @code{safe_mysqld} に与えることで可能です。 また、@code{max_connections} の値(デフォルトは90)を少なくするならば、開くファイル数も少なくできます。 @tindex ulimit @code{mysqld} が取り扱えるファイル記述子の数を変更するには、 @code{safe_mysqld} を編集します。 この中に @code{ulimit -n 256} がコメントアウトされています。 このコメントをはずし(@code{'#'}文字を消す)、256 を @code{mysqld} が扱う数に変更してください。 @code{ulimit} はオペレーティングシステムの制限内でしかファイル記述子の数を指定できません。 もし OS の制限以上にファイル記述子のオープン数を増やしたい場合、 お使いのオペレーティングシステムのドキュメントを見て対処してください。 @code{tcsh} を使用している場合は @code{ulimit} は動かないことに注意してください! @code{tcsh} は現在の制限をあなたが問い合わせても、違った値を報告するでしょう。 この場合、@code{safe_mysqld} は @code{sh} で起動すべきです! @node Using DATE, Timezone problems, Not enough file handles, Problems @section @code{DATE} フィールド使用時の問題 日付 @code{DATE} の形式は @code{'YYYY-MM-DD'} です。ANSI SQL に従って実際には他のは許されま せん。更新または @code{SELECT} 文中の WHERE 節内ではこの形式を使用すべきです。すなわち: @example mysql> SELECT * FROM tbl_name WHERE date >= '1997-05-05'; @end example 利便のため @strong{MySQL} は、日付が数値の文脈で使用されると、日付を自動的に数 値に変換します。これにより、更新と @code{TIMESTAMP}, @code{DATE} または @code{DATETIME} フィールドでの @code{WHERE} 時に、わりと自由に日付を指定することができます。 (この記述を許すため、句読記号を日付のセパレーターとして使用します。 例えば、@code{'1998-08-15'} と @code{'1998#08#15'} は同一です.) もしろんセパレーターのない記述(例:@code{'19980815'})も日付として変換してくれます。 特別な日付 @code{'0000-00-00'} は @code{'0000-00-00'} として格納され取り出されます。 @strong{MyODBC} を通して @code{'0000-00-00'} 日付を使用する時、@strong{MyODBC} 2.50.12 以上では自 動的に @code{NULL} に変換されます。ODBC はこの日付の種類を扱えないためです。 これは次が動くことを意味します: @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 次は動きません: @example mysql> SELECT idate FROM tbl_name WHERE STRCMP(idate,'19970505')=0; @end example @code{STRCMP()} は文字列関数で、@code{idate} を文字に変換して、文字比較を行います。 @code{'19970505'} は日付には変換してくれず、日付の比較も行いません。 @strong{MySQL} は日付が正しいかどうかをチェックしないことに注意してくだ さい。間違った日付(例えば @code{'1998-2-31'})を格納すると、その間違った日付が格納 されます。日付が全体的に不可能な場合、@code{0} が @code{DATE} フィールドに格納されます。 これは主に速度の問題で、日付のチェックはサーバではなくアプリケーションでと我々 は考えています。 @cindex Timezone problems @tindex TZ environment variable @tindex Environment variable, TZ @node Timezone problems, Case sensitivity, Using DATE, Problems @section Timezone problems もし @code{SELECT NOW()} があなたのローカル時間ではなく GMT を返すなら、 @code{TZ} 環境変数をローカルのTimezone に設定しなくてはなりません。 環境変数の設定は、サーバーを実行する前に行われなくてはなりません。 たとえば、@code{safe_mysqld} や @code{mysql.server} スクリプトで 行います。 @cindex Case sensitivity, in searches @cindex Chinese @cindex Big5 Chinese character encoding @node Case sensitivity, Problems with NULL, Timezone problems, Problems @section 検索時のケース依存 デフォルトでは @strong{MySQL} フィールドはケース非依存です (しかし、ケース非依 存にならないいくつかの文字セットはありますsuch as @code{czech})。 これは、@code{col_name LIKE 'a%'} で検索した場合、@code{A} または @code{a} で始まる全てのフィールドを得ることを 意味します。検索をケース依存にしたいのなら、始まりをチェックするには @code{INDEX(column, "A")=0} のようなことを、また、文字列全体が同じかどう かには @code{STRCMP(column, "A") = 0} を使用してください。 単純な比較操作 @code{>=, >, =, <, <=}、ソートそしてグループ化は、文字 ``sort value'' 上で行われます。同じソート値の文字 (like E, e and @'e)は同じ文字と して扱われます! @code{LIKE} 比較は各文字の大文字で行われます (E == e but E <> @'e) @code{column} をいつでもケース依存で扱いたい場合は、それを @code{BINARY} として宣言してください。@xref{CREATE TABLE, , @code{CREATE TABLE}}. big5 エンコーディングと呼ばれる中国語データを使用している場合は、全ての 文字項目を @code{BINARY} にしてください。これは、big5 エンコーディング文 字のソート順が ascii コードが基になっているため、機能します。 @cindex NULL values vs. empty values @tindex NULL @node Problems with NULL, Problems with alias, Case sensitivity, Problems @section @code{NULL} 値での問題 SQL の初心者のありがちな混乱は、@code{NULL} 値が空文字列 @code{''} と同じ物だと考えるこ とです。これは正しくありません! 例えば、次のステートメントは全く別のも のです: @example mysql> INSERT INTO my_table (phone) VALUES (NULL); mysql> INSERT INTO my_table (phone) VALUES (""); @end example 両方の文とも @code{phone} フィールドに値を挿入していますが、 初めのは @code{NULL} 値を挿入し、二番目のは空文字列を挿入しています。 初めのは ``電話番号を知らない'' と見なされ、二番目のは ``彼女は電話を 持っていない'' と見なされます。 SQL では、 @code{NULL} は他の全ての値(たとえ @code{NULL} でも)と比較した時に、常に偽に なる値です。 @code{NULL} を含む式は、特に断りがなければ、常に @code{NULL} 値を生成しま す。次の項目は全て @code{NULL} を返します: @example mysql> SELECT NULL,1+NULL,CONCAT('Invisible',NULL); @end example @code{NULL} 値がセットされている項目を検索する場合、 @code{=NULL} テストを行わないでください。 これは @code{expr = NULL} が FALSE なので、なんの行も返しません。 例えば以下の例: @example mysql> SELECT * FROM my_table WHERE phone = NULL; @end example @code{NULL} 値を持つフィールドを検索したい場合は、@code{IS NULL} テストを使用しなくてはいけま せん。次は @code{NULL} 電話番号と空の電話番号を見つける方法を示しています: @example mysql> SELECT * FROM my_table WHERE phone IS NULL; mysql> SELECT * FROM my_table WHERE phone = ""; @end example @strong{MySQL} では、他の多くの SQL サーバのように、@code{NULL} 値を持つ インデックスフィールドを持てません。これらのフィールドは @code{NOT NULL} と宣言しな くてはいけません。 インデックスフィールドには、@code{NULL} を設定することはできません。 @findex LOAD DATA INFILE @code{LOAD DATA INFILE} でデータを読み込むときは、空のフィールドは @code{''} で更新されます。 項目を @code{NULL} 値にしたい場合は、テキストファイル中に @code{\N} を使用すべきです。 リテラルとしての @code{'NULL'} 語が、ある状況下で使用されています。 @xref{LOAD DATA, , @code{LOAD DATA}}. @code{ORDER BY} 使用時, @code{NULL} 値は最初に提示されます. @code{DESC} を使用して降順にソートする時、@code{NULL} 値は最後になります。 @code{GROUP BY} 使用時, 全ての @code{NULL} 値は等しいと見なされます。 @code{NULL} 処理を手助けするため、次の関数を使用できます: @code{IS NULL}, @code{IS NOT NULL}, @code{IFNULL()}. @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 いくつかの項目型では、@code{NULL} 値はハンドルとして扱われます。 もしテーブル内の最初の @code{TIMESTAMP} 項に @code{NULL} を挿入するなら、 現在の日付と時刻が挿入されます。もし @code{AUTO_INCREMENT} 項に@code{NULL} 値を挿入するなら、 次のシーケンス番号が挿入されます。 @tindex alias @node Problems with alias, Deleting from related tables, Problems with NULL, Problems @section @code{alias} の問題 @code{GROUP BY}, @code{ORDER BY}, @code{HAVING} 節において 項目を参照するに当たりエイリアスが使用できます。 エイリアスは項目としてより良い名称を与えるのに使用されます: @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 ANSI SQL が @code{WHERE} 節内でエイリアスを参照することを 許可していないことに注意してください。これは @code{WHERE} が実行される時点で 項目の値がまだ決定されていないからです。例えば、以下のクエリは @strong{あやまりです}: @example SELECT id,COUNT(*) AS cnt FROM table_name WHERE cnt > 0 GROUP BY id; @end example どの行が @code{GROUP BY} に含まれるかを決めるために @code{WHERE} 構文が 実行される一方で、 得られた結果のどの行を使うか確定するために @code{HAVING} が使用されます。 @node Deleting from related tables, No matching rows, Problems with alias, Problems @section Deleting rows from related tables @strong{MySQL} は現在 sub-select は未サポートで、また @code{DELETE} 構文で複数のテーブルを扱う事もサポートしていません。 したがって、2つのテーブルに関連するレコードを消すには、以下のようにして行います: @enumerate @item いくつかの @code{WHERE} 条件を使用して、基本となるテーブルから行を @code{SELECT} @item 同じ条件下で、基本となるテーブルに含まれる行を @code{DELETE} @item @code{DELETE FROM related_table WHERE related_column IN (selected_rows)} @end enumerate @code{related_column} のクエリの合計文字数が、1,048,576 (デフォルトは @code{max_allowed_packet} の値) をこえる場合、 それをいくつかに分割して、複数の @code{DELETE} 構文にしなくてはなりません。 @code{related_column} がインデックスで、100-1000 の@code{related_column}だけを消す場合、 よりはやく @code{DELETE} できます。 もし @code{related_column} がインデックスでない場合、その速度は @code{IN} 節の引数の数に無関係になります。 @node No matching rows, ALTER TABLE problems, Deleting from related tables, Problems @section Solving problems with no matching rows 複雑なクエリーを行って、もしなんの結果も返さなければ、 そのクエリーの何が悪いかを見つけるため、以下の手続きを行います: @enumerate @item @code{EXPLAIN} を使用してクエリーをテストし、明白な間違いを見つけます。 @xref{EXPLAIN, , @code{EXPLAIN}}. @item @code{WHERE} 節で使用されているフィールドだけを Select してみます @item 結果が返ってくるまで、一つ一つクエリーからテーブルを取り除いていきます。 テーブルが大きい場合、@code{LIMIT 10} をクエリーで使用することは良くありません。 @item 行にマッチすべきであろう項を @code{SELECT} してみます。 その場合、select するのは、上記で最後に取り除いたテーブルに対して行います。 @item もし @code{FLOAT} か @code{DOUBLE} 型のものを数字と比較するなら、 @code{=} は使用しないでください!これはほとんどのコンピュータ言語において、 浮動小数点の値はぴったりの値にならないからです。 @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 もしなにも悪いところを見つけることができなかった場合、 小さなテストをつくって @code{mysql test < query.sql} を行ってみてください。 @code{mysqldump --quick database tables > query.sql} でテストファイルを作成できます。 このファイルをエディターで編集し、いくつかのinsert行を(多すぎるなら)消します。 そしてファイルの最後にselect構文を付け足します。 テストを行うには: @example shell> mysqladmin create test2 shell> mysql test2 < query.sql @end example @code{mysqlbug} を使用して @email{mysql@@lists.mysql.com} にテストを投稿してください。 @end enumerate @node ALTER TABLE problems, Change column order, No matching rows, Problems @section Problems with @code{ALTER TABLE}. もし @code{ALTER TABLE} が以下のようなエラーで死んだ場合: @example Error on rename of './database/name.frm' to './database/B-a.frm' (Errcode: 17) @end example これは以前の @code{ALTER TABLE} で @strong{MySQL} がクラッシュしており、 @file{A-something} か @file{B-something} という名前の、誤った情報を流している 古いテーブルが存在しています。 この場合、@strong{MySQL} データディレクトリに入り、@code{A-} や @code{B-} で始まる 名前を持つファイルを全て消します。 (消す代わりにどこかに移動しても構いません。) @code{ALTER TABLE} は以下のように動作します: @itemize @bullet @item 変更要求のあった @file{A-xxx} という名前の新しいテーブルを作成。 @item 元のテーブル内の全ての行を @file{A-xxx} にコピー。 @item 元のテーブルを @file{B-xxx} に名称変更。 @item @file{A-xxx} は元のテーブル名に名称変更される。 @item @file{B-xxx} は消去される。 @end itemize もし名称変更の際に問題があると、@strong{MySQL} は変更を取り消すように動きます。 致命的な問題が起きた場合(ありえませんが)、@strong{MySQL} は元の古いテーブルを @file{B-xxx} という名前のままにしておきます。単に名称変更すればデータは戻ります。 @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 @strong{MySQL} @cindex Replication @menu * Log Replication:: 更新ログを使用したデータベースの複製 * Backup:: データベースのバックアップ * Update log:: The update log * Multiple servers:: 同一マシン上に複数の @strong{MySQL} サーバーを走らせる @end menu @cindex Database replication @cindex Log Replication, database @node Log Replication, Backup, Common problems, Common problems @section 更新ログを使用したデータベースの複製 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}. これは、一つのデータベースがマスター(主)として動作ふるまっており (全てのデータ変更がここで行われます)、かつ、一つ以上の他のサーバーがスレーブ(従)と して動作していることを要求します。 スレーブを更新するには @code{mysql < update_log} を実行するだけです。 スレーブデータベースのホスト、ユーザー、パスワードをコマンドのオプションに与え、 マスターから取得した更新ログを入力に使用します。 もし、テーブルからなにも削除しない場合、 @code{TIMESTAMP} フィールドを使用すれば、 最後の複製時以後に、新規に挿入されたものや変更されたものだけを ミラーサーバーにコピーできます。(最後の複製を行った時間と比較すれば抽出できます) 更新ログ(削除のため)とタイムスタンプ(両側で)の両方を使用する2つの方法の 更新システムを作ることができます。しかしこの場合は、同じデータが両側で変 更された時に、あなたが衝突を操作できなければなりません。あなたはおそらく 何が更新されたかを決定するのを助けるために、古いバージョンを保持したいで しょう。 この時行う複製には SQL ステートメントで行われるため、データベースを更新す るステートメント中で次の関数は使ってはいけません。これらは他の コピー元のサーバとは違う値を返すからです: @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 全ての時刻関数は、必要な場合にミラーにタイムスタンプを送るようにして、安 全に使用できます。@code{LAST_INSERT_ID()} も安全に使用できます。 @cindex Backups @node Backup, Update log, Log Replication, Common problems @section データベースのバックアップ @strong{MySQL} テーブルはファイルとして格納されるため、バックアップを行 うのは簡単です。矛盾のないバックアップを得るためには、@code{LOCK TABLES} を関連するテーブルで行ってください。@xref{LOCK TABLES, , @code{LOCK TABLES}}. 読み込みロックだ けが必要なので、そのテーブルでデータベースディレクトリのファイルのコピー が行われている間も、他のスレッドはクエリを継続できます。もしくは、テーブルを SQL レベルでバックアップしたいのであれば、@code{SELECT INTO OUTFILE} を使 用できます。 他の方法は @code{mysqldump} プログラムを使用することです: @enumerate @item フルバックアップをとるには: @example shell> mysqldump --tab=/path/to/some/dir --opt --full @end example 若しサーバーがいっさいデータの変更をしないのであれば、 単に全てのテーブルファイル(@file{*.frm}, @file{*.MYD}, @file{*.MYI} files)を コピーするだけでも構いません。 The script @code{mysqlhotcopy} does use this method. @item @cindex Log file, names @code{mysqld} を止め、そして @code{--log-update[=file_name]} オプションをつけて起動します。 @xref{Update log}. ログファイルは、 @code{mysqldump} 実行後に行われたデータベースの変更を 複製するための情報を与えてくれます。 @end enumerate もしリストアをしなければならない場合、まず最初に @code{myisamchk -r} を実行して テーブルの修復を試みてください。 ほとんどの場合、99.9% 修復はできるはずです。 もし @code{myisamchk} が失敗した場合、以下のようにします: (This will only work if you have started @strong{MySQL} with @code{--log-update}. @xref{Update log}.) @enumerate @item オリジナルの @code{mysqldump} バックアップデータをリストアします。 @item 以下のコマンドのようにして、更新ログに記録されている変更を適用します。 @example shell> ls -1 -t -r hostname.[0-9]* | xargs cat | mysql @end example @end enumerate @code{ls} は、全ての更新ログファイルを正しい順で得るために行われます。 @code{SELECT * INTO OUTFILE 'file_name' FROM tbl_name} での選択的バックアップと @code{LOAD DATA FROM INFILE 'file_name' REPLACE ...} でのリストアを行う こともできます。重複レコードを避けるためには、テーブル内に @code{PRIMARY KEY} or a @code{UNIQUE} が必要です。@code{REPLACE} は、'重複インデックス' 衝突があった場合、 新しいレコードを挿入する時に古いレコードが新しいものに置き換えられることを意味します。 @cindex Update log @node Update log, Multiple servers, Backup, Common problems @section 更新ログ @code{--log-update=file_name}オプションを使用して@code{mysqld}を起動すると、 データを更新した全てのSQLコマンドをログファイルに書きます。 もし file_name が与えられなかった場合は、ホスト名がデフォルトで使用されます。 もし file_name にディレクトリパスが含まれなかった場合は、 このファイルはデータディレクトリに書かれます。 もし file_name が拡張を持たなかったなら、@code{mysqld} は @code{file_name.#} という形でログファイルを作成します。 このログファイルはデータディレクトリにかかれ、 その名前は @code{file_name.#} という形式の名前になっています。 @code{#} は @code{mysqladmin refresh} か @code{mysqladmin flush-logs} を実行する度に、 あるいは @code{FLUSH LOGS} 構文を実行したり、サーバーをリスタートする度に 自動的に増える数字です。 もし @code{--log} か @code{-l} オプションを使用した場合、ログファイルの名前は @code{mysqld} は全部のログを @file{hostname.log} に書き出します。 この場合、リスタートやりフレッシュを行っても新しくログファイルを作りません。 (一度クローズして再度オープンしますが。) デフォルトでは、@code{mysql.server} スクリプトは @code{-l} オプションを付加して @strong{MySQL} サーバーを起動します。 もし @strong{MySQL} のパフォーマンスをあげて本番環境などで使用したい場合、 @code{mysql.server} スクリプトから @code{-l} オプションを外してください。 更新ログは、実際に更新されたデータのステートメントだけを書くため、きびきびと動作します。 @code{WHERE} を使用した @code{UPDATE} か @code{DELETE} で結果が得られなかった場合、 ログは書き出されません。 すでにセットされている値に、もう一度項目を更新するような @code{UPDATE} もスキップされます。 ログファイルの更新に従ってデータベースを更新したい場合は、次を行います (更新ログファイル名を @file{file_name.#} と仮定します): @example shell> ls -1 -t -r file_name.[0-9]* | xargs cat | mysql @end example @code{ls} は全てのログファイルを正しく並べるために使用しています。 これは、クラッシュ後にバックアップした状態まで戻りたい、あるいは、 バックアップした後からクラッシュするまでの間のデータの更新を行いたい、 そんな場合に使えます。 @cindex Database replication @cindex Replication, database @cindex Database mirroring @cindex Mirroring, database ログは違うホストのデータベースのミラーやマスターデータベースの複製を作る場合にも利用できます。 @xref{Replication}. @cindex Multiple servers @node Multiple servers, , Update log, Common problems @section 同一マシン上に複数の @strong{MySQL} サーバーを走らせる 同じマシン上で複数のサーバーを走らせたい場合があります。 例えば、すでに存在しているサーバーはそのままにしておいて、新しい @strong{MySQL} をテストしたい場合や、 あるいは、インターネットプロバイダーを営んでいて、@strong{MySQL} をそれぞれの顧客用に提供したい場合など。 複数のサーバーをたちあげる場合、簡単な方法として、 TCP/IP ポート、ソケットファイルを変えて、サーバーをコンパイルする方法があります。 そでに走っているサーバーがデフォルトのポート番号とソケットファイルで動作しているとします。 新しくサーバーを作るには、以下のように @code{configure} します: @example shell> ./configure --with-tcp-port=port_number \ --with-unix-socket=file_name \ --prefix=/usr/local/mysql-3.22.9 @end example @code{port_number} と @code{file_name} には、デフォルトのポート番号、ソケットファイルとは違うものを指定します。 そして @code{--prefix} を、すでに走っている @strong{MySQL} のインストール先とは違うディレクトリーに指定します。 現在走っている @strong{MySQL} サーバーのソケットとポートを知るには、以下のようにします: @example shell> mysqladmin -h hostname --port=port_number variables @end example あなたが使用しているポートに @strong{MySQL} サーバーが走っていれば、 これは変更可能な @strong{MySQL} 変数を(ソケットファイルの名前も含んで)出力します。 立ち上げスクリプト(おそらく @file{mysql.server} ファイル)を編集して 複数の @strong{MySQL} サーバーを立ちあげても構いません。 この場合、 @strong{MySQL} サーバーを再コンパイルする必要はありません。 @code{safe_mysqld} のオプションを指定してサーバーを起動すれば、ポートとソケットを変更できます: @example shell> /path/to/safe_mysqld --socket=file-name --port=port_number @end example もし、他のサーバーがロギングを行っているディレクトリと同じデータベースディレクトリを、 新しいサーバーで使用するのであれば、ログファイルの名前を指定すべきです。 ( @code{safe_mysqld} に @code{--log} と @code{--log-update} を指定する) そうしないと、両方のサーバーが同じログファイルに書き込もうとするからです。 @strong{Warning}: 通常、二つサーバーに同じデータベースを操作させてはいけません! もし使用している OS が fault-free system locking をサポートしていないと、 これは悲惨なことになるでしょう! もし二つ目のサーバーに違うデータベースディレクトリを使用させたい場合、 @code{safe_mysqld} に @code{--datadir=path} オプションを指定します。 @example shell> /path/to/safe_mysqld --datadir=/new/path/to/datadir \ --socket=file-name --port=file-name @end example もし違うポートで走っている @strong{MySQL} サーバーに、 これまた違うポートを使用するように作られたクライアントから接続したい場合、 以下のようにします: @itemize @bullet @item クライアントを @code{--host 'hostname' --port=port_numer} か @code{[--host localhost] --socket=file_name} オプションで起動します。 @item C あるいは Perl プログラムの場合、ポートとソケットを与えることができます: @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 @code{MYSQL_UNIX_PORT} と @code{MYSQL_TCP_PORT} 環境変数に UNIX ソケットファイルと TCP/IP のポート番号とセットし、クライアントを立ちあげます。 もし、このポート番号やソケットファイルを常に使用するのであれば、 @file{.login} ファイルかなにかに環境変数をセットするように書いておけばよいでしょう。 @xref{Environment variables}. @xref{Programs}. @item @tindex .my.cnf file あなたのホームディレクトリの @file{.my.cnf} ファイルに、 通常使用するポート番号とソケットファイルを書くこともできます。 @xref{Option files}. @end itemize @node Clients, Comparisons, Common problems, Top @chapter @strong{MySQL} クライアントツールと API @menu * C:: @strong{MySQL} C API * C API datatypes:: C API データ型 * C API function overview:: C API 関数概要 * C API functions:: C API 関数説明 * 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 * Ruby:: @strong{MySQL} Ruby API @end menu @node C, C API datatypes, Clients, Clients @section @strong{MySQL} C API C API コードは @strong{MySQL} とともに配布されます。これは @code{libmysqlclient} ライブラリに含まれ、C プログラムからデータベースへ のアクセスを許します。 MySQL ソースディストリビューション内のクライアントの多くは C で書かれています。C API の使 用法を示す例を探すなら、これらのクライアントを調べてください。 他のクライアント API の多く(Java を除く全て)は、@strong{MySQL} サーバと の通信にこのライブラリを使用します。そのため、例えば、他のクライアントプ ログラムで使用されるのと同じ環境変数の多くの利点を得ることができます。そ れらはライブラリから参照されるからです。これらの変数のリストについては @ref{Programs} を参照して下さい。 クライアントは最大通信バッファサイズを持ちます。最初に割り当てられるバッ ファのサイズ(16K バイト)は自動的に最大サイズ(デフォルトは 24M)まで増加し ます。バッファサイズは必要に応じて増加するため、単純にデフォルトの最大制 限を増加しても、さらに内部で資源を使用することはありません。このサイズチェッ クは主に間違ったクエリと通信パケットのためのチェックです。 通信バッファは一つの SQL ステートメント(クライアントからサーバへの通信)と、 返されるデータ(サーバからクライアントへの通信)の1レコードを含むのに 十分大きくなくてはいけません。各スレッドの 通信バッファは、任意のレコードやクエリを処理するために、指定された制限まで動的 に増大します。例えば、最大 16M のデータを含む @code{BLOB} 値がある場合、 少なくとも 16M を通信バッファ制限として持つ必要があります(サーバとクライ アントの両方で)。 クライアントのデフォルトの最大値は 24M ですが、サーバの最大値のデフォルトは 1M です。これはサーバ起動時に、@code{max_allowed_packet} パラメータの 値を変更することにより、増やすことが出来ます。 @xref{Server parameters}. @strong{MySQL} サーバは、各クエリ後に各通信バッファを @code{net_buffer_length} バイトに縮小します。 クライアントでは、接続に割り当てられたバッファのサイズは、接続が閉じられるまで減少しません。 クライアントメモリは接続がクローズされた時に調整されます。 スレッドプログラミングを行なう場合は、@strong{MySQL} C API を @code{--with-thread-safe-client} 付きでコンパイルすべきです。これは C API を接続毎のスレッド安全にします。次の場合に限り、2つのスレッドは同じ接 続を共有できます: @table @asis @item 2つのスレッドが同じ接続上で同時に @strong{MySQL} にクエリを送信することは できません。特に @code{mysql_query()} と @code{mysql_store_result()} の間 で、他のスレッドが同じ接続を使用しないことを確実にする必要があります。 @item 多くのスレッドが @code{mysql_store_result()} で取り出された別々の結果セッ トにアクセスできます。 @item @code{mysql_use_result} を使用する場合、結果セットがクローズされるまで、他 のスレッドが同じ接続上で何も尋ねないことを確実にする必要があります。 @end table @node C API datatypes, C API function overview, C, Clients @section C API データ型 @table @code @tindex MYSQL C type @item MYSQL この構造体は一つのデータベース接続のハンドルを表わします。これはほとんど全て の @strong{MySQL} 関数に使用されます。 @tindex MYSQL_RES C type @item MYSQL_RES この構造体はレコードを返すクエリ(@code{SELECT}, @code{SHOW}, @code{DESCRIBE}, @code{EXPLAIN})の結果を表わ します。クエリから返される情報は、この節の残りでは@emph{結果セット}と呼 ばれます。 @tindex MYSQL_ROW C type @item MYSQL_ROW これはデータの1レコードの安全な型表現です。これは現在バイト文字列の配列として実 装されています。(フィールド値がバイナリデータを含むことがある場合、これを NULL 終端文字列として扱うことはできません。そのような値は内部に NULL バイトを含 むことがあるからです。) @code{mysql_fetch_row()} の呼び出しによりレコードが獲得 されます。 @tindex MYSQL_FIELD C type @item MYSQL_FIELD この構造体はフィールドについての情報、つまりフィールドの名前、型、サイズ 等を含んでいます。このメンバは後でさらに詳細に説明されています。 @code{mysql_fetch_field()} を繰り返し呼び出すことにより、各フィールドの @code{MYSQL_FIELD} 構造体を得ることができます。 フィールド値はこの構造体の一部ではありません; それは @code{MYSQL_ROW} 構造 体に含まれています。 @tindex MYSQL_FIELD_OFFSET C type @item MYSQL_FIELD_OFFSET これは、@strong{MySQL} フィールドリストへのオフセットの安全な型表現です。 (@code{mysql_field_seek()} で使用されます。)オフセットはレコード内のフィールド 番号で、0 から始まります。 @tindex my_ulonglong C type @tindex my_ulonglong values, printing @item my_ulonglong レコード数と @code{mysql_affected_rows()}, @code{mysql_num_rows()} そして @code{mysql_insert_id()} に使用される型です。 この型は @code{0} から @code{1.84e19} の範囲を与えます。 システムによっては、@code{my_ulonglong} 型の値を表示しようとしても、動作 しないことがあります。この値を表示するには、@code{unsigned long} に変換 し、@code{%lu} 出力書式を使用してください。例: @example printf (Number of rows: %lu\n", (unsigned long) mysql_num_rows(result)); @end example @end table @noindent @code{MYSQL_FIELD} 構造体は次のメンバを含みます: @table @code @item char * name フィールドの名前。null終端文字列。 @item char * table このフィールドを含むテーブルの名前。計算されたフィールドでない場合のみ有 効です。計算されたフィールドでは、@code{table} 値は空文字列です。 @item char * def このフィールドのデフォルト値。null終端文字列。 これは @code{mysql_list_fields()} 使用時にだけ設定されます。 @item enum enum_field_types type フィールドの型。 @code{type} 値は次の一つです: @multitable @columnfractions .3 .55 @item @strong{型の値} @tab @strong{型の意味} @item @code{FIELD_TYPE_TINY} @tab @code{TINYINT} フィールド @item @code{FIELD_TYPE_SHORT} @tab @code{SMALLINT} フィールド @item @code{FIELD_TYPE_LONG} @tab @code{INTEGER} フィールド @item @code{FIELD_TYPE_INT24} @tab @code{MEDIUMINT} フィールド @item @code{FIELD_TYPE_LONGLONG} @tab @code{BIGINT} フィールド @item @code{FIELD_TYPE_DECIMAL} @tab @code{DECIMAL} または @code{NUMERIC} フィールド @item @code{FIELD_TYPE_FLOAT} @tab @code{FLOAT} フィールド @item @code{FIELD_TYPE_DOUBLE} @tab @code{DOUBLE} または @code{REAL} フィールド @item @code{FIELD_TYPE_TIMESTAMP} @tab @code{TIMESTAMP} フィールド @item @code{FIELD_TYPE_DATE} @tab @code{DATE} フィールド @item @code{FIELD_TYPE_TIME} @tab @code{TIME} フィールド @item @code{FIELD_TYPE_DATETIME} @tab @code{DATETIME} フィールド @item @code{FIELD_TYPE_YEAR} @tab @code{YEAR} フィールド @item @code{FIELD_TYPE_STRING} @tab 文字列 (@code{CHAR} または @code{VARCHAR}) フィールド @item @code{FIELD_TYPE_BLOB} @tab @code{BLOB} または @code{TEXT} フィールド (最大長を確定するには @code{max_length} を使用して下さい) @item @code{FIELD_TYPE_SET} @tab @code{SET} フィールド @item @code{FIELD_TYPE_ENUM} @tab @code{ENUM} フィールド @item @code{FIELD_TYPE_NULL} @tab @code{NULL}型 フィールド @item @code{FIELD_TYPE_CHAR} @tab 非推奨; @code{FIELD_TYPE_TINY} を代わりに使用してください @end multitable @code{IS_NUM()} マクロで、フィールドが数値タイプかどうかをテストできます。 フィールドが数値の場合、@code{type} メンバを @code{IS_NUM()} に渡すと TRUE と評価します: @example if (IS_NUM(field->type)) printf("Field is numeric\n"); @end example @item unsigned int length フィールドの幅。これはテーブル定義で指定されたものです。 @item unsigned int max_length 結果セットのフィールドの最大幅(実際の結果セットの中のレコードの最長フィールド値 の長さ)。@code{mysql_store_result()} または @code{mysql_list_fields()} を 使用する場合は、これはフィールドの最大幅になります。 @code{mysql_use_result()} を使用する場合は、この変数の値は 0 になります。 @item unsigned int flags フィールドの種々のビットフラグ。@code{flags} 値は 0 または次のビットの一つ 以上の組み合わせです: @multitable @columnfractions .3 .55 @item @strong{フラグの値} @tab @strong{フラグの意味} @item @code{NOT_NULL_FLAG} @tab フィールドは @code{NULL} にできない @item @code{PRI_KEY_FLAG} @tab フィールドはプライマリキーの一部である @item @code{UNIQUE_KEY_FLAG} @tab フィールドはユニークキーの一部である @item @code{MULTIPLE_KEY_FLAG} @tab フィールドは非ユニークキーの一部である @item @code{UNSIGNED_FLAG} @tab フィールドは @code{UNSIGNED} 属性を持っている @item @code{ZEROFILL_FLAG} @tab フィールドは @code{ZEROFILL} 属性を持っている @item @code{BINARY_FLAG} @tab フィールドは @code{BINARY} 属性を持っている @item @code{AUTO_INCREMENT_FLAG} @tab フィールドは @code{AUTO_INCREMENT} 属性を持っている @item @code{ENUM_FLAG} @tab フィールドは @code{ENUM} である (非推奨) @item @code{BLOB_FLAG} @tab フィールドは @code{BLOB} または @code{TEXT} である (非推奨) @item @code{TIMESTAMP_FLAG} @tab フィールドは @code{TIMESTAMP} である (非推奨) @end multitable @code{BLOB_FLAG}, @code{ENUM_FLAG}, @code{TIMESTAMP_FLAG} の使用は推奨さ れません。これらは型の属性ではなくフィールドの型を示すからです。代わり に @code{field->type} を @code{FIELD_TYPE_BLOB}, @code{FIELD_TYPE_ENUM}, @code{FIELD_TYPE_TIMESTAMP} に対してテストする方をお勧めします。 @noindent 次の例は @code{flags} 値の典型的な使用を示しています: @example if (field->flags & NOT_NULL_FLAG) printf("Field can't be null\n"); @end example @code{flags} 値の真偽状態を調べるために、次の便利なマクロを使用でき ます: @multitable @columnfractions .3 .5 @item @code{IS_NOT_NULL(flags)} @tab このフィールドが @code{NOT NULL} として定義されていれば真 @item @code{IS_PRI_KEY(flags)} @tab このフィールドがプライマリキーならば真 @item @code{IS_BLOB(flags)} @tab このフィールドが @code{BLOB} または @code{TEXT} ならば真 (非推奨; 代わりに @code{field->type} をテストして下さい) @end multitable @item unsigned int decimals 数値フィールドの小数部桁数。 @end table @node C API function overview, C API functions, C API datatypes, Clients @section C API 関数概要 C API には次に一覧された関数が存在します。これらの関数は次の節でかな り詳細に説明されています。 @xref{C API functions}。 @multitable @columnfractions .3 .7 @item @strong{mysql_affected_rows()} @tab 最後の @code{UPDATE}, @code{DELETE}, @code{INSERT} クエリによって影響さ れたレコード数を返します。 @item @strong{mysql_close()} @tab サーバ接続をクローズします。 @item @strong{mysql_connect()} @tab @strong{MySQL} サーバに接続します。この関数は推奨されません; 代わりに @code{mysql_real_connect()} を使用してください。 @item @strong{mysql_change_user()} @tab 接続中ののユーザとデータベースを変更します。 @item @strong{mysql_create_db()} @tab データベースを生成します。この関数は推奨されません; 代わりに SQL コマン ド @code{CREATE DATABASE} を使用してください。 @item @strong{mysql_data_seek()} @tab クエリ結果セット中の任意のレコードにシークします。 @item @strong{mysql_debug()} @tab 与えられた文字列で @code{DBUG_PUSH} を行ないます。 @item @strong{mysql_drop_db()} @tab データベースを破棄します。この関数は推奨されません; 代わりに SQL コマン ド @code{DROP DATABASE} を使用してください。 @item @strong{mysql_dump_debug_info()} @tab サーバに、デバッグ情報をログに書き出させます。 @item @strong{mysql_eof()} @tab 結果セットの最後のレコードが読まれたかどうかを判定します。この関数は推奨されませ ん; 代わりに @code{mysql_errno()} または @code{mysql_error()} を使用して下 さい。 @item @strong{mysql_errno()} @tab 最後の @strong{MySQL} 関数からのエラー番号を返します。 @item @strong{mysql_error()} @tab 最後の @strong{MySQL} 関数からのエラーメッセージを返します。 @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 SQL ステートメント内で使用するために文字列中の特殊文字をエスケープします。 @item @strong{mysql_fetch_field()} @tab テーブルの次のフィールドの型を返します。 @item @strong{mysql_fetch_field_direct()} @tab テーブルの、番号で指定されたフィールドの型を返します。 @item @strong{mysql_fetch_fields()} @tab 全てのフィールド構造体の配列を返します。 @item @strong{mysql_fetch_lengths()} @tab 現在のレコード中の全てのフィールドの長さを返します。 @item @strong{mysql_fetch_row()} @tab 結果セットから次のレコードを取り出します。 @item @strong{mysql_field_seek()} @tab 指定されたフィールド上にフィールドカーソルを置きます。 @item @strong{mysql_field_count()} @tab 最後のクエリの結果のフィールドの数を返します。 @item @strong{mysql_field_tell()} @tab 最後の @code{mysql_fetch_field()} で使用されたフィールドカーソルの位置を返 します。 @item @strong{mysql_free_result()} @tab 結果セットによって使用されたメモリを解放します。 @item @strong{mysql_get_client_info()} @tab クライアントバージョン情報を返します。 @item @strong{mysql_get_host_info()} @tab 接続を説明する文字列を返します。 @item @strong{mysql_get_proto_info()} @tab 接続に使用されるプロトコルバージョンを返します。 @item @strong{mysql_get_server_info()} @tab サーバのバージョン番号を返します。 @item @strong{mysql_info()} @tab 最後に実行されたクエリについての情報を返します。 @item @strong{mysql_init()} @tab @code{MYSQL} 構造体を獲得または初期化します。 @item @strong{mysql_insert_id()} @tab @code{AUTO_INCREMENT} フィールドに最後に生成された ID を返します。 @item @strong{mysql_kill()} @tab 指定されたスレッドを殺します。 @item @strong{mysql_list_dbs()} @tab 簡易正規表現に適合するデータベース名を返します。 @item @strong{mysql_list_fields()} @tab 簡易正規表現に適合するフィールド名を返します。 @item @strong{mysql_list_processes()} @tab 現在のサーバスレッドのリストを返します。 @item @strong{mysql_list_tables()} @tab 簡易正規表現に適合するテーブル名を返します。 @item @strong{mysql_num_fields()} @tab 結果セット中のフィールド数を返します。 @item @strong{mysql_num_rows()} @tab 結果セット中のレコード数を返します。 @item @strong{mysql_options()} @tab @code{mysql_connect()} のための接続オプションを設定します。 @item @strong{mysql_ping()} @tab サーバへの接続が動作しているかどうかをチェックします。 必要であれば再接続します。 @item @strong{mysql_query()} @tab NULL 終端文字列として記述された SQL クエリを実行します。 @item @strong{mysql_real_connect()} @tab @strong{MySQL} サーバに接続します。 @item @strong{mysql_real_query()} @tab 数えられた文字列として記述された SQL クエリを実行します。 @item @strong{mysql_reload()} @tab 権限テーブルを再読み込みするようにサーバに指示します。 @item @strong{mysql_row_seek()} @tab 結果セット内のあるレコードへシークします。@code{mysql_row_tell()} から返される値を 使用します。 @item @strong{mysql_row_tell()} @tab レコードカーソルの位置を返します。 @item @strong{mysql_select_db()} @tab データベースを選択します。 @item @strong{mysql_shutdown()} @tab データベースサーバをシャットダウンします。 @item @strong{mysql_start_slave()} @tab Starts slave replication thread @item @strong{mysql_stat()} @tab 文字列でサーバ状態を返します。 @item @strong{mysql_store_result()} @tab クライアントに完全な結果セットを取り出します。 @item @strong{mysql_stop_slave()} @tab Stops slave replication thread @item @strong{mysql_thread_id()} @tab 現在のスレッド ID を返します。 @item @strong{mysql_thread_save()} @tab Returns 1 if the clients are compiled as threadsafe. @item @strong{mysql_use_result()} @tab 各レコードの動的結果セットを初期化します。 @end multitable サーバへ接続するには、接続ハンドラを初期化するために @code{mysql_init()} を呼びだし、それから @code{mysql_real_connect()} をそのハンドラで呼びだし ます (ホスト名、ユーザ名、パスワードのような他の情報に加えて)。 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. その接続で の処理が終了した時は、接続を終了させるために @code{mysql_close()} を呼びだ します。 接続が有効な間は、クライアントは @code{mysql_query()} または @code{mysql_real_query()} を使用して SQL クエリをサーバに送信できます。こ の2つの違いは、@code{mysql_query()} は NULL終端文字列としてクエリが記述さ れることを期待するのに対し、@code{mysql_real_query()} は数えられた文字列を 期待することです。文字列がバイナリデータ(NULバイトを含みことがある)を含む 場合は、@code{mysql_real_query()} を使用する必要があります。 非@code{SELECT} クエリ(例えば、@code{INSERT}, @code{UPDATE}, @code{DELETE})では、どれくらいのレコードが影響(変更)されたかを @code{mysql_affected_rows()} を呼び出すことで見つけ出すことができます。 @code{SELECT} クエリでは、選択されたレコードを結果セットとして取り出します。 (注意: いくつかのステートメントは、レコードを返すという点で @code{SELECT}に似ています。それは @code{SHOW}, @code{DESCRIBE}, @code{EXPLAIN} です。これらは @code{SELECT} ステートメントと同じ方法で扱わ れるべきです。) クライアントが結果セットを処理するには2つの方法があります。一つ目は、 @code{mysql_store_result()} を呼び出すことで、結果セット全体を一度にすべて 取り出すことです。この関数はサーバからクエリによって返されるすべてのレコー ドを取得し、それをクライアントに格納します。二つ目は、 @code{mysql_use_result()} を呼び出すことで、レコードごとの結果セット取り出 しを初期化することです。この関数は取り出しを初期化しますが、実際にはサーバ から何のレコードも得ません。 どちらの場合でも、@code{mysql_fetch_row()} を呼び出してレコードにアクセス します。@code{mysql_store_result()} では、@code{mysql_fetch_row()} は既に サーバから取得してあるレコードにアクセスします。 @code{mysql_use_result()} では、@code{mysql_fetch_row()} は実際にサーバか らレコードを取り出します。各レコードのデータ値のサイズについての情報は @code{mysql_fetch_lengths()} を呼び出すことで得られます。 結果セットでの処理が終った後は、@code{mysql_free_result()} を呼び出し、そ れが使用していたメモリを解放して下さい。 この2つの取り出し機構は相補的なものです。クライアントプログラムは、必要に よってもっとも適切なアプローチを選択すべきです。慣例的に、クライアントは一 般に @code{mysql_store_result()} を使用する傾向にあります。 @code{mysql_store_result()} の利点は、すべてのレコードをクライアントに取っ て来るため、連続してレコードをアクセスできるだけでなく、結果セット中の現在 のレコード位置を変更するために、@code{mysql_data_seek()} や @code{mysql_row_seek()} を使用して、結果セットの中を後や前に移動することが できます。また、@code{mysql_num_rows()} を呼び出すことで、レコード数を見つ けることもできます。一方、@code{mysql_store_result()} の必要メモリは、大き な結果セットではとても高く、out-of-memory 状態に遭遇する可能性が高くなりま す。 @code{mysql_use_result()} の利点は、一度に一つのレコードだけを保持するため、 クライアントが結果セットに要求するメモリが少ないことです(そして、割当のオー バーヘッドも少ないので、@code{mysql_use_result()} はより速くなります)。不 利な点は、サーバの拘束を避けるため、各レコードを素早く処理する必要があるこ と、結果セット中でレコードのランダムアクセスができないこと(レコードを順番 にアクセスすることしかできません)、そして、すべてのレコードを取り出さない 限り、結果セット中にいくつのレコードがあるかを知ることができないことです。 さらに、あなたが探している情報を、検索の途中で見つけることができて、問題が 解決したとしても、すべてのレコードを取り出さ@emph{なければなりません}。 API はクライアントがクエリが @code{SELECT} であるかどうかを知ることなしに、 (必要時だけレコードを取り出す)クエリに適切に応答できるようにします。 それぞれの @code{mysql_query()}(または @code{mysql_real_query()})の後で、 @code{mysql_store_result()} を呼び出すことで、これが可能です。結果セットの 呼び出しが成功すると、クエリは @code{SELECT} であり、レコードを読むことが できます。結果セット呼び出しが失敗した場合は、結果が実際に期待されたもので あるかどうかを確定するために、@code{mysql_field_count()} を呼び出してくだ さい。@code{mysql_field_count()} が 0 を返す場合は、クエリはデータを返しま せん(クエリが @code{INSERT}, @code{UPDATE}, @code{DELETE} 等であることを 示します)。つまりレコードが返ることを期待できません。 @code{mysql_field_count()} が 0 でない場合は、クエリはレコードを返すべきな のに、返さなかったということです。これはクエリが @code{SELECT} で失敗した ということを示します。これをどのように行なうことができるかの例は、 @code{mysql_field_count()} の説明を参照してください。 @code{mysql_store_result()} と @code{mysql_use_result()} はどちらも、結果 セットを作るフィールドについての情報(フィールドの数、その名前や型など)を 獲得することができます。@code{mysql_fetch_field()} を繰り返し呼び出すこと で順番に、または、@code{mysql_fetch_field_direct()} を呼び出すことでレコー ド内のフィールド番号で、レコード内のフィールド情報にアクセスすることができ ます。現在のフィールドカーソル位置は @code{mysql_field_seek()} を呼び出す ことで変更できます。フィールドカーソルの設定は、その後の @code{mysql_fetch_field()} 呼び出しに影響します。 @code{mysql_fetch_fields()} を呼び出すことで、一度にすべてのフィールドの情 報を得ることもできます。 エラーの検出、報告については、@code{mysql_errno()} と @code{mysql_error()} 関数の方法によって、@strong{MySQL} はエラー情報へのア クセスを提供します。これらは、最後に呼び出された成功または失敗し得る関数に ついてのエラーコードとエラーメッセージを返し、エラーがいつ何で発生したかを 確定することができます。 @node C API functions, Perl, C API function overview, Clients @section C API 関数説明 @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_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 以下の説明では、@code{NULL} の引数または戻り値は C プログラミング言語で の @code{NULL} を意味します。@strong{MySQL} @code{NULL} 値ではありません。 関数は通常ポインタか整数の値を返します。しかし関数説明に記述がある場合、 ポインタを返す関数は、成功を示すために非 @code{NULL} 値を返し、エラーを示すた めに @code{NULL} を返します。整数を返す関数は、成功を示すために 0 を返し、 エラーを示すために非0を返します。``非0'' は関数説明が他に述べていない限 り、その意味になることに注意してください; 関数説明が他に述べている場合、 これらに対して 0 以外の固有の値をテストしないでください: @example if (result) /* 正しい */ ... error ... if (result < 0) /* 間違い */ ... error ... if (result == -1) /* 間違い */ ... error ... @end example 関数がエラーを返すとき、関数説明の @strong{エラー} 節が起り得るエラーの 種類を一覧しています。@code{mysql_errno()} の呼び出しによってどれが発生 したかを見つけ出すことができます。エラーを表現する文字列は @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 説明 最後の @code{UPDATE}, @code{DELETE}, @code{INSERT} クエリによって影響さ れた(変更された)行数を返します。@code{UPDATE}, @code{DELETE}, @code{INSERT} ステート メントでの @code{mysql_query()} 直後に呼び出します。@code{SELECT} ステート メントでは、これは @code{mysql_num_rows()} に似た動きをします。 @code{mysql_affected_rows()} は現在マクロとして実装されています。 @subsubheading 戻り値 0 より大きい整数は影響された行数または取り出された行数を示します。クエリ の @code{WHERE} 節に適合したレコードがない場合またはクエリがまだ実行され ていない場合は 0 です。クエリがエラーを返したか、@code{SELECT} クエリに ついて @code{mysql_store_result()} が呼ばれる前に @code{mysql_affected_rows()} が呼ばれた場合は -1 です。 @subsubheading エラー 無し。 @subsubheading 例 @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 説明 前にオープンされた接続をクローズします。ハンドルが @code{mysql_init()} ま たは @code{mysql_connect()} で自動的に割り当てられた場合、 @code{mysql_close()} は @code{mysql} で示される接続ハンドルの解放も行ない ます。 @subsubheading 戻り値 無し。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 この関数は推奨されません。代わりに @code{mysql_real_connect()} の使用を お勧めします。 @code{mysql_connect()} は @code{host} 上で動作している @strong{MySQL} デー タベースエンジンへの接続の確立を試みます。@code{mysql_get_client_info()} を除く他のすべての API 関数を実行する前に@code{mysql_connect()} が成功終了 している必要があります。 パラメータの意味は @code{mysql_real_connect()} の対応するパラメータと同じですが、 接続パラメータは @code{NULL} にできることが異なります。この場合 C API は接 続構造体に自動的にメモリを割り当て、@code{mysql_close()} 呼び出し時にそれ を解放します。このアプローチの不利な点は接続が失敗した場合にエラーメッセー ジを取り出すことができないことです。(@code{mysql_errno()} または @code{mysql_error()} からエラー情報を得るには、正しい @code{MYSQL} ポイン タを提供する必要があります。) @subsubheading 戻り値 @code{mysql_real_connect()} と同じ @subsubheading エラー @code{mysql_real_connect()} と同じ @findex @code{mysql_change_user()} @node mysql_change_user, mysql_create_db, 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 説明 ユーザを変更し、@code{mysql} で示された接続上で、@code{db} で示されたデー タベースがデフォルト(現在の)データベースになります。その後のクエリでは、 明示的なデータベースの指定を含んでいないテーブル参照について、このデータベー スがデフォルトになります。 この関数は @strong{MySQL} 3.23.3 で導入されました。 @code{mysql_change_user()} は接続されたユーザが認証されない場合、またはデー タベースを使用する権限を持っていない場合に失敗します。この場合、ユーザとデー タベースは変更されません。 デフォルトデータベースを持ちたくない場合、@code{db} パラメータを @code{NULL} に設定できます。 @subsubheading 戻り値 成功時 0。エラーが発生した場合は非0。 @subsubheading エラー @code{mysql_real_connect()} から得られるものと同じです。 @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @item ER_UNKNOWN_COM_ERROR @strong{MySQL} サーバはこのコマンドを実装していない(おそらく古いサーバ)。 @item ER_ACCESS_DENIED_ERROR ユーザまたはパスワードが間違っている。 @item ER_BAD_DB_ERROR データベースが存在しない。 @item ER_DBACCESS_DENIED_ERROR ユーザがデータベースへのアクセス権を持っていない。 @item ER_WRONG_DB_NAME データベース名が長過ぎる。 @end table @subsubheading 例 @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_create_db()} @node mysql_create_db, mysql_data_seek, mysql_change_user, C API functions @subsection @code{mysql_create_db()} @code{int mysql_create_db(MYSQL *mysql, const char *db)} @subsubheading 説明 @code{db} 引数によって指定されたデータベースを作成します。 この関数は推奨されません。代わりに @code{mysql_query()} を使って、SQL @code{CREATE DATABASE} ステートメントを発行することをお勧めします。 @subsubheading 戻り値 データベースの作成が成功した場合は0。エラーが発生した場合は非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @end table @subsubheading 例 @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 説明 クエリ結果セット中の任意のレコードにシークします。これは、結果セット構造体 がクエリのすべての結果を持っていることを要求します。そのため、 @code{mysql_data_seek()} は @code{mysql_store_result()} と共にだけ使用され、 @code{mysql_use_result()} と共には使用できません。 オフセットの値は @code{0} から @code{mysql_num_rows(result)-1} でなくては なりません。 @subsubheading 戻り値 無し。 @subsubheading エラー 無し。 @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 説明 与えられた文字列で @code{DBUG_PUSH} を行ないます。@code{mysql_debug()} は Fred Fish が作成した debug library を使用します。この関数を使用するためには、デバッ グをサポートするように、クライアントライブラリをコンパイルする必要があり ます。 @xref{Debugging server}. @xref{Debugging client}. @subsubheading 戻り値 無し。 @subsubheading エラー 無し。 @subsubheading 例 次に示した呼び出しは、クライアントライブラリが、クライアントマシン上の @file{/tmp/client.trace} にトレースファイルを生成します: @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 説明 @code{db} 引数によって指定されたデータベースを破棄します。 この関数は推奨されません。代わりに @code{mysql_query()} を使って、SQL @code{DROP DATABASE} ステートメントを発行することをお勧めします。 @subsubheading 戻り値 データベースの破棄が成功した場合は0。エラーが発生した場合は非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @end table @subsubheading 例 @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 説明 いくつかのデバッグ情報をログにダンプするようにサーバに指示します。この動 作をするためには、接続されたユーザが @strong{process} 権を持っていなけ ればなりません。 @subsubheading 戻り値 コマンドが成功した場合は0。コマンドが失敗した場合は非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 この関数は推奨されません。@code{mysql_errno()} か @code{mysql_error()} が 代わりに使用できます。 @code{mysql_eof()} は結果セットの最後のレコードが読まれたかどうかを調べま す。 @code{mysql_store_result()} の呼び出しが成功して、結果セットを入手した場合、 クライアントは一つのオペレーションですべてのセットを受け取ります。この場合、 @code{mysql_fetch_row()} から返される @code{NULL} は、常に結果セットの終端 に達したことを意味し、@code{mysql_eof()} を呼ぶ必要はありません。 一方、結果セット取り出しの初期化のために @code{mysql_use_result()} を使用 する場合、セットのレコードは @code{mysql_fetch_row()} を繰り返し呼ぶことに より、ひとつずつサーバから獲得されます。この処理中に接続上でエラーが発生し 得るため、@code{mysql_fetch_row()} からの戻り値 @code{NULL} は、通常必ずし も結果セットの終端に達したことを意味しません。この場合 @code{mysql_eof()} を使用して、何が起こったかを検出できます。結果セットの 終端に達した場合は @code{mysql_eof()} は非0値を返し、エラーが発生した場合 は 0 を返します。 歴史的に @code{mysql_eof()} は標準 @strong{MySQL} エラー関数 @code{mysql_errno()} と @code{mysql_error()} 以前に遡ります。これらのエラー 関数は同じ情報を提供するので、これらの使用が @code{mysql_eof()} よりも好ま れます。@code{mysql_eof()} は現在推奨されません。(実際、これらは多くの情 報を提供します。エラー関数はエラーが発生した時のエラーの理由を示しますが、 @code{mysql_eof()} は真偽値だけを返します。) @subsubheading 戻り値 エラーが発生しなかった場合は0。結果セットの終端に達した場合は非0。 @subsubheading エラー 無し。 @subsubheading 例 次の例は @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 しかし、標準 @strong{MySQL} エラー関数で同じ効果を得ることができます: @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 説明 @code{mysql} によって指定された接続上で、最後に呼び出された API 関数の成否のエラーコー ドを返します。戻り値0はエラーが発生しなかったことを意味します。クライア ントエラーメッセージ番号は @file{errmsg.h} にリストされています。サーバ エラーメッセージ番号は @file{mysqld_error.h} にリストされています。 @subsubheading 戻り値: エラーコード値。エラーが発生していない場合は0。 @subsubheading エラー 無し。 @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 説明 @code{mysql} によって指定された接続上で、 @code{mysql_error()} は 最後に呼び出された API 関数の成否を、エラーメッセージとして返します。 エラー発生しなかった場合は空文字列 (@code{""}) が返されます。 これは次の2つのテストが同じであることを意味します: @example if(mysql_errno(&mysql)) @{ // an error occurred @} if(mysql_error(&mysql)[0] != '\0') @{ // an error occurred @} @end example クライアントエラーメッセージの言語は @strong{MySQL} クラ イアントライブラリの再コンパイルで変更できます。現在はいくつかの言語で書かれた クライアントエラーメッセージを選択できます。 @xref{Languages}. @subsubheading 戻り値 エラーを表わす文字列。 エラーが発生していない場合は空文字列。 @subsubheading エラー 無し。 @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 説明 結果セットの一つのフィールドの定義を @code{MYSQL_FIELD} 構造体として返しま す。結果セット内の全てのフィールドについて情報を取り出すには、この関数を繰 り返し呼んでください。@code{mysql_fetch_field()} はフィールドが残っていな いと @code{NULL} を返します。 @code{mysql_fetch_field()} は、新しい @code{SELECT} クエリを実行するたびに、 最初のフィールドについての情報を返すようにリセットされます。 @code{mysql_fetch_field()} で返されるフィールドは @code{mysql_field_seek()} の呼び出しにも影響をうけます。 テーブルを @code{SELECT} するために @code{mysql_query()} を呼び、しかしま だ @code{mysql_store_result()} を呼んでいない場合、 @code{mysql_fetch_field()} を @code{BLOB} フィールドの長さの問い合わせに使 用すると、@strong{MySQL} はデフォルトの blob 長 (8K bytes) を返します。 (8K サイズになるのは、@strong{MySQL} は @code{BLOB} の最大長を知らないから です。これはいつかコンフィグ可能になるべきです。) 一度結果セットを取り出せ ば、@code{field->max_length} は指定したクエリ内でのこのフィールドの最大値 の長さを含みます。 @subsubheading 戻り値 現在のフィールドの @code{MYSQL_FIELD} 構造体。フィールドが残っていない場合は @code{NULL}。 @subsubheading エラー 無し。 @subsubheading 例 @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 説明 結果セットのすべての @code{MYSQL_FIELD} 構造体の配列を返します。各構造体は 結果セットの一つのフィールドのフィールド定義を提供します。 @subsubheading 戻り値 結果セットの全ての項目の @code{MYSQL_FIELD} 構造体の配列。 @subsubheading エラー 無し。 @subsubheading 例 @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 説明 結果セット中のフィールドを示すフィールド番号 @code{fieldnr} が与えられ、そ のフィールドのフィールド定義を @code{MYSQL_FIELD} 構造体として返します。こ の関数は任意のフィールドについての定義を取り出すことに使用できます。 @code{fieldnr} の値は 0 から @code{mysql_num_fields(result)-1} の範囲にす べきです。 @subsubheading 戻り値 指定されたフィールドの @code{MYSQL_FIELD} 構造体。 @subsubheading エラー 無し。 @subsubheading 例 @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 説明 結果セット中の現在のレコードのフィールドの長さを返します。フィールドの値をコピーする場合、 この長さ情報は最適化にも有用です。@code{strlen()} の呼び出しを回避できる ためです。 さらに、結果セットがバイナリデータを持つ場合は、データのサイズを特定するためにこの関数を@emph{使わなければなりません}。 なぜなら @code{strlen()} は NULL 文字を含むフィールドについての結果を正しく返さないからです。 空フィールドの長さと @code{NULL} 値を含むフィールドの長さは 0 です。この2 つのケースを区別する方法については、@code{mysql_fetch_row()} の説明を参照 して下さい。 @subsubheading 戻り値 各フィールドのサイズ (終端 NUL 文字は含みません)を提供する unsigned long 整数の配列。 エラーが発生した場合は @code{NULL}。 @subsubheading エラー @code{mysql_fetch_lengths()} は結果セットの現在のレコードについてだけ有効 です。@code{mysql_fetch_row()} を呼び出す前、または結果の全てのレコードを 取り出した後にこれを呼んだ場合、@code{NULL} が返されます。 @subsubheading 例 @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 説明 結果セットの次のレコードを取り出します。@code{mysql_store_result()} の後に使用すると、 これ以上取り出すレコードがない時は、@code{NULL} を返します。 @code{mysql_use_result()} の後に使用するなら、 これ以上取り出すレコードがない場合やエラーが発生した場合に @code{NULL} を返します。 レコード内の値の数は @code{mysql_num_fields(result)} によって与えられます。 @code{row} が @code{mysql_fetch_row()} の呼び出しからの戻り値を保持する場 合、値へのポインタは @code{row[0]} から @code{row[mysql_num_fields(result)-1} としてアクセスされます。レコード内の @code{NULL} 値は@code{NULL} ポインタによって示されます。 レコードのフィールド値の長さは、@code{mysql_fetch_lengths()} の呼び出しで 獲得できます。空フィールドと @code{NULL} を含むフィールドはどちらも長さ 0 を持ちます; フィールド値のポインタをチェックすることで、これらを区別でき ます。ポインタが @code{NULL} の場合、フィールドは @code{NULL} です; そうで なければフィールドは空です。 @subsubheading 戻り値 次のレコードの @code{MYSQL_ROW} 構造体、エラーが発生したか、もう取り出すレ コードがない場合は @code{NULL}。 @subsubheading エラー @table @code @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @end table @subsubheading 例 @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)} 3.22.24 より前の @code{MySQL} バージョンを使用している場合、 @code{unsigned int mysql_num_fields(MYSQL *mysql)} を代わりに使用すべきで す。 @subsubheading 説明 接続上の最後のクエリのフィールド数を返します。 この関数は通常 @code{mysql_store_result()} が @code{NULL} を返した時(そし てこのように結果セットポインタを持っていない時)に使用されます。この場合、 @code{mysql_store_result()} が空でない結果を提供すべきかどうかを調べるため に、@code{mysql_field_count()} を呼び出すことができます。これは、クエリが @code{SELECT}(または @code{SELECT}に似た)ステートメントであるかを知るこ と無しに、クライアントプログラムに、適切な行動をとらせることができます。下 に示される例は、これをどのように行なうことができるかを説明しています。 @xref{NULL mysql_store_result, , @code{NULL mysql_store_result()}}. @subsubheading 戻り値 結果セット中のフィールド番号を表す unsigned integer。 @subsubheading エラー 無し。 @subsubheading 例 @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 別の方法は、@code{mysql_field_count(&mysql)} 呼び出しを @code{mysql_errno(&mysql)} に置き換えることです。この場合、ステートメント が @code{SELECT} かどうかを @code{mysql_field_count()} の値から推測するの ではなく、直接 @code{mysql_store_result()} からのエラーをチェックします。 @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 説明 与えられたオフセットにフィールドカーソルを設定します。次の @code{mysql_fetch_field()} の呼び出しはそのオフセットに対応したフィールドを取 り出します。 レコードの最初にシークするには、0 の @code{offset} 値を渡してください。 @subsubheading 戻り値 フィールドカーソルの前の値。 @subsubheading エラー 無し。 @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 説明 最後の @code{mysql_fetch_field()} に使用したフィールドカーソルの位置を返 します。この値は @code{mysql_field_seek()} への引数として使用できます。 @subsubheading 戻り値 フィールドカーソルの現在のオフセット。 @subsubheading エラー 無し。 @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 説明 @code{mysql_store_result()}, @code{mysql_use_result()}, @code{mysql_list_dbs()} 等によって結果セットに割り当てられたメモリを解放 します。結果セットで何かを行なった時、@code{mysql_free_result()} を呼び 出してそれが使用したメモリを解放する必要があります。 @subsubheading 戻り値 無し。 @subsubheading エラー 無し。 @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 説明 クライアントライブラリバージョンを表わす文字列を返します。 @subsubheading 戻り値 @strong{MySQL} クライアントライブラリバージョンを表わす文字列。 @subsubheading エラー 無し。 @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 説明 使用中の接続タイプを表わす文字列を返します。サーバのホスト名を含みます。 @subsubheading 戻り値 サーバホスト名と接続タイプを表わす文字列。 @subsubheading エラー 無し。 @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 説明 現在の接続に使用されているプロトコルバージョンを返します。 @subsubheading Return values 現在の接続に使用されているプロトコルバージョンを表わす符号無し整数値。 @subsubheading エラー 無し。 @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 説明 サーバのバージョン番号を表わす文字列を返します。 @subsubheading 戻り値 サーバのバージョン番号を表わす文字列。 @subsubheading エラー 無し。 @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 説明 最も最近に実行されたクエリについての情報を文字列で返します。が、 以下に挙げる構文に限ります。 他の構文では@code{mysql_info()} は @code{NULL} を返します。 文字列の形式 はクエリの型によって様々です。次に説明します (数値は例です; 文字列はクエ リに適した値を含みます): @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 注意: 複数の値リストがステートメント中に記述された場合にだけ、 @code{mysql_info()} は、@code{INSERT ... VALUES} ステートメントに非 @code{NULL}値を返します。 @subsubheading 戻り値 最も最近に実行されたクエリについての追加情報を表わす文字列。クエリに有効 な情報がない場合は @code{NULL} ポインタ。 @subsubheading エラー 無し。 @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 説明 @code{mysql_real_connect()} に適した @code{MYSQL} オブジェクトの割り当て または初期化を行ないます。引数が @code{NULL} ポインタの場合、関数は新し いオブジェクトを割り当てて初期化し返します。そうでなければオブジェクトは 初期化され、オブジェクトのアドレスが返されます。新しいオブジェクトが割り 当てられた場合、@code{mysql_close()} はこのオブジェクトを解放します。 @subsubheading 戻り値 初期化された @code{MYSQL*} ハンドル、または新しいオブジェクトを割り当て るのに十分なメモリがなかった場合は @code{NULL} ポインタ。 @subsubheading エラー メモリ不足の場合は @code{NULL} が返されます。 @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 説明 前のクエリによって @code{AUTO_INCREMENT} フィールドに生成された ID を返します。 @code{AUTO_INCREMENT} フィールドを含むテーブルに @code{INSERT} クエリを 実行した後で、この関数を使用してください。 注意: 前のクエリが @code{AUTO_INCREMENT} 値を生成しなかった場合、 @code{mysql_insert_id()} は @code{0} を返します。後のために値を保存する必 要がある場合、値を生成するクエリの直後に @code{mysql_insert_id()} を呼び出 すことに気をつけてください。 また、SQL @code{LAST_INSERT_ID()} 常に最後に生成された @code{AUTO_INCREMENT} 値を含み、クエリ間でリセットされないことに注意して下 さい。その関数の値はサーバ内で保守されるからです。 @subsubheading 戻り値 前のクエリによって更新された @code{AUTO_INCREMENT} フィールドの値。接続上 の前のクエリがない場合、クエリが @code{AUTO_INCREMENT} 値を更新しなかった 場合には 0 が返ります。 @subsubheading エラー 無し。 @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 説明 @code{pid} で指定されたスレッドを殺すようにサーバに頼みます。 @subsubheading 戻り値 成功時0。失敗時非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 サーバ上の、@code{wild} 引数で指定された簡易正規表現に適合する、データベー ス名からなる結果セットを返します。@code{wild} はワイルドカード文字 @samp{%} または @samp{_} を含むことができます。また、全てのデータベース に適合するように @code{NULL} ポインタにできます。@code{mysql_list_dbs()} の呼び出しはクエリ @code{SHOW databases [LIKE wild]} を実行するのと同様 です。 @code{mysql_free_result()} で結果セットを解放する必要があります。 @subsubheading 戻り値 成功時 @code{MYSQL_RES} 結果セット。失敗した場合は @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_OUT_OF_MEMORY メモリ不足。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 与えられたテーブル内の、@code{wild} 引数で指定された簡易正規表現に適合する フィールド名からなる結果セットを返します。@code{wild} はワイルドカー ド文字 @samp{%} または @samp{_} を含むことができます。また、全てのフィー ルドに適合するように @code{NULL} ポインタにできます。 @code{mysql_list_fields()} はクエリ @code{SHOW COLUMNS FROM table [LIKE wild]} を実行するのと同様です。 注意: @code{mysql_list_fields()} の代わりに @code{SHOW COLUMNS FROM tbl_name} の使用を勧めます。 @code{mysql_free_result()} で結果セットを解放する必要があります。 @subsubheading 戻り値 成功時 @code{MYSQL_RES} 結果セット。エラーが発生した場合は @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 現在のサーバスレッドを示す結果セットを返します。これは @code{mysqladmin processlist} や @code{SHOW PROCESSLIST} クエリで 報告されるものと同じ種類の情報です。 @code{mysql_free_result()} で結果セットを解放する必要があります。 @subsubheading 戻り値 成功時 @code{MYSQL_RES} 結果セット。失敗した場合は @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 @code{wild} 引数で指定された簡易正規表現に適合する、現在のデータベース 内のテーブル名からなる結果セットを返します。@code{wild} はワイルドカード 文字 @samp{%} または @samp{_} を含むことができます。また、全てのテーブル に適合するように @code{NULL} ポインタにできます。 @code{mysql_list_tables()} はクエリ @code{SHOW tables [LIKE wild]} を実 行するのと同様です。 @code{mysql_free_result()} で結果セットを解放する必要があります。 @subsubheading 戻り値 成功時 @code{MYSQL_RES} 結果セット。失敗した場合は @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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)} または @code{unsigned int mysql_num_fields(MYSQL *mysql)} 二番目の形式は @strong{MySQL} 3.23 以上では動作しません。@code{MYSQL*} 引 数を通す場合は、代わりに @code{unsigned int mysql_field_count(MYSQL*mysql)} を使用しなくてはいけません。 @subsubheading 説明 結果セット中のフィールド数を返します。 注意: 結果セットへのポインタまたは接続ハンドルのいずれかからフィールドの数 を得ることができます。@code{mysql_store_result()} または @code{mysql_use_result()} が @code{NULL} を返した(つまり結果セットポイン タが無い)場合、接続ハンドルを使用します。この場合、 @code{mysql_field_count()} を呼び出して、@code{mysql_store_result()} が空 でない結果を提供すべきかどうかを決定できます。これにより、クライアントプロ グラムはクエリが @code{SELECT}(または @code{SELECT} に似た)ステートメン トだったかどうかを知ることなしに、適切な行動を取ることができます。以下に示 す例はこれをどのように行なうかを説明しています。 @xref{NULL mysql_store_result, , @code{NULL mysql_store_result()}}. @subsubheading 戻り値 結果セット中のフィールド数を表わす符号無し整数。 @subsubheading エラー 無し。 @subsubheading 例 @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 (結果セットが返るべきクエリであることを知っている場合の)方法は、 @code{mysql_errno(&mysql)} コールを @code{mysql_field_count(&mysql)} が 0 かどうかのチェックに置き換えることです。これは何かが悪い場合にだけ起こり ます。 @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 説明 結果セット中のレコード数を返します。 @code{mysql_num_rows()} の使用は、結果セットを返すのに @code{mysql_store_result()} か @code{mysql_use_result()} のどちらを使用す るかに依存します。@code{mysql_store_result()} を使用する場合、 @code{mysql_num_rows()} はすぐに呼ぶことができます。 @code{mysql_use_result()} を使用する場合、結果セットの全てのレコードが取り 出されるまで、@code{mysql_num_rows()} は正しい値を返しません。 @subsubheading 戻り値 結果セットのレコード数。 @subsubheading エラー 無し。 @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 説明 特別な接続オプションを設定し、接続の振舞いに影響を与えるために使用できます。 この関数は複数のオプションを設定するために複数回呼ぶことができます。 @code{mysql_options()} は @code{mysql_init()} の後で、 @code{mysql_connect()} や @code{mysql_real_connect()} の前に呼ばれなければ なりません。 @code{option} 引数は設定したいオプションです; @code{arg} 引数はオプション に対する値です。オプションが整数の場合、@code{arg} は整数値へのポインタで す。 有効なオプション値: @multitable @columnfractions .25 .25 .5 @item @strong{オプション} @tab @strong{引数型} @tab @strong{機能} @item @code{MYSQL_OPT_CONNECT_TIMEOUT} @tab @code{unsigned int *} @tab 接続タイムアウト(秒)。 @item @code{MYSQL_OPT_COMPRESS} @tab 使用しない @tab 圧縮クライアント/サーバプロトコルを使用する。 @item @code{MYSQL_OPT_NAMED_PIPE} @tab 使用しない @tab NT 上の @strong{MySQL} サーバへの接続に名前付パイプを使用する。 @item @code{MYSQL_INIT_COMMAND} @tab @code{char *} @tab @strong{MySQL} サーバへの接続時に実行するコマンド。再接続時に自動的に再実行される。 @item @code{MYSQL_READ_DEFAULT_FILE} @tab @code{char *} @tab @file{my.cnf} の代わりに指定されたオプションファイルからオプションを読み込む。 @item @code{MYSQL_READ_DEFAULT_GROUP} @tab @code{char *} @tab @file{my.cnf} または @code{MYSQL_READ_DEFAULT_FILE} で指定されたファイルから指定されたグループのオプションを読み込む。 @end multitable 注意: @code{MYSQL_READ_DEFAULT_FILE} と @code{MYSQL_READ_DEFAULT_GROUP} を 使用する場合、@code{client} グループが常に読まれます。 オプションファイル中に指定されるグループは次のオプションを含むことができま す: @multitable @columnfractions .3 .7 @item @code{compress} @tab 圧縮クライアント/サーバプロトコルを使用する。 @item @code{database} @tab 接続命令中でデータベースが指定されない場合、このデータベースに接続する。 @item @code{debug} @tab デバッグオプション @item @code{host} @tab デフォルトホスト名 @item @code{init-command} @tab @strong{MySQL} サーバへの接続時に実行するコマンド。再接続時に自動的に再実行される。 @item @code{password} @tab デフォルトパスワード @item @code{pipe} @tab NT 上の @strong{MySQL} サーバへの接続に名前付パイプを使用する。 @item @code{port} @tab デフォルトポート番号 @item @code{return-found-rows} @tab @code{UPDATE} 使用時、@code{mysql_info()} が更新された行の代わりに見つかった行を返すようにする。 @item @code{socket} @tab デフォルトソケット番号 @item @code{timeout} @tab 接続タイムアウト(秒)。 @item @code{user} @tab デフォルトユーザ @end multitable オプションファイルについてのさらなる情報は、@ref{Option files} を参照して 下さい。 @subsubheading 戻り値 成功の場合は0。未知のオプションを使用した場合は非0。 @subsubheading 例 @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 上記は、圧縮クライアント/サーバプロトコルを使用し、@code{my.cnf} ファイル 中の @code{odbc} セクションから追加オプションを読むように、クライアントに 要求します。 @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 説明 サーバへの接続が動作しているかどうかをチェックします。ダウンしている場合 は、自動的に再接続を試みます。 この関数は、長い間静かにしているクライアントが、サーバが接続をクローズし たかどうかをチェック(と再接続)するために使用できます。 @subsubheading 戻り値 サーバが生きている場合0。他の値はエラーを示します。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 NULL 終端文字列 @code{query} で示される SQL クエリを実行します。クエリはひ とつの SQL ステートメントでなければなりません。終端のセミコロン (@samp{;})や @code{\g} をステートメントに追加すべきではありません。 @code{mysql_query()} はバイナリデータを含むクエリには使用できません(バ イナリデータは @samp{\0} 文字を含むことがあります。これはクエリ文字列の 最後として解釈されます)。この場合、@code{mysql_real_query()} を代わりに 使用してください。 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 戻り値 クエリが成功した場合は0。クエリが失敗した場合は非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 @code{host} 上で動作している @strong{MySQL} データベースエンジンへの接続 の確立を試みます。 @code{mysql_get_client_info()} 以外の他の API 関数を実行する前に、 @code{mysql_real_connect()} が成功している必要があります。 @code{mysql_real_connect()} を呼び出す前に、@code{MYSQL} 構造体を獲得ま たは初期化するために @code{mysql_init()} を呼ぶ必要があることに注意して ください。 @itemize @bullet @item 最初のパラメータは既存の @code{MYSQL} 構造体のアドレスです。 @code{mysql_real_connect()} を呼ぶ前に、@code{MYSQL} 構造体の初期化のため に @code{mysql_init()} を呼ぶ必要があります。後述の例を参照してください。 @item @code{host} の値はホスト名か IP アドレスのどちらでも可能です。 @code{host} が @code{NULL} または文字列 @code{"localhost"} の場合はロー カルホストへの接続とみなされます。OS がソケットをサポートする場合(Unix) または名前つきパイプをサポートする場合(Win32)、サーバへの TCP/IP 接続の 代わりに使用されます。 @item @code{user} パラメータはユーザの @strong{MySQL} ログイン ID が入っています。 @code{user} が @code{NULL} の場合、現在のユーザとみなされます。Windows ODBC 下では、現在のユーザは明示的に指定されなければなりません。Unix 下で は現在のログイン名が適用されます。 Windows ODBC では, カレントのユーザー名を与えなければなりません。 @xref{ODBC administrator}. @item @code{passwd} パラメータは @code{user} のパスワードが入っています。 もし @code{passwd} が @code{NULL} の場合、空白のパスワードフィールドを持つ @code{user} テーブル内のレコードだけが適合チェックされます。このような方 法で、パスワードが記述されたかどうかによってユーザが異なる権限を得るよう に、データベース管理者が @strong{MySQL} 特権システムを設定することができ ます。 注意: @code{mysql_connect()} を呼び出す前に @code{passwd} を暗号化しない でください。パスワードの暗号化はクライアント API で自動的に処理されます。 @item @code{db} が @code{NULL} でない場合、接続はこの値をデフォルトデータベー スにセットします。 @item @code{port} が 0 でない場合、値は TCP/IP 接続のポート番号として使用され ます。@code{host} パラメータが接続のタイプを決定することに注意してくださ い。 @item @code{unix_socket} が @code{NULL} でない場合、文字列は使用されるソケット または名前つきパイプを記述します。@code{host} パラメータが接続のタイプを 決定することに注意してください。 @item client_flag の値は通常 0 ですが、とても特殊な状況のため次のフラグの組み 合わせを設定できます: @multitable @columnfractions .25 .7 @item @strong{フラグ名} @tab @strong{フラグの意味} @item @code{CLIENT_FOUND_ROWS} @tab 影響された行数ではなく見つかった行数を返します @item @code{CLIENT_NO_SCHEMA} @tab @code{db_name.tbl_name.col_name} を許しません。これは ODBC のためです; その構文を使用した場合、パーサがエラーを生成します。これはいくつかの ODBC プログラムのバグのトラップに役立ちます。 @item @code{CLIENT_COMPRESS} @tab 圧縮プロトコルを使用します @item @code{CLIENT_ODBC} @tab クライアントが ODBC クライアント。これは @code{mysqld} をさらに ODBC-フレンドリに変更します。 @end multitable @end itemize @code{mysql_real_connect()} の最初の引数に @code{NULL} ポインタを記述す ることもできます。これは C API が接続構造体のメモリを割り当て、 @code{mysql_close()} 呼び出し時に自動的に解放されます。この方法の不利な 点は、接続が失敗した場合に @code{mysql_real_connect()} からのエラーメッ セージを取り出すことができないことです。 最初の引数が @code{NULL} ポインタでない場合は、存在する @code{MYSQL} 構 造体のアドレスであるべきです。 @subsubheading 戻り値 接続が成功した場合は @code{MYSQL*} 接続ハンドルです。接続が失敗した場合 は C @code{NULL} ポインタです。 接続に成功すると、最初のパラメータが @code{NULL} でない場合、戻り値はそのパラ メータの値と同じです。 @subsubheading エラー @table @code @item CR_CONN_HOST_ERROR @strong{MySQL} サーバへの接続に失敗した。 @item CR_CONNECTION_ERROR ローカル @strong{MySQL} サーバへの接続に失敗した。 @item CR_IPSOCK_ERROR IP ソケットの生成に失敗した。 @item CR_OUT_OF_MEMORY メモリ不足。 @item CR_SOCKET_CREATE_ERROR Unix ソケットの生成に失敗した。 @item CR_UNKNOWN_HOST ホスト名の IP アドレスを見つけるのに失敗した。 @item CR_VERSION_ERROR 異なるプロトコルバージョンを使用するクライアントライブラリでサーバへの接 続を試みた結果のプロトコルミスマッチ。これは、とても古いクライアントライ ブラリを使用して、@code{--old-protocol} オプション付きで開始していない新 しいサーバに接続する場合に発生します。 @item CR_NAMEDPIPEOPEN_ERROR; Win32 上の名前つきパイプの生成に失敗した。 @item CR_NAMEDPIPEWAIT_ERROR; Win32 上の名前つきパイプの wait に失敗した。 @item CR_NAMEDPIPESETSTATE_ERROR; Win32 上のパイプハンドラの獲得に失敗した。 @end table @subsubheading 例 @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 説明 @code{from} の文字列を、SQL ステートメントとしてサーバに送ることができる ように、現在のキャラクタ・セットを考慮しながら変換します。 結果は @code{to} に入り、終端 null 文字を追加します。 変換される文字列は @samp{NUL} (ASCII 0), @samp{\n}, @samp{\r}, @samp{\}, @samp{'}, @samp{"}, Control-Z です。(@pxref{Literals}). @code{from} で示される文字列 は@code{length} バイト長でなければなりません。 @code{to} バッファには少なくとも @code{length*2+1} バイト長を割り当てる 必要があります。(最悪の場合、それぞれの文字が2バイトに変換されることがあ り、さらに終端 null バイトのための場所が必要です。) @code{mysql_escape_string()} が復帰するとき、@code{to} の内容は @code{NUL} 終端文字列になります。 戻り値は変換された文字列の長さです。終端 null 文字は含みません。 @subsubheading 例 @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 上記の @code{strmov()} 関数は @code{mysqlclient} ライブラリに含まれてい て、@code{strcpy()} のように働きますが、最初の引数の終りの null へのポイ ンタを返します。 @subsubheading 戻り値 @code{to} へ置かれた値の長さ。終端 null 文字は含みません。 @subsubheading エラー 無し。 @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 説明 @code{query} で示される SQL クエリを実行します。これは @code{length} バ イト長です。クエリはひとつの SQL ステートメントでなければなりません。終端 のセミコロン(@samp{;})や @code{\g} をステートメントに追加すべきではありま せん。 バイナリデータを含むクエリは @code{mysql_real_query()} を使 用@emph{しなければなりません}。バイナリデータは @samp{\0} 文字を含むこと があるからです。 また、@code{mysql_real_query()} は @code{mysql_query()} よりも速いです。 クエリの @code{strlen()} を呼ばないからです。 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 戻り値 クエリが成功した場合は0。クエリが失敗した場合は非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 @strong{MySQL} サーバに、アクセス権テーブルを再読み込みするように依頼し ます。接続されたユーザは @strong{reload} 権限を持つ必要があります。 この関数は推奨されません。代わりに、SQL @code{FLUSH PRIVILEGES} ステートメ ントを発行する @code{mysql_query()} の使用が推奨されます。 @subsubheading 戻り値 成功時0。失敗時非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 レコードカーソルをクエリ結果セット中の絶対レコードに設定します。これは、結 果セット構造体がクエリのすべての結果を持っていることを要求します。そのため、 @code{mysql_row_seek()} は @code{mysql_store_result()} と共にだけ使用でき、 @code{mysql_use_result()} と共には使用できません。 オフセットは @code{mysql_row_tell()} または @code{mysql_row_seek()} 呼びだ しからの戻り値であるべきです。この値は単純なレコード番号ではありません;レ コード番号を使用して結果セット内のレコードにシークしたい場合は、 @code{mysql_data_seek()} を代わりに使用してください。 @subsubheading 戻り値 レコードカーソルの前の値。この値はその後の @code{mysql_row_seek()} 呼びだ しに渡すことができます。 @subsubheading エラー 無し。 @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 説明 最後の @code{mysql_fetch_row()} についてレコードカーソルの現在の位置を返します。 この値は @code{mysql_row_seek()} への引数として使用できます。 @code{mysql_row_tell()} は @code{mysql_store_result()} の後にだけ使用すべ きで、@code{mysql_use_result()} の後には使用すべきではありません。 @subsubheading 戻り値 行カーソルの現在のオフセット。 @subsubheading エラー 無し。 @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 説明 @code{mysql} で示される現在の接続に、デフォルト(現在の)データベースとし て @code{db} で示されるデータベースを使用するように指示します。以降のク エリでは、明示的にデータベースを指定しないテーブル参照について、このデー タベースがデフォルトになります。 接続されたユーザがデータベースを使用する権限を持っていると証明されなけれ ば、@code{mysql_select_db()} は失敗します。 @subsubheading 戻り値 成功時0。失敗時非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 データベースサーバにシャットダウンするように要求します。接続されたユーザ は @strong{shutdown} 権限を持っている必要があります。 @subsubheading 戻り値 成功時0。失敗時非0。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 @code{mysqladmin status} で提供されるのと同様の情報を文字列として返しま す。これは秒での uptime と、実行中のスレッド数、問い合わせ数、再読み込み 数、オープンテーブル数を含みます。 @subsubheading 戻り値 サーバ状態を表わす文字列。エラーが発生した場合 @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 データを取り出すクエリ(@code{SELECT}, @code{SHOW}, @code{DESCRIBE}, @code{EXPLAIN})が成功する毎に、@code{mysql_store_result()} または @code{mysql_use_result()} を呼び出す必要があります。 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()} はクエリのすべての結果をクライアントへ読み込み、 @code{MYSQL_RES} 構造体を割り当て、この構造体に結果を配置します。 @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. 返されるレコードが無い場合、空の結果セットが返されます。 (空の結果セットは @code{NULL} 戻り値とは異なります。) 一度 @code{mysql_store_result()} を呼び出して null ポインターでない 結果を得る事ができたら、結果セット中にいくつのレ コードがあるかを見つけるために、@code{mysql_num_rows()} を呼び出すことがで きます。 結果セットからレコードを取り出すために @code{mysql_fetch_row()} を呼び出す ことができます。また、結果セット内の現在のレコード位置を設定/取得するため に @code{mysql_row_seek()} と @code{mysql_row_tell()} を呼び出すことができ ます。 一度結果セットで行なうと、@code{mysql_free_result()} を呼び出す必要があ ります。 @xref{NULL mysql_store_result, , @code{NULL mysql_store_result()}}. @subsubheading 戻り値 結果の @code{MYSQL_RES} 結果構造体。エラーがある場合 @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_OUT_OF_MEMORY メモリ不足。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @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 説明 現在の接続のスレッド ID を返します。この値は、スレッドを殺すための @code{mysql_kill()} への引数として使用できます。 接続が失われて、@code{mysql_ping()} で再接続した場合、スレッド ID は変更さ れます。これはスレッド ID を後で使うために取得して格納すべきではないことを 意味します。必要な時にそれを取得すべきです。 @subsubheading 戻り値 現在の接続のスレッド ID。 @subsubheading エラー 無し。 @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 説明 データを取り出すクエリ(@code{SELECT}, @code{SHOW}, @code{DESCRIBE}, @code{EXPLAIN})が成功する毎に、 @code{mysql_store_result()} または @code{mysql_use_result()} を呼び出す必要があります。 @code{mysql_use_result()} は結果セット検索を開始しますが, @code{mysql_store_result()} のように、実際にクライアントに結果セットを読み 取りません. 代わりに、各レコードは @code{mysql_fetch_row()} 呼びだしが行な われることにより、個々に取り出されます。 @code{mysql_use_result()} はクエリの結果を、一時テーブルやローカルバッファ に格納すること無く、サーバから直接読み込みます。これは @code{mysql_store_result()} よりもいくらか速く、少ないメモリを使用します。 この場合、クライアントは現在の行と接続バッファ ( @code{max_allowed_packet} bytes まで増加する ) のメモリだけを割り当てます。 一方、クライアント側で各行に ついて多くの処理を行なう場合や、ユーザが @code{^S} (スクロール停止) を入 力できるような画面に出力を送る場合は、@code{mysql_use_result()} を使用す べきではありません。これはサーバと連携しており、他のスレッドが データが取り出されるテーブルを更新する事を邪魔します。 @code{mysql_use_result()} 使用時、@code{NULL} 値を取り出すまで @code{mysql_fetch_row()} を実行する必要があります。そうしないと、次のク エリは前のクエリから結果を取り出します。これを忘れると、C API はエラー @code{Commands out of sync; You can't run this command now} を与えます! @code{mysql_use_result()} から返される結果では、 @code{mysql_data_seek()}, @code{mysql_row_seek()}, @code{mysql_row_tell()}, @code{mysql_num_rows()}, @code{mysql_affected_rows()} を使用できません。 また、@code{mysql_use_result()} が終了するまで他のクエリの発行もできませ ん。(全ての行をフェッチした後に、フェッチされた行数を知るために @code{mysql_num_rows} を呼び出すことができます。) 一度結果セットで行なうと、@code{mysql_free_result()} を呼び出す必要があ ります。 @subsubheading 戻り値 結果の @code{MYSQL_RES} 結果構造体。エラーがある場合 @code{NULL}。 @subsubheading エラー @table @code @item CR_COMMANDS_OUT_OF_SYNC 不当な順にコマンドが実行された。 @item CR_OUT_OF_MEMORY メモリ不足。 @item CR_SERVER_GONE_ERROR @strong{MySQL} サーバがいなくなった。 @item CR_SERVER_LOST サーバへの接続がクエリ中に失われた。 @item CR_UNKNOWN_ERROR 未知のエラーが発生した。 @end table @node NULL mysql_store_result, Query results, mysql_use_result, C API functions @subsection @code{mysql_query()} が成功を返した後、@code{mysql_store_result()} が @code{NULL} を返す時があるのは何故? @code{mysql_query()} の呼び出しが成功した後に @code{mysql_store_result()} が @code{NULL} を返すことがあります。これが 起こったとき、次の条件のどれかの発生を意味します: @itemize @bullet @item @code{malloc()} が失敗した (例えば、結果セットが大き過ぎた場合)。 @item データが読めなかった (接続のエラー)。 @item クエリがデータを返さなかった (@code{INSERT}, @code{UPDATE}, @code{DELETE})。 @end itemize ステートメントが空でない結果を提供するかどうかは @code{mysql_field_count()} の呼び出しによっていつでもチェックできます。 @code{mysql_field_count()} が 0 を返す場合、結果は空で最後のクエリは値を 返さないステートメントです (例えば、@code{INSERT} や @code{DELETE})。 @code{mysql_field_count()} が非 0 値を返す場合、ステートメントは空でない 結果を提供します。 例は@code{mysql_field_count()} 関数の説明を参照してください。 @code{mysql_error()} または @code{mysql_errno()} を呼び出すことによって エラーのテストもできます。 @node Query results, Getting unique ID, NULL mysql_store_result, C API functions @subsection クエリから得られる結果は何か? クエリによって返される結果セットに加えて、次の情報も得ることができます: @itemize @bullet @item @code{mysql_affected_rows()} は、@code{INSERT}, @code{UPDATE} または @code{DELETE} を行なった時の最後のクエリで、影響された行数を返します。 @code{WHERE} 節がない @code{DELETE} が使用されて、テーブルが切り詰められ た場合は例外です。これはとても速いです! この場合、 @code{mysql_affected_rows()} は影響された行数を 0 と返します。 @item @code{mysql_num_rows()} は結果セットのレコード数を返します。 @code{mysql_store_result()} では、@code{mysql_num_rows()} は @code{mysql_store_result()} が復帰したすぐ後に呼び出すことができます。 @code{mysql_use_result()} では、@code{mysql_num_rows()} は @code{mysql_fetch_row()} ですべてのレコードを取り出した後にだけ呼ぶ出すこ とができます。 @item @code{mysql_insert_id()} は、@code{AUTO_INCREMENT} インデックスを持つテー ブルに行を挿入した最後のクエリによって生成された ID を返します。 @xref{mysql_insert_id, , @code{mysql_insert_id()}}. @item いくつかのクエリ (@code{LOAD DATA INFILE...}, @code{INSERT INTO ... SELECT ...}, @code{UPDATE}) は追加情報を返します。結果は @code{mysql_info()} で返されます。 返す文字列の形式については、@code{mysql_info()} の説明を参照してください。 @code{mysql_info()} は追加情報がない場 合は @code{NULL} ポインタを返します。 @end itemize @node Getting unique ID, C API linking problems, Query results, C API functions @subsection 最後に挿入された行のユニーク ID をどのように得られるか? @code{AUTO_INCREMENT} 属性を持つ項目を含むテーブルにレコードを挿入する場 合、@code{mysql_insert_id()} 関数で与えられた ID を得ることができます。 @code{mysql_query()} に渡すクエリ文字列内の@code{LAST_INSERT_ID()} 関数 を使用することでも、ID を取り出すことができます。 次のコードを実行することで、@code{AUTO_INCREMENT} インデックスが使用され たかどうかチェックできます。これは、クエリが @code{AUTO_INCREMENT} イン デックスを伴う @code{INSERT} だったかどうかもチェックできます: @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 生成された最後の ID は接続毎にサーバ内で維持されています。他のクライアント によって変更はされません。他の @code{AUTO_INCREMENT} 項目を非マジック値 (すなわち、@code{NULL} でなく @code{0} でない値) で更新する場合でも、それは変更 されません。 また、他のテーブルにその ID を挿入しようとする場合、次で行なうことができます: @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 C API でのリンクの問題 C API でリンクする時、いくつかのシステム上では次のエラーになります: @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 これは、あなたのシステム上では、コンパイル/リンク行の最後に、math ライブ ラリ (@code{-lm}) を含める必要があることを意味します。 @node Thread-safe clients, , C API linking problems, C API functions @subsection スレッド安全クライアントを作る方法 クライアントは `ほとんど' スレッド安全です。一番大きな問題は @file{net.c} (ソケットから読み込みをするサブルーチンを含むファイル) が割 り込み安全でないことです。これは、サーバからの長い読み込みを中断できるよ うに、自身のアラームを持ちたいだろうという考慮で行なわれました。 If you install an interrupt handlers for the @code{SIGPIPE} interrupt, the socket handling should be thread safe. 標準クライアントライブラリはスレッドオプションでコンパイルされていません。 スレッド安全クライアント(MySQLサーバーとの通信時に、 他のスレッドがクライアントのスレッドに interrupt をかけたり、 タイムアウトをセットしたりする) を得るためには、@code{-lmysys}, @code{-lstring}, @code{-ldbug} ライブラリとサーバが使用する @code{net_serv.o} を使用しま す。 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. スレッドクライアントを使用する時、@file{thr_alarm.c} ルーチンを大いに使 用できます。@code{mysys} ライブラリからのルーチンを使用する場合、覚えて おかなければならないことは @code{my_init()} を最初に呼ぶことだけです! @code{mysql_real_connect()} を除く全ての関数は現在スレッド安全です。スレッ ド安全クライアントライブラリをコンパイルし、それをスレッド安全なマナーで使 用するための方法を、次の注意で説明します。(この @code{mysql_real_connect()} についての注意は、実際には @code{mysql_connect()} にも有効です。しかし @code{mysql_connect()} は推奨 されませんので、とにかく @code{mysql_real_connect()} を使用すべきです。) @code{mysql_real_connect()} をスレッド安全にするためには、クライアントを次の コマンドで再コンパイルする必要があります: @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. 標準クライアントのリンク時に未定義シンボルのためいくつかのエラーが出るで しょう。これはデフォルトでは pthread ライブラリが含まれていないためです。 @c 結果の @file{libmysqld.a} ライブラリは現在スレッド安全です。 @c 2つのスレッドは同じ接続ハンドル (@code{mysql_connect()} で返されるもの) @c を同時に使用できません。2つのスレッドが、@code{mysql_store_result()} で @c 作成された異なる @code{MYSQL_RES} ポインタを使用できるとしてもです。 結果の @file{libmysqlclient.a} ライブラリはスレッド安全です。これの意味す ることは、同じ接続ハンドル(@code{mysql_real_connect()} で返される)に、同時 に2つのスレッドからクエリを行なわない限り、クライアントコードはスレッド安 全ということです; クライアント/サーバプロトコルは、与えられた接続上で同時 に一つの要求だけを許します。複数のスレッドから同じ接続を使用したい場合は、 @code{mysql_query()} と @code{mysql_store_result()} の組み合わせのまわりで mutex lock を行なう必要があります。一度 @code{mysql_store_result()} の用意 ができると、ロックは解放でき、他のスレッドが同じ接続にクエリを行なうことが できます。(他の言葉で言うと、正しいロックプロトコルを使用する限り、別のス レッドは、@code{mysql_store_result()} で生成される別の @code{MYSQL_RES} ポ インタを使用できます。) POSIX スレッドでプログラムを行なう場合、 @code{pthread_mutex_lock()} と @code{pthread_mutex_unlock()} を、mutex lock の確立と解放に使用できます。 @code{mysql_store_result()} でなく @code{mysql_use_result()} を使用する場 合、@code{mysql_use_result()} の回りと @code{mysql_fetch_row()} 呼び出しに ロックが必要です。しかし、スレッド化クライアントに本当に一番良いのは、 @code{mysql_use_result()} を使用しないことです。 @node Perl, Eiffel, C API functions, Clients @section @strong{MySQL} Perl API ここでは Perl @code{DBI} インターフェースについて述べる。 以前のインターフェースは @code{mysqlperl} であった。 @code{DBI}/@code{DBD} が Perl インターフェースとして現在推奨されているので、 @code{mysqlperl} に関してはここでは述べない。 @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} は多くのデーターベースとの一般的なインターフェースである。 これは、多くのデーターベースと動作するスクリプトを変更なしに書けることを意味する。 そのためには、それぞれのデータベース用のデータベースドライバ (DBD) が必要である。 @strong{MySQL} では、そのドライバは @code{DBD::mysql} である。 Perl5 DBI に関する詳細は、@code{DBI}ウェッブページを参照のこと: @example @uref{http://www.symbolstone.org/technology/perl/DBI/index.html} @end example Object Oriented Programming (OOP) に関する詳細は、Perl OOP ページを参照のこと: @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 @subsubsection The @code{DBI} interface @noindent @strong{Portable DBI methods} @multitable @columnfractions .3 .7 @item @code{connect} @tab データベースサーバと接続する @item @code{disconnect} @tab データベースサーバとの接続を切る @item @code{prepare} @tab SQL文を設定する @item @code{execute} @tab 設定されたSQL文を実行する @item @code{do} @tab SQL文を設定し、実行する @item @code{quote} @tab 挿入するためのクォート文字、または @code{BLOB} 値 @item @code{fetchrow_array} @tab フィールドの配列として次のレコードを取り出す @item @code{fetchrow_arrayref} @tab フィールドの配列参照として次のレコードを取り出す @item @code{fetchrow_hashref} @tab ハッシュテーブルへの参照として次のレコードを取り出す @item @code{fetchall_arrayref} @tab 配列の配列として全データを取り出す @item @code{finish} @tab 命令を終了し、リソースからシステムを切り離す @item @code{rows} @tab 影響のあったレコードの数を返す @item @code{data_sources} @tab ローカルホスト上で利用できるデータベースの配列を返す @item @code{ChopBlanks} @tab @code{fetchrow_*} メソッドが空白を取り除くかどうかを管理する @item @code{NUM_OF_PARAMS} @tab 設定された命令文中の placeholder の数 @item @code{NULLABLE} @tab どのフィールドに @code{NULL} 値があるか? @item @code{trace} @tab Perform tracing for debugging @end multitable @noindent @strong{MySQL 固有メソッド} @multitable @columnfractions .3 .7 @item @code{insertid} @tab 最後の @code{AUTO_INCREMENT} 値 @item @code{is_blob} @tab どのフィールドが @code{BLOB} か? @item @code{is_key} @tab どのフィールドがキーか? @item @code{is_num} @tab どのフィールドが数値型か? @item @code{is_pri_key} @tab どのフィールドがプライマリキーか? @item @code{is_not_null} @tab どのフィールドが @code{NULL} 値か? @code{NULLABLE} 参照。 @item @code{length} @tab 利用可能なフィールドサイズの最大値 @item @code{max_length} @tab 実際に存在しているフィールドサイズの最大値 @item @code{NAME} @tab フィールド名 @item @code{NUM_OF_FIELDS} @tab 返されたフィールドの数 @item @code{table} @tab 返されたセットのテーブル名 @item @code{type} @tab 全てのフィールドの型 @item @code{_CreateDB} @tab データベースを作成する @item @code{_DropDB} @tab データベースを削除する。 @strong{***このメソッドは危険である***} @end multitable 以下の節に、より詳細な Perl メソッドの解説がある。 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{汎用 DBI メソッド} @table @code Generally the 'do' statement is MUCH faster (and is preferable) than prepare/execute for statements that doesn't contain parameters. @findex DBI->connect() @findex connect() DBI method @item connect($data_source, $username, $password) データソースとのデータベース接続をするために @code{connect} を使う。 @code{$data_source} 値は @code{DBI:driver_name:} ではじめること。 @code{DBD::mysql} ドライバーを用いた @code{connect} の使用例: @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 ユーザー名またはパスワードが未設定の場合、 @code{DBI} は環境変数である @code{DBI_USER} と @code{DBI_PASS} をそれぞれ使う。 ホスト名を指定しない場合は、@code{'localhost'} がデフォルトとなる。 ポート番号を指定しない場合は、@strong{MySQL} ポート(@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 @code{disconnect} メソッドは、データベースとのデータベースハンドルを切断する。 プログラムを終了する直前に呼び出されるのが典型的である。 例: @example $rc = $dbh->disconnect; @end example @findex DBI->prepare() @findex prepare() DBI method @item prepare($statement) データベースエンジンで実行するためのSQL文を設定し、@code{execute} メソッドで 使用出来るステートメントハンドル @code{($sth)} を返す。 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 $sth = $dbh->prepare($statement) or die "Can't prepare $statement: $dbh->errstr\n"; @end example @findex DBI->execute @findex execute DBI method @item execute @code{execute} メソッドは、設定されたSQL文を実行する。非 @code{SELECT} 文のときは、 影響のあったレコードの数を返す。 もしなんの変化もなかったなら、 @code{execute} は @code{"0E0"} (これは Perl では ゼロ 扱いですが、 真 でもある) を返す。 @code{SELECT} 文のときは、SQL要求を開始するのみである。 データを操作する @code{fetch_*} メソッドの内の一つを記述する必要がある。 例: @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) @code{do} メソッドはSQL文を設定・実行し、影響のあったレコードの数を返す。 このメソッドは、「非 select」文、すなわち、高度(ドライバーの限界のため)で設定できない文、 一度の実行(inserts, deletes など)で済む文のときに一般的に用いられる。 例: @example $rv = $dbh->do($statement) or die "Can't execute $statement: $dbh- >errstr\n"; @end example @findex DBI->quote() @findex quote() DBI method @cindex Quoting strings @cindex Strings, quoting @item quote($string) @code{quote} メソッドは、文字列中にエスケープ文字があるときに用いられ、 クォート文字を文の外側に付加する。 例: @example $sql = $dbh->quote($string) @end example @findex DBI->fetchrow_array @findex fetchrow_array DBI method @item fetchrow_array このメソッドはデータの次のレコードを取り出し、フィールドの値の配列として返す。 例: @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 このメソッドはデータの次のレコードを取り出し、フィールドの値の配列への参照として返す。 例: @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 このメソッドはデータのレコードを取り出し、名前・値のペアのフィールドを含んだ ハッシュテーブルへの参照を返す。このメソッドは、上で示した配列参照 (訳注:@code{fetchrow_arrayref})よりもかなり効率的ではない。例: @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 このメソッドは、SQL文より返されたデータ(レコード)の全てを得るために使う。 このメソッドは、各レコードへの参照の配列の配列への参照を返す。 入れ子のループを使ってデータを利用・表示する。例: @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 そのステートメントハンドルからそれ以上データを取り出さないことを示す。ステートメントハンドルや、つかんでいたシステムリソースを解放するためにこのメソッドを呼び出す。例: @example $rc = $sth->finish; @end example @findex DBI->rows @findex rows DBI method @item rows 最後の命令により、(データの更新、削除、などで)影響のあったレコードの数を返す。 このメソッドは @code{do} あるいは 非 @code{SELECT} @code{execute} 文を 実行した後に、たいてい使われる。例: Example: @example $rv = $sth->rows; @end example @findex DBI->@{NULLABLE@} @findex NULLABLE DBI method @item NULLABLE 配列の各要素に対し、ブール値の配列への参照を返す。 TRUE であればそのフィールドに @code{NULL} 値が含まれていることを示す。例: Example: @example $null_possible = $sth->@{NULLABLE@}; @end example @findex DBI->@{NUM_OF_FIELDS@} @findex NUM_OF_FIELDS DBI method @item NUM_OF_FIELDS この属性は、@code{SELECT} 文や @code{SHOW FIELDS} 文によって返された フィールドの数を示している。命令文が結果を返したかどうかをチェックするのに、 これを使うことが出来る:0値は、@code{INSERT}, @code{DELETE} または @code{UPDATE} のような非 @code{SELECT} 文を示している。例: 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) このメソッドは、@code{'localhost'} ホスト上の @strong{MySQL} サーバで 利用可能なデータベースの名前を含んだ配列を返す。例: @example @@dbs = DBI->data_sources("mysql"); @end example @findex DBI->@{ChopBlanks@} @findex ChopBlanks DBI method @item ChopBlanks この属性は、 @code{fetchrow_*} メソッドが返り値から前後の空白を 除去するかどうかを決定する。例: @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 固有メソッド} 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 @cindex AUTO_INCREMENT, using with DBI @item insertid @strong{MySQL} の特徴である @code{AUTO_INCREMENT} を使うとき、 新しい自動繰り上がり値がここに記憶される。例: 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 配列の各要素に対し、ブール値の配列への参照を返す。TRUE であれば そのフィールドが @code{BLOB} 値であることを示す。例: @example $keys = $sth->@{is_blob@}; @end example @findex DBI->@{is_key@} @findex is_key DBI method @item is_key 配列の各要素に対し、ブール値の配列への参照を返す。TRUE であれば そのフィールドがキーであることを示す。 例: @example $keys = $sth->@{is_key@}; @end example @findex DBI->@{is_num@} @findex is_num DBI method @item is_num 配列の各要素に対し、ブール値の配列への参照を返す。TRUE であれば そのフィールドが数値型であることを示す。 例: @example $nums = $sth->@{is_num@}; @end example @findex DBI->@{is_pri_key@} @findex is_pri_key DBI method @item is_pri_key 配列の各要素に対し、ブール値の配列への参照を返す。TRUE であれば そのフィールドがプライマリーキーであることを示す。 例: @example $pri_keys = $sth->@{is_pri_key@}; @end example @findex DBI->@{is_not_null@} @findex is_not_null DBI method @item is_not_null 配列の各要素に対し、ブール値の配列への参照を返す。FALSE であれば そのフィールドが @code{NULL} 値を含むことを示す。 例: @example $not_nulls = $sth->@{is_not_null@}; @end example @code{is_not_null} is deprecated; 前述の @code{NULLABLE} 属性を使用するほうが望ましい。それが DBI の標準である。 @findex DBI->@{length@} @findex length DBI method @findex DBI->@{max_length@} @findex max_length DBI method @item length @itemx max_length それぞれのメソッドは、フィールドサイズの配列への参照を返す。@code{length} 配列は、 (テーブル記述で定義された)各フィールドの利用可能最大値を示す。 @code{max_length} 配列は、テーブル中に実際に存在している最大値を示す。例: @example $lengths = $sth->@{length@}; $max_lengths = $sth->@{max_length@}; @end example @findex DBI->@{NAME@} @findex NAME DBI method @item NAME フィールド名の配列への参照を返す。 例: @example $names = $sth->@{NAME@}; @end example @findex DBI->@{table@} @findex table DBI method @item table テーブル名の配列への参照を返す。 例: @example $tables = $sth->@{table@}; @end example @findex DBI->@{type@} @findex type DBI method @item type フィールドの型の配列への参照を返す。 例: @example $types = $sth->@{type@}; @end example @end table @node DBI-info, , Perl DBI Class, Perl @subsection @code{DBI}/@code{DBD} に関するそれ以上の情報 @code{DBI} に関するそれ以上の情報は @code{perldoc} コマンドで得られる。 @example perldoc DBI perldoc DBI::FAQ perldoc DBD::mysql @end example 他のフォーマットに変換するツール、@code{pod2man}, @code{pod2html} なども 使うことが出来る。 そしてもちろん、@code{DBI} の最新情報は @code{DBI} ウェッブページで見ることが出来る: @example @uref{http://www.symbolstone.org/technology/perl/DBI/index.html} @end example @node Eiffel, Java, Perl, Clients @section @strong{MySQL} Eiffel wrapper The @strong{MySQL} @uref{http://www.mysql.com/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 @strong{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/Contrib}. For documentation consult any JDBC documentation and the drivers own documentation for @strong{MySQL} specific features. @node PHP, Cplusplus, Java, Clients @section @strong{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:: @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 @strong{MySQL} C++ APIs Two API's is available in the @strong{MySQL} @uref{http://www.mysql.com/Contrib/,Contrib directory}. @node Python, Tcl, Cplusplus, Clients @section @strong{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, Ruby, Python, Clients @section @strong{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. @cindex Ruby @node Ruby, , Tcl, Clients @section @strong{MySQL} Ruby API 以下のサイトに、Ruby の MySQL インターフェースがあります。 @uref{http://www.tmtm.org/, www.tmtm.org とみたまさひろ氏の Web ページ} @node Comparisons, MySQL internals, Clients, Top @chapter How @strong{MySQL} compares to other databases @menu * Compare mSQL:: @strong{MySQL} と @code{mSQL} との比較 * Compare PostgreSQL:: @strong{MySQL} と @code{PostgreSQL} との比較 @end menu @node Compare mSQL, Compare PostgreSQL, Comparisons, Comparisons @section @strong{MySQL} と @code{mSQL} との比較 この節は、@strong{MySQL} 開発者によって書かれていますので、そのつもりで 読んで下さい。しかし我々が知っている事実上の間違いはありません。 For a list of all supported limits, functions and types, see the @uref{http://www.mysql.com/crash-me-choose.htmy, @code{crash-me} web page}. @table @strong @item Performance 真の速度比較のためは、増加する @strong{MySQL} ベンチマークスイートを見て下さい @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 これらのオペレーションはとても単純なので、開始のオーバーヘッドが高くなる 時にそれらを良くするのは難しいです。接続が確立された後は @strong{MySQL} はとても良い性能になります。 他のものでは @strong{MySQL} は @code{mSQL} や多くの他の SQL 実装よりとて も速いです: @itemize @bullet @item Complex @code{SELECT} operations. @item 大きな結果の取り出し (@strong{MySQL} はより良く, より速くそしてより安全 なプロトコルを持ちます) @item 可変長文字列を持つテーブル。@strong{MySQL} はさらに効率的な処理を持ち、 @code{VARCHAR} 上にインデックスを持つことができます。 @item 多くのフィールドを持つテーブルの処理。 @item 大きなレコード長のテーブルの処理。 @item @code{SELECT} with many expressions. @item @code{SELECT} on large tables. @item 同時に多くの接続を処理します。@strong{MySQL} は完全なマルチスレッドです。 各接続はそれ自身のスレッドを持ちます。これは、それらが他を待つ必要がない ことを意味します(同じテーブルを変更するクエリが実行される場合を除く)。 @code{mSQL} では、全ての他の接続は、最初のもの - クエリが長いか短いかに 関わらず - が実行され、終わるまで待つ必要があります。その後次の接続が与 えられ、他の全ては再び待ちます。 @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 @code{TEXT} または @code{BLOB} フィールドの使用。 @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} は @code{HAVING} を伴う完全な @code{GROUP BY} や、次の関 数 @code{count()}, @code{avg()}, @code{min()}, @code{max()}, @code{sum()} そして @code{std()} をサポートします。@code{min()} と @code{max()} は文字列の引数も取れます。@code{count(*)} は、クエリ内がこ れだけの場合にとても速く返されるように最適化されます。@code{mSQL} は @code{GROUP BY} を全くサポートしません。 @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} はフィールドのエイリアス名を持ちます。 @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 領域能力 これは、テーブルをどのように小さくできるかです。 @strong{MySQL} はとても精密な型を持ちます。とても小さい領域を使用するテーブルを作成でき るためです。@strong{MySQL} データ型の有用な例は、3バイト長の @code{MEDIUMINT} です。10,000,000 レコードを持つ場合、1レコードあたり1バイトの節約でもと ても重要です。 @code{mSQL2} は4つの型(char,text,int,real)しかないので、小さなテーブルを 得るのは難しいです。 @item 安定性 これを客観的に判断するのは難しいです。@strong{MySQL} の安定性については @ref{Stability} を参照してください。 我々には @code{mSQL} 安定性の経験がありません。そのため、我々はこれにつ いては何も言えません。 @item 価格 もう一つの重要な問題はもちろんライセンスです。@strong{MySQL} は @code{mSQL} よりも柔軟なライセンスを持っています。そして @code{mSQL} よ りもより安いです。少なくとも、あなたが使用を選択した製品全てに、ライセン スまたは email サポートへの支払いを考慮することを覚えていて下さい。 @strong{MySQL} を含めた製品を売る場合、もちろんこのライセンスの獲得が要求 されます。 @item Perl interfaces @strong{MySQL} は基本的に @code{mSQL} と同じ perl インタフェースと、いくつかの追 加機能を持ちます。 @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 開発の速度 @strong{MySQL} はとても小さい開発チームを持っていますが、我々は C と C++ のコーディ ングをとても速く行ないます。スレッド、関数、 @code{GROUP BY} などはまだ @code{mSQL} には実装されていませんので、it has a lot of chatching up to do. この上でいくつかの見通しを得るために、去年の @code{mSQL} @file{HISTORY} ファ イルを見て、@strong{MySQL} Reference Manual News 節と比較できます(@pxref{News})。速く開発された多くのもの が、かなり明白になります。 @item ユーティリティプログラム @code{mSQL} と @strong{MySQL} は多くの興味深いサードパーティツールを持っ ています。上位への移行 (@code{mSQL} -> @strong{MySQL}) はとても簡単です。 @strong{MySQL} は、ほとんど全ての興味深い @code{mSQL} アプリケーションを 持っています。 @strong{MySQL} には、簡単な @code{msql2mysql} プログラムが用意されています。 これは、@code{mSQL} と @strong{MySQL} の C API 関数のスペルの違いを修正するプログラムです。 For example, it changes instances of @code{msqlConnect()} to @code{mysql_connect()}. @code{mSQL} から MySQL への変換は通常、数分使用するだけです。 @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 シェルスクリプト @code{msql2mysql} をソースに実行します。バイナリプログラム @code{replace} が必要です。これは @strong{MySQL} で配布されます。 @item Compile. @item 全てのコンパイラエラーを修復します. @end enumerate @strong{MySQL} と @code{mSQL} 間の C API の違い: @itemize @bullet @item @strong{MySQL} は @code{MYSQL} 構造体を接続型として使用します (@code{mSQL} は @code{int} を使用します)。 @item @code{mysql_connect()} は @code{MYSQL} 構造体へのポインタをパラメータとして使用します。そ れをグローバルに定義したり、その獲得に @code{malloc()} を使用するのは簡単です。 @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()} は @code{MYSQL} 構造体をパラメータとして使用します。古いコードを移 行する場合、あなたの古い @code{msql_error()} コードへパラメータを追加してください。 @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 メッセージバッファは多くの結果行を含めます。 @item 質問または回答が現在のバッファよりも大きい場合、サーバとクライアントのコ ンフィグ可能制限まで、メッセージバッファは動的に増大されます。 @item 全てのパケットは、パケットの重複や見失いを見つけ出すために、番号づけさ れています。 @item 全ての項目は ASCII で送られ、項目の行と長さはパックされたバイナリコーディン グ(1,2 または 3 バイト)で送られます。 @item @strong{MySQL} はバッファされない結果で読み込み可能です(クライアント内に完全なセッ トを格納する必要がありません)。 @item 一つの書き込み/読み込みが 30 秒以上かかると、サーバは接続をクローズしま す。 @item 接続で 8 時間何も起きないと、サーバは接続をクローズします。 @end itemize @node Syntax differences, , Protocol differences, Compare mSQL @subsection @strong{MySQL} & @code{mSQL} 2.0 間の SQL 構文の違いは? @noindent @strong{Column types} @table @code @item @strong{MySQL} 他に加え次の項目オプション型を持ちます (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} オプション @item 整数項目への @code{ZEROFILL} オプション @item @code{PRIMARY KEY} も含み全ての整数項目への @code{AUTO_INCREMENT} オプション @xref{mysql_insert_id, , @code{mysql_insert_id()}}. @item 全ての項目への @code{DEFAULT} 値 @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 @strong{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} はさらに進んだ機能をいくつか持っています。ユーザ定義型、トリ ガ、ルール、トランザクションのような。 (currently it's has about same symantic as @code{MySQL}'s transactions in that the transaction is not 100 % atomic) しかし ANSI SQL と ODBC の標準型と 機能の多くが欠けています。サポート/未サポートの型/関数の完全な一覧は @uref{http://www.mysql.com/crash-me-choose.htmy, @code{crash-me} web page} を見てください。 通常、@code{PostgreSQL} は @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/crash-me-choose.htmy, @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:: @end menu @node MySQL threads, , MySQL internals, MySQL internals @section MySQL threads @strong{MySQL} サーバーは以下のスレッドを作成します: @itemize @bullet @item TCP/IP 接続ハンドルは、全ての接続要求を扱い、さらに、 認証を行うためのスレッドSQLクエリを処理するスレッドを生成します @item NTでは、ネームド・パイプ・ハンドラー・スレッドがあります。 これはネームド・パイプの接続要求に対し、TCP/IP接続スレッドと同様に動きます。 @item シグナルスレッドは、全てのシグナルを扱います。 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 もし @code{--flush-time} オプションを使用したなら、 全てのテーブルを一定期間でフラッシュするためだけのスレッドを作ります。 @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{UMSK} ! @item @code{UMASK} @tab The user-file creation mask when creating files. @item @code{USER} @tab The default user on Windows to use when connection 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} @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} @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 @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 backed @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 @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" @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 Borsen} @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 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/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/Contrib/00-README, 00-README} This listing. @appendixsec API's @itemize @bullet @item Perl modules @itemize @bullet @item @uref{http://www.mysql.com/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/Contrib/DBI-1.13.tar.gz, DBI-1.13.tar.gz} Perl @code{DBI} module. @item @uref{http://www.mysql.com/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/Contrib/Msql-Mysql-modules-1.2209.tar.gz, Msql-Mysql-modules-1.2209.tar.gz} Perl @code{DBD} module to access mSQL and @strong{MySQL} databases.. @item @uref{http://www.mysql.com/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/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/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 ou updated as frequently. @item @uref{http://www.mysql.com/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/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/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/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 TCX. @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/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/Contrib/DelphiMySQL2.zip, DelphiMySQL2.zip} Delphi interface to @code{libmysql.dll}, by @email{bsilva@@umesd.k12.or.us} @item @uref{http://www.mysql.com/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/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/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/Contrib/Db.py, Db.py} Python module with caching. By @email{gandalf@@rosmail.com}. @item @uref{http://www.mysql.com/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/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/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/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/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/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/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/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/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/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/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 TCX. @item @uref{http://www.mysql.com/Contrib/kmysqladmin-0.4.1.tar.gz, kmysqladmin-0.4.1.tar.gz} @item @uref{http://www.mysql.com/Contrib/kmysqladmin-0.4.1-1.src.rpm, kmysqladmin-0.4.1-1.src.rpm} @item @uref{http://www.mysql.com/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/Contrib/mysql-admin-using-java+swing.tar.gz, Java client using Swing} By Fredy Fischer, @email{se-afs@@dial.eunet.ch}. Ypu can always find the latest version @uref{http://www.trash.net/~ffischer/admin/index.html, here}. @item @uref{http://www.mysql.com/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/Contrib/netadmin.zip, netadmin.zip} A 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/Contrib/xmysqladmin-1.0.tar.gz, xmysqladmin-1.0.tar.gz} A 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 TcX. @item @uref{http://www.mysql.com/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/Win32/ArtronicWINAdmin.exe,Atronic's @strong{MySQL} client for Win32} @item @uref{http://www.mysql.com/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/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/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, bonis@@kiss.de. Not maintained anymore! @item @uref{http://www.mysql.com/Contrib/mysqladm.tar.gz, mysqladm.tar.gz} @strong{MySQL} Web Database Administration written in Perl. By Tim Sailer. @item @uref{http://www.mysql.com/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/Contrib/billowmysql.zip, billowmysql.zip} Updated version of @file{mysqladm.tar.gz}, by Ying Gao. @item @uref{http://www.mysql.com/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/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/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/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. @end itemize @appendixsec Web tools @itemize @bullet @item @uref{http://www.mysql.com/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/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/Contrib/udmsearch-2.2.1b.tar.gz, UdmSearch 2.2.1b (stable version)} @item @uref{http://www.mysql.com/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/Contrib/wmtcl.doc, wmtcl.doc} @item @uref{http://www.mysql.com/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/Contrib/www-sql-0.5.7.lsm, www-sql-0.5.7.lsm} @item @uref{http://www.mysql.com/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/Contrib/genquery.zip, genquery.zip} Perl SQL database interface package for html. @item @uref{http://www.mysql.com/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/Contrib/webboard-1.0.zip, WebBoard 1.0} EU-Industries Internet-Message-Board. @item @uref{http://www.mysql.com/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/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/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/Contrib/icradius-0.10.tar.gz, icradius 0.10} @uref{http://www.mysql.com/Contrib/icradius.README, icradius readme file} @item @uref{http://www.mysql.com/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/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/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/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/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/Contrib/mysql-passwd.README, mysql-passwd.README} @item @uref{http://www.mysql.com/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/Contrib/MySQLTutor-0.2.tar.gz, MySQLTutor}. MySQLTutor. A tutor of @strong{MySQL} for beginners @item @uref{http://www.mysql.com/Contrib/MySQLDB.zip, MySQLDB.zip} A COM library for @strong{MySQL} by Alok Singh. @item @uref{http://www.mysql.com/Contrib/MySQLDB-readme.html, MySQLDB-readme.html} @item @uref{http://www.mysql.com/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/Contrib/DBIx-TextIndex-0.02.tar.gz, DBIx-TextIndex-0.02.tar.gz} Perl program that uses reverse indexing to handle text searching. By Daniel Koch. @end itemize @appendixsec RPMs for common tools (Most are for RedHat 6.1) @itemize @bullet @item @uref{http://www.mysql.com/Contrib/perl-Data-ShowTable-3.3-2.i386.rpm,perl-Data-ShowTable-3.3-2.i386.rpm} @item @uref{http://www.mysql.com/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/Contrib/php-pg-3.0.13-1.i386.rpm,php-pg-3.0.13-1.i386.rpm} @item @uref{http://www.mysql.com/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/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/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/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/Contrib/findres.pl, findres.pl} Find reserved words in tables. By Nem W Schlecht. @item @uref{http://www.mysql.com/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/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/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/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/Contrib/wu-ftpd-2.6.0-mysql.4.tar.gz,wu-ftpd-2.6.0-mysql_support.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/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 at TcX) 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/detron. @item Patrick Lynch For helping us acquire @code{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 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@@mysql.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. @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 @strong{MySQL} change history 新しい変更を @strong{MySQL} に施すと同時に、マニュアルを変更することに注意してください。 もしマニュアルにかかれているのに @uref{http://www.mysql.com/download.html,@strong{MySQL} download page} に 新しいバージョンの MySQL が見つからない場合、そのバージョンはまだリリースされていません! @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) リリース3.23、およびリリース3.22と3.21との違いは、 3.23が新しいISAMライブラリ( MyISAM )を含むということです。 これは古いISAMより、SQLにとってよりチューニングされています。 3.23リリースは開発中で、機能は速いペースで付け加えられるでしょう。 さしあたり、我々は、このリリースを、このリリースのみにある機能 (大ファイルのサポート、および、マシン非依存のテーブル)を 必要としているユーザーに対してのみ、推薦します。 ( MySQL 3.23の全ての新しい機能は、広くテストされます。 しかし、このリリースが多くの新型コードを含むので、すべてをテストすることが難しいです)。 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.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.18, News-3.23.17, News-3.23.x, 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} one 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) - you have to be as stupid as Sasha to try this :-) @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 @code{myisamchk} の致命的なバグを修正した。 このバグはインデックスファイル中の ヘッダーを、テーブルをチェックしているだけなのにもかかわらず、更新していた。 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 shoul 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 auto_increment が最初のキーでない場合の @code{myisamchk} のバグを修正。 @item Allow @code{DATETIME} in ISO8601 format: 2000-03-12T12:00:00 @item 動的キャラクタセット。 1個の @code{mysqld} バイナリで、多くの違う キャラクタセットを扱えるようになった。 (@code{mysqld} スタート時に指定できます). @item @code{REPAIR TABLE} コマンドを追加。 @item @code{mysql_thread_safe()} C API 関数を追加。 @item @code{UMASK_DIR} 環境変数を追加。 @item @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 sjis キャラクターセットの @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}. @item @code{SQL_BUFFER_RESULT} オプションを @code{SELECT} に追加 @item Removed end space from double/float numbers in results from temporary tables. @code{CHECK TABLE} コマンドの追加。 @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 Linux Alpha 用に多くのパッチを追加. @strong{MySQL} now appears to be relatively stable on Alpha. @item 重複したレコードを速く見つけるためのハッシュ化されたキーを使用するために、 @code{HEAP} 一時テーブル上の @code{DISTINCT} を変更した。 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. 新しく追加したコードは、とても速い。 @item MacOS X で @code{MySQL} をコンパイルできるようになるパッチの追加 @item オプション @code{IF NOT EXISTS} を @code{CREATE DATABASE} に追加. @item 多くのデータベースを同時にダンプできるように、 @code{--all-databases} と @code{--databases} オプションを @code{mysqldump} に追加。 @item @code{MyISAM} 型テーブル中の圧縮した @code{DECIMAL()} インデックスのバグを修正した。 @item 0 を timestamp に保存したときのバグを修正した。 @item ローカルの接続で @code{mysqladmin shutdown} を実行した場合に、@code{mysqladmin} は 終了前に pidfile が無くなるまで待つようになった。 @item いくつかの @code{COUNT(DISTINCT ...)} クエリでコアを吐いたのを修正した。 @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 @code{ALTER TABLEL tbl_name ADD (field_list)} 文を許可した。 @item Fixed problem with optimizer that could sometimes use wrong keys. @item @code{GRANT/REVOKE ALL PRIVILEGES} が @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 @code{CREATE} 文での @code{UNIQUE INDEX} の使用を許可。 @item @code{mysqlhotcopy} - ローカルの @strong{MySQL} データベースをバックアップする ツール。 By Tim Bunce. @item 新しい @code{mysqlaccess}. Thanks to Steve Harvey for this. @item @code{--i-am-a-dummy} と @code{--safe-updates} オプションを @code{mysql} に追加。 @item @code{select_limit} と @code{max_join_size} 変数を @code{mysql} に追加。 @item SQL の変数を追加: @code{SQL_MAX_JOIN_SIZE} と @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 オプション @code{--skip-delay-key-write} を @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 @code{source} コマンドを @code{mysql} に追加。 これは @code{mysql} クライアント内 で、バッチファイルを読むことができる。 Original patch by Matthew Vanecek. @item @code{WITH GRANT 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 Tnu 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 @code{mysqld} の起動オプション @code{--delay-key-write} を @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 変数のデフォルトを表示するオプションをクライアントに追加 @item @code{mysqld} に @code{--log-slow-queries} を追加。 これは時間のかかった 全てのクエリを別のログファイルに記録する。どのくらい時間がかかったかが記される @item @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}. @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 8G より大きなインデックスファイルを扱った場合の問題を修正。 @item NetBSD 用の最新の mit-pthread のパッチを追加。 @item タイムゾーン < GMT - 11 の場合の問題を修正。 @item @code{NISAM} 中のパックされたキーの削除時のバグを修正。 @item いくつか @code{ORDER BY ... DESC} クエリを実行した際の @code{ISAM} の問題を修正。 @item Fixed bug when doing a join on a text key which didn't covert the whole key. @item オプション @code{--delay-key-write} が 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 @code{YEARWEEK()} 関数の追加と、@code{x}, @code{X}, @code{v}, @code{V} オプションの @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 Linux環境下において、@code{pthread_mutex_timedwait} の問題を避けるようにした。 この関数は @code{INSERT DELAYED} で使用されていた。 @xref{Linux}. @item Fixed that one will get at 'disk full' error message if one gets disk full when doing sorting (instead of waiting until we got more disk space). @item @code{MyISAM} で、キーが 250 文字を超えた場合のバグを修正。 @item @code{MyISAM} において、他のスレッドが読んでいるテーブルに対し、 他のスレッドが @code{INSERT} を同時に行うことができるようになった。 @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 @code{concurrency} 変数を @code{thread_concurrency} に改名。 @item 以下の関数がマルチバイト・セーフになった: @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 @code{FULL} オプションを @code{SHOW PROCESSLIST} に追加。 @item @code{--verbose} オプションを @code{mysqladmin} に追加。 @item HEAP の MyISAM への自動変換時のバグを修正。 @item HEAP テーブルに対して、insert + delete + insert + scan table を行った際の バグを修正。 @item Alpha プラットフォーム上での、@code{REPLACE()} と @code{LOAD DATA INFILE} のバグを修正。 @item @code{mysqld} 変数に @code{interactive_timeout} を追加. @item @code{mysql_data_seek()} の引数を @code{ulong} から @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 @code{mysqld} に @code{-O lower_case_table_names=@{0|1@}} オプションを追加。 これはテーブル名を強制的に小文字にします。 @item @code{SELECT ... INTO DUMPFILE} 追加。 @item mysqld に @code{--ansi} オプションを追加。 これはいくつかの関数を @code{ANSI SQL} 互換にします。 @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 FreeBSD 上で、@code{floor()} をオーバーフローセーフにした。 @item @code{--quote-names} オプションを @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 MyODBC の @code{mysql_odbc_escape_string()} 関数が、big5 をサポートした。 @item Rewrote the table handler to use classes. This introduces a lot of new code, but will make table handling faster and better. @item ユーザー定義変数のパッチ(Sashaによる)を追加。 @item Changed that @code{FLOAT} and @code{DOUBLE} (without any length modifiers) are not anymore fixed decimal point numbers. @item @code{FLOAT(X)} の意味を変更: X <=24 ならば、これは @code{FLOAT} と同じで、 24 < X <= 53 であるならば @code{DOUBLE} と同じになります。 @item @code{DECIMAL(X)} は @code{DECIMAL(X,0)} のエイリアスになりました。 また @code{DECIMAL} は @code{DECIMAL(10,0)} のエイリアスになりました。 The same goes for @code{NUMERIC}. @item @code{ROW_FORMAT=@{default | dynamic | static | compressed@}} オプションを @code{CREATE_TABLE} に追加. @item @code{DELETE FROM table_name} が一時テーブルで動かなかった。 @item @code{CHAR_LENGTH()} 関数をマルチバイトセーフに変更 @item @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 新しいデータハンドリング中のいくつかの Y2K 問題を修正。 @item @code{SELECT DISTINCT ... ORDER BY RAND()} の問題を修正。 @item Sergei A. Golubchik による MyISAM のレベルでのテキストサーチのパッチを追加 @item キー無しでfull JOIN を使用した際のキャッシュオーバーフローの問題を修正。 @item いくつかの configure の問題を修正。 @item Some small changes to make parsing faster. @item ALTER TABLE + adding a column after the last field didn't work. @item 2つのキー中でauto_incrementフィールドを使用したときの問題を修正。 @item @code{MyISAM} で auto_increment をサブパートとして使用できるようになった: @code{ CREATE TABLE foo (a int not null auto_increment, b char(5), primary key (b,a)) } @item Fixed bug in @code{MyISAM} with packed char keys that could be @code{NULL}. @item フィールド名を @code{CREATE TABLE table_name SELECT ... } 時にとした場合、動かなかった。 @item Allow use of @code{NATIONAL} and @code{NCHAR} when defining character columns. This is the same as not using @code{BINARY}. @item @code{NULL} のフィールドを @code{PRIMARY KEY} ( @code{UNIQUE} キー) には 許さなくなった。 @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 @item @code{WHERE auto_increment_column IS NULL} を使用して最後にレコードが挿入された後に、 @code{SET SQL_AUTO_IS_NULL=0|1} はサーチのハンドリングの on/off になった。 @item Added new @code{mysqld} variable concurrency for Solaris. @item @code{--relative} オプションを @code{mysqladmin} に追加。 これは @code{extended-status} で変更のモニターをする場合、より便利になった。 @item 空のテーブルに対して @code{COUNT(DISTINCT..)} を使用した際のバグを修正。 @item 中国語のキャラクターセット @code{GBK} を追加。 @item @code{LOAD DATA INFILE} を @code{BLOB} フィールドに使用した際の問題を修正。 @item 論理演算子 @code{~} (negation) を追加。 @item @code{UDF} 関数での問題を修正。 @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 @code{DATETIME} 型を @code{TIME} フィールドに挿入するとき、'day' を 保存しようと試みなくなった。 @item low endian のマシンで float/double の保存の問題を修正。 (これは @code{SUM()} に影響する.) @item TCP/IP 接続の connect timeout を追加。 @item インデックス上で、 @code{NULL} 値を持つかもしれないものに @code{LIKE} "%" した際の問題を修正。 @item @code{REVOKE ALL PRIVILEGES} が全ての権限を取り消していなかったのを修正。 @item オリジナルのテーブル名と同じ名前で一時テーブルを作れるようにした。 @item データベースへの権限をあるユーザーに与えた際、 そのユーザーは他のユーザーに権限を与えることが出来なかった。 @item 新コマンド: @code{SHOW GRANTS FOR user} (by Sinisa). @item 新 @code{date_add} syntax: @code{date/datetime + INTERVAL # interval_type}. By Joshua Chamas. @item @code{LOAD DATA REPLACE} の権限のチェックを修正。 @item Solaris 2.7 上での、壊れた include ファイルを自動修正。 @item big file system を検出する際のいくつかの configure の問題を修正。 @item @code{REGEXP} はケース非依存になった。もしバイナリ文字でない場合は。 @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 @item NetBSD 上での MIT-pthreads パッチを追加。 @item MyISAM 中の range bug を修正。 @item @code{ORDER BY} のデフォルトが再び @code{ASC} になった。 @item @code{LIMIT} を @code{UPDATE} に追加。 @item 新クライアント関数: @code{mysql_change_user()}. @item @code{SHOW VARIABLES} にキャラクターセットを追加。 @item @code{--[whitespace]} コメントをサポートした。 @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{GROUP BY} をともなった @code{SUM(..)} は 0 を返すようになった。 @item @code{SHOW TABLE STATUS} の出力を変更。 @item @code{DELAY_KEY_WRITE} オプションを @code{CREATE TABLE} に追加。 @item @code{AUTO_INCREMENT} をいかなるキーの部分に使用できるようにした。 @item @code{YEAR(NOW())} , @code{YEAR(CURDATE())} の問題を修正。 @item Added @code{CASE} construct. @item 新刊数 @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 @code{WHERE} 節に使用されているインデックスフィールドを更新できるようになった: @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 Linux Alpha 上で @code{egcs} 1.1.2 optimizer のバグ(@code{BLOB} 使用時)を修正。 @item Fixed problem with @code{LOCK TABLES} combined with @code{DELETE FROM table}. @item MyISAM テーブルは @code{NULL} 値と @code{BLOB/TEXT} フィールドにキーを許すようになった。 @item 以下のJOINがより速くなった: @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 @code{WHERE key_column = function} でインデックスが使用されるようになった。 @item 例えフィールドが全く同じにパックされていなくても、 @code{WHERE key_column = column_name} でインデックスが使用されるようになった。 @item @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 @code{--init-file=file_name} オプションを @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 新予約語 (@code{CASE} を要求): @code{CASE, THEN, WHEN, ELSE and END}. @item 新関数 @code{EXPORT_SET()} , @code{MD5()}. @item GB2312 中国語キャラクターセットをサポート。 @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 いくつかのコンパイル問題を修正した。 @end itemize @node News-3.23.0, , News-3.23.1, News-3.23.x @appendixsubsec Changes in release 3.23.0 @itemize @bullet @item 多くの新しい特徴を備えた新しいテーブル・ハンドラー・ライブラリ( @code{MyISAM} )。 @xref{MyISAM}. @item メモリー内に @code{HEAP} テーブルを作成できるようになりました。 これは探索がとても速いです。 @item 大容量ファイルをサポートしているOS上で、大ファイル (63 bit) のサポート。 @item 新しい関数 @code{LOAD_FILE(filename)} 。 これはファイルの中身を文字列値として読みます。 @item 新しい演算子 @code{<=>} 。 これは、 @code{=} のように振る舞いますが、 もし両辺の引数が @code{NULL} なら、真を返します。 これはテーブル間の変更の比較に役立ちます。 @item ODBC 3.0 @code{EXTRACT(interval FROM datetime)} 関数の追加。 @item @code{FLOAT(X)} フィールドは、保存した値を丸めません。 これは検索されたときに 科学表記 (1.0 E+10) になるかもしれません。 @item @code{REPLACE} が前よりも速くなった。 @item @code{LIKE} 文字比較を @code{=} のよに振る舞うように変更; これは @code{'e' LIKE '@'e'} が真になるということです。 @item @code{SHOW TABLE STATUS} はテーブルについての情報を多く出すようになりました。 @item @code{LIKE} を @code{SHOW STATUS} コマンドに追加。 @item @code{SHOW COLUMNS} に Privileges 項目を追加。 @item @code{SHOW INDEX} に @code{packed} と @code{comment} 項目を追加。 @item テーブルへのコメントを追加。 ( @code{CREATE TABLE ... COMMENT "xxx"}). @item @code{UNIQUE} を次のように追加: @code{CREATE TABLE table_name (col int not null UNIQUE)} @item 新 create 構文: @code{CREATE TABLE table_name SELECT ....} @item 新 create 構文: @code{CREATE TABLE IF NOT EXISTS ...} @item @code{CHAR(0)} フィールドの作成を許可した。 @item @code{DATE_FORMAT()} は、フォーマット文字の前に @samp{%} が必要になった。 @item @code{DELAYED} が予約語になった。 (sorry about that :( ). @item プロセジャーの例を追加: @code{analyse}, file: @file{sql_analyse.c}. これはクエリのデータについて説明します。 以下の様にしてみてください: @example SELECT ... FROM ... WHERE ... PROCEDURE ANALYSE([max elements,[max memory]]) @end example この プロセジャーは、テーブルのデータをチェックしたい時に、とても役立ちます! @item @code{BINARY} cast to force a string to be compared case sensitively. @item @code{--skip-show-database} オプションを @code{mysqld} に追加。 @item @code{BLOB}/@code{TEXT} フィールドにおいて、 @code{UPDATE} された レコードをチェックできるようになりました。 @item @code{INNER JOIN} の追加。 @strong{注意}: @code{INNER} は予約語になりました! @item @strong{MySQL} テーブルのホストにネットマスクをサポートした。 @code{IP/NETMASK} として、ネットマスクを指定できます。 @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 (...)} は @code{0} ではなく @code{NULL} を返します。 これは @code{null_column NOT IN (...)} が @code{NULL} 値にマッチしないのを確実にします。 @item @code{TIME} フィールド中に、浮動小数点の値を入れるのを修正。 @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 @code{LOW_PRIORITY} 属性を @code{LOAD DATA INFILE} に追加。 @item デフォルトのインデックス名を、フィールドの名前と同じケースにした。 @item デフォルトの接続数を 100 に変更。 @item @code{LOAD DATA INFILE} 時に、より大きなバッファを使用するようにした。 @item @code{DECIMAL(x,y)} は 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} が凄く速くなった; これは @code{MyISAM} の新しい @code{UNIQUE} を使用します。 @strong{MySQL} 3.22 と一つ違う点は、 @code{DISTINCT} の出力が ソートされないという事です。 @item 全ての C クライアント API が、共有ライブラリを柔軟に作成するため、 マクロから関数になりました。 このため、 @code{mysql_num_fields()} を @code{MYSQL} ととしてコールできず、この代わりに @code{mysql_field_count()} を 使用しなくてはなりません。 @item @code{LIBEWRAP} の追加; Patch by Henning P . Schmiedehausen. @item Don't allow @code{AUTO_INCREMENT} for other than numerical columns. @item @code{AUTO_INCREMENT} の使用は、フィールドを自動的に @code{NOT NULL} にします。 @item Show @code{NULL} as the default value for AUTO_INCREMENT columns. @item @code{SQL_BIG_RESULT} の追加; @code{SQL_SMALL_RESULT} がデフォルトになりました。 @item Added a shared library RPM. This enchancement was contributed by David Fox (dsfox@@cogsci.ucsd.edu). @item @code{--enable-large-files/--disable-large-files} スイッチを @code{configure} に 追加。 See @file{configure.in} for some systems where this is automatically turned off because of broken implementations. @item @code{readline} 4.0 にアップグレード @item 新しい @code{CREATE TABLE} オプション: @code{PACK_KEYS} と @code{CHECKSUM}. @item @code{mysqld} オプションに @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 3.22 はより早く、より安全なコードをもち、たくさんの新しい機能が盛り込まれています。 これらの変更を 3.21 に行わないのは、3.21 の安定度を保つためにはとても多くの変更が必要とされるからです。 これらの変更はメジャーバージョンの変更ではないので、簡単に障害もなく 3.22 にアップグレードができます。 @xref{Upgrading-from-3.21}. 3.22 は新しい @code{DBD-mysql} (1.20xx) ドライバーのみを新しい接続プロトコルに対して使用します! @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 数値を timestamps に保存する際の問題を修正した。 @item Fix problem with timezones that have half hour offsets. @item @code{mysqlhotcopy} - ローカルの @strong{MySQL} データベースをコピーする ツール. By Tim Bunce. @item @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 Win32 でのいくつかの小さなバグ修正 @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 @code{WITH GRANT 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 NetBSD 用の最新の mit-pthread のパッチを追加。 @item タイムゾーン < GMT - 11 の場合の問題を修正。 @item @code{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 キーに対して @code{ORDER BY} を行ったときの問題を修正 @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 @code{CONCAT()} をある @code{WHERE} 節で使用した際にコア・ダンプする問題を修正した。 @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 @file{my_ctype.h} 中の、他のキャラクターセットのプロトタイプを修正。 @item configure 中の、大ファイルシステムを検出する部分の問題を修正。 @item 大きなBLOBフィールドをソートしたときのバグを修正。 @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 空の @code{BLOB/TEXT} フィールドを @code{REVERSE()} した際にコアダンプしたのを修正。 @item @code{/*! */} バージョン番号 を拡張した @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 @code{INSERT ... SELECT} が @code{SQL_BIG_TABLES} を使用していなかったのを修正。 @item @code{SET SQL_LOW_PRIORITY_UPDATES=#} が動いてなかった。 @item 許可を @code{GRANT ... IDENTIFIED BY} で変更しても直にパスワードが 反映されなかったのを修正。 @item 以下の最適化のバグを修正: @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 インストール時の小さな問題を修正。 @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} は予約語でなくなった。 @item たった1レコードしかないテーブルの最適化のバグを修正。 @item @code{LOCK TABLES table_name READ; FLUSH TABLES;} を使用した際のバグ修正。 @item HP-UX のパッチを適用。 @item @code{isamchk} が 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 Autoconf 2.13, Automake 1.4, @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 @code{MySQL} 3.23 のキーワードを無視するように @code{CREATE} 構文を拡張した。 @item @code{LOCK TABLES} でロックされているテーブルに @code{INSERT DELAYED} を 使用した際の、デッドロックの問題を修正。 @item 他のスレッドにロックされているテーブルに @code{DROP TABLE} を使用した際の 問題を修正。 @item @code{GRANT/REVOKE} コマンドを update log に追加。 @item 新しいエラー項目を検出するように @code{isamchk} を修正。 @item @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 @code{mysql_init()} の後に直接 @code{mysql_close()} を読んだときの問題を修正。 (C API) @item Better client error message when you can't open socket. @item 新しいdelayed_insert スレッドが作成できなかったときの @code{delayed_insert_thread} 数の表示を修正。 @item @code{CONCAT()} の引数を多くした場合のバグを修正。 @item DEC 3.2 と SCO のパッチの追加。 @item NT のサービスとして @strong{MySQL} をインストールした際の パスの問題を修正。 @item @strong{MySQL}-Win32 は VC++ 6.0 でコンパイルされるようになった。 (VC++ 5.0 のかわりに) @item @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 テーブルが他のスレッドにロックされたときの、@code{DELETE FROM TABLE} の 問題を修正。 @item Fixed bug in @code{LEFT JOIN} involving empty tables. @item @code{mysql.db} フィールドを @code{char(32)} から @code{char(60)} に変更。 @item @code{MODIFY} と @code{DELAYED} は予約語でなくなった。 @item @code{TIME} フィールドに日にちを入れようとしたときのバグを修正。 @item @code{GRANT} コマンドで新しい @strong{MySQL} ユーザーを登録した後に @code{Host '..' is not allowed to connect to this MySQL server} となる問題を修正。 @item Linux 上で @code{TCP_NODELAY} を使用するように変更。 (これは TCP/IP 接続を速くします) @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 いくつかのOS でupdate log が改行を入れていなかったのを修正。 @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 @code{mysql_install_db} のバグ修正。 (from 3.22.17). @item デフォルトのキーキャッシュを 8M に変更。 @item @code{BLOB} フィールドで一時テーブルが必要とされるクエリの問題を修正。 @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 Linux上で、3.22.17の致命的な問題の修正; @code{shutdown} 後、全ての スレッドが確実に死ななかった。 @item @code{-O flush-time=#} オプションを @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 @code{VARCHAR} フィールドと @code{CHAR} を比較した際にキーを効果的に 使用していなかったのを修正。 @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 @code{--log-update} を使用したときとデフォルトのデータベースを指定しないで 接続したときのコアダンプを修正した。 @item いくつかの @code{configure} と移植性の問題を修正した。 @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 table_name WHERE key_column=column_name} が マッチする行を1行も見つけれないのを修正 @item @code{DATE_ADD(column,...)} が動かないのを修正 @item @code{INSERT DELAYED} could deadlock with status 'upgrading lock' @item 2文字以上のソルトが使用できるように、@code{ENCRYPT()} を拡張。 @item @code{longlong2str} は以前よりかなり速くなった。@code{Intel x86} 用に このコードは最適化されたアセンブラで書き直した @item @code{ALTER TABLE} に @code{MODIFY} キーワードを追加 @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} を @code{IDENTIFIED BY} と共に使用した際、権限情報がフラッシュされるまで 有効にならない @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 もし2つの違うデータベースのテーブルを使用した場合、 @code{LEFT JOIN USING (col1,col2)} が動作しなかった @item @code{LOAD DATA LOCAL INFILE} がファイルがないための理由で UNIX では動作しなかった @item とても短い行(<4バイト)しかない @code{VARCHAR}/@code{BLOB} での問題の修正; error 127 がこの行を消去する場合に起きる可能性があった @item Updating @code{BLOB/TEXT} through formulas didn't work for short (< 256 char) strings. @item 新しいホスト上で @code{GRANT} を実行した場合、そのホストからの最初のコネクションで @code{mysqld} が死ぬ可能性があった @item エイリアス名と同じ項目名を @code{ORDER BY} で使用する場合のバグを修正 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 シェルスクリプトからの起動のために、@code{mysqld} の引数がない場合を許可した。 @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 将来の @strong{MySQL} リリースのために、@code{mysql_fix_privileges} は、 UDF のサポートのために、新しい項目を @code{mysql.func} に追加する。 ( type enum ('function','aggregate') NOT NULL が追加された ) @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{WHERE} 節が無い場合、@code{SELECT COUNT(*) ... LEFT JOIN ...} が動かなかった @item UnixWare 7.0.x で @strong{MySQL} をコンフィグできるように @file{config.guess} を更新 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 @code{WHERE} 節で @code{DATE_ADD()} と @code{DATE_SUB()} を使用した際の問題を修正 @item @code{GRANT ... TO user IDENTIFIED BY 'password'} 構文でパスワードをセットできるようにした @item 多くのテーブルを @code{SELECT} して @code{GRANT} を確認する際のバグを修正 @item RPM 配布での @code{mysql_fix_privilege_tables} ファイルの追加。 これはクライアントパッケージに含んだため、デフォルトでは起動されない。 @item @code{SQL_SMALL_RESULT} オプションを @code{SELECT} に追加。 これは強制的に速い一時テーブルを使用する。 結果が小さいとわかっている場合に使用すると有効。 @item 小数点をつけなくても実数が使用できるようにした @item @code{DATE_ADD}/@code{DATE_SUB()} の結果、十分な日数を得られない場合、 日数を月の最大日にするようにした。 @item @code{GRANT} がカラムをケース非依存で比較していたのを修正 @item ある構文の組み合わせで @code{ALTER TABLE} が core をはくバグが @file{sql_list.h} にあったのでこれを修正 @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 大きな一時ファイルを必要とするテーブルへの @code{isamchk} を修正 @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{重要}: 3.22.11にアップグレードする場合、必ず @code{mysql_fix_privilege_tables} スクリプトを実行しなくてはなりません! これは新しい @code{GRANT} システムのために実行します。 もしこれを行わなければ、@code{ALTER TABLE} や @code{CREATE INDEX}, @code{DROP INDEX} を 実行しようとすると @code{Access denied} になります。 @item テーブル、カラムごとにユーザーのアクセスに対して許可や拒否を設定できます @item @code{USER()} を @code{user@@host} を返すように変更 @item 他のユーザーの @code{PASSWORD} をセットする構文を変更 @item 新コマンド:@code{FLUSH STATUS} はほとんどのステータス変数をゼロにセットします @item 新ステータス変数: @code{aborted_threads}, @code{aborted_connects}. @item 新オプション: @code{connection_timeout} @item ソートのサポート (by Pruet Boonma @email{pruet@@ds90.intanon.nectec.or.th}). @item スロバキア語と日本語のエラーメッセージ @item Configuration and portability fixes. @item Added option @code{SET SQL_WARNINGS=1} to get a warning count also for simple inserts. @item FreeBSD 上でシャットダウンするために、@code{SIGQUIT} のかわりに @code{SIGTERM} を使用します @item @code{mysql} に オプション @code{\G} (print vertically) 追加 @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 mysql_install_db は @strong{MySQL} サーバーを起動しなくなりました! mysql_install_db を行った後に、@code{safe_mysqld} で mysqld を開始させる必要があります。 しかし @strong{MySQL} の RPM パッケージはサーバーをたちあげるようにしています。 @item @code{--bootstrap} を @code{mysqld} に追加。@code{mysql_install_db} はこれを使用します。 この引数は RPM パッケージで @strong{MySQL} のインストールを簡略化します。 @item @code{+, - (sign and minus), *, /, %, ABS() and MOD()} のコードを修正。 @code{BIGINT}で使用した場合の危険性を回避しました(64 bit safe). @item @code{ALTER TABLE} が mysqld をクラッシュさせるバグを修正。 @item 重複したキー結果を得た場合、@strong{MySQL}は常にその旨を報告するようになりました。 (以前のバージョンでは、@code{INSERT} の時にしかメッセージが出ませんでした) @item New syntax: @code{INSERT INTO table_name SET column=value,column=value,...} @item @file{.err} ログファイルのログ記録に、time stamp をつけるようにしました。 @item @code{MYSQL_INIT_COMMAND} オプションを @code{mysql_options()} に追加。 (接続要求する場合に使用できる) @item @code{MYSQL_READ_DEFAULT_FILE} と @code{MYSQL_READ_DEFAULT_GROUP} を @code{mysql_options()}に追加。 @strong{MySQL} オプションファイルから以下のパラメーターを読み取る: @code{port}, @code{socket}, @code{compress}, @code{password}, @code{pipe}, @code{timeout}, @code{user}, @code{init-command}, @code{host} and @code{database} (訳注)オプションファイルのデフォルトは /etc/my.cnf , install_directory/share/mysql/my.cnf @item UDF 構文に @code{maybe_null} を追加 @item Added option @code{IGNORE} to @code{INSERT} statemants with many rows. @item koi8 キャラクターをソートする場合の問題を修正。 koi8を使用しているユーザーは、@code{CHAR} や @code{VARCHAR} カラムを インデックスにしているテーブルに対して、@strong{必ず} @code{isamchk -rq} を実行すること。 @item 新規スクリプト @code{mysql_setpermission} (Luuk de Boer 作) これは指定されたデータベースに対してアクセスを許可するユーザーを 簡単に登録してくれます。 @item Allow use of hexadecimal strings (0x...) when specifying a constant string (like in the column separators with @code{LOAD DATA INFILE}). @item OS/2 に移植 (thanks to Antony T. Curtis @email{antony.curtis@@olcs.net}). @item @code{SHOW STATUS} での変数を増やしました。また、@code{SHOW VARIABLES} の ような出力フォーマットに変更しました。 @item @code{extended-status} コマンドを @code{mysqladmin} に追加。 これは新しいステイタス変数を表示します @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 AIX, DEC OSF1 4.x で @strong{MySQL} を簡単にコンパイルできるように include ファイルを変更。 @item @code{ALTER TABLE} を使用して @code{INT} からサイズの小さい @code{CHAR()} に 変更する場合におきていた不具合を修正。 @item @code{SELECT HIGH_PRIORITY} 追加。 @code{SELECT} において、たとえ他の @code{SELECT} を待っているスレッドがあったとしても、 @code{WRITE LOCK} することができます。 @item Moved wild_compare to string class to be able to use @code{LIKE} on @code{BLOB}/@code{TEXT} columns with \0. @item Added @code{ESCAPE} option to @code{LIKE} @item @code{mysqladmin debug} において、より多くの出力が得られるようにした。 @item Win32 において、@code{--flush} オプションをつけて @code{mysqld} を起動できるようになりました。 これはアップデートが終わった後ですべてのテーブルをディスクにフラッシュします。 このオプションにより NT/Win98 上ですごく安全に動かすことができますが、 @strong{とても} 遅くなります。 @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{ftp://www.mysql.com/pub/mysql/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 @email{tommy@@valley.ne.jp} による日本語キャラクターセット(SJIS, 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/Download/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/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 MySQL での既知のエラーと欠けているデザイン @itemize @bullet @item MIT-pthread を使用するとき、他のディレクトリでビルド出来ません。 これは MIT-pthread の変更を要求するため、我々は、これを修正しそうにないです。 @item @code{BLOB} values can't ``reliably'' be used in @code{GROUP BY} or @code{ORDER BY} or @code{DISTINCT}. これらの場合、 @code{BLOB} の比較の際には最初の @code{max_sort_length} バイト (デフォルト1024)だけが使用されます。 これは @code{mysqld} の @code{-O max_sort_length} オプションで変更可能です。 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 全ての文字型のフィールド、@code{BLOB} と @code{TEXT} はのぞいて、は、 検索されるときに最後についているスペースを自動で取り除きます。 @code{CHAR} 型ではこれは OK で、この特徴は ANSI SQL92 に従っていると見なされるでしょう。 @strong{MySQL} のバグは、 @code{VARCHAR} でも同様に行ってしまうことです。 @item 一つのテーブルに @code{ENUM} と @code{SET} フィールドは 255 までしか持てません。 @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 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 @strong{MySQL} 3.23 より前では、全ての数値型で、少数部分が削られてしまいます。 これは、そのフィールドが何桁の小数部を持つか、定義しなければならなかった、と いうことです。 全ての結果は10進の数で正しく返ってきました。 @end itemize For platform-specific bugs, see the sections about compiling and porting. @cindex TODO @node TODO, Porting, Bugs, Top @appendix MySQL に将来加えたいもの (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 このリストのすべては、それが終わるだろう順番に書かれています。 もしあなたが優先順位に影響を及ぼしたければ、どうかライセンスかサポート登録して、 我々にあなたがより速く欲しいものを言ってください。 @xref{Licensing and Support}. @node TODO future, TODO sometime, TODO, TODO @appendixsec 近い将来に完了せねばならないもの @itemize @bullet @item Fail safe replication. @item Optimize, test and document transactions safe tables @item 副問い合わせ。 @code{select id from t where grp in (select grp from g where u > 100)} @item mysqld に、同時に多くのキャラクタ・セットをサポートさせる @item もし他の disk に symlink されているテーブルに対して @code{ALTER TABLE} を 実行した場合、一時テーブルをこの 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 キーの部分での JOIN を許す (最適化問題) @item Entry for @code{DECRYPT()}. @item @file{.frm} ファイルに @code{FOREIGN} キーの定義を記憶する。 @item サーバーサイドのカーソル @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 自動で @code{DEFAULT} 値をフィールドに追加しない。 @code{DEFAULT} を持たないフィールドを含まない @code{INSERT} の使用は エラーにする @item クエリーと結果のキャッシュ。 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 @code{BIT} 型を 1 bit 取るように最適化 (今 @code{BIT} は一文字とります) @item なぜいくつかの FreeBSD システムで MIT-pthreads @code{ctime()} が動かないか検証。 @item Check if locked threads take any CPU. @item 更新に @code{ORDER BY} を追加。 This would be handy with functions like: @code{generate_id(start,step)}. @item @code{TIMESTAMP} と @code{AUTO_INCREMENT} フィールドを更新しないように、 @code{IMAGE} オプションを @code{LOAD DATA INFILE} に追加。 @item @code{LOAD DATA INFILE} に以下の文を理解させる: @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{VARCHAR} のサポート (MyISAM にはこのサポートが既にあります) @item @code{mysql} から自動的に netscape に出力 @item @code{LOCK DATABASES}. (いろいろなオプション付きで) @item @code{NATURAL JOIN}. @item Change sort to allocate memory in ``hunks'' to get better memory utilization. @item @code{DECIMAL} と @code{NUMERIC} 型は 指数表示の数字を読むことが出来ません: これを修正するには、 @code{Field_decimal::store(const char *from,uint len)} を再コードしなくてはなりません @item Fix @code{mysql.cc} to do fewer @code{malloc()} calls when hashing field names. @item 関数: ADD_TO_SET(value,set) と REMOVE_FROM_SET(value,set) @item @code{t1 JOIN t2 ON ...} と @code{t1 JOIN t2 USING ...} の使用の追加。 現在、 @code{LEFT JOIN} のみが使用できます。 @item @code{unsigned long long} 型の完全なサポート。 @item @code{CASE} 関数 @item @code{show status} にもっと多くの変数を。 @code{INSERT}/@code{DELETE}/@code{UPDATE} 文のカウント。 レコードの読み込みと更新のカウント。 1テーブルでのSELECTとJOINを伴ったSELECTのカウント。 SELECT 中のテーブルの数のカウント。 キーバッファの reaad/write のヒット数(理論値と実数)のカウント。 @code{ORDER BY}, @code{GROUP BY}, 一時テーブルの作成のカウント @item もしクエリの途中で @code{mysql} を中断した場合、あなたは他から接続して 走っているクエリを kill しなくてはなりません。 最終的には、こういったことはサーバー内で検知されるように試みるべきです。 @item テーブルの情報のためのハンドラーインターフェースの追加。 それをシステムテーブルとして使えるように。 これはもしあなたがすべてのテーブルについて情報をリクエストした場合は 少し遅くなるでしょう。 しかしとても柔軟性があります。 基本的なテーブルへの @code{SHOW INFO FROM tbl_name} では実行されるべきです。 @item 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 は queries/thread の数を表示すべき。 @item @code{DELETE} と @code{REPLACE} オプションを @code{UPDATE} 文に追加。 ( これは更新中に起こったキーの重複エラーのあるレコードを 全て削除するでしょう). @item Change the format of @code{DATETIME} to store fractions of seconds. @item ANSI92 と ODBC 3.0 型でかけている物全てを追加。 @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 @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: line_number - line number in data file error_message - the error/warning message and maybe data_line - the line from the data file @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. @end itemize @node TODO sometime, TODO unplanned, TODO future, TODO @appendixsec いつかは行うべきもの @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/.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. TcX's main business is the use of @strong{MySQL} not the development of it. But because TcX is a very flexible company, we have put a lot of resources into the development of @strong{MySQL}. @node TODO unplanned, , TODO sometime, TODO @appendixsec 行う予定のない物 @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 他のシステムへの移植について 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 * RTS-threads:: Comments about RTS threads * Thread packages:: Differences between different thread packages @end menu @node Debugging server, Debugging client, Porting, Porting @appendixsec MySQL server のデバッグ もしあなたが @strong{MySQL} のとても新しいある機能を使っている場合、 @code{--skip-new} (これは全く新しい、潜在的に危険な機能を無効にします) または @code{--safe-mode} (これは問題を生じさせるかもしれない多くの最適化を無効にします) オプションで mysqld を実行させることができます。 @xref{Crashing}. もし @code{mysqld} が起動しないようなら、 @code{my.cnf} が無いかチェックしてください。 @code{my.cnf} の引数は @code{mysqld --print-defaults} でチェックできます。 また @code{mysqld --no-defaults ...} で起動することにより、 @code{my.cnf} を無視することが可能です。 もしあるとても特殊な問題があれば、あなたは、いつも @strong{MySQL} を デバッグするよう試みることができます。 これを行うには、 @strong{MySQL} を @code{--with-debug} オプション付きで configure しなくてはなりません。 @strong{MySQL} がデバッギングを有効にしてコンパイルされているかを 知るには、 @code{mysqld --help} とします。 もし @code{--debug} フラグが リストされていればデバッグが有効です。 @code{mysqladmin ver} も @code{mysqld} のバージョンをリストできます。 この場合は @code{mysql ... -debug} と、バージョン番号に表示されるでしょう。 gcc か egcs の場合、推奨する configure のラインは: @example CC=gcc CFLAGS="-O6" CXX=gcc CXXFLAGS="-O6 -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-debug @end example これは @code{libstdc++} ライブラリと C++ の例外による問題を避けることが出来るでしょう。 (many compilers have problems with C++ exceptions in threaded code). 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. もし @code{mysqld} サーバーのクラッシュを直に引き起こすことができるなら、 あなたはこのトレースファイルを作成することができます: @code{mysqld} サーバーをトレースログファイル @file{/tmp/mysql.trace} オプションで起動。 このログファイルはとても大きくなります。 @code{mysqld --debug --log} か @code{mysqld --debug=d,info,error,query,general,where:O,/tmp/mysql.trace} これは重要なタグのみを出力します。 @strong{MySQL} をデバッグで configure すると、自動で多くの安全な検査関数が enable になります。 これは @code{mysqld} の状態をモニターできます。 もしそれら関数がなにか ``予期せぬこと'' を発見したら、それらを @code{stderr} に書き出します。 これは @code{safe_mysqld} が受け取って error ログに 書き出します! このことはどういうことかというと、 @strong{MySQL} に予期せぬことが 起きた場合、まず最初にすべきことは、 @strong{MySQL} をデバッグ有効にして configure することです! (次に、もちろん、 @email{mysql@@lists.mysql.com} に メールを送り、help を聞くことです。 全てのバグレポート、@strong{MySQL} のバージョンに 関連する質問は、 @code{mysqlbug} スクリプトを使用してください!) ほとんどのシステムでは、もし @code{mysqld} がクラッシュするなら、 @code{gdb} から @code{mysqld} を起動させて多くの情報を得ることが可能です。 Linux 上でのいくつかの @code{gdb} バージョンでは、 @code{mysqld} スレッドのデバッグを可能にする場合、 @code{run --one-thread} を使用しなくてはなりません。 この場合、一度にただ一つのactiveなスレッドだけを持つことになります。 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! もし Linux 上で gdb 4.17.x を使用しているなら、 @file{.gdb} ファイルを いかにしたがって、カレントのディレクトリーにインストールすべきです: @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! 以下は mysqld のデバッグ例です: @example shell> gdb /usr/local/libexec/mysqld gdb> run ... back # mysqld がクラッシュした際、これを行います info locals up info locals up ... (until you get some information about local variables) quit @end example 上記の出力を、 @code{mysqlbug} で作成したメールに含み、 そして @code{mysql@@lists.mysql.com}. に送ってください。 もし @code{mysqld} がハングするなら、 @code{strace} や @code{/usr/proc/bin/pstack} のような システムツールを使用して @code{mysqld} がどこでハングしているか 調べることができます。 もし @code{mysqld} が CPU や メモリー を食い始めたり、``ハング'' したりするなら、 @code{mysqladmin processlist status} を使用して誰かが多くの時間のかかる クエリを実行しているか確かめることが出来ます。 パフォーマンスの問題や新しいクライアントが接続できないときの問題と もしあなたが考えるなら、 いくつかのウインドウで @code{mysqladmin -i10 processlist status} を 実行するのはよい考えでしょう。 もし @code{mysqld} が死んだりハングしたりするなら、 @code{mysqld} を @code{--log} で起動すべきです。 再び @code{mysqld} が死んだら、 あなたはログファイル中の、 @code{mysqld} を kill するクエリをチェックします。 @code{mysqld} を @code{--log} オプションで起動する前に、 全てのテーブルを @code{myisamchk} でチェックすべきです。 (前のクラッシュ時にテーブルが壊れているかもしれないので) @xref{Maintenance}. もし @code{mysqld --log} でログファイルを使用するなら、'hostname' ログファイル、 これはデータベースディレクトリにありますが、これをチェックし、問題を引き起こすクエリ を見つけます。 mysqld が適切にインデックスを使用するのに時間がとてもかかる全ての @code{SELECT} 文を @code{EXPLAIN} で実行することを試みます。 @xref{EXPLAIN, , @code{EXPLAIN}}. また、@code{mysql} コマンドラインでは出来なかった、複雑なクエリもテストすべきです。 もしエラーログファイル(@file{hostname.err})中に @code{mysqld restarted} という文があるなら、 @code{mysqld} を失敗させるクエリを見つけます。 もしこれが起きるなら、@code{myisamchk} (@pxref{Maintenance}) で全てのテーブルをチェックし、 @strong{MySQL} ログファイルにあるそのクエリをテストすべきです。 もしそのようなクエリをみつけたなら、まず最初に最新の @strong{MySQL} にアップグレード してみてください。 もしそれでもだめで、かつ @code{mysql} メーリングリストの アーカイブにもなにも見つけることが出来なかったなら、 @email{mysql@@lists.mysql.com} に バグレポートを出すべきです。 メーリングリストのアーカイブへのリンクは @uref{http://www.mysql.com/doc.html, @strong{MySQL} documentation page}. もし不正なテーブルをえたり、 @code{mysqld} が常にいくつかの update コマンドで 失敗するなら、以下のようにしてこのバグの再現をテストします: @itemize @bullet @item mysqld daemon 停止 (@code{mysqladmin shutdown} で) @item @code{myisamchk -s database/*.MYI} で全テーブルをチェック. @code{myisamchk -r database/table.MYI} で悪いテーブルを修正。 @item @code{mysqld} を @code{--log-update} でスタート. @xref{Update log}. @item 壊れたテーブルを得た時、@code{mysqld server} を停止。 @item バックアップをリストア @item @code{mysqld} server を @code{--log-update} @strong{なしで} 起動。 @item @code{mysql < update-log} で再実行。 update log は @strong{MySQL} データベースディレクトリに @code{your-hostname.#} という名前で保存されています。 @item これでもし再びテーブルがおかしくなるなら、 @code{ISAM} コード中の 再現可能なバグを見つけたことになります! このテーブルと update log を @uref{ftp://www.mysql.com/pub/mysql/secret} に FTP で put します。 われわれはこれをできる限り速く修正します! @end itemize @code{mysqladmin debug} コマンドは使用中のロック、使用しているメモり、 クエリの使用の情報を、mysql ログファイルにいくつかダンプします これはいくつかの問題解決に役立ちます。 このコマンドは、 @strong{MySQL} を デバッグ可能でコンパイルしていなくても、いくつかの役立つ情報も提供します。 いくつかのテーブルでだんだん遅くなる問題であるなら、 @code{OPTIMIZE TABLE} か @code{myisamchk} でテーブルを修復し、最適化を試みるべきです。 遅いクエリは、 @code{EXPLAIN} でもチェックできます。 @xref{Maintenance}. このマニュアルの OS 固有の問題 の節も読むべきです。 @xref{Source install system issues}. @findex DBI->trace @findex trace DBI method @tindex DBI_TRACE environment variable @tindex Environment variable, DBI_TRACE もし Perl @code{DBI} を使用しているなら、 @code{trace} メソッド、あるいは@code{DBI_TRACE} 環境変数で デバッグ情報を有効にできます。 @xref{Perl DBI Class, , Perl @code{DBI} Class}. @node Debugging client, RTS-threads, 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 RTS-threads, Thread packages, Debugging client, 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 スレッドパッケージ間の違いは何? @strong{MySQL} は使用されるスレッドパッケージに非常に依存しています。 そのため、@strong{MySQL} に良いプラットフォームを選択する時には、 スレッドパッケージが非常に重要です。 少なくとも3つのタイプのスレッドパッケージがあります: @itemize @bullet @item シングルプロセス内のユーザスレッド。 スレッド切替えはアラームで管理され、 スレッドライブラリはロックを伴う非スレッド安全関数のすべてを管理します。 動作中スレッドがデータを待つ必要がある場合、read, write そして select は、 通常、他のスレッドに切替えるスレッド固有の select で管理されます。 もしユーザ・スレッドパッケージが標準ライブラリ (FreeBSD と BSDI スレッド) に 統合されているなら、スレッドパッケージのオーバーヘッドは、全ての非安全コールを マップしなければならないスレッドパッケージ(MIT-スレッド, FSU-スレッド, RTS スレッド) よりも少なくなります。 他の環境(例えば SCO)では、全てのシステムコールはスレッド安全なので、 マッピングはとても簡単に行なわれます(SCO 上の FSU-スレッド)。 Downside: 全てのマップされるコールは少し時間がかかり、全ての状況を 処理可能にすることは、とても困難です。 通常、スレッドパッケージによって処理できないシステムコールがいくつかあります (MIT-スレッドとソケットのように)。 スレッドスケジューリングは常に最 適というわけではあ りません。 @item 別のプロセスないのユーザスレッド。 スレッド切替えはカーネルによって行なわれ、全てのデータはスレッド間で共有されます。 スレッドパッケージは、スレッ ド間のデータ共有を許可するために標準スレッドコールを管理します。 LinuxThreads はこの方法を使用しています。 Downside: 多くのプロセス。スレッド生成は遅いです。 もし一つのスレッドが死ぬと、残りは通常ハングして残り、再起動前に それら全て を kill する必要があります。スレッド切替えはいくらか高価(expensive)です。 @item カーネルスレッド。 スレッド切替えはスレッドライブラリかカーネルによって処理され、 とても速いです。 全ては一つのプロセス内で行なわれますが、 いくつかのシステムでは、@code{ps} が異なったスレッドを示します。 もし一つのスレッドがアボートした場合、プロセス全体がアボートします。 多くのシステムコールはスレッド安全で、オーバーヘッドはとても少ないです。 Solaris, HP/UX, AIX そして OSF1 がカーネルスレッドを持っています。 @end itemize いくつかのシステムでは、カーネルスレッドは、システムライブラリ内で、 ユーザレベルスレッドの統合によって管理されます。 この場合、スレッド切替えはスレッドライブラリによってだけ行なわれ、 カーネルは実際には 'thread aware' ではありません。 @node Regexp, Unireg, Porting, Top @appendix MySQL の正規表現の文法について A regular expression (regex) is a powerful way of specifying a complex search. @strong{MySQL} は正規表現の regular Henry Spencers 実装を使用します。 そしてこれは POSIX 1003.2 に一致することが 目的です。@strong{MySQL} は拡張 バージョンを使用します。 これは詳細を省いた簡単なリファレンスです。 さらに正確な情報は Henry Spencers @code{regex(7)} マニュアルを見てください。 これはソース配布に含まれています。 @xref{Credits}. 正規表現は文字列の組み合わせて記述されます。 もっとも簡単な場合は、非特殊文字の一文字です。例えば、 regexp @code{hello} は @code{hello} と適合し、 他には適合しません。 簡単でない正規表現は、1つの文字列以上に適合できるような、いくつかの 特殊な構成を使用します。例えば、regexp @code{hello|word} は 文字列 @code{hello} と文字列 @code{word} に適合します。 そしてさらに複雑な例 regexp @code{B[an]*s} は、 文字列 @code{Bananas}, @code{Baaaaas}, @code{Bs} のどれか、 そして @code{B} で始まり @code{a} や @code{n} が 任意の数続き、@code{s} で終わるような他の文字列に適合します。 正規表現では、次の特殊文字/構成が使用できます: @table @code @item ^ 文字列全体の始まり。 @example mysql> select "fo\nfo" REGEXP "^fo$"; -> 0 mysql> select "fofo" REGEXP "^fo"; -> 1 @end example @item $ 文字列全体の終り。 @example mysql> select "fo\no" REGEXP "^fo\no$"; -> 1 mysql> select "fo\no" REGEXP "^fo$"; -> 0 @end example @item . 任意の文字 (改行含む)。 @example mysql> select "fofo" REGEXP "^f.*"; -> 1 mysql> select "fo\nfo" REGEXP "^f.*"; -> 1 @end example @item a* 0個以上の文字 @code{a} の並び。 @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+ 文字 @code{a} が 1個以上並ぶ。 @example mysql> select "Ban" REGEXP "^Ba+n"; -> 1 mysql> select "Bn" REGEXP "^Ba+n"; -> 0 @end example @item a? 0 または 1個の文字 @code{a}。 @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 @code{de} か @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)* 文字列 @code{abc} の 0 回以上の並びにマッチ。 @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@} 多くの発生に適合する regexp の記述する一般的な方法。 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 さらに正確には、1つの整数 i とコンマ無しを含む修飾が続くアトムは、 厳密にアトムに適合する @code{i} 回の並びに適合します。 整数 @code{i} とコンマを含む修飾が続くアトムは、 アトムに適合する @code{i} 回以上の並びに適合します。 整数 @code{i} と @code{j} を含む装飾が続くアトムは、 アトムに適 合する @code{i} 回から @code{j} 回までの並びに適合します。 両方の引数は @code{0 >= value <= RE_DUP_MAX (default 255)} でないとい けません。 そして、2つある場合、2番目は1番目よりも大きいか同じでないといけません。 @item [a-dX] @itemx [^a-dX] @code{a}, @code{b}, @code{c}, @code{d}, @code{X} のどれかの文字 (@code{^} を使用するとどれでもない文字) にマッチ。 @code{]} 文字を含めるには、 @code{[} のあとに続いてすぐに書く必要があります。 @code{-} 文字を含めるには最初か最後に書く必要があります。 @code{[0-9]} は任意 の10進数値に適合します。 @code{[]} ペア内部の定義された 意味を持たない全ての文字は、特殊な意味を持たず、それ自身にだけ適合します。 @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.]] 照合要素(collating element)の文字の並び。 並びは括弧表現リストの一つの要素です。 複数文字の照合要素を含む括弧表現は一つ以上の文字に適合します。 例えば、照合並びが @code{ch} 照合要素を含む場合、 正規表現 @code{[[.ch.]]*c} は @code{chchcc} の最初の5文字に適合します。 @item [=character_class=] 同等のクラス。その一つと等しい全ての照合要素の文字の並びを表します。それ自身も含みます。 例えば、@code{o} と @code{(+)} が同等クラスのメンバである場合、 @code{[[=o=]]}, @code{[[=(+)=]]}, @code{[[=(+)=]]} は全て同義語です。 同等クラスは範囲の終了位置にはなりません。 @item [:character_class:] 括弧表現の内部で、@code{[:} と @code{:]} で括られた文字クラスの名前は、 そのクラスに属する全ての文字のリストを表します。標準文字クラス名は: @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 これらは @code{ctype(3)} マニュアルページに記載されている文字クラスを表します。 ロケールが他のを提供することもあります。文字クラスは範囲の終了位置としては使えません。 @example mysql> select "justalnums" REGEXP "[[:alnum:]]+"; -> 1 mysql> select "!!" REGEXP "[[:alnum:]]+"; -> 0 @end example @item [[:<:]] @itemx [[:>:]] それぞれ、単語の始めと終りの空文字列に適合します。単語は、単語文字が前後 にない単語文字の並びとして定義されます。単語文字は alnum 文字 (@code{ctype(3)} で定義されます) と下線(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, Public license, Regexp, Top @appendix UNIREG とは何か? UNIREG は我々の tty インタフェースビルダです。 これは我々の (@strong{MySQL} で使用される) ISAM への低レベル接続に使用します。 これがとても速いためです。これは 1979 年から (UNIX 上で C は 1986 年から) 存在していました。 UNIREG は次のコンポーネントを持ちます: @itemize @bullet @item 一つのテーブルの参照。更新/照会に。 @item 複数のテーブルの参照 (1スクロール範囲で)。 @item テーブルの生成 (@strong{MySQL} では作成できない沢山の項目タグで)。 これは (tty で の) WYSIWYG です。スクリーンと UNIREG プロンプトを項目ごとにデザインできます。 @item レポート生成。 @item 沢山のユーティリティ (テキストファイルへのテーブルの高速エキスポート/インポー ト、テーブル内容の解析...)。 @item 強力な複数テーブルの更新 (我々は頻繁にこれを使用します)。 BASIC に似た言語で多 くの機能を持っています。 @item 動的な言語(現在はスウェーデン語とフィンランド語)。 誰かが英語バージョンを欲しいのなら、翻訳しないといけないいくつかのファイルがあります。 @item 対話的にまたはバッチで更新を実行する機能。 @item Emacs に似たキー定義。キーボードマクロ付き。 @item 全部で 800k のバイナリ。 @item @code{convform} ユーティリティ。異なる文字セット間で @file{.frm} とテキストファイルを変換します。 @item @code{mpack_isam} ユーティリティ。 ISAM テーブルをパックします(50-80% 小さくできます)。 このテーブルは普通のテーブルと同じように @strong{MySQL} で読み込みできます。 1 レコー ドだけ圧縮解除 / アクセスする必要があります。 @code{BLOB} や @code{TEXT} 項目の操作と更新は(まだ)できません。 @end itemize 我々は、UNIREG インタフェースで多くの我々の製品データベースを更新し、 @strong{MySQL} (そしていくつかの特殊な場合、UNIREG レポート生成プログラム) を通して Web ページを提供します。 UNIREG は 3M のディスク領域を使用し、少なくとも次のプラットフォーム上で動作します: SUN OS 4.x, Solaris, Linux, HP/UX, ICL Unix, DNIX, SCO そし て MSDOS。 UNIREG は現在スウェーデン語とフィンランド語でのみ有効です。 UNIREG の価格は 10,000 スウェーデン kr (約 1500$ US) です。 ただし、これはサポートを含みます。 UNIREG はバイナリで配布されます (しかし全ての ISAM ソースは @strong{MySQL} 内に見つけられます)。 通常、我々は顧客のサイトにて顧客用にバイナリをコンパイルします。 新しい開発は @strong{MySQL} に集中しています。 @page @c This node name is special @node Public license, Win license, Unireg, Top @appendix The MySQL server license for non Microsoft operating systems @center @strong{MySQL FREE PUBLIC LICENSE} @center (Version 4, March 5, 1995) @center Copyright (C) 1995, 1996 TcX AB & MySQL Finland AB & Detron HB @center Stockholm SWEDEN, Helsingfors FINLAND and Uppsala SWEDEN @center All rights reserved. NOTE: This license is not the same as any of the GNU Licenses published by the Free Software Foundation. Its terms are substantially different from those of the GNU Licenses. If you are familiar with the GNU Licenses, please read this license with extra care. This License applies to the computer program known as "MySQL". The "Program", below, refers to such program, and a "work based on the Program" means either the Program or any derivative work of the Program, as defined in the United States Copyright Act of 1976, such as a translation or a modification. The Program is a copyrighted work whose copyright is held by TcX Datakonsult AB and MySQL Finland AB and Detron HB. This License does not apply when running "MySQL" on any Microsoft operating system. Microsoft operating systems include all versions of Microsoft Windows NT and Microsoft Windows. 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. NOTHING OTHER THAN THIS LICENSE GRANTS YOU PERMISSION TO MODIFY OR DISTRIBUTE THE PROGRAM OR ITS DERIVATIVE WORKS. THESE ACTIONS ARE PROHIBITED BY LAW. IF YOU DO NOT ACCEPT THESE TERMS AND CONDITIONS, DO NOT MODIFY OR DISTRIBUTE THE PROGRAM. @enumerate @item Licenses. Licensor hereby grants you the following rights, provided that you comply with all of the restrictions set forth in this License and provided, further, that you distribute an unmodified copy of this License with the Program: @enumerate a @item You may copy and distribute literal (i.e., verbatim) copies of the Program's source code as you receive it throughout the world, in any medium. @item You may modify the Program, create works based on the Program and distribute copies of such throughout the world, in any medium. @end enumerate @item Restrictions. This license is subject to the following restrictions: @enumerate a @item Distribution of the Program or any work based on the Program by a commercial organization to any third party is prohibited if any payment is made in connection with such distribution, whether directly (as in payment for a copy of the Program) or indirectly (as in payment for some service related to the Program, or payment for some product or service that includes a copy of the Program "without charge"; these are only examples, and not an exhaustive enumeration of prohibited activities). However, the following methods of distribution involving payment shall not in and of themselves be a violation of this restriction: @enumerate A @item Posting the Program on a public access information storage and retrieval service for which a fee is received for retrieving information (such as an on-line service), provided that the fee is not content-dependent (i.e., the fee would be the same for retrieving the same volume of information consisting of random data). @item Distributing the Program on a CD-ROM, provided that the files containing the Program are reproduced entirely and verbatim on such CD-ROM, and provided further that all information on such CD-ROM be redistributable for non-commercial purposes without charge. @end enumerate @item Activities other than copying, distribution and modification of the Program are not subject to this License and they are outside its scope. Functional use (running) of the Program is not restricted, and any output produced through the use of the Program is subject to this license only if its contents constitute a work based on the Program (independent of having been made by running the Program). @item You must meet all of the following conditions with respect to the distribution of any work based on the Program: @enumerate A @item If you have modified the Program, you must cause your work to carry prominent notices stating that you have modified the Program's files and the date of any change; @item 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 and at no charge to all third parties under the terms of this License; @item If the modified program normally reads commands interactively when run, you must cause it, at each time the modified program commences operation, 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). Such notice must also state that users may redistribute the Program only under the conditions of this License and tell the user how to view the copy of this License included with the Program. (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.); @item You must accompany any such work based on the Program with the complete corresponding machine-readable source code, delivered on a medium customarily used for software interchange. 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 code. However, 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 code; @item If you distribute any written or printed material at all with the Program or any work based on the Program, such material must include either a written copy of this License, or a prominent written indication that the Program or the work based on the Program is covered by this License and written instructions for printing and/or displaying the copy of the License on the distribution medium; @item You may not impose any further restrictions on the recipient's exercise of the rights granted herein. If distribution of executable or object code is made by offering the equivalent ability to copy from a designated place, then offering equivalent ability 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 code along with the object code. @end enumerate @end enumerate @item Reservation of Rights. No rights are granted to the Program except as expressly set forth herein. 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. @item Other Restrictions. If the distribution and/or use of the Program is restricted in certain countries for any reason, Licensor 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. @item Limitations. THE PROGRAM IS PROVIDED TO YOU "AS IS," WITHOUT WARRANTY. THERE IS NO WARRANTY FOR THE PROGRAM, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 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. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL LICENSOR, 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 enumerate @c This node name is special @node Win license, Function Index, Public license, Top @appendix The MySQL license for Microsoft operating systems @center @strong{MySQL shareware license for Microsoft operating systems} @center (Version 1, September 4, 1998) @center Copyright (C) 1998 TcX AB & MySQL Finland AB & Detron HB @center Stockholm SWEDEN, Helsingfors FINLAND and Uppsala SWEDEN @center All rights reserved. This License applies to the computer program known as "MySQL". This License applies when running MySQL on any Microsoft operating system. Microsoft operating systems include all versions of Microsoft Windows NT and Microsoft Windows. YOU SHOULD CAREFULLY READ THE FOLLOWING TERMS AND CONDITIONS BEFORE USING, COPYING OR DISTRIBUTING MySQL. BY USING, COPYING AND DISTRIBUTING MySQL, YOU INDICATE YOUR ACCEPTANCE OF THIS LICENSE TO DO SO, AND ALL ITS TERMS AND CONDITIONS FOR USING, COPYING AND DISTRIBUTING MySQL OR WORKS BASED ON IT. NOTHING OTHER THAN THIS LICENSE GRANTS YOU PERMISSION TO USE, COPY OR DISTRIBUTE MySQL OR ITS DERIVATIVE WORKS. THESE ACTIONS ARE PROHIBITED BY LAW. IF YOU DO NOT ACCEPT THESE TERMS AND CONDITIONS, DO NOT USE, COPY OR DISTRIBUTE MySQL. @enumerate @item Evaluation and License Registration. This is an evaluation version of MySQL for Win32. Subject to the terms below, you are hereby licensed to use MySQL for evaluation purposes without charge for a period of 30 days. If you use MySQL after the 30 day evaluation period the registration and purchase of a MySQL license is required. The price for a MySQL license is currently 200 US dollars and email support starts from 200 US dollars/year. Quantity discounts are available. If you pay by credit card, the currency is EURO (The European Unions common currency) so the prices will differ slightly. The easiest way to register or find options about how to pay for MySQL is to use the license form at TcX's secure server at @uref{https://www.mysql.com/license.htmy}. This can be used also when paying with credit card over the Internet. Other applicable methods for paying are SWIFT payments, cheques and 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, EuroGiro (that should be cheaper) can be used 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 11382 STOCKHOLM, SWEDEN @end example For more information about commercial licensing, please contact: @example David Axmark Kungsgatan 65 B 753 21 UPPSALA SWEDEN Voice Phone +46-18-10 22 80 GMT 9-21. Swedish and English spoken Fax +46-8-729 69 05 Email *much* preferred. E-Mail: mysql-licensing@@mysql.com @end example For more about the license prices and commercial support, like email support, please refer to the MySQL manual. @xref{Cost}. @xref{Support}. The use of MySQL or any work based on MySQL after the 30-day evaluation period is in violation of international copyright laws. @item Registered version of MySQL. After you have purchased a MySQL license we will send you a receipt by paper mail. You are allowed to use MySQL or any work based on MySQL after the 30-days evaluation period. The use of MySQL is, however, restricted to one physical computer, but there are no restrictions on concurrent uses of MySQL or the number of MySQL servers run on the computer. We will also email you an address and password for a password-protected WWW page that always has the newest MySQL-Win32 version. Our current policy is that a user with the MySQL license can get free upgrades. The best way to ensure that you get the best possible support is to purchase commercial support! @item Registration for use in education and university or government-sponsored research. You may obtain a MySQL license for the use in education and university or government-sponsored research for free. In that case, send a detailed application for licensing MySQL for such use to the email address @email{mysql-licensing@@mysql.com}. The following information is required in the application: @itemize @bullet @item The name of the school or institute. @item A short description of the school or institute and of the type of education, resarch or other functions it provides. @item A detailed report of the use of MySQL in the institution. @end itemize In this case you will be provided with a license that entitles you to use MySQL in a specified manner. @item Distribution. Provided that you verify that you are distributing an evaluation or educational/research version of MySQL you are hereby licensed to make as many literal (i.e., verbatim) copies of the evaluation version of MySQL and documentation as you wish. @item Restrictions. The client code of MySQL is in the Public Domain or under the GPL (for example the code for readline) license. You are not allowed to modify, recompile, translate or create derivative works based upon any part of the server code of MySQL. @item Reservation of Rights. No rights are granted to MySQL except as expressly set forth herein. You may not copy or distribute MySQL except as expressly provided under this License. Any attempt otherwise to copy or distribute MySQL 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. @item Other Restrictions. If the distribution and/or use of MySQL is restricted in certain countries for any reason, the Licensor 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. @item Limitations. MySQL IS PROVIDED TO YOU "AS IS," WITHOUT WARRANTY. THERE IS NO WARRANTY FOR MySQL, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF MySQL IS WITH YOU. SHOULD MySQL PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL THE LICENSOR, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE MySQL 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 MySQL (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 MySQL TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. @end enumerate @page @node Function Index, Concept Index, Win 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