When I try to run mysql database using following command without password
mysql -u root -p
It says following error
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
But I can connect database using this command without password
sudo mysql -u root -p
But if I try to connect database using php I am getting the same error messages saying
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
How should I solve this problem?
PHP code for connecting with database is
<?php
/* Attempt MySQL server connection.
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "","dbName");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Print host information
echo "Connect Successfully. Host info: " . mysqli_get_host_info($link);
?>
I got solution from stack overflow and did the same as it suggested but it didn't work for me. The link which suggested the answer is This link has similar question related to me