Oct 22

sql无法连接解决

hihebei , 22:19 , mysql , 评论(0) , 引用(0) , 阅读(721) , Via 本站原创 | |
Warning: mysql_connect() [function.mysql-connect]: OK packet 6 bytes shorter than expected in /opt/lampp/htdocs/abcgw/exchange/mysql_master.php on line 10

Warning: mysql_connect() [function.mysql-connect]: mysqlnd cannot connect to MySQL 4.1+ using old authentication in /opt/lampp/htdocs/abcgw/exchange/mysql_master.php on line 10
无法连接到61.156.238.32 MySQL,请检查61.156.238.32 的MySQl是否正常运行!!!2011-08-07 19:03:16


in 3 steps!] packet 6 bytes shorter than expected – mysqlnd cannot connect to MySQL 4.1+ using old authentication

Weird, huh?

I'll explain you in 3 steps how to solve it! (trust me!)

Ok, I thought the same than you when I get this message.
I had a script that makes two connections to two servers.
I was using the "second" server from my client application and it was working perfectly, so what happened!?

I've read many posts that said me to re-install PHP and or MySQL. What the heck!? No way!
Those are production servers, tenths of thousand kilometers from here, and are working. I simply can't.

Ok, here is the short 3-steps guide (then will explain you why)

1. Turn off the old_passwords compatibility in MySQL
PLAIN TEXT
SQL:

    SET @@old_passwords = 0  (执行此sql语句)

2. Recreate the password for the user
PLAIN TEXT
SQL:

    SET PASSWORD FOR 'username'@'hostname' = PASSWORD('your_pass') (执行此sql语句)

3. Check for the new password's length (must be 41 instead of 16 and it hast to start with an asterisc)
PLAIN TEXT
SQL:

    SELECT
      Length(`Password`),
      Substring(`Password`, 1, 1)
    FROM `mysql`.`user`
    WHERE `user`= ''  (执行此sql语句)

4. Breath again :)

Ok, but WHY?
I'm not going to burden explaining why PHP is not compatible with the old_passwords hashing method.
If you want to know the truth then you can Google for it.

Just let me tell you that simply creating a new user or a new password will not solve your problem until you don't turn off the old_passwords BEFORE changing it.

()内我自己注明的。造成原因是mysql版本不同,之间权限与密码的加密方式不同。
Tags: , , ,
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]