# Receive "Bad handshake" error when connect MSQL in Azure from custom database section

**URL:** <https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654>\
**Category:** Get Help\
**Tags:** login, auth0\
**Created:** [November 5, 2021, 1:28am UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654 "2021-11-05T01:28:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tianjun.zhou](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tianjun.zhou/32/13269_2.png) [@tianjun.zhou](https://community.auth0.com/u/tianjun.zhou)\
**Post date:** [November 5, 2021, 1:28am UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/1 "2021-11-05T01:28:06Z")

</div>

When I use Login script in database action scripts, MySQL cannot be connected.

My node code is as follows:

```javascript
function login(userName, password, callback) {
  const mysql = require('mysql');
  const bcrypt = require('bcrypt');
  const azureCa = "...";

  const connection = mysql.createConnection({
    host: '...',
    port: '3306',
    user: '...',
    password: '...',
    database: '...',
    ssl: {
      ca: azureCa,
      rejectUnauthorized: false
    },
    insecureAuth: true
  });

  connection.connect();

  const query = 'SELECT id, username, password FROM tb_user WHERE username = ?';

  connection.query(query, [userName], function(err, results) {
    if (err) return callback(err);
    if (results.length === 0) return callback(new WrongUsernameOrPasswordError(userName));
    const user = results[0];

    bcrypt.compare(password, user.password, function(err, isValid) {
      if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(user));

      return callback(null, {
        user_id: user.id,
        username: user.username
      });
    });
  });
}

```

Error returned:

```auto
ER_HANDSHAKE_ERROR: Bad handshake

```

Do I need to add any configuration or do some action to solve this problem?

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 15, 2021, 9:37pm UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/3 "2021-11-15T21:37:07Z")

</div>

Hi @tianjun.zhou,

It looks like another user solved a similar issue by hardcoding the cert. Here is the related topic with more info:

> [@Connect mysql in azure from custom database with node.js](https://community.auth0.com/t/connect-mysql-in-azure-from-custom-database-with-node-js/16358/2):
>
> Hey there! Sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes the number of incoming questions is just too big for our bandwidth. Sorry for such inconvenience! Do you still require further assistance from us?

---

<div class="post-metadata">

**Author:** ![tianjun.zhou](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tianjun.zhou/32/13269_2.png) [@tianjun.zhou](https://community.auth0.com/u/tianjun.zhou)\
**Post date:** [November 16, 2021, 2:00am UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/4 "2021-11-16T02:00:36Z")

</div>

Hi @dan.woda ,  
Thank you for your reply. However, the code I showed above has already hardcoded the cert according to the solution of issue provided by you, but it still reports an error: bad handshake.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 16, 2021, 9:30pm UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/5 "2021-11-16T21:30:45Z")

</div>

Can you please provide an example (scrubbed of sensitive info) of the formatting you are using for the cert?

---

<div class="post-metadata">

**Author:** ![tianjun.zhou](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tianjun.zhou/32/13269_2.png) [@tianjun.zhou](https://community.auth0.com/u/tianjun.zhou)\
**Post date:** [November 17, 2021, 12:51am UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/6 "2021-11-17T00:51:12Z")

</div>

“-----BEGIN CERTIFICATE-----\nMIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n…\nCAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n-----END CERTIFICATE-----\n”

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 23, 2021, 9:09pm UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/7 "2021-11-23T21:09:25Z")

</div>

Have you tried connecting to your DB from a node app? That can help us narrow this to the MySQL server config or the Auth0 Custom DB script.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 8, 2021, 9:09pm UTC](https://community.auth0.com/t/receive-bad-handshake-error-when-connect-msql-in-azure-from-custom-database-section/72654/8 "2021-12-08T21:09:57Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
