[翻译]如何在mysql上创建新用户、授予权限
原文是业界鼎鼎有名,linode的强力竞争对手,DigitalOcean公司写的。主要是方便他们的VPS客户对系统进行配置。我觉得写的很好,故翻译出来,方便各位用了linux vps但英文不是很熟练的朋友。关于DigitalOcean的介绍以及如何在上面购买机器,选择什么样的套餐
原文是业界鼎鼎有名,linode的强力竞争对手,DigitalOcean公司写的。主要是方便他们的VPS客户对系统进行配置。我觉得写的很好,故翻译出来,方便各位用了linux vps但英文不是很熟练的朋友。关于DigitalOcean的介绍以及如何在上面购买机器,选择什么样的套餐合适,请看我的这篇文章:DigitalOcean介绍及购买指南。如果你想要买DO的vps,请猛搓这个链接
以下是原文的翻译
标红的字段是什么意思
本教程中标红行中的字段指的是需要输入或者定制的内容!
剩下的大部分应该是可以直接复制粘贴的。
关于MySQL
翻译略
如何创建一个新用户
让我们使用MySQL shell来创建一个新用户:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
悲剧的是,此时这个账户对这个数据库没有任何权限。实际上,即使这个新用户试图用密码登陆,甚至连MySQL的shell都无法进入。
既然如此,首先要做的事就是提供用户访问所需的信息:
GRANT ALL PRIVILEGES ON . TO 'newuser'@'localhost';
命令中的星号(*)指的是此账户可以访问的数据库和表(分别的)--这个特定的命令允许用户对所有的数据库、表能读、编辑、执行、运行所有的任务。
一旦操作完毕对你的新用户的权限设置,总是确认重载所有的权限:
FLUSH PRIVILEGES;
现在你的更改已经生效了。
如何授予不同的用户权限
这有一个其他通常可能的权限使用的小列表:
- ALL PRIVILEGES - 如同我们前面所见,这会允许MySQL用户能访问所有的指定的数据库;
- CREATE- 允许用户创建新表或者数据库;
- DROP- 允许用户删除表或数据库;
- DELETE- 允许用户删除表中的行;
- INSERT- 允许用户能向表中插入新行;
- SELECT- 允许用户能使用select命令来读取数据库里面的内容;
- UPDATE- 允许用户更新表中的行;
- GRANT OPTION- 允许用户授权或者取消其他用户的特权;
给一个指定的用户提供某些权限,你可以使用如下这样的命令格式:
GRANT [type of permission] ON [database name].[table name] TO '[username]'@'localhost';
如果你想给用户授权访问所有的数据库、表的权限,请确认使用星号(*)在对应的数据库名/表名位置。
每一次你更新或者改变了权限,确认使用FLUSH PRIVILEGES 命令
如果你需要撤销一个权限,命令的格式与授权基本一致:
REVOKE [type of permission] ON [database name].[table name] FROM '[username]'@'localhost';
与你使用drop来删掉一个数据库一样的,你可以使用使用drop来完全的删除一个用户:
DROP USER 'demo'@'localhost';
要测试你的新用户,只需要退出后,使用新用户登录,即可测试。
quit
mysql -u[username] -ppassword -A DATABASE
翻译完
后记:
在实际运行中,某些账户只需要select权限,某些只需要insert权限,某些只需要update权限,为了安全,可以考虑最小化权限,在遭受攻击时,也可以作为一道可能的安全防线。
限于本人英文阅读能力,中文表达能力,计算机水平能力有限,其中翻译的错误,表达不清楚肯定存在,如果有错漏之处,希望能留言指出,谢谢。
原文地址:[翻译]如何在mysql上创建新用户、授予权限, 感谢原作者分享。

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



In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

To fill in the MySQL username and password: 1. Determine the username and password; 2. Connect to the database; 3. Use the username and password to execute queries and commands.

1. Use the correct index to speed up data retrieval by reducing the amount of data scanned select*frommployeeswherelast_name='smith'; if you look up a column of a table multiple times, create an index for that column. If you or your app needs data from multiple columns according to the criteria, create a composite index 2. Avoid select * only those required columns, if you select all unwanted columns, this will only consume more server memory and cause the server to slow down at high load or frequency times For example, your table contains columns such as created_at and updated_at and timestamps, and then avoid selecting * because they do not require inefficient query se

Navicat itself does not store the database password, and can only retrieve the encrypted password. Solution: 1. Check the password manager; 2. Check Navicat's "Remember Password" function; 3. Reset the database password; 4. Contact the database administrator.

Create a database using Navicat Premium: Connect to the database server and enter the connection parameters. Right-click on the server and select Create Database. Enter the name of the new database and the specified character set and collation. Connect to the new database and create the table in the Object Browser. Right-click on the table and select Insert Data to insert the data.

View the MySQL database with the following command: Connect to the server: mysql -u Username -p Password Run SHOW DATABASES; Command to get all existing databases Select database: USE database name; View table: SHOW TABLES; View table structure: DESCRIBE table name; View data: SELECT * FROM table name;

Copying a table in MySQL requires creating new tables, inserting data, setting foreign keys, copying indexes, triggers, stored procedures, and functions. The specific steps include: creating a new table with the same structure. Insert data from the original table into a new table. Set the same foreign key constraint (if the original table has one). Create the same index. Create the same trigger (if the original table has one). Create the same stored procedure or function (if the original table is used).
