Reset MySQL root password to "default" - MAMP - mysql

I changed my root level password on phpMyAdmin. I was unsure where to enter the password itself, as it did not give me the option (login form). I wondered if it was the php.ini file but users with read privileges could read it if I placed the password in there.
Now, the mysql doesn't run as I tried various online resources to fix the problem. If needs be I would delete mamp and re-install but I do not want to lose my database files. Ideally I would revert the password to default, which I believe was nothing, except now I cannot connect to phpmyadmin, or the mamp start page:
Error: Could not connect to MySQL server!
Any help would be great.
UPDATE -
Error message from mamp:
/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user 'root'#'localhost' (using password: YES) when trying to connect

This seemed to have fixed it when using terminal to reset the password:
/Applications/MAMP/Library/bin/mysqladmin -u root -p password newpassword
Found on mamp faq.

Look in the files:
checkMysql.sh
quickCheckMysqlUpgrade.sh
repairMysql.sh
stopMysql.sh
The important one in this case is "quickCheckMysqlUpgrade.sh".
All the files are located in the /Applications/MAMP/bin/ directory.
In these files you'll find something like
# /bin/sh
/Applications/MAMP/Library/bin/mysqlcheck --quick --check-upgrade -u root -proot --socket=/Applications/MAMP/tmp/mysql/mysql.sock mysql
When you see -proot that is the password MAMP will try to use,
-p{password}.
-p means "password" and whatever comes after is the password.
So change "-proot" to eg. "-pmysecret" or whatever your password is.

I was being annoyed by the startup "access denied" error MAMP would show, even though I was able to access my site using phpMyAdmin or other SQL tools. I even found/updated the password in checkMysql.sh, repairMysql.sh, and upgradeMysql.sh. I did not notice the script called quickCheckMysqlUpgrade.sh and correcting the password in that fixed the startup error for me.

I just solved this issue on my MBP!
In MAMP Pro (v352), go to the MySQL tab and press "Change Password".

Related

Unable to connect to MySQL instance after installing

I'm setting up a MySQL database following this tutorial. I installed it and successfully initialized an instance with a root password, but I am having trouble connecting to the instance via command line. When I click on the 'mysql' executable under bin, I get this message
ERROR 1045 (28000): Access denied for user 'hunter'#'localhost' (using password: NO)
and if I try to enter
> mysql -u root -p
in the terminal I get this message
-bash: mysql: Permission denied
It says in the instructions that I should be getting prompted to enter the password for the database, but for some reason it won't let me.
I would suggest first off to try a mysql workbench. You can download it at https://dev.mysql.com/downloads/workbench/ .
It seems that calling mysql from bash is causing issues for you. If you are using a *Nix environment, it could be a permissions issue and you need to set the correct permissions on the mysql binary. However, usually a correct installation should have already done that. See: https://askubuntu.com/questions/229589/how-to-make-a-file-e-g-a-sh-script-executable-so-it-can-be-run-from-a-termi
Secondly, you should use the username root . hunter is not default username.
From the mysql documentation:
How to Reset the Root Password
If you have never assigned a root password for MySQL, the server does not require a password at all for connecting as root. However, this is insecure. For instructions on assigning a password, see Section 2.10.4, “Securing the Initial MySQL Account”.
Reference:
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

Access denied for user 'root'#'localhost' (using password: NO). NOTHING WORKS

I feel like I've tried everything.
user root with empty password doesn't work.
Tried uninstalling and reinstalling mysql. Doesn't work.
Thinking this had something to do with my project in Laravel, I uninstalled and reinstalled it. Started a fresh project. Nope.
Uninstalled reinstalled Homestead. Nope.
Uninstalled reinstalled Vagrant. Nope.
My database config in Laravel looks like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
But when I try:
mysql -u homestead -p
and 'secret'
I get:
ERROR 1045 (28000): Access denied for user 'homestead'#'localhost' (using password: YES)
I followed all the steps to this post, and....can you guess? NOPE NOTHING.
Access denied for user 'homestead'#'localhost' (using password: YES) on Laravel 5.2.27
Please help. I will be happy to provide any more information if I missed anything.
I had an old version of Homestead.yaml laying around I think. All I had to do was to change mysql to true under features in my Homestead.yaml. This was false for some reason.
Then i did
vagrant destroy
vagrant up
And everything was working. Hopefully this helps someone
I've ran into this before and honestly sometimes it differs from one person to another, so here is a couple of solutions I know:
First:
Add a password to mysql by running mysqladmin -u root -p pass
But I believe you already tried that so on to the next one,
Second
use this query inside the mysql cli:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('root');
Please notice that this method directly manipulates your database, you just have to start your mysql cli inside your vagrant vm, and type that query as it is inside, then try to login with root as the username and root as password, hopefully this helps.
You can try reseting the root password by running MySQL in Safe Mode.
Stop MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and..
Log in without a password as root:
mysql -u root
Update root (and any other user's) password)
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
\q
Restart MySQL in normal mode
sudo /usr/local/mysql/support-files/mysql.server start
Reference: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/
Note: this is pretty much a copy-paste from the reference link. this is pretty standard reset procedure, but just documented better in that guide compared to mysql reference docs.

MySQL not working with Laravel

This may be a noob question.
But I have tried everything, purging and reinstalling trying to reconfigure and the works.
For some reason my root that was set without a password on localhost is denying me access
I have tried to reset the root password using the command line but to no avail.
Does anybody know how to get this error to be fixed?
ERROR 1045 (28000): Access denied for user 'devin'#'localhost' (using password: NO)
I am using linux and ubuntu
Even though you set your root user to login without a password, this does not mean that user devin has been configured to login without a password.
Edit your .my.cnf file:
vi ~/.my.cnf
In the file which you see, hard code the password for user devin, save the file, then exit.
[client]
user=devin
password=your_password_goes_here
Then restart MySQL and devin should be able to login without using a password.
The following command should work to connect you to a database called my_db:
mysql --user=devin my_db

phpMyAdmin can't connect to the MySQL server

I am using MAMP.
It seems that when I tried making some changes with the passwords, I messed it up and now I can't access anything on phpMyAdmin.
I've tried to reinstall MAMP, but all I get is still the same error.
Does anybody know how to fix this?
UPDATE: Even in terminal I get the same error
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
check your configuration file in MAMP, the password isn't defined
The reinstallation doesnt rewrite conf files
Try resetting your root password via the console. Instructions can be found here.
The instructions cover Windows and *Nix.
The reason why when you re-installed MAMP/WAMP/LAMP/MySQL etc and it doesn't remove the password is because it saves the config files, and when you remove MySQL it doesn't delete the config files relating to the passwords.
I've had this issue on Windows and Linux - But I can see it affects Mac's too.
Edit: I am assuming you have console access, because you mention MAMP - If you don't, try your host' control panel, it will have an option for Mysql there.

MAMP mysql issue

I am currently using MAMP and I've come across an issue when I try to access localhost:8888/MAMP/?language=English
I get Error: Could not connect to MySQL server!
All of my sites are accessible, just not the MAMP admin area.
I've read that I may need to change the password, but when I run
/Applications/MAMP/Library/bin/mysqladmin -u root -p password NEWPASSWORD
I get:
/Applications/MAMP/Library/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: YES)'
Why is any of this happening and how can I get it back to working order?
It looks like the root password is not what you expect it to be. No telling how that happened or if it's simple typos, but just in case it got changed out from under you, here is a handy little guide to resetting the root password, which will allow you to administer other users passwords, etc.
mysql.com reset root password on Unix
Be sure to also modify /Applications/MAMP/bin/mamp/index.php. The mysql root password is hard coded in there. You want to change this line:
$link = #mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');
so the second "root" is what you changed your mysql root user's password to be. Hopefully, when you launch index.php, you will no longer get that error.