一、操作步骤

1、停止mysql服务;在mysql安装目录下找到mysqld.cnf;在mysqld.cnf中找到以下片段[mysqld];另起一行加入代码:skip-grant-tables 并保存
比如我的在:/etc/mysql/mysql.conf.d目录下的mysqld.cnf文件,修改后为:

root@c1c5dbe81b37:/etc/mysql/mysql.conf.d# cat mysqld.cnf
# Copyright (c) , , Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., Franklin St, Fifth Floor, Boston, MA - USA #
# The MySQL Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld]
skip-grant-tables
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
#log-error = /var/log/mysql/error.log
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=

2、启动mysql服务,并登录

2.1 有用户的情况

  用用户名密码登录

2.2无用户的情况

直接可登录(无用户名和密码),然后加入root用户
INSERT INTO user (Host,User,Password) VALUES( 'localhost ', 'root ',password( '123456 '));

3、root用户设置权限
update user set Host='%',select_priv='y', insert_priv='y',update_priv='y',Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';commit;

4、把mysql.conf.d刚才加入的那行删除并重启服务

5、最后用root用户登录就可以了

二、其他有关命令

给用户授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '';
授权后刷新权限,使其生效
flush privileges;
查看mysql用户有哪些
select user,host from mysql.user;
更新用户密码
UPDATE mysql.user SET Password=PASSWORD('') where USER='root';
删除用户
Delete FROM mysql.user Where User='root' and Host='%';
插入用户
insert into mysql.user(Host,User,Password) values("%","root",password(""));

【Mysql】Mysql root用户误删了或只剩下没有任何操作权限的用户怎么办的更多相关文章

  1. mysql 忘记root密码,重置密码,及重置密码后权限问题不能登录的解决方案

    由于一段时间没有使用MySQL,忘记了root登录密码. 决定重置下密码,搜索帮助. 参考文档: http://blog.csdn.net/odailidong/article/details/507 ...

  2. mysql忘记root密码 + 授权登录

    一.拥有原来的myql的root的密码: 方法一:在mysql系统外,使用mysqladmin# mysqladmin -u root -p password "test123"E ...

  3. 第八章| 2. MySQL数据库|数据操作| 权限管理

    1.数据操作 SQL(结构化查询语言),可以操作关系型数据库 通过sql可以创建.修改账号并控制账号权限:  通过sql可以创建.修改数据库.表:  通过sql可以增删改查数据: 可以通过SQL语句中 ...

  4. Oracle操作管理之用户和角色

    1.用户管理 (1)建立用户(数据库验证) CREATE USER smith IDENTIFIED BY smith_pwd DEFAULTTABLESPACE users TEMPORARY TA ...

  5. linux下误删mysql的root用户,解决方法

    开始对liunx界面不熟悉,可能由于不小心,把root误删了,怎么办? 1. # killall mysqld    干掉所有mysql进程 2. # mysqld_safe --skip-grant ...

  6. 删除mysql中root用户恢复方法

    1.# service mysqld stop  #停止mysql数据库服务 2.# service mysqld start --skip-grant-tables #跳过授权表启动mysql数据库 ...

  7. mac 安装mysql + 修改root用户密码 + 及报Access denied for user 'root'@'localhost' (using password:YES)解决办法

    1.下载MySQL 到mysql的官网http://dev.mysql.com/downloads/mysql/然后在页面中会看到“MySQL Community Server”下方有一个“downl ...

  8. Mysql修改root用户密码 For Mac 报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

    环境 Mysql版本:5.7.12 操作系统:OSX 10.11 安装文件:.dmg文件 MySQL:mysql-5.7.12-osx10.11-x86_64.dmg(注意5.7跟之前的字段有些不同, ...

  9. MySQL重置root用户密码的方法

    本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云主机产品. 当管理员忘记MySQL密码怎么办?屡次输入密码,仍然提示错误,网站无法正常运行,数据库也无法管理,管理员束手无策. 网站程 ...

随机推荐

  1. CPU 的由来

    由 c# 的CEF 框架提供的 js 扩展,WebBrowser. JavascriptObjectRepository. 问:为什么要提供这一种方式. 提供了一种 能让js 与后端代码通讯的 方式. ...

  2. python虚拟环境切换无效问题

    使用pycharm创建新项目,使用虚拟环境,但是进入到项目的cainiao_guoguo_health\venv\Scripts目录启动虚拟环境后,安装第三方库,却还是安装到其他环境中去了, 检查ac ...

  3. ASP.NET Core Windows服务开发技术实战演练

    一.课程介绍 人生苦短,我用.NET Core!大家都知道如果想要程序一直运行在Windows服务器上,最好是把程序写成Windows服务程序:这样程序会随着系统的自动启动而启动,自动关闭而关闭,不需 ...

  4. .NET配置引用程序集的路径(分离exe和dll)

    按照引用程序集路径的不同,程序集DLL分为两类: 1)全局DLL(在GAC中注册,GAC——全局程序集缓存),有关GAC的详细资料可以参考一下链接: http://dddspace.com/2011/ ...

  5. Oracle GoldenGate 同步数据至Hbase

    该方法没试过,先记下再说 1.软件版本说明: Goldengate 12c 12.2.0.1 for Oracle(源端) Goldengate 12c 12.3.0.1 for Bigdata (目 ...

  6. Rancher 构建 CI/CD 自动化流程 - 动态配置 Jenkins-slave(一)

    一.说明 1)需求: Rancher 上部署 Jenkins-master,服务采用 Jenkins-slave 发布,发布完成后 Jenkins-slave 自动销毁. 2)环境: Rancher ...

  7. [转帖]Elasticsearch数据库

    Elasticsearch数据库 2018-05-06 11:30:48 七色米 阅读数 23634更多 分类专栏: 数据库   版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转 ...

  8. Disable foreign key checks during import

    The command SET FOREIGN_KEY_CHECKS=0; sets the value of a variable in a session scope. So it affects ...

  9. 计算几何 + 统计 --- Parallelogram Counting

    Parallelogram Counting Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5749   Accepted: ...

  10. Vue父组件如何调用子组件(弹出框)中的方法的问题

    如果子组件是一个弹出框,只有在触发某个点击事件时弹出框才能出现(也就是说在父组件中的子组件使用上用了v-if),那在父组件上如果不点击弹出框是不能获取到$ref的. 原因就是:引用指向的是子组件创建的 ...