Ruby

Connect Ruby to MySQL database

Connect Ruby to MySQL database and execute a SQL query.

Install gem

gem install mysql

Use

Connect to the Database, execute a SQL query and perform an action with the result

require 'mysql'  
  
con = Mysql.new(hostname, username, password, databasename)  
rs = con.query('select * from table')  
rs.each_hash { |h| puts h['text']}  
con.close