Cygwin - MySQLクライアントインストール!

Updated:


今日は、Cygwin にインストールした Ruby で MySQL を操作する目的で、 MySQL のクライアントをインストールしました。

サーバは既に Windows 側にインストールされているのでそれを使用します。 ライブラリのみが必要だったためにクライアントのみのインストールとしました。 ※libmysqlclient-dev をインストールするという記事も見かけましたが、Cygwin でのパッケージからのインストール方法やソースからのインストール方法がイマイチ不明でした。(昨日記事にした「Cygwin - apt-cyg インストール!」の apt-cyg の方法でもパッケージが存在しないためダメでした)

以下が手順です。

1.アーカイブダウンロード・展開

MySQL :: MySQL Downloads の「MySQL Community Server」からソースコードを取得して展開します。 当記事執筆時点では 5.5.19 が最新ですが、以下(※)の理由から、これではなく「Looking for previous GA versions?」というリンクへ入り 5.1.60 のソースコードを取得します。 ※5.5.8 以降は configure ではなく cmake を使用するため、サーバをインストールしないオプション(–without-server)がわからないし、サーバも含めて cmake しようとすると stdlib.h 内の dtoa とカチ合ってエラーとなる。(一時的に stdlib.h 内の dtoa をコメントアウトする方法もあるようだが・・・)また、ライブラリが必要なだけで最新である必要もないので。

$ wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.60.tar.gz/from/ftp://ftp.jaist.ac.jp/pub/mysql/
$ tar zxvf mysql-5.1.60.tar.gz

2.ビルド・インストール

展開したディレクトリへ移動し、configure, make, make install します。 当方の環境で下記全てで30分ちょっとかかりました。

$ cd mysql-5.1.60
$ ./configure --prefix=/usr/local/mysql --without-server --without-readline
$ make
$ make install
  • –prefix=/usr/local/mysql ・・・ インストール先
  • –without-server ・・・ サーバはインストールしない
  • –without-readline ・・・ システムの readline ライブラリを使用する

3.動作確認

Windows ネイティブの MySQL サーバを起動して、Cygwin 側から接続できるか確認してみる。

$ cd /usr/local/mysql/bin
$ ./mysql.exe --version
./mysql  Ver 14.14 Distrib 5.1.60, for pc-cygwin (i686) using readline 6.1
$ ./mysql.exe -uroot -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.0-m2-community MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| get_loto           |
| get_mbox           |
| get_trade          |
| get_trade_old      |
| mkmode             |
| mysql              |
| phpmyadmin         |
| wordpress          |
+--------------------+
9 rows in set (0.29 sec)

mysql>

バージョンが表示できて、MySQL サーバへもログインできました。 ※ローカルホストは localhost でなく 127.0.0.1 で指定しないとソケットエラーで接続できません。


とりあえず、これで OK ではないでしょうか。

以上。





 

Sponsored Link

 

Comments