简体   繁体   English

如何将ruby连接到mysql?

[英]How do I connect ruby to mysql?

So, I'm new in MacOs and in Ruby. 因此,我是MacO和Ruby的新手。 I was playing a bit with Ruby on terminal, all went fine so far. 我在终端上玩了Ruby,到目前为止一切正常。 Then I downloaded and installed the rails framework. 然后,我下载并安装了Rails框架。 All went fine! 一切都很好! But when I start the server 但是当我启动服务器时

rails server

and just after refreshing the "welcome aboard site" I get this error in terminal: 在刷新“欢迎使用网站”后,我在终端中收到此错误:

Mysql2::Error (Access denied for user 'root'@'localhost' (using password: NO)):
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `connect'
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `initialize'

There are more lines of errors, but I'm sure they are all related with couldn't find and/or couldn't connect to mySql. 有更多的错误行,但是我确定它们都与找不到和/或无法连接到mySql有关。 I have had installed the mySql server before installing rails to use it with Apache/PHP. 我已经安装了mySql服务器,然后再安装Rails使其与Apache / PHP一起使用。 So I think there must be somewhere a file to say rails where the server is or maybe tell rails user/password? 所以我认为必须在某个地方说出Rails服务器所在的位置,或者告诉Rails用户/密码?

I was looking for a solution on Google but I just got results of people having troubles because of different things. 我当时一直在寻找Google的解决方案,但是我得到的结果是人们因事情不同而遇到麻烦。

Please specify mysql username and password in config/database.yml file 请在config / database.yml文件中指定mysql用户名和密码

for eg, for development environment: 用于例如开发环境:

development:
  adapter: mysql2
  encoding: utf8
  database: < your database name>
  username: <your usename>
  password: <your password>   

You can add more properties if you want, i've showed here only required fields. 您可以根据需要添加更多属性,此处仅显示必填字段。

Thanks 谢谢

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

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