NetAdminTools.com
 
SignalQ Sites:
NetAdminTools - Coprolite - NoNIC - SpotBridge - NAW
RoboCoop - AreWeDown - SolarPower - SysAdminTools
Xfig - Gold Loaf - GeekPapa - FixGMC - MCJ - FixRambler
Categories:
GNU/Linux | Homebrew designs | Perl | Administration | Backup/Recovery | Bugs/Fixes | Certification | Database | Email | File/Print | Hardware | Information Grab Bag | Interoperability | GNU/Linux ABCs | Monitoring | Name Resolution | Network Services | Networking | Remote Control | Security | Desktop | Web | BSD | Solaris | GIAGD | REALbasic

Last 30 Days | Last 60 Days | Last 90 Days | All Articles | RSS | Hail Support


Categories:
·GNU/Linux
·Homebrew designs
·Perl
·Administration
·Backup/Recovery
·Bugs/Fixes
·Certification
·Database
·Email
·File/Print
·Hardware
·Information Grab Bag
·Interoperability
·GNU/Linux ABCs
·Monitoring
·Name Resolution
·Network Services
·Networking
·Remote Control
·Security
·Desktop
·Web
·BSD
·Solaris
·GIAGD
·REALbasic
·All Categories


Removing Grants in MySQL
Topic: Database   Posted:2005-08-07
Printer Friendly: Print

spacerspacer
Grants are how MySQL handles user permissions to databases. See our article here for information on showing the grants. To delete grants, you can directly modify the mysql.user table:

mysql> select User,Host from mysql.user;
+------+---------------------------+
| User | Host                      |
+------+---------------------------+
| are  | 10.10.10.10               |
| are  | 10.10.10.11               |
| are  | 10.50.100.0/255.255.255.0 |
| are  | 10.50.100.112             |
| are  | 10.50.100.2               |
|      | localhost                 |
| are  | localhost                 |
| root | localhost                 |
|      | srv-1.networking7by24.com |
| root | srv-1.networking7by24.com |
+------+---------------------------+
10 rows in set (0.00 sec)
mysql> DELETE FROM mysql.user WHERE User='are' 
and host='10.50.100.0/255.255.255.0';
Query OK, 1 row affected (0.06 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select User,Host from mysql.user;
+------+---------------------------+
| User | Host                      |
+------+---------------------------+
| are  | 10.10.10.10               |
| are  | 10.10.10.11               |
| are  | 10.50.100.112             |
| are  | 10.50.100.2               |
|      | localhost                 |
| are  | localhost                 |
| root | localhost                 |
|      | srv-1.networking7by24.com |
| root | srv-1.networking7by24.com |
+------+---------------------------+
9 rows in set (0.00 sec)
mysql>

We can delete all access for the user are with this command:

mysql> DELETE FROM mysql.user WHERE User='are'; 
Query OK, 5 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select User,Host from mysql.user;
+------+---------------------------+
| User | Host                      |
+------+---------------------------+
|      | localhost                 |
| root | localhost                 |
|      | srv-1.networking7by24.com |
| root | srv-1.networking7by24.com |
+------+---------------------------+
4 rows in set (0.00 sec)
mysql>

Notice the ones with blank User names? These are anonymous accounts. We can delete all of these as well if we want with another DELETE command:

mysql> DELETE FROM mysql.user WHERE User='';
Query OK, 2 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> select User,Host from mysql.user;
+------+---------------------------+
| User | Host                      |
+------+---------------------------+
| root | localhost                 |
| root | srv-1.networking7by24.com |
+------+---------------------------+
2 rows in set (0.00 sec)
mysql>

For more information on the GRANT command for MySQL and associated commands, see this page.




Please read our Terms of Use
Microsoft, Windows, Windows XP, Windows 2003, Windows 2000, and NT are either trademarks or registered trademarks of Microsoft Corporation. NetAdminTools.com is not affiliated with Microsoft Corporation. Linux is a registered trademark of Linus Torvalds, and refers to the Linux kernel. The operating system of most distributions that contain the Linux kernel is GNU/Linux. All logos and trademarks in this site are property of their respective owner. Copyright 1997-2008 NetAdminTools.com

Created by:
MCJ
MCJ CMS