SQL 分类
-
DDL: 操作数据库和表
- create database 创建
- create Table 创建
- Alter 更改
- drop 删除
-
DML: 增删改表中的数据
- insert into
- delete from
- update
-
DQL 查询表中的数据
- select
-
DCL :管理用户、授权
-
管理用户
-
添加用户
create user '用户名'@'主机名' identified by '密码'
例子:
CREATE USER 'apple'@'localhost' IDENTIFIED BY 'root'; CREATE USER 'yellow'@'%' IDENTIFIED BY 'root'; -- %代表任意host
-
删除用户
drop user '用户名'@'主机名';
-
修改用户密码
-
update user set password=password('新密码') where user='用户名';
-
set password for '用户名'@'主机名' =password('新密码');
-
-
查询用户
- 切换到mysql数据库
use mysql; - 查询user表
- 切换到mysql数据库
-
-
权限管理
-
查询权限
show grants for '用户名'@'主机名';
-
授予权限
-
撤销权限
-
-
% 通配符 代表任意host
忘记root密码怎么办呢???
- cmd————> net stop mysql 停止mysql服务
cmd 管理员身份 运行 - 使用无验证方式启动mysql服务:mysqld --skip-grant-tables
- 打开新的cmd窗口,直接输入mysql命令、敲回车。登陆成功
- use mysql
- 设置密码。
- 关闭窗口
- 使用任务管理器,手动结束mysqld.exe的进程
- 启动mysql服务 net start nysql
- 使用新密码登录