[英]Cannot connect to mysql 5.0.8 using mysql_connect with password
I can connect to my mysql db using php without a password fine. 我可以使用PHP连接到我的mysql数据库,没有密码。 However, when I add a password in phpmyadmin I can no longer connect.
但是,当我在phpmyadmin中添加密码时,我无法再连接。 I consistently get the error of:
我一直得到错误:
"Could not connect: Access denied for user 'admin'@'localhost' (using password: YES)"
I've tried using both settings of MySQL password 4.0 and 4.1+ with the same results. 我尝试使用MySQL密码4.0和4.1+的两种设置,结果相同。
mysql_connect ("127.0.0.1", "admin", "password") or die('Could not connect: ' . mysql_error());;
mysql_select_db ("datatable");
Does anyone have an idea of what may be going on here? 有没有人知道这里会发生什么?
EDIT: I can access it if I turn off the password. 编辑:如果我关闭密码,我可以访问它。 There seems to be some misunderstanding
似乎有一些误解
According to the mysql_connect statement you are showing, you are attempting to connect as admin@'127.0.0.1'
. 根据您显示的mysql_connect语句,您尝试以
admin@'127.0.0.1'
进行连接。 This demands the use of TCP/IP to connect to mysql. 这需要使用TCP / IP连接到mysql。 If you connect as
admin@localhost
this uses mysql.sock (the socket file) to connect to mysqld. 如果您以
admin@localhost
身份连接,则使用mysql.sock(套接字文件)连接到mysqld。
You should run this query 您应该运行此查询
SELECT user,host,password FROM mysql.user WHERE user='admin';
You should see admin@localhost
defined. 您应该看到
admin@localhost
定义。 You probably won't see admin@'127.0.0.1'
. 你可能不会看到
admin@'127.0.0.1'
。 You could add it but it is easier to just code for admin@localhost
. 您可以添加它,但只是为
admin@localhost
编码更容易。
Try changing your code as follows: 尝试更改代码,如下所示:
mysql_connect ("localhost", "admin", "password") or die('Could not connect: ' . mysql_error());;
mysql_select_db ("datatable");
If you can connect to mysql without a password, then your mysql installation is not secure. 如果你可以在没有密码的情况下连接mysql,那么你的mysql安装就不安全了。
You need to add a password to admin@localhost and remove anonymous user logins as follows: 您需要为admin @ localhost添加密码并删除匿名用户登录,如下所示:
UPDATE mysql.user SET password=password('whateverpassword')
where user='admin' and host='localhost';
DELETE FROM mysql.user WHERE user='';
FLUSH PRIVILEGES;
Here is another suggestion: Create the admin@127.0.0.1 user like this: 这是另一个建议:像这样创建admin@127.0.0.1用户:
GRANT ALL PRIVILEGES ON *.* TO admin@'127.0.0.1' IDENTIFIED BY 'whateverpassword';
and try your original code 并尝试您的原始代码
This might help 这可能有所帮助
steps- 脚步-
it will ask you for a pw – just hit the return since you don't have one yet (next time you go to the console you'll need to enter the new pw that you'r entering here). 它会问你一个pw - 只是点击返回因为你还没有它(下次你去控制台时你需要输入你进入这里的新pw)。 type the following:
输入以下内容:
UPDATE mysql.user SET Password=PASSWORD("xxxxxx") WHERE User="root"; UPDATE mysql.user SET Password = PASSWORD(“xxxxxx”)WHERE User =“root”; (where xxxxxx is the password you entered in the previous step).
(其中xxxxxx是您在上一步中输入的密码)。
Now type: FLUSH PRIVILEGES; 现在输入:FLUSH PRIVILEGES;
go to your WAMP or MAMP folder, find the APPS folder, and than click on your PHPMYADMIN folder ( eg my folder called phpmyadmin2.11.6 ) and find the config.inc.php 转到您的WAMP或MAMP文件夹,找到APPS文件夹,然后单击您的PHPMYADMIN文件夹(例如我的文件夹名为phpmyadmin2.11.6)并找到config.inc.php
open config.inc.php with wordpad and find the following text: 用wordpad打开config.inc.php并找到以下文本:
$cfg['Servers'][$i]['password'] = '';
now add the password that you used in step number 3 like this : 现在添加您在步骤3中使用的密码,如下所示:
$cfg['Servers'][$i]['password'] = 'yourPasswordHere';
You should be all set now! 你现在应该全部准备好了!
Source - http://www.knowledgesutra.com/discuss/tsilti-php-myadmin-access-mysql-database.html 来源 - http://www.knowledgesutra.com/discuss/tsilti-php-myadmin-access-mysql-database.html
Your username or password are incorrect. 您的用户名或密码不正确。 Make sure you typed them correctly, without leaving trailing spaces.
确保正确键入它们,而不留下尾随空格。 Usernames and passwords are case sensitive.
用户名和密码区分大小写。
If you tamper with MySQL user data via phpMyAdmin you MUST execute the 如果您通过phpMyAdmin篡改MySQL用户数据,您必须执行
FLUSH PRIVILEGES
command in order to make the new rules apply. 命令以使新规则适用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.