I am migrating my site from classic linux to cpanel linux. I keep running into unexpected issues. cpanel uses higher versions of php (from 5.3 to 7.2) and mysql (from 5.5 to 5.6), which call for some code modifications (such as conversion of mysql_connect to mysqli_connect).
To get started, I made a backup of my database in classic, created a database with the same name user and password incpanel, then imported the contents of the backup. Now I am failing to connect in the new version:
$db_host = "localhost"; $db_user = "my_db"; $db_pass = "my_pass"; $db_name = "my_db"; $link = mysqli_connect($db_host,$db_user,$db_pass,$db_name);
At this point mysqli_connect_errno() returns error 1044, which is
Error number: 1044; Symbol: ER_DBACCESS_DENIED_ERROR; SQLSTATE: 42000
Message: Access denied for user '%s'@'%s' to database '%s'
I am able to connect using these same credentials from the command line:
user@machine [~]$ mysql -h localhost -u my_db -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1310627 Server version: 5.6.43-cll-lve MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (none)>
So this tells me the host/database/password work. But I can't establish a connection using the snippet of code above in php.
What am I missing? It doesn't seem like this should be so hard!
Solved! Go to Solution.
Did you grant permissions to the user to the database - in your screen capture you show that you connected to MySQL but didn't select the database.
My guess is if you grant permissions to the database to the user you should be good to go
Once your issue is resolved,
please be sure to come back and click accept for the solution