1

I have learned MySql in my school, but on CMD Prompt. Since i want to use that knowledge and want to create a GUI program in ruby (NOT A RUBY-ON-RAILS PROJECT) which use MySql commands like:

SHOW DATABASES; USE DATABASE ruby; SELECT * FROM TABLE staff; CREATE TABLE STUDENT(Rollno integer, Class integer); INSERT INTO STUDENT VALUES(32, 12); SHOW TABLES; DROP TABLE STUDENT; etc. and etc...

but i am unable to find about that, i have found mysql2 gemfile but it doesn't supports the command in my code, in

require 'mysql2'

client = Mysql2::Client.new(hostname: 'localhost', username: 'root', password: '1234', database: 'ruby')

list = client.query("SHOW TABLES")
list.each do |item|
    puts item
end

No output and I'm just frustrated

Please give Suggestions

WITH THE CONTIBUTION OF @URSUS, WE HAVE SOLVED THIS, WE RECHECKED THE MySql GEMFILE AND RECHECK THE Table in Database AND USE irb

look over at this link: https://drive.google.com/open?id=19YUhmcLeMJn9aNEjM0bQNjpHIWrPZ0RX

1
  • Ideally you'd use a database layer like Sequel at the absolute least. The mysql2 driver is pretty feeble. This code won't produce output unless you have tables defined in that database. Commented Dec 19, 2017 at 17:58

1 Answer 1

1

You need to adjust the query. This query works for me.

client.query("SHOW TABLES FROM DB") DB being your database.

In your connection string you are specifying a database to connect to, so I don't believe you will be able to run SHOW DATABASES. Try removing the DB from the connection string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.