search
HomeDatabaseMysql TutorialMySQL数据库的用户帐号管理基础知识_MySQL

MySQL数据库的用户帐号管理基础知识_MySQL

Jun 01, 2016 pm 02:11 PM
mysqlbasic knowledgedesignationdatabasePermissionsmanagestatement


  MySQL管理员应该知道怎样通过指定哪些用户可连接到服务器、从哪里进行连接,以及在连接时做什么,来设置MySQL用户账号。MySQL3.22.11引入了两个更容易进行这项工作的语句:GRANT 语句创建MySQL用户并指定其权限,REVOKE 语句删除权限。这两个语句充当mysql数据库中的授权表的前端,并提供直接操纵这些表内容的可选择的方法。GRANT 和REVOKE 语句影响以下四个表:
  
  授权表 内容
  
  user 可连接到服务器的用户和他们拥有的任何全局特权
  
  db 数据库级的特权
  
  tables _ priv 表级特权
  
  c o l um n s _ priv 列级特权
  
  还有第五个授权表( host),但它不受GRANT 或REVOKE的影响。
  
  当您为某个用户发布GRANT 语句时,应在user表中为该用户创建一个项。如果该语句指定了所有全局特权(管理权限或用于所有数据库的权限),则这些指定也被记录在user表中。如果指定了数据库、表或列的权限,它们将记录在db、tables_priv 和columns_priv表中。
  
  使用GRANT 和REVOKE语句比直接修改授权表更容易。但是,建议您最好通过阅读第12章来补充本章的内容,第12章中详细讨论了授权表。这些表非常重要,作为一位管理员应该了解这些表是怎样在GRANT 和REVOKE 语句级上工作的。
  
  本节下面的部分将讨论如何设置MySQL用户的账号和授权,还将介绍如何取消权限以及从授权表中删除全部用户,并且将考虑一个困扰许多新的MySQL管理员的难题。
  
  您还要考虑使用mysqlaccess 和mysql_setpermission 脚本,它们是MySQL分发包的组成部分。这些是Perl 的脚本,它们提供了设置用户账号的GRANT 语句的代用品。mysql_setpermission 需要具有DBI 的支持环境。
  
  创建新用户和授权
  
  GRANT 语句的语法如下:
  
  GRANT privileges (columns)
  
  ON what
  
  TO user IDENTIFIEDBY "password"
  
  WITH GRANT OPTION
  
  要使用该语句,需要填写以下部分:
  
  privileges 分配给用户的权限。下表列出了可在GRANT 语句中使用的权限说明符:
  
  权限说明符权限允许的操作
  MySQL数据库的用户帐号管理基础知识_MySQL
  上表显示的第一组权限说明符适用于数据库、表和列。第二组说明符是管理特权。通常,这些权限的授予相当保守,因为它们会影响服务器的操作(例如, SHUTDOWN 特权不是按每天来分发的权限)。第三组说明符是特殊的。ALL的意思是“所有的权限”,而USAGE 的意思是“无权限”─即创建用户,但不授予任何的权限。
  
  columns 权限适用的列。这是可选的,只来设置列专有的权限。如果命名多于一个列,则用逗号分开。
  
  what 权限应用的级别。权限可以是全局的(适用于所有数据库和所有的表)、数据库专有的(适用于某个数据库中的所有表),或表专有的。可以通过指定一个C O L U M N S子句将权限授予特定的列。
  
  user 使用权限的用户。它由用户名和主机名组成。在MySQL中,不仅指定谁进行连接,还要指定从哪里连接。它允许您拥有两个带有相同名字的、从不同位置连接的用户。MySQL允许在它们之间进行区别并相互独立地分配权限。
  
  MySQL的用户名就是您在连接到服务器时指定的名字。该名字与您的UNIX 注册名或Windows 名的没有必然连系。缺省设置时,客户机程序将使用您注册的名字作为MySQL的用户名(如果您不明确指定一个名字的话),但这只是一个约定。有关将root作为可以操作一切MySQL的超级用户名也是这样,就是一种约定。您也可以在授权表中将此名修改成nobody,然后作为nobody 用户进行连接,以执行需要超级用户特权的操作。
  
  password 分配给该用户的口令。这是可选的。如果您不给新用户指定IDENTIFIEDBY子句,该用户不分配口令(是非安全的)。对于已有的用户,任何指定的口令将替代旧口令。如果不指定新口令,用户的旧口令仍然保持不变。当您确实要使用ID E N T I F I E DBY 时,该口令串应该是直接量,GRANT 将对口令进行编码。当用SET PA S S W O R D语句时,不要使用PASSWORD() 函数。
  
  WITH GRANT OPTION 子句是可选的。如果包含该子句,该用户可以将GRANT 语句授予的任何权限授予其他的用户。可以使用该子句将授权的能力授予其他的用户。
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Describe the different SQL transaction isolation levels (Read Uncommitted, Read Committed, Repeatable Read, Serializable) and their implications in MySQL/InnoDB.Apr 15, 2025 am 12:11 AM

MySQL/InnoDB supports four transaction isolation levels: ReadUncommitted, ReadCommitted, RepeatableRead and Serializable. 1.ReadUncommitted allows reading of uncommitted data, which may cause dirty reading. 2. ReadCommitted avoids dirty reading, but non-repeatable reading may occur. 3.RepeatableRead is the default level, avoiding dirty reading and non-repeatable reading, but phantom reading may occur. 4. Serializable avoids all concurrency problems but reduces concurrency. Choosing the appropriate isolation level requires balancing data consistency and performance requirements.

MySQL vs. Other Databases: Comparing the OptionsMySQL vs. Other Databases: Comparing the OptionsApr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.