13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Introducing <strong>MySQL</strong>’s Privilege System<br />

225<br />

or<br />

MAX_UPDATES_PER_HOUR n<br />

or<br />

MAX_CONNECTIONS_PER_HOUR n<br />

These clauses allow you to limit the number of queries, updates, or connections per<br />

hour a user may make.They can be useful for limiting individual user load on shared<br />

systems.<br />

Privileges are stored in five system tables, in the database called mysql.These five<br />

tables are called mysql.user, mysql.db, mysql.host, mysql.tables_priv, <strong>and</strong><br />

mysql.columns_priv. As an alternative to GRANT, you can alter these tables directly.<br />

We discuss exactly how these tables work <strong>and</strong> how you can alter them directly in<br />

Chapter 12,“Advanced <strong>MySQL</strong> Administration.”<br />

Types <strong>and</strong> Levels of Privileges<br />

Three basic types of privileges exist in <strong>MySQL</strong>: privileges suitable for granting to regular<br />

users, privileges suitable for administrators, <strong>and</strong> a couple of special privileges. Any user<br />

can be granted any of these privileges, but it’s usually sensible to restrict the administrator<br />

type privileges to administrators, according to the principle of least privilege.<br />

You should grant privileges to users only for the databases <strong>and</strong> tables they need to<br />

use.You should not grant access to the mysql database to anyone except an administrator.This<br />

is the place where all the users, passwords, <strong>and</strong> so on are stored. (We look at this<br />

database in Chapter 12.)<br />

Privileges for regular users directly relate to specific types of SQL comm<strong>and</strong>s <strong>and</strong><br />

whether a user is allowed to run them.We discuss these SQL comm<strong>and</strong>s in detail in the<br />

next chapter. For now, let’s look at a conceptual description of what they do.The basic<br />

user privileges are shown in Table 9.1.The items under the Applies To column are the<br />

objects to which privileges of this type can be granted.<br />

Table 9.1 Privileges for Users<br />

Privilege Applies To Description<br />

SELECT tables, columns Allows users to select rows (records) from tables.<br />

INSERT tables, columns Allows users to insert new rows into tables.<br />

UPDATE tables, columns Allows users to modify values in existing table rows.<br />

DELETE tables Allows users to delete existing table rows.<br />

INDEX tables Allows users to create <strong>and</strong> drop indexes on particular tables.<br />

ALTER tables Allows users to alter the structure of existing tables by, for<br />

example, adding columns, renaming columns or tables, <strong>and</strong><br />

changing data types of columns.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!