I pulled this directly off php.net
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "
";
$mysqli = new mysqli("127.0.0.1", "user", "password", "database", 3306);
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
echo $mysqli->host_info . "
";
my output is like so:
Localhost via UNIX socket
My question is... why am i getting an error message when i try to use the second method.
Failed to connect to MySQL: (1045) Access denied for user '*'@'127.0.0.1' (using password: YES)
Ensure that skip-networking is commented out in your conig file. Also look into your users table and see if "user" is allowed to connect from 127.0.0.1
Go to terminal and type: (login as root user)
mysql -i -u root
Let’s start by making a new user within the MySQL shell (if you do not have (*) user at 127.0.0.1 host):
CREATE USER '*'@'127.0.0.1' IDENTIFIED BY 'password';
Then you've to type the following: (give (*) user permission to access database)
GRANT ALL PRIVILEGES ON * . * TO '*'@'127.0.0.1';
Once you have finalized the permissions that you want to set up for your new users, always be sure to reload all the privileges:
FLUSH PRIVILEGES;
Your changes will now be in effect.
How To Grant Different User Permissions Here is a short list of other common possible permissions that users can enjoy.
ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)