Access denied for user 'root'@'localhost' (using password: YES)
PS:
OS:wins XP
database.yml:
development:
adapter: mysql
encoding: utf8
database: test_development
username: root
password: 0000
host: localhost
test:
adapter: mysql
encoding: utf8
database: test_test
username: root
password: 0000
host: localhost
production:
adapter: mysql
encoding: utf8
database: test_production
username: root
password: 0000
host: localhost
请大家帮帮看看是怎么回事呀?谢谢了~~
[b]问题补充:[/b]
在一个.rb文件里
require 'mysql'
begin
dbh = Mysql.real_connect("localhost", "root", "0000", "library",3306)
创建表,插入计录,查询计录
dbh.query("drop table if exists test_rb")
dbh.query("create table test_rb(id int,name char(20))")
dbh.query("insert into test_rb values(1,'张三'),(2,'李四')")
printf "%d rows were inserted\n",dbh.affected_rows
res = dbh.query("SELECT name FROM test_rb")
puts "========\n"
while row = res.fetch_row do
printf "%s, %s\n", row[0], row[1]
end
puts "========\n"
puts "Server version: " + dbh.get_server_info
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
ensure
dbh.close if dbh
end
在dos下用命令的形式执行这个rb文件,是可以插入成功的:
2 rows were inserted
张三,
李四,
Server version: 5.0.22-community-nt
这是不是就说明ruby 和mysql是连上了呢?有点晕了~~
[b]问题补充:[/b]
我的平台是XP
[b]问题补充:[/b]
[quote]应该是密码不对了
development:
database: test_development
username: root
password: 0000
host: localhost
Access denied for user 'root'@'localhost' (using password: YES)
这俩处的不一样呀
[/quote]
我的mysql中的root密码就是0000呀,没有问题的呀。而且在用命令的形式插入数据库是可以成功的呀
[b]问题补充:[/b]
[quote]mysql -u root -p0000 localhost[/quote]
在dos下执行这个命令是可以通过的
[b]问题补充:[/b]
这几天查了好多资料,终于有点成果了,今天重新在mysql中新建了一个用户dd,并分配给dd的这个库test_development 的权限,这回测试通过了,具体操作如下:
首先进入mysql的bin目录下: cd C:\Program Files\MySQL\MySQL Server 5.0\bin
在mysql中新建一个用户dd,分配给dd test_development 的权限
mysql –u root –p
Enter password:****
分配给用户dd权限:
grant all on test_development .* to 'dd'@'localhost' identified by '';
并用对database.yml文件时行修改
development:
adapter: mysql
encoding: utf8
database: test_development
pool: 5
username: dd
password:
host: localhost
这样进行之后就可以得到相应的结果了,继续研究root用户为什么不可以。。。。
[b]问题补充:[/b]
[quote]mysql -u root -p0000 -h localhost
如何?
mysql要對應hostname/IP與username
Omnibus (中级程序员) 2009-02-20 采纳为答案[/quote]
我在dos下执行这个命令是可以通过的:这是执行的结果:
C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -u root -p0000 -h localhost
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5 to server version: 5.0.22-community-nt
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
是不是还要对mysql进行一些配置之后,root用户才能使用呀?
谢谢了~~
[b]问题补充:[/b]
我把root的密码更改了一下,重新编译了一下,OK,通过了