[root@MyServer ~]> mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld1 is not running MySQL server from group: mysqld2 is not running MySQL server from group: mysqld3 is not running MySQL server from group: mysqld4 is not running
[root@MyServer ~]> mysqld_multi report Reporting MySQL servers MySQL server from group: mysqld1 is running MySQL server from group: mysqld2 is running MySQL server from group: mysqld3 is running MySQL server from group: mysqld4 is running
shell> mysql -u root -P3309 -S /tmp/mysql.sock3 -p Enter password: [直接回车] elcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.6.27-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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'forhelp. Type '\c' to clear the current input statement.
mysql> show variables like "port"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3307 | +---------------+-------+ 1 row in set (0.00 sec)
[root@MyServer data1]# pwd /data1 [root@MyServer data1]# ll | grep pem -rw-------. 1 mysql mysql 1675 Nov 25 23:55 ca-key.pem -rw-r--r--. 1 mysql mysql 1070 Nov 25 23:55 ca.pem -rw-r--r--. 1 mysql mysql 1078 Nov 25 23:55 client-cert.pem #客户端证书文件 -rw-------. 1 mysql mysql 1679 Nov 25 23:55 client-key.pem #客户端私钥文件 -rw-------. 1 mysql mysql 1675 Nov 25 23:55 private_key.pem #用于密钥交换的公钥 -rw-r--r--. 1 mysql mysql 451 Nov 25 23:55 public_key.pem #用户密钥交换的私钥 -rw-r--r--. 1 mysql mysql 1078 Nov 25 23:55 server-cert.pem #服务器端证书文件 -rw-------. 1 mysql mysql 1679 Nov 25 23:55 server-key.pem #服务器端私钥文件 [root@MyServer data1]> mysqld_multi stop 1 [root@MyServer data1]> mysqld_multi start 1
mysql> grant all on *.* to 'burn'@'%'; Query OK, 0 rows affected (0.01 sec)
mysql> select * from mysql.user where user='burn'\G *************************** 1. row *************************** Host: % User: burn Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: N References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y ssl_type: -- 此处为空 ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 password_expired: N password_last_changed: 2015-11-26 09:55:31 password_lifetime: NULL account_locked: N 1 row in set (0.00 sec)
# # 当前虚拟机2 MyServer2 # [root@MyServer2 bin]> ./mysql -u burn -h 172.18.14.68 -P3307 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.9-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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'forhelp. Type '\c' to clear the current input statement.
mysql> \s -------------- ./mysql Ver 14.14 Distrib 5.7.9, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 6 Current database: Current user: burn@192.168.115.223 SSL: Cipher in use is DHE-RSA-AES256-SHA #已经使用了ssl登录了 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.9-log MySQL Community Server (GPL) Protocol version: 10 Connection: 172.18.14.68 via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3307 Uptime: 3 min 6 sec
Threads: 2 Questions: 19 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.102 --------
1 2 3 4 5 6 7 8 9
# # 当前虚拟机2 MyServer2 # 上面测试中我们没有使用--ssl参数,也是用了ssl登录的,原因如下 # [root@MyServer2 bin]> ./mysql --help | grep ssl --ssl If set to ON, this option enforces that SSL is server. To disable client SSL capabilities use --ssl=OFF. (Defaults to on; use --skip-ssl to disable.) # 这里说,默认是开启的,可以用--skip-ssl 禁用
# # 当前虚拟机2 MyServer2 # 禁用ssl登录测试 # [root@MyServer2 bin]> ./mysql -u burn -h 172.18.14.68 -P3307 -p --skip-ssl #这里跳过了ssl Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.9-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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'forhelp. Type '\c' to clear the current input statement.
mysql> \s -------------- ./mysql Ver 14.14 Distrib 5.7.9, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 7 Current database: Current user: burn@192.168.115.223 SSL: Not in use # 果然就禁用了ssl Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.9-log MySQL Community Server (GPL) Protocol version: 10 Connection: 172.18.14.68 via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3307 Uptime: 5 min 50 sec
Threads: 2 Questions: 24 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.068 --------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14
-- -- 当前虚拟机1 MyServer, 当前实例mysql1 -- 让用户必须使用ssl -- mysql> show variables like "port"; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 3307 | +---------------+-------+ 1 row in set (0.00 sec)
# # 当前虚拟机2 MyServer2 # [root@MyServer2 bin]> ./mysql -u burn -h 172.18.14.68 -P3307 -p --skip-ssl Enter password: ERROR 1045 (28000): Access denied for user 'burn'@'192.168.115.223' (using password: YES) ## 禁用了SSL就无法登录了 ## [root@MyServer2 bin]> ./mysql -u burn -h 172.18.14.68 -P3307 -p # 默认就启用ssl Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.9-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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'forhelp. Type '\c' to clear the current input statement.
mysql> \s -------------- ./mysql Ver 14.14 Distrib 5.7.9, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 9 Current database: Current user: burn@192.168.115.223 SSL: Cipher in use is DHE-RSA-AES256-SHA # 确实启用了 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.9-log MySQL Community Server (GPL) Protocol version: 10 Connection: 172.18.14.68 via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3307 Uptime: 14 min 25 sec
Threads: 2 Questions: 32 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.036 --------------
mysql> grant all on *.* to 'burn'@'%'; Query OK, 0 rows affected (0.01 sec)
mysql> select * from mysql.user where user='burn_x509'\G *************************** 1. row *************************** Host: % User: burn_x509 Select_priv: N Insert_priv: N Update_priv: N Delete_priv: N Create_priv: N Drop_priv: N Reload_priv: N Shutdown_priv: N Process_priv: N File_priv: N Grant_priv: N References_priv: N Index_priv: N Alter_priv: N Show_db_priv: N Super_priv: N Create_tmp_table_priv: N Lock_tables_priv: N Execute_priv: N Repl_slave_priv: N Repl_client_priv: N Create_view_priv: N Show_view_priv: N Create_routine_priv: N Alter_routine_priv: N Create_user_priv: N Event_priv: N Trigger_priv: N Create_tablespace_priv: N ssl_type: X509 -- 使用X509登录 ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: mysql_native_password authentication_string: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 password_expired: N password_last_changed: 2015-11-26 10:14:43 password_lifetime: NULL account_locked: N 1 row in set (0.00 sec)
1 2 3 4 5 6
# # 当前虚拟机2 MyServer2 # [root@MyServer2 bin]> ./mysql -u burn_x509 -h 172.18.14.68 -P3307 -p Enter password: ERROR 1045 (28000): Access denied for user 'burn_x509'@'192.168.115.223' (using password: YES) # 即使默认开启了ssl,也是无法登录的
# # 当前虚拟机1 MyServer # [root@MyServer data1]> pwd /data1 [root@MyServer data1]> ll | grep pem -rw-------. 1 mysql mysql 1675 Nov 25 23:55 ca-key.pem -rw-r--r--. 1 mysql mysql 1070 Nov 25 23:55 ca.pem -rw-r--r--. 1 mysql mysql 1078 Nov 25 23:55 client-cert.pem -rw-------. 1 mysql mysql 1679 Nov 25 23:55 client-key.pem -rw-------. 1 mysql mysql 1675 Nov 25 23:55 private_key.pem -rw-r--r--. 1 mysql mysql 451 Nov 25 23:55 public_key.pem -rw-r--r--. 1 mysql mysql 1078 Nov 25 23:55 server-cert.pem -rw-------. 1 mysql mysql 1679 Nov 25 23:55 server-key.pem [root@MyServer data1]> scp client-cert.pem client-key.pem root@172.18.14.41:~/ The authenticity of host '172.18.14.41 (172.18.14.41)' can't be established. RSA key fingerprint is 5f:f5:3c:b0:57:79:8d:50:c6:c8:69:b0:90:6e:98:3b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '172.18.14.41' (RSA) to the list of known hosts. root@172.18.14.41's password: client-cert.pem 100% 1078 1.1KB/s 00:00 client-key.pem 100% 1679 1.6KB/s 00:00
[root@MyServer2 ~]> mysql -u burn_x509 -h 172.18.14.68 -P 3307 -p --ssl-cert=./client-cert.pem --ssl-key=./client-key.pem Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 5.7.9-log MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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'forhelp. Type '\c' to clear the current input statement.
mysql> \s -------------- mysql Ver 14.14 Distrib 5.6.27, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 12 Current database: Current user: burn_x509@192.168.115.223 SSL: Cipher in use is DHE-RSA-AES256-SHA # 使用加密方式登录,且通过证书,因为这个用户 require X509 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.9-log MySQL Community Server (GPL) Protocol version: 10 Connection: 172.18.14.68 via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3307 Uptime: 32 min 15 sec
Threads: 2 Questions: 41 Slow queries: 0 Opens: 114 Flush tables: 1 Open tables: 107 Queries per second avg: 0.021 --------------