数据库基础运用

列出所有的数据库:show databases;
创建一个数据库 :crate database feng;
使用这个数据里:use feng;
列出这个数据库的所有表:show tables;
创建一张名字为table1的表并定义字段名以及字段的类型:
        create table table1(id int(11) DEFAULT NULL,name varchar(30) DEFAULT NULL,book varchar(30) DEFAULT     NULL)ENGINE =MyISAM   DEFAULT CHARSET=utf8;(加上后面的一句话是为了防止输入中文时乱码)
查看table1具体字段信息:desc table1; 
查看创建table1的命令行:show create table table1;
 
插:insert into table1(id,name ,book) values('1','dingdang','傲慢与偏见');
查:select * from table1;(查所有信息)或者select id,name from table1;(查id和name的信息)
改:update table1 set book="《傲慢与偏见》" where id=1;(如果不加where的话,所有的book字段都会改变)
增:alter table friend1 add passwd varchar(30) DEFAULT NULL;(给表friend1增加passwd字段)
删除一条:delete from table1 where id=1;
删表:drop table table1;
删库:drop database feng;
查表里的某些类容:select * from table1 where book like '%与%';(%匹配任何内容)
将两张表关联起来mysql> select table1.id,table1.name,table1.book,table2.age from table2,table1 where table2.name = table1.name;
 
远程登录数据库:mysql -h192.168.137.11 -uroot -phaoning 
如果出现乱码:mysql --default-character-set=utf8 -h192.168.137.11 -uroot -phaoning

猜你喜欢

转载自fengxyun.iteye.com/blog/2286768