Rails uses sqlite3 database and data manipulation basic commands

Source: Internet
Author: User

Rails uses sqlite3 as a database by default, although many people prefer MySQL. But if it is for learning, sqlite3 enough, because it is lightweight and does not need to be installed.

Let's start with a brief introduction to Sqlite3:
1, Sqlite3 does not need to be configured, does not need to install, also does not need the administrator. Most of all, it doesn't have a server, it's just an EXE or DLL.
2, the database is stored in the form of files on disk, you can freely copy the use of
3. Because Sqlite3 does not have a server listening port, it cannot connect to the database remotely via IP and port like MySQL. If you want to access the database remotely, only through database file sharing

1. Install Gem
Gem Install Sqlite3
2, installation Sqlite3

Installation method under Windows:
Download http://dl.dbank.com/c0cmb3fd78

After unpacking the installation package, put all 3 files (including sqlite3.exe,sqlite3.dll,sqlite3.def) into the/ruby/bin directory.
Installation method under Linux:

sudo apt-get install Sqlite3

If the gem installation still fails after Apt-get installs Sqlite3, refer to http://rubyer.me/blog/738 to compile the installation sqlite3
OK, now you can create the project and use the SQLite3

3. Basic commands

After you create a project using rails new MyProject, there is database.yml in the Myproject/config directory, which uses Sqlite3 by default.

As follows:

Development:  adapter:sqlite3  database:db/development.sqlite3  5  5000  

Open terminal to MyProject root directory, edit Development.sqlite3 database

#go to database under DB folder Development.sqlite3Sqlite3 DB/Development.sqlite3#View a table for this database. Table#Create a tableCREATE table users (ID integer primay key, username text);#Inserting DataINSERT into users (username) VALUES ('God');#view data in a tableSelect* fromUsers

 

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.