最新消息: 新版网站上线了!!!

MYSQL命令行的使用,建库建表建记录

  • mysql> create database test;
    Query OK, 1 row affected (0.00 sec)


    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | test               |
    +--------------------+
    3 rows in set (0.02 sec)


    mysql> use test
    Database changed
    mysql> create table book(id int(3) not null
        -> auto_increment,name char(50) not null
        -> ,unique(id),primary key(id));
    Query OK, 0 rows affected (0.42 sec)

    mysql> show tables
        -> ;
    +----------------+
    | Tables_in_test |
    +----------------+
    | book           |
    +----------------+
    1 row in set (0.00 sec)

    mysql> describe book;
    +-------+----------+------+-----+---------+----------------+
    | Field | Type     | Null | Key | Default | Extra          |
    +-------+----------+------+-----+---------+----------------+
    | id    | int(3)   | NO   | PRI | NULL    | auto_increment |
    | name  | char(50) | NO   |     | NULL    |                |
    +-------+----------+------+-----+---------+----------------+
    2 rows in set (0.08 sec)

     


    好了,插入记录看看
    mysql> insert into book(name) values("PHP5.0");
    Query OK, 1 row affected (0.09 sec)

    mysql> insert into book(name) values("MYSQL5.0");
    Query OK, 1 row affected (0.00 sec)

    mysql> select * from book;
    +----+----------+
    | id | name     |
    +----+----------+
    |  1 | PHP5.0   |
    |  2 | MYSQL5.0 |
    +----+----------+
    2 rows in set (0.00 sec)

    删除一条看看
    mysql> delete from book where id=1;
    Query OK, 1 row affected (0.03 sec)

    mysql> select * from book;
    +----+----------+
    | id | name     |
    +----+----------+
    |  2 | MYSQL5.0 |
    +----+----------+
    1 row in set (0.00 sec)

    大家可以看到在data文件夹下面有test文件夹,在其里面有三个文件,分别是book.frm,book.MYD,book.MYI

     

    当然可以使用PHPMyAdmin来操作更直观。

.....

转载请注明:谷谷点程序 » MYSQL命令行的使用,建库建表建记录