MySQL终端操纵常用命令【MySQL教程】,mysql,命令
本文重要报告的是数据库运用中最经常使用的终端操纵敕令,人人一起来进修相识一下吧!
一、数据库敕令
1、衔接数据库
mysql -uroot -p暗码
2、竖立数据库
create database 库名;
3、切换到指定数据库
use 库名;
4、显现数据库列表
show databases;
5、显现数据库竖立语句
show create database 库名;
6、修正数据库
alter database 库名 选项;
7、删除数据库
drop database 库名;
二、数据表敕令
1、竖立数据表
create table 数据表名(字段名1 范例 润饰符,字段名2 范例 润饰符,字段名3 范例 润饰符,…);
create table news(id int primary key auto_increment,
title varchar(50),author varchar(20),content text);
2、检察数据表列表
show tables;
3、检察数据表构造
desc 数据表名;
4、检察数据表建表语句
show create table 数据表名;
5、删除数据表
drop table 数据表名;
6、修正数据表
alter table 数据表名 选项;
7、新增字段
alter table 数据表名 add column 字段名 范例 润饰语句 位置;
alter table news add column newstime timestamp default current_timestamp after content;
8、修正字段定义
alter table 数据表名 modify column 字段名 新的定义;
alter table news modify column content longtext;
9、修正字段名及定义
alter table 数据表名 change column 旧字段名 新字段名 新的定义;
10、删除字段
alter table 数据表名 drop column 字段名;
三、纪录操纵敕令
1、新增纪录
insert into 数据表名(字段1,字段2,…,字段n) values(值1,值2,…,值n);
注重:值的数目与范例必需与字段列表数目与范例定义一致
2、检察纪录
select 字段列表 from 数据表名 where 前提 order by 字段名 desc limit m,n;
select * from news;
select * from news where id=10;
select * from news order by id desc limit 10;
注重:select语句时SQL中最为壮大与庞杂的查询语句,有七大子句,每段子句都可以省略,
假如涌现,必需涌现在准确的位置递次上,不可以换取先后递次
3、修正纪录
update 数据表名 set 字段1=值1 and 字段2=值2 where 前提;
update news set title=‘xxxxx’ where id=1;
4、删除纪录
delete from 数据表名 where 前提;
delete from news where id=10;
【引荐课程:mysql视频教程】
以上就是MySQL终端操纵经常使用敕令的细致内容,更多请关注ki4网别的相干文章!