Mysql的一些常用方法
查看当前所有的数据库:
show databases;
新建数据库:
create database 数据库名;
删除数据库:
drop database 数据库名;
选择(进入) 数据库:
use 数据库名;
查看当前数据库所有的表:
show tables;
查看 某个表的字段结构 :
desc 表名;
查询表数据:
select * from 表名;
新建表:
CREATE TABLE 表名 <
字段名字 数据类型 修饰,
...
>;
添加数据:
insert into 表名 valuse(值,值);
修改数据表:
alter table 表名 add 字段名 类型 修饰【加的列在表的最后面】
alter table 表名 add 字段名 类型 修饰 after 某列【把新列加在某列后面】
修改数据:
update user set name=新值 where 表达式
删除数据表:
drop table 表名;
删除列:
alter table 表名 drop 列名称;
删除数据:
delete from 表名 where 表达式;
查询所有行:
命令:select 【字段,字段,…】 from 表名 where 表达式
查询前几行数据:
select from 表名 order by id limit 【开始行,最后行】
更新字段内容 :
update 表名 set 字段名 = 新内容
update 表名 set 字段名 = replace(字段名,'旧内容','新内容')
另外MySQL有三大类数据类型
分别为数字、时间、字符串
整数: tinyint、smallint、mediumint、int、bigint
浮点数: float、double、real、decimal
时间: date、time、datetime、timestamp、year
字符串: char、varchar
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment