0% found this document useful (0 votes)
35 views

Ruby DB Connection

The document discusses how to create and use a database and table in MySQL. It shows how to 1) create a database called "menagerie", 2) select this database for use, 3) create a table called "pet" with columns to store information about pets, and 4) insert sample data into the table.

Uploaded by

gampesh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Ruby DB Connection

The document discusses how to create and use a database and table in MySQL. It shows how to 1) create a database called "menagerie", 2) select this database for use, 3) create a table called "pet" with columns to store information about pets, and 4) insert sample data into the table.

Uploaded by

gampesh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

• If the administrator creates your database for you when setting up your

permissions, you can begin using it. Otherwise, you need to create it yourself:

mysql> CREATE DATABASE menagerie;

Under Unix, database names are case sensitive

• Creating a database does not select it for use; you must do that explicitly. To make
menagerie the current database, use this command:

mysql> USE menagerie;


Database changed

Table :- Pet(name, owner, species, sex, birth, death)

Use a CREATE TABLE statement to specify the layout of your table:

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),


 species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

VARCHAR => the column values vary in length

mysql> SHOW TABLES;

To verify that your table was created the way you expected, use a DESCRIBE statement:

mysql> DESCRIBE pet;

• INSERT INTO TABLE :-

mysql> INSERT INTO pet


 VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);

To load the text file pet.txt into the pet table, use this command:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

You might also like