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;
原文:https://www.cnblogs.com/xiaozhumaopao/p/11071863.html