自从上一篇安装MySQL文章写了之后:CentOS 5下源码安装Mysql 5.5,好几年没碰MySQL了,现在因为新项目的需要,又要重新开始学习MySQL了。不过在这一次源码安装的过程中遇到一些小问题,写个笔记方便自己学习。这一次我安装的环境是Fedora 24,MySQL源码5.7.14。这一次安装和以前写的文章类似,这里不在重复,只是将遇到的几个问题记录一下。
[root@oracle mysql-5.7.14]# cmake -DCMAKE_INSTALL_PREFIX=/data/mysql/ \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_genral_ci \ > -DENABLED_LOCAL_INFILE=ON \ > -DWITH_INNOBASE_STORAGE_ENGINE=1 \ > -DWITHOUT_FEDERATED_STORAGE_ENGINE=1\ > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ > -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \ > -DWITH_PARTITION_STORAGE_ENGINE=1 \ > -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \ > -DCOMPILATION_COMMENT='Buddy MySQL' \ > -DSYSCONFDIR=/data/mysql \ > -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
首先这是我编译的一些参数,很有必要先了解一下这些参数的含义。有兴趣的可以参考官方文档:CMAKE,官方有一个表格,详细的列出了这些选项的含义。以下我就我这次编译的这些参数做解释,因为这些比较常用。
-DCMAKE_INSTALL_PREFIX 这个参数方便指向安装的路径,默认MySQL你不指定他就会给你安装到/usr/local/mysql目录下去。所以预先还是规划好,程序文件安装在那个目录.
-DDEFAULT_CHARSET 指定MySQL服务器的默认字符集,默认字符集是拉丁(latin1),这里我选择的是UTF-8,但是其实拉丁也不会乱码.
-DDEFAULT_COLLATION 指定MySQL服务器的默认校对规则,默认是(latin1_swedish_ci),这里我选择的是utf8_genral_ci.
-DENABLED_LOCAL_INFILE 是否允许从客户端本地加载数据到MySQL服务器端。这个主要用于LOAD DATA INFILE.
-DWITH_INNOBASE_STORAGE_ENGINE 编译InnoDB存储引擎.
-DWITHOUT_FEDERATED_STORAGE_ENGINE 编译FEDERATED存储引擎.
-DWITH_BLACKHOLE_STORAGE_ENGINE 编译BLACKHOLE存储引擎.
-DWITHOUT_EXAMPLE_STORAGE_ENGINE 不编译EXAMPLE存储引擎.
-DWITH_PARTITION_STORAGE_ENGINE 是否允许支持分区功能.
-DWITH_PERFSCHEMA_STORAGE_ENGINE 是否包含Performance Schema.
-DCOMPILATION_COMMENT 指定编译信息
-DSYSCONFDIR 指定MySQL参数文件的默认路径.
-DMYSQL_UNIX_ADDR 指定MySQL Socket文件的存放路径.
-DMYSQL_TCP_PORT 指定MySQL数据库提供的TCP/IP端口,默认为3306.
-DMYSQL_DATADIR 指定MySQL数据库文件的存储路径.
在编译过程中遇到的第一个错误如下:
-- Performing Test HAVE_LLVM_LIBCPP -- Performing Test HAVE_LLVM_LIBCPP - Failed -- Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH) CMake Error at cmake/readline.cmake:64 (MESSAGE): Curses library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel. Call Stack (most recent call first): cmake/readline.cmake:107 (FIND_CURSES) cmake/readline.cmake:197 (MYSQL_USE_BUNDLED_EDITLINE) CMakeLists.txt:483 (MYSQL_CHECK_EDITLINE) -- Configuring incomplete, errors occurred! See also "/home/oracle/下载/mysql-5.7.14/CMakeFiles/CMakeOutput.log". See also "/home/oracle/下载/mysql-5.7.14/CMakeFiles/CMakeError.log"
这个错误是由于没有安装ncurses-devel包导致的。
[root@oracle mysql-5.7.14]# yum install ncurses-devel
接下来遇到的问题如下:
-- Found ZLIB: zlib (found version "1.2.3") -- Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source. -- If you are inside a firewall, you may need to use an http proxy: export http_proxy=http://example.com:80 -- Performing Test HAVE_UNUSED_TYPEDEFS -- Performing Test HAVE_UNUSED_TYPEDEFS - Success CMake Warning at cmake/bison.cmake:20 (MESSAGE): Bison executable not found in PATH Call Stack (most recent call first): sql/CMakeLists.txt:528 (INCLUDE) CMake Warning at cmake/bison.cmake:20 (MESSAGE): Bison executable not found in PATH Call Stack (most recent call first): libmysqld/CMakeLists.txt:160 (INCLUDE) -- Library mysqlserver depends on OSLIBS -lpthread;m;rt;crypt;dl -- INSTALL mysqlclient.pc lib/pkgconfig -- Skipping deb packaging on unsupported platform . -- CMAKE_BUILD_TYPE: RelWithDebInfo -- COMPILE_DEFINITIONS: _GNU_SOURCE;_FILE_OFFSET_BITS=64;HAVE_CONFIG_H;HAVE_LIBEVENT1 -- CMAKE_C_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Wwrite-strings -Wdeclaration-after-statement -- CMAKE_CXX_FLAGS: -Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -- CMAKE_C_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -DDBUG_OFF -- CMAKE_CXX_FLAGS_RELWITHDEBINFO: -O3 -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing -std=gnu++03 -DDBUG_OFF -- Configuring done -- Generating done -- Build files have been written to: /home/oracle/下载/mysql-5.7.14
这个时候虽然编译成功了,但是上面有一个小错误,Googlemock was not found. gtest-based unit tests will be disabled. You can run cmake . -DENABLE_DOWNLOADS=1 to automatically download and build required components from source.这个意思是需要在编译的参数上加上DENABLE_DOWNLOADS=1,这样就会自动的下载Googlemock这个工具。下载完对这个工具做个编辑就行了。这是个做C++单元测试的工具。不过国内封杀了Google,在编译这个时候根本下载不下来,不过问题不大,可以使用Yum来安装。
[root@oracle source_downloads]# yum install gmock [root@oracle source_downloads]# make [root@oracle source_downloads]# make install
安装好了就可以开始初始化数据库了。在初始化数据库的时候需要下列问题:
[mysql@oracle mysqldata]$ mysqld --initialize --user=mysql --datadir=/data/mysqldata --basedir=/data/mysql 2016-09-08T12:48:17.691302Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-09-08T12:48:17.693168Z 0 [ERROR] Unknown collation: 'utf8_genral_ci' 2016-09-08T12:48:17.693245Z 0 [ERROR] Aborting
这个问题需要在参数文件中设置字符集为UTF-8,阿西吧,我们不是编译的选项设置了UTF-8吗?为什么还要在参数文件中在设置一遍呢。
[mysql@oracle mysqldata]$ more /data/my.cnf [mysqld] basedir=/data/mysql datadir=/data/mysqldata character_set_server=utf8 [mysql@oracle mysqldata]$ mysqld --defaults-file=/data/my.cnf --initialize --user=mysql 2016-09-08T12:52:10.616392Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-09-08T12:52:12.332400Z 0 [Warning] InnoDB: New log files created, LSN=45790 2016-09-08T12:52:12.778097Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-09-08T12:52:13.041590Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 101751eb-75c3-11e6-8891-1c6f65aafdbd. 2016-09-08T12:52:13.107937Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2016-09-08T12:52:13.109834Z 1 [Note] A temporary password is generated for root@localhost: Ie:e&lnZp3yd
这里初始化完成之后默认会给你一个root密码。接下来启动数据库修改默认root密码就好。
mysqld_safe --defaults-file=/data/my.cnf & [mysql@oracle ~]$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.14 Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'; Query OK, 0 rows affected (0.00 sec)