2013年6月19日水曜日

mysqlのinstall

久しぶりにmysqlを使うことになったので環境構築のメモ

環境

  • mountain lion
  • brew

insrall


brew install mysql

上記のコマンドでinstall完了

mysql起動


mysql.server start
Starting MySQL
.. SUCCESS! 

rootのパスワードを設定

初期状態だとrootのパスワードは空白なので設定します。


mysql -u root password 'new_password'

セキュリティ設定

全部デフォルト設定にします


mysql_secure_installation

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

失敗。mysql.sockがないみたいです。mysqlを止めて調査。


 mysql.server stop

 ls -l /tmp/mysql.sock
 ls: /tmp/mysql.sock: No such file or directory

セーフモードで起動

 
mysqld_safe
130619 05:24:50 mysqld_safe Logging to '/usr/local/var/mysql/Macintosh.local.err'.
130619 05:24:50 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql

別タブでターミナルを開く

 
 ls -l /tmp/mysql.sock
 srwxrwxrwx  1 username  wheel  0  6 19 05:25 /tmp/mysql.sock

OK。自動でmysql.sockが作成されました。接続します。

 
mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

え???調べると権限がなくてもこうなるとか。面倒ですね。postgres万歳。


 // ソケット作成のため起動させていたセーフモードを解除
 kill -KILL mysqld_safeのPID
 
 // 権限システムを使用しないで起動
 mysqld_safe --skip-grant-tables &
 
 // パスワードなしで入る
 mysql -u root
 
 // userチェック
 select host, user from user;
 +-----------------+------+
 | host            | user |
 +-----------------+------+
 | 127.0.0.1       | root |
 | ::1             | root |
 | Macintosh.local |      |
 | Macintosh.local | root |
 | localhost       |      |
 | localhost       | root |
 +-----------------+------+
 6 rows in set (0.00 sec)
 

なんじゃこりゃ。ユーザーがいっぱいいますね。バグ?とりあえず削除。


 mysql> truncate table user;
 Query OK, 0 rows affected (0.03 sec)

 mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)

 mysql> grant all privileges on *.* to root@localhost identified by 'new_password' with grant option;
 Query OK, 0 rows affected (0.00 sec)

 mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)

 mysql> select host, user from user;
 +-----------+------+
 | host      | user |
 +-----------+------+
 | localhost | root |
 +-----------+------+
 1 row in set (0.00 sec)

これでいいはず。サーバースタート。


mysql.server start

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
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_secure_installation

rootパスワード以外はYESと答えて終了です。お疲れさまでした。

つーか、みんなpostgres使いましょうよ。何この糞RDB。


参考サイト

この記事がお役にたちましたらシェアをお願いします

このエントリーをはてなブックマークに追加

0 件のコメント:

コメントを投稿

Related Posts Plugin for WordPress, Blogger...