数据库 - MySQL
一、数据库管理系统DBMS
软件
写程序:
a.数据库在本地
1.找到目录
2.添加数据
b.数据库在远程
1.socket连接上远程机器
2.socket发送{命令}
做些什么?
a.
A.程序
程序,socket客户端
B.数据
socket服务端
C.制作一套规则
add|阿萨德
delete|发发呆
……
D.socket客户端和服务端用户认证,授权,限制
-- 微软开发了sqlserver(收费)、Oracle(稳定收费)、sqlite、access...,MySQL
3、初始化
MySQL解压后的 bin 目录下有一大堆的可执行文件,执行如下命令初始化数据:
cd c:\mysql-5.7.16-winx64\bin mysqld --initialize-insecure
4.客户端连接
省事:
将mysql服务端制作成一个windows服务
net start mysql
net stop mysql
== 打开服务管理,直接点击
三、MySQL数据库
1、概念
数据库,文件夹
数据库表,文件
数据行,文件中的一行数据
启动服务器:
net start mysql mysql.server start /etc/init.d/mysql start
客户端连接:
d:\mysql-8.0.11-winx64\bin\mysql -u root -p
简单操作:
show databases; # 查看当前Mysql都有哪些数据,根目录都有哪些文件夹 create database 数据库名; # 创建文件夹 use 数据库名; # 使用选中数据库,进入目录 show tables; # 查看当前数据库下都有哪些表 create table 表名(nid int,name varchar(20)); # 创建数据库表 select * from 表名; # 查看表中的所有数据 insert into 表名(nid,name) values(1,'Jone'); # 插入数据
2.用户授权
用户管理特殊命令
创建用户 create user '用户名'@'IP地址' identified by '密码'; 删除用户 drop user '用户名'@'IP地址'; 修改用户 rename user '用户名'@'IP地址'; to '新用户名'@'IP地址';; 修改密码 set password for '用户名'@'IP地址' = Password('新密码')
授权管理
show grants for '用户'@'IP地址' -- 查看权限 grant 权限 on 数据库.表 to '用户'@'IP地址' -- 授权 revoke 权限 on 数据库.表 from '用户'@'IP地址' -- 取消权限
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
all privileges 除grant外的所有权限 select 仅查权限 select,insert 查和插入权限 ... usage 无访问权限 alter 使用alter table alter routine 使用alter procedure和drop procedure create 使用create table create routine 使用create procedure create temporary tables 使用create temporary tables create user 使用create user、drop user、rename user和revoke all privileges create view 使用create view delete 使用delete drop 使用drop table execute 使用call和存储过程 file 使用select into outfile 和 load data infile grant option 使用grant 和 revoke index 使用index insert 使用insert lock tables 使用lock table process 使用show full processlist select 使用select show databases 使用show databases show view 使用show view update 使用update reload 使用flush shutdown 使用mysqladmin shutdown(关闭MySQL) super 使用change master、kill、logs、purge、master和set global。还允许mysqladmin调试登陆 replication client 服务器位置的访问 replication slave 由复制从属使用
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
对于目标数据库以及内部其他: 数据库名.* 数据库中的所有 数据库名.表 指定数据库中的某张表 数据库名.存储过程 指定数据库中的存储过程 *.* 所有数据库
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
用户名@IP地址 用户只能在改IP下才能访问 用户名@192.168.1.% 用户只能在改IP段下才能访问(通配符%表示任意) 用户名@% 用户可以再任意IP下访问(默认IP地址为%)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
grant all privileges on db1.tb1 TO '用户名'@'IP' grant select on db1.* TO '用户名'@'IP' grant select,insert on *.* TO '用户名'@'IP' revoke select on db1.tb1 from '用户名'@'IP' 示例