1、下载安装mysql
https://dev.mysql.com/downloads/mysql/
选择最新版安装。执行安装过程中需要输入root用户名和密码,自己用你开心
2、下载安装mysql workbench
https://dev.mysql.com/downloads/workbench
3、打开workbench 连接到mysql服务
…
show databases;
建表users/blogs
tables — > create tables —> 完毕之后点击apply
基本sql语句
select username, nickname from users;
select * from blogs order by id desc;
select username, nickname from users where username=’zhangsan’ and password
=’1234’;
insert into users (username, password
, nickname) values (‘zhangsan’, ‘123’, ‘张三’);
update blogs set content=’内容1内容1’ where id=’1’;
delete from blogs where id=2;
增删改查
查询总数,分页
总数 select count(id) as count
from blogs;
分页 select from blogs order by id desc limit 2 offset 2; (offset 2n)
外键
创建外键
Foreign keys
更新限制&删除级联
连表查询
select from blogs inner join users on users.id = blogs.userid;
解决有多个id
select blogs.,users.username,users.nickname from blogs inner join users on users.id = blogs.userid;
ER图