If you have that same problem in MySql 5.7.+ :
Access denied for user 'root'@'localhost'
it's because MySql 5.7 by mặc định allow to tướng connect with socket, which means you just connect with sudo mysql
. If you run rẩy sql :
SELECT user,authentication_string,plugin,host FROM mysql.user;
then you will see it :
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | | auth_socket | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *497C3D7B50479A812B89CD12EC3EDA6C0CB686F0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in phối (0.00 sec)
To allow connection with root and password, then update the values in the table with command :
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Current-Root-Password';
FLUSH PRIVILEGES;
Then run rẩy the select command again and you'll see it has changed :
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | *2F2377C1BC54BE827DC8A4EE051CBD57490FB8C6 | mysql_native_password | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *497C3D7B50479A812B89CD12EC3EDA6C0CB686F0 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
4 rows in phối (0.00 sec)
And that's it. You can run rẩy this process after running and completing the sudo mysql_secure_installation
command.
For mariadb, use
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('manager');
to phối password. More at https://mariadb.com/kb/en/set-password/
answered Nov 26, 2018 at 18:59
KeitelDOGKeitelDOG
5,1504 gold badges22 silver badges35 bronze badges
10
Use the instructions for resetting the root password - but instead of resetting the root password, we'll going to tướng forcefully INSERT a record into the mysql.user table
In the init tệp tin, use this instead
INSERT INTO mysql.user (Host, User, Password) VALUES ('%', 'root', password('YOURPASSWORD'));
GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION;
answered Jul 31, 2013 at 16:42
Andy JonesAndy Jones
6,2654 gold badges32 silver badges47 bronze badges
9
It didn't lượt thích my user privilege ví I SUDO it. (in bash << sudo phối user and password) (this gives username of root and sets the password to tướng nothing) (On Mac)
sudo mysql -uroot -p
Pang
10k146 gold badges85 silver badges124 bronze badges
answered Jun 30, 2017 at 6:48
Dan KaiserDan Kaiser
1,07110 silver badges7 bronze badges
1
Try the following commands
~$ sudo /etc/init.d/mysql stop
~$ sudo mysqld_safe --skip-grant-tables &
~$ mysql -u root
Welcome to tướng the MySQL monitor. Commands kết thúc with ; or \g.
Your MySQL connection id is 1 to tướng server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to tướng clear the buffer.
mysql>
mysql> use mysql;
mysql> update user phối password=PASSWORD("root") where User='root';
mysql> flush privileges;
mysql> quit
~$ sudo /etc/init.d/mysql stop
Stopping MySQL database server: mysqld
STOPPING server from pid tệp tin /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+ Done mysqld_safe --skip-grant-tables
~$ sudo /etc/init.d/mysql start
~$ mysql -u root -p
* MySQL Community Server 5.6.35 is started
~$ mysql -u root -p
Enter password:
Welcome to tướng the MySQL monitor. Commands kết thúc with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35 MySQL Community Server (GPL)
Copyright (c) 2000, năm nhâm thìn, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to tướng clear the current input statement.
mysql>
answered Sep đôi mươi, 2017 at 13:28
aashishaashish
2,6031 gold badge23 silver badges20 bronze badges
5
for the people who are facing below error in mysql 5.7+ version -
Access denied for user 'root'@'localhost' (using password: YES)
Open new terminal
sudo /etc/init.d/mysql stop
... MySQL Community Server 5.7.8-rc is stoppedsudo mysqld_safe --skip-grant-tables &
this will skipp all grant level privileges and start the mysql in safe mode Sometimes the process got stucked just because of
grep: write error: Broken pipe 180102 11:32:28 mysqld_safe Logging to tướng '/var/log/mysql/error.log'.
Simply press Ctrl+Z or Ctrl+C to tướng interrupt and exit process
mysql -u root
Welcome to tướng the MySQL monitor. Commands kết thúc with ; or \g. Your MySQL connection id is 2 Server version: 5.7.8-rc MySQL Community Server (GPL)
Copyright (c) 2000, năm ngoái, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to tướng clear the current input statement.
- mysql>
use mysql;
Reading table information for completion of table and column names You can turn off this feature to tướng get a quicker startup with -A
Database changed
mysql>
update user phối authentication_string=password('password') where user='root';
Query OK, 4 rows affected, 1 warning (0.03 sec) Rows matched: 4 Changed: 4 Warnings: 1mysql>
flush privileges;
Query OK, 0 rows affected (0.00 sec)mysql>
quit
Byesudo /etc/init.d/mysql stop
..180102 11:37:12 mysqld_safe mysqld from pid tệp tin /var/run/mysqld/mysqld.pid ended . * MySQL Community Server 5.7.8-rc is stopped arif@ubuntu:~$ sudo /etc/init.d/mysql start .. * MySQL Community Server 5.7.8-rc is started
mysql -u root -p
Enter password:
Welcome to tướng the MySQL monitor. Commands kết thúc with ; or \g. Your MySQL connection id is 2 Server version: 5.7.8-rc MySQL Community Server (GPL)
after mysql 5.7+ version the column password replaced by name authentication_string from the mysql.user table.
hope these steps will help anyone, thanks.
answered Jan 2, 2018 at 6:20
ArifMustafaArifMustafa
4,9255 gold badges43 silver badges49 bronze badges
I was using ubuntu 18 and simply installed MySQL (password:root) with the following commands.
sudo apt install mysql-server
sudo mysql_secure_installation
When I tried to tướng log in with the normal ubuntu user it was throwing bầm this issue.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
But I was able to tướng login to tướng MySQL via the super user. Using the following commands I was able to tướng log in via a normal user.
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
exit;
Then you should be able to tướng login to tướng Mysql with the normal tài khoản.
answered Sep 17, 2019 at 7:06
If you are getting this error in Workbench but you are able to tướng log in from terminal then follow this steps.
First simply log in with your current password:
sudo mysql -u root -p
Then change your password because having low strength password gives error sometimes.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-strong-password';
FLUSH PRIVILEGES;
Then simply exit and again login with your new password:
quit
sudo mysql -u root -p
Once you successfully logged in type the command:
use mysql;
It should show a message lượt thích 'Database changed' then type:
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
After that type:
UPDATE mysql.user phối authentication_string=PASSWORD('new-strong-password') where user='root';
Then type:
FLUSH PRIVILEGES;
Then simply exit:
quit
Now try to tướng log in with your new password in your WORKBENCH. Hope it will work. Thank you.
answered Apr 17, 2020 at 17:04
For my case, I found this error after fresh installation of mysql on Mac OS Big Sur.
What i did to tướng fix it was: I click on the táo bị cắn logo, go to tướng system preferences and then click on mysql.
There's an initialize database button on the opened settings window, I click on that, and then when I try to tướng access again, it's solved.
answered Apr 4, 2021 at 4:04
2
alter user 'root'@'localhost' identified with mysql_native_password by '$your_password$';
it worked for bầm.
note: use strong password
for example
alter user 'root'@'localhost' identified with mysql_native_password by 'root';
answered Mar 31, 2022 at 15:01
I faced this problem while installing Testlink on Ubuntu server, I followed these steps
mysql -u root
use mysql;
update user phối password=PASSWORD("root") where User='root';
flush privileges;
quit
Now stop the instance and start again i.e
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
radbyx
9,65022 gold badges89 silver badges133 bronze badges
answered Aug 4, 2018 at 6:57
Well the easiest way to tướng reset root password is:
restart mysqld --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to tướng use --skip-grant-tables in conjunction with --skip-networking to tướng prevent remote clients from connecting.
Connect to tướng the mysqld server with this command:
shell> mysql Issue the following statements in the mysql client. Replace the password with the password that you want to tướng use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass') -> WHERE User='root'; mysql> FLUSH PRIVILEGES;
Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options).
Source Mysql documentation and personal experience:
http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html
answered May 21, năm trước at 10:42
avijendravijendr
4,1332 gold badges34 silver badges46 bronze badges
In my case:
- I phối plugin authentication to tướng "" (empty) and I can't run rẩy mysql server:
SOLUTION:
- nano /etc/mysql/my.cnf
- edit:
[mysqld]
skip-grant-tables
- service mysql restart
- mysql -u root
- use mysql
- UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root'
- flush privileges
answered Apr 27, 2021 at 12:08
CecherzCecherz
561 silver badge7 bronze badges
I resolved the same issue by running Workbench as administrator.
...I guess it's because of restrictions on company computers, in my case...
answered Feb 28, 2018 at 12:17
MySQL mặc định password for root is assigned depending on the way you have installed MySQL.
If you have installed it from MySQL Yum repository, MySQL SUSE repository, or RPM packages directly downloaded from Oracle, you can obtain the password using following command:
sudo grep 'temporary password' /var/log/mysqld.log
answered Dec 15, 2020 at 13:50
nayan dhabardenayan dhabarde
2,3062 gold badges27 silver badges48 bronze badges
Try out the following steps to tướng overcome this issue:
- Open terminal / command prompt and navigate to tướng the bin thư mục of the MySQL installation thư mục. Then run rẩy the command
mysqld --console
. - If you can see that line
171010 14:58:22 [Note] --secure-file-priv
is phối to tướng NULL. Operations related to tướng importing and exporting data are disabled, after executing the above command from the command prompt. - Then you need to tướng kiểm tra that the
mysqld
is either blocked by the Windows Firewall or another program. - If it's blocked by Windows Firewall then need to tướng unblock from it and save settings.
- To unblock the
mysqld
ormysql
application, follow the below steps:- Go to tướng command prompt and type
wf.msc
to tướng open the firewall settings. - Click on Allow an tiện ích or feature through Windows Firewall.
- Check the
mysqld
ormysqld
instances are available in the list and kiểm tra the checkbox for the domain name, public and private and save the settings.
- Go to tướng command prompt and type
- Return to tướng the bin thư mục and try the command from step 1 again.
- It should work fine and not show any errors.
It should be possible to tướng run rẩy the MySQL console without any problems now!
answered Oct 10, 2017 at 9:42
I resolved the same issue using next sql and restarting MySQL server:
update mysql.user phối Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y'
where user='root';
answered Nov 11, 2017 at 19:39
I worked on Access Denied for User 'root'@'localhost' (using password: YES) for several hours, I have found following solution,
The answer to tướng this problem was that in the my.cnf located within
/etc/mysql/my.cnf
the line was either
bind-address = 127.0.0.1
(or)
bind-address = localhost
(or)
bind-address = 0.0.0.0
I should prefer that 127.0.0.1
I should also prefer 0.0.0.0, it is more flexible
because which will allow all connections
answered Nov 15, 2017 at 6:36
I don't think you have to tướng escape the --init-file
parameter:
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.6\\my.ini" --init-file=C:\\mysql-init.txt
Should be:
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.6\\my.ini" --init-file=C:\mysql-init.txt
answered Nov 30, 2017 at 2:19
JordanJordan
1582 silver badges13 bronze badges
for the above problem ur password in the system should matches with the password u have passed in the program because when u run rẩy the program it checks system's password as u have given root as a user ví gives u an error and at the same time the record is not deleted from the database.
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
class Delete
{
public static void main(String []k)
{
String url="jdbc:mysql://localhost:3306/student";
String user="root";
String pass="jacob234";
try
{
Connection myConnection=DriverManager.getConnection(url,user,pass);
Statement myStatement=myConnection.createStatement();
String deleteQuery="delete from students where id=2";
myStatement.executeUpdate(deleteQuery);
System.out.println("delete completed");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Keep ur system password as jacob234 and then run rẩy the code.
answered Feb 9, 2018 at 14:11
With bầm was the same problem, but it was caused, because i was using the mysql server on 32 (bit) and the workbench was running on 64(bit) version. the server and the workbench need to tướng has the same version.
xpress
answered Dec 16, 2018 at 16:24
I was facing the same problem when I'm trying to tướng connecting Mysql database using the Laravel application. I would lượt thích to tướng recommend please kiểm tra the password for the user. MySQL password should not have special characters lượt thích #, &, etc...
answered Mar 13, 2020 at 16:23
1
cause might be missing mysqld tệp tin in /var/run/mysqld
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables
sudo service mysql start
if tệp tin does not exits then create file
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
check now you are able to tướng login mysql -uroot -p123 otherwise do
sudo mysql -u root
use mysql;
show tables;
describe user;
update user phối authentication_string=password('1111') where user='root';
FLUSH PRIVILEGES;
exit;
mysql -uroot -p123
link - mysqld_safe Directory '/var/run/mysqld' for UNIX socket tệp tin don't exists
answered Jun 29, 2021 at 12:41
For windows:-
If the instance configuration fails with similar issue and if you cannot log in to tướng the root tài khoản.
Steps I followed to tướng fix the issue:-
- Stop MySql service if running.
- Uninstall MySql using 'remove' option from the installation wizard.
- If MySql service is not removed from services,
sc delete
- Delete all data containing in the MySql thư mục ('Program files', 'Program data' or the custom installation directory you have given).
- Remove MySql path from the environmental variable.
- Disable windows firewall.
- Reinstall and config root tài khoản with new password.
answered Jun 30, 2022 at 9:55
the only thing that worked was sudo mysql
followed by adding skip-grant-tables
in [mysqld] section of /etc/my.cnf tệp tin - Ubuntu Mysql 5.5
answered Jan 25, 2023 at 9:25
Please tự crosscheck your password from your phpmyadmin login webpage on localhost, if its correct, then it will work without tempering with yoru credentials
answered Jul 10, 2023 at 20:26
Error : Access denied for user 'sa'@'Developer' (using password: YES)
By using the Create User feature and accessing all privileges on the MySQL server, I was able to tướng resolve the same problem.
Create user 'sa'@'Developer' identified by 'developer@123';
Grant all privileges on * . * to tướng 'sa'@'Developer';
Flush privileges;
Same issue occurred with bầm also, turned out my db username was wrong
answered Jul đôi mươi, 2022 at 6:04
alphcoderalphcoder
1301 silver badge10 bronze badges