创建用户:

mysql> create user 'cai'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec) mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| cai | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| wordpress | localhost |
+---------------+-----------+
5 rows in set (0.00 sec)
[root@cairui ~]# mysql -ucai -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 275
Server version: 5.7.21-debug Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

授权:

命令:GRANT privileges ON databasename.tablename TO 'username'@'host'

mysql> grant select,delete,create,insert,update on aa.* to 'cai'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for cai@localhost;
+-----------------------------------------------------------------------------+
| Grants for cai@localhost |
+-----------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'cai'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `aa`.* TO 'cai'@'localhost' |
+-----------------------------------------------------------------------------+
2 rows in set (0.00 sec)

撤销用户权限:

命令:REVOKE privilege ON databasename.tablename FROM 'username'@'host';

mysql> show grants for cai@localhost;
+-----------------------------------------------------------------------------+
| Grants for cai@localhost |
+-----------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'cai'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `aa`.* TO 'cai'@'localhost' |
+-----------------------------------------------------------------------------+
2 rows in set (0.00 sec) mysql> revoke insert on aa.* from 'cai'@'localhost';
Query OK, 0 rows affected (0.00 sec) mysql> show grants for cai@localhost;
+---------------------------------------------------------------------+
| Grants for cai@localhost |
+---------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'cai'@'localhost' |
| GRANT SELECT, UPDATE, DELETE, CREATE ON `aa`.* TO 'cai'@'localhost' |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec) 

设置与修改用户密码:

  方法一:

[root@cairui ~]# mysqladmin -ucai -p'123456' password '123'
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@cairui ~]# mysql -ucai -p123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 279
Server version: 5.7.21-debug Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  方法二:

mysql> update mysql.user set authentication_string=password('cai') where user='cai' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
[root@cairui ~]# mysql -ucai -pcai;
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 284
Server version: 5.7.21-debug Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

   方法三:

mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@cairui ~]# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 288
Server version: 5.7.21-debug Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>

忘记密码情况下的登录:

[root@cairui mysql]# bin/mysqld_safe --skip-grant-tables &
#登录时不需要密码,进入可修改密码

删除用户:

mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| cai | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| wordpress | localhost |
+---------------+-----------+
5 rows in set (0.00 sec) mysql> drop user 'cai'@'localhost';
Query OK, 0 rows affected (0.00 sec) mysql> select user,host from mysql.user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| wordpress | localhost |
+---------------+-----------+
4 rows in set (0.00 sec)

Mysql的用户基本操作的更多相关文章

  1. Mysql创建用户并授权

    运行命令行 mysql -uroot -p 登录mysql use mysql; 创建用户:create user 'test123'@'localhost' identified by '12345 ...

  2. mysql数据库的基本操作

    mysql数据库的基本操作dos命令启动mysql服务:net start mysql启动数据库: mysql -uroot -p查看所有的数据库:show databases:新建数据库:creat ...

  3. mysql 操作用户权限

    使用可以对mysql数据库用户表有操作权限的用户名登陆mysqlinsert into user(Host,User,Password) values('%','name','password');如 ...

  4. MySQL的用户和权限介绍

    一.关于MySQL权限的几点常识: 1.MySQL的权限系统主要用来验证用户的操作权限. 2.在MySQL内部,权限信息存放在MySQL数据库的granttable里.当mysql启动后,grantt ...

  5. Mysql新增用户,权限管理

    MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. grant selec ...

  6. 详解MySQL的用户密码过期功能

    这篇文章主要为大家详细介绍了MySQL的用户密码过期功能的相关资料,需要的朋友可以参考下   Payment Card Industry,即支付卡行业,PCI行业表示借记卡.信用卡.预付卡.电子钱包. ...

  7. mysql创建用户

    mysql创建用户 创建用于localhost连接的用户并指定密码 mysql> create user 'pcom'@'localhost' identified by 'aaa7B2249' ...

  8. ubuntu下mysql添加用户的问题

    在ubuntu下使用命令: $:sudo apt-get install mysql-server 命令安装的Mysql 版本为:Server version: 5.7.13-0ubuntu0.16. ...

  9. 转: MySQL 赋予用户权限(grant %-远程和localhost-本地区别)

    相关参考资料: MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删除 数据库中所有表数据的权利. gr ...

随机推荐

  1. redis基本操作和在springboot中的使用

    本文介绍redis的使用 redis启动步骤 说明 redis自增自减相关操作 redis string set操作 get操作 其他操作 redis hash set操作 get操作 其他操作 re ...

  2. python学习——练习题(4)

    """ 题目:输入某年某月某日,判断这一天是这一年的第几天? """ import datetime import time from fu ...

  3. C#向pdf 添加水印

    调用直接这样用: //PDFHelper.AddImageWatermarkPDF(path, "D://my.pdf", Server.MapPath("/HtmlTo ...

  4. Ant 执行 exec cmd.exe 时路径包含空格的问题

    需求描述 通过Ant脚本调用bat脚本 问题描述 bat脚本所在目录名称包含空格(space),cmd.exe调用时候报错The system cannot find the path specifi ...

  5. Java中迭代Map的方法

    Map<String, String> mapServlet = new HashMap<String, String>(); System.out.println(" ...

  6. django: django rest framework 分页

    django: django rest framework 分页 2018年06月22日 13:41:43 linux_player_c 阅读数:665更多 所属专栏: django 实战   版权声 ...

  7. 使用EasyUI,关于日期格式的文本框按照正常方式获取不到值的问题

    这是个小菜在实际工作中遇到的问题,相信很多EasyUI新手很可能也遇到这样的问题,因此小菜觉得有必要拿出来分享一下. 这个问题要从EasyUI的datebox组件说起,小菜用这个组件的时候,发现用$( ...

  8. 认识Filter

    1). Filter 是什么 ? ①. JavaWEB 的一个重要组件, 可以对发送到 Servlet 的请求进行拦截, 并对响应也进行拦截. ②. Filter 是实现了 Filter 接口的 Ja ...

  9. python核心编程第4章课后题答案(第二版75页)

    4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...

  10. HDU 6047 Maximum Sequence (贪心+单调队列)

    题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由 ...