创建用户:

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. c语言相关知识点解析

    程序基本结构 常量变量标识符 数据类型 整型类型 浮点类型(实型) 基本类型转换 字符串 函数类型 枚举类型 enum 数组类型 结构体类型 共用体类型 字符串函数 运算符 流程控制语句 输入输出语句 ...

  2. 阿里云ECS centos7 支持IPv6

    1.编辑 /etc/sysctl.conf 文件,将其中三条禁用IPv6的设置更改为: net.ipv6.conf.all.disable_ipv6 = 0 net.ipv6.conf.default ...

  3. AE插件之SKYBOX CONVERTER

    AE插件之SKYBOX CONVERTER AE插件SKYBOX CONVERTER的主要作用是开发全景视频或者制作全景图片时,对添加的字幕.图片进行扭曲. 下载目录:http://www.gfxca ...

  4. 「小程序JAVA实战」微信小程序工程结构了解(五)

    转自:https://idig8.com/2018/08/09/xiaochengxu-chuji-05/ 微信小程序工程结构 audio,button,canvas,checkbox 都是由4个文件 ...

  5. AMF解析之数据类型定义 (转)

    目录(?)[-] OpenRTMFPCumulus Primer15AMF解析之数据类型定义 数据类型 undefined Type null Type false type true type in ...

  6. android 4.0.4系统下实现apk的静默安装和启动

    转 android 4.0.4系统下实现apk的静默安装和启动 分类: Android 2013-02-14 14:13 1762人阅读 评论(10) 收藏 举报 最近在android 4.0.4系统 ...

  7. 面试题:filter过滤器 listener 监听器 案例有点用

    1.Filter工作原理(执行流程) 当客户端发出Web资源的请求时,Web服务器根据应用程序配置文件设置的过滤规则进行检查,若客户请求满足过滤规则,则对客户请求/响应进行拦截,对请求头和请求数据进行 ...

  8. PHP学习笔记之continue与break

    百度中有人这样解释:break是结束整个循环体,continue是结束单个循环体.昨天看燕十八老师PHP视频,讲到break,continue时,举了一个例子,理解更容易.天龙八部中,西夏国公主选婿, ...

  9. EF 常见语句以及sql语句简单 后续继续添加

    1.注意级联删除的时候数据库的外键要设置为开启级联删除,(数据库里sqlserver的外键修改的时候,可以看到级联删除和级联更新) using System;using System.Collecti ...

  10. 用JQuery获取输入框中的光标位置

    (function ($, undefined) { $.fn.getCursorPosition = function () { var el = $(this).get(0); var pos = ...