创建用户:

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. classmethod VS staticmethod

  2. Stall Reservations(贪心+优先队列)

    Description Oh those picky N (1 <= N <= 50,000) cows! They are so picky that each one will onl ...

  3. spark编译安装 spark 2.1.0 hadoop2.6.0-cdh5.7.0

    1.准备: centos 6.5 jdk 1.7 Java SE安装包下载地址:http://www.oracle.com/technetwork/java/javase/downloads/java ...

  4. spring mvc default-servlet mvc:resources mvc:default-servlet-handler区别

    mvc:default-servlet-handler其实就是default-servlet 交由web容器自己处理 mvc:resources spring来处理 没有被映射的url web容器来处 ...

  5. uboot启动正常,加载内核kernel启…

    先说现象吧:uboot能够正常启动,不过在kernel启动时却出现起不了的现象,停在这里 Uncompressing Linux.................................... ...

  6. linux启动lcd屏如水纹状波动,不稳…

    开发环境:arm-s3c2416.ubuntu. 内核:linux2.6.26 病症:内核启动时,arm的lcd屏幕出现抖动现象,如水纹状波动,屏幕最下面还有白线闪动,甚至lcd有很多亮点等现象 分析 ...

  7. @RequestParam注解的作用

    1.这个注解是干什么的??? 提取和解析请求参数的能力. 2.实例解析: a.代码 @Controller @RequestMapping("/pets") @SessionAtt ...

  8. Spring总结六:AOP(面向切面编程)

    概述: AOP(Aspect-Oriented Programming,面向切面的编程),它是可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术.它是一种新的 ...

  9. CMD指令大全

    命令提示符(CMD)是在OS / 2 , Windows CE与Windows NT平台为基础的操作系统(包括Windows 2000和XP中, Vista中,和Server 2003 )下的“MS- ...

  10. QT编译时出现警告 Warning: Class Node implements the interface QGraphicsItem but does not list it in Q_INTERFACES. qobject_cast to QGraphicsItem will not work!

    1.一定要将public QObject放在public QGraphicsItem的前面,并且在该类的定义中添加Q_OBJECT宏. class XXGraphicsItem : public QO ...