Home Database Mysql Tutorial MySQL数据库管理员常见问题汇总(1)

MySQL数据库管理员常见问题汇总(1)

Jun 07, 2016 pm 04:06 PM
mysql common problem database Summary administrator connect

谁能连接,从那儿连接? 你可以允许一个用户从特定的或一系列主机进行连接。有一个极端,如果你想要只从一个主机连接,你可以将权限局限于单个主机: GRANT ALL ON samp_db.* TO boris@localhost IDENTIFIED BY "ruby"GRANT ALL ON samp_db.* TO fred@res.mar

谁能连接,从那儿连接?

你可以允许一个用户从特定的或一系列主机进行连接。有一个极端,如果你想要只从一个主机连接,你可以将权限局限于单个主机:

GRANT ALL ON samp_db.* TO boris@localhost <br>IDENTIFIED BY "ruby"GRANT ALL ON samp_db.* <br>TO fred@res.mars.com IDENTIFIED BY "quartz"
Copy after login

(samp_db.*意思是“samp_db数据库的所有表)另一个极端是,你可能有一个经常旅行并需要能从世界各地的主机连接的用户max。在这种情况下,你可以允许他无论从那里连接:

GRANT ALL ON samp_db.* TO max@% IDENTIFIED BY "diamond"
Copy after login

“%”字符起通配符作用,与LIKE模式匹配的含义相同。在上述语句中,它意味着“任何主机”。所以max和max@%等价。这是建立用户最简单的方法,但也是最不安全的。

取其中,你可以允许一个用户从一个受限的主机集合访问。例如,要允许mary从snake.net域的任何主机连接,用一个%.snake.net主机指定符:

GRANT ALL ON samp_db.* TO mary@.snake.net IDENTIFIED BY "quartz";
Copy after login

如果你喜欢,用户标识符的主机部分可以用IP地址而不是一个主机名来给定。你可以指定一个IP地址或者一个包含模式字符的地址,而且,从MySQL 3.23,你还可以指定具有指出用于网络号的位数的网络掩码的IP号:

GRANT ALL ON samp_db.* TO boris@192.168.128.3 IDENTIFIED BY "ruby"  <br>GRANT ALL ON samp_db.* TO fred@192.168.128.% IDENTIFIED BY "quartz"  <br>GRANT ALL ON samp_db.* TO rex@192.168.128.0/17 IDENTIFIED BY "ruby"
Copy after login

第一个例子指出用户能从其连接的特定主机,第二个指定对于C类子网192.168.128的IP模式,而第三条语句中,192.168.128.0/17指定一个17位网络号并匹配具有192.168.128头17位的IP地址。

如果MySQL抱怨你指定的用户值,你可能需要使用引号(只将用户名和主机名部分分开加引号)。

GRANT ALL ON samp_db.president TO "my friend"@"boa.snake.net"
Copy after login

用户应该有什么级别的权限和它们应该适用于什么?

你可以授权不同级别的权限,全局权限是最强大的,因为它们适用于任何数据库。要使ethel成为可做任何事情的超级用户,包括能授权给其它用户,发出下列语句:

GRANT ALL ON *.* TO ethel@localhost <br>IDENTIFIED BY "coffee" WITH GRANT OPTION
Copy after login

ON子句中的*.*意味着“所有数据库、所有表”。从安全考虑,我们指定ethel只能从本地连接。限制一个超级用户可以连接的主机通常是明智的,因为它限制了试图破解口令的主机。

有些权限(FILE、PROCESS、RELOAD和SHUTDOWN)是管理权限并且只能用"ON *.*"全局权限指定符授权。如果你愿意,你可以授权这些权限,而不授权数据库权限。例如,下列语句设置一个flush用户,他只能发出flush语句。这可能在你需要执行诸如清空日志等的管理脚本中会有用:

GRANT RELOAD ON *.* TO flushl@localhost IDENTIFIED BY "flushpass"
Copy after login

一般地,你想授权管理权限,临界点,因为拥有它们的用户可以影响你的服务器的操作。

数据库级权限适用于一个特定数据库中的所有表,它们可通过使用ON db_name.*子句授予:

GRANT ALL ON samp_db TO bill@racer.snake.net <br>INDETIFIED BY "rock" GRANT SELECT ON samp_db <br>TO ro_user@% INDETIFIED BY "rock"
Copy after login

第一条语句向bill授权samp_db数据库中所有表的权限,第二条创建一个严格限制访问的用户ro_user(只读用户),只能访问samp_db数据库中的所有表,但只有读取,即用户只能发出SELECT语句。

你可以列出一系列同时授予的各个权限。例如,如果你想让用户能读取并能修改现有数据库的内容,但不能创建新表或删除表,如下授予这些权限:

GRANT SELECT,INSERT,DELETE,UPDATE ON samp_db TO bill@snake.net INDETIFIED BY "rock"
Copy after login

对于更精致的访问控制,你可以在各个表上授权,或甚至在表的每个列上。当你想向用户隐藏一个表的部分时,或你想让一个用户只能修改特定的列时,列特定权限非常有用。如:

GRANT SELECT ON samp_db.member TO bill@localhost <br>INDETIFIED BY "rock"GRANT UPDATE (expiration) ON <br>samp_db. member TO bill@localhost
Copy after login

第一条语句授予对整个member表的读权限并设置了一个口令,第二条语句增加了UPDATE权限,当只对expiration列。没必要再指定口令,因为第一条语句已经指定了。

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

See all articles