参考: 21分钟MySQL入门教程html
登陆MySQL
mysql -D DATABASENAME -h HOSTNAME -P PORT -u USERNAME -p
-D 登陆后进入数据库,非必选
-h 指定登陆主机名,登陆当前机器可省略
-P 端口
-u 登陆用户名
-p 使用密码登陆,若该用户没有设置密码可省略mysql
建立数据库
create database DATABASENAME [other options];
other options 如character set
查看已建立的数据库
show databasessql
选择所要操做的数据库
1、登陆时直接指定
2、登录后
use DATABASENAME;数据库
建立数据库表
create table TABLENAME(columns);
查看已建立的表名称
show tables;
查看已建立的表的详细信息
describe TABLENAME;post
向表中插入数据
insert [into] TABLENAME [(COLUMNNAME1, COLUMNNAME2, ...)] values (VALUE1, VALUE2, ...);htm
查询表中数据
select COLUMNNAME from TABLENAME [where conditions];
COLUMNNAME能够用通配符 * 代替,查询全部列
where子句支持=、<、>、<=、>=、!=、is [not] null、in、like、or、and等等blog
更新表中数据
update TABLENAME set COLUMNNAME = NEWVALUE [where conditions];教程
删除表中数据
delete from TABLENAME [where conditions];get
添加表
alter table TABLENAME add COLUMNNAME DATATYPE [after postion];it
修改列
alter table TABLENAME change OLDCOLUMNNAME NEWCOLUMNNAME DATATYPE;
删除列
alter table TABLENAME drop COLUMNNAME;
重命名表
alter table OLDTABLENAME rename NEWTABLENAME;
删除整张表
drop table TABLENAME;
删除数据库 drop database [if exists] DATABASENAME;