require 'mysql' con=Mysql.new('localhost','root','root','test') con.query('set names utf8') rs=con.query('select * from demotb') p rs.num_fields() p '---------------------' num=rs.num_rows() for i in 0..num-1 rs.data_seek(i) a=rs.fetch_row() puts a[0]+':'+a[1] end p '----------------------' for i in 0..num-1 rs.data_seek(i) a=rs.fetch_hash() puts a['name']+' : '+a['age'] end rs.free() con.close con.close