Rails开发 - MySQL连接问题

时间:2014-01-10 13:49:17

标签: mysql ruby-on-rails ruby-on-rails-4 mysql-error-1045

我是Rails的新手。我尝试了很多用本网站给出的答案来解决我的问题但是失败了。

1.我的配置

Window 7 64bit
ruby 1.9.3p484
rails 4.0.2
mysql server 5.0.91-community-nt (32bit)
mysql gem
I set a password for root in mysql configuration

2.我创建了一个新的应用程序
rails new my_cms -d mysql
我做了两次修改 1.在Gemfile内部我使用mysql而不是mysql2
2.在config / database.yml里面我使用mysql而不是mysql2

第3。 config / database.yml内容

development:
  adapter: mysql  
  encoding: utf8  
  database: mycms_development  
  pool: 5  
  username: root  
  password:  
  host: 127.0.0.1  
  port: 3306

test:
  adapter: mysql2  
  encoding: utf8  
  database: mycms_test  
  pool: 5  
  username: root  
  password:  
  host: localhost

production:
  adapter: mysql2  
  encoding: utf8  
  database: mycms_production  
  pool: 5  
  username: root  
  password:  
  host: localhost

4.运行服务器
rails s
服务器正在运行 5.打开浏览器并输入 localhost:3000 ERROR,如下所示

Mysql::Error
Access denied for user 'root'@'localhost' (using password: NO)
Rails.root: E:/cms/mycms

6.我努力解决错误
我尽力在这里引导错误。
     TRY => 更改了127.0.0.1而不是localhost,添加了端口:3306
     RESULT => Mysql::Error
                Access denied for user 'root'@'localhost' (using password: NO)
                 Rails.root: E:/cms/mycms

TRY => 将我的密码作为root密码字段放在config / database.yml文件中
     RESULT => ActiveRecord::ConnectionNotEstablished

TRY => 已执行mysql -uroot
RESULT => ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

TRY => 创建新用户vipin并授予所有权限并执行mysql -uvipin
RESULT => ERROR 1045 (28000): Access denied for user 'vipin'@'localhost' (using password: NO)

TRY => 已执行mysql -uroot -p
RESULT => password:当我提供密码时,它成功导向mysql>提示。

我不知道接下来会发生什么。请帮忙。谢谢

修改
输入localhost:3000

时的当前状态

enter image description here

2 个答案:

答案 0 :(得分:1)

尝试为测试环境设置密码和主机:

development:
  adapter: mysql  
  encoding: utf8  
  database: mycms_development  
  pool: 5  
  username: root  
  password: vipin 
  host: localhost  
  port: 3306

test:
  adapter: mysql  
  encoding: utf8  
  database: mycms_test  
  pool: 5  
  username: root  
  password: vipin
  host: localhost
  port: 3306

production:
  adapter: mysql  
  encoding: utf8  
  database: mycms_production  
  pool: 5  
  username: root  
  password:  
  host: localhost
  port: 3306

如果无效,请尝试host: 127.0.0.1

无论如何,我建议使用MySQL 5.5和mysql2 gem。 安装那个gem看看这个link

或者您可以尝试使用BitMani Ruby Stack Installer for Windows。

Ruby Stack Installer

BitMani wiki

答案 1 :(得分:0)

尝试进入mysql -u root并在mycms_development上执行`GRANT ALL PRIVILEG。。* to root @ localhost