mysql 常用sql
mysql 的常用 sql 命令就是一般的增、删、查、改
数据库
创建
> create database db1 default charset utf8;
# 创建db1数据库并指定字符集utf8
> create database if not exists db1 default charset utf8 collate utf8_general_ci;
# if not exists 如果数据库不存在就创建
# collate utf8_general_ci : mysql的字符序遵从命名惯例。以_ci(表示大小写不敏感),以_cs(表示大小写敏感),以_bin(表示用编码值进行比较)删除
> drop database db1;
> drop database if exists db1;数据表
创建
> create table if not exists users (
-> userID int(11) not null auto_increment,
-> username varchar(64) default null,
-> nickname varchar(32) unique default null,
-> age int(11) default null,
-> description varchar(256) default null,
-> primary key (userID)
-> ) engine=MyISAM;命令解析:
create table tbname (...) :创建表unique
userID int(11) not null auto_increment :指定字段,
int(11)字段类型,not null不为空,auto_increment自增长,unique: 唯一字段primary key (userID) :指定主键
engine=MyISAM :表引擎
查看表结构
修改
删除
table的增删查改
插入数据
修改数据
查询数据
删除数据
最后更新于
这有帮助吗?