MySQL(前言)狂神笔记

1.初识MySQL

image

1.1 为什么学习数据库

image

1.2 什么是数据库

image

1.3 数据库分类

image
image

1.4 MySQL简介

image

尽量不要使用exe安装,会有注册表卸载难 ,尽可能使用压缩包安装

1.5 基本使用

启动和关闭的是服务

net stop mysql
net start mysqlnet start mysql
mysql -u root -p(后面不加空格但可直接加密码)连接数据库
flush privileges;//刷新权限
update mysql.user set authentication_string=password('*****') where user='root' and Host='localhost';--修改用户密码
show databases;--查看所有数据库
use 数据库名 ;--切换数据库
show tables ;--查看所有表
describe 表名 ;--显示表中所有信息
create database 数据库名;--创建数据库
exit;--退出连接
/*多行注释
*/

2.操作数据库

2.1 基本语句

create database if not exists 名字;
drop database if exists 名字;
use `name`; --tab上,如果表名或字段名是一个特殊字符要加这个符号``
show databases;--查看所有数据库

2.2 列类型

image
image
image

2.3 字段属性*

image
image
image

2.4 创建表

image

create table if not exists `student`(
  `id` int(4) not null auto_increment comment '学号',
  `name` carchar(30) not null default '匿名' comment '姓名',
)

image
image

2.5 数据表类型

数据库引擎区别:
image
image
image
建议在创建表使用,更改本地ini文件可能导致别人运行SQL文件出问题

2.6 修改和删除

--修改表名 alter table 旧表名 rename as 新表名
alter table teacher rename as teacher1

--添加字段 alter table 表名 add 字段名 列属性
alter table teacher1 add age int(11)

--修改表字段 alter table 表名 modify 字段名 列属性[]
alter table teacher1 modify age varchar(11)--修改约束
--alter table 表名 change 新名字 旧名字 列属性[]
alter table teacher1 change age age1 int(3)--字段重命名

--删除表字段 alter table 表名 drop 字段名
alter table teacher1 drop age1

--删除表
drop table if exsits teacher1

image
image

posted @ 2023-07-26 10:23  huihui不会写代码  阅读(21)  评论(0)    收藏  举报