MySQL基础操作

2022-12-26  本文已影响0人  小阿飞的小蝴蝶

打开MySQL
我的电脑 -> 管理 -> 计算机管理 -> 服务和应用程序 -> MySQL 打开

关闭MySQL
任务管理器 mysqld.exe 关闭进程

MySQL基础命令
(MySQL基础命令)

cmd 进入D:\mysql\mysql-8.0.25-winx64\bin目录
登录数据库
mysql -u root -p 密码

显示数据库列表
show databases;

显示库中的数据表
use seckill;
show tables;

显示表结构
describe goods;

查看表数据
select * from goods;

建库与删库:
create database 库名;
drop database 库名;

建表:
use 库名;
create table 表名(字段列表);
create table device (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL,
info VARCHAR(50) NOT NULL);
drop table 表名;

清空表中记录:
delete from 表名;
truncate table 表名;

update tbl_user set age = 30 where user_name = 'jay'

select * from user_tbl where age=26 and signin_date='2022-12-28';

insert into user_tbl value('xiaoafei',26,'18513687318','1311257372','2022-12-27');

create table user_tbl(user_name varchar(30),age int,phone_num varchar(11),password varchar(20),signin_date date);

delete from tbl_user where user_name = 'jay';

alter table tbl_user add email varchar(30);

alter table tbl_user drop email;

alter table tbl_user change age user_age int;

alter table tbl_user change user_age user_age tinyint(1) not null;

alter table tbl_user rename user_tbl;

drop table user_tbl;

alter table user_tbl modify id int first;

alter table user_tbl modify signin_date date alter email;

insert into user (name,age,phone,password,email) values ('tom',33,'15623656564','6464634343','15623656564@qq.com');

select * from user limit 0,5; 第一页 5条数据

select * from user limit 5,5; 第二页 5条数据

select * from user limit 10,5; 第三页 5条数据

分页查询公式 (page - 1) * pageSize , pageSize.

select * from user limit (page - 1) * pageSize , pageSize;

//外连接 分为三种 左连接 右连接 全外连接
select * from tbl_user left join tbl_address on tbl_user.id = tbl_address.user_id;

select * from tbl_user right join tbl_address on tbl_user.id = tbl_address.user_id;

select * from tbl_user full join tbl_address on tbl_user.id = tbl_address.user_id;

//内连接
select * from tbl_user join tbl_address on tbl_user.id = tbl_address.user_id where user_id = '10';

//交叉连接 没有where条件的交叉连接将产生连接表所涉及的笛卡尔积
select * from tbl_user cross join tbl_address;

group by 分组
having count(字段)>1 重复字段。

order by 排序
order by 字段 desc 降序
order by 字段 asc 升序
字段 & 1 取奇

上一篇 下一篇

猜你喜欢

热点阅读