mySQL root password not working - mysql

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.

Related

Rails—mysqldump error when migrating

I'm using Rails 4.0, every time I run a migration I get this error:
mysqldump: Got error: 1045: Access denied for user 'regan'#'localhost' (using password: NO) when trying to connect
Could not dump the database structure. Make sure `mysqldump` is in your PATH and check the command output for warnings.
I think the migrations are still working ok, but I'm getting a lot of failing tests (I just received this project already built).
How do I fix this error?
I assume you don't have the users password setup in the database.yml file. The common scenario is that you setup a password in the mysql installation and now not providing it.
Your database.yml file should look some thing like this.
development:
adapter: mysql2
encoding: utf8
database: <my db>
username: <my user>
password: <my password>
host: localhost
port: 3306

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.

Connecting remote database server in Rails app failed

Using Rails 3.2, mysql2 gem, MariaDB 5.5. I got the following error while trying to deploy the app for the first time:
Mysql2::Error: Access denied for user 'abc'#'%' to database 'app_production'
I'm not sure why the percent sign % in 'abc'#'%'.
Here's my database.yml:
production:
adapter: mysql2
encoding: utf8
reconnect: true
host: db.domain.com
port: 3306
database: app_production
pool: 5
username: abc
password: some_password_here
socket: /run/mysqld/mysqld.sock
My /etc/mysql/my.cnf has bind 0.0.0.0, firewall is temporarily disabled with sudo iptables -F.
This error due to permission on database access for the user, so you have to grant access permission for this user on above database. Find below command to grant permission. run these command on mysql terminal
GRANT ALL PRIVILEGES ON app_production.* TO 'abc'#'%' WITH GRANT OPTION
FLUSH PRIVILEGES
It sounds like the user abc is not set up with MySQL. Go to your MySQL client and make sure that user is created (with that database).

Unable to start rails server due to access mysql server - access denied for 'root'#'localhost'

I have git cloned a repository in order to start contributing to a private project.
Now when I start the mysql server as well as the rails server I get the following error:
Access denied for user 'root'#'localhost' (using password: YES) (Mysql2::Error)
Now I tried to login with the password that I found in the config/database.yml file but without success. What should I do to have the app run properly in my local environment?
Thanks for helping out.
the database.yml file:
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: sc_development
pool: 5
username: root
password: Mysql2047
socket: /tmp/mysql.sock
# 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: sc_test
pool: 5
username: root
password: Mysql2047
socket: /tmp/mysql.sock
You need to start mysql server on your local machine, create database sc_development and clear the password in your database settings file.
I would create a new MySQL user, with a username something other than root. It's a good practice to have a different database user for each different app.
You'll also, of course, need to grant privileges on the sc_development database to your app's user.
CREATE DATABASE sc_development;
CREATE USER sc IDENTIFIED BY 'somepassword';
GRANT ALL PRIVILEGES ON sc_development.* TO sc;
Something like that might do the trick.
This was doing the trick for me:
First, instead of logging into mysql with
mysql
login like this:
mysql -uroot
root#localhost has all rights and NO password.
Next, I created the database and another user who I gave all rights.
mysql> CREATE USER joe identified by 'foobar'
mysql> Grant All PRIVILEGES ON smartcheckups_development.* TO joe;
Create the database:
mysql> CREATE DATABASE sc_development;
In my database.yml file, I updated the login & password with that of the above user joe. This will allow me to login.
Leave mysql via \q
Then
bundle exec rake db:create
and start rails rails s

MySql Error 1045 after I did rake db:create

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.