Cloud 9 / c9 - Rails unable to connect to mysql - mysql

I'm a beginner using the Lynda tutorial for Ruby on Rails, but trying to go through it on c9. I've just installed Rails and mysql, and when I try to run the rails server (rails s -b $IP -p $PORT), it produces errors when I go to https://my_rails_app-username.c9users.io/:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Looking at config/database.yml
development:
<<: *default
database: my_rails_app_development
This needs to be changed to
development:
adapter: mysql2
encoding: utf8
database: c9
username: <%=ENV['C9_USER']%>
host: <%=ENV['IP']%>
This gets your c9 username, and hostname (in this case 0.0.0.0) for you and inserts the values so you don't need to go figuring them out yourself. Now, when you restart the server, you get:
Can't connect to MySQL server on '0.0.0.0' (111)
Stop the server. Run: mysql-ctl start And now restart the server (rails s -b $IP -p $PORT)
If this still doesn't work, try: sudo service mysqld start or sudo service mysql start
Credit to:
Cloud 9 IDE can't connect to database
Mysql can't connect to local server through socket on Amazon EC2
https://docs.c9.io/docs/running-a-rails-app

I tried
mysql-ctl restart
on my terminal and it worked.

Related

Running MySQL and Webrick at the same time Windows 7

Hopefully this is a simple problem to fix
I have installed the Ruby installer for windows, installed mysql 5.5 and have configured mysql to listen on port 3000
When I run the mysql server and then try to run webrick with rails s i get the error message
Only one usage of each socket is normally permitted bind(2)
So both servers are trying to run off the same port? I cannot use them both at the same time, if i kill the processes on localhost:3000 then both services are reset
is there a way of configuring these to both work at the same time?
EDIT
My config/database.yml file
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: library_development
pool: 5
username: root
password:
host: localhost
port: 3000
Has anyone come across this before, very frustrating
Use the -p flag to specify that webrick bind to a different port. Something like
rails server -p 3001 # Assuming you are starting via command prompt
That should allow both services to run simultaneously.

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

Do I need MySQL installed locally as well?

I have 2 ubuntu 11.04 servers on IPs 192.168.9.14 and 192.168.9.15. On .14 I have installed ruby + rails and on .15 I have installed mysql and the database for my site resides on .15
I now want to get rails 2.3.8 to connect from .14 to the database on .15. I have the following in my database.yml on .14.
production:
adapter: mysql
encoding: utf8
reconnect: false
database: gtt_production
pool: 5
username: root
password: admin
host: 192.168.9.15
port: 3306
I'm currently getting an error showing up in my rails log as follows:
Can't connect to MySQL server on 192.168.9.15.
I originally thought this was due to user privileges on the mysql server but I have now added that in and still getting the same problem.
So I then tried connecting via a terminal (command line) as follows:
mysql -h 192.168.9.15 -uroot -p
and I got a message saying :
The program 'mysql' can be found in the following packages:
* mysql-client-cor-5.1
Try: sudo apt-get install <selected package>
...And that's what makes me think I need a local copy of mysql even though the database completely resides on another server.
Please can someone confirm whether my 'guess' is correct or whether there is some 'clever' way of connecting to the mysql server on .15 without also installing mysql on .14.
you need the client - sudo apt-get install mysql The server is usually mysql-server
Did you install the mysql gem for ruby? Rails will need this in order to connect to the DB. Also make sure .15 can accept remote requests from .14.
Have you configured your mysql db to listen to external IP traffic? I dont think MySQL by default allows external connections, only localhost traffic. Check your my.cnf.

Ruby on Rails 3 Can't connect to local MySQL server through socket '/tmp/mysql.sock' on OSX

I have a standard Rails3 environment, RVM 1.2.9, Rails 3.0.5, Ruby 1.9.2p180, MySQL2 Gem 0.2.7, mysql-5.5.10-osx10.6-x86_64
Error I get when running rake db:migrate to create database is:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
config/database.yml has
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
sure it's something simple I'm missing.
First, to find your socket file:
mysqladmin variables | grep socket
For me, this gives:
| socket | /tmp/mysql.sock |
Then, add a line to your config/database.yml:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /tmp/mysql.sock
Found it!
Change host: localhost in config/database.yml to host: 127.0.0.1 to make rails connect over TCP/IP instead of local socket.
development:
adapter: mysql2
host: 127.0.0.1
username: root
password: xxxx
database: xxxx
Your mysql server may not be running. Below explains how to start the server. This is an excerpt from the README file that comes with the mysql download.
After the installation, you can start up MySQL by running the following
commands in a terminal window. You must have administrator privileges
to perform this task.
If you have installed the Startup Item, use this command:
shell> sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
(ENTER YOUR PASSWORD, IF NECESSARY)
(PRESS CONTROL-D OR ENTER "EXIT" TO EXIT THE SHELL)
If you don't use the Startup Item, enter the following command sequence:
shell> cd /usr/local/mysql
shell> sudo ./bin/mysqld_safe
(ENTER YOUR PASSWORD, IF NECESSARY)
(PRESS CONTROL-Z)
shell> bg
(PRESS CONTROL-D OR ENTER "EXIT" TO EXIT THE SHELL)
These are options to fix this problem:
Option 1: change you host into 127.0.0.1
staging:
adapter: mysql2
host: 127.0.0.1
username: root
password: xxxx
database: xxxx
socket: your-location-socket
Option 2: It seems like you have 2 connections into you server MySql.
To find your socket file location do this:
mysqladmin variables | grep socket
for me gives:
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock' exists!
or
mysql --help
I get this error because I installed XAMPP in my OS X Version 10.9.5 for PHP application. Choose one of the default socket location here.
I choose for default rails apps:
socket: /tmp/mysql.sock
For my PHP apps, I install XAMPP so I set my socket here:
socket: /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
OTHERS Socket Location in OS X
For MAMPP:
socket: /Applications/MAMP/tmp/mysql/mysql.sock
For Package Installer from MySQL:
socket: /tmp/mysql.sock
For MySQL Bundled with Mac OS X Server:
socket: /var/mysql/mysql.sock
For Ubuntu:
socket: /var/run/mysqld/mysql.sock
Option 3: If all those setting doesn't work you can remove your socket location:
staging:
# socket: /var/run/mysqld/mysql.sock
I hope this help you.
"/tmp/mysql.sock" will be created automatically when you start the MySQL server. So remember to do that before starting the rails server.
With my installation of MAMP on OSX the MySQL socket is located at /Applications/MAMP/tmp/mysql/mysql.sock. I used locate mysql.sock to find my MySQL socket location.
So my config/database.yml looks like:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
socket: /Applications/MAMP/tmp/mysql/mysql.sock
If you are on Mac OSX,
The default location for the MySQL Unix socket is different on Mac OS X and Mac OS X Server depending on the installation type you chose
MySQL Unix Socket Locations on Mac OS X by Installation Type
Package Installer from MySQL ------------------/tmp/mysql.sock
Tarball from MySQL -------------------------------/tmp/mysql.sock
MySQL Bundled with Mac OS X Server -------/var/mysql/mysql.sock
So just change your database.yml in socket: /tmp/mysql.sock to point to the right place depending on what OS and installation type you are using
The default location for the MySQL socket on Mac OS X is /var/mysql/mysql.sock.
I have had the same problem, but none of the answers quite gave a step by step of what I needed to do. This error happens because your socket file has not been created yet. All you have to do is:
Start you mysql server, so your /tmp/mysql.sock is created, to do that you run: mysql server start
Once that is done, go to your app directory end edit the config/database.yml file and add/edit the socket: /tmp/mysql.sock entry
Run rake:dbmigrate once again and everything should workout fine
I found that the problem is that I only have a production environment. I do not have a development or test environment.
By adding 'RAILS_ENV=production' to give the command
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
it worked
If you are running MYSQL through XAMPP:
Open XAMPP mysql configuration file (on OSX):
/Applications/XAMPP/etc/my.cnf
Copy the socket path:
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
Open rails project's database configuration file:
myproject/config/database.yml
Add the socket config to the development database config:
-->
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: difiuri_falcioni
pool: 5
username: root
password:
host: localhost
socket: /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
Restart rails server
Enjoy :)
You have problem with like this: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'
Ans: $ sudo service mysql start
On my machine mysqld service stopped that's why it was giving me the same problem.
1:- Go to terminal and type
sudo service mysqld restart
This will restart the mysqld service and create a new sock file on the required location.
If you are running MYSQL through XAMPP or LAMPP on Ubuntu or other Linux, try:
socket: /opt/lampp/var/mysql/mysql.sock

Rails 3.o MYSQL connection problem

I have installed RVM in my ubunut linux box and configured the Rails 3 app in that ... i can able to start app server... my problem is when i invoke http://localhost:3000 . i getting the follwing error
Mysql::Error (Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)):
I checked mysqld service is running well.
I checked my database.yml file .... the defined well
development:
adapter: mysql
encoding: utf8
reconnect: false
database: test_development
username: root
password: admin
socket: /var/run/mysqld/mysqld.sock
my installed mysql gem version is 2.8.1.... I really don't know what is the problem here....
Your mysql server might be started, it seems the socket leading to it isn't available at the path you're providing to it (/var/run/mysqld/mysqld.sock).
You must change this socket path to the appropriate one in your machine.
The best way to find it is the following in a console : sudo find / -name mysqld.sock
Then you'll get the path and you'll just have to change it in your configuration file.