MySQL SSL接続

サーバ側

# cat /var/db/mysql/my.cnf | grep ^ssl
ssl = 1
ssl-ca = /var/db/mysql/example_root.crt
ssl-cert = /var/db/mysql/master.example.com.crt
ssl-key = /var/db/mysql/master.example.com.key
# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10281
Server version: 5.5.15-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> grant all on test.* to test@’client.example.com’ identified by ‘XXXXXX’ ;
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye

クライアント側

% mysql -u test -p –ssl-ca=example_root.crt -h master.example.com –ssl-verify-server-cert
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6838
Server version: 5.5.15-log Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> status
————–
mysql  Ver 14.14 Distrib 5.5.16, for FreeBSD8.2 (amd64) using  5.2

Connection id:          6838
Current database:
Current user:           test@client.example.com
SSL:                    Cipher in use is DHE-RSA-AES256-SHA
Current pager:          more
Using outfile:          ”
Using delimiter:        ;
Server version:         5.5.15-log Source distribution
Protocol version:       10
Connection:             master.example.com via TCP/IP
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
TCP port:               3306
Uptime:                 1 day 23 hours 3 min 21 sec

Threads: 2  Questions: 196428  Slow queries: 0  Opens: 11328  Flush tables: 1  Open tables: 4  Queries per second avg: 1.159
————–
mysql> \q
Bye