参考博客:https://blog.goodjack.tw/2018/02/mariadb-root.html
和以往修改方式不同
修改办法:
#开启skip-networking和skip-grant-tables
vi /etc/my.cnf
skip-networking
skip-grant-tables
#重启服务
systemctl restart mysql
mysql -uroot -p
use mysql;
update user set authentication_string=PASSWORD("密码") where user='root';
update user set plugin="mysql_native_password";
flush privileges;
quit
#注释掉skip-networking和skip-grant-tables
vi /etc/my.cnf
#skip-networking
#skip-grant-tables
#重启服务
systemctl restart mysql
密码测试显示成功。
其中的坑:
换了个机器修改密码失败,查看user表,原来没有root账户,于是进入安全模式创建root用户,
#查看用户,没有root
MariaDB [mysql]> SELECT user, plugin FROM mysql.user;
#创建root
MariaDB [mysql]> insert into user set user=‘root’,ssl_cipher=’’,x509_issuer=’’,x509_subject=’’,authentication_string=’’;
#修改root密码
MariaDB [mysql]> UPDATE mysql.user SET password=PASSWORD(“root@1234”) WHERE user=“root”;
MariaDB [mysql]> FLUSH PRIVILEGES;
root是能连接,但是查看只有usage权限
MariaDB [mysql]> show grants for root@localhost;
授权办法:下面这个是授权过后,授权之前都是N,不是Y
MariaDB [mysql]> select * from user where user='root'\G;
*************************** 1. row ***************************
Host: localhost
User: root
Password: *A8304DF67962C37F28A4D0A686842E7F3449E8AC
Select_priv: Y
Insert_priv: Y
Update_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
Alter_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
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
Delete_history_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string:
password_expired: N
is_role: N
default_role:
max_statement_time: 0.000000
1 row in set (0.000 sec)
#授权所有权限,其实直接修改user表的字段
update user set
Select_priv = 'Y',
Insert_priv = 'Y',
Update_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',
Alter_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',
Event_priv = 'Y',
Trigger_priv = 'Y',
Create_tablespace_priv = 'Y',
Delete_history_priv = 'Y'
where user='root';
MariaDB [mysql]> flush privileges;
#到这里这里一连窜的坑就结束了
本文详细介绍了在MariaDB中修改root用户的密码及其权限的步骤,包括开启skip-networking和skip-grant-tables,更新密码,授权所有权限,并在完成后恢复配置。在过程中遇到的问题如root用户不存在时,如何创建并设置权限也一并给出解决方案。

被折叠的 条评论
为什么被折叠?



