How to connect Rails with MySQL? [duplicate] - mysql

This question already has answers here:
"Access Denied" when rails connects to Mysql
(3 answers)
Closed 8 years ago.
I have the following running correctly:
rails new simple
rails server (working)
rails generate controller demo index
mysql -u root -p and creating the database and assigning GRANT PRIVILIGES on the database is done.
Now the problem is, I used the Bitnami-RubyStack packages on my MAC 10.7. When I want to run rake db:schema:dump, I get this error:
bash-3.2$ rake db:schema:dump
rake aborted!
Access denied for user 'root'#'localhost' (using password: YES)
/Applications/rubystack-1.9.3-18/simple/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:schema:dump => environment
(See full trace by running task with --trace)
even if I run GRANT PRIVILEGES.
Also I checked the username and password on my DB.yml:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_development
pool: 5
username: root
password: something
socket: /tmp/mysql.sock
host: 127.0.0.1

In your database config
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_development
pool: 5
username: root
password: something
socket: /tmp/mysql.sock
host: 127.0.0.1
you should use either socket or host, not both. Since socket works for you (mysql -u root -p works), try using it with your app. If there's any permission problems or whatnot, you are going to have to create root#127.0.0.1 in your mysql console and use the host parameter.

Related

Ruby on rails - Mysql2::Error Access denied for user 'simple_cms'#'localhost' (using password: YES)

I am working through a RoR tutorial from lynda.com
for a week already & without changing anything today i was not able to see my content on localhost due to this error :
Mysql2::Error Access denied for user 'simple_cms'#'localhost' (using password: YES)
I do know that this problem has been referred many times befored , i am still not able to find a confirmed solution .
To give you further information regarding my set up my working enviroment is Yosemite 10.10.4 - Rails 3.2.22 - 5.6.22 MySQL - WEBrick 1.3.1
i have set up the SQL database as it looks below on the database.yml file on the config folder of the project
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_development
pool: 5
username: simple_cms
password: **********
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_test
pool: 5
username: root
password:
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: simple_cms_production
pool: 5
username: root
password:
socket: /tmp/mysql.sock
Also i noticed that by trying to connect via terminal on the database with the password
ยง mysql -u root -p
and again i get the error ::ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES).
I tried to restart manually MySQL server from menu & all i got was the same error!
What is the problem and it doesn't let me log in with the settings as i did all this time ?
Is it a problem with rails or with mysql settings?
While everything seems to be as it has to be,do i have to change something on the database.yml file?
The error-message
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES).
will Show up if you entered a wrong password. Reset your Password according to this link.
I finally solved this problem by uninstalling the current MySQL via terminal with the command brew uninstall MySQL & then reinstalling it with brew, from the beginning!
After the installation, when i tried to login into MySQL i did it through the command :mysql -u root -p! At this point on the password request i added the one that has been set up before on the config file :database.yml and it logged in succesfully!
Thanks for the help!
You need to do 3 things :
Check if Mysql Server is On(or Started)
Change the password logging in mysql from terminal.
Create a database in your project folder using:
$ rake db:create
and that should do it for you so it did for me.

ERROR 1045 (28000): Access denied for user '<username>'#'localhost' (using password: YES)

I realize there are other similar questions, however I haven't found one that is exactly what I'm having. My issue is that I'm trying to access the Rails dbconsole but it's using the wrong user.
To explain, here's my database.yml:
development:
adapter: mysql2
host: localhost
database: db/development.mysql2
user: root
password: password
pool: 5
timeout: 5000
# 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
database: db/test.mysql2
host: localhost
user: root
password: password
pool: 5
timeout: 5000
production:
adapter: mysql2
database: db/production.mysql2
host: localhost
user: root
password: password
pool: 5
timeout: 5000
When I try and access the console by typing rails dbconsole, this is the result:
$ rails dbconsole
Enter password:
ERROR 1045 (28000): Access denied for user 'marshallsherman'#'localhost' (using password: YES)
I can log in to mysql by typing $ mysql -uroot -ppassword AND by typing $ mysql -umarshallsherman -ppassword. But when I try and log into the $ rails dbconsole it defaults to the "marashallsherman" user, and this is incorrect.
This seems like such a stupid question, however, I don't know how to change the "default" user for the dbconsole so that I can log in with the info that's in my database.yml file.
Help? I'm on Mac OS X 10.9.2
EDIT: I managed to get it so that I can log into the $ rails dbconsole, however, it's still logging me in as 'marshallsherman'#'localhost' -- I can't figure out how to switch it to log me in as 'root'#'localhost'.

rake db:multi:migrate DATABASE=configuration error with JRuby, mysql, riak

JRuby 1.7.1 and Rails 3.2.11
In terminal I'm running "rake db:multi:migrate DATABASE=configuration" but I keep getting the error below meaning as far as I can tell that the configuration database is not being created.
Connecting to database specified by database.yml
(4.0ms) SET SQL_AUTO_IS_NULL=0
rake aborted!
The driver encountered an unknown error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'configuration'
The specific steps I'm supposed to follow to get this set up are:
mysql.server start
mysql -uroot
create user 'funapp_test'#'localhost' IDENTIFIED BY 'funapp_test';
grant all privileges on *.* to 'funapp_test'#'localhost' with grant option;
create user 'funapp'#'localhost' IDENTIFIED BY '#sh4r3!';
grant all privileges on *.* to 'funapp'#'localhost' with grant option;
RAILS_ENV=test rake db:create
RAILS_ENV=development rake db:create
mysql -uroot funapp_test < db/structure.sql
mysql -uroot funapp < db/structure.sql
rake db:multi:migrate DATABASE=funapp
rake db:multi:migrate DATABASE=configuration
database.yml
development:
adapter: mysql
database: funapp
username: funapp
password: "#sh4r3!"
host: 127.0.0.1
pool: 5
xa: false
test: &test
adapter: mysql
database: funapp_test
username: funapp_test
password: "funapp_test"
host: 127.0.0.1
pool: 5
xa: false
configuration_development:
adapter: mysql
database: configuration
username: funapp
password: "#sh4r3!"
host: 127.0.0.1
pool: 5
xa: false
configuration_test:
adapter: mysql
database: configuration_test
username: funapp_test
password: "funapp_test"
host: 127.0.0.1
pool: 5
xa: false
Any ideas on what I can do to get this fixed? I've tried doing rake db:drop and rake db:migrate, as well as rake db:create:all (which gives me a Riak::Node configuration must include :source and :root keys. error) Thank you so much!
Figured it out, much simpler than I thought
mysql -uroot
create database configuration;
create database configuration_test;

Rails Project Connection error with MySQL DB - Access Denied for root user

I get this error when running rails with mysql db. Basically it is not giving the root user access. I have no idea why this is and have been stuck with this for a while now.
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: YES)):
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack- 3.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (5.7ms)
Rendered /Users/USER/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (17.7ms)
My Database.yml file is posted below for your reference. Im not sure how i check the password that MYSQL is automatically assigned to? Would it be my computer login password? Anyhow how do i check it. Also i cant simply type mysql on my command line i have to enter the entire path to access it. How do i change it. Most importantly i want to know how this access denied issue can be resolved. Thank you. Using mysql 5.5 on mac. x86_64 build.
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: 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: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: project1_db
pool: 5
user : root
username: root
password: password
host: localhost
Mysql uses the one that you've set on install. Sometimes it's empty.
Try mysql -u root. If it works - remove pass string form database yaml.
If it's not empty - https://stackoverflow.com/search?q=mysql+reset+password

Redmine installation issues rake command issue, MySQL database issue?

I have somewhat of a complex issue involving several different programs including redmine, MySQL, Ruby, Ruby on Rails etc. This is on Windows XP.
I am following the redmine instructions here: http://www.redmine.org/projects/redmine/wiki/RedmineInstall
I am on step 5. where I am suppose to type RAILS_ENV=production rake db:migrate
When I type this in the command prompt and hit enter I get an error: "RAILS_ENV" is not a command blah blah.
So I reorder it to: rake db:migrate RAILS_ENV=production
This seems to work correct, but I get the following:
C:\redmine-1.2.1>rake db:migrate RAILS_ENV=production --trace
* Invoke db:migrate (first_time)
* Invoke environment (first_time)
* Execute environment
rake aborted!
Access denied for user 'redmine'#'localhost' (using password: YES)
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:620:in `real_connect'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:620:in `connect'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:203:in `initialize'
C:/redmine-1.2.1/vendor/rails/activerecord/lib/active_record/connection_adapters
/mysql_adapter.rb:75:in `new'
Here is my database.yml file contents:
MySQL (default setup).
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: ****
encoding: utf8
development:
adapter: mysql
database: redmine_development
host: localhost
username: root
password:
encoding: utf8
# 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: mysql
database: redmine_test
host: localhost
username: root
password:
encoding: utf8
test_pgsql:
adapter: postgresql
database: redmine_test
host: localhost
username: postgres
password: "postgres"
test_sqlite3:
adapter: sqlite3
database: db/test.sqlite3
I really need some direction here. It's almost like there is a problem with my users/passwords. I have changed the passwords not to contain "!" or any other special characters. I do have capital and lower case letters.
Any help would be greatly appreciated.
DemiSheep
So, you have created the 'redmine' mysql user with the password specified in database.yml?
Can you connect to this user using mysql client? (e.g. mysql -uredmine -pyourmysqlpassword)
Does the user have all required privileges?