# Couldn't able to solve MySQL error

**URL:** <https://www.ruby-forum.com/t/couldnt-able-to-solve-mysql-error/239577>\
**Category:** Ruby\
**Created:** [March 5, 2014, 4:05pm UTC](https://www.ruby-forum.com/t/couldnt-able-to-solve-mysql-error/239577 "2014-03-05T16:05:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [March 5, 2014, 4:05pm UTC](https://www.ruby-forum.com/t/couldnt-able-to-solve-mysql-error/239577/1 "2014-03-05T16:05:45Z")

</div>

I am new for MySQL and Ruby.

require ‘rubygems’  
require ‘mysql’

# Connect to a MySQL database ‘test’ on the local machine

# using username of ‘root’ with no password.

db = Mysql.connect(‘localhost’, ‘root’, ‘’, ‘test’)

# Perform an arbitrary SQL query

db.query(“INSERT INTO people (name, age) VALUES(‘Chris’, 25)”)

# Perform a query that returns data

begin  
query = db.query(‘SELECT \* FROM people’)  
puts “There were #{query.num\_rows} rows returned”  
query.each\_hash do |h|  
puts h.inspect  
end  
rescue  
puts db.errno  
puts db.error  
end

# Close the connection cleanly

db.close

When I try to run above program, I got error like following:

mysql.rb:6:in `connect’: Access denied for user ‘root’@‘localhost’  
(using

password: NO) (Mysql::Error)

from mysql.rb:6:in `’

How can I able to solve this error?

Could anyone one help me in this?

Thank you.

---

<div class="post-metadata">

**Author:** ![jaimin26783](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@jaimin26783](https://www.ruby-forum.com/u/jaimin26783)\
**Post date:** [March 5, 2014, 5:09pm UTC](https://www.ruby-forum.com/t/couldnt-able-to-solve-mysql-error/239577/2 "2014-03-05T17:09:26Z")

</div>

On Wed, Mar 5, 2014 at 4:05 PM, Jaimin P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I am new for MySQL and Ruby.
> 
> require ‘rubygems’

With current Ruby versions the line above should not be necessary.

> require ‘mysql’
> 
> # Connect to a MySQL database ‘test’ on the local machine
> 
> # using username of ‘root’ with no password.
> 
> db = Mysql.connect(‘localhost’, ‘root’, ‘’, ‘test’)

> When I try to run above program, I got error like following:
> 
> mysql.rb:6:in `connect’: Access denied for user ‘root’@‘localhost’  
> (using
> 
> password: NO) (Mysql::Error)
> 
> from mysql.rb:6:in `’
> 
> How can I able to solve this error?

Can you access the database with these credentials with the MySQL  
command line tool? If not you need to use proper credentials that you  
have set up your database with. If you can something with your Ruby  
setup seems to be broken.

Cheers

robert

---

<div class="post-metadata">

**Author:** ![jaimin26783](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@jaimin26783](https://www.ruby-forum.com/u/jaimin26783)\
**Post date:** [March 5, 2014, 6:16pm UTC](https://www.ruby-forum.com/t/couldnt-able-to-solve-mysql-error/239577/3 "2014-03-05T18:16:27Z")

</div>

> Can you access the database with these credentials with the MySQL  
> command line tool? If not you need to use proper credentials that you  
> have set up your database with. If you can something with your Ruby  
> setup seems to be broken.
> 
> Cheers
> 
> robert

I am trying to access the database with these credentials with the MYSQL  
command line tool.

Thank you.
