mysql為我們提供了三種安裝方式:二進制、rpm、源代碼編譯。這裡我們詳細討論mysql的源代碼編譯安裝方式。
在5.5版本之後,mysql不再提供configure編譯方式,改為使用cmake編譯工具,cmake工具的一個顯著特點是其編譯獨立於源代碼,即我們可以在源代碼之外的目錄使用cmake來編譯mysql,如
[root@easy tmp]# ls -l | grep mysql drwxr-xr-x 2 root root 4096 4月 29 21:11 mysql2 drwxr-xr-x 33 7161 wheel 4096 3月 15 03:07 mysql-5.6.17 -rw-r--r-- 1 easy oinstall 32862539 4月 23 20:52 mysql-5.6.17.tar.gz drwx------ 2 easy oinstall 4096 4月 27 22:43 mysql-workbench.easy [root@easy tmp]# cd mysql2 [root@easy mysql2]# cmake ../mysql-5.6.17
這樣我們便可以在不同的目錄下對源文件進行多次編譯,而相互不影響。
使用cmake,可以通過 -LAH來獲取所有的編譯選項
[root@easy mysql1]# cmake ../mysql-5.6.17 -LAH -- Running cmake version 2.6.4 -- MySQL 5.6.17 -- Packaging as: mysql-5.6.17-Linux-x86_64 -- HAVE_VISIBILITY_HIDDEN -- HAVE_VISIBILITY_HIDDEN -- HAVE_VISIBILITY_HIDDEN -- Using cmake version 2.6.4 -- Not building NDB -- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl -- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl;aio -- Configuring done -- Generating done -- Build files have been written to: /tmp/mysql1 -- Cache values // path to the executable ACLOCAL_EXECUTABLE:FILEPATH=/usr/bin/aclocal ..... // Missing description WITH_ZLIB:STRING=bundled 如果要清除編譯信息,可以使用如下命令:
[root@easy mysql1]# make clean [root@easy mysql1]# rm CMakeCache.txt rm:是否刪除普通文件 "CMakeCache.txt"?y
編譯選項:
部分選項使用來指定編譯過程中使用的可執行文件的路徑,如 ACLOCAL_EXECUTABLE:FILEPATH=/usr/bin/aclocal,大家可以自己研究,這裡不再獒述。
-DBUILD_CONFIG=mysql_release
使用該選項,可以促使編譯器按照oracle生成官方版本的選項來編譯程序,例子:
cmake -DBUILD_CONFIG=mysql_release ? -DCMAKE_BUILD_TYPE=type 該選項具有兩個選擇值 ? RelWithDebInfo: 默認值,啟用optimizations,同時生成調試信息 ? Debug: 禁用optimizations, 同時生成調試信息,與-DWITH_DEBUG=1 具有相同的效果 ? -DCPACK_MONOLITHIC_INSTALL=bool
該選項影響make package操作的行為,如果設置為真,生成單個文件,否則生成多個文件。默認是生成多個文件
The CMAKE_INSTALL_PREFIX option indicates the base installation directory. Other options with
names of the form INSTALL_xxx that indicate component locations are interpreted relative to the
prefix and their values are relative pathnames. Their values should not include the prefix.
?
-DCMAKE_INSTALL_PREFIX=dir_name
該選項指定了mysql的安裝目錄,除了在編譯時指定此值,我們也可月使用--basedir在mysql啟動時設置基准目錄。在編譯時,INSTALL_XXX格式的選項是相對於PREFIX的相對路徑,這是需要注意的一點
?
-DINSTALL_BINDIR=dir_name
bin文件的目錄
?
-DINSTALL_LAYOUT=name
使用何種已經預設好的文件布局,我們可以在這些的布局的基礎上,再手工設定某些目錄的位置
? STANDALONE: Same layout as used for .tar.gz and .zip packages. This is the default.
? RPM: Layout similar to RPM packages.
? SVR4: Solaris package layout.
? DEB: DEB package layout (experimental).
如下
shell> cmake . -DINSTALL_LAYOUT=SVR4 -DMYSQL_DATADIR=/var/mysql/data
?
-DINSTALL_MYSQLTESTDIR=dir_name
Where to install the mysql-test directory. As of MySQL 5.6.12, to suppress installation of this
directory, explicitly set the option to the empty value (-DINSTALL_MYSQLTESTDIR=).
?
-DINSTALL_SQLBENCHDIR=dir_name
Where to install the sql-bench directory. To suppress installation of this directory, explicitly set the
option to the empty value (-DINSTALL_SQLBENCHDIR=).
?
-DMYSQL_DATADIR=dir_name
指定數據文件的位置,也可以安裝後使用--datadir來設置
?
-DODBC_INCLUDES=dir_name
The location of the ODBC includes directory, and may be used while configuring Connector/ODBC.(配置odbc時可能會使用)
?
-DODBC_LIB_DIR=dir_name
The location of the ODBC library directory, and may be used while configuring Connector/ODBC.
?
-DSYSCONFDIR=dir_name
The default my.cnf option file directory. This location cannot be set at server startup, but you can start the server with a given option file using the --defaults-file=file_name option, where file_name is the full path name to the file.
在編譯mysql時,我們可以指定如何將存儲引擎編譯進mysql:靜態編譯和動態編譯。個人認為靜態編譯的服務器效率會高一些。
默認情況下MyISAM, MERGE, MEMORY, CSV 四種存儲引擎是必須的,並且會靜態編譯進服務器中。如果我們需要靜態編譯其他存儲引擎可以使用如下參數
-DWITH_engine_STORAGE_ENGINE=1
這裡的engine可以取值ARCHIVE, BLACKHOLE, EXAMPLE, FEDERATED, INNOBASE,NDB or NDBCLUSTER (NDB), PARTITION (partitioning support), and PERFSCHEMA(Performance Schema).
我們也可以顯示排除某種存儲引擎,如
-DWITHOUT_engine_STORAGE_ENGINE=1.
如果對於某種引擎即沒有顯示引入也沒有顯示排除,mysql會將該引擎編譯成共享模塊,如果無法編譯成共享模塊,則排除該引擎。
-DDEFAULT_CHARSET=charset_name
指定數據庫的默認字符集,字符集的取值可以在cmake/charset-sets.cmake下找到
-DDEFAULT_COLLATION=collation_name
指定數據庫的排序方式,可以在數據庫啟動時通過--collation_server選項來指定,通過show collation命令可以查看可選的排序方式
-DENABLE_DEBUG_SYNC=bool
用於開啟mysql的同步調試功能,默認情況下,該功能是開啟的,但是只有在mysql配置為啟用調試時才會生效。既是啟用了該功能,在運行時該功能亦是關閉的,需要使用--debug-sync-timeout=N 選項來啟動mysql服務器才可以,默認n為0,即該功能禁用,如果n大於0,在同步調試會等待n時間單位,否則會超時。
?
-DENABLE_DOWNLOADS=bool
用來下載一些可選文件,如google的測試分支等。
-DENABLE_DTRACE=bool
是否啟用dtrace
?
-DENABLE_GCOV=bool
Whether to include gcov support (Linux only).
?
-DENABLE_GPROF=bool
Whether to enable gprof (optimized Linux builds only). This option was added in MySQL 5.6.6.
?
-DENABLED_LOCAL_INFILE=bool
使mysql客戶端具有load data infile的功能,該功能具有安全隱患,
?
-DENABLED_PROFILING=bool
是否啟用PROFILING功能,建議開啟,用於性能監視
?
-DIGNORE_AIO_CHECK=bool
If the -DBUILD_CONFIG=mysql_release option is given on Linux, the libaio library must be
linked in by default. If you do not have libaio or do not want to install it, you can suppress the
check for it by specifying -DIGNORE_AIO_CHECK=1. This option was added in MySQL 5.6.1.
?
-DINNODB_PAGE_ATOMIC_REF_COUNT=bool
Whether to enable or disable atomic page reference counting. Fetching and releasing pages from the buffer pool and tracking the page state are expensive and complex operations. Using a page
mutex to track these operations does not scale well. With INNODB_PAGE_ATOMIC_REF_COUNT=ON (default), fetch and release is tracked using atomics where available. For platforms that do not
support atomics, set INNODB_PAGE_ATOMIC_REF_COUNT=OFF to disable atomic page reference counting.
When atomic page reference counting is enabled (default), “[Note] InnoDB: Using atomics
to ref count buffer pool pages” is printed to the error log at server startup. If atomic page reference counting is disabled, “[Note] InnoDB: Using mutexes to ref count buffer pool pages” is printed instead.
This build option was introduced with the fix for MySQL Bug #68079.
?
-DMYSQL_MAINTAINER_MODE=bool
Whether to enable a MySQL maintainer-specific development environment. If enabled, this option causes compiler warnings to become errors.
?
-DMYSQL_TCP_PORT=port_num
The port number on on which the server listens for TCP/IP connections. The default is 3306. This value can be set at server startup with the --port option.
-DMYSQL_UNIX_ADDR=file_name
The Unix socket file path on which the server listens for socket connections. This must be an absolute path name. The default is /tmp/mysql.sock.
This value can be set at server startup with the --socket option.
?
-DOPTIMIZER_TRACE=bool
Whether to support optimizer tracing. See MySQL Internals: Tracing the Optimizer. This option was added in MySQL 5.6.3.
?
-DWITH_ASAN=bool
Whether to enable AddressSanitizer, for compilers that support it. The default is off. This option was added in MySQL 5.6.15.
?
-DWITH_DEBUG=bool
Whether to include debugging support.
Configuring MySQL with debugging support enables you to use the --debug="d,parser_debug" option when you start the server. This causes the Bison parser that is used to process SQL statements to dump a parser trace to the server's standard error output. Typically, this output is written to the error log.
?
-DWITH_DEFAULT_FEATURE_SET=bool
Whether to use the flags from cmake/build_configurations/feature_set.cmake. This
option was added in MySQL 5.6.6.
?
-DWITH_EDITLINE=value
Which libedit/editline library to use. The permitted values are bundled (the default) and
system.
WITH_EDITLINE was added in MySQL 5.6.12. It replaces WITH_LIBEDIT, which has been
removed.
?
-DWITH_EMBEDDED_SERVER=bool
Whether to build the libmysqld embedded server library.
?
-DWITH_EXTRA_CHARSETS=name
Which extra character sets to include:
? all: All character sets. This is the default.
? complex: Complex character sets.
? none: No extra character sets.
?
-DWITH_INNODB_MEMCACHED=bool
Whether to generate memcached shared libraries (libmemcached.so and innodb_engine.so).
?
-DWITH_LIBEVENT=string
Which libevent library to use. Permitted values are bundled (default), system, and yes. If
you specify system or yes, the system libevent library is used if present. If the system library
is not found, the bundled libevent library is used. The libevent library is required by InnoDB
memcached.
-DWITH_LIBEDIT=bool
Whether to use the libedit library bundled with the distribution.
WITH_LIBEDIT was removed in MySQL 5.6.12. Use WITH_EDITLINE instead.
?
-DWITH_LIBWRAP=bool
Whether to include libwrap (TCP wrappers) support.
?
-DWITH_READLINE=bool
Whether to use the readline library bundled with the distribution. This option was removed in
MySQL 5.6.5 because readline is no longer bundled.
?
-DWITH_UNIXODBC=1
Enables unixODBC support, for Connector/ODBC.
?
-DWITH_ZLIB=zlib_type
Some features require that the server be built with compression library support, such as the
COMPRESS() and UNCOMPRESS() functions, and compression of the client/server protocol. The
WITH_ZLIB indicates the source of zlib support:
? bundled: Use the zlib library bundled with the distribution.
? system: Use the system zlib library. This is the default.
?
-DWITHOUT_SERVER=bool
Whether to build without the MySQL server. The default is OFF, which does build the server.
了解了各個選項的意義,下面就可以執行安裝了
# Preconfiguration setup shell> groupadd mysql shell> useradd -r -g mysql mysql # Beginning of source-build specific instructions shell> tar zxvf mysql-VERSION.tar.gz shell> cd mysql-VERSION shell> cmake . shell> make shell> make install # End of source-build specific instructions # Postinstallation setup shell> cd /usr/local/mysql shell> chown -R mysql . shell> chgrp -R mysql . shell> scripts/mysql_install_db --user=mysql shell> chown -R root . shell> chown -R mysql data shell> bin/mysqld_safe --user=mysql & # Next command is optional shell> cp support-files/mysql.server /etc/init.d/mysql.server