日期:2014-05-16  浏览次数:20969 次

新手操作mySQL命令 必看经典图解
Microsoft Windows XP [版本 5.1.2600]  //命令行模式下操作
(C) 版权所有 1985-2001 Microsoft Corp.

C:\Documents and Settings\reton.ma>d:

D:\>cd D:\Program Files\MySQL\MySQL Server 5.0\bin

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -polcp
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye

D:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -p
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.0.67-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| book               |
| mysql              |
| orilore            |
| student            |
| test               |
+--------------------+
6 rows in set (0.00 sec)

mysql> select * from employee;
ERROR 1046 (3D000): No database selected
mysql> use orilore;
Database changed
mysql> select * from employee;
+-----+-----------+-------+---------+
| Id  | name      | grade | salary  |
+-----+-----------+-------+---------+
| 100 | wang      |     2 | 4000.00 |
| 101 | sdfds     |     1 | 3220.00 |
| 102 | ieuriouer |     2 | 5454.00 |
| 103 | sddf      |     1 | 4000.00 |
| 104 | wefer     |     2 | 4000.00 |
| 105 | rewq      |     2 | 4000.00 |
+-----+-----------+-------+---------+
6 rows in set (0.00 sec)

mysql> delete from employee where id=105;
Query OK, 1 row affected (0.42 sec)

mysql> select * from employee;
+-----+-----------+-------+---------+
| Id  | name      | grade | salary  |
+-----+-----------+-------+---------+
| 100 | wang      |     2 | 4000.00 |
| 101 | sdfds     |     1 | 3220.00 |
| 102 | ieuriouer |     2 | 5454.00 |
| 103 | sddf      |     1 | 4000.00 |
| 104 | wefer     |     2 | 4000.00 |
+-----+-----------+-------+---------+
5 rows in set (0.00 sec)

mysql> create database mydb charset=gb2312;
Query OK, 1 row affected (0.42 sec)

mysql> use mydb;
Database changed
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| book               |
| mydb               |
| mysql              |
| orilore            |
| student            |
| test               |
+--------------------+
7 rows in set (0.00 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql> create table student(
    -> id int primary key auto_increment,
    -> name varchar(20) not null,
    -> age int
    -> );
Query OK, 0 rows affected (0.48 sec)

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

mysql> insert into student values(100,'wang',20);
Query OK, 1 row affected (0.41 sec)

mysql> select * from studen;
ERROR 1146 (42S02): Table 'mydb.studen' doesn't exist
mysql> select * from student;
+-----+------+------+
| id  | name | age  |
+-----+------+------+
| 100 | wang |   20 |
+-----+------+------+
1 row in set (0.00 sec)

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

mysql> desc student;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int(11)     | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | NO   |     | NULL    |                |
| age   | int(11)     | YES  |     | NULL    |                |
+-------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

mysql> descibe student;
ERROR 1