简体   繁体   中英

MySQL/phpMyAdmin - Only root user can log in

I've been having some issues trying to log in as non-root users from a .php file onto phpMyAdmin.

I've set up a login form that uses the root user to check if the login that someone uses matches an entry in the mysql.User table and then stores the username and password as session variables which I'm using to try and log in to MySQL and perform user specific tasks later.

This is the code I'm having issues with:

$host = "localhost"; // Host name 
$username = $_SESSION['myusername']; // Mysql username 
$password = $_SESSION['mypassword']; // Mysql password 
$db_name = "gcim"; // Database name 
$tbl_name = "permissions"; // Table name 

// Create connection
$conn = new mysqli($host, $username, $password, $db_name);

myusername and mypassword are just the session variables I've stored and they're set to the values exactly how they should be, "gcim" is the database I'm trying to access and "permissions" is the table

Trying to execute the code results in the following:

Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'BUT03'@'localhost' (using       password: YES) in C:\xampp\htdocs\gcim\permissions\permissions.php on line 12
Connection failed: Access denied for user 'BUT03'@'localhost' (using password: YES)

I'm pretty sure that the issue isn't a wrong hostname, username or password because even if I change the connection line to:

$conn = new mysqli("localhost", "BUT03", "test", "gcim");

it still gives me the same error

Here's the setup of my mysql.User table: http://puu.sh/dDxd3/5e25f315f4.png

Anyway, any help would be very much appreciated, Thanks

EDIT: I've been experimenting and I've come to the conclusion that the ONLY way to get a successful login to MySQL is using the root account with no password, any attempt to log in with a password will give me the same error, as well as removing the password from a non-root account and trying to log in with no password which gives me the following error: Connection failed: Access denied for user ''@'localhost' to database 'gcim'

I have a feeling that there's some issue with the server settings, was I meant to change anything from the default phpMyAdmin settings?

EDIT: I just tried to log in to phpMyAdmin itself as 'BUT03'@'localhost' and I appear to have no privileges at all even though everywhere I can see I've granted all possible privileges to that account, could this be affecting anything and does anyone know what could be causing it?

I assume passowrds are saved not in plain text, but hashed. That would mean your hashed password is 'test', and you actual password is something unknown. Change your password to test with this function

 SET PASSWORD FOR 'BUT03'@'localhost' = PASSWORD('test');

see: http://dev.mysql.com/doc/refman/5.0/en/set-password.html

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