Jump to content

MySQL "Connect Error (1045) Access denied" with SSL


BigBill

Recommended Posts

Hello,

I have a very frustrating problem. I have some php code that needs to connect to a MySQL database on another server. The connection needs to be through SSL.

 

When I go to connect I get this error message:

Connect Error (1045) Access denied for user 'WebUser'@'mydomain.com' (using password: YES)

 

I have checked that I can log in with WebUser using another client program.

 

I am worried that PHP is not finding my SSL certificates. For testing purposes I am running the PHP server from my windows machine, and have the path for the certificates as "C:\temp\client-key.pem" etc. Does anyone else think this is the problem?

Link to comment
Share on other sites

OK, I have found that it isn't the location of the SSL certificates. When I change the path to something that doesn't exist I get an error saying "SSL certificate error", so that rules that out.

 

But I am still having no luck. In desperation, I uploaded the code to my web server and tried it out there. Now things are even more confusing. When I try to run the page it just hangs and doesn't open at all - not even if I leave it for 15 minutes.

 

Here is the code:

 

define ("HOST","mydomain.com");
define ("USER","WebUser");
define ("PASSWORD","password");
define ("DATABASE","Database");	

echo phpinfo();

$mysqli = mysqli_init();

if (!$mysqli) {
    die('mysqli_init failed');
}

$mysqli->ssl_set('/etc/ssl/client-key.pem','/etc/ssla/client-cert.pem', '/etc/ssla/ca-cert.pem',NULL,NULL);

if (!$mysqli->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
    die('Setting MYSQLI_INIT_COMMAND failed');
}

if (!$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
    die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
}

if (!$mysqli->real_connect(HOST, USER, PASSWORD, DATABASE, NULL, NULL, MYSQLI_CLIENT_SSL)) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

 

If I remove the MYSQLI_CLIENT_SSL flag I get the error message "Connect Error (1045) Access denied". If I put the flag in the page just hangs and never loads.

 

What could be wrong? I mean, this code was copied and pasted straight out of the PHP documentation!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.