当前位置:网站首页>数据库 | SQL增删改查基础语法
数据库 | SQL增删改查基础语法
2022-07-31 05:11:00 【Benni-King】
命令模式下输入
如果是linux的终端terminal复制粘贴的话就是用鼠标中键
linux 查看系统日期 内存 进程
查看日期
date
查看内存
free -h
磁盘使用情况
df -h
查看进程
ps -ef
然后就回罗列出一堆进程,自己选择杀死进程几
kill -9
防火墙
查看防火墙状态
systemctl status firewalld.serivce
停止firewalld服务(一次)
systemctl stop firewalld.serivce
开机禁用firewalld服务(永久)
systemctl disable firewalld.serivce
查看本机MySQL状态
sudo service mysql status
sudo service mysql start
终端启用MySQL
mysql -uroot -p
后输入密码
对数据库的操作
查看现在时间
select now();
查看
select version();
使用某个数据库
use DatabaseName();
选择(查看)当前use的数据库
select DatabaseName();
创建 字符集默认是latin
create database name01 charset=utf-8;
查看刚刚创建的信息
show create database name01;
删除数据库
drop database name01;
对数据表的操作
1. 查看当前数据库中的所有表
show tables;
2. 创建新的表
create table xxxx(id int , name varchar(30));
create table yyyy(id int primary key not null , name varchar(30));
create table students(
id int unsigned not null auto_increment primary key,
name varchar(30),
age tinyint unsigned default 0,
high decimal(5,2);
gender enum("男","女","保密") default "保密"
class_id int unsigned
)
3. 查看这个表的详细信息,表头,
desc xxxx;
4.查看这个表的所有信息
select * from students;
5. 查看这个表是怎么创建的
show create table students;
增
mysql> select * from student;
+----+--------+--------+------+
| ID | Name | Gender | Age |
+----+--------+--------+------+
| 1 | Benni | Men | 22 |
| 2 | Icey | Women | 23 |
| 3 | yeager | Men | 22 |
| 4 | NULL | NULL | NULL |
| 5 | yeager | Men | 22 |
| 6 | Lili | Women | 22 |
+----+--------+--------+------+
6 rows in set (0.00 sec)
--单行插入
insert into student values(1, "James", NULL, 5);
--多行插入
mysql> insert into student(ID,name) values(7,'小王’),(8,'李磊'); -- alter table 表名 add 列名 类型; alter table students add birthday datetime; --枚举可以用123代替具体的文字-- insert into students values ('小明',18,180.00,2,1,0), ('小月月',18,180.00,2,2,1), (彭于晏',29,185.00,1,1,0),
('刘德华',59,175.00,1,2,1),
('黄蓉',38,160.00,2,1,0),
('凤姐',28,150.00,4,2,1),
('王祖贤',18,172.00,2,1,1),
('周杰伦',36,NULL,1,1,0),
('程萧',27,181.00,1,2,0),
('刘亦菲',25,166.00,2,2),
('金星',33,162.00,3,3,1),
('静香',12,180.00,2,4,0),
('郭靖',12,170.00,1,4,9),
('周杰',34,176.00,2,5,0);
修改
mysql> select * from student;
+----+--------+--------+------+
| ID | Name | Gender | Age |
+----+--------+--------+------+
| 1 | Benni | Men | 22 |
| 2 | Icey | Women | 22 |
| 3 | yeager | Men | 22 |
| 5 | yeager | Men | 22 |
| 6 | Lili | Women | 22 |
+----+--------+--------+------+
5 rows in set (0.00 sec)
mysql> update student set Name='Yeagerrrr' where ID=5;
-- 修改表 不重命名版
-- 在表名student里面的birthday数据类型type修改为date
alter table students modify birthday date;
-- 在表名student里面的birthday数据类型type修改为date,并重命名为birth
alter table students modify birthday birth date;
alter table students modify birthday birth date default "2022-01-01";
--把性别整一列的枚举值都改为1
update students set gender = 1;
update students set gender = 1 where id = 1;
删除
+----+--------+--------+------+
| ID | Name | Gender | Age |
+----+--------+--------+------+
| 1 | Benni | Men | 22 |
| 2 | Icey | Women | 22 |
| 3 | yeager | Men | 22 |
| 4 | NULL | NULL | NULL |
| 5 | yeager | Men | 22 |
| 6 | Lili | Women | 22 |
+----+--------+--------+------+
6 rows in set (0.00 sec)
mysql> delect from student where ID=4;
--删数据库
drop database name;
delect from student where ID=4;
--表清空
delect from students;
# 查
--根据表名查
select name gender from students;
select id as 序号, gender as 性别 , name as 姓名 from students;
边栏推荐
- 11 【定位】
- gin框架学习-Casbin进阶之策略管理API使用方法
- Linux修改MySQL数据库密码
- uni-app进阶之自定义【day13】
- GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
- What is the difference between NFT and digital collection?
- Qt Creator + CMake 运行调试总会自动 build 所有目标
- 闭包(四)----IIFE
- GUCCI, LV and other luxury giant universe how to layout yuan, other brands should keep up with?
- 初涉C语言
猜你喜欢
随机推荐
Detailed explanation of pointers in C language
npm WARN config global `--global`, `--local` are deprecated. Use `--location解决方案
leetcode-每日一题1217. 玩筹码(贪心+位运算)
What is an EVM Compatible Chain?
leetcode-每日一题剑指 Offer II 041. 滑动窗口的平均值(队列模拟)
2021 Mianjing - Embrace Change
leetcode-2321. 拼接数组的最大分数(差分+枚举)
[Elastic-Job] Overview of Distributed Scheduling Tasks
Linux modify MySQL database password
年终总结——岁月静好~
Build vulhub vulnerability shooting range on kali
MySQL compressed package installation, fool teaching
阿里一面,说说你知道消息中间件的应用场景有哪些?
SQL注入中数据库的判断
MySQL高级语句(一)
字符串的新增方法
10 【高度塌陷与BFC】
Judgment of database in SQL injection
(Crypto必备干货)详细分析目前NFT的几大交易市场
永恒之蓝漏洞复现