Reputation: 59
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
Upvotes: 1
Views: 203
Reputation: 378
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.
Upvotes: 1