작성일 : 10-06-22 04:44
[서버관리] Create a mysql database, tables and insert data
 글쓴이 : 테크넷코리…
조회 : 7,147  

Create a mysql database, tables and insert data

by Vivek Gite · 20 comments

Q. How do I create a MySQL database and tables?
A. If you want to create a database and set up tables for the same use the following two sql commands:
=> CREATE DATABASE - create the database
=> CREATE TABLE - create the table
=> INSERT - To add/insert data to table
CREATE DATABASE creates a database with the given name. To use this statement, you need the CREATE privilege for the database
CREATE TABLE creates a table with the given name. You must have the CREATE privilege for the table.
INSERT inserts new rows into an existing table.

Procedure for creating a database and a sample table

Login as the mysql root user to create database:
$ mysql -u root -p
Add a database called books
mysql> CREATE DATABASE books;
Now database is created. Use a database with use command:
mysql> USE books;
Now create a table called authors with name, email and id:
mysql> CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
Display your table name just created:
| Tables_in_books |
| authors         |
1 row in set (0.00 sec)
Now add a data / row to table books using INSERT statement:
mysql> INSERT INTO authors (id,name,email) VALUES(1,"Vivek","xuz@abc.com");
Query OK, 1 row affected (0.00 sec)
Add few more rows:
mysql> INSERT INTO authors (id,name,email) VALUES(2,"Priya","p@gmail.com");
INSERT INTO authors (id,name,email) VALUES(3,"Tom","tom@yahoo.com");
Now display all rows:
mysql> SELECT * FROM authors;
| id   | name  | email         |
|    1 | Vivek | xuz@abc.com   |
|    2 | Priya | p@gmail.com   |
|    3 | Tom   | tom@yahoo.com |
3 rows in set (0.00 sec)
Now you know how to create a database and a table. For further information please see MySQL data types and official documentation.


whois inames 아사달 Domainpapa Digitalnames Netpia OnlineNIC KSNETCMS KSNETPG ICODE
회사소개 | 웹제작및유지보수약관 | 호스팅서비스약관 | | 테크넷웹메일
서울시 양천구 목동중앙본로7가길 26-6 / 전화 : 1688-2527 | 긴급 : 010-4697-2527 / 팩스 : 0303-0303-0840 / 운영자 : 테크넷
사업자 등록번호 : 107-42-67578 / 대표 : 강만수 / 개인정보관리책임자 : / 통신판매업신고번호 :
Copyright © 2001-2008 테크넷코리아. All Rights Reserved.