Cannot connect to MySQL server on "127.0.0.1".

I am trying to clone a repo and run it on my local machine. I do not have a database created, and I'm trying to manually create the database.yml file (my first time doing it). I’m not quite sure what I’m doing, and I continue to receive errors about connecting to the MySql server. Here is my database.yml file:

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 db by doing "bundle exec rake db: create" ... I get this error:

 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 that I am doing something wrong, but I cannot understand what it is. Do I need to start mysql server or something else?

This is the result when I run 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 
+4
source share
5 answers

Try:

 development: adapter: mysql database: app_development username: root password: socket: /var/lib/mysql/mysql.sock 

Then make 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.

Update: Matthew first needs to install mySQL on his machine (Mac).
I directed it to http://dev.mysql.com/downloads/mysql/

+3
source

Explicitly mention your port: 3306 in your .yml database

If this does not work, then

 netstat -tupln 

and check if MySQL is listening on port 3306 or not

+1
source

First of all, try the following to check if you have a mysql connection from the command line (without Ruby on Rails).

 mysql -u root 

If you can’t connect, you have probably provided a password. You need to either remember it or reinstall MySQL. If you can, then create your database:

 create database app_development; 

Last but not least, remove the 'db /' prefix from database.yml. You do not need the full path:

 database: app_development 

Hope this helps!

0
source

If you don't mind which database software you use (I don’t think you indicated if you need MySQL or just want the repo to work), you can try using SQLite3 instead. SQLite3 does not start the server or does not use ports, so it may be easier for you to configure it.

Try to emulate the default bas.yml database, which looks like this:

 # 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 the gem 'sqlite3' to your Gemfile and run bundle install

Hope this helps!

0
source

It can also be solved by changing the version of MySQL. Had the same problem with some project that was developed using MySQL 5.5 , but the installed version in my mac was MySQL 5.7, so I had to downgrade my version and it worked for me.

0
source

Source: https://habr.com/ru/post/1390574/


All Articles