I am working on setting up a basic RoR app. All my databases are MySQL and local, my database,yml file is included. I am trying to access a basic view but am still getting the ActiveRecord::ConnectionNotEstablished error. What am I doing wrong?
# database.yml
development:
adapter: mysql2
encoding: utf8
database: *****_dev
username: ****
password: *****
host: 127.0.0.1
port: 3306
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
database: *****_test
username: ****
password: *****
host: 127.0.0.1
port: 3306
production:
adapter: mysql2
encoding: utf8
database: *****_prod
username: ****
password: *****
host: 127.0.0.1
port: 3306
MySQL2 in the gem file:
gem 'mysql2', '~>0.3.10'
So when go to type in: http://localhost:3000/controller/view I get: ActiveRecord::ConnectionNotEstablished
What else can I include that would be helpful?
Thanks in advance.
Have a look at your /etc/mysql/my.cnf and check for the binding address of the mysql deamon. It probably doesnt bind to any ip. Then it will use unix sockets which are by the way faster then ip connections,...
Option name for the bind address is bind-address if theres no match it wont bind to any address. Also have a look for socket which specifies the path to the unix socket. You can use the socket like this in your database.yml
development:
adapter: mysql2
encoding: utf8
database: *****_dev
username: ****
password: *****
socket: /path/to/the/socket/mysql.sock
That should do it for you,...
Related
I've been trying to get this figured out for two days now. Any help would be appreciated. I'm trying to just make a sample app using mysql, and rails. But, every time I try to rake db:migrate I get a no access error. I've checked my database.yml file 100 times, and everything looks right. Logging into mysql through the terminal with the exact same login credentials works fine. It seems like mysql is working for everything except for Rails.
default: &default
adapter: mysql2
encoding: utf8
host: localhost
port: 3306
database: my_ror
pool: 50
username: root
password: password
socket: /opt/lampp/var/mysql/mysql.sock
development:
adapter: mysql2
encoding: utf8
host: localhost
port: 3306
database: my_ror_development
pool: 50
username: root
password: password
socket: /opt/lampp/var/mysql/mysql.sock
What am I doing wrong?
I am new to the linux world and I do apologize if this has been asked before, I could not find the answer I need among the answers.
I am running rails 4.2.1 with mysql 5.5.43 with Passenger and Nginx reverse server installed.
I started having problems when I switched to production mode, first it was trying to go to localhost:3000 which is the loopback used for testing. So I started reading online but could not figure out the correct way to set up the config/database.yml to use the correct url for production. I tried and implement several online suggestions but none worked.
If someone could show me the correct way to configure rails to run mysql in development and production include any env variable that I should set. It would be greatly appreciated.
Paul
If you have multiple databases for testing and development, Then you can do something like this.
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: DBNAME
pool: 5
username: root
password: paswd
host: localhost
port: 3306
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: DBNAME
pool: 5
username: root
password: paswd
host: localhost
port: 3306
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: DBNAME
pool: 5
username: root
password: paswd
host: localhost
port: 3306
I have a problem connecting to DB from my rails app.
I have provided the database.yml file with credentials:
development: &development
adapter: mysql2
encoding: utf8
database: myapp_dev
pool: 5
username: root
password: passoword
test:
<<: *development
database: myapp_test
production:
<<: *development
database: myapp_prod
staging:
<<: *development
database: myapp_staging
But when I try run the app it gives me the following error:
Access denied for user 'root'#'localhost' (using password: NO)
using mysql -u root -p with same credentials I can access my db without issues. can someone tell me what could be a problem here?
EDIT:
I've changed the user from root to some other user but it still gives me the same error. so apparently it uses some other credentials to connect to db.
I ran into the same issue. It turns out it was a mistake in my database.yml file. Here is what my database.yml file looked like:
production:
adapter: mysql2
encoding: utf8
database: my_db
username: my_db_user
password: !strong_password
host: localhost
port: 3306
pool: 5
timeout: 5000
The ! character at the beginning of the password is not valid YAML markup (for at least what I was trying to achieve). Wrapping quotes ('') around the password fixes the issue. Here is the updated database.yml file:
production:
adapter: mysql2
encoding: utf8
database: my_db
username: my_db_user
password: '!strong_password'
host: localhost
port: 3306
pool: 5
timeout: 5000
Try the following code, if it works we can go forward
Comment all the previous code in database.yml and paste the following
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp_dev
pool: 5
username: root
password: passoword
host: localhost
im struggling to connect to my mysql service running on my local windows 7 machine- I am getting the following error when trying to rake migrations or access through the web browser-
Mysql2::Error (Can't connect to MySQL server on 'localhost' (10061)):
i have left the mysql user/pass as default - this is my yaml conf file
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
port: 3306
encoding: utf8
reconnect: false
database: events_development
pool: 5
username: root
password:
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: events_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: events_production
pool: 5
username: root
password:
host: localhost
the thing is i can login using root through mysql on the command line and also running phpmyadmin through xampp- so i have narrowed it down to a firewall issue? or permissions issues? everything is running localhost on my machine
update
i turned windows firewall off and it made no difference
Make sure you've granted localhost privileges. Info here.
i restarted the machine and restarted the servers- seemed to work
I'am a bit confused? Localost => Port (10061) ?
Maybe try to add port: 3306 everywhere.
Do you started the Server in dev env?
I'm creating my first ROR application.
Details:
creating new app ->
rails new simple_cms -d mysql
creating a controller and a corresponding view -->
rails generate controller demo index
Then when after i started the rails server, the http://localhost:3000 page works perfectly fine. but when i try to go to the page that I just created, http://localhost:3000/demo/index, it spurts out a MYSQL error:
Access denied for user 'root'#'localhost' (using password: NO)
At first, I think it's just a database connection problem, so I've gone through the MYSQL interface and create a new database called: simple_cms_development
and I have also made a corresponding user: simple_cms
with granted privileges.
and lastly, I have configured the database.yml file to fit the details:
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: simple_cms
password: developer
host: localhost
But still, it spits out the same mysql problem:
Access denied for user 'root'#'localhost' (using password: NO)
Please. to anyone who knows how to use mysql as a database for rails app..A help would be really appreciated. Thank you so much!
UPDATE: This is all what's inside on the database.yml file
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: root
password: developer
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_test
pool: 5
username: root
password:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_production
pool: 5
username: root
password:
host: localhost
I found that you need to add the following line to config/database.yml:
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
host: your_host # <----- normally localhost
database: the_db_I_made
pool: 5
username: the_user_I_made
password: the_password
socket: /var/lib/mysql/mysql.sock
Only reason that can cause your issue is that you are loading your server with different environment. I think that in your case you are loading your server under production mode.