I am totally new to ruby on rails, trying to set up a project with connection to mysql.
In mysql i've created databases, granted privileges to user like this:
GRANT ALL PRIVILEGES ON testdb_development.* TO 'rails_user'#'localhost' IDENTIFIED BY 'test';
In the database.yml file i've configured:
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: rails_user
password: test
host: localhost
I am trying to test the connection with schema dump
rails db:schema:dump
Bizarrely, the access denied message is giving me a weird localhost IP (172.20.0.1), i'm not sure if this is why its failing, but unsure how to resolve from there?
rails aborted!
Mysql2::Error: Access denied for user 'rails_user'#'172.20.0.1' (using password: YES)
Tried setting password like this also, to no avail - I cannot even login using this rails_user at all with access denied error
SET PASSWORD FOR 'rails_user'#'localhost' = PASSWORD('test');
Related
I get the following error when I run 'rails db:schema:dump' after initially configuring my Ruby on Rails project and checking the schema set-up for my Mysql database, which should be empty in terms of data so far the tables I've created:
Mysql2::Error::ConnectionError: Access denied for user 'rails_user'#'localhost' (using password: YES)
I enter mysql -u root -p in the command line and create the following databases:
CREATE DATABASE simple_ex_development;
CREATE DATABASE simple_ex_test;
Now instead of using root user to connect to my newly created databases (which isn't an optimal security practice), I define a new user that the rails application can use to connect to them called 'rails_user' as follows:
GRANT ALL PRIVILEGES simple_ex_development.* TO 'rails_user'#'localhost' IDENTIFIED BY 'blahpassword'
GRANT ALL PRIVILEGES simple_ex_test.* TO 'rails_user'#'localhost' IDENTIFIED BY 'blahpassword'
Then I exit mysql and go to my rails application config/database.yml file and update the username and password, respectively:
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: rails_user
password: blahpassword
host: localhost
Then when I go back to the terminal and run 'rails db:schema:dump' I get the following error above, when I'm not expecting to get anything at all. I've read other stackoverflow posts here touching on similar issues and hinting that it might be anonymous user.
Why am I getting this error message and how can I resolve it?
Any pointers here would be great, thank you!
P.S. When I do run rails server I can see the web app on localhost but again, I'm not sure if it's being configured properly to the new user and password versus root and my root password.
Try creating the user before granting privileges:
CREATE USER 'rails_user'#'localhost' IDENTIFIED BY 'blahblahpassword';
And then grant the privileges the same way:
GRANT ALL PRIVILEGES ON simple_ex_development.* TO 'rails_user'#'localhost' IDENTIFIED BY 'blahpassword';
GRANT ALL PRIVILEGES ON simple_ex_test.* TO 'rails_user'#'localhost' IDENTIFIED BY 'blahpassword';
I can't get access to my recently created database. I have tried repeatedly to flush privileges but am unable to reset the password to gain access.
I get the following error when trying to access it on the command line after typing mysql -u rails_user -p then entering what I believe should be the correct password:
ERROR 1045 (28000): Access denied for user 'rails_user'#'localhost'
(using password: YES)
Here's my database.yml:
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: rails_user
password: examplepassword
host: localhost
development:
<<: *default
database: simple_cms_development
Also, when I enter: grant all on simple_cms_development.* to 'rails_user'#'localhost' identified by 'examplepassword'; on the command line I get the following error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'identified by 'examplepassword'' at line 1
I've read other examples somewhat similar to my own here on stackoverflow but the solutions do not work to successfully configure and connect my database to my rails app. Any pointers would be greatly appreciated!
If you forget your password for mysql or getting access denied while doing mysql -u UserName -p
then you can open mysql by skipping authorization and then change the password.
See Here
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.
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'.
I am using mySQL and Rails 3.2 and I run into this problem: The error code is: "rake aborted! Access denied for user 'root'#'localhost' (using password: NO)"
I am particularly sure that my database.yml is configured correctly, as follow:
development:
adapter: mysql2
encoding: utf8
database: simple_cms_development
pool: 5
username: simple_cms
password: my_actual_password
socket: /tmp/mysql.sock
I am very confused as the error said access denied for user 'root'#'localhost'. Now I cannot run any command like rake, rake db:migrate.
I've gone through other similar questions on Stackoverflow like (Why my rake db:migrate throws error message?) but the answer does not solve my problem.