mysql_config 为您提供编译 MySQL 客户端并将其连接到 MySQL 的有用信息。它是一个 shell 脚本,因此仅在 Unix 和类 Unix 系统上可用。mysql_config provides you with useful information for compiling your MySQL client and connecting it to MySQL. It is a shell script, so it is available only on Unix and Unix-like systems.
pkg-config 可以作为 mysql_config 的替代方案,用于获取编译 MySQL 应用程序所需的编译器标志或链接库等信息。更多信息,请参见 使用 pkg-config 构建 C API 客户端程序。pkg-config can be used as an alternative to mysql_config for obtaining information such as compiler flags or link libraries required to compile MySQL applications. For more information, see Building C API Client Programs Using pkg-config.
mysql_config 支持以下选项。mysql_config supports the following options.
用于查找包含文件的 C 编译器标志以及在编译
libmysqlclient库时使用的关键编译器标志和定义。返回的选项与创建库时使用的特定编译器相关,并可能与您自己编译器的设置冲突。使用--include以获得仅包含包含路径的更通用选项。C Compiler flags to find include files and critical compiler flags and defines used when compiling thelibmysqlclientlibrary. The options returned are tied to the specific compiler that was used when the library was created and might clash with the settings for your own compiler. Use--includefor more portable options that contain only include paths.类似于
--cflags,但是用于 C++编译器标志。Like--cflags, but for C++ compiler flags.用于查找 MySQL 包含文件的编译器选项。Compiler options to find MySQL include files.
与 MySQL 客户端库链接所需的库和选项。Libraries and options required to link with the MySQL client library.
与线程安全的 MySQL 客户端库链接所需的库和选项。在 MySQL 8.4 中,所有客户端库都是线程安全的,因此无需使用此选项。
--libs选项在所有情况下都可以使用。Libraries and options required to link with the thread-safe MySQL client library. In MySQL 8.4, all client libraries are thread-safe, so this option need not be used. The--libsoption can be used in all cases.默认插件目录路径名称,在配置 MySQL 时定义。The default plugin directory path name, defined when configuring MySQL.
默认的 TCP/IP 端口号,在配置 MySQL 时定义。The default TCP/IP port number, defined when configuring MySQL.
默认的 Unix 套接字文件,在配置 MySQL 时定义。The default Unix socket file, defined when configuring MySQL.
显示指定配置变量的值。允许的
var_name值为pkgincludedir(头文件目录)、pkglibdir(库目录)和plugindir(插件目录)。Display the value of the named configuration variable. Permittedvar_namevalues arepkgincludedir(the header file directory),pkglibdir(the library directory), andplugindir(the plugin directory).MySQL 分发的版本号。Version number for the MySQL distribution.
如果你调用mysql_config而不加任何选项,它会显示它支持的所有选项及其值:If you invoke mysql_config with no options, it displays a list of all options that it supports, and their values:
$> mysql_config
Usage: ./mysql_config [OPTIONS]
Compiler: GNU 10.4.0
Options:
--cflags [-I/usr/local/mysql/include/mysql]
--cxxflags [-I/usr/local/mysql/include/mysql]
--include [-I/usr/local/mysql/include/mysql]
--libs [-L/usr/local/mysql/lib/mysql -lmysqlclient -lpthread -ldl
-lssl -lcrypto -lresolv -lm -lrt]
--libs_r [-L/usr/local/mysql/lib/mysql -lmysqlclient -lpthread -ldl
-lssl -lcrypto -lresolv -lm -lrt]
--plugindir [/usr/local/mysql/lib/plugin]
--socket [/tmp/mysql.sock]
--port [3306]
--version [8.4.0]
--variable=VAR VAR is one of:
pkgincludedir [/usr/local/mysql/include]
pkglibdir [/usr/local/mysql/lib]
plugindir [/usr/local/mysql/lib/plugin]
你可以在命令行中使用mysql_config并用反引号包含它为特定选项生成的输出。例如,要编译和链接一个 MySQL 客户端程序,可以如下使用mysql_config:You can use mysql_config within a command line using backticks to include the output that it produces for particular options. For example, to compile and link a MySQL client program, use mysql_config as follows:
gcc -c `mysql_config --cflags` progname.c gcc -o progname progname.o `mysql_config --libs`