MySQL error 3159: connections using insecure transport are prohibited
3159 (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.
Fix it fast
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';2Match what you see, then jump to its fix
- 1
ssl_disabled=True in the connect call or config dictThe client code turns TLS offFix - 2
Client asks for TLS but the server was started without valid certificate filesThe server has no TLS certificate files, so TLS cannot startFix - 3
Host 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
- 1
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
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
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
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:
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
Related fixes
Databases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Django cannot load MySQLdb and asks whether mysqlclient is installed
Error loading MySQLdb module: Did you install mysqlclient or MySQL-python?
Django's MySQL backend imports MySQLdb, which is provided by the mysqlclient package.
3 causes, each with a fixDatabases
python manage.py migrate finishes but the tables for my app are missing
relation "myapp_book" does not exist
migrate only applies migration files that exist.
3 causes, each with a fixDatabases
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 fixDatabases
pip install mysqlclient fails to build on Windows, Linux or macOS
error: metadata-generation-failed
mysqlclient is a C extension.
3 causes, each with a fixDatabases
pandas read_sql fails with Execution failed on sql ... sqlite_master on a MySQL connection
Execution failed on sql 'SELECT name FROM sqlite_master WHERE type='table' AND name=?;'
pandas supports a plain DBAPI connection only for sqlite3.
3 causes, each with a fix