[求助]无法连接到MySQL_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 1926 | 回复: 0   主题: [求助]无法连接到MySQL        下一篇 
ad222888
注册用户
等级:新兵
经验:66
发帖:134
精华:0
注册:2016-9-25
状态:离线
发送短消息息给ad222888 加好友    发送短消息息给ad222888 发消息
发表于: IP:您无权察看 2018-6-19 9:59:00 | [全部帖] [楼主帖] 楼主

无法连接到MySQL

将给出以下错误:

Message: SQLSTATE[28000] [1045] Access denied for user 'my_user'@'xx.xx.xx.xx' (using password: YES) <-- the client IP


我缩小了麻烦的起始。$mysqli->ssl_set(...).

等我的证书,则必须抛出错误的路径传递给SSL certificate error据此帖 由玩家都因同样的问题而不是以前访问拒绝它会抛出同样的错误。

我设法建立连接使用Navicat发送到服务器,以帮助管理员通过配置ssl连接的数据库,如下所示:

注释:

我的是PHP版本 5 .3 .15
使用远程数据库服务器上的my sql版本是5 .5 0.13 55
Navicat和PHP代码都在相同的PC运行。
数据库管理创造了 ssl_user 专门进行测试。 将拒绝该用户正常访问,并且必须使用ssl连接。
不使用代理。
我试过 PDO也因此而产生同样的问题。
我试过 mysql->connect()但这将throw不良握手错误并根据 手册中的注释有没用。
中打开启用了ssl, phpinfo()
问题在于为什么PHP不抱怨了错误的路径证书? PHP似乎并忽略该行,我要将证书路径设置了 !

Update : 我试着改变这一行在我的端口建立连接以显式地设置和使用 MYSQLI_CLIENT_SSL:

$mysqli->real_connect('xx.xx.xx.xx', 'my_user', 'my_password', 'my_db','3306',NULL,MYSQLI_CLIENT_SSL)


不过,我这有个错误:

Warning: mysqli::real_connect(): (08S01/1043): Bad handshake in ...
Update 2:


这是tcpdump的结果ing从数据库服务器:

0x0040: 3142 6164 2068 616e 6473 6861 6b65 1Bad.handshake
13:16:18.133282 IP (tos 0x8, ttl 64, id 40823, offset 0, flags [DF], proto: TCP (6), length: 52) xx.xx.xx.202.mysql > xx.xx.xx.130.42766: F, cksum 0xf15f (correct), 112:112(0) ack 79 win 46 <nop,nop,timestamp 19516376 3465907>
0x0000: 4508 0034 9f77 4000 4006 c8a7 c0a8 28ca E..4.w@.@.....(.
0x0010: c0a8 2882 0cea a70e b36c 7e8b 7b4d a169 ..(......l~.{M.i
0x0020: 8011 002e f15f 0000 0101 080a 0129 cbd8 ....._.......)..
0x0030: 0034 e2b3 .4..
13:16:18.133433 IP (tos 0x8, ttl 64, id 17337, offset 0, flags [DF], proto: TCP (6), length: 52) xx.xx.xx.130.42766 > xx.xx.xx.202.mysql: F, cksum 0xb695 (correct), 79:79(0) ack 113 win 92 <nop,nop,timestamp 3480910 19516376>
0x0000: 4508 0034 43b9 4000 4006 2466 c0a8 2882 E..4C.@.@.$f..(.
0x0010: c0a8 28ca a70e 0cea 7b4d a169 b36c 7e8c ..(.....{M.i.l~.
0x0020: 8011 005c b695 0000 0101 080a 0035 1d4e ............5.N
0x0030: 0129 cbd8 .)..
13:16:18.133452 IP (tos 0x8, ttl 64, id 40824, offset 0, flags [DF], proto: TCP (6), length: 52) xx.xx.xx.202.mysql > xx.xx.xx.130.42766: ., cksum 0xb6c3 (correct), 113:113(0) ack 80 win 46 <nop,nop,timestamp 19516376 3480910>
0x0000: 4508 0034 9f78 4000 4006 c8a6 c0a8 28ca E..4.x@.@.....(.
0x0010: c0a8 2882 0cea a70e b36c 7e8c 7b4d a16a ..(......l~.{M.j
0x0020: 8010 002e b6c3 0000 0101 080a 0129 cbd8 .............)..
0x0030: 0035 1d4e .5.N


xx .xx .xx .202是数据库服务器ip 。
xx .xx .xx .130是我的PC ip 。

Update 3:


我检查过输入密码长度使用下面的代码:

mysql> select length(Password) from mysql.user where User='youruser'


并且密码长度是 41 。

Update 4:


可能有提示错误信息中返回时使用命令行连接通过 ssh 在远程服务器( I 整个项目上传到远程服务器) :

mysql -u test_ssl -password --ssl-key=/usr/local/apache2/htdocs/certs/client-key.pem --ssl-cert=/usr/local/apache2/htdocs/certs/WRONG-CERTIFICATE.pem


出现了以下错误:

SSL error: Unable to get certificate from '/usr/local/apache2/htdocs/certs/WRONG-CERTIFICATE.pem'
ERROR 2026 (HY000): SSL connection error ---> notice the error here


如果我根本不提供任何证书时收到下面的消息:

-bash-3.2$ mysql -u test_ssl -password
ERROR 1045 (28000): Access denied for user 'test_ssl'@'localhost' (using password: YES)


这是相同的错误我叫我用PHP连接时使用正确的证书或无效路径 !

也许这意味着什么?

乍一看,你为什么不能设置 MYSQLI_CLIENT_SSL选项来连接。

if (!$mysqli->real_connect('localhost', 'my_user', 'my_password', 'my_db', null, MYSQLI_CLIENT_SSL)) { ... }
Update :


你可以尝试添加 $mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, true);之前, $mysqli->ssl_set().

另外,这适用于我:

<?php
$pdo = new PDO('mysql:host=ip;dbname=dbname', 'username', 'password', array(
PDO::MYSQL_ATTR_SSL_KEY =>'/etc/mysql/ssl/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT=>'/etc/mysql/ssl/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA =>'/etc/mysql/ssl/ca-cert.pem'
$stmt = $pdo->query("SHOW TABLES;");
$row = $stmt->fetch(PDO::FETCH_ASSOC);
print_r($row);
?>


Update 2: 你可能会收到一个 bad handshake如果使用旧式my sql密码( 16字节长 ) 。 要检查,请运行以下查询:

mysql> select length(Password) from mysql.user where User='youruser'


如果收到 16:

// disable old_passwords:
mysql> SET @@session.old_passwords = 0;
// update password for user used in PHP script:
mysql> SET PASSWORD FOR 'existinguser'@'localhost' = PASSWORD('existingpass');
// check if we have a 41 bytes long password:
mysql> select length(Password) from mysql.user where User='youruser'


并再次从PHP脚本检查连接。 




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论