■[Linux][Rails]Debian WheezyのMySQL初期設定
Debian7(Vagrant上)にbundle install( gem 'mysql2', '0.3.11')でMySQLを入れた場合、
[vagrant@vagrantvlc: /vagrant/app]$ rails s => Booting Puma => Rails 4.0.1 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server Exiting /home/vagrant/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect': Access denied for user 'root'@'localhost' (using password: YES) (Mysql2::Error)
rails起動する際にMySQLのAccess deniedエラーが出る。
どうやら
apt-get install mysql-server libmysqlclient-dev libmysql-ruby
でMySQLを入れた際に設定したはずのrootパスワードがdatabase.ymlの設定と異なっている&初期設定値がわからない
というお粗末
debianは /etc/mysql/debian.cnf の設定もスーパーユーザになっているため、
そのため、まずmysqldをstop
$ sudo /etc/init.d/mysql stop [FAIL] Stopping MySQL database server: mysqld failed!
おっとstopすらできない。しょうがないのでkill
sudo kill `sudo cat /run/mysqld/mysqld.pid`
- skip-grant-tablesオプションつけて再起動
$ sudo /etc/init.d/mysql start --skip-grant-tables [ ok ] Starting MySQL database server: mysqld .. [info] Checking for tables which need an upgrade, are corrupt or were not closed cleanly..
んん?
mysql_upgrade -pを実行
debian.cnfの設定でログイン
mysql -u debian-sys-maint -p
> SELECT Host,User,Password From mysql.user; +------------+------------------+-------------------------------------------+ | Host | User | Password | +------------+------------------+-------------------------------------------+ | localhost | root | *81F5***** | | vagrantvlc | root | *81F5***** | | 127.0.0.1 | root | *81F5***** | | ::1 | root | *81F5***** | | localhost | debian-sys-maint | *A79***** | +------------+------------------+-------------------------------------------+
一応、rootはあるようなので、
UPDATE mysql.user SET Password=PASSWORD('****') WHERE User='root';
※database.ymlに合わせる
通常モードで再起動
$ sudo /etc/init.d/mysql restart [ ok ] Stopping MySQL database server: mysqld. [ ok ] Starting MySQL database server: mysqld .. [info] Checking for tables which need an upgrade, are corrupt or were not closed cleanly.. [vagrant@vagrantvlc: /vagrant/app]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 37 Server version: 5.5.33-0+wheezy1 (Debian) Copyright (c) 2000, 2013, 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> quit Bye
でOK