I am having some connection problems with MySQL users when trying to connect directly to a database. This came up when trying to use mysqli_connect in PHP.
$dbc=mysqli_connect('127.0.0.1', 'test_user', 'test_password', 'test_database');
To verify that the user is setup correctly in MySQL; from the linux shell;
If I specify the database : mysql -h 127.0.0.1-u test_user -ptest_password test_database The connection fails
If I don't Specify the database: mysql -h 127.0.0.1 -u test_user -ptest_password
Connection Succeeds
Here is the OS and MySQL information
- mysql Ver 14.14 Distrib 5.1.61, for redhat-linux-gnu (i386) using readline 5.1
- CentOS release 6.3 (Final)
- Plesk 11 install
- MySQL is listening on all addresses
Using the Plesk Control Planel, I have created a user test_user that has access to a database test_database.
SHOW GRANTS FOR 'test_user'@'%'
Grants for test_user@%
GRANT USAGE ON *.* TO 'test_user'@'%'
IDENTIFIED BY PASSWORD '*0319BFCC3B30D01FD6CE82075F9A6AAC6E8E6570'
GRANT ALL PRIVILEGES ON `test\_database`.* TO 'test_user'@'%'
On another MySQL 5.1 server that was installed via yum on Centos 6, I am able to connect directly to the database
mysql -h 127.0.0.1 -u test_user -ptest123 test_database
The my.cnf file on both the plesk server and other server don't have any additional options other than the defaults.
Question:
What would prevent a user from connecting directly to his/her database in MySQL?
mysql -h 127.0.0.1 -u test_user -ptest123 test_database
as opposed to
mysql -h 127.0.0.1 -u test_user -ptest123