MySQL用户和权限及破解root口令的方法示例


当前第2页 返回上一页

创建一个wordpress的用户,并授权。

MariaDB [(none)]> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.02 sec)

MariaDB [(none)]> GRANT ALL ON wordpress.* TO wpuser@'192.168.73.%' identified by 'mylinuxops';
Query OK, 0 rows affected (0.00 sec)

2.查看用户的权限

MariaDB [(none)]> show grants for wpuser@'192.168.73.%';
+------------------------------------------------------------------------------------------------------------------+
| Grants for wpuser@192.168.73.%                     |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wpuser'@'192.168.73.%' IDENTIFIED BY PASSWORD '*EC0DBFB480593BB6ED2EC028A4231A72D8137406' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wpuser'@'192.168.73.%'             |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

3.授权的其他选项

MAX_QUESRIES_PER_HOUR count #每小时最多查多少次
MAX_UPDATES_PER_HOUR count #每小时最多改多少次
MAX_CONNECTIONS_PER_HOUR count #每小时最多连多少次
MAX_USER_CONNECTIONS count #用户的最大数连接数

取消权限

REVOKE
 priv_type [(column_list)]
  [, priv_type [(column_list)]] ...
 ON [object_type] priv_level
 FROM user [, user] ...

示例:

MariaDB [(none)]> revoke delete on wordpress.* from wpuser@'192.168.73.%';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for wpuser@'192.168.73.%';
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for wpuser@192.168.73.%                                                   |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wpuser'@'192.168.73.%' IDENTIFIED BY PASSWORD '*EC0DBFB480593BB6ED2EC028A4231A72D8137406'                              |
| GRANT SELECT, INSERT, UPDATE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER ON `wordpress`.* TO 'wpuser'@'192.168.73.%' |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
# 此时wpuser@'192.168.73.%'已经没有了delete权限

MySQL的root口令破解

工作中有时候可能会遇到root口令丢失的情况,此时可以通过以下方法进行找回root口令

以下为示范如何破解root口令

一、密码未知无法登陆MySQL

[root@localhost ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

二、破解

1.修改配置文件/etc/my.cnf,添加两行参数

skip_grant_tables:跳过授权表信息,此项生效后再次使用MySQL就无需使用密码了,但是远程的其他用户也可以不使用密码登陆,有一定的风险性

skip_networking:关闭网路功能,由于光启用skip_grant_tables选项,其他用户也可以无需密码登陆MySQL非常危险,所以需要关闭网路功能只允许本地的用户进行操作。

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
skip_networking=on   #不启用网络功能
skip_grant_tables=on   #跳过授权表

[root@localhost ~]# service mysqld restart       #对位置文件修改后需要重新启动服务
Restarting mysqld (via systemctl):       [ OK ]

2.登陆MySQL,进行密码修改

[root@localhost ~]# mysql           #此时已经无需输入密码就能登陆
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.2.23-MariaDB-log Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> UPDATE mysql.user SET password=PASSWORD('123456') where user='root';  #对root的口令进行修改
Query OK, 4 rows affected (0.01 sec)
Rows matched: 4 Changed: 4 Warnings: 0

3.口令修改完毕后,需要将配置文件恢复

将刚才启用的两个选项进行注销或者删除,然后重启服务

[root@localhost ~]# vim /etc/my.cnf
[mysqld]
#skip_networking=on   
#skip_grant_tables=on   

[root@localhost ~]# service mysqld restart
Restarting mysqld (via systemctl):       [ OK ]

4.使用新口令登陆MySQL

[root@localhost ~]# mysql -uroot -p123456 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.2.23-MariaDB-log Source distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

更多相关Mysql内容来自木庄网络博客


标签:Mysql

返回前面的内容

相关阅读 >>

mysql数据库之数据表操作

mysql怎么求最大值、最小值和平均值?

mysql如何配置及mysql服务无法启动

navicat如何操作mysql数据库?

怎么查看mysql当前连接数

如何查看mysql的默认存储引擎

centos7 64位 mysql 5.6.40源码安装过程

分析优化mysql 多表联合查询效率

redhat6.5怎么安装mysql

必学!mysql数据库查询之limit的使用方法

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...