简体   繁体   English

rake db:用mysql2 gem创建错误(无法为{“adapter”=>“mysql2”创建数据库)

[英]rake db:create error with mysql2 gem (Couldn't create database for {“adapter”=>“mysql2”)

I'm trying to get rails 4 up and running together with ruby 2.0 on my debian 7 box and I'm having issues connecting to a mysql database with mysql2 gem. 我正试图在我的debian 7盒子上使用ruby 2.0和rails 4一起运行,并且我在使用mysql2 gem连接到mysql数据库时遇到问题。

I have used the commands below to set up the everything around: 我使用下面的命令来设置周围的一切:

\curl -L https://get.rvm.io | bash -s stable
rvm install ruby   
rvm use ruby --default
rvm rubygems current 
gem install rails --no-ri --no-rdoc

When I try to run rake db:create and I'm getting the follow error: 当我尝试运行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"}

My inspections after having a deep look: 深入了解我的检查:

  • mysql is up and running mysql启动并运行
  • mysql username and password are correct. mysql的用户名和密码都是正确的。
  • mysql is listening to localhost and 127.0.0.1 mysql正在侦听localhost和127.0.0.1
  • /var/run/mysqld/mysqld.sock file exists /var/run/mysqld/mysqld.sock文件存在
  • I looked at the mysql logs and it seem slike mysql2 is not even attempting to connect. 我查看了mysql日志,看起来很像mysql2甚至没有尝试连接。
  • when replacing mysql2 gem with the older, slower mysql gem, the problem goes away. 当用较旧的,较慢的mysql gem替换mysql2 gem时,问题就消失了。

My mysql version: 我的mysql版本:

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

This is my database/config.yml file: 这是我的database / 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

Local gem list: 本地宝石清单:

*** LOCAL GEMS ***

actionmailer (4.0.0)
actionpack (4.0.0)
activemodel (4.0.0)
activerecord (4.0.0)
activerecord-deprecated_finders (1.0.3)
activesupport (4.0.0)
arel (4.0.1)
atomic (1.1.14)
builder (3.1.4)
bundler (1.3.5)
bundler-unload (1.0.2)
coffee-rails (4.0.1)
coffee-script (2.2.0)
coffee-script-source (1.6.3)
erubis (2.7.0)
execjs (2.0.2)
executable-hooks (1.2.6)
hike (1.2.3)
i18n (0.6.5)
jbuilder (1.5.2)
jquery-rails (3.0.4)
json (1.8.1)
mail (2.5.4)
mime-types (1.25)
minitest (4.7.5)
multi_json (1.8.2)
mysql2 (0.3.13)
polyglot (0.3.3)
rack (1.5.2)
rack-test (0.6.2)
rails (4.0.0)
railties (4.0.0)
rake (10.1.0)
rdoc (3.12.2)
rubygems-bundler (1.4.1)
rvm (1.11.3.8)
sass (3.2.12)
sass-rails (4.0.1)
sdoc (0.3.20)
sprockets (2.10.0)
sprockets-rails (2.0.1)
thor (0.18.1)
thread_safe (0.1.3)
tilt (1.4.1)
treetop (1.4.15)
turbolinks (1.3.0)
tzinfo (0.3.38)
uglifier (2.3.0)

Packages installed: 安装包:

$ 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

对于每个人仍然挣扎,记得在一个单独的终端运行mysqld

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LoadError:无法在rake db:create上加载此类文件mysql2 / mysql2 - LoadError: cannot load such file — mysql2/mysql2 - on rake db:create 无法rake db:create:all - 无法为{“encoding”=>“utf8”,“username”=>“root”,“adapter”=>“mysql”创建数据库 - Cannot rake db:create:all — Couldn't create database for {“encoding”=>“utf8”, “username”=>“root”, “adapter”=>“mysql” 宝石mysql2适配器未安装 - Gem mysql2 adapter not installing 安装mysql2适配器时出错:请安装mysql2适配器:`gem install activerecord-mysql2-adapter`(无法加载此类文件 - mysql2 / mysql2) - Error installing mysql2 adapter: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (cannot load such file — mysql2/mysql2) Rails mysql2错误:“rake aborted!请安装mysql2适配器...“ - Rails mysql2 error: “rake aborted! Please install the mysql2 adapter…” mysql2 gem安装错误 - mysql2 gem install error mysql2 Gem错误 - mysql2 Gem error on rails 耙db:migrate中止了! 用MySQL2开发Ghost数据库? - Rake db:migrate aborted! Ghost development database using MySQL2? rake db:migrate-Mysql2 :: Error:表'database_development.locations'不存在:从`locations'中显示完整字段 - rake db:migrate - Mysql2::Error: Table 'database_development.locations' doesn't exist: SHOW FULL FIELDS FROM `locations` Globalize3:运行“rake db:seed”任务时出现“Mysql2::Error: Unknown database” - Globalize3: "Mysql2::Error: Unknown database" when running the 'rake db:seed' task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM