I am sure they are passwords to different things but i am not sure what. When in terminal to connect to MySQL I enter /usr/LOCAL/mysql/BIN/mysql -h host -u username -p
I am then prompted for a password and the password is ''
. But when connecting to MySQL with PHP I use the following code and it works
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_USER', 'root');
DEFINE('DB_PASS', 'root');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASS,) or
die('could not connect: '. mysqli_connect_error() );
If i were to use DEFINE('DB_PASS', '');
it returns "Access denied for user 'root'@'localhost' (using password: NO)", why does there appear to be two separate passwords?
Q: Why does there appear to be two separate passwords?
A: Because you are connecting as two different users.
Each user has its own password and privileges.
A MySQL database "user" is identified by two parts: the user name and the host.
For example, these are three distinct users:
'username'@'localhost'
'username'@'127.0.0.1'
'username'@'%'
To view the users defined on your database, you can query mysql.user
table, e.g.
SELECT user, host FROM mysql.user ;
You might want to review the relevant section of the MySQL Reference Manual.
Reference: https://dev.mysql.com/doc/refman/5.5/en/adding-users.html
NOTE: A value localhost
in the mysql.user
table or a connection is not synonymous with the TCP loopback address (127.0.0.1). It does not resolve to that IP address, or any other IP address. It's a special value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With