创建:

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

最新文章

  1. Notes:SVG(3)---滤镜和渐变
  2. 《Entity Framework 6 Recipes》中文翻译系列 (31) ------ 第六章 继承与建模高级应用之自引用关联
  3. java分享第十三天(fastjson生成和解析json数据,序列化和反序列化数据)
  4. STL之容器适配器priority_queue
  5. await之后的线程问题
  6. 数据库执行监控,除了Profiler的方案
  7. 2013 Multi-University Training Contest 4
  8. cocos2d-x中Node中重要的属性
  9. WCF入门(三)---WCF与Web服务/Web Service
  10. python学习笔记12(函数三): 参数类型、递归、lambda函数
  11. js基础第二天
  12. 依赖注入及AOP简述(二)——工厂和ServiceLocator .
  13. Windows文件操作的API函数[转载]
  14. Linux下/proc目录简介(转)
  15. IDEA2017使用Maven方式配置Mybatis-Generator
  16. Win10下安装RabbitMQ以及基本知识学习
  17. Locally Weighted Linear Regression 局部加权线性回归-R实现
  18. go语言实现https的简单get和post请求
  19. python +ps 三方面库整理
  20. selenium--控制浏览器和简单元素操作

热门文章

  1. 使用vs2010创建MFC C++ Ribbon程序
  2. C语言程序设计第七次作业
  3. C++虚方法(虚函数)随笔
  4. Java 图片压缩
  5. 软件测试第三次作业——7.使用下面方法printPrimes()完成后面的问题(a)~(f)
  6. codeforces 341d (树状数组)
  7. nopi excel 导入
  8. C#多线程线程
  9. oracle行转列,decode 等用法
  10. python3 filter用法(举例求0~n之间的素数)