Simple database connection

Discussion in 'Ruby' started by jrq, Jul 8, 2011.

  1. jrq

    jrq Guest

    Apologies for being really dumb today. I'm sure this is something
    really basic.
    I'm trying to open a connection to a MySQL database using mysql2 using
    the following:

    require "rubygems"
    require "mysql2"
    mysql = => 'localhost', :user =>
    'user1', :password => 'XXXX', :database => 'www_wpportal')
    res = mysql.query("select * from contact_tag")

    But I keep getting this message when I run it:

    36:in `connect': Access denied for user 'root'@'localhost' (using
    password: YES) (Mysql2::Error)

    I don't understand where it's getting the "root@localhost" from.

    Any assistance greatly appreciated.
    jrq, Jul 8, 2011
    1. Advertisements

  2. jrq

    jrq Guest

    Of course I figured it out 2 minutes after posting. It's "username"
    not "user".
    jrq, Jul 8, 2011
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.