DBA-mysql-用户控制
创建:
CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'new_password
' PASSWORD EXPIRE;
授权:
Grant all on *.* to 'jeffrey'@'localhost';
创建并授权
Grant all privileges on *.* to root1@'%' identified by "root" with grant option;
创建用户:
CREATE USER 'jacky'@'localhost' identified BY 'mypass';
GRANT SELECT ,UPDATE ON *.* TO 'testUser'@'localhost' identified BY 'testpwd';
INSERT INTO mysql.user(host,user,password) VALUES ('localhost','customer1',password('customer1'))
*identified with只能在MYSQL5.5.7及以上版本使用,identified with和identified by是互斥的
*CREATE USER语句的操作会被记录到服务器日志文件或者操作历史文件中 cat ~/.mysql_history
*查出哈希值 SELECT password('mypass'); 再使用 CREATE user 'tom'@'localhost' identified BY password 'B292FED686394CC81F802198C941D43EF0E4FB62'; 再赋值
赋予权限
grant all privileges on *.* to root@'(localhost或192.168.1.1或%)' identified by "password" with grant option;
flush privileges;
show grants;
回收权限
revoke delete on *.* from 'root'@'localhost';
REVOKE INSERT ON *.* FROM 'grantUser'@'localhost';
INSERT, SELECT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGER
查看用户
select host,user,password from user; 重命名:rename user 'jack'@'%' to 'jim'@'%';
删除用户
drop user 'root'@'localhost'; 或 DELETE FROM mysql.user WHERE `Host`='localhost' and `User`='testUser'
修改密码
SET PASSWORD=PASSWORD("123456")
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
mysqladmin -uroot -p123456 password 1234abcd
update user set PASSWORD = PASSWORD('1234abcd') where user = 'root';
grant USAGE ON *testUser*TO 'localhost' identified BY '123456';
找回root密码
mysqld_safe --skip-grant-tables user=mysql
/etc/init.d/mysql start-mysqld --skip-grant-tables
基础查看操作
show databases; show tables; show columns from 表 ; desc 表; show create table 表
删除整个表数据
truncate table 表名 或delete from 表名
*效率上truncate比delete快,但truncate删除后不记录mysql日志,不可以恢复数据。
删除某条表数据
delete from ofUser where username='admin';
插入某条表数据
insert into ofUser (username,plainPassword,creationDate,modificationDate) values('admin','admin','1464292787204','1464292787204');
================================================================
命令行下具体用法如下:
mysqldump -u用戶名 -p密码 -d 数据库名 表名 > 脚本名;
导出整个数据库结构和数据
mysqldump -h localhost -uroot -p123456 database > dump.sql
导出单个数据表结构和数据
mysqldump -h localhost -uroot -p123456 database table > dump.sql
导出整个数据库结构(不包含数据)
mysqldump -h localhost -uroot -p123456 -d database > dump.sql
导出单个数据表结构(不包含数据)
mysqldump -h localhost -uroot -p123456 -d database table > dump.sql
最新文章
- Notes:SVG(3)---滤镜和渐变
- 《Entity Framework 6 Recipes》中文翻译系列 (31) ------ 第六章 继承与建模高级应用之自引用关联
- java分享第十三天(fastjson生成和解析json数据,序列化和反序列化数据)
- STL之容器适配器priority_queue
- await之后的线程问题
- 数据库执行监控,除了Profiler的方案
- 2013 Multi-University Training Contest 4
- cocos2d-x中Node中重要的属性
- WCF入门(三)---WCF与Web服务/Web Service
- python学习笔记12(函数三): 参数类型、递归、lambda函数
- js基础第二天
- 依赖注入及AOP简述(二)——工厂和ServiceLocator .
- Windows文件操作的API函数[转载]
- Linux下/proc目录简介(转)
- IDEA2017使用Maven方式配置Mybatis-Generator
- Win10下安装RabbitMQ以及基本知识学习
- Locally Weighted Linear Regression 局部加权线性回归-R实现
- go语言实现https的简单get和post请求
- python +ps 三方面库整理
- selenium--控制浏览器和简单元素操作