Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL has two different passwords?

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?

like image 378
Justin O'Brien Avatar asked Feb 11 '23 03:02

Justin O'Brien


1 Answers

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.

like image 76
spencer7593 Avatar answered Feb 12 '23 18:02

spencer7593