一、操作步骤

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. qbxt济南七日(游)学习

    七月的风八月的雨 卑微的我喜欢遥远的你 第七天: 更新 友谊的巨轮! 第六天: 我好饿 动态规划wcnm hhh, zkx坐在我旁边xswl 只要我和男生聊天 他就会把头探过来 用肯定的语气说: &q ...

  2. 安装Ruby 2.3.0

    安装最新的redis集群需要用到的rb脚本要ruby2.3.0版本,centos7默认的是2.0.0,很显然报错不行,所以安装呗,使用rvm安装,安装步骤如下: yum -y install curl ...

  3. haproxy 配置文件详解 之 listen

    配置示例: listen admin_stats bind mode http log 127.0.0.1 local0 err stats refresh 30s stats uri /haprox ...

  4. JS- 数组去重方法整理

    [indexOf] 简单而且可以加中文,但是兼容性不好,indexOF兼容到ie9 function uniq(arr) { var temp = []; for (let i = 0; i < ...

  5. SQL数据同步到ELK(一)- 日常开篇

    需求 在我们的实际业务中,业务数据大部分是通过传统DB做持久化,但有时会使用Solr/Elastic Search等做搜索.缓存等其他服务,那么如何将数据同步到这些异构的存储系统中呢? 这就是我最近在 ...

  6. 几句话总结一个算法之DQN

    DQN利用深度学习对Q-learning的一个扩展,回顾上篇文章,Q-learning的核心在于Q(s,a)的建模.如果状态s非常复杂,很难通过一张表来存储所有的状态. 深度学习正好可以自动提取s的特 ...

  7. Csp-s2019 划分

    本题主要靠结论 12pt 爆搜 时间复杂度\(O(n^n)\) 36pt \(f_{i,j}表示前i个数由状态j转移过来,a_i表示前缀和\) \(So,f_{i,j}=f_{j,k}+(a_i-a_ ...

  8. linux 远程文件复制和拉取

    基本命令格式 上传 scp -r  myfilder  tiantian@192.168.168.221:/home/tiantian/temp/ 复制本地文件到远程/home/tiantian/te ...

  9. 正则表达式之re模块

    re模块一.什么是正则表达式与re模块?1.1 字符组1.2 元字符1.2.1 单个使用1.2.2 组合使用二.为什么要使用正则三.如何使用3.1 re模块的三种比较重要的方法3.1.1 findal ...

  10. C语言指向函数的指针

    定义形式:类型 (*指针变量名)(参数列表); 例如:int (*p)(int i,int j); 在这里 int是函数的返回类型,*p是指向函数的指针,(int i,int j);是函数的参数 注意 ...