1.连接
mysql -h[主机地址] -u[用户名] -p[用户密码]
mysql -u root -p
2.创建数据库
create database <数据库名>;

3.查看所有的数据库
show databases;
注意,database后面有个s,以分号结尾。

4.使用某个数据库
use <数据库名>

5.创建一张表
create table <表的名字>(<字段1><类型2>,<字段2><类型2>,...);
示例:
create table wl_table(
id int(8) not null primary key auto_increment,
name char(50) not null,
age int(10) not null default ’10’,
score double(8,1) default ‘0’
);
注意结尾部分有分号。


6.插入一条数据
insert into <表名> values(值1,值2,值3…);
注意分号结尾。

使用默认值
insert into <表名> values(值1,值2,default,值3)

这里的age使用了默认值,即10(创建表的时候设置的).
7.查询表中的数据
select <字段1,字段2,字段3…> from <表名> where <条件>
查看表中所有数据
select * from wl_table

8.修改表中的数据
update <表名> set 字段=新值 where 条件
update wl_table set age=20 where id=3;

9.删除表中的数据
delete from <表名> where <条件>
delete from wl_table where id=2;

10.查询数据库中的总数据条数
select count(*) from 表名;

11.退出数据库
\q

加油~
网友评论