数据库管理

管理员密码设置:

1.知道原始密码
1.1需要登录到mysql中执行更新语句来修改
update user set password =password('123') where host='localhost' and user='root';

1.2mysqladmin小工具:
mysqladmin -u root -p123 password 321
-p原始密码

2.不知道原始密码
2.1删除权限相关文件
2.2跳过授权表手动启动mysql指定参数
mysqld --skip-grant-tables
update user set password =password('111') where host ='localhost' and user='root'
重启mysql

操作库:

切换数据库  use+库名
查看所有数据库 show +databases;
查看某个数据库的详细信息 show create databse +库名
创建新的数据库  create database +库名 charset utf8
删库         drop database 库名

操作表:

创表:  create table 表名 (列名  列数据类型) charset utf8
删表  drop table 表名
查看库下表  show tables;
查看表结构 desc 表名
插入值 insert into 表 values(...)
查看表内容  select * from 表
清空表的数据   truncate table  表

添加表的字段  alter table 表 add  列名  列的数据类型
删除字段     alter table 表  drop 列名
修改表的数据类型  alter table 表 modify 旧列  新列  新的数据类型
改表名       rename   table 旧表名  to  新表名

创建mysql账户:

创建账户 create user 用户名@localhost  identified by '123'
删除   drop user  用户名@localhost
在创建用户同时授权
grant all on *.* to 用户名@localhost   identified by '123'

收回权限  revoke all on *.* from 用户名@localhost;
刷新权限  flush privileges

将拥有权限的用户授予其他用户权限
grant all on *.* to root1@localhost identified by '123' with grant option

授予某个用户在任何机器上登录
grant all on *.* to 用户@"%" identified by '123'

posted @ 2019-07-20 18:22  enazede  阅读(208)  评论(0编辑  收藏  举报