search
HomeDatabaseMysql TutorialMySQL数据库管理员常见问题汇总(1)

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

Jun 07, 2016 pm 04:06 PM
mysqlcommon problemdatabaseSummaryadministratorconnect

谁能连接,从那儿连接? 你可以允许一个用户从特定的或一系列主机进行连接。有一个极端,如果你想要只从一个主机连接,你可以将权限局限于单个主机: 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"

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

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

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

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

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

如果你喜欢,用户标识符的主机部分可以用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"

第一个例子指出用户能从其连接的特定主机,第二个指定对于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"

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

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

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

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

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

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

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

数据库级权限适用于一个特定数据库中的所有表,它们可通过使用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"

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

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

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

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

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

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

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
How to use MySQL functions for data processing and calculationHow to use MySQL functions for data processing and calculationApr 29, 2025 pm 04:21 PM

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

An efficient way to batch insert data in MySQLAn efficient way to batch insert data in MySQLApr 29, 2025 pm 04:18 PM

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

Steps to add and delete fields to MySQL tablesSteps to add and delete fields to MySQL tablesApr 29, 2025 pm 04:15 PM

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

How to analyze the execution plan of MySQL queryHow to analyze the execution plan of MySQL queryApr 29, 2025 pm 04:12 PM

Use the EXPLAIN command to analyze the execution plan of MySQL queries. 1. The EXPLAIN command displays the execution plan of the query to help find performance bottlenecks. 2. The execution plan includes fields such as id, select_type, table, type, possible_keys, key, key_len, ref, rows and Extra. 3. According to the execution plan, you can optimize queries by adding indexes, avoiding full table scans, optimizing JOIN operations, and using overlay indexes.

How to use MySQL subquery to improve query efficiencyHow to use MySQL subquery to improve query efficiencyApr 29, 2025 pm 04:09 PM

Subqueries can improve the efficiency of MySQL query. 1) Subquery simplifies complex query logic, such as filtering data and calculating aggregated values. 2) MySQL optimizer may convert subqueries to JOIN operations to improve performance. 3) Using EXISTS instead of IN can avoid multiple rows returning errors. 4) Optimization strategies include avoiding related subqueries, using EXISTS, index optimization, and avoiding subquery nesting.

How to configure the character set and collation rules of MySQLHow to configure the character set and collation rules of MySQLApr 29, 2025 pm 04:06 PM

Methods for configuring character sets and collations in MySQL include: 1. Setting the character sets and collations at the server level: SETNAMES'utf8'; SETCHARACTERSETutf8; SETCOLLATION_CONNECTION='utf8_general_ci'; 2. Create a database that uses specific character sets and collations: CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci; 3. Specify character sets and collations when creating a table: CREATETABLEexample_table(idINT

How to uninstall MySQL and clean residual filesHow to uninstall MySQL and clean residual filesApr 29, 2025 pm 04:03 PM

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

How to rename a database in MySQLHow to rename a database in MySQLApr 29, 2025 pm 04:00 PM

Renaming a database in MySQL requires indirect methods. The steps are as follows: 1. Create a new database; 2. Use mysqldump to export the old database; 3. Import the data into the new database; 4. Delete the old database.

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

Video Face Swap

Video Face Swap

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

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

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.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),