下载地址: https://dev.mysql.com/downloads/mysql/
— 通过 * 把 users 表中所有数据查询出来
select * from users
— 从 users 表中把 username 和 password 对应的数据查询出来
select username, password from users
— 向 users 表中, 插入新数据, username 的值为 tony stark password 的值为 098123
insert into users (username, password) values (‘tony stark’, ‘098123’)
select * from users
— 把users 里面id为5的用户密码,修改一条数据 密码为888888
update users set password=’888888’ where id=5
— 把 users 里面 id为6的 用户名和 动态 status0 修改成1 修改多条数据
update users set username=’admin123’, status=’1’ where id=6
— 删除 users 表中, id 为 4 的用户
delete from users where id=4
— 演示 where 子句的使用
select from users where status=1 // 查询status=1
select from users where id>2 // 查询id>2 的
select from users where username!=’zs’ * // 查询 姓名不是 ‘zs’ 的 其他人
— 使用 AND 来显示所有状态为0且id小于3的用户
select * from users where status=0 and id<3
— 使用 or 来显示所有状态为1 或 username 为 ‘xh’ 的用户
select * from users where status=1 or username=’xh’
— 对 users 表中的数据, 按照 status 字段进行升序排序
select * from users order by status
— 按照 id 对结果进行行降序排序 desc 表示降序排序 asc 表示升序排序(默认情况下, 就是升序排序的)
select * from users order by id desc
— 对 users 表中的数据, 先按照 status 进行降序排序, 再按照 username 字母顺序, 进行升序排序
select * from users order by status desc, username asc
— 使用 count(*) 来统计 users 表中, 状态为 0 用户的总数量
select count(*) from users where status=0 // 结果只显示有多少个数字 2
— 使用 AS 关键字给列起别名
— select count(*) as total from users where status=0 // 下面展示的别名就是 total 而不是count
select username as uname, password as upwd from users // 下面展示的 username 修改成了uname, password 修改成了 upwd
现在文件夹中运行 终端 npm init -y // 生成一个package.json 安装项目文件表
然后运行 npm i mysql // 安装mysql数据库