[SQL] 简单新建(create)删除(dropdelete)权限(grant/revoke)修改(setupdate)

一、前言

说起来 数据库(Structured Query Language),本站写过很多类似文章。

如:

甚至:我还做了一个项目:SQL 中用户建立与权限授予


然而,今天弄信息安全的时候一个 MYSQL 的问题瞬间把握弄懵了。我就在想如果碰到 利用社区开源代码进行二次开发的商业软件,那应该怎么办呢?有哪些具体的操作。

本文针对上述内容做了思考,总结以下内容。

二、思考

从商业软件的角度出发,一定是希望以最小的代价获取最大的回报。

  • 利用 mairadb 开源代码完成核心部分,开发一个 GUI 外壳方便用户使用与隐藏伪装。
  • 利用 phpmyadmin 现成网页端解决方案。
  • MySQL 生态非常好,兼容性非常高。

三、检查

1、确定 my.ini 位置

首先找到 control panel -> 看到MYSQL服务 -> 右键属性确定my.ini位置

2、尝试登陆

发现无法登陆。(using password: YES)

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password)
这种类型的提示是帐号密码不对或者帐号不存在的现象。

四、破解

1、添加 skip-grant-tables

在文件“底部”添加 skip-grant-tables 保存退出 -> 重启服务

BTW:网上说给 mysqld.exe 加 --skip-grant-tables 进行权限的略过,我并没有成功。

2、破解登陆

2-1、查询情况

cmd.exe -> mysql -h localhost -u root -p > 直接登陆

MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host      |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1       |
| root | localhost |
+------+-----------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 

2-2、新建用户

MariaDB [(none)]> create user 'root'@'%' identified by "example";
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> 

2-3、删除用户

MariaDB [(none)]> drop user 'root'@'%';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 

这样就没办法远程登陆(“%”)了

2-4、权限相关

MariaDB [(none)]> grant all privileges on *.* to 'rabbit'@'%' IDENTIFIED BY 'rabbit';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> revoke all privileges on *.* from 'root'@'%' ;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 
  • ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
  • CREATE- allows them to create new tables or databases
  • DROP- allows them to them to delete tables or databases
  • DELETE- allows them to delete rows from tables
  • INSERT- allows them to insert rows into tables
  • SELECT- allows them to use the Select command to read through databases
  • UPDATE- allow them to update table rows
  • GRANT OPTION- allows them to grant or remove other users' privileges

2-5、修改密码

MariaDB [(none)]> SET PASSWORD FOR 'rabbit'@'%' = PASSWORD('test');
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> UPDATE mysql.user SET password=PASSWORD('other-way') where user = 'rabbit' and host = '%';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

希望大家都能熟练掌握。

原文地址:https://www.cnblogs.com/itxdm/p/Simple_create_delete_delete__delete_permissions_grant__revoke_modify_set__update.html