SSL(Secure Sockets Layer 安全套接层),是为网络通信提供安全及数据完整性的一种安全协议,其利用公开密钥数据加密(Encryption)技术,确保数据在网络上之传输过程中不会被截取及窃听。 SSL协议提供的服务主要有: 认证用户和服务器,确保数据发送到正确的客
SSL(Secure Sockets Layer 安全套接层),是为网络通信提供安全及数据完整性的一种安全协议,其利用公开密钥数据加密(Encryption)技术,确保数据在网络上之传输过程中不会被截取及窃听。
SSL协议提供的服务主要有:
认证用户和服务器,确保数据发送到正确的客户机和服务器;
加密数据以防止数据中途被窃取;
维护数据的完整性,确保数据在传输过程中不被改变。
为了在MySQL服务器和客户端之间建立SSL联接,服务器系统必须满足:
操作系统安装有OpenSSL或yaSSL;
安装的MySQL版本必须支持SSL。
这里使用OpenSSL。
一、检查是否满足要求:
shell>rpm -qa | grep openssl #检查是否安装OpenSSL。MySQL需要openssl的共享库。
openssl-1.0.0-20.el6.x86_64
openssl-devel-1.0.0-20.el6.x86_64
openssl098e-0.9.8e-17.el6.x86_64
mysql> show global variables like ‘have%ssl’;
#检查是否支持ssl。NO表示不支持,DISABLE表示支持但未使用。
+—————+———-+
| Variable_name | Value |
+—————+———-+
| have_openssl | DISABLED |
| have_ssl | DISABLED |
+—————+———-+
2 rows in set (0.00 sec)
如果是使用编译好的二进制,那默认都支持,如果自行编译,针对5.5版本,需要使用cmake . -DWITH_SSL=system选项。
为使客户端能够使用SSL方式进行连接,需要配置合适的证书和密钥文件,以及为用户授予合适的权限。
在mysql启动配置文件my.cnf的[mysqld]这段加上ssl,如果mysqldump备份要使用ssl连接,则要在[mysqldump]段里面也记得加上ssl,然后重启启动数据库,使用上面的命令mysql> show global variables like ‘have%ssl’;查看就发现状态变成yes了,说明已经开启了ssl安全连接。
二、为MySQL生成证书和密钥
shell>mkdir -p /db/ssl
shell>cd /db/ssl
#以下创建认证机构的数字认证证书,后续服务器端和客户端的证书都使用该认证机构进行签署。
shell>openssl genrsa 2048 > ca-key.pem
Generating RSA private key, 2048 bit long modulus
………+++
…………………………………………………………………………………………………..+++
e is 65537 (0×10001)
shell>openssl req -new -x509 -nodes -days 3600 -key ca-key.pem -out ca-cert.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:Shanghai
Locality Name (eg, city) [Newbury]:Shanghai
Organization Name (eg, company) [My Company Ltd]:CA
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:
Email Address []:
#以下创建服务器端证书
shell>openssl req -newkey rsa:2048 -days 3600 -nodes -keyout server-key.pem -out server-req.pem
Generating a 2048 bit RSA private key
……………….+++
…………+++
writing new private key to ‘server-key.pem’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:Shanghai
Locality Name (eg, city) [Newbury]:Shanghai
Organization Name (eg, company) [My Company Ltd]:CH
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:mysqlserver
Email Address []:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:abc123
An optional company name []:
shell>openssl rsa -in server-key.pem -out server-key.pem #移除server-key中的passphrase【可选】
writing RSA key
shell>openssl x509 -req -in server-req.pem -days 3600 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem #签署服务端证书
Signature ok
subject=/C=CN/ST=Shanghai/L=Shanghai/O=CH/CN=mysqlserver
Getting CA Private Key
#以下创建客户端证书
shell>openssl req -newkey rsa:2048 -days 3600 -nodes -keyout client-key.pem -out client-req.pem
Generating a 2048 bit RSA private key
………………………………………………………………………………………+++
…+++
writing new private key to ‘client-key.pem’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [GB]:CN
State or Province Name (full name) [Berkshire]:Shanghai
Locality Name (eg, city) [Newbury]:Shanghai
Organization Name (eg, company) [My Company Ltd]:CH
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server’s hostname) []:mysqlclient
Email Address []:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:abc123
An optional company name []:
shell>openssl rsa -in client-key.pem -out client-key.pem #移除client-key中的passphrase【可选】
writing RSA key
shell>openssl x509 -req -in client-req.pem -days 3600 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem #签署客户端证书
Signature ok
subject=/C=CN/ST=Shanghai/L=Shanghai/O=CH/CN=mysqlclient
Getting CA Private Key
#生成完毕后,验证下
shell>openssl verify -CAfile ca-cert.pem server-cert.pem client-cert.pem
server-cert.pem: OK
client-cert.pem: OK
经过上述步骤,就生成了如下文件:
ca-cert.pem在服务器端和客户端都是用–ssl-ca=ca-cert.pem
server-cert.pem,server-key.pem 服务器端指定–ssl-cert=server-cert.pem和–ssl-key=server-key.pem
client-cert.pem,client-key.pem 客户端指定–ssl-cert=client-cert.pem和–ssl-key=client-key.pem
三、配置SSL连接
如下两种方案均可以实现使用SSL进行配置和赋权。
【方案一】
Server:
在服务器端的配置文件my.cnf中添加如下参数:
[mysqld]
ssl-cert=/db/ssl/server-cert.pem
ssl-key=/db/ssl/server-key.pem
重启mysqld。
用户赋权,用GRANT语句的REQUIRE SSL选项
如:
mysql>create user user@localhost identified by ‘abc’;
mysql>grant select on testdb.* to user@localhost require ssl;
Client:
mysql -u user -pabc -P 3300 –ssl-ca=ca-cert.pem
【方案二】
Server:
在服务器端的配置文件my.cnf中添加如下参数:
[mysqld]
ssl-ca=/db/ssl/ca-cert.pem
ssl-cert=/db/ssl/server-cert.pem
ssl-key=/db/ssl/server-key.pem
重启mysqld。
用户赋权,用GRANT语句的REQUIRE x509选项
如:
mysql>create user user@localhost identified by ‘abc’;
mysql>grant select on testdb.* to user@localhost require x509;
Client:
mysql -u user -pabc -P 3300 –ssl-ca=ca-cert.pem –ssl-key=client-key.pem –ssl-cert=client-cert.pem
显然方案二的验证要求更严格,需要指定key和cert。
四、检查
配置完成后,可以如下方式查看自身对ssl的支持:
mysql> show global variables like ‘%ssl%’; #查看服务器是否支持SSL连接
+—————+————————-+
| Variable_name | Value |
+—————+————————-+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /db/ssl/ca-cert.pem |
| ssl_capath | |
| ssl_cert | /db/ssl/server-cert.pem |
| ssl_cipher | |
| ssl_key | /db/ssl/server-key.pem |
+—————+————————-+
7 rows in set (0.00 sec)
mysql> SHOW STATUS LIKE ‘Ssl_cipher’; #查看本连接是否是SSL加密的连接
+—————+——————–+
| Variable_name | Value |
+—————+——————–+
| Ssl_cipher | DHE-RSA-AES256-SHA |
+—————+——————–+
1 row in set (0.00 sec)
附:SSL协议的工作方式简介
客户端要收发几个握手信号:
发送一个“ClientHello”消息,说明它支持的密码算法列表、压缩方法及最高协议版本,也发送稍后将被使用的随机数。
然后收到一个“ServerHello”消息,包含服务器选择的连接参数,源自客户端初期所提供的“ClientHello”。
当双方知道了连接参数,客户端与服务器交换证书(依靠被选择的公钥系统)。这些证书通常基于X.509,不过已有草案支持以OpenPGP为基础的证书。
服务器请求客户端公钥。客户端有证书即双向身份认证,没证书时随机生成公钥。
客户端与服务器通过公钥保密协商共同的主私钥(双方随机协商),这通过精心谨慎设计的伪随机数功能实现。结果可能使用Diffie-Hellman交换,或简化的公钥加密,双方各自用私钥解密。所有其他关键数据的加密均使用这个“主密钥”。
参考:
http://baike.baidu.com/view/16147.htm
http://zh.wikipedia.org/zh-cn/SSL
http://linux.chinaitlab.com/safe/731541.html
http://www.sqlparty.com/mysql%E9%85%8D%E7%BD%AEssl/
使用过程中的报错:
验证秘钥:
Shell> openssl verify -CAfile ca-cert.pem server-cert.pem client-cert.pem
server-cert.pem: C = IN, ST = KERALA, L = COCHIN, O = ABCD, OU = OPERATIONAL, CN = SATHISH, emailAddress = salley@126.com
error 18 at 0 depth lookup:self signed certificate
OK
client-cert.pem: C = IN, ST = KERALA, L = COCHIN, O = ABCD, OU = OPERATIONAL, CN = sathish, emailAddress =?salley@126.com
error 18 at 0 depth lookup:self signed certificate
OK
在客户端登陆发现报错:ERROR 2026
最后发现Common Name在server端和client的配置不能用一样的,一样的就会报错,连接不上,只要设置不同的Common Name就可以连接了。
见一下参考:
Whatever method you use to generate the certificate and key files, the Common Name value used for the server and client certificates/keys must each differ from the Common Name value used for the CA certificate. Otherwise, the certificate and key files will not work for servers compiled using OpenSSL
原文地址:MySQL配置SSL安全连接, 感谢原作者分享。

웹 응용 프로그램에서 MySQL의 주요 역할은 데이터를 저장하고 관리하는 것입니다. 1. MySQL은 사용자 정보, 제품 카탈로그, 트랜잭션 레코드 및 기타 데이터를 효율적으로 처리합니다. 2. SQL 쿼리를 통해 개발자는 데이터베이스에서 정보를 추출하여 동적 컨텐츠를 생성 할 수 있습니다. 3.mysql은 클라이언트-서버 모델을 기반으로 작동하여 허용 가능한 쿼리 속도를 보장합니다.

MySQL 데이터베이스를 구축하는 단계에는 다음이 포함됩니다. 1. 데이터베이스 및 테이블 작성, 2. 데이터 삽입 및 3. 쿼리를 수행하십시오. 먼저 CreateAbase 및 CreateTable 문을 사용하여 데이터베이스 및 테이블을 작성한 다음 InsertInto 문을 사용하여 데이터를 삽입 한 다음 최종적으로 SELECT 문을 사용하여 데이터를 쿼리하십시오.

MySQL은 사용하기 쉽고 강력하기 때문에 초보자에게 적합합니다. 1.MySQL은 관계형 데이터베이스이며 CRUD 작업에 SQL을 사용합니다. 2. 설치가 간단하고 루트 사용자 비밀번호를 구성해야합니다. 3. 삽입, 업데이트, 삭제 및 선택하여 데이터 작업을 수행하십시오. 4. Orderby, Where and Join은 복잡한 쿼리에 사용될 수 있습니다. 5. 디버깅은 구문을 확인하고 쿼리를 분석하기 위해 설명을 사용해야합니다. 6. 최적화 제안에는 인덱스 사용, 올바른 데이터 유형 선택 및 우수한 프로그래밍 습관이 포함됩니다.

MySQL은 다음과 같은 초보자에게 적합합니다. 1) 설치 및 구성이 쉽고, 2) 풍부한 학습 리소스, 3) 직관적 인 SQL 구문, 4) 강력한 도구 지원. 그럼에도 불구하고 초보자는 데이터베이스 디자인, 쿼리 최적화, 보안 관리 및 데이터 백업과 같은 과제를 극복해야합니다.

예, sqlisaprogramminglanguages-pecializedfordatamanagement.1) 그것은 초점을 맞추고, 초점을 맞추고, 초점을 맞추고, sqlisessentialforquerying, 삽입, 업데이트 및 adletingdataindataindationaldatabase.3) weburer infriendly, itrequires-quirestoamtoavase

산성 속성에는 원자력, 일관성, 분리 및 내구성이 포함되며 데이터베이스 설계의 초석입니다. 1. 원자력은 거래가 완전히 성공적이거나 완전히 실패하도록합니다. 2. 일관성은 거래 전후에 데이터베이스가 일관성을 유지하도록합니다. 3. 격리는 거래가 서로를 방해하지 않도록합니다. 4. 지속성은 거래 제출 후 데이터가 영구적으로 저장되도록합니다.

MySQL은 데이터베이스 관리 시스템 (DBMS) 일뿐 만 아니라 프로그래밍 언어와 밀접한 관련이 있습니다. 1) DBMS로서 MySQL은 데이터를 저장, 구성 및 검색하는 데 사용되며 인덱스 최적화는 쿼리 성능을 향상시킬 수 있습니다. 2) SQL과 같은 ORM 도구를 사용하여 Python에 내장 된 SQL과 프로그래밍 언어를 결합하면 작업을 단순화 할 수 있습니다. 3) 성능 최적화에는 인덱싱, 쿼리, 캐싱, 라이브러리 및 테이블 부서 및 거래 관리가 포함됩니다.

MySQL은 SQL 명령을 사용하여 데이터를 관리합니다. 1. 기본 명령에는 선택, 삽입, 업데이트 및 삭제가 포함됩니다. 2. 고급 사용에는 조인, 하위 쿼리 및 집계 함수가 포함됩니다. 3. 일반적인 오류에는 구문, 논리 및 성능 문제가 포함됩니다. 4. 최적화 팁에는 인덱스 사용, 선택*을 피하고 한계 사용이 포함됩니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Dreamweaver Mac版
시각적 웹 개발 도구

드림위버 CS6
시각적 웹 개발 도구
