I am trying to clone a repo and run it on my local machine. I don't have a DB created and I am trying to manually create my database.yml file (my first time doing this). I am not quite sure what i'm doing and keep getting errors about connecting to the MySql server. Here's my database.yml file:
我正在尝试克隆一个repo并在我的本地机器上运行它。我没有创建数据库,我正在尝试手动创建我的database.yml文件(我第一次这样做)。我不太清楚我在做什么,并继续得到有关连接到MySql服务器的错误。这是我的database.yml文件:
development:
adapter: mysql
host: 127.0.0.1
database: db/app_development
username: root
password:
I also tried localhost instead of 127.0.0.1, both give me errors when trying to create the db by doing 'bundle exec rake db:create' ...i get this error:
我也试过localhost而不是127.0.0.1,在尝试通过执行'bundle exec rake db:create'来创建数据库时都给我错误...我收到此错误:
Can't connect to MySQL server on '127.0.0.1' (61)
Couldn't create database for {"username"=>"root", "adapter"=>"mysql", "database"=>"db/app_development", "host"=>"127.0.0.1", "password"=>nil}, charset: utf8, collation: utf8_unicode_ci
I know i'm doing something wrong but I can't quite figure out what it is. Do I need to start the mysql server or something?
我知道我做错了什么但我无法弄清楚它是什么。我需要启动mysql服务器吗?
This is the output when I run mysqld_safe:
这是我运行mysqld_safe时的输出:
120111 20:35:39 mysqld_safe Logging to '/usr/local/var/mysql/Matthew-Bermans-MacBook-Air.local.err'.
120111 20:35:39 mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
120111 20:35:41 mysqld_safe mysqld from pid file /usr/local/var/mysql/Matthew-Bermans-MacBook-Air.local.pid ended
5 个解决方案
#1
3
Try:
development:
adapter: mysql
database: app_development
username: root
password:
socket: /var/lib/mysql/mysql.sock
Then do your rake db:create
to create it from rails.
or
in mysql do create database db_name
and then the above code for :development
will let you use it.
然后做你的rake db:create从rails创建它。或者在mysql中创建数据库db_name然后上面的代码:开发将让你使用它。
Update: Matthew first needs to get mySQL installed on his (Mac) machine.
I directed him to http://dev.mysql.com/downloads/mysql/
更新:Matthew首先需要在他的(Mac)机器上安装mySQL。我指示他到http://dev.mysql.com/downloads/mysql/
#2
1
Explicitly mention your port: 3306
in your database.yml
在您的database.yml中明确提及您的端口:3306
If that doesn't work then executed
如果那不起作用则执行
netstat -tupln
and check if MySQL is listening to port 3306
or not
并检查MySQL是否正在侦听端口3306
#3
0
First of all, try executing the following to check if you have a connection to mysql from command prompt (without Ruby on Rails).
首先,尝试执行以下操作以检查是否从命令提示符(没有Ruby on Rails)连接到mysql。
mysql -u root
If cannot connect you probably specified and password. You will need to either remember it or reinstall MySQL. If you can, then create your database:
如果无法连接你可能指定和密码。您需要记住它或重新安装MySQL。如果可以,那么创建您的数据库:
create database app_development;
Last but no the least, remove prefix 'db/' from database.yml. You don't need a full path:
最后但并非最不重要,从database.yml中删除前缀'db /'。您不需要完整路径:
database: app_development
Hope that helps!
希望有所帮助!
#4
0
If you don't mind what database software you use (I don't think you specified whether you needed MySQL or just wanted to get the repo to work), you might try using SQLite3 instead. SQLite3 doesn't run a server or use ports, so it might be easier for you to get setup.
如果你不介意你使用什么数据库软件(我不认为你指定你是否需要MySQL或只是想让repo工作),你可能会尝试使用SQLite3。 SQLite3不运行服务器或使用端口,因此您可能更容易进行设置。
Try imitating the rails default database.yml, which looks like:
尝试模仿rails默认的database.yml,它看起来像:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
Then add gem 'sqlite3'
to your Gemfile and run bundle install
然后将gem'sqlite3'添加到您的Gemfile并运行bundle install
Hope this helps!
希望这可以帮助!
#5
0
It can also be solved by changing MySQL version. Had the same issue with some project which was developed using MySQL 5.5 but installed version in my mac was MySQL 5.7 so I had to downgrade my version and it worked for me.
它也可以通过更改MySQL版本来解决。有一些项目使用MySQL 5.5开发但在我的mac中安装的版本是MySQL 5.7,所以我不得不降级我的版本,它对我有用。
#1
3
Try:
development:
adapter: mysql
database: app_development
username: root
password:
socket: /var/lib/mysql/mysql.sock
Then do your rake db:create
to create it from rails.
or
in mysql do create database db_name
and then the above code for :development
will let you use it.
然后做你的rake db:create从rails创建它。或者在mysql中创建数据库db_name然后上面的代码:开发将让你使用它。
Update: Matthew first needs to get mySQL installed on his (Mac) machine.
I directed him to http://dev.mysql.com/downloads/mysql/
更新:Matthew首先需要在他的(Mac)机器上安装mySQL。我指示他到http://dev.mysql.com/downloads/mysql/
#2
1
Explicitly mention your port: 3306
in your database.yml
在您的database.yml中明确提及您的端口:3306
If that doesn't work then executed
如果那不起作用则执行
netstat -tupln
and check if MySQL is listening to port 3306
or not
并检查MySQL是否正在侦听端口3306
#3
0
First of all, try executing the following to check if you have a connection to mysql from command prompt (without Ruby on Rails).
首先,尝试执行以下操作以检查是否从命令提示符(没有Ruby on Rails)连接到mysql。
mysql -u root
If cannot connect you probably specified and password. You will need to either remember it or reinstall MySQL. If you can, then create your database:
如果无法连接你可能指定和密码。您需要记住它或重新安装MySQL。如果可以,那么创建您的数据库:
create database app_development;
Last but no the least, remove prefix 'db/' from database.yml. You don't need a full path:
最后但并非最不重要,从database.yml中删除前缀'db /'。您不需要完整路径:
database: app_development
Hope that helps!
希望有所帮助!
#4
0
If you don't mind what database software you use (I don't think you specified whether you needed MySQL or just wanted to get the repo to work), you might try using SQLite3 instead. SQLite3 doesn't run a server or use ports, so it might be easier for you to get setup.
如果你不介意你使用什么数据库软件(我不认为你指定你是否需要MySQL或只是想让repo工作),你可能会尝试使用SQLite3。 SQLite3不运行服务器或使用端口,因此您可能更容易进行设置。
Try imitating the rails default database.yml, which looks like:
尝试模仿rails默认的database.yml,它看起来像:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
Then add gem 'sqlite3'
to your Gemfile and run bundle install
然后将gem'sqlite3'添加到您的Gemfile并运行bundle install
Hope this helps!
希望这可以帮助!
#5
0
It can also be solved by changing MySQL version. Had the same issue with some project which was developed using MySQL 5.5 but installed version in my mac was MySQL 5.7 so I had to downgrade my version and it worked for me.
它也可以通过更改MySQL版本来解决。有一些项目使用MySQL 5.5开发但在我的mac中安装的版本是MySQL 5.7,所以我不得不降级我的版本,它对我有用。