Cannot connect to mysql server Error: mysqld.sock' (38) - mysql

Hi I am working on ruby on rails project. after setting up all environment for the project but when I run localhost:3000 on my web browser it gives my this error
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (38)
Can someone help me how can I solve this problem?

Check if mysql is running
mysqladmin -u root -p status

Rails by default tries to connect to MySQL using a socket file. You probably want it to connect using a TCP connection.
Check your database.yml; it should look similar to this:
development:
adapter: mysql2
encoding: utf8
reconnect: true
host: localhost
database: {database name}
pool: 5
username: {username}
password: {password}
Notice the host parameter and the missing socket parameter.

Related

In Rails 6, how do I add "protocol" into my db configs?

I have my MySql 5.7 db running on a virtual server, whose port 3306 is forwarded to my local . I can connect using this
> mysql -h localhost --protocol=tcp -u mouser mydb_test -p
Which would fail if the params “--protocol=tcp” weren’t present. As such, I’m trying to figure out how to add “protocol” into my database.yml config for Rails 6. I discovered the below is not the way to do it
test:
adapter: mysql2
encoding: utf8
host: localhost
database: mydb_test
pool: 5
username: mouser
password: mypass
protocol: tcp
variables:
sql_mode: NO_ENGINE_SUBSTITUTION
Since I get connection errors when attempting to connect to the db.

Ruby on Rails - Mysql2::Error: Can't connect to MySQL server on 'localhost' (10061)

Hey I'm just getting started with Ruby on Rails and need some help. I installed Ruby on Rails and then created a project with MySQL but I am unable to connect to the MySQL server to create a database. Side note I am using Windows 10.
After running the command (rake db:create) I get this error.
#<Mysql2::Error: Can't connect to MySQL server on 'localhost' (10061)>
Here is my database.yml file
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: 1234
host: localhost
Assuming you're running Linux, try the following command to see if MySQL is running:
/etc/init.d/mysql status
Make sure you're specifying a database name to connect to as well, but that would likely give you a different error code than the one you're seeing.

Can't connect to local MySQL server through socket: I'm lost [Rails App]

I am currently trying to deploy my Rails 4 app to AWS, but each time I try to view the app on AWS, I get an application error. I check the logs and see:
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
I've been reading several things, such as: this, but I haven't had any luck trying these various solutions and I'm driving myself crazy.
The app runs fine locally.
Here are some details:
I have Mysql and Mysql server installed
The service is running (again everything works as expected locally)
Here is the [client] portion of my.cnf, which is located at /etc/mysql/
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
I see some suggestions talking about mysqld, others mysql - I don't understand the difference.
Database.yml
development:
adapter: mysql2
encoding: utf8
database: wp_development
pool: 5
username: root
password: **Left out
host: localhost
I just downloaded MySql today, so I am on 5.5, the latest build. *I'm running Linux.
Can someone please point me toward a solution?
Thanks!
If you want to connect locally, you should add socket: /var/run/mysqld/mysqld.sock inside the development config in your database.yml.
Also, make sure your RAILS_ENV is correct when running your app on AWS. If it is not set, then it should be development. But I'm not sure how you are starting your app.
The reason could be the specified socket path in your Gemfile might be wrong.
First, to find your socket file:
mysqladmin variables | grep socket
For me, this gives:
| socket /var/run/mysqld/mysqld.sock
Then, add this line /var/run/mysqld/mysqld.sock to your config/database.yml in the socket field. See the below examples
Example: socket: /var/run/mysqld/mysqld.sock
Development Mode
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock # this line
Production Mode
production:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock # this line
Test Mode
test:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /var/run/mysqld/mysqld.sock # this line

`connect': Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) (Mysql2::Error)

When I tried to run rails s on remote server I got this issue.
Mysql working fine with "rails db"
Find your socket file using
mysqladmin variables | grep socket
And then add the socket file to your database.yml configuration
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: <socket location>
Is the MySQL login/pass fine and is the mysql server running?

Rails: Can't connect to local MySQL server through socket

I run Ubuntu using VirtualBox on Windows 7.
When I launch "localhost:3000" (after I ran rails s), I got the following error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
I installed XAMPP on Ubuntu, so my MySQL installation seems to be here: /opt/lampp/var/mysql
(mysql.sock is there)
How should I connect my rails application to this MySQL installation ?
try the socket param in your database.yml (it defaults to /tmp/mysql.sock I think)
development:
adapter: mysql
encoding: utf8
database: yourapp_development
username: youruser
password: yourpassword
socket: /opt/lampp/var/mysql/mysql.sock