I am using My SQL 5.6.31 on RHEL 7.2 and PHP 5.5. Here are some issues I am facing in the following scenarios:
Scenario #1 (Adding User via command line which works fine with PHP Code)
There is a database called practiceDB
. I used Use practiceDB
command to select the database and created a user using the command
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'mypass';
Connection Test Via PHP Code:
So, when I connect via my PHP code and specify user jeffrey
and password mypass
in my PHP files, I can connect to the database without any problem.
Connection Test Via Command Line:
Also, when I log in like the following from linux shell mysql -u jeffrey -pmypass
, I can get the mysql prompt and running Show databases
command lists practiceDB
database.
Scenario #2: (When my PHP Code is creating user and adding it to database)
Connection Test Via PHP Code:
The user gets created and inserted into the users
table of practiceDB
database. However, when I try to connect using the same user (say for example I used peter
as username), I keep on getting the following error in my logs:
[:error] [pid 22866] [client ] PHP Fatal error: Could Not Connect to the Database : Access denied for user 'peter'@'localhost' (using password: YES) in /var/www/dbonn.php on line ##, referer: ....
The reason for above error as I can see is there is no password I have specified/hardcoded as I did in Scenario #1 for user jefferey
. Basically, I don’t want to specify password at all, even for user jeffrey
, Is there a way to achieve this?
Connection Test Via Command Line:
When I try to log in like this, mysql -u peter
, I can get into the mysql prompt and upon running the show database
command , I see information-schema
database selected which is default I believe. So basically, it has nothing to do with the practiceDB
where user was inserted using the PHP Code.