SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ruby MySQL access problem

    I've got the following code seems runnable. it just performs like building a connection with a configurable username and password.

    Code:
    # dbConn.rb
    
    require "mysql"
    
    begin
    
    dbname="aDatabase"
    print "Please enter your user name associating with mysql DB: "
    uName= gets
    print "Please enter your password: "
    pwd= gets
    
    m = Mysql.real_connect("localhost",uName,pwd)
    m.select_db(dbname)
    result = m.query("SELECT * FROM content")
    
    m.close
    end
    But when I attempt to run it, it returns Access denied as shown below. Anyone got idea on why?

    george@linux:~/updating> ruby dbConn.rb
    Please enter your user name associating with mysql DB: root
    Please enter your password: xxxxxx
    dbConn.rb:14:in `real_connect': Access denied for user: 'root (Mysql::Error)
    @localhost' (Using password: YES) from dbConn.rb:14

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you call "gets" make you sure you call "gets.chomp" because it includes the newline in it.
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  3. #3
    SitePoint Member
    Join Date
    Feb 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    I've just tried it out, and it is exactly the point!! Thanks for your comment!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    UK
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to hijack the thread, I just installed Mysql 5.0.2 and I am running 1.8.4 stable of Ruby.

    I am just messing around, seeing what can be done,

    I tried to connect to mysql through a ruby file but I get this error.

    no such file to load - mysql (LoadError)

    mysql is installed at C:\Program Files\MySQL
    ruby is installed at C:\ruby
    the file is located at C:\ruby\programs\mysqlconn.rb

    Cheers

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    California
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to install the mysql gem:
    Code:
    gem install mysql
    Happy switcher to OS X running on a MacBook Pro.

    Zend Certified Engineer

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    UK
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that.. and got:

    undefined local variable or method 'mysql' for main: Object (NameError)
    http://www.tmtm.org/en/mysql/ - I tried to install this but when I run extconf.rb it doesnt follow through, not sure what path to put after?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •