新手入门MySQL数据库命令大全
作者:人工智能 来源:IT科技类资讯 浏览: 【大中小】 发布时间:2025-11-05 09:02:04 评论数:
Windows操作系统进入CMD命令行,新手进入mysql.exe所在目录,入门运行命令
mysql.exe -h主机名 -u用户名 -p密码

注意:参数名与值之间没有空格 ,据库 如:-h127.0.0.1
二、命令数据库命令
1. 创建数据库
create database 数据库名;
如:
复制create database itsource;1.2. 切换到指定数据库
use 数据库名;
如:
复制use itsource;1.3. 显示数据库列表
复制show databases;1.4. 显示数据库建立语句
show create database 数据库名;
如:
复制show create database itsource;1.5. 修改数据库
alter database 数据库名 选项;
如:
复制alter database itsource charset=gbk;1.6. 删除数据库
drop database 数据库名;
如:
复制drop database itsource;1.三、大全数据表命令
1. 创建数据表
create table 数据表名(
字段名1 类型 修饰符,新手
字段名2 类型 修饰符,
字段名n 类型 修饰符
);
如:
复制create table news(id int primary key auto_increment,title varchar(50),author varchar(20),content text ); 1.2.3.4.5.2. 查看数据表列表
复制show tables;1.3. 查看数据表结构
desc 数据表名;
例如:
复制desc news;1.4. 查看数据表建表语句
show create table 数据表名;
如:
复制show create table news;1.5. 删除数据表
drop table 数据表名;
如:
复制drop table news;1.6. 修改数据表
alter table 数据表名 选项;
如:
复制alter table news charset=utf8;1.7. 新增字段
alter table 数据表名 add column 字段名 类型 修饰语句 位置
如:
复制alter table news add column newstime timestamp default current_timestamp after content;1.8. 修改字段定义
alter table 数据表名 modify column 字段名 新的定义
如:
复制alter table news modify column content longtext;1.9. 修改字段名及定义
alter table 数据表名 change column 旧字段名 新字段名 新的定义;
10. 删除字段
alter table 数据表名 drop column 字段名;
如:
复制alter table news drop column title;1.四、记录操作命令
1. 新增记录
insert into 数据表名(字段1,入门字段2,字段n) values(值1,值2,值n);
如:
复制insert into news(title,author,content) values(新闻标题,作者,新闻详细内容);1.注意:值的企商汇数量与类型必须与字段列表数量与类型定义一致
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; 1.2.3.注意:select语句是SQL中最为强大与复杂的查询语句,有七大子句,据库每段子句都可以省略,命令如果出现必须在正确的大全位置顺序上,不可调换先后位置。云服务器新手
3. 修改记录
update 数据表名 set 字段1=值1 and 入门字段2=值2 where 条件;
如:
复制update news set title=新的新闻标题 where id=1;1.4. 删除记录
delete from 数据表名 where 条件;
如:
复制delete from news where id=10;1.五、其它常用命令
复制set names gbk1.由于CMD命令行只支持系统当前编码,据库所以一般需要将CMD与MYSQL服务器的命令交互编码设置为gbk才能正常显示utf8的数据。
大全