Access denied for root user @localhost mysql error 1045

I am new to PHP. When running my application, the following error appears:

In phpMyadmin, the code is as follows

$cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = ''; $cfg['Servers'][$i]['AllowNoPasswordRoot'] = true; 

As I already did, I changed the above code to

 $cfg['Servers'][$i]['auth_type'] = 'config'; $cfg['Servers'][$i]['user'] = 'root'; $cfg['Servers'][$i]['password'] = 'Pass123'; $cfg['Servers'][$i]['AllowNoPasswordRoot'] = true; 

Now I get the following error

Access denied for user 'root' @ 'localhost' (using password: YES) MySQL error #: 1045

Please let me know what is wrong here.

+4
source share
7 answers

Having lost most of the day on this issue, it turned out that all I had to do was provide a non-localhost hostname. I donโ€™t know why (the user is allowed to connect from any host), but it works!

 root@base :~# mysql -u username -h hostname -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. 

And in PHP:

 Test 1807: <?php $username = "username"; $password = "password"; $hostname = "actualhostnamenotlocalhost"; $con = mysqli_connect($hostname, $username, $password); // Check connection if (mysqli_connect_errno($con)){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_close($con); ?> OK. 
+2
source

No one here mentioned this (for one reason or another), the owner assigned to your user may be mistaken. When it says root@localhost , it means the root with the localhost host.

On some servers, by default, root may not be on localhost . Try the following:

root@127.0.0.1

root@ [yourhostname]

+1
source

Please check the password you entered here.

These errors occur when the password does not match the original password.

0
source

make sure you set a password for mysql

0
source

To reset youre password, please go to this page http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

0
source

There may be a problem with the MySQL server and the port on which it is running. The default value is 3306. If this does not work, change the port in my.ini (รณr, regardless of the mysql-ini file name), and also change the port link in config.inc.php in the phpmyadmin folder.

So the error explained here (Gnanendra)

Access denied for user 'root' @ 'localhost' (using password: YES) MySQL error #: 1045

may be set because the MySQL server is not running correctly.

Also check this post for more information on this issue:

Cannot start server: bind to TCP / IP port: no such file or directory

0
source

Make sure the password is correct (cover lock?) And possibly use a raw IP address, i.e. 127.0.0.1

0
source

Source: https://habr.com/ru/post/1346658/


All Articles