MQSQL重要命令:
1.显示当前所有数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
2.创建一个新的数据库
mysql> create database linux;
+--------------------+
| Database |
+--------------------+
| information_schema |
| linux |
| mysql |
| test |
+--------------------+
3.删除一个数据库
mysql> drop database linux;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
4.指定当前数据库
mysql> use test
Database changed
5.创建新表
例如创建一个book的表,形式如下,可执行如下语句:
mysql> create table book(bookid int auto_increment primary key,bname varchar(30)
not null,bprice double,categoryid int);
6.为book表增加一列
mysql> alter table book add column des varchar(60);
结果如下:
7.增加一个自增长的主键
mysql> alter table category add primary key(categoryid);
mysql>alter table category modify column categoryid int not null auto_increment;
执行mysql> show create table category; 看看是否成功
CREATE TABLE `category` (
`categroyid` int(11) NOT NULL auto_increment,
`cname` varchar(30) NOT NULL,
`cdes` varchar(60) default NULL,
PRIMARY KEY (`categroyid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
8.删除主键
mysql> alter table category drop primary key(categoryid);
9.插入数据
mysql> insert into category(cname,cdes) values("sport","i love sport");
mysql> insert into category(cname,cdes) values("music","i love music");
索引:
视图: