MySql Error 1045 after I did rake db:create - mysql

I created a new Rails project, I used scaffold and then tried to:
rake db:create
I didn't changed config/database.yml so password was empty (I always enter the password I use to log in to localhost/phpmyadmin but this time I forgot it).
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: test_associations_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock
So, back to terminal I had the following message:
$ rake db:create
Access denied for user 'root'#'localhost' (using password: NO).
Please provide the root password for your mysql installation
>******* (I entered my password here)
$ rake db:create rake aborted!
(<unknown>): couldn't parse YAML at line 31 column 2
Tasks: TOP => db:create => db:load_config
(See full trace by running task with --trace)
After this, I cannot login to phpmyadmin and when I run my apps locally I'm getting this error:
Mysql2::Error
Access denied for user 'root'#'localhost' (using password: YES)
I'm using OS X 10.7.2, Rails 3.2, Ruby 1.9.3.
Any ideas?

You might try and access MySQL using the Terminal.app. At the command line run:
mysql -u root
if you expect the root password to be blank and yet see this:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
You know the password has been changed.
Sounds like the root password has been changed. If you do not know what it is, follow these instructions to reset the password:Resetting MySQL password.

This answer is in connection with Ruby on Rails framework where this behavior occurred
have mysql with user root and password
bootstrap new rails project
using with mysql "rails new projectname
-d mysql"
do not modify config/database.yml - defaults credentials for server are name: root, password is blank
rake db:create prompt show up - asking for root password and then when you provide root password
the answer is in GRANT command on line 68 in here
basically it executed GRANT command with credentials matches your current database.yml
I have discussed this topic and behavior will improved and it is taken and reported as a bug.

Related

Rails database issue - ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)

I have looked through a lot of similar solutions but have been unable to resolve my issue so hopefully someone can help.
I have joined a Rails project and need to pull data via a dump.sh file to enable me to work locally. Whenever I run the required command, I receive this error:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
If I try mysql -u root I see the exact same error message.
Trying mysql -u root -p requires my password to be entered (it is the same password in the database.yml file) which is kind of weird - surely this step should not work based on my error message?
My database.yml file looks like this for development:
development:
adapter: mysql2
database: database_development
host: localhost
port: 3306
username: root
password: "password_is_here"
pool: 5
timeout: 5000
I feel like I am missing something really basic here, but cannot for the life of me work out what it is :-/
EDIT: Forgot to mention, the database exists and has been migrated so rake db:create and rake db:migrate are not the issues.
EDIT2: My test database has the same information
I have seen this error before, that was because the database.yml contain some special characters that can't see in normal mode of text editor. I suggest to try to create totally new database.yml file from scratch then input database info again manually, restart the server to check the result.

mySQL root password not working

I am working on a new project with a friend. We installed mySQL on it but eventually decided to remove it to make a fresh new installation.
I am following the tutorial on DigitalOcean to install mySQL to be eventually used on Ruby on Rails
When I re-installed it during the installation I got prompted to enter a root password and once entered, the installation finished with no errors. At some point in the tutorial it says to add the following command:
sudo mysql_secure_installation
At this point it asked my root password but it doesn't work. I would get the following message:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
I looked everywhere for a solution to my problem, this seems to occur to many people! I finally found a solution on the ubuntuforums which temporarily solved the problem.
Now I am trying to run the command:
rake db:create
after setting up my config/database.yml file as follows:
encoding: utf8
pool: 5
username: root
password: ********
host: localhost
database: app_test
socket: /var/run/mysqld/mysqld.sock
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
username: app
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
in the middle of the installation it prompts me for my db root password again due to denied access even thought it is set up on the .yml file:
Access denied for user 'root'#'localhost' (using password: YES)Please provide the root password for your MySQL installation
I enter it and get:
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8",
"pool"=>5, "username"=>"root", "password"=>"******",
"host"=>"localhost", "database"=>"OApp_test",
"socket"=>"/var/run/mysqld/mysqld.sock"}
Then I tried to log into mysql with the command:
mysql -u root -p
and guess what? again, my root password is supposedly invalid!I am very confused...
extra info (if it is any help):
the first installation of the database that we made a few month ago and that we deleted was installed from my friends account.
I uninstalled mysql following this instructions.
if I uninstall mysql again, when I search for mysql files with the 'find a mysql' command it find a lot of files:
./var/lib/php5/modules/cgi/enabled_by_maint/mysql
./var/lib/php5/modules/apache2/disabled_by_maint/mysql
./var/lib/php5/modules/fpm/enabled_by_maint/mysql
./var/lib/php5/modules/cli/enabled_by_maint/mysql
./var/lib/php5/modules/registry/mysql
./var/lib/mysql
./var/lib/mysql/mysql
./var/log/mysql
./etc/apparmor.d/abstractions/mysql
./etc/mysql
./root/vst_install_backups/1438441474/mysql
./root/vst_install_backups/1438441474/mysql/mysql_datadir/mysql
./usr/share/bash-completion/completions/mysql
./usr/share/dbconfig-common/data/roundcube/upgrade/mysql
./usr/share/dbconfig-common/data/roundcube/install/mysql
./usr/share/dbconfig-common/internal/mysql
check your grants for that database
SHOW GRANTS ON app_development;
there is a difference between localhost and 127.0.0.1 make sure you have both.
If this is a new installation, you should be able to reset the password by uninstalling MySQL and installing it again. You can remove it completely with the --purge option to apt.
You can also google for password reset instructions if you have root on the OS level.

"Access Denied" when rails connects to Mysql

I have did all the procedures as mentioned in several places and I also learned from lynda.com video tutorial. I used Mac 10.7 and I installed rubystack. I created the databases, add and checked the database.yml here is you can see it again.
development:
adapter: mysql2
encoding: utf8
reconnect: false
host: localhost
database: simplecmsdevelopment
pool: 5
username: simple_cms
password: maiwandj
socket: /tmp/mysql.sock
Therefore, when I run rake db:schema:dump it print the following errors
bash-3.2$ rake db:schema:dump
/Applications/rubystack-1.9.3-18/ruby/lib/ruby/gems/1.9.1/gems/bundler-1.5.2/lib/bundler/runtime.rb:220: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
rake aborted!
Access denied for user 'simplecms'#'localhost' (using password: YES)
/Applications/rubystack-1.9.3-18/simplecms/config/environment.rb:5:in `' Tasks: TOP => db:schema:dump => environment (See full trace by running task with --trace)
Have you granted permissions for that user on that database? i.e., GRANT ALL PRIVILEGES ON simplecmsdevelopment.* TO simple_cms#localhost;
You'll want to grant permissions on the simplecmsdevelopment database for simple_cms#localhost:
GRANT ALL PRIVILEGES ON 'simplecmsdevelopment'.* TO 'simple_cms'#'localhost';
You might want to change the directory permissions to something like 755 for /usr/local/bin as well... That should fix the warning.
DB yml Config file mentions username: simple_cms, but error message in console mentions user 'simplecms'#'localhost'.... I would suggest you should rewrite db yml configurations. I guess you might be having wrong username 'simplecms' written for test environment.... most probably.... do check...

Cannot run rake db:migrate - Access denied for user 'root'#'localhost' in MySQL

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.

Heroku db:push Sequel::DatabaseConnectionError -> Mysql::Error: Access denied for user 'reg'#'localhost ' (using password: NO)

I have a problem using the heroku db:push command to transfer a MySQL database to heroku. I've tried using the same command for another app with a sqlite3 database and everything went fine.
C:\Users\reg\Team-Omni>heroku db:push
Loaded Taps v0.3.9
Auto-detected local database: mysql://127.0.0.1/omni_dev?encoding=utf8
Warning: Data in the app 'growing-mist-42' will be overwritten and will not be recoverable
.
Are you sure you wish to continue? (y/n)? y
Failed to connect to database:
Sequel::DatabaseConnectionError -> Mysql::Error: Access denied for user 'reg'#'localhost
' (using password: NO)
if i remove the password for the mysql anonymous account, the error changes to
Sequel::DatabaseConnectionError -> Mysql::Error: Access denied for user ''#'localhost' to database 'omni_dev'
--additional information--
my .gems file:
rails -v 2.3.8
andre-geokit --version 1.5.0 --source http://gems.github.com
You are getting that error because you are not specifying the password for the local database connection. Apparently the username is configured as 'reg' (maybe in the MySQL config file). This doesn't have anything to do with the Heroku PostgreSQL database, it's a problem connecting to your local MySQL database (named omni_dev).
Try the following connection string:
mysql://USERNAME:PASSWORD#127.0.0.1/omni_dev?encoding=utf8
for the appropriate values of USERNAME and PASSWORD.
I've had this problem as well, but I was passing a password. My local app worked fine, but when using heroku db:push, I got the same error as redge.
Adding a port in the database.yml fixed the problem. So, a working database.yml has the following entries:
database: DATABASE
username: USER
password: PASSWORD
adapter: mysql
encoding: utf8
socket: /Applications/MAMP/tmp/mysql/mysql.sock
port: 8889