在主目录中为多个数据库配置.my.cnf无效.适用于单个数据库 [英] Configuring .my.cnf in home directory for multiple databases does not work. Works for single database
问题描述
这是我的.my.cnf文件:
Here is my .my.cnf file:
[client]
user=user1
password=somePasswd1
database=someDb
[client2]
user=user1
password=somePassed2
database=someotherDb
如果我只有一个条目,它会起作用,如:
It works if I just have one entry, as in:
[client]
user=user1
password=somePasswd1
database=someDb
[客户]的意义是什么?应该有什么?另外,如果我只想将这些用户密码限制为本地主机怎么办?
What is the significance of [client]? What should it have? Also, what if I want to restrict these user-passwords for localhost only?
推荐答案
MySQL发行版中提供的所有客户端程序(而不是mysqld)都读取[client]选项组.
The [client] option group is read by all client programs provided in MySQL distributions (but not by mysqld). 通过[client]组,您可以指定适用于所有客户端的选项.例如,[client]是用于指定连接到服务器的密码的适当组. (但是请确保该选项文件只能由您自己访问,以免其他人无法找到您的密码.)除非您使用的所有客户端程序都能识别该选项,否则请确保不要将其放置在[client]组中./p>
The [client] group enables you to specify options that apply to all clients. For example, [client] is the appropriate group to use to specify the password for connecting to the server. (But make sure that the option file is accessible only by yourself, so that other people cannot discover your password.) Be sure not to put an option in the [client] group unless it is recognized by all client programs that you use. MySQL客户端程序在手册中: https://dev.mysql.com/doc/refman/8.0/zh-CN/programs-client.html The MySQL client programs are in the manual: https://dev.mysql.com/doc/refman/8.0/en/programs-client.html 如果使用的选项组如 If you use an option group like https://dev.mysql.com/doc/refman/8.0/en/option-file-options.html 说: -defaults-group-suffix = str --defaults-group-suffix=str 不仅读取常规选项组,还读取具有常规名称和后缀str的组.例如,mysql客户端通常读取[client]和[mysql]组.如果指定了--defaults-group-suffix = _other选项,则mysql还将读取[client_other]和[mysql_other]组. Read not only the usual option groups, but also groups with the usual names and a suffix of str. For example, the mysql client normally reads the [client] and [mysql] groups. If the --defaults-group-suffix=_other option is given, mysql also reads the [client_other] and [mysql_other] groups. 就您而言,您可以运行: In your case, you could run: mysql --defaults-group-suffix = 2 mysql --defaults-group-suffix=2 这将使mysql客户端从选项文件中的 That would make the mysql client read options from the "而且,如果我只想将这些用户密码限制为本地主机该怎么办?" 当您授予用户特权时会处理此问题. This is handled when you GRANT privileges to your user. 通过在user1之后指定主机,这意味着仅当user1从本地主机连接时,授予才有效.如果user1尝试从任何其他主机进行连接,则授予将不起作用.这包括密码凭证本身.阅读 https://dev.mysql.com/doc/refman/8.0/en/grant.html 了解更多信息. By specifying the host after user1, it means the grant only works when user1 connects from localhost. If user1 is trying to connect from any other host, the grants won't work. That includes the password credential itself. Read https://dev.mysql.com/doc/refman/8.0/en/grant.html for more information. 这篇关于在主目录中为多个数据库配置.my.cnf无效.适用于单个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
[client2]
,则除非使用--defaults-group-suffix
选项,否则不会使用此选项组.[client2]
this is not used unless you use the --defaults-group-suffix
option.
[client2]
组读取选项.[client2]
group in your option file.GRANT ... ON *.* TO 'user1'@'localhost';