Ruby on Rails - unable to open mySQL command line - mysql

I am able to open the mySQL command line doing the following steps:
depot>mysql -u root
mysql>CREATE DATABASE depot_production DEFAULT CHARACTER SET utf8;
mysql>GRANT ALL PRIVILEGES ON depot_production.* TO 'gotqn' IDENTIFIED BY 'mypass';
mysql>EXIT;
then changing my config/database.yml
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_production
pool: 5
username: gotqn
password: mypass
host: localhost
and final typing:
gotqn:~/Aptana Projects/depot$mysql depot_production
gives me:
ERROR 1045 (28000): Access denied for user 'gotqn'#'localhost' (using
password: NO)
I've supposed that I should specified a password but typing:
gotqn:~/Aptana Projects/depot$mysql depot_production mypass
just shows me the some variables information.
I am using:
Rails 3.2.8
mysql Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (x86_64) using
readline 6.2
Ubuntu LTS 12.04

Configuration file config/database.yml is for Ruby, not for mysql command line tool. For command line tool use correct syntax:
mysql --user=user_name --password=your_password db_name
by default it uses your current logged in user if --user=user_name is omited.

In database.yml use username as root:
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: depot_production
pool: 5
username: root
password:
host: localhost

Create the user in mysql as #'localhost'
mysql>GRANT ALL PRIVILEGES ON depot_production.* TO 'gotqn'#'localhost' IDENTIFIED BY 'mypass';

Related

How to enable passwordless access to Mysql for Rails?

I have this database config which connects to MySQL database using root without the password. How do I configure MySQL so that all database operations coming from my app will work?
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: myapp
pool: 25
username: root
password:
host: 127.0.0.1
strict: false
possible solution
Answer to this question by chaintng
https://serverfault.com/questions/563714/allow-linux-root-user-mysql-root-access-without-password
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
along with .my.cnf configuration
$ cat ~/.my.cnf
[client]
user=root
password=''
It seems to work, but I am not sure if it is a correct solution.

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'.

Changing the default database for Rails to MySQL

Im trying to use MySQL as a database for an application to which I updated the default database.yml file to
development:
adapter: mysql
encoding: utf8
reconnect: false
database: ***_development
pool: 5
username: root
password: ******
host: localhost
test:
adapter: mysql
encoding: utf8
reconnect: false
database: ***_test
pool: 5
username: root
password: ******
host: localhost
production:
adapter: mysql
encoding: utf8
reconnect: false
database: ***_production
pool: 5
username: root
password: ******
host: localhost
`
But I dont see any .sql file being generated after trying to create tables from the console. Im a noob in Ruby on rails any help would be appreciated. Thank you.
It won't be in your rails directory. You need MySQL installed on your computer and you need to create the databases in mysql.
Install mysql: http://dev.mysql.com/doc/refman/5.1/en/installing.html
To access mysql through the command line:
$ mysql
or if you have a mysql root user:
$ mysql -u root -p
And enter your root mysql user password. Once you are in mysql:
mysql> CREATE DATABASE db_name;
mysql> GRANT ALL PRIVILEGES ON db_name.*
mysql> TO 'username'#'localhost'
mysql> IDENTIFIED BY 'password';
Obviously replace db_name, username and password accordingly.

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