Rails comes with sqlite3 in all aspects, but the free version lacks a fatal function: Add a password! Although the third party has an encrypted version of the compiled binary version, we will not be confused.
Rails comes with sqlite3 in all aspects, but the free version lacks a fatal function: Add a password! Although the third party has an encrypted version of the compiled binary version, we will not be confused.
Rails comes with sqlite3 in all aspects, but the free version lacks a fatal function: Add a password! Although the third party has a compiled binary version of the encrypted version, let's not go to mysql first.
It is very easy to install mysql In Ubuntu. I will not talk about it first. I will first talk about how to change rails to the mysql driver and use the following command:
Rails new xxx-d mysql
Because the new version of rails supports mysql using the gem mysql2, you need to add the 'mysql2' gem in Gemfile; however, with the above command, rails will automatically add this sentence in Gemfile, so you don't need to worry about it.
Rails naturally needs to download and install the mysql2 package, but an error will be reported here, prompting that the mysql header file cannot be found. It seems that you need to download the mysql dev package and other things. You can run the following command to install it:
Sudo apt-get install libmysqlclient-dev
This time rails new is okay. Next we will create a model:
Rails g scaffold book name: string count: integer price: integer remark: string
Create a new database as follows:
Rake db: migrate
An error occurred. The system prompts that mysql cannot be connected. The mysql service is not in the listening status! Now let's start to install the mysql server:
Sudo apt-get install mysql-server
Next, the mysql client:
Apt-get isntall mysql-client
When installing the server, you will be prompted to enter the root password. Here I enter abc. If it is a pure number (such as 123), In the rails database. yml configuration should be included in '123456' (I have not tried it yet, and other people's experience on the Internet ). after the server is installed, run the following command to determine whether to start listening in the mysql Background:
Sudo netstat-tap | grep mysql
If the mysql server is installed and listening, you can create a database in rails:
Rake db: create-v
Rake db: migrate
In linux, the path of the mysql database is/var/lib/mysql.
We can confirm the created mysql database. Open the terminal and enter the command:
Mysql-u root-p
Mysql will prompt you to enter the password to log on, enter the previously set password abc, and successfully log on to mysql; then you can use show databases; to view the existing database:
Mysql> show databases;
+ --------------------- +
| Database |
+ --------------------- +
| Information_schema |
| Db_test_development |
| Db_test_test |
| Mysql |
| Performance_schema |
+ --------------------- +
5 rows in set (0.00 sec)
Use the use mysql command to select the current database:
Mysql> use db_test_development;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with-
Database changed
Let's take a look at all the tables in the database:
Mysql> show tables;
+ ------------------------------- +
| Tables_in_db_test_development |
+ ------------------------------- +
| Books |
| Schema_migrations |
+ ------------------------------- +
2 rows in set (0.00 sec)
Finally, let's take a look at the structure of the books table:
Mysql> show columns from books;
+ ------------ + -------------- + ------ + ----- + --------- + ---------------- +
| Field | Type | Null | Key | Default | Extra |
+ ------------ + -------------- + ------ + ----- + --------- + ---------------- +
| Id | int (11) | NO | PRI | NULL | auto_increment |
| Name | varchar (255) | YES | NULL |
| Count | int (11) | YES | NULL |
| Price | int (11) | YES | NULL |
| Remark | varchar (255) | YES | NULL |
| Created_at | datetime | NO | NULL |
| Updated_at | datetime | NO | NULL |
+ ------------ + -------------- + ------ + ----- + --------- + ---------------- +
7 rows in set (0.00 sec)
Install Apache server in Ubuntu and use the Passenger plug-in to deploy Rails Applications
Build a Ruby On Rails platform using CentOS
Build Ruby On Rails in Ubuntu
Web development agile way application Rails agile Web development (original book version 4th). (US) Sam Ruby). [PDF] + source code
For details about Rails, click here
Rails: click here
,