Sequel ProからVagrant上のMySQLに接続する
SSHで接続するサーバーとMySQLサーバーが同じサーバのケースで、Vagrantで立てた仮想サーバにアクセスするには、Sequel ProからSSHトンネルを利用してMySQLへ接続するため、標準/ソケット/SSHのうち「SSH」を選択する。
- MySQLの接続にパスワードを設定せず、サーバへの接続設定(Vagrantfile)もデフォルトのままであれば、下記のように設定すれば問題ない。
$ vagrant ssh-config Host default HostName 127.0.0.1 User vagrant Port 2222 (省略)
コマンドラインから接続確認してみると。
$ ssh vagrant@127.0.0.1 -p 2222 vagrant@127.0.0.1's password: Last login: Wed Dec 24 05:44:48 2014 from 10.0.2.2 Welcome to your Vagrant-built virtual machine.
参照
Railsチュートリアル 9章「9.3.1 ユーザーインデックス」で引っかかった箇所について
エラー(1)
9.3.1 ユーザーインデックスの最後のテストを実行すると、67 examples, 45 failures
とかなりのエラーが発生。
[vagrant@localhost first_app]$ bundle exec rspec spec/ ..................FFFFFFFFFFFFFF.F...FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF Failures: 1) Authentication signin page Failure/Error: before { visit signin_path } ActionView::Template::Error: Undefined variable: "$grayLighter". (in /home/vagrant/rails_projects/first_app/app/assets/stylesheets/custom.css.scss:125) # ./app/assets/stylesheets/custom.css.scss:125 # ./app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__3241731177217114664_69995784417680' # ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>' (省略) Finished in 24.4 seconds (files took 1.6 seconds to load) 67 examples, 45 failures Failed examples: rspec ./spec/requests/authentication_pages_spec.rb:10 # Authentication signin page (省略)
Undefined variable: "$grayLight".
とあるので、どうやら変数が未定義らしい。
bootstrap2から3へのバージョンアップにより変数も変更されている模様。
$ bundle list | grep boot* bootstrap-sass (3.3.1.0)
リスト9.25のapp/assets/stylesheets/custom.css.scss
は下記のように変数を変更した。
修正前 | 修正後 |
---|---|
$grayLight | $gray-light |
$grayLighter | $gray-lighter |
$grayDarker | $gray-darker |
エラー(2)
ぐっっっとエラーが減ったが、まだ3つ残っている。
[vagrant@localhost first_app]$ bundle exec rspec spec/ ..............................................FFF.................. Failures: 1) User pages index Failure/Error: visit users_path ActionView::Template::Error: wrong number of arguments (2 for 1) # ./app/helpers/users_helper.rb:4:in `gravatar_for' # ./app/views/users/index.html.erb:7:in `block in _app_views_users_index_html_erb__2530831136725654681_70088240176620' # ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__2530831136725654681_70088240176620' # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>' (省略) Finished in 2.27 seconds (files took 1.83 seconds to load) 67 examples, 3 failures Failed examples: rspec ./spec/requests/user_pages_spec.rb:15 # User pages index rspec ./spec/requests/user_pages_spec.rb:16 # User pages index rspec ./spec/requests/user_pages_spec.rb:18 # User pages index should list each user
リスト9.24のapp/views/users/index.html.erb
は下記のように修正した。
修正前 | 修正後 |
---|---|
<%= gravatar_for user, size: 52 %> | <%= gravatar_for user %> |
これでエラーは0に。しかし画面レイアウトは崩れたまま・・・。
参照
MySQL4.1と5.0を共存させた環境でMySQL5.0のmysqlコマンドで接続しようとすると、設定とは異なるsocketに接続しようとする
同一サーバ上に異なるバージョンのMySQLを起動させる必要があったため、下記の記事を元に進めていたのだが、最後の「5. 接続の確認」でエラーが出てしまった。後々忘れてしまいそうなのでメモしておく。解決はしていない。
環境
- CentOS 6.4
既存のMySQL
RPMパッケージを利用してインストールしておく。
- MySQL-client-standard-4.1.22-0.rhel4.x86_64.rpm
- MySQL-devel-standard-4.1.22-0.rhel4.x86_64.rpm
- MySQL-server-standard-4.1.22-0.rhel4.x86_64.rpm
- MySQL-shared-standard-4.1.22-0.rhel4.x86_64.rpm
追加するMySQL
最初はMySQL5.0の方もRPMパッケージを使うつもりだったのだけど、RPM同士だとどうやら設定ファイル等が衝突してしまうらしく、追加する方のMySQL5.0はソースインストールすることに。
- mysql-5.0.96.tar.gz
事象
# service mysqld50 start Starting MySQL. SUCCESS!
MySQL5.0の起動はできたが、参照したサイトの「5. 接続の確認」を試すとエラー。
# /usr/local/mysql50/bin/mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
- my.cnfのパス:
/usr/local/mysql50/var/my.cnf
- socketのパス:
/usr/local/mysql50/var/mysql.sock
そもそもエラーメッセージのsocketのパスと/usr/local/mysql50/var/my.cnf
に設定したsocketのパスが異なっている。
# mysql_config --socket /var/lib/mysql/mysql.sock
対応(1)
/usr/local/mysql50/var/my.cnf
の [mysqld] と [client] に下記を追加。ちなみに [mysqld_safe] にはすでに記述あり。
socket=/usr/local/mysql50/var/mysql.sock
再起動させてみたが、エラーは変わらず、効果なし。
対応(2)
socketを指定してMySQLを起動してみる。
# mysql --socket=/usr/local/mysql50/var/mysql.sock Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 to server version: 5.0.96-log Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql>
server version: 5.0.96
と出ているので、MySQL5.0が起動したらしい。なんだかよく分からない。
その他
MySQL4.1を起動して、/usr/local/mysql50/bin/mysql -u root
を実行すると接続できるが、Server version: 4.1.22
となる。
# /etc/rc.d/init.d/mysql start Starting MySQL SUCCESS! # /usr/local/mysql50/bin/mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 4.1.22-standard-log Copyright (c) 2000, 2011, 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>
参照
RPMパッケージを利用してMySQL4.1をCentOS6.4にインストールする
環境
- CentOS6.4
VagrantのBox(Vagrantbox.es)は下記を利用している。
CentOS 6.4 x86_64 Minimal (VirtualBox Guest Additions 4.3.2, Chef 11.8.0, Puppet 3.3.1)
RPMパッケージの選定
インストールしたいのはメジャーバージョンがMySQL4.1でマイナーバージョンが最新のものなので、 Index of /MySQL/Downloads/MySQL-4.1 を見ると、メジャーバージョンの最新は「4.1.22」らしい。
MySQL公式ドキュメント Index of /MySQL/Downloads/MySQL-4.1 を参照すると、VagrantのBoxとして「CentOS 6.4 x86_64 Minimal」を利用しているので、PLATFORMは「glibc23」、CPU値*1は「x86_64」のRPMパッケージをインストールすればいいようだ。
今回は下記のRPMパッケージを利用する。
- MySQL-server-4.1.22-0.glibc23.x86_64.rpm
- MySQL-client-4.1.22-0.glibc23.x86_64.rpm
- MySQL-devel-4.1.22-0.glibc23.x86_64.rpm
- MySQL-shared-4.1.22-0.glibc23.x86_64.rpm
インストール手順
スーパーユーザになっておく。
$ su -
既存のMySQLパッケージを調べる。
# rpm -qa | grep mysql mysql-libs-5.1.66-2.el6_3.x86_64
既存のパッケージをアンインストールしておく。
# yum -y remove mysql-libs
RPMパッケージをDLする。
# cd /usr/local/src # wget http://download.softagency.net/MySQL/Downloads/MySQL-4.1/MySQL-server-4.1.22-0.glibc23.x86_64.rpm # wget http://download.softagency.net/MySQL/Downloads/MySQL-4.1/MySQL-client-4.1.22-0.glibc23.x86_64.rpm # wget http://download.softagency.net/MySQL/Downloads/MySQL-4.1/MySQL-devel-4.1.22-0.glibc23.x86_64.rpm # wget http://download.softagency.net/MySQL/Downloads/MySQL-4.1/MySQL-shared-4.1.22-0.glibc23.x86_64.rpm
DLしたRPMパッケージをインストールする。
※ rpmコマンド(rpm -ivh MySQL-*
)ではなく、yumコマンドを使うと依存関係のある「perl-DBI」も同時にインストールしてくれる。
# ls -all total 20752 -rw-r--r-- 1 root root 4478227 Nov 23 2006 MySQL-client-4.1.22-0.glibc23.x86_64.rpm -rw-r--r-- 1 root root 2917745 Nov 23 2006 MySQL-devel-4.1.22-0.glibc23.x86_64.rpm -rw-r--r-- 1 root root 12605102 Nov 23 2006 MySQL-server-4.1.22-0.glibc23.x86_64.rpm -rw-r--r-- 1 root root 1238667 Nov 23 2006 MySQL-shared-4.1.22-0.glibc23.x86_64.rpm # yum -y install MySQL* (省略) Installed: MySQL-client.x86_64 0:4.1.22-0.glibc23 MySQL-devel.x86_64 0:4.1.22-0.glibc23 MySQL-server.x86_64 0:4.1.22-0.glibc23 MySQL-shared.x86_64 0:4.1.22-0.glibc23 Dependency Installed: perl-DBI.x86_64 0:1.609-4.el6 Complete!
細かい設定は置いておいて、MySQLのRPMパッケージのインストールのみ完了。
メモ
perl(DBI) is needed by 〜
RPMパッケージをインストールする際に、下記のようなエラーメッセージが出る場合は「perl-DBI」をインストールすること。
# rpm -ivh MySQL-* error: Failed dependencies: perl(DBI) is needed by MySQL-client-4.1.22-0.glibc23.x86_64 perl(DBI) is needed by MySQL-server-4.1.22-0.glibc23.x86_64
# yum -y install perl-DBI
file 〜 from install of 〜 conflicts with file from package 〜
CentOS 6.4 にはデフォルトで 5.1 系の mysql-libs がインストールされており、mysql-libs に依存しているパッケージがいくつかあります。
インストール時にパッケージがコンフリクトした場合、
# rpm -i MySQL-server-4.1.22-0.glibc23.x86_64.rpm file /usr/share/mysql/charsets/README from install of MySQL-server-4.1.22-0.glibc23.x86_64 conflicts with file from package mysql-libs-5.1.66-2.el6_3.x86_64 (省略)
インストール済みのパッケージを調べ、
# rpm -qa | grep mysql mysql-libs-5.1.66-2.el6_3.x86_64
コンフリクトしたパッケージをアンインストールする。
# yum -y remove mysql-libs
※ rpmコマンドを使用すると、下記のように依存関係にあるパッケージをアンインストールしてくれないので、yumコマンドを使用するとよい。
# rpm -e mysql-libs-5.1.66-2.el6_3.x86_64 error: Failed dependencies: libmysqlclient.so.16()(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64 libmysqlclient.so.16(libmysqlclient_16)(64bit) is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64 mysql-libs is needed by (installed) postfix-2:2.6.6-2.2.el6_1.x86_64
rpmコマンドでインストールする場合
rpmコマンドで「MySQL-client-4.1.22-0.glibc23.x86_64」と「MySQL-server-4.1.22-0.glibc23.x86_64」をインストールする場合、perl-DBIをインストールする必要がある。
# yum -y install perl-DBI # rpm -ivh MySQL-* Preparing... ########################################### [100%] 1:MySQL-shared ########################################### [ 25%] 2:MySQL-server ########################################### [ 50%] PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' See the manual for more instructions. Please report any problems with the /usr/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 Starting MySQL SUCCESS! 3:MySQL-devel ########################################### [ 75%] 4:MySQL-client ########################################### [100%]
参照
MySQL5.5のレプリケーションでスレーブがSlave_IO_Running: Connectingとなってしまう
このサイトを参考にレプリケーションを進めたが、MySQL5.1(マスター・スレーブ共に5.1、yum install)でのレプリケーションはうまくいったのだが、MySQL5.5(ソースインストール)同士でのレプリケーションはスレーブ側でSlave_IO_Running: Connectingとなってしまった。
mysql> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Connecting to master Master_Host: 192.168.33.12 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysqld-bin.000001 Read_Master_Log_Pos: 249 Relay_Log_File: localhost-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: mysqld-bin.000001 Slave_IO_Running: Connecting Slave_SQL_Running: Yes (省略)
結論から言うと、対応(3)にあるように、マスター側でスレーブ(外部ホスト)からの接続を許可してやればOK。
環境
対応(1)
よくよく CHANGE MASTER TO を確認してみると、MASTER_LOG_FILE の設定が「mysqld-bin.000001」となっている。今回の場合、これは「mysqld」ではなく「mysql」が正解。
修正前
CHANGE MASTER TO MASTER_HOST='192.168.33.12', MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysqld-bin.000001', MASTER_LOG_POS=249;
修正後
CHANGE MASTER TO MASTER_HOST='192.168.33.12', MASTER_USER='repl', MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=249;
上記の対応を行ったが、Slave_IO_Running は Connecting のままで、エラーも変わらず・・・。
mysql> SHOW SLAVE STATUS\G (省略) Slave_SQL_Running: Yes (省略) 150108 23:29:30 [ERROR] Slave I/O: error connecting to master 'repl@192.168.33.12:3306' - retry-time: 60 retries: 86400, Error_code: 2003
対応(2)
マスター側でMySQLの3306番ポートを許可するようiptablesを設定してみる。iptablesに-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
を追加する。
[root@localhost mysql-5.5.24]# vi /etc/sysconfig/iptables [root@localhost mysql-5.5.24]# service iptables restart iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ] iptables: Applying firewall rules: [ OK ]
これも効果なし。
mysql> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.33.12 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 249 Relay_Log_File: localhost-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: No Slave_SQL_Running: Yes (省略) Last_IO_Errno: 1593 Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it). Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
対応(3)
スレーブからマスターのMySQLに接続できるか確認すると、アクセスが拒否された。どうやらマスターのMySQLへの接続権限がないらしい。
[root@localhost ~]# mysql -h 192.168.33.12 -u root ERROR 1045 (28000): Access denied for user 'root'@'192.168.33.13' (using password: NO)
マスター側でスレーブ(外部ホスト)からの接続を許可する。(参照サイト)
grant all privileges on client_data.* to root@"192.168.33.%" identified by '' with grant option;
再度、スレーブからマスターのMySQLに接続できるか確認すると、接続できた。
[root@localhost ~]# mysql -h 192.168.33.12 -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 19 Server version: 5.5.24-log Source distribution Copyright (c) 2000, 2011, 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>
スレーブで Slave_IO_Running を確認してみると、「Slave_IO_Running: Yes」となった。
SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.33.12 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 746 Relay_Log_File: localhost-relay-bin.000007 Relay_Log_Pos: 253 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 746 Relay_Log_Space: 413 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
マスターで新規作成した「sample」データベースも、スレーブで反映された。
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sample | | test | +--------------------+ 5 rows in set (0.00 sec)
ちなみに、対応(2)のiptablesの設定をせずともレプリケーションには問題なかった。
スレーブからマスターのMySQLに接続できるか確認した際に、下記のエラーメッセージが出力された場合は、対応(2)のようにiptablesの設定をする必要がある。
[root@localhost ~]# mysql -h 192.168.33.12 -u root ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.33.12' (113)
参照
HomebrewでインストールしたGitを優先的に使うよう設定する
環境
$ brew -v Homebrew 0.9.5
事象
Homebrewで最新版のGit(今回は2.2.1)をインストールしたが、Mac標準のGitが指定されていて、HomebrewのGitが使用できない。
$ brew install git ==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-2.2.1.yosemite.bottle.tar.gz ######################################################################## 100.0% ==> Pouring git-2.2.1.yosemite.bottle.tar.gz (省略) ==> Summary 🍺 /usr/local/Cellar/git/2.2.1: 1356 files, 31M $ git --version git version 1.9.3 (Apple Git-50)
手順
パスを通すため、.bash_profile
ファイルにexport PATH=/usr/local/bin:$PATH
を追記する。
$ vi ~/.bash_profile $ cat ~/.bash_profile export PATH=/usr/local/bin:$PATH
変更内容を反映させるため、sourceコマンドを実行する。
$ source ~/.bash_profile
バージョンを確認すると、HomebrewでインストールしたGitが反映された。
$ git --version git version 2.2.1
mysqld: unrecognized service
以前と異なるサーバーで下記コマンドを実行したところ、再起動できなかった。
# service mysqld restart mysqld: unrecognized service
service コマンドは /etc/rc.d/init.d/ 内のスクリプトを実行させるためのコマンド
/etc/rc.d/init.d/
ディレクトリを確認してみると、どうやら「mysqld」ではなく「mysql」。
# ls /etc/rc.d/init.d/ | grep mysql mysql
スクリプト名を「mysql」に変更して実行すると、無事、再起動できた。
※このスクリプト名は「mysqld」に変更できるらしい。
# service mysql start Starting MySQL SUCCESS!