# Accessing mysql thorugh ruby

**URL:** <https://www.ruby-forum.com/t/accessing-mysql-thorugh-ruby/59701>\
**Category:** Ruby\
**Created:** [May 5, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/accessing-mysql-thorugh-ruby/59701 "2006-05-05T17:03:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bfsog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bfsog](https://www.ruby-forum.com/u/bfsog)\
**Post date:** [May 5, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/accessing-mysql-thorugh-ruby/59701/1 "2006-05-05T17:03:23Z")

</div>

Heres the code:

```auto
# example of connecting to mysql

require "mysql"

begin

	dbName = "database"
	m = Mysql.new("localhost", "root", "password") # this line fails
	m.select_db(dbName)

	result = m.query("SELECT * FROM test")
	fields = result.fetch_fields
	fields.each do |field|
	puts field.name
	end
	gets
	m.close

end

```

The error: "Cant connect to MySQL server on “localhost” (10061)  
(MySQL::Error)

I accessed mysql through its window with the values I use in the line  
that fails, so they are correct.

Any ideas?
