用MySQL GRANT语句来增添新用户实操
我们今天主要向大家讨论的是用MySQL GRANT语句来增添新的用户的实际操作方案,以及对图解MySQL数据库的实际安装步骤与具体操作,你如果对其有兴趣的话你就可以点击以下的文章进行观看了。 如何实现MySQL(和PHP搭配之最佳组合)数据库的备份与恢复 MySQL(和PHP
我们今天主要向大家讨论的是用MySQL GRANT语句来增添新的用户的实际操作方案,以及对图解MySQL数据库的实际安装步骤与具体操作,你如果对其有兴趣的话你就可以点击以下的文章进行观看了。
如何实现MySQL(和PHP搭配之最佳组合)数据库的备份与恢复
MySQL(和PHP搭配之最佳组合)数据库接口的VC实现与应用(2)
如何备份MySQL(和PHP搭配之最佳组合)数据库
MySQL(和PHP搭配之最佳组合):用Java来测试MySQL(和PHP搭配之最佳组合)数据库的最
MySQL(和PHP搭配之最佳组合)数据库技术(01)
如何在ASP中连接MySQL(和PHP搭配之最佳组合)数据库
最简便的MySQL(和PHP搭配之最佳组合)数据库备份的方法
MySQL(和PHP搭配之最佳组合)数据库备份与恢复
MySQL(和PHP搭配之最佳组合)数据库连接过多的错误,可能的原
下面的例子显示如何使用MySQL(和PHP搭配之最佳组合)客户安装新用户。这些例子假定权限已缺省被安装。
这意味着为了改变,你必须在MySQL(和PHP搭配之最佳组合)正在运行同一台机器上,你必须作为MySQL(和PHP搭配之最佳组合) root用户连接,并且root用户必须对MySQL(和PHP搭配之最佳组合)数据库有insert权限和reload管理权限。另外,如果你改变了root用户口令,你必须如下的MySQL(和PHP搭配之最佳组合)命令指定它。
你可以通过发出MySQL GRANT语句增加新用户:
<ol class="dp-xml"><li class="alt"><span><span>shell</span><span class="tag">></span><span> MySQL(和PHP搭配之最佳组合) </span><span class="attribute">--user</span><span>=</span><span class="attribute-value">root</span><span> MySQL(和PHP搭配之最佳组合) <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> GRANT ALL PRIVILEGES ON *.* <br>TO monty@localhost IDENTIFIED BY 'something' WITH GRANT OPTION; <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> GRANT ALL PRIVILEGES ON *.* TO monty@"%" IDENTIFIED BY 'something' WITH GRANT OPTION; <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> MySQL GRANT RELOAD,PROCESS ON *.* TO admin@localhost; MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> MySQL GRANT USAGE ON *.* TO dummy@localhost; </span></span></li></ol>
这些GRANT语句安装3个新用户:
monty:可以从任何地方连接服务器的一个完全的超级用户,但是必须使用一个口令('something'做这个。注意,我们必须对monty@localhost和monty@"%"发出MySQL GRANT语句。
如果我们增加localhost条目,对localhost的匿名用户条目在我们从本地主机连接接时由MySQL(和PHP搭配之最佳组合)_install_db创建的条目将优先考虑,因为它有更特定的Host字段值,所以以user表排列顺序看更早到来。
admin:可以从localhost没有一个口令进行连接并且被授予reload和process管理权限的用户。这允许用户执行MySQL(和PHP搭配之最佳组合)admin reload、MySQL(和PHP搭配之最佳组合)admin refresh和MySQL(和PHP搭配之最佳组合)admin flush-*命令,还有MySQL(和PHP搭配之最佳组合)admin processlist。
没有授予数据库有关的权限。他们能在以后通过发出另一个GRANT语句授权。
dummy:可以不用一个口令连接的一个用户,但是只能从本地主机。全局权限被设置为'N'--USAGE权限类型允许你无需权限就可设置一个用户。它假定你将在以后授予数据库相关的权限。
你也可以直接通过发出INSERT语句增加同样的用户存取信息,然后告诉服务器再次装入授权表:
<ol class="dp-xml"><li class="alt"><span><span>shell</span><span class="tag">></span><span> MySQL(和PHP搭配之最佳组合) </span><span class="attribute">--user</span><span>=</span><span class="attribute-value">root</span><span> MySQL(和PHP搭配之最佳组合) <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user <br>VALUES('localhost','monty',PASSWORD('something'), <br>'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y') <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user <br>VALUES('%','monty',PASSWORD('something'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y') <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user SET </span><span class="attribute">Host</span><span>=</span><span class="attribute-value">'localhost'</span><span>,</span><span class="attribute">User</span><span>=</span><span class="attribute-value">'admin'</span><span>, </span><span class="attribute">Reload_priv</span><span>=</span><span class="attribute-value">'Y'</span><span>, </span><span class="attribute">Process_priv</span><span>=</span><span class="attribute-value">'Y'</span><span>; <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user (Host,User,Password) VALUES('localhost','dummy',''); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> FLUSH PRIVILEGES; </span></span></li></ol>
取决于你的MySQL(和PHP搭配之最佳组合)版本,对上述,你可能必须使用一个不同数目'Y'值(在3.22.11以前的版本有更少的权限列)。对admin用户,只用在3.22.11开始的版本具有的更加可读的INSERT扩充的语法。
注意,为了设置一个超级用户,你只需创造一个user表条目,其权限字段设为'Y'。不需要db或host表的条目。
在user表中的权限列不是由最后一个INSERT语句明确设置的(对dummy用户),因此那些列被赋予缺省值'N'。这是MySQL GRANT USAGE做的同样的事情。
下列例子增加一个用户custom,他能从主机localhost、server.domain和whitehouse.gov连接。他只想要从localhost存取bankaccount数据库,从whitehouse.gov存取expenses数据库和从所有3台主机存取customer数据库。他想要从所有3台主机上使用口令stupid。
为了使用GRANT语句设置个用户的权限,运行这些命令:
<ol class="dp-xml"><li class="alt"><span><span>shell</span><span class="tag">></span><span> MySQL(和PHP搭配之最佳组合) </span><span class="attribute">--user</span><span>=</span><span class="attribute-value">root</span><span> MySQL(和PHP搭配之最佳组合) MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> MySQL GRANT SELECT,<br>INSERT,UPDATE,DELETE,CREATE,DROP ON bankaccount.* TO custom@localhost IDENTIFIED BY 'stupid'; <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON expenses.* <br>TO custom@whitehouse.gov IDENTIFIED BY 'stupid'; <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> MySQL GRANT SELECT,<br>INSERT,UPDATE,DELETE,CREATE,DROP ON customer.* TO custom@'%' IDENTIFIED BY 'stupid'; </span></span></li></ol>
通过直接修改授权表设置用户权限,运行这些命令(注意,在结束时FLUSH PRIVILEGES):
<ol class="dp-xml"><li class="alt"><span><span>shell</span><span class="tag">></span><span> MySQL(和PHP搭配之最佳组合) </span><span class="attribute">--user</span><span>=</span><span class="attribute-value">root</span><span> MySQL(和PHP搭配之最佳组合) <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user (Host,User,Password) VALUES('localhost','custom',PASSWORD('stupid')); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user (Host,User,Password) VALUES('server.domain','custom',PASSWORD('stupid')); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO user (Host,User,Password) VALUES('whitehouse.gov','custom',PASSWORD('stupid')); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, <br>Create_priv,Drop_priv) VALUES ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y'); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,<br>Update_priv,Delete_priv, Create_priv,Drop_priv) VALUES ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y'); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,<br>Update_priv,Delete_priv, Create_priv,Drop_priv) VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y'); <br>MySQL(和PHP搭配之最佳组合)</span><span class="tag">></span><span> FLUSH PRIVILEGES; </span></span></li></ol>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Big data structure processing skills: Chunking: Break down the data set and process it in chunks to reduce memory consumption. Generator: Generate data items one by one without loading the entire data set, suitable for unlimited data sets. Streaming: Read files or query results line by line, suitable for large files or remote data. External storage: For very large data sets, store the data in a database or NoSQL.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.
