Running MySQL and Webrick at the same time Windows 7 - mysql

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.

Related

Cloud 9 / c9 - Rails unable to connect to 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.

Rails Can't connect to MySQL server on 'localhost'

I'm having no end of trouble with my Rails 3 app's Mysql connection, though I have studied countless relevant threads. My error message:
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32/lib/mysql2/client.rb:44:in `connect': Can't connect to MySQL server on 'localhost' (10061) (Mysql2::Error)
(Before you flag this as a duplicate question, consider whether you can find another thread with pertinent advice I have not followed.)
My efforts thus far:
I have copied the libmysql.dll file from <mysql installation>/bin to <ruby installation>/bin.
I have the mysql2 gem in the bundle, and it was installed with the connector (--with-mysql-dir=C:/mysql-connector-c-noinstall-6.0.2-win32):
> bundle show mysql2
C:/Ruby193/lib/ruby/gems/1.9.1/gems/mysql2-0.3.11-x86-mingw32
I believe my database.yml file is configured correctly:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: tq_development
pool: 5
username: root
password: pinney
host: localhost
try replacing localhost with 127.0.0.1 (in workbench and yml)
Have you ran rake db:create yet on the project in question?
I agree with the above....Make sure it works with workbench or some other GUI tool and you can connect using the info the database.yml file.
If not....come back and give us another holler.

Can't connect to MySQL server on '127.0.0.1'

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:
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:
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?
This is the output 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
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.
Update: Matthew first needs to get mySQL installed on his (Mac) machine.
I directed him to http://dev.mysql.com/downloads/mysql/
Explicitly mention your port: 3306 in your database.yml
If that doesn't work then executed
netstat -tupln
and check if MySQL is listening to port 3306 or not
First of all, try executing the following to check if you have a connection to mysql from command prompt (without Ruby on Rails).
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:
create database app_development;
Last but no the least, remove prefix 'db/' from database.yml. You don't need a full path:
database: app_development
Hope that helps!
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.
Try imitating the rails default database.yml, which looks like:
# 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
Hope this helps!
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.

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.

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.