MySQL 免密连接的两种配置方式
实现 MySQL 客户端在不输入用户名和密码的情况下直接连接数据库,主要有两种方法。第一种方法是修改配置文件参数,在 Windows 系统中通常修改 my.ini 文件,而在 Linux 系统中则修改 my.cnf 文件。在配置文件的 [client] 段落中,可以指定 port=3306、default-character-set=utf8、host=localhost、user=root 以及 password=1 等具体参数,其他相关配置也可在此处进行调整。第二种方法是利用环境变量进行设置,其中 MYSQL_HOST 用于定义主机名,USER 用于指定用户名,而 MYSQL_PWD 则用于存储密码。关于更多详细的参数说明,建议查阅 MySQL 的帮助文档,例如英文表格中列出了如 CXX、CC、CFLAGS 等编译器相关变量,以及 DBI_USER、HOME、LD_RUN_PATH 等与 MySQL 运行环境相关的变量。特别需要注意的是,MYSQL_PWD 虽然能作为连接 mysqld 时的默认密码,但这种方式被认为是不安全的,应参考 Section 5.5.6.2 “End-User Guidelines for Password Security” 中的用户密码安全指南。此外,文档还涵盖了 MYSQL_DEBUG、MYSQL_GROUP_SUFFIX、MYSQL_HISTFILE、MYSQL_HOME、MYSQL_PS1、MYSQL_TCP_PORT、MYSQL_UNIX_PORT、PATH、TMPDIR、TZ、UMASK 和 UMASK_DIR 等变量的具体描述与作用。
| Variable | Description |
CXX |
The name of your C++ compiler (for running configure ). |
CC |
The name of your C compiler (for running configure ). |
CFLAGS |
Flags for your C compiler (for running configure ). |
CXXFLAGS |
Flags for your C++ compiler (for running configure ). |
DBI_USER |
The default user name for Perl DBI. |
DBI_TRACE |
Trace options for Perl DBI. |
HOME |
The default path for the mysql history file is $HOME/.mysql_history . |
LD_RUN_PATH |
Used to specify the location of libmysqlclient.so . |
MYSQL_DEBUG |
Debug trace options when debugging. |
MYSQL_GROUP_SUFFIX |
Option group suffix value (like specifying --defaults-group-suffix ). |
MYSQL_HISTFILE |
The path to the mysql history file. If this variable is set, its value overrides the default for $HOME/.mysql_history . |
MYSQL_HOME |
The path to the directory in which the server-specific my.cnf file resides (as of MySQL 5.0.3). |
MYSQL_HOST |
The default host name used by the mysql command-line client. |
MYSQL_PS1 |
The command prompt to use in the mysql command-line client. |
MYSQL_PWD |
The default password when connecting to mysqld . Note that using this is insecure. See Section 5.5.6.2, “End-User Guidelines for Password Security”. |
MYSQL_TCP_PORT |
The default TCP/IP port number. |
MYSQL_UNIX_PORT |
The default Unix socket file name; used for connections to localhost . |
PATH |
Used by the shell to find MySQL programs. |
TMPDIR |
The directory where temporary files are created. |
TZ |
This should be set to your local time zone. See Section B.1.4.6, “Time Zone Problems”. |
UMASK |
The user-file creation mode when creating files. See note following table. |
UMASK_DIR |
The user-directory creation mode when creating directories. See note following table. |
USER |
The default user name on Windows and NetWare used when connecting to mysqld . |