mariadb(MySql)匿名添加root权限帐户或者重置root帐户密码

运行环境

  • 操做系统:Centos7
  • mariadb 版本:mysql Ver 15.1 Distrib 5.5.41-MariaDB, for Linux (x86_64) using readline 5.1
  • 参考文献:
    参考博客

操做步骤

0.中止mariadbhtml

systemctl stop mariadb.service #关闭mariadb
ps -ef | grep mariadb #查询进程PID

1.经过如下命令匿名登陆mariadbmysql

mysqld_safe --skip-grant-tables &

注意在这以后输入以下代码开启mysqlsql

mysql #后面不加任何用户名,直接登陆

2.匿名登陆后输入以下命令数据库

use mysql; #使用mysql系统数据库
        
insert into user(Host,User,Password) values('localhost','root',PASSWORD('123456')); 
#插入一个名为test的新用账号为test,密码为123,可根据自身须要自行修改
        
update user set Password=PASSWORD('123') where User='root' #将root密码改成123,做为重置root密码之用
        
select * from user; #查看用户是否加入

3.赋予建立用户全部权限bash

注意:此时若是如今使用赋权限语句ide

grant all privileges on *.* to test@localhost identified by '123456';

会报执行错误,由于用户以前经过命令 --skip-grant-tables & 来登录数据库的,所以不能使用grant相关命令来进行权限赋值。操作系统

此时应先输入命令code

flush privileges;

以后再输入命令htm

grant all privileges on *.* to root@localhost identified by '123456';

便可执行成功,最后输入如下命令来查看用户权限是否变动blog

select * from user; #查看用户权限是否变动
相关文章
相关标签/搜索