Rails newする際にMySQLを指定する方法
$ rails new Name(アプリ名) -d mysql -B
オプション:
-d データベース名: データベースを指定してアプリを作成。デフォルトだとsqlite。
-B: bundle installを自動実行しない。Gemfileを編集してからbundle installしたい場合はこのオプションをつける。
MySQLの初期パスを変更する際
mysql > USE mysql;
mysql > ALTER USER 'root'@'localhost' identified BY 'hoge';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
rootユーザーのパスワードを忘れてしまった場合
一度、セーフモードで起動し、パスワードなしでログインする。
.server stop
$ mysqld_safe
$ mysql -u root
$ mysql
下記コマンドでいったんパスワードを空にする。
> UPDATE mysql.user SET authentication_string=null WHERE User='root';
mysql > exit;
mysql
MySQLを再起動し、ALTER USERでパスワードの再設定。
.server restart
$ mysql -u root -p
mysql > USE mysql;
mysql > ALTER USER 'root'@'localhost' identified BY 'hoge';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
$ mysql