How can i connect Ruby to Mysql without rails? I want to use Ruby standalone to write pure ruby code to make web application. with no abstraction
Launch a new command prompt (cmd) from the Start menu. Test the Ruby installation by running the command ruby -v to see the version installed. Test the Gem installation by running the command gem -v to see the version installed. Build the Mysql2 module for Ruby using Gem by running the command gem install mysql2 .
MySQL2 project is a continuation of MySQL-Native. Protocol parser code was rewritten from scratch and api changed to match popular mysqljs/mysql. MySQL2 team is working together with mysqljs/mysql team to factor out shared code and move it under mysqljs organisation.
Ruby on Rails uses SQLite as its database by default, but it also supports the use of MySQL.
Look here
require "mysql" # if needed
@db_host = "localhost"
@db_user = "root"
@db_pass = "root"
@db_name = "your_db_name"
client = Mysql::Client.new(:host => @db_host, :username => @db_user, :password => @db_pass, :database => @db_name)
@cdr_result = client.query("SELECT * from your_db_table_name')
install gem mysql
(check that you have libmysqlclient-dev installed).
mysql = Mysql.new(host, user, password, database)
mysql.query("SELECT ...")
mysql.close
See the documentation for more information
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With