我正在尝试通过 sha256 使用 SSL 和密码加密来保护 mysql 连接。我的设置在 cli mysql 和使用本机 mysql 密码时按预期工作。当尝试使用 sha256 密码以用户身份连接时,我得到“HY000/1045):用户 'sha256user'@'192.168.120.45' 的访问被拒绝(使用密码:YES)”,但我可以通过 cli mysql 连接同一个用户。我在本地和从远程主机尝试时都有同样的问题。
[root@vt0-0-7 bin]# /ct/nih/mysql-5.6/bin/mysql -u sha256user -p -h 192.168.120.30
Enter password:
...
mysql> SHOW STATUS LIKE 'Ssl_cipher';
+---------------+--------------------+
| Variable_name | Value |
+---------------+--------------------+
| Ssl_cipher | DHE-RSA-AES256-SHA |
+---------------+--------------------+
1 row in set (0.02 sec)
mysql>
我的php设置:
[root@vt0-0-7 bin]# php --version
PHP 5.6.9 (cli) (built: Jun 3 2015 13:06:06)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
[root@vt0-0-7 bin]#
[root@vto-0-5 bin]# php -i | grep -n mysqlnd
6:Configure Command => './configure' '--prefix=/ct/nih/php-5.6.9/' '--with-mysql=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-xsl' '--with-libxml-dir' '--with-mysqli=mysqlnd' '--with-openssl' '--with-zlib' '--enable-ftp' '--with-apxs2=/ct/nih/httpd-2.2.29/bin/apxs' '--enable-sockets' '--with-curl' '--with-mcrypt' '--with-readline' '--with-pcre-regex=/ct/nih/pcre-8.20' '--enable-soap' '--without-sqlite3' '--without-pdo-sqlite' '--enable-mbstring'
280:Client API version => mysqlnd 5.0.11-dev - 20120503 - $Id:3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
298:Client API library version => mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
316:mysqlnd
318:mysqlnd => enabled
319:Version => mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
329:Loaded plugins => mysqlnd,debug_trace,auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password
332:mysqlnd statistics =>
521:Client API version => mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $
[root@vto-0-5 bin]#
当我使用具有“本机密码”的用户时,PHP 使用 SSL 连接。
PHP连接代码:
$this->dbh = mysqli_init();
$res = $this->dbh->ssl_set(DB_CLIENT_KEY, DB_CLIENT_CERT, DB_CA_CERT, NULL, NULL);
$user="sha256user";
$pass="Sh@256Pa33";
$connRes = $this->dbh->real_connect($dbHost, $user , $pass, $dbName, 3306, NULL, MYSQLI_CLIENT_SSL);
编辑: MySQL 在本地编译:
$> cmake . -DWITH_SSL=system
$> mysql --version
mysql Ver 14.14 Distrib 5.6.25, for Linux (x86_64) using EditLine wrapper
$>
有谁知道在哪里寻找问题?