一、操作步骤

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. C++2.0新特性(三)——<=default,=delete、alias(别名)、noexcept、override、final、以及和const对比>

    一.=default,=delete 1.首先我们要回顾一下类默认函数的概念: C++中,当我们设计与编写一个类时,若不显著申明,则类会默认为我们提供如下几个函数: (1)构造函数(A()).(2)析 ...

  2. ping-pong buffer

    1 什么是pingpong? pingpong是一种数据缓存的手段,通过pingpong操作可以提高数据传输的效率. 2 什么时候需要pingpong? 在两个模块间交换数据时,上一级处理的结果不能马 ...

  3. jvm jdk jre 关系

    JDK : Java Development ToolKit(Java开发工具包).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工 ...

  4. git clean解决 GIT error: The following untracked working tree files would be overwritten

    git clean用法:https://www.cnblogs.com/lsgxeva/p/8540476.html :

  5. (火狐浏览器)前端以FormData类形成表单(含文件),通过ajax提交,PHP后端iconv()报“文件名含有非法字符”且POST中的‘Ttitle’丢失

    [错误信息]后端获取的POST中丢失了Ttile,文件名乱码导致iconv()出错,利用mb_detect_encoding()函数检测输入的字符串,返回false; mb_detect_encodi ...

  6. Delphi支付宝支付【支持SHA1WithRSA(RSA)和SHA256WithRSA(RSA2)签名与验签】

    作者QQ:(648437169) 点击下载➨Delphi支付宝支付             支付宝支付api文档 [Delphi支付宝支付]支持条码支付.扫码支付.交易查询.交易退款.退款查询.交易撤 ...

  7. go中&^(按位置零)符号的含义

    go中有一个 &^ 的运算符,它代表的是按位置零 首先来看下几个输出例子: i := 1 &^ 0 fmt.Println("1 &^ 0 -- ",i) ...

  8. 谷歌浏览器安装Elasticsearch-head 插件

    下载该插件,地址:https://github.com/liufengji/es-head/blob/master/elasticsearch-head.crx 下载后的文件名是:elasticsea ...

  9. centos6 配置静态IP地址

    CentOS网卡配置源文件如下:DEVICE=eth0HWADDR=00:0C:29:A8:67:46TYPE=EthernetUUID=4103d7a8-d073-4e93-ac68-e6f8496 ...

  10. linux部署安装SRS流媒体服务器教程

    这段时间一直在搞RTMP流媒体直播项目,期间踩过很多坑,刚开始是用的nginx-rtmp作为流媒体转发服务器,但是效果并不尽人意,推拉流不稳定,特别是拉流,速度特别慢,平均要十多秒才能拉到流,并且交互 ...