请教高手:关于VFP与MYSQL数据库连接问题

请教高手:关于VFP与MYSQL数据库连接问题,第1张

先自己扔块砖头出来。

归纳如下:

故障现象 : 无法连接 mysql

错误信息1 :ERROR 1045 (28000): Access denied for user 'usera'@'localhost' (using password:YES)

错误信息2 :ERROR 1045 (28000): Access denied for user 'usera'@'localhost' (using password:NO)

下面,首先分析说明这两种错误信息分别在什么情况下会出现:

描述:使用mysql连接命令或连接工具,对远程数据库进行连接时,可能会出现以上两种错误信息,下面以命令的连接方式进行说明。

当使用mysql里连接命令时,若带-p参数且指明密码,或带-p参数不指明密码,但在下一步输入密码时有字符串输入,则返回的是

“错误信息1”,若不带-p参数,或带-p参数但在下一步输入密码时,不输入任何字符,则返回的是“错误信息2”,如下所示:

C:\Documents and Settings\Administrator>mysql -uroot -h 192.168.8.88 -proot//带-p参数,并指明密码

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: YES)

C:\Documents and Settings\Administrator>mysql -uroot -h 192.168.8.88 -p//带-p参数,在下一步进行密码输入

Enter password: //有字符串输入

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: YES)

C:\Documents and Settings\Administrator>mysql -uroot -h 192.168.8.88//不带-p参数

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: NO)

C:\Documents and Settings\Administrator>mysql -uroot -h 192.168.8.88 -p //带-p参数,在下一步进行密码输入

Enter password://无字符串输入

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: NO)

上面的对比可总结出一点,使用mysql命令进行登录时,若有密码输入行为并输入了字符,则验证出错后,则返回的错误提示中,对于 (using password: ?)中?的关键字,则返回的是YES,若没有密码输入行为,或无密码字符输入,则返回的是NO。

除上面的实验对比,还进行了如下的登录对比 *** 作,并记录了他们所返回错误提示类型,对上面的总结进行验证:

1.使用存在的用户,不输入密码

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: NO)

2.使用不存在的用户,不输入密码

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: NO)

3.使用存在的用户,且输入密码正确

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: YES)

4.使用存在的用户,但输入密码不正确

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: YES)

5.使用不存在的用户,但输入数据库中存在的某一个密码

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: YES)

6.使用不存在的用户,且输入数据库中不存在的一个密码

ERROR 1045 (28000): Access denied for user 'root'@'192.168.8.123' (using password: YES)

总结:对于 ERROR 1045 (28000): Access denied for user'root'@'192.168.8.123' 此类错误返回时, (using password: ?)中?的

关键字是YES还是NO,关键不在于用户是否存在,密码是否正确,它的结果取决于登录时,用户对于密码有没有字符串的输入,如果没有,MySQL数据库验证后,若出错返回此类信息,则应是 (using password: NO),若用户对密码有字符串的输入,返回的则是

(using password: YES)。

下面分析这类 ERROR 1045 (28000): Access denied for user'usera'@'localhost' 错误出现的原因:

原因1 : 客户端远程访问的用户账号并未创建

检查 :

以管理员ROOT登录后,show grants for 'user'@’IP‘或者 select user from mysql.user确认用户账号是否存在。

mysql>show grants for 'jtsec'@'192.168.8.123'

ERROR 1141 (42000): There is no such grant defined for user 'jtsec' on host '192.168.8.123'

mysql>

返回信息:ERROR 1141 (42000): There is no such grant defined for user 'jtsec' on host '192.168.8.123'

说明,没有jtsec用户,或者没有对jtsec用户进行在192.168.8.123远程访问的授权。

mysql>select user,host from mysql.user

+-------+---------------+

| user | host |

+-------+---------------+

| root | localhost |

+-------+---------------+

1 rows in set (0.00 sec)

mysql>

关于user记录数只有一条,是root,并没有jtsec相关的记录,说明没有数据库中没有jtsec这个帐号。

处理 :创建用户账号。

mysql> grant all privileges on *.* to 'jtsec'@'192.168.8.123' identified by 'jtsec' with grant option

Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges

Query OK, 0 rows affected (0.00 sec)

mysql>show grants for 'jtsec'@'192.168.8.123'

+---------------------------------------------------------------------------------------------------------------------------------------------+

| Grants for [email protected] |

+---------------------------------------------------------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'jtsec'@'192.168.8.123' IDENTIFIED BY PASSWORD '*0B4AB716B6BE11F89101577836F3016D8EEAA217' WITH GRANT OPTION |

+---------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

mysql>select user,host from mysql.user

+-------+---------------+

| user | host |

+-------+---------------+

| jtsec | 192.168.8.157 |

| root | localhost |

+-------+---------------+

2 rows in set (0.00 sec)

mysql>

原因2 : 用户账号存在,但未对其所在的客户端的IP进行远程访问授权允许

检查 :

以管理员ROOT登录后 show grants for 'user'@'IP'

mysql>show grants for 'root'@'192.168.8.123'

ERROR 1141 (42000): There is no such grant defined for user 'root' on host '192.168.8.123'

mysql>

返回信息:ERROR 1141 (42000): There is no such grant defined for user 'root' on host '192.168.8.123'

说明,没有root用户(因为是MySQL超级用户所以排除此种可能),或者没有对root用户进行在192.168.8.123远程访问的授权。

我们来对比一下看,root用户本地访问的权限,则可查出:

mysql>show grants for 'root'@'localhost'

+----------------------------------------------------------------------------------------------------------------------------------------+

| Grants for root@localhost |

+----------------------------------------------------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION |

+----------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

或者直接查询mysql的user用户表select user,host from mysql.user,其中记录了每一个用户的权限信息

mysql>select user,host from mysql.user

+-------+---------------+

| user | host |

+-------+---------------+

| root | localhost |

+-------+---------------+

1 rows in set (0.00 sec)

mysql>

关于user值为root的记录数只有一条,且host值为localhost,说明root用户只能在本地访问数据库。

处理 :进行root用户的远程访问授权,可以授权到指定的客户端IP,也可以授权为所有IP都可访问(host值为%)。

授权为所有IP都使用用户root,密码root,来远程访问数据库

mysql>GRANT ALL PRIVILEGES ON *.* TO'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION

Query OK, 0 rows affected (0.00 sec)

mysql>flush privileges

Query OK, 0 rows affected (0.00 sec)

再次进行授权的查询

mysql>show grants for 'root'@'%'

+--------------------------------------------------------------------------------------------------------------------------------+

| Grants for root@% |

+--------------------------------------------------------------------------------------------------------------------------------+

| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION |

+--------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

再次查询授权表记录

mysql>select user,host,password from mysql.user

+-------+---------------+-------------------------------------------+

| user | host | password |

+-------+---------------+-------------------------------------------+

| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| root | % | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

+-------+---------------+-------------------------------------------+

2 rows in set (0.00 sec)

mysql>

原因3 : 用户账号授权访问的密码不正确

检查 :以管理员ROOT登录后, select user,host,password from mysql.user

mysql>select user,host,password from mysql.user

+-------+---------------+-------------------------------------------+

| user | host | password |

+-------+---------------+-------------------------------------------+

| root | localhost | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| root | % | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

| jtsec | 192.168.8.123 | |

| jtsec | 192.168.8.123 | *0B4AB716B6BE11F89101577836F3016D8EEAA217 |

+-------+---------------+-------------------------------------------+

4 rows in set (0.00 sec)

mysql>

根据查询结果可以看出来,root账户的本地访问和远程访问密码一样。

而jtse账户在192.168.8.123这个IP上,远程访问数据库的密码有两个,其中一个为空(第三条记录)。

也就是说在IP为192.168.8.123的客户机上,使用jtsec这个账户远程访问数据库,合法的密码有两个可以选择:

一个是不输入密码(密码为空),另一个是*0B4AB716B6BE11F89101577836F3016D8EEAA217(经过加密的),

其余的输入,都是错的。

处理 :使用正确的访问密码进行访问即可。

错误信息 :ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.8.88' (10065)

原因 :MySQL服务器上防火墙的阻断

检查 :在Linux下查看iptables规则,看是否未对MySQL数据库默认通信端口3306进行放行

处理 :

添加相应的放行规则

自己在 /etc/sysconfig/iptables 里加了一下代码:

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

或尝试关掉防火墙

chkconfig ip6tables off

chkconfig iptables off

问题描述:

C:\Documents and Settings\Administrator>mysql -uroot -h 192.168.8.88 -proot

ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.8.88' (10065)

C:\Documents and Settings\Administrator>

错误信息 :ERROR 2003 (HY000): Can't connect to MySQL server on 'hostxxxxx' (10061)

原因 : mysqld数据库服务没有启动。

检查 :在windows 的任务管理器,或者 unix/linux 下 ps -aux | grep mysql 看一下。确认服务已经启动。

处理 :启动mysqld 服务

错误信息 :ERROR 1130: Host xx.xx.xx.xx is not allowed to connect to this MySQL server

原因 : mysql服务器没有赋予此客户端远程连接的权限。

检查 :在mysql服务器本地查询mysql库里user表对应的host是否包含客户端机器的IP(%为不限制IP允许远程连接)。

处理 :修改mysql库下的user表:update user set host '%' where user 'XXX'flush privileges

错误信息 :ERROR 1045 (28000): Access denied for user 'usera'@'localhost' (using password:NO)

原因 : 用户账号并未创建,远程登录时登录指令未直接包含密码项

检查 :以管理员ROOT登录后,show grants for 'usera'@'localhost'或者 select user from mysql.user确认用户账号是否存在。

处理 :创建用户账号。

 

用oledb 的方式连接到sql 服务器  发送命令 backup database 数据库名 to disk='c:\备份文件名.bak'

Priv Cnn, MYrs, strmy

cnn=Createobject("adodb.connection")

MYrs=Createobject("adodb.recordset")

cnn.Open ("Provider=sqloledb Data Source=服务器IP Initial Catalog=数据库名 User Id=用户名 Password=密码")

sqlstr="backup database 数据库名 to disk='c:\备份文件名.bak' "

rs=cnn.Execute(strmy)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/9893596.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-03
下一篇 2023-05-03

发表评论

登录后才能评论

评论列表(0条)

保存