简体   繁体   中英

MySQL Access Denied Revisited

I have read and analyzed countless questions and answers centered around the following error message:

"Access denied for user 'root'@'localhost' (using password: YES)."

Most of them deal with missing/forgotten/corrupted passwords and there's lots of suggestions on how to fix the problem. Yet, none of them seem to apply to my situation but that hasn't stopped me from trying everything.

History:

I installed LAMP on my Ubuntu 17.10, which I'm new to having finally given up on Windows and WAMP. MySQL was installed with a 'root' password, which I can use to login to phpMyAdmin and MySQL-Workbench where I am unrestricted in what I can do. Everything works great and I don't receive any errors. Apache also functions correctly and I have populated the system with a few current web projects that all function under 'localhost' as expected.

Finally, today I tried to bring up a project that uses PHP to access MySQL, which is something I've coded hundreds of times yet under Ubuntu I can't get past the above error generated by a mysqli_connect() request. I've changed passwords, created other users, fiddled with IP addresses, etc. and everything works great and as expected in phpMyAdmin and MySQL Workbench but not when using PHP.

There has to be a simple explanation for this but I'm not fluent enough with Linux to know what that is.

I'm hoping someone can recommend something to try.

Settings:

Database server

Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.7.21-0ubuntu0.17.10.1 - (Ubuntu)
Protocol version: 10
User: root@localhost
Server charset: UTF-8 Unicode (utf8)

Web server

Apache/2.4.27 (Ubuntu)
Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $
PHP extension: mysqliDocumentation curlDocumentation mbstringDocumentation
PHP version: 7.1.15-0ubuntu0.17.10.1

phpMyAdmin

Version information: 4.6.6deb5

SOLVED

As I said, I'm new to Linux and the default user security features take some getting used to. Apparently, my user name and password (as root?) were used to restrict access to three MySQL folders under /var/lib when I installed MySQL.

Once I figured that out I constructed a MySQL user in phpMyAdmin using that same name/pass and suddenly all my backend routines worked. Maybe this is related to installing MySQL using a password for root, but I'm confused as to why my root/pass works in phpMyAdmin but not from code.

Surely there's a simple explanation for all of this and maybe someone can explain it. But for now, if you're someone like me whose knowledge of Linux is lacking and you have this problem hopefully this will work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM