MySQL基本增删改查语句练习

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介: MySQL基本增删改查语句练习 #创建数据库: create database zhangsan character set gbk; # 为了便于在命令提示符下显示中文, 在创建时通过 character set gbk 将数据库字符编码指定为 gbk #要对一个数据库进行操作, 必.

MySQL基本增删改查语句练习

#创建数据库:
create database zhangsan character set gbk; # 为了便于在命令提示符下显示中文, 在创建时通过 character set gbk 将数据库字符编码指定为 gbk

#要对一个数据库进行操作, 必须先选择该数据库
C:\Users\Administrator>mysql -u root -p #登录MySQL环境
Enter password: ********

mysql> mysql -D zhangsan -u root -p #登录创建好的zhangsan数据库
-> use zhangsan
-> ^C

mysql> use zhangsan #登录后使用zhangsan这个数据库
Database changed #有该提示表示可以成功使用zhangsan这个数据库

#创建数据库表:
create table students
(
id int unsigned not null auto_increment primary key,
name char(8) not null,
sex char(4) not null,
age tinyint unsigned not null,
tel char(13) null default “-”
);

create table students
(
id int unsigned not null auto_increment primary key,
name char(20)not null,
sex char(4)not null,
result int(10) not null,
age tinyint unsigned not null,
tel char(20) null default “-”
);

#插入数据库
mysql> insert into students values(NULL,“王刚”,“男”,20,“12345678”);
Query OK, 1 row affected (0.53 sec)

mysql> select name,age from students;
±-------±----+
| name | age |
±-------±----+
| 王刚 | 20 |
±-------±----+
1 row in set (0.30 sec)

查询数据库:
mysql> select * from students;
±—±-------±----±----±---------+
| id | name | sex | age | tel |
±—±-------±----±----±---------+
| 1 | 王刚 | 男 | 20 | 12345678 |
±—±-------±----±----±---------+
1 row in set (0.00 sec)

插入数据库:
mysql> insert into students values(NULL,“钟无艳”,“女”,100,“987654321”);
Query OK, 1 row affected (0.35 sec)

mysql> select * from students;
±—±----------±----±----±----------+
| id | name | sex | age | tel |
±—±----------±----±----±----------+
| 1 | 王刚 | 男 | 20 | 12345678 |
| 2 | 钟无艳 | 女 | 100 | 987654321 |
±—±----------±----±----±----------+
2 rows in set (0.00 sec)

查询数据库:
mysql> select * from students where sex=“女”;
±—±----------±----±----±----------+
| id | name | sex | age | tel |
±—±----------±----±----±----------+
| 2 | 钟无艳 | 女 | 100 | 987654321 |
±—±----------±----±----±----------+
1 row in set (0.28 sec)

修改数据库:
mysql> update students set tel = 123 where id = 2;
Query OK, 1 row affected (0.36 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from students;
±—±----------±----±----±---------+
| id | name | sex | age | tel |
±—±----------±----±----±---------+
| 1 | 王刚 | 男 | 20 | 12345678 |
| 2 | 钟无艳 | 女 | 100 | 123 |
±—±----------±----±----±---------+
2 rows in set (0.00 sec)

删除数据库:
mysql> delete from students where id=1;
Query OK, 1 row affected (0.35 sec)

mysql> select * from students;
±—±----------±----±----±-----+
| id | name | sex | age | tel |
±—±----------±----±----±-----+
| 2 | 钟无艳 | 女 | 100 | 123 |
±—±----------±----±----±-----+
1 row in set (0.00 sec)

修改数据库:
mysql> update students set id = 1 where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0

mysql> select * from students;
±—±----------±----±----±-----+
| id | name | sex | age | tel |
±—±----------±----±----±-----+
| 2 | 钟无艳 | 女 | 100 | 123 |
±—±----------±----±----±-----+
1 row in set (0.00 sec)

mysql> update students set id = 1 where id = 2;
Query OK, 1 row affected (0.40 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from students;
±—±----------±----±----±-----+
| id | name | sex | age | tel |
±—±----------±----±----±-----+
| 1 | 钟无艳 | 女 | 100 | 123 |
±—±----------±----±----±-----+
1 row in set (0.00 sec)

原文地址 https://blog.csdn.net/weixin_43184774/article/details/82819519
相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1月前
|
存储 关系型数据库 MySQL
【mysql】—— 表的增删改查
【mysql】—— 表的增删改查
|
2月前
|
关系型数据库 MySQL 数据库
|
3月前
|
SQL 关系型数据库 MySQL
MySQL | 数据库的管理和操作【表的增删改查】(二)
MySQL | 数据库的管理和操作【表的增删改查】(二)
|
3月前
|
SQL 存储 缓存
SQL语句在MySQL中是如何执行的
SQL语句在MySQL中是如何执行的
45 0
|
18天前
|
存储 Java 关系型数据库
不同主题增删改查系统【控制台+MySQL】(Java课设)
不同主题增删改查系统【控制台+MySQL】(Java课设)
12 0
|
1月前
|
SQL 关系型数据库 MySQL
MySQL表的增删改查(进阶)
MySQL表的增删改查(进阶)
|
1月前
|
SQL 存储 关系型数据库
MySQL表的增删改查(基础且保姆级的教程)
MySQL表的增删改查(基础且保姆级的教程)
|
2月前
|
关系型数据库 MySQL 数据库
MySQL员工打卡日志表——数据库练习
MySQL员工打卡日志表——数据库练习
136 0
|
3月前
|
SQL 关系型数据库 MySQL
MySQL | 数据库的表的增删改查【进阶】【万字详解】(二)
MySQL | 数据库的表的增删改查【进阶】【万字详解】(二)
|
3月前
|
存储 关系型数据库 MySQL
MySQL | 数据库的表的增删改查【进阶】【万字详解】(一)
MySQL | 数据库的表的增删改查【进阶】【万字详解】(一)