简体   繁体   English

Rails开发 - MySQL连接问题

[英]Rails Development- MySQL Connection Problems

I'm new in Rails. 我是Rails的新手。 I tried a lot to solve my problem with the answers given in this site, but failed. 我尝试了很多用本网站给出的答案来解决我的问题但是失败了。

1.My configurations 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.I created a new application 我创建了一个新的应用程序
rails new my_cms -d mysql
I made two changes 我做了两处改动
1. Inside Gemfile I use mysql instead of mysql2 1.在Gemfile中我使用mysql而不是mysql2
2. Inside config/database.yml I use mysql instead of mysql2 2.在config / database.yml里面我使用mysql而不是mysql2

3. config/database.yml content 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.Running server 4.运行服务器
rails s
server running. 服务器运行。
5.opening browser and typing localhost:3000 ERROR like below 5.打开浏览器并输入 localhost:3000 ERROR,如下所示

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

6.My efforts to solve the error 6.我努力解决错误
I tried my best to crack the error as guided here. 我尽力在这里引导错误。
TRY=> changed 127.0.0.1 instead of localhost, added port: 3306 TRY =>更改了127.0.0.1而不是localhost,添加了端口:3306
RESULT=> Mysql::Error RESULT => Mysql::Error
Access denied for user 'root'@'localhost' (using password: NO)
Rails.root: E:/cms/mycms

TRY=> put my password as root password field inside config/database.yml file TRY =>将我的密码作为root密码字段放在config / database.yml文件中
RESULT=> ActiveRecord::ConnectionNotEstablished RESULT => ActiveRecord::ConnectionNotEstablished

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

TRY=> Created a new user vipin and grant all privileges and executed mysql -uvipin TRY =>创建一个新用户vipin并授予所有权限并执行mysql -uvipin
RESULT=> ERROR 1045 (28000): Access denied for user 'vipin'@'localhost' (using password: NO) RESULT => ERROR 1045 (28000): Access denied for user 'vipin'@'localhost' (using password: NO)

TRY=> executed mysql -uroot -p TRY =>执行mysql -uroot -p
RESULT=> password: and when i gave the password it successfully direct to mysql> prompt. RESULT => password:当我给出密码时,它成功直接进入mysql>提示符。

I dont know what is next. 我不知道接下来会发生什么。 Please help. 请帮忙。 Thank you 谢谢

EDIT 编辑
CURRENT STATUS WHEN ENTERING localhost:3000 输入localhost:3000当前状态localhost:3000

在此输入图像描述

Try to set password and host for test environment too: 尝试为测试环境设置密码和主机:

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

If doesn't work try host: 127.0.0.1 如果不起作用,请尝试host: 127.0.0.1

Anyway I recommend to to use MySQL 5.5 and the mysql2 gem. 无论如何,我建议使用MySQL 5.5和mysql2 gem。 to install that gem have a look this link . 安装那个宝石看看这个链接

Or you can try BitMani Ruby Stack Installer for windows. 或者您可以尝试使用BitMani Ruby Stack Installer for windows。

Ruby Stack Installer Ruby Stack安装程序

BitMani wiki BitMani维基

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

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM