Reputation: 169
I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts. Since it is impossible to connect without the error:
# 1045 - Access denied for user 'root' @ 'localhost' (using password: NO)
I have search a little on the net before, and even the technic:
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
does not work, or I didn't understood how it worked.
I'm on FreeBSD 8.1, my version of PhpMyadmin is 2.11.
Thank you in advance for your answers.
Upvotes: 16
Views: 18327
Reputation: 21
mysql80:
update user SET authentication_string='your password after encode to sha256' where User='root';
Upvotes: 0
Reputation: 597
in my case its a frustrating Windows Server installation (iis/php/mysql) so this is what i did:
NOTE: if you already have data you should back it up!
Step 1 Uninstall MySQL from Control Panel. (you should know how to do this)
Step 2 Run Command Prompt as Admini and execute the following commands to stop and remove MySQL service.
Net stop MySQL
Sc delete MySQL
Step 3 Delete these folders:
C:\Program Files\MySQL
C:\Program Files (x86)\MySQL
C:\ProgramData\MySQL
And if it exists:
C:\Users\[User-Name]\AppData\Roaming\MySQL
Download installer from https://dev.mysql.com/downloads/installer/ and install -MySQL Server 8.0.23
open cmd as admin and go to c:\Program Files\MySQL\MySQL Server 8.0\bin\ run
mysqld --initialize --console
mysqld --install
now start the service (type services.msc in run panel)
now back to console run:
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
that's it
Upvotes: 0
Reputation: 1104
I am Using MySQL Server 8 and this is how I solved this problem.
create a file and name it accordingly. I've named it as reset.txt. put below content in the file but change MyNewPass. This will be your new SQL password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Stop my SQL server (Go to services and search MYSQL and right-click on it and stop )
Now open a cmd in your bin folder of My SQLserver directory. in my case it's
C:\Program Files\MySQL\MySQL Server 8.0\bin
execute the following command.
mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\reset.txt'
NOTE: my reset.txt file is in the c drive. Give the correct path. Check my.ini file is in the directory. In my case, it is in
C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
Finally, restart the SQL Server. Check with your new password.
Upvotes: 1
Reputation: 1103
here is what I did and it worked:
After you install (rpm installation), do a vi /etc/my.cnf
.
This will give you a path where your datadir
is set. For me it was datadir=/var/lib/mysql
.
Add a line there user=root
, and remove all the content inside the datadir
path: rm -rf /var/lib/mysql/*
.
Now hit the command: mysqld --initialize
.
A temporary password is generated at a location. For this:
grep "A temporary password" /var/log/*
.
You will get a line that says:
/var/log/mysqld.log:2018-05-01T15:13:47.937449Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: &uosjoGfi9:K
. So for me &uosjoGfi9:K
was my temporary password.
Now do a mysql -u root -p
. Paste your temporary password from what you got from above.
You will be in your mysql cli mode. Now do:
mysql> use mysql;
You will be asked to reset your password:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Run your ALTER command:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPswd';
And you are done.
Upvotes: 0
Reputation: 20565
Answer for XAMPP on Windows:
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
DONE!
Be awared that mysql root user password does not have to be the same as password for phpmyadmin.
Upvotes: 0
Reputation: 520
For mysql 5.7.16 or later I found this (from mysql.com) to be the working solution. Below are some points which are different compared to previous older versions
1) I used the below command to run mysql in safe mode as per some other references which actually worked fine for me (mysql 5.7.16 ubuntu 16.04).
mysqld_safe --skip-grant-tables --skip-networking
2) The below update stmt is NOT working for later version (ie. 5.7 and above)
-- NOT Working for 5.7 and later
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
INSTEAD use below for 5.7.6 and later
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
OR user below for 5.7.5 or earlier versions.
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
Upvotes: 6
Reputation: 20110
Please follow the instruction from the below link to reset your root password.You have to do it from outside mysql.
Resetting MySql Password
Forgetting your MySQL password can be a real headache for you.Here are some easy steps that you can follow to recover MySql password under Windows Stop MySql
You have to stop MySql service before you proceed.In Windows environment, go to 'Task Manager' and Under 'Service' tab find MySQL and stop it. Write Sql to change your password
All you need to do is to create a text file and put the below two lines into that. UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES; Save it under C:\ drive and give it a name 'mysql-init.txt' Time to restart MySQL by your own.
Now it's time to restart your MySQl which you stopped in before but this time from command line. C:> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt Finishing up!
Now you can log in with your new password. When you finish remove the file that you created in the previous stage.
Also there is a link (http://kaziprogrammingblog.osinweb.com/article/showarticle/Resetting-MySql-Password) where I have explained the same thing.
Hope this will help..:)
Upvotes: 0
Reputation: 9447
I summarised my solution here: http://snippets.dzone.com/posts/show/13267
sudo stop mysql
sudo mysqld --skip-grant-tables --skip-networking
mysql
mysql> update mysql.user set password = password('your_new_password') where user = 'root';
mysql> flush privileges;
mysql> exit;
sudo mysqladmin shutdown
sudo start mysql
Upvotes: 20