# Part 6.1Granting privileges in MySQL

SQL provides a layer of authority over the database, allowing certain users to access certain features of the database. This can be an excellent way to ensure data security.

It is often necessary to have a single user who has authority to do everything on a database but then for some web application a user who only has certain authorities over certain databases.

MySQL allows the database to be accessed in different ways by different users very easily, and the GRANT command allows users to be setup this way very easily.

## Granting privileges

Adding privileges to a user is called granting privileges in MySQL.

The basic structure for granting privileges is as follows:

SQL
GRANT privilege[, privilege] ...
ON database.tables
TO account.host


Assume there exists a user called toby and a database called friends. The following SQL statement would allow toby access to all tables in the friends database.

SQL
	GRANT ALL PRIVILEGES ON friends.* TO 'toby'@'localhost';
FLUSH PRIVILEGES;


In this statement:

• ALL can be replaced with specific, comma-separated individual privileges that the user should have.
• The * means every table within the friends database.
• The localhost can be replaced with anything or a wildcard that informs MySQL that the user could come from any valid host using the % symbol.
• It is important to run the FLUSH PRIVILEGES command straight after to ensure that the database engine is updated with the changes.
Code preview
Feedback 👍
Comments are sent via email to me.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.21953192353248596, "perplexity": 3331.7172905599955}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-05/segments/1642320299894.32/warc/CC-MAIN-20220129002459-20220129032459-00062.warc.gz"}