3

我正在尝试在我的 debian 7 机器上启动 rails 4 并与 ruby​​ 2.0 一起运行,但在使用 mysql2 gem 连接到 mysql 数据库时遇到问题。

我已经使用下面的命令来设置周围的一切:

\curl -L https://get.rvm.io | bash -s 稳定
rvm 安装红宝石   
rvm 使用 ruby​​ --default
rvm ruby​​gems 电流
gem install rails --no-ri --no-rdoc

当我尝试运行 rake db:create 时,出现以下错误:


no implicit conversion of Fixnum into String
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:72:in `create'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:86:in `block in create_current'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:182:in `block in each_current_configuration'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each_current_configuration'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:85:in `create_current'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:20:in `block (2 levels) in '
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/bin/rake:33:in `'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `load'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `'
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"myapp_development", "pool"=>5, "username"=>"dev", "password"=>password, "socket"=>"/var/run/mysqld/mysqld.sock"}
no implicit conversion of Fixnum into String
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `connect'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:8:in `connection'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/mysql_database_tasks.rb:16:in `create'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:72:in `create'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:86:in `block in create_current'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:182:in `block in each_current_configuration'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:181:in `each_current_configuration'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/tasks/database_tasks.rb:85:in `create_current'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:20:in `block (2 levels) in '
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/home/mayrun/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/gems/rake-10.1.0/bin/rake:33:in `'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `load'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247@global/bin/rake:23:in `'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `eval'
/home/mayrun/.rvm/gems/ruby-2.0.0-p247/bin/ruby_executable_hooks:15:in `'
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"myapp_test", "pool"=>5, "username"=>"dev", "password"=>password, "socket"=>"/var/run/mysqld/mysqld.sock"}

深入了解后我的检查:

  • mysql已启动并正在运行
  • mysql用户名和密码正确。
  • mysql 正在监听 localhost 和 127.0.0.1
  • /var/run/mysqld/mysqld.sock 文件存在
  • 我查看了 mysql 日志,似乎 mysql2 甚至没有尝试连接。
  • 当用较旧、较慢的 mysql gem 替换 mysql2 gem 时,问题就消失了。

我的mysql版本:

$ mysql --version    
mysql  Ver 14.14 Distrib 5.5.31, for debian-linux-gnu (x86_64) using readline 6.2    

这是我的数据库/config.yml 文件:


development:
  adapter: mysql2
  encoding: utf8
  database: myapp_development
  pool: 5
  username: dev
  password: password
  host: localhost
  socket: /var/run/mysqld/mysqld.sock

test:
  adapter: mysql2
  encoding: utf8
  database: myapp_test
  pool: 5
  username: dev
  password: password
  socket: /var/run/mysqld/mysqld.sock

production:
  adapter: mysql2
  encoding: utf8
  database: myapp_production
  pool: 5
  username: dev
  password: password
  socket: /var/run/mysqld/mysqld.sock

本地宝石清单:

*** 当地宝石 ***

actionmailer (4.0.0)
动作包 (4.0.0)
活动模型(4.0.0)
活动记录(4.0.0)
activerecord-deprecated_finders (1.0.3)
主动支持 (4.0.0)
雷尔 (4.0.1)
原子(1.1.14)
建设者(3.1.4)
捆绑器 (1.3.5)
捆绑器卸载 (1.0.2)
咖啡轨(4.0.1)
咖啡脚本(2.2.0)
咖啡脚本源 (1.6.3)
厄鲁比斯 (2.7.0)
执行js (2.0.2)
可执行挂钩 (1.2.6)
远足 (1.2.3)
i18n (0.6.5)
jbuilder (1.5.2)
jquery-rails (3.0.4)
json (1.8.1)
邮件 (2.5.4)
哑剧类型 (1.25)
迷你测试(4.7.5)
multi_json (1.8.2)
mysql2 (0.3.13)
多语言(0.3.3)
机架 (1.5.2)
机架测试(0.6.2)
导轨 (4.0.0)
铁路(4.0.0)
耙子 (10.1.0)
rdoc (3.12.2)
rubygems 捆绑器 (1.4.1)
rvm (1.11.3.8)
萨斯(3.2.12)
sass-rails (4.0.1)
sdoc (0.3.20)
链轮 (2.10.0)
链轮导轨 (2.0.1)
雷神 (0.18.1)
线程安全(0.1.3)
倾斜 (1.4.1)
树梢 (1.4.15)
涡轮链接 (1.3.0)
tzinfo (0.3.38)
丑化者(2.3.0)

安装的软件包:

$ sudo dpkg -l | grep mysql
ii  libdbd-mysql-perl                  4.021-1+b1                    amd64        Perl5 database interface to the MySQL database
ii  libmysqlclient-dev                 5.5.31+dfsg-0+wheezy1         amd64        MySQL database development files
ii  libmysqlclient18:amd64             5.5.31+dfsg-0+wheezy1         amd64        MySQL database client library
ii  mysql-client                       5.5.31+dfsg-0+wheezy1         all          MySQL database client (metapackage depending on the latest version)
ii  mysql-client-5.5                   5.5.31+dfsg-0+wheezy1         amd64        MySQL database client binaries
ii  mysql-common                       5.5.31+dfsg-0+wheezy1         all          MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server                       5.5.31+dfsg-0+wheezy1         all          MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.5                   5.5.31+dfsg-0+wheezy1         amd64        MySQL database server binaries and system database setup
ii  mysql-server-core-5.5              5.5.31+dfsg-0+wheezy1         amd64        MySQL database server binaries
ii  php5-mysql                         5.4.4-14+deb7u5               amd64        MySQL module for php5
4

2 回答 2

8

对于仍在苦苦挣扎的每个人,请记住在单独的终端中运行mysqld 。

于 2014-05-07T07:39:15.603 回答
1

请确保您的 mysql.sock 在 ubuntu 14.04 中是正确的,它位于 /var/run/mysqld/mysqld.sock

于 2014-10-15T12:49:48.667 回答