1、查看所有数据库: mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.00 sec) 2、打开test数据库 mysql> use test; Database changed 3、空的 mysql> show tables; Empty set (0.00 sec) 4、到mysql库查看里面的表: mysql> show tables from mysql; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | | db | | event | | func | | general_log | | help_category | | help_keyword | | help_relation | | help_topic | | host | | ndb_binlog_index | | plugin | | proc | | procs_priv | | proxies_priv | | servers | | slow_log | | tables_priv | | time_zone | | time_zone_leap_second | | time_zone_name | | time_zone_transition | | time_zone_transition_type | | user | +---------------------------+ 24 rows in set (0.00 sec) 5、查看当前所在的数据库 mysql> select database(); +------------+ | database() | +------------+ | test | +------------+ 1 row in set (0.00 sec) 6、创建stuinfo表的结构: mysql> create table stuinfo( -> id int, -> name varchar(20)); Query OK, 0 rows affected (0.01 sec) 7、打开当前所在库的表: mysql> show tables; +----------------+ | Tables_in_test | +----------------+ | stuinfo | +----------------+ 1 row in set (0.00 sec) 8、查看表的结构: mysql> desc stuinfo; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) 8、查看stuinfo表: mysql> select * from stuinfo; Empty set (0.00 sec) 9、插入数据: mysql> insert into stuinfo (id,name) values(1,'john'); Query OK, 1 row affected (0.00 sec) mysql> insert into stuinfo (id,name) values(2,'rose'); Query OK, 1 row affected (0.00 sec) mysql> select * from stuinfo; +------+------+ | id | name | +------+------+ | 1 | john | | 2 | rose | +------+------+ 2 rows in set (0.00 sec) 10、更新表的数据 mysql> update stuinfo set name='lilei' where id=1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from stuinfo; +------+-------+ | id | name | +------+-------+ | 1 | lilei | | 2 | rose | +------+-------+ 2 rows in set (0.00 sec) 11、删除表 mysql> delete from stuinfo where id=1; Query OK, 1 row affected (0.00 sec) mysql> select * from stuinfo; +------+------+ | id | name | +------+------+ | 2 | rose | +------+------+ 1 row in set (0.00 sec) 12、查看mysql的版本号 mysql> select version(); +-----------+ | version() | +-----------+ | 5.5.15 | +-----------+ 1 row in set (0.00 sec) mysql> exit Bye