Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

MySQL error 3159: connections using insecure transport are prohibited

Error3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.

Short answer

Error 3159 means the server has require_secure_transport turned on and your client connected over plain TCP. Connect with TLS (leave ssl_disabled False in mysql-connector-python), use the local socket file, or, if the policy is not needed, turn the variable off on the server.

  • Applies to MySQL 8.4, mysql-connector-python 9.x, Python 3.12
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Ask the server whether the policy is on. If it returns ON, plain TCP clients are refused.

    SHOW VARIABLES LIKE 'require_secure_transport';
  2. 2Match what you see, then jump to its fix

    1. 1ssl_disabled=True in the connect call or config dictThe client code turns TLS offFix
    2. 2Client asks for TLS but the server was started without valid certificate filesThe server has no TLS certificate files, so TLS cannot startFix
    3. 3Host is 127.0.0.1 or localhost on the same machine as MySQLThe app runs on the database host and can use the socket fileFix

What does the error look like?

  • 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
  • ER_SECURE_TRANSPORT_REQUIRED

Cause 1 of 3

The client code turns TLS off

1Check

In mysql-connector-python, ssl_disabled defaults to False. Search your code and config for a setting that disables it.

grep -rn "ssl_disabled" .

2Fix

Remove ssl_disabled=True, or set it to False, so the connector asks the server for an encrypted connection.

import mysql.connector
cnx = mysql.connector.connect(
    host="db.example.com",
    user="app",
    password="...",
    database="mydb",
    ssl_disabled=False,
)

3Verify

The connection opens.

print(cnx.is_connected())

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 3

The server has no TLS certificate files, so TLS cannot start

1Check

The server enables encrypted connections only if it finds valid ca.pem, server-cert.pem and server-key.pem in its data directory, or you configure them.

SHOW VARIABLES LIKE '%ssl%';

2Fix

Provide valid certificate and key files (or let a build with OpenSSL generate them at start), then restart the server. Clients can then verify with ssl_ca and ssl_verify_cert=True.

cnx = mysql.connector.connect(
    host="db.example.com", user="app", password="...",
    ssl_ca="/path/ca.pem", ssl_verify_cert=True,
)

3Verify

The connection succeeds over TLS.

print(cnx.is_connected())

Confirmed by dev.mysql.com

Did this fix it?

Cause 3 of 3

The app runs on the database host and can use the socket file

1Check

With the policy on, the server accepts TCP only with TLS, but it still allows a socket file on Unix and shared memory on Windows.

SHOW VARIABLES LIKE 'socket';

2Fix

Connect through unix_socket instead of host and port.

cnx = mysql.connector.connect(
    user="app", password="...", database="mydb",
    unix_socket="/var/run/mysqld/mysqld.sock",
)

3Verify

The connection opens without TLS settings.

print(cnx.is_connected())

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Keep the TLS setting in one shared connection config, not scattered in scripts.
  • Test new clients against a server with require_secure_transport on, as production does.
  • Change the variable with SET PERSIST so it survives restarts, and tell your team.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Databases

pip install mysqlclient fails on a Mac

The build output mentions pkg-config or the MySQL client library

mysqlclient is a C extension, so pip compiles it against the MySQL client library and finds that library with pkg-config.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.