1.查看数据库
mysql> show databases;
2.查看mysql数据库中的表
mysql> use mysql;
mysql> show tables;
3.查看user表属性信息
show table status from mysql where name='user'\G;
4.练习
a.创建库bookshop
mysql> create database bookshop;
b.在bookshop库下创建表reserver
mysql> create table reserve (id int primary key,bookname varchar(50),writer varchar(50),bookdate date,price float,amount int);
*primary key为主键,主键表明数据唯一性,后期做索引用
*或者指定数据库创建表
mysql> create table bookshop.test(id int primary key,name varchar(30),age int,sex varchar(20));
c.删除表
mysql> drop table test;
d.查看表结构
mysql> desc reserve
e.向reserve表插入数据
mysql> insert into reserve set id=1,bookname='live with linux',writer='tute',bookdate=2007-1-25,price=75.00,amount=50;
*第二种插入方式:
insert into reserve values(2,'Linux inside','Kevin','2008-2-15',83.00,50),
-> (3,'L.A.M.P','Tom','2008-2-5',82.50,50);
f.删除reserve表中第一行信息
mysql> delete from reserve where id=1;
*and或or的使用
mysql> delete from reserve where id=1 and writer='Kevin';(同时满足id=1和writer='Kevin')
mysql> delete from reserve where id=1 or writer='Kevin';(满足id=1或者writer='Kevin')
g.修改书名是L.A.M.P的库存为48:
mysql> update reserve set amount=48 where bookname='L.A.M.P';
****语法***