@thorikiriのてょりっき

@thorikiriがWebとかAndroidとかの技術ネタや本を読んだブログです

MacにMySQLをインストールする

OS: OS X 10.8.2 Mountain Lion
MySQL Server: 5.5.28
MacBook Proを買ったので、開発環境を作っています。今回はMySQLを入れましょう。
MacPortsがインストール済みとします。 → MacPortsのインストールする - @thorikiriのてょりっき
まずは、バージョンの確認。

$ port search mysql55
・・・(略)
mysql55-server @5.5.28 (databases)
    Run mysql55 as server
・・・(略)

それでは、インストールしてみましょう。

$ sudo port install mysql55-server
--->  Computing dependencies for mysql55-server
--->  Dependencies to be installed: mysql55 mysql_select tcp_wrappers
--->  Fetching archive for mysql_select
--->  Attempting to fetch mysql_select-0.1.2_0.darwin_12.noarch.tbz2 from http://jog.id.packages.macports.org/macports/packages/mysql_select
・・・(略)
--->  Installing mysql55-server @5.5.28_0
--->  Activating mysql55-server @5.5.28_0

If this is a new install you might want to run:

$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db

--->  Cleaning mysql55-server
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

インストールできましたね。インストールのメッセージに新しいインストールだったら、次のコマンドを実行してねと言ってるので、そのとおりに打ち込みます。

$ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
Installing MySQL system tables...
OK
Filling help tables...
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/mysql55/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql55/bin/mysqladmin -u root -h twinkle.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql55/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/mysql55/bin/mysqld_safe &

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

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

よさそうですね。
パスを通すために、~/.bash_profileを編集しましょう。

$ vim ~/.bash_profile

記述内容は次の通りです。

PATH=$PATH:/opt/local/lib/mysql55/bin
export PATH

そして、反映させます。

$ source ~/.bash_profile

続いて、mysqlコマンドを使えるようにしていきましょう。

$ sudo port load mysql55-server
$ sudo port select mysql mysql55
Selecting 'mysql55' for 'mysql' succeeded. 'mysql55' is now active.

rootのパスワードを設定していきます。

mysqladmin -u root password [新しいパスワード]

起動してみましょう。

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.28 Source distribution

Copyright (c) 2000, 2012, 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> 

できましたね、データベースを確認して、終了してみましょう。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

mysql> quit
Bye

問題ないようです。testデータベースはDROPしてしまって問題ないですね。