Snow LeopardにMySQLをインストール

MacPortsを使ってMacにMySQLをインストールを参考にしてインストールしてみた。

インストール開始

bash-3.2$ sudo port install mysql5 +server
Password:
      • > Computing dependencies for mysql5
      • > Fetching zlib
      • > Attempting to fetch zlib-1.2.3.tar.bz2 from http://distfiles.macports.org/zlib
      • > Verifying checksum(s) for zlib
      • > Extracting zlib
      • > Applying patches to zlib
      • > Configuring zlib
      • > Building zlib
      • > Staging zlib into destroot
      • > Installing zlib @1.2.3_3
      • > Activating zlib @1.2.3_3
      • > Cleaning zlib
      • > Fetching openssl
      • > Attempting to fetch openssl-0.9.8k.tar.gz from http://distfiles.macports.org/openssl
      • > Verifying checksum(s) for openssl
      • > Extracting openssl
      • > Applying patches to openssl
      • > Configuring openssl
      • > Building openssl
      • > Staging openssl into destroot
      • > Installing openssl @0.9.8k_0+darwin
      • > Activating openssl @0.9.8k_0+darwin
      • > Cleaning openssl
      • > Fetching ncursesw
      • > Attempting to fetch ncurses-5.7.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/ncurses
      • > Verifying checksum(s) for ncursesw
      • > Extracting ncursesw
      • > Configuring ncursesw
      • > Building ncursesw
      • > Staging ncursesw into destroot
      • > Installing ncursesw @5.7_0+darwin_10
      • > Activating ncursesw @5.7_0+darwin_10
      • > Cleaning ncursesw
      • > Fetching ncurses
      • > Verifying checksum(s) for ncurses
      • > Extracting ncurses
      • > Configuring ncurses
      • > Building ncurses
      • > Staging ncurses into destroot
      • > Installing ncurses @5.7_0+darwin_10
      • > Activating ncurses @5.7_0+darwin_10
      • > Cleaning ncurses
      • > Fetching readline
      • > Attempting to fetch readline-6.0.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/readline
      • > Verifying checksum(s) for readline
      • > Extracting readline
      • > Applying patches to readline
      • > Configuring readline
      • > Building readline
      • > Staging readline into destroot
      • > Installing readline @6.0.000_2+darwin
      • > Activating readline @6.0.000_2+darwin
      • > Cleaning readline
      • > Fetching mysql5
      • > Attempting to fetch mysql-5.0.86.tar.gz from http://mysql.oss.eznetsols.org/Downloads/MySQL-5.0/
      • > Attempting to fetch mysql-5.0.86.tar.gz from http://mysql.he.net/Downloads/MySQL-5.0/
      • > Verifying checksum(s) for mysql5
      • > Extracting mysql5
      • > Applying patches to mysql5
      • > Configuring mysql5
The +server variant is obsolete. Please install the mysql5-server port instead.
      • > Building mysql5
      • > Staging mysql5 into destroot
      • > Installing mysql5 @5.0.86_0+server
      • > Activating mysql5 @5.0.86_0+server
      • > Cleaning mysql5

すぐに終わるのかと思いきや20分くらいかかりました。
opensslやら何やら必要なものも一緒に入れてくれてるようです。
mac portsのことよくわかってません。)
最後の方で何か出ました。
+serverというオプションはもう使えないそうです。

インストール自体をうまくいってるのかな?
一応、mysql5-serverでやり直す。

bash-3.2$ sudo port install mysql5-server
Password:
      • > Computing dependencies for mysql5-server
      • > Fetching mysql5-server
      • > Verifying checksum(s) for mysql5-server
      • > Extracting mysql5-server
      • > Configuring mysql5-server
      • > Building mysql5-server
      • > Staging mysql5-server into destroot
      • > Creating launchd control script
########################################################### # A startup item has been generated that will aid in # starting mysql5-server with launchd. It is disabled # by default. Execute the following command to start it, # and to cause it to launch at startup: # # sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist ###########################################################
      • > Installing mysql5-server @5.0.86_0
****************************************************** * In order to setup the database, you might want to run * sudo -u mysql mysql_install_db5 * if this is a new install ******************************************************
      • > Activating mysql5-server @5.0.86_0
      • > Cleaning mysql5-server

既に入っているような感じ。

初期化を実施

bash-3.2$ sudo -u mysql mysql_install_db5
Password:
Installing MySQL system tables...
091013 22:23:44 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK
Filling help tables...
091013 22:23:45 [Warning] Setting lower_case_table_names=2 because file system for /opt/local/var/db/mysql5/ is case insensitive
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h hostname.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
bash-3.2$ 
bash-3.2$ echo $?
0

それでMySQL起動

bash-3.2$ sudo /opt/local/share/mysql5/mysql/mysql.server start
Password:
Starting MySQL
. SUCCESS! 

めでたくサクセス!
が!こんなん出ました。

めんどいのでとりあえず「許可」
(だいじょうぶか?後でFirewallで制限かけられるのかな?)

接続確認

bash-3.2$ mysql5 -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.86 Source distribution

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

mysql> help

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Network Support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql> q
    -> quit
    -> /
    -> \q
Bye
bash-3.2$ 

繋がった!
\qで抜けるのね。

パスワード設定

/opt/local/lib/mysql5/bin/mysqladmin -u root password xxxxxxxx

自動起動設定

bash-3.2$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist

とりあえず今日はここまで。
意味がよく分かっていないでやったのでMySQL自体の基本的なことは覚えねば。

[Q]DB作成、Table作成、SQL発行、基本的なオプションの把握

[追記]

設定ファイルの作成(参考

bash-3.2$ sudo cp /opt/local/share/mysql5/mysql/my-small.cnf /opt/local/etc/mysql5/my.cnf
bash-3.2$ sudo vim /opt/local/etc/mysql5/my.cnf

〜my.cnf内の[mysqld]節に以下の2行を追記〜
default-character-set=utf8
skip-character-set-client-handshake