Windows安装并使用MySQL

下载MySQL(Windows):

https://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-8.0.26.0.msi

 

安装MySQL:

使用开发默认配置,root密码设成自己能记住的,以后如果密码忘了就重装

 

创建数据库、创建表、给表加减列(修改表)、删除表:

使用DBeaver、Workbench、Navicat都可以

 

建表时常用的数据类型:

int、bigint、varchar、longtext

 

其他操作(包括基本的增删改查):

use myblog;

show tables;

insert into users (username, `password`, realname) values ('lisi', '123', '李四');

select * from users;

select id, username from users;

select * from users where username='zhangsan' and password='123';

select * from users where username='zhangsan' or password='123';

select * from users where username like '%zhang%';

select * from users where password like '%1%';

select * from users where password like '%1%' order by id desc;

SET SQL_SAFE_UPDATES = 0;

update users set realname='李四2' where username='lisi';

delete from users where username='lisi'; -- 实际不用

select * from users where state='1';

select * from users where state<>'0';

update users set state='0' where username='lisi'; -- 软删除

update users set state='1' where username='lisi'; -- 恢复

 

insert into blogs (title, content, createtime, author) values ('标题A', '内容A', 1614000592592, 'zhangsan');

insert into blogs (title, content, createtime, author) values ('标题B', '内容B', 1614000716930, 'lisi');

select * from blogs where author='lisi' order by createtime desc;

select * from blogs where title like '%标题%' order by createtime desc;

 

select version();

 

posted @ 2021-02-22 21:23  starlog  阅读(80)  评论(0编辑  收藏  举报