0
0
MySQLquery~5 mins

Secure connection (SSL) in MySQL

Choose your learning style9 modes available
Introduction

Secure connections protect your data when it travels between your computer and the database. SSL (Secure Sockets Layer) helps keep your information safe from others who might try to see it.

When you connect to a database over the internet and want to keep your data private.
When your company requires encrypted connections for all database access.
When you handle sensitive information like passwords or personal details.
When you want to prevent hackers from intercepting your database traffic.
When using public Wi-Fi and connecting to a remote database.
Syntax
MySQL
mysql --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem -u username -p
Use the --ssl-ca option to specify the Certificate Authority file.
Use --ssl-cert and --ssl-key to provide your client certificate and key.
Examples
Connects using the CA certificate to verify the server, but no client certificate.
MySQL
mysql --ssl-ca=ca.pem -u user -p
Connects with full SSL using CA, client certificate, and client key for stronger security.
MySQL
mysql --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem -u user -p
Forces SSL connection if the server supports it, without specifying certificates.
MySQL
mysql --ssl-mode=REQUIRED -u user -p
Sample Program

This command connects to the MySQL server using SSL with the specified certificates to secure the connection.

MySQL
mysql --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem -u testuser -p
OutputSuccess
Important Notes

Make sure your MySQL server is configured to support SSL connections.

Certificates must be valid and trusted by both client and server.

Using --ssl-mode=REQUIRED is a simple way to enforce SSL without managing certificates.

Summary

SSL encrypts data between your computer and the database to keep it safe.

You provide certificates to verify identities and secure the connection.

Use SSL options in your MySQL client command to connect securely.