[转帖] mysql 用户 权限 密码等操作记录
前言
From :https://blog.csdn.net/yu12377/article/details/78214336
mysql5.7版本中用户管理与以前版本略有不同,在此记录,以备忘
登陆
[root@ver ~]# mysql -h -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id Server version: Source distribution Copyright (c) , , 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>
参数说明:
-h: 指定数据库IP地址;
-P: 指定端口,默认的3306时,可以忽略;
-u: 指定登陆用户名;
-p: 指定登陆密码(小写,注意与指定端口的大写P区分);
指定操作数据库
mysql> show databases; # 查看所有数据库 +--------------------+ | Database | +--------------------+ | information_schema | | fhgk | | mysql | | performance_schema | | sys | +--------------------+ rows in set (0.01 sec) mysql> use mysql # 指定当前操作的数据库 Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql>
创建用户
# 创建用户 mysql> CREATE USER 'username'@'host' IDENTIFIED BY 'password'; # 删除用户 mysql> DROP USER 'username'@'host';
host参数说明:
% 匹配所有主机
localhost localhost不会被解析成IP地址,直接通过UNIXsocket连接
127.0.0.1 会通过TCP/IP协议连接,并且只能在本机访问;
::1 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1
此时还没有授权,只能登陆,无法做其余操作
用户授权
# 用户授权 mysql> grant privileges ON databasename.* TO 'username'@'host'; # 创建用户的同时授权 mysql> grant all privileges on databasename.* to '; # 授权刷新 mysql> flush privileges; # 查看用户拥有权限 mysql> show grants for dev@'%'; +----------------------------------------------------------------------+ | Grants for dev@% | +----------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'dev'@'%' | | GRANT SELECT, INSERT, UPDATE, DELETE, ALTER ON `fhgk`.* TO 'dev'@'%' | +----------------------------------------------------------------------+ rows in set (0.00 sec) # 撤消用户授权,撤消要求各参数与授权时使用的一致,可以相查看授权再撤消 mysql> revoke privileges ON databasename.* FROM 'username'@'host';
privileges参数说明: all privileges: 所有权限; select: 查询; insert: 新增记录; update: 更新记录; delete: 删除记录; create: 创建表; drop: 删除表; alter: 修改表结构; index: 索引相关权限; execute: 执行存储过程与call函数 references: 外键相关; create temporary tables:创建临时表; lock tables 锁表; create view 创建视图; show view 查看视图结构; create routine alter routine: event: trigger: 触发器相关;
databasename.*参数说明:
此处可以针对具体的某个库,如:【zjims.*】;
也可以针对具体库中的某个对象,如:【zjims.t_user】;
还可以针对所有数据库,如:【.】;
修改密码
# 修改自己的密码
mysql> set password=password('newpassword');
# 修改别人密码——方法1
mysql> set password for 'username'@'host' = password('newpassword');
# 修改别人密码——方法2: 适用mysql5.7以前的版本,.7以后的版本中mysql.user表没有了password字段
mysql> update mysq.user set password=password('newpassword') where user='user' and host='host';
# 修改别人密码——方法3:适用mysql5.
mysql> update mysql.user set authentication_string=password('newpassword') where user='root';
# 修改别人密码——方法4
mysql> alter user 'test'@'%' identified by 'newpassword';
重置管理员密码
- 停止mysql服务:service mysqld stop 或 ./mysql.server stop;
- 以不检查权限方式启动mysql:./mysqld –skip-grant-tables –user=mysql &;
- 以空密码方式登陆:mysql -h 127.0.0.1 -P 3306 -u root;
- mysql5.7以前版本——修改root密码:update mysq.user set password=password(‘newpassword’) where user=’root’;
- mysql5.7以后版本——修改root密码:update mysql.user set authentication_string=password(‘newpassword’) where user=’root’;(只能用此种update方法修改)
- 刷新权限:flush privileges;
- 关闭mysql:shutdown;
- 以正常方式启动mysql: service mysqld start 或 ./mysql.server start;
参考资料
- http://www.cnblogs.com/fslnet/p/3143344.html
- http://www.cnblogs.com/xujishou/p/6306765.html
- http://www.cnblogs.com/4php/p/4113593.html
[转帖] mysql 用户 权限 密码等操作记录的更多相关文章
- mysql用户权限操作
mysql用户权限操作1.创建用户mysql -urootcreate database zabbix default charset utf8;grant all on zabbix.* to za ...
- (转)mysql账号权限密码设置方法
原文:http://www.greensoftcode.net/techntxt/2013410134247568042483 mysql账号权限密码设置方法 我的mysql安装在c:\mysql 一 ...
- MySQL——用户与密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码.通过下面的方式找到root默认密码,然后登录mysql进行修改: grep 'temporary p ...
- mysql用户权限
mysql> show grants for root@'localhost';+-------------------------------------------------------- ...
- MySQL 用户登录密码和远程登录权限问题
1.mysql数据库,忘记root用户登录密码. 解决如下: a.重置密码 #/etc/init.d/mysqld stop #mysqld_safe --user=mysql --skip-gran ...
- 在Windows下忘记MySQL最高用户权限密码的解决方案
1.打开MySQL配置文件 my.ini中,添加上skip-grant-tables,可以添加到文件的末尾或者是这添加到[mysqld]的下面(直接添加在my.ini文件最后亲测可以,但是在[mysq ...
- mysql用户权限设置
1.创建新用户 通过root用户登录之后创建 >> grant all privileges on *.* to testuser@localhost identified by &quo ...
- mysql 用户权限设置【转】
在Linux下phpStudy集成开发环境中,要先进入mysql下bin目录,执行mysql ./mysql -u root -p 1.创建新用户 通过root用户登录之后创建 >> gr ...
- 转 MySQL 用户权限详细汇总
http://blog.csdn.net/mchdba/article/details/45934981 1,MySQL权限体系 MySQL 的权限体系大致分为5个层级: 全局层级: 全局权限适用于一 ...
随机推荐
- django表格form无法保存评论排查步骤
初学django项目,在网上找了个blog教程,还是很不错的,这里感谢一下博主https://www.zmrenwu.com/post/2/ 这个项目适合django初学者,是一个完整的blog项目 ...
- JAVA框架 Spring 约束配置本地资源
一:粘贴约束url:http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.or ...
- A. Nephren gives a riddle
What are you doing at the end of the world? Are you busy? Will you save us? Nephren is playing a gam ...
- ceph 部署步骤和原理理解
1.ceph的官方源在国外,网速比较慢,此处添加ceph源为阿里源(每个节点上均执行) vim /etc/yum.repos.d/ceph.repo [Ceph] name=Ceph packages ...
- Hadoop体系结构杂谈
hadoop体系结构杂谈 今天跟一个朋友在讨论hadoop体系架构,从当下流行的Hadoop+HDFS+MapReduce+Hbase+Pig+Hive+Spark+Storm开始一直讲到HDFS的底 ...
- 【stylus】stylus在webstrom中的识别
<style lang="stylus" rel="stylesheet/stylus"> @import './common/stylus/mix ...
- Python3入门(五)——高级特性
一.切片 对于取指定索引的值,python提供了切片来简化傻傻的循环 list2 = ["apple", "water", "banana" ...
- 20155229《网络对抗技术》Exp2:后门原理与实践
实验预习 后门: 指绕过安全控制而获取对程序或系统访问权的方法.最主要目的就是方便以后再次秘密进入或者控制系统. 木马与后门的区别: 木马:通过欺骗用户的方法(包含捆绑,利用网页等)让用户不知不觉的安 ...
- 20155321 《网络攻防》 Exp4 恶意代码分析
20155321 <网络攻防> Exp4 恶意代码分析 计划任务监控 在C盘根目录下建立一个netstatlog.bat文件(先把后缀设为txt,保存好内容后记得把后缀改为bat),内容如 ...
- Ubuntu16.04上用源代码安装ICE
ubuntu16.04上用源代码安装ICE