博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在MySQL上创建用户
阅读量:2503 次
发布时间:2019-05-11

本文共 3212 字,大约阅读时间需要 10 分钟。

Right after you install MySQL, you will have the root user available.

在安装MySQL之后,您将具有root用户可用。

This is the user you might use to try and see if MySQL is working, but it should not be the user for other kinds of usages.

这是您可能用来尝试查看MySQL是否正在运行的用户,但不应该是其他用途的用户。

Why? Because it’s too powerful.

为什么? 因为它太强大了

With great power comes great responsibility (said Spider-Man’s uncle). And in particular, great danger if you make mistakes.

强大的力量带来巨大的责任(蜘蛛侠的叔叔说)。 特别是如果您犯了错误,将会带来极大的危险。

Instead, you should create ad-hoc users that only have permissions to perform their job, and no more. Same for using Linux or any Unix system, for example: you don’t want to be using the root user, but your own user account.

相反,您应该创建临时用户,这些用户仅具有执行其工作的权限,而没有其他权限。 例如,与使用Linux或任何Unix系统的情况相同:您不想使用root用户,而要使用自己的用户帐户。

To create a new user, connect to MySQL using the root user:

要创建新用户,请使用root用户连接到MySQL:

mysql -u root -p

then use the command

然后使用命令

CREATE USER '
'@'localhost' IDENTIFIED BY '
';

For example, to create a user named test_user with password test_password12A run the command:

例如,要创建一个名为test_user且密码为test_password12A的用户,请运行以下命令:

CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'test_password12A';

The command should return a line saying Query OK, 0 rows affected (X.XX sec):

该命令应返回一行Query OK, 0 rows affected (X.XX sec)

If you used an invalid password, the system would tell you something like ERROR 1819 (HY000): Your password does not satisfy the current policy requirements. In this case the error says that the password is not complex enough, because when I installed MySQL I told it to use a certain policy on passwords.

如果您使用了无效的密码,系统将告诉您类似ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 。 在这种情况下,该错误表明密码不够复杂,因为在安装MySQL时,我告诉它对密码使用某种策略。

That’s great! Now the user has been created, and we can connect using that user to MySQL. From the command line you can exit by typing QUIT, and typing:

那很棒! 现在已经创建了用户,我们可以使用该用户连接到MySQL。 在命令行中,您可以输入QUITQUIT

mysql -u test_user -p

Now if I try to create a database, I’d get an error saying ERROR 1044 (42000): Access denied for user 'test_user'@'localhost' to database 'testing':

现在,如果我尝试创建数据库,则会收到一条错误消息,提示ERROR 1044 (42000): Access denied for user 'test_user'@'localhost' to database 'testing'

Why? Because the user does not have the permission to create a new database.

为什么? 因为用户没有创建新数据库的权限

We’ll see how to work with permissions in another tutorial.

在另一个教程中,我们将介绍如何使用权限。

It’s worth mentioning the @'localhost' string we used to create the user. This tells MySQL that the user can only connect from localhost. Which is fine when testing things out and when any application that will connect to MySQL is running on the same computer that runs the DBMS.

值得一提的是我们用来创建用户的@'localhost'字符串。 这告诉MySQL用户只能从本地主机连接。 当进行测试以及将要连接到MySQL的任何应用程序在运行DBMS的同一台计算机上运行时,这很好。

When this is not true, you either need to manually enter the IP the user will connect from, or use the % wildcard:

如果不正确,则需要手动输入用户将要连接的IP,或者使用%通配符:

CREATE USER 'test_user'@'%' IDENTIFIED BY 'test_password12A';

I want to close this tutorial by showing how to remove the user we created:

我想通过显示如何删除我们创建的用户来结束本教程:

DROP USER 'test_user'@'localhost';

翻译自:

转载地址:http://xtqgb.baihongyu.com/

你可能感兴趣的文章
cmd 导入数据库
查看>>
Makefile书写注意事项--个人择记(一)
查看>>
文件转码重写到其他文件
查看>>
场景3 Data Management
查看>>
Dubbo入门---搭建一个最简单的Demo框架(转)
查看>>
树结构练习——排序二叉树的中序遍历
查看>>
AC自动机模板
查看>>
python 基本语法
查看>>
Oracle JDBC hang on
查看>>
inotify+rsync实现实时热备
查看>>
C#杂问
查看>>
Cocoapods的使用教程
查看>>
Swift - 点击箭头旋转
查看>>
SpringBoot学习(四)
查看>>
深入理解javascript作用域系列第四篇
查看>>
git配置
查看>>
bing智能提示搜索框实现
查看>>
12月月计划与周计划
查看>>
分享Java开发的利器-Lombok
查看>>
实战中总结出来的CSS常见问题及解决办法
查看>>