mysql - Why do I get "Access denied for user 'root'@'localhost'"? -


i'm using code connect mysql database:

username="root" password="admin" host="localhost" db="one" mysql.new(host,username,password,db) 

i got error while executing code:

access denied user 'root'@'localhost' (using password: yes) 

if use mysql.new('localhost','root','admin','one') works fine.

when print variables correct values printed.

please me figure out what's wrong.

basic trouble-shooting 101:

if literal strings work, , variable assignments don't, suspect variable assignments; wrong 1 of them, such invisible character.

try:

vars = ('localhost','root','admin','one') mysql.new(*vars) 

then try:

vars = %w(localhost root admin one) mysql.new(*vars) 

or:

host, username, password, db = %w(localhost root admin one) mysql.new(host, username, password, db) 

or:

host, username, password, db = 'localhost','root','admin','one' mysql.new(host, username, password, db) 

the idea start know works, , work backwards until assigning variables works, or breaks. @ point you've either fixed problem (possibly without knowing why), or you've learned broke it. either way you're ahead.

you say:

when print variables correct values printed.

how printing variables? can't see terminal, , didn't give information. if it's invisible character, common culprits when copying , pasting text, might not show when printing. inspecting variables should help, should display escaped values:

password = "root\u00a0"  puts password # >> root   puts password.inspect # >> "root "  puts password.chars # >> r # >> o # >> o # >> t # >>    puts password.unpack('c*').map{ |s| s.to_s(16) } # >> 72 # >> 6f # >> 6f # >> 74 # >> c2 # >> a0 

otherwise, revert original comment, problem how set mysql root account , should read "access denied user 'root'@'localhost' (using password: yes) (mysql::error)".


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -