1. MySQL 数据库下载网址: https://dev.mysql.com/downloads/mysql/
账号是 root 密码是 a1************
网站账号是邮箱, 密码是 Aa1********
2 MySQL workbench. 操作 MySQL 的客户端, 可视化操作. 下载地址是
https://dev.mysql.com/downloads/workbench
alert table 是继续编辑表; drop table 是删除表
相关命令:
use myblog;
-- show tables; 注释
-- 增加内容
insert into users(username,`password`,realname) values('zhangsan','123','张三');
-- password 是关键字 所以包起来
insert into users(username,`password`,realname) values('lisi','123','李四');
-- 查询内容
- select * from users;
- select id,username from users;
- select * from users where username='zhangsan';
- select * from users where username='zhangsan' and password='123';
- select * from users where username='zhangsan' or password='12';
-- 模糊查询
select * from users where username like '%zhang%';
-- 排序 (查找 password 中包含 1 的数据, 并且根据 id 排序, 默认正顺序, desc 是倒顺序)
- select * from users where password like'%1%' order by id desc;
- --
- use myblog;
-- 直接执行 update 会报错, 安全问题, 所以先执行下面的命令
- SET SQL_SAFE_UPDATES = 0;
- update users set realname='李四 2' where username='lisi';
- select * from users;
-- 删除
- delete from users where username='lisi';
- select * from users;
- insert into users(username,`password`,realname) values('lisi','123','李四');
- select * from users;
-- 执行上述命令之后, 可以发现 李四的 id 已经变成 3 了, 因为之前 id=2 的时候已经被使用过了
-- 但一般用 update 去更新表格, 新增 state, 默认为 1;
-- 1 表示有效, 0 表示该行无效
- select * from users;
- select * from users where state='1';
-- 一般不会用 delete 去删除一行, 这样的话这一行就会空出来, 用 update, 且软删除的好处是, 可以恢复
- update users set state='0' where username='lisi';
- select * from users where state='1';
-- 查询 不等于 0
select * from users where state <> '0';
这里为了练习使用 delete, 所以采用 delete 方法, 故删掉 state 这一行:
中的 delete Selected;
来源: http://www.bubuko.com/infodetail-3101028.html