Access denied for user 'root#localhost' (using password:NO) - mysql

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?

for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>

You can reset your root password. Have in mind that it is not advisable to use root without password.

1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.

Use mysql -u root -p
It will ask for password, insert password and enter.

I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details

Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:

For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.

Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account

Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.

Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.

In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.

For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';

Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.

If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.

if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');

If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html

mysqladmin -u root -p password
enter your current password
then
enter your new password

It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

Related

MySql -u root -p not working on new computer [duplicate]

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

mysql error : ERROR 1045 (28000): Access denied for user [duplicate]

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

Get error Access denied for user 'root'#'localhost' (using password: NO) when setting Wordpress on amazon ec2 [duplicate]

I'm trying to run WordPress in my Windows desktop and it needs MySQL.
I install everything with Web Platform Installer which is provided by Microsoft. I never set a root password for MySQL and in the final step of installing WordPress, it asks for a MySQL server password.
What is the default password for root (if there is one) and how to change it?
I tried:
mysql -u root password '123'
But it shows me:
Access denied for user 'root#localhost' (using password:NO)
After this I try:
mysql -u root -p
However, it asks for a password which I don't have.
Update: as Bozho suggested, I did the following:
I stopped the MySQL Service from Windows services
Opened CMD
Changed the location to c:\program files\mysql\bin
Executed the command below
mysqld --defaults-file="C:\\program files\\mysql\\mysql server 5.1\\my.ini" --init-files=C:\\root.txt
The command ran with a warning about character set which I mentioned below
I start the MySQL service from Windows services
I write in the command line
mysql -u root -p
EnterPassword: 123 // 123 was the password
The command line shows the following error
Access denied for user 'root#localhost' (using password:**YES**)
How do I solve this?
for this kind of error; you just have to set new password to the root user as an admin. follow the steps as follows:
[root ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password:NO)
Stop the service/daemon of mysql running
[root ~]# service mysql stop
mysql stop/waiting
Start mysql without any privileges using the following option;
This option is used to boot up and do not use the privilege system of MySQL.
[root ~]# mysqld_safe --skip-grant-tables &
At this moment, the terminal will seem to halt. Let that be, and use new terminal for next steps.
enter the mysql command prompt
[root ~]# mysql -u root
mysql>
Fix the permission setting of the root user ;
mysql> use mysql;
Database changed
mysql> select * from user;
Empty set (0.00 sec)
mysql> truncate table user;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to root#localhost identified by 'YourNewPassword' with grant option;
Query OK, 0 rows affected (0.01 sec)
*if you don`t want any password or rather an empty password
mysql> grant all privileges on *.* to root#localhost identified by '' with grant option;
Query OK, 0 rows affected (0.01 sec)*
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Confirm the results:
mysql> select host, user from user;
+-----------+------+
| host | user |
+-----------+------+
| localhost | root |
+-----------+------+
1 row in set (0.00 sec)
Exit the shell and restart mysql in normal mode.
mysql> quit;
[root ~]# kill -KILL [PID of mysqld_safe]
[root ~]# kill -KILL [PID of mysqld]
[root ~]# service mysql start
Now you can successfully login as root user with the password you set
[root ~]# mysql -u root -pYourNewPassword
mysql>
You can reset your root password. Have in mind that it is not advisable to use root without password.
1) You can set root password by invoking MySQL console. It is located in
C:\wamp\bin\mysql\mysql5.1.53\bin by default.
Get to the directory and type MySQL. then set the password as follows..
> SET PASSWORD FOR root#localhost = PASSWORD('new-password');
2) You can configure wamp's phpmyadmin application for root user by editing
C:\wamp\apps\phpmyadmin3.3.9\config.inc.php
Note :- if you are using xampp then , file will be located at
C:\xampp\phpMyadmin\config.inc.php
It looks like this:
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YOURPASSWORD';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
The error "Access denied for user 'root#localhost' (using password:NO)"
will be resolved when you set $cfg['Servers'][$i]['AllowNoPassword'] to false
If you priviously changed the password for 'root#localhost', then you have to do 2 things to solve the error "Access denided for user 'root#localhost'":
if ['password'] have a empty quotes like ' ' then put your password between quotes.
change the (using password:NO) to (using password:YES)
This will resolve the error.
Note: phpmyadmin is a separate tool which comes with wamp.
It just provide a interface to MySQL. if you change my sql root's password, then you should change the phpmyadmin configurations. Usually phpmyadmin is configured to root user.
Use mysql -u root -p
It will ask for password, insert password and enter.
I was getting the same error on OS X El captain.
Mysql version 5.7 . I was able to connect to mysql with root after executing these steps.
Stop the mysql server
sudo mysql.server stop
Start mysql in safe mode
sudo mysqld_safe --skip-grant-tables
Using mysqld, Change the database to mysql and update the details for user 'root'.
show databases;
use mysql;
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
exit;
After that kill the 'mysqld_safe' process and start mysql normally. You should be able to login to mysql using root and new password. SQL docs for more details
Simply edit my.ini file in C:\xampp\mysql\bin path. Just add:
skip-grant-tables
line in between lines of # The MySQL server [mysqld] and port=3306. Then restart the MySQL server.
Looks like:
For some information I've get error after changing password:
Access denied for user 'root'#'localhost' (using password: NO)
Access denied for user 'root'#'localhost' (using password: YES)
In both cases there was error.
But the thing is after that I've tried it with
mysql -uroot -ppassword instead of
mysql -u root -p password -> with spaces between -uroot and -ppassword so maybe if someone get trouble can try this way.
Make sure the MySQL service is running on your machine, then follow the instructions from MySQL for initially setting up root (search for 'windows' and it will take you to the steps for setting up root):
Securing the Initial MySQL Account
Another solution if someone gets the error The specified password for user account ‘root’ is not valid, or failed to connect to the database server also with the right password, is the follow
•In the Windows registry, delete the mysql_pwd reg key under HKCU\Software\Microsoft\WebPlatformInstaller
•Unistall older version of MySQL .NET connector
•Download and install the latest MySql .NET Connector.
Change the password from config.inc.php present in C:\xampp\phpMyAdmin.
Type mysql -u root -p in the command prompt.
You will be asked to enter the password. Enter that password which you updated in the config.inc.php.
In your code replace the 'root' with your Server username and password with your server password.
For example if you have DB and your php files on the server http://www.example.com
then obviously you would have to enter into this server site using your username and password.
For MySQL 5.7. These are the below steps:
Stop your MySQL server completely. This can be done by accessing the Services window inside Windows XP and Windows Server 2003, where you can stop the MySQL service.
Open your MS-DOS command prompt using "cmd" inside the Run window. Inside it navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Execute the following command in the command prompt: mysqld.exe -u root --skip-grant-tables
Leave the current MS-DOS command prompt as it is, and open a new MS-DOS command prompt window.
Navigate to your MySQL bin folder, such as C:\MySQL\bin using the cd command.
Enter mysql and press enter.
You should now have the MySQL command prompt working. Type use mysql; so that we switch to the "mysql" database.
Execute the following command to update the password:
update user set authentication_string=password('1111') where user='root';
Some times it just happens due to installation of Wamp or changing of password options of root user.
One can use privilages-->root (user) and then set password option to NO to run the things without any password OR set the password and use it in the application.
If you are using XAMPP just go to C:\xampp\phpMyAdmin and then open config.inc.php find $cfg['Servers'][$i]['password'] = '' line and put your password there.
if you changed the port to non standard one, then you need to specify it:
$connection = mysqli_connect('localhost:3308', 'root', '', 'loginapp');
If the root account exists but has no password, connect to the server as root using no password, then assign a password. This was my situation when I encountered this issue.
Connect to the server as root using no password:
$> mysql -u root --skip-password
Assign a password:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'root-password';
I was able to solve my problem this way. Hope this helps someone who encounters a similar issue in the future. Cheers!
Reference: https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html
mysqladmin -u root -p password
enter your current password
then
enter your new password
It happens because of the security reason.
try with the following
mysql -u root -p
click enter and enter the password and try again

How to find out the MySQL root password

I cannot figure out my MySQL root password; how can I find this out? Is there any file where this password is stored?
I am following this link but I do not have directadmin directory in local.
thanks to #thusharaK I could reset the root password without knowing the old password.
On ubuntu I did the following:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables --skip-syslog --skip-networking
Then run mysql in a new terminal:
mysql -u root
And run the following queries to change the password:
UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
FLUSH PRIVILEGES;
In MySQL 5.7, the password field in mysql.user table field was removed, now the field name is 'authentication_string'.
Quit the mysql safe mode and start mysql service by:
mysqladmin shutdown
sudo service mysql start
You can't view the hashed password; the only thing you can do is reset it!
Stop MySQL:
sudo service mysql stop
or
$ sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
$ sudo mysqld_safe --skip-grant-tables
(above line is the whole command)
This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:
$ mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
MySQL 5.7 and over:
mysql> use mysql;
mysql> update user set authentication_string=password('password') where user='root';
Exit the MySQL CLI:
mysql> exit
Restart MySQL in normal mode, first stopping the safe mode instance:
$ mysqladmin -u root -p shutdown # (when prompted, enter the new password just set)
$ sudo service mysql start
or
$ sudo /usr/local/mysql/support-files/mysql.server start
Your new password is 'password'.
MySQL 5.7 and above saves root in MySQL log file.
Please try this:
sudo grep 'temporary password' /var/log/mysqld.log
One thing that tripped me up on a new install of MySQL and wondering why I couldn't get the default password to work and why even the reset methods where not working.
Well turns out that on Ubuntu 18 the most recent version of MySQL server does not use password auth at all for the root user by default. So this means it doesn't matter what you set it to, it won't let you use it. It's expecting you to login from a privileged socket.
mysql -u root -p
This will not work, even if you are using the correct password.
Instead, you need to use:
sudo mysql
that will work with out any password.
then once you in you need type in
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'Password you want to use';
Then log out and now it will accept your password.
Follow these steps to reset password in Windows system
Stop Mysql service from task manager
Create a text file and paste the below statement
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('yournewpassword');
MySQL 5.7.6 and later:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'yournewpassword';
Save as mysql-init.txt and place it in 'C' drive.
Open command prompt and paste the following
C:\> mysqld --init-file=C:\\mysql-init.txt
You cannot find it. It is stored in a database, which you need the root password to access, and even if you did get access somehow, it is hashed with a one-way hash. You can reset it: How to Reset the Root Password
This worked for me:
On terminal type the following
$ sudo mysql -u root -p
Enter password://just press enter
mysql>
Unless the package manager requests you to type the root password during installation, the default root password is the empty string. To connect to freshly installed server, type:
shell> mysql -u root --password=
mysql>
To change the password, get back the unix shell and type:
shell> mysqladmin -u root --password= password root
The new password is 'root'. Now connect to the server:
shell> mysql -u root --password=
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Oops, the password has changed. Use the new one, root:
shell> mysql -u root --password=root
...
blah, blah, blah : mysql welcome banner
...
mysql>
Bingo! New do something interesting
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
Maurycy
As addition to the other answers, in a cpanel installation, the mysql root password is stored in a file named /root/.my.cnf. (and the cpanel service resets it back on change, so the other answers here won't help)
you can view mysql root password , well i have tried it on mysql 5.5 so do not know about other new version well work or not
nano ~/.my.cnf
The default password which worked for me after immediate installation of mysql server is : mysql
The procedure changes depending the version of MySql. Follow the procedure exactly as described for your version:
HINTS - Read before the instructions page for your version of MySql*
In step 5: Instead of run CMD, create a shortcut on your desktop calling CDM.exe. Then right-click on the shortcut and select "Execute as Administrator".
In step 6: Skip the first proposed version of the command and execute the second one, the one with the --defaults-file parameter
Once you execute the command, if everything is ok, the CMD window remains open and the command of step 6 continues executing. Simply close the window (click 'x'), and then force close MySQl from the Task Manager.
Delete the file with the SQL commands, and start again MySQL. The password must be changed now.
5.0
http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
5.1
http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html
... just change the version in the link (5.5, 5.6, 5.7)
In your "hostname".err file inside the data folder MySQL works on, try to look for a string that starts with:
"A temporary password is generated for roor#localhost "
you can use
less /mysql/data/dir/hostname.err
then slash command followed by the string you wish to look for
/"A temporary password"
Then press n, to go to the Next result.
I solved this a different way, this may be easier for some.
I did it this way because I tried starting in safe mode but cannot connect with the error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
What I did was to connect normally as root:
$ sudo mysql -u root
Then I created a new super user:
mysql> grant all privileges on *.* to 'myuser'#'%' identified by 'mypassword' with grant option;
mysql> quit
Then log in as myuser
$ mysql -u myuser -p -h localhost
Trying to change the password gave me no errors but did nothing for me so I dropped and re-created the root user
mysql> drop user 'root'#'localhost;
mysql> mysql> grant all privileges on *.* to 'root'#'localhost' identified by 'mypassword' with grant option;
The root user is now working with the new password
Using Debian / Ubuntu mysql packages, you can login with user debian-sys-maint, which has all the expected privileges, the password is stored in the file /etc/mysql/debian.cnf
Answers provided here did not seem to work for me, the trick turned out to be:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
(complete answer here: Change user password in MySQL 5.7 with “plugin: auth_socket”)
System:
CentOS Linux 7
mysql Ver 14.14 Distrib 5.7.25
Procedure:
Open two shell sessions, logging in to one as the Linux root user
and the other as a nonroot user with access to the mysql command.
In your root session, stop the normal mysqld listener and start a
listener which bypasses password authentication (note: this is a
significant security risk as anyone with access to the mysql
command may access your databases without a password. You may want
to close active shell sessions and/or disable shell access before
doing this):
# systemctl stop mysqld
# /usr/sbin/mysqld --skip-grant-tables -u mysql &
In your nonroot session, log in to mysql and set the mysql root password:
$ mysql
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit;
In your root session, kill the passwordless instance of mysqld and restore the normal mysqld listener to service:
# kill %1
# systemctl start mysqld
In your nonroot session, test the new root password you configured above:
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql>
I was stuck with this problem for a couple of minutes and the following was the only solution that actually worked:
https://phoenixnap.com/kb/access-denied-for-user-root-localhost
sudo mysql
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';
mysql -u root -p
In case you already set a password in the past the mysql -uroot -p solution will not work,
In my case I used some of the answers above to solve this (Ubuntu 16). The result was:
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
if you see this text in the screen:
mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
then do:
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo mysqld_safe --skip-grant-tables & # Look at the & at the end!
Enter other terminal to set your password like this:
sudo mysql -u root
mysql> use mysql;
mysql> SET PASSWORD FOR 'root'#'localhost'=PASSWORD('__NEW__PASSWORD__');
mysql> flush privileges;
mysql> quit;
then restart the service and login
# end mysqld_safe in the other terminal
sudo service mysql start
sudo mysql -h 127.0.0.1 -uroot -p
For MySQL 5.5 on Windows 10
You can't find the password as it is hashed in the table, so resetting it is the only option.
The solution of importing the new password script by .txt file, as offered by Lokesh kumar Chippada, didn't work for me. I found that the command prompt just froze after initiating the import.
I added skip-grant-tables to the my.ini file as per the top the answer on this SO post by tonycoupland.
I was then able to login to mysql from the command line
$> mysql
and then in mysql
mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
See 'B.3.3.2.3 Resetting the Root Password: Generic Instructions' on mysql dev page. I have now removed skip-grant-tables from the my.ini file, and I can login as a root user using the new password I created.
Go to phpMyAdmin > config.inc.php > $cfg['Servers'][$i]['password'] = '';

MySQL root password change

I have been trying to reset my MySQL root password. I have run mysqld_safe --skip-grant-tables, updated the root password, and checked the user table to make sure it is there.
Once restarting the MySQL daemon I tried logging in with the new root password that I just set and still get Access denied for user 'root' errors. I have also tried completely removing and reinstalling MySQL (including removing the my.cnf file) and still no luck. What can I do next?
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('mypass');
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
You can find Resetting the Root Password in the MySQL documentation.
Have a look at this from the MySQL reference manual:
First log in to MySQL:
mysql -u root -p
Then at the mysql prompt, run:
UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
Then
FLUSH PRIVILEGES;
Look at this page for more information: Resetting the Root Password: Unix Systems
UPDATE:
For some versions of mysql, the password column is no longer available and you'll get this error:
ERROR 1054 (42S22): Unknown column 'Password' in 'field list'
In this case, use ALTER USER as shown in the answer below.
Please follow the below steps.
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables
sudo service mysql start
sudo mysql -u root
use mysql;
show tables;
describe user;
update user set authentication_string=password('1111') where user='root';
FLUSH PRIVILEGES;
Log in with password "1111".
This is the updated answer for WAMP v3.0.6 and up.
In the MySQL command-line client, phpMyAdmin or any MySQL GUI:
UPDATE mysql.user
SET authentication_string=PASSWORD('MyNewPass')
WHERE user='root';
FLUSH PRIVILEGES;
In MySQL version 5.7.x there is no more password field in the MySQL table. It was replaced with authentication_string. (This is for the terminal/CLI.)
In the MySQL command-line client, phpMyAdmin or any MySQL GUI:
UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE user='root';
FLUSH PRIVILEGES;
I searched around as well and probably some answers do fit for some situations,
my situation is Mysql 5.7 on a Ubuntu 18.04.2 LTS system:
(get root privileges)
$ sudo bash
(set up password for root db user + implement security in steps)
# mysql_secure_installation
(give access to the root user via password in stead of socket)
(+ edit: apparently you need to set the password again?)
(don't set it to 'mySecretPassword'!!!)
# mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> set password for 'root'#'localhost' = PASSWORD('mySecretPassword');
mysql> FLUSH PRIVILEGES;
mysql> exit;
# service mysql restart
Many thanks to zetacu (and erich) for this excellent answer (after searching a couple of hours...)
Enjoy :-D
S.
Edit (2020):
This method doesn't work anymore, see this question for future reference...
I found it! I forgot to hash the password when I changed it. I used this query to solve my problem:
update user set password=PASSWORD('NEW PASSWORD') where user='root';
I forgot the PASSWORD('NEW PASSWORD') and just put in the new password in plain text.
On MySQL 8.0.4+
To update the current root user:
select current_user();
set password = 'new_password';
To update another user:
set password for 'otherUser'#'localhost' = 'new_password';
To set the password policy before updating the password:
set global validate_password.policy = 0;
set password = 'new_password';
set password for 'otherUser'#'localhost' = 'new_password';
Another / better way to update the root password:
mysql_secure_installation
Do you want to stick with 5.x authentication, so you can still use legacy applications?
In my.cnf file
default_authentication_plugin = mysql_native_password
To update root:
set global validate_password.policy = 0;
alter user 'root'#'localhost' identified with mysql_native_password by 'new_password';
On MySQL 8 you need to specify the password hashing method:
ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'new-password';
This worked for me -
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
Chapter 4 Resetting the Root Password: Windows Systems
For MySQL 5.7.6 and later:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
For MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
For me, only these steps could help me setting the root password on version 8.0.19:
mysql
SELECT user,authentication_string FROM mysql.user;
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_pass_here';
FLUSH PRIVILEGES;
SELECT user,authentication_string FROM mysql.user;
If you can see changes for the root user, then it works.
Source: Can't set root password MySQL Server
You have to reset the password! Steps for Mac OS X (tested and working) and Ubuntu:
Stop MySQL
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
(The above line is the whole command.)
This will be an ongoing command until the process is finished, so open another shell/terminal window and log in without a password:
mysql -u root
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
Start MySQL
sudo /usr/local/mysql/support-files/mysql.server start
Your new password is 'password'.
Using the mysqladmin command-line utility to alter the MySQL password:
mysqladmin --user=root --password=oldpassword password "newpassword"
Source
For the current latest MySQL version (8.0.16), none of these answers worked for me.
After looking at several different answers and combining them together, this is what I ended up using that worked:
update user set authentication_string='test' where user='root';
I tried the answer from kta, but it didn't work for me.
I am using MySQL 8.0.
This worked for me in the MySQL command-line client (executable mysql):
SET PASSWORD FOR 'root'#'localhost' = 'yourpassword'
This is for Mac users.
On 8.0.15 (maybe already before that version) the PASSWORD() function does not work. You have to do:
Make sure you have Stopped MySQL first (above).
Run the server in safe mode with privilege bypass:
sudo mysqld_safe --skip-grant-tables
Replace this mysqld_safe with your MySQL path like in my case it was
sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables
then you have to perform the following steps.
mysql -u root
UPDATE mysql.user SET authentication_string=null WHERE User='root';
FLUSH PRIVILEGES;
exit;
Then
mysql -u root
ALTER USER 'root'#'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
Now just use:
SET PASSWORD FOR <user> = '<plaintext_password>'
Because 'SET PASSWORD FOR <user> = PASSWORD('<plaintext_password>')' is deprecated and will be removed in a future release.(Warning in 04/12 2021)
Please use SET PASSWORD FOR <user> = '<plaintext_password>' instead.
Update 04/12 2021 AM 2:22:07 UTC/GMT -5 hours.
Use the following statement to modify directly in the mysql command line:
mysql> SET PASSWORD FOR'root'#'localhost' = PASSWORD('newpass');
or 1.The terminal enters the bin directory of MySQL
cd /usr/local/mysql/bin
2.Open MySQL
mysql -u root -p
3.At this time you can use your default password
4.Perform operations in MySQL at this time
show databases;
5.You will be prompted to reset the root user password.
So how to reset the root password? I checked a lot of information but it didn’t take effect.
Including entering to modify the database in safe mode, using the mysqladmin command:
"Mysqladmin -u root password"your-new-password""
etc.,
Will not work.
The correct steps are as follows:
1.It is still in the cd /usr/local/mysql/bin/ directory
2.sudo su
After entering, you will be asked to enter your computer password.
When you enter it, nothing is displayed. After you enter it, press Enter
Then press enter
3.Cross the authorization verification
sh-3.2# ./mysqld_safe --skip-grant-tables &
If the execution of the command is stopped, and the execution has been completed at this time,
press Enter directly, and then exit to exit:
sh-3.2# exit
4.Re-enter MySQL at this time, no -p parameter, no password
./mysql -u root
5.Select the database MySQL (here MySQL refers to a database in MySQL,
there are other databases in MySQL, you can view it through show databases;)
use mysql;
6.Update the password of the root user in the database table:
update user set authentication_string=‘123456’ where User='root';
Note: The password field here is authentication_string,
not the password circulated on the Internet.
It is estimated that MySQL was updated later.
Re-enter MySQL and use the password you just set, is it all right?
Because you have just set to bypass the authorization authentication,
you can log in to MySQL directly without a password.
My stupid way is to restart the computer and log in to MySQL with the password again to see if the modification is effective;
Update from 2022
I've tried a few of the answer but the one that works for me is the following
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
Courtesy of StrongDM
Note: I'm using the MySql client for Windows 10 and I'm also logging as the root user.
In MySQL 5.7, the password is replaced
with 'authentication_string'. Use
update user set authentication_string=password('myfavpassword') where user='root';
So many comments, but I was helped by this method:
sudo mysqladmin -u root password 'my password'
In my case after installation I had got the MySQL service without a password for the root user, and I needed to set the password for my security.
A common error I run into from time to time, is that I forget the -p option, so be sure to use:
mysql -u root -p
Or just use interactive configuration:
sudo mysql_secure_installation
For macOS users, if you forget your root password, thusharaK's answer is good, but there are a few more tricks:
If you are using a system preference to start MySQL serverside, simply
sudo mysqld_safe --skip-grant-tables
might not work for you.
You have to make sure the command-line arguments are the same with the system start configuration.
The following command works for me:
/usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so --skip-grant-tables
You can use
ps aux | grep mysql
to check your own.
Exit from WAMP and Stop all WAMP services.
Open Notepad and then type:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('');
Then save it to the C: drive with any name... like this "c:/example.txt"
Now go to your "wamp" folder: wamp → bin → mysql → mysql (your version) → bin
In my case the path is "C:\wamp\bin\mysql\mysql5.6.17\bin".
Now copy your path, run CMD with (Ctrl + R), and then type "cmd" (Enter).
Type cd, right click on CMD, and paste the path (Enter).
Now type (mysqld --init-file=C:\\example.txt) without braces and (Enter).
Then restart the PC or open Task Manager and kill mysqld.exe.
Start WAMP and your password will be removed...
Resetting root password.
sudo mysql --defaults-file=/etc/mysql/debian.cnf
alter user 'root'#'localhost' identified with mysql_native_password by 'new_password';
On Ubuntu,
sudo dpkg-reconfigure mysql-server-5.5
Replace 5.5 with your current version and you will be asked for the new root password.
On Mac open system preferences   MySQL.
In the configuration section of MySQL, check for "Initialize Database".
Change the password in the prompt.