Rails connects to MySQL database running on Ubuntu

Source: Internet
Author: User

Rails installs Rails on Ubuntu (RVM Ruby gem Bootstrap bootswatch)

Rails 4.1.4

Ruby 2.2.0


  1. sudo apt-get install mysql-server mysql-client installing MySQL (setting up the MySQL user root password during installation)

  2. sudo apt-get install Libmysqlclient-dev (HTTPS://GITHUB.COM/BRIANMARIO/MYSQL2 see this section for Linux and other unixes)

  3. Mysql-u root-p (log in to MySQL with MySQL root user)

  4. Create Database railstest; (CREATE DATABASE)

  5. show databases; (View database)

  6. Exit (Quit database)

  7. Rails new trails-d MySQL

  8. CD Trails

  9. VI config/database.yml (connection data file, modified to the following)

    Default: &default
    Adapter:mysql2
    Encoding:utf8
    Pool:5
    Username:root
    Password:mysql User root Password
    Socket:/var/run/mysqld/mysqld.sock

    Development:
    <<: *default
    Database:railstest

  10. VI gemfile (Modify Gem ' mysql2 ')

    Gem ' mysql2 ', ' ~> 0.3.20 '

  11. Bundle Install (Install the software in Gemfile)

  12. Test

    ails G Scaffold Product name:string price:decimal description:text (CREATE TABLE)

    Rake db:migrate (CREATE TABLE)


Note:

Error: Specified ' MYSQL2 ' for database adapter, but the gem was not loaded. In connection with the MYSQL2 version, refer here https://github.com/brianmario/ Mysql2

Ruby on rails/active Record
    • MYSQL2 0.4.x works with rails/active Record 4.2.5-5.0 and higher.

    • MYSQL2 0.3.x works with Rails/active Record 3.1, 3.2, 4.x, 5.0.

    • MYSQL2 0.2.x works with Rails/active Record 2.3-3.0.




This article is from "XS Notes" blog, declined reprint!

Rails connects to MySQL database running on Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.