**
环境准备
操作系统:CentOS
软件:MySQL-5.7.19
**
**
一、RPM 方式安装
进入官方网站:https://www.mysql.com
注册账号
downloads
选择MySQL Community Edition (GPL)>>Community (GPL) Downloads >>MySQL Community Server (GPL)>>download
操作系统:Red Hat Enterprise & Oracle Linux
操作系统版本:Redhat 64
**
1、上传Mysql rpm 包到Linux服务器并解压
2、创建Mysql用户和用户组
3、安装Mysql
发现出错了,有两个依赖包没有安装,因此需要安装此依赖包,依赖包的为libaio和numactl,安装即可
再次安装服务端:
说明:这里rpm如果不采用–nodeps必须将上面的四个包依次进行安装,否则会提示依赖解决。
只安装服务端,不安装通用包和libs包
4、启动Mysql并登录到Mysql数据库
说明:由于第一次启动Mysql,并且如果没有在/etc/my.cnf中添加参数skip-grant-tables参数的话,那么是无法登录到Mysql数据库的,这里有两种解决三种解决方法:
第一种,mysql初次初始化后,在/var/log/mysqld.log中提供了一个可以用于登录的临时密码,使用这个密码,可以登录到数据库,如上图
第二种,在/etc/my.cnf中添加skip-grant-tables参数,不过需要重新启动数据库才可以生效。
第三种,直接使用命令,/etc/init.d/mysqld –skip-grant-tables,然后重新打开一个窗口,如果不想重新打开一个窗口,那么在末尾添加一个
&
符号,让其在后台运行。
5、初次使用修改密码
说明:在以前的版本中,Mysql对于密码的修改,是在mysql库中的user表中有一列为password列,但是从msyql 5.7版本开始,Oracle对mysql搞了一点事情,它把原有的user表中的column password取消掉了,使用authentication_string来替代了,所以,现在如果使用update修改表user中的密码必须使用update user set authentication_string=password(‘your_password’) where user=’user_name’ and host=’servcie_host_ip’;而不是原来的update user set password了,所以在这里Oracle做了一些改动。并且,mysql从5.6开始,开始强化密码,要求密码中必须使用至少有一个大写字母和小写字母,数字和特殊字符,并且长度不能少于8位,这在windows图形界面安装下非常明显,但是在Linux下,我为了方便记忆,并没有遵守Mysql的约定,所以请引起注意。
**
二、二进制安装Mysql
**
进入官方网站:https://www.mysql.com
注册账号
downloads
选择MySQL Community Edition (GPL)>>Community (GPL) Downloads >>MySQL Community Server (GPL)>>download
操作系统:Linux_Generic
操作系统版本:Linux_generic x86_64
1、上传msyql二进制包致Linux服务器,并解压到/usr/local目录
2、创建Mysql用户和用户组
说明:-r 参数表示login -s 指定默认的shell
3、对/usr/local下的mysql解压包做软连接(相当于windows下的快捷方式)并授权
4、执行mysql_install_db脚本并指定用户
在这里有必要进行提前说明,在以前执行mysql_install_db都是在scripts目录下,但是从Mysql 5.7.5开是,Oracle又搞了一些事情,把scripts拿掉了,直接把mysql_install_db放在bin目录下了,并且从 mysqld –initialize这个脚本也是从5.7.6开始加上去的,现在的版本是5.7.19,说明这个脚本加入的时间并不是怎么长
注意,上面出错了,第一个只是warning,说明并没有错,只是在这里警告说这样执行mysql_install_db命令不是推荐的方式,给出的建议是使用mysqld –initialize 的方式
第二个的确是错误,说,必须要指定存放数据文件的目录
首先解决第一个警告
OK!没有问题,并且和 RPM一样,最后生成了一个临时密码,这个密码用来登陆Mysql,以便于对初始化的用户名的密码进行修改设置。
解决第二个错误,在这里依然使用mysql_install_db –user的方式,既然要求我们指定一个数据文件的目录,那么我们给指定一个不就行了。
OK!都是一些警告,这只是测试环境,并不是生产环境,在生产环境中,为了保证数据库宕机的可能性,一些参数必须要进行设置和指定,特别是性能和基准测试。
5、执行mysql_ssl_rsa_setup脚本进行进行密匙初始化
mysql_ssl_rsa_setup这个脚本也是从mysql 5.7.6以后加入的性特性,旨在增强安全加密连接
执行这个脚本后会生成采用RSA加密的三个文件,一个为客户端连接加密安全文件,一个为服务端连接加密安全文件,还有一个为CA认证文件
6、修改目录权限,并执行mysqld_safe脚本
可以在mysql_safe –user=msyql加一个
&
以便于在后台运行
7、拷贝配置文件并配置环境变量
8、执行自带的mysql_secure_installation命令强化安全脚本,这个脚本将会删除匿名用户
鉴于时间限制就不上传图片了
也可以进行手动删除
执行
- 1
- 2
- 1
- 2
**
三、源码安装
**
进入官方网站:https://www.mysql.com
注册账号
downloads
选择MySQL Community Edition (GPL)>>Community (GPL) Downloads >>MySQL Community Server (GPL)>>download
操作系统:Source Code
操作系统版本:Generic_Linux
1、老套路,将源码包上传之Linux服务器
说明:这里有两个包,在5.7以后,必须要有boost这个包
2、安装编译环境所需要的包和一些依赖包
点击(此处)折叠或打开
- [root@mysql ~]# yum install -y cmake make gcc gcc-c++ ncurses-devel
- 已加载插件:fastestmirror
- 设置安装进程
- Loading mirror speeds from cached hostfile
- 包 1:make-3.81-20.el6.x86_64 已安装并且是最新版本
- 解决依赖关系
- --> 执行事务检查
- ---> Package cmake.x86_64 0:2.8.12.2-4.el6 will be 安装
- --> 处理依赖关系 libarchive.so.2()(64bit),它被软件包 cmake-2.8.12.2-4.el6.x86_64 需要
- ---> Package gcc.x86_64 0:4.4.7-11.el6 will be 安装
- --> 处理依赖关系 libgomp = 4.4.7-11.el6,它被软件包 gcc-4.4.7-11.el6.x86_64 需要
- --> 处理依赖关系 cpp = 4.4.7-11.el6,它被软件包 gcc-4.4.7-11.el6.x86_64 需要
- --> 处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.4.7-11.el6.x86_64 需要
- --> 处理依赖关系 cloog-ppl >= 0.15,它被软件包 gcc-4.4.7-11.el6.x86_64 需要
- --> 处理依赖关系 libgomp.so.1()(64bit),它被软件包 gcc-4.4.7-11.el6.x86_64 需要
- ---> Package gcc-c++.x86_64 0:4.4.7-11.el6 will be 安装
- --> 处理依赖关系 libstdc++-devel = 4.4.7-11.el6,它被软件包 gcc-c++-4.4.7-11.el6.x86_64 需要
- --> 处理依赖关系 libmpfr.so.1()(64bit),它被软件包 gcc-c++-4.4.7-11.el6.x86_64 需要
- ---> Package ncurses-devel.x86_64 0:5.7-3.20090208.el6 will be 安装
- --> 执行事务检查
- ---> Package cloog-ppl.x86_64 0:0.15.7-1.2.el6 will be 安装
- --> 处理依赖关系 libppl_c.so.2()(64bit),它被软件包 cloog-ppl-0.15.7-1.2.el6.x86_64 需要
- --> 处理依赖关系 libppl.so.7()(64bit),它被软件包 cloog-ppl-0.15.7-1.2.el6.x86_64 需要
- ---> Package cpp.x86_64 0:4.4.7-11.el6 will be 安装
- ---> Package glibc-devel.x86_64 0:2.12-1.149.el6 will be 安装
- --> 处理依赖关系 glibc-headers = 2.12-1.149.el6,它被软件包 glibc-devel-2.12-1.149.el6.x86_64 需要
- --> 处理依赖关系 glibc-headers,它被软件包 glibc-devel-2.12-1.149.el6.x86_64 需要
- ---> Package libarchive.x86_64 0:2.8.3-4.el6_2 will be 安装
- ---> Package libgomp.x86_64 0:4.4.7-11.el6 will be 安装
- ---> Package libstdc++-devel.x86_64 0:4.4.7-11.el6 will be 安装
- ---> Package mpfr.x86_64 0:2.4.1-6.el6 will be 安装
- --> 执行事务检查
- ---> Package glibc-headers.x86_64 0:2.12-1.149.el6 will be 安装
- --> 处理依赖关系 kernel-headers >= 2.2.1,它被软件包 glibc-headers-2.12-1.149.el6.x86_64 需要
- --> 处理依赖关系 kernel-headers,它被软件包 glibc-headers-2.12-1.149.el6.x86_64 需要
- ---> Package ppl.x86_64 0:0.10.2-11.el6 will be 安装
- --> 执行事务检查
- ---> Package kernel-headers.x86_64 0:2.6.32-504.el6 will be 安装
- --> 完成依赖关系计算
- 依赖关系解决
- =========================================================================================================
- 软件包 架构 版本 仓库 大小
- =========================================================================================================
- 正在安装:
- cmake x86_64 2.8.12.2-4.el6 name 8.0 M
- gcc x86_64 4.4.7-11.el6 name 10 M
- gcc-c++ x86_64 4.4.7-11.el6 name 4.7 M
- ncurses-devel x86_64 5.7-3.20090208.el6 name 642 k
- 为依赖而安装:
- cloog-ppl x86_64 0.15.7-1.2.el6 name 93 k
- cpp x86_64 4.4.7-11.el6 name 3.7 M
- glibc-devel x86_64 2.12-1.149.el6 name 983 k
- glibc-headers x86_64 2.12-1.149.el6 name 611 k
- kernel-headers x86_64 2.6.32-504.el6 name 3.3 M
- libarchive x86_64 2.8.3-4.el6_2 name 126 k
- libgomp x86_64 4.4.7-11.el6 name 133 k
- libstdc++-devel x86_64 4.4.7-11.el6 name 1.6 M
- mpfr x86_64 2.4.1-6.el6 name 157 k
- ppl x86_64 0.10.2-11.el6 name 1.3 M
- 事务概要
- =========================================================================================================
- Install 14 Package(s)
- 总下载量:35 M
- Installed size: 89 M
- 下载软件包:
- ---------------------------------------------------------------------------------------------------------
- 总计 63 MB/s | 35 MB 00:00
- 运行 rpm_check_debug
- 执行事务测试
- 事务测试成功
- 执行事务
- 正在安装 : mpfr-2.4.1-6.el6.x86_64 1/14
- 正在安装 : cpp-4.4.7-11.el6.x86_64 2/14
- 正在安装 : kernel-headers-2.6.32-504.el6.x86_64 3/14
- 正在安装 : glibc-headers-2.12-1.149.el6.x86_64 4/14
- 正在安装 : glibc-devel-2.12-1.149.el6.x86_64 5/14
- 正在安装 : libstdc++-devel-4.4.7-11.el6.x86_64 6/14
- 正在安装 : libgomp-4.4.7-11.el6.x86_64 7/14
- 正在安装 : ppl-0.10.2-11.el6.x86_64 8/14
- 正在安装 : cloog-ppl-0.15.7-1.2.el6.x86_64 9/14
- 正在安装 : gcc-4.4.7-11.el6.x86_64 10/14
- 正在安装 : libarchive-2.8.3-4.el6_2.x86_64 11/14
- 正在安装 : cmake-2.8.12.2-4.el6.x86_64 12/14
- 正在安装 : gcc-c++-4.4.7-11.el6.x86_64 13/14
- 正在安装 : ncurses-devel-5.7-3.20090208.el6.x86_64 14/14
- Verifying : gcc-4.4.7-11.el6.x86_64 1/14
- Verifying : gcc-c++-4.4.7-11.el6.x86_64 2/14
- Verifying : libarchive-2.8.3-4.el6_2.x86_64 3/14
- Verifying : ppl-0.10.2-11.el6.x86_64 4/14
- Verifying : glibc-devel-2.12-1.149.el6.x86_64 5/14
- Verifying : mpfr-2.4.1-6.el6.x86_64 6/14
- Verifying : glibc-headers-2.12-1.149.el6.x86_64 7/14
- Verifying : libgomp-4.4.7-11.el6.x86_64 8/14
- Verifying : cmake-2.8.12.2-4.el6.x86_64 9/14
- Verifying : libstdc++-devel-4.4.7-11.el6.x86_64 10/14
- Verifying : cpp-4.4.7-11.el6.x86_64 11/14
- Verifying : kernel-headers-2.6.32-504.el6.x86_64 12/14
- Verifying : ncurses-devel-5.7-3.20090208.el6.x86_64 13/14
- Verifying : cloog-ppl-0.15.7-1.2.el6.x86_64 14/14
- 已安装:
- cmake.x86_64 0:2.8.12.2-4.el6 gcc.x86_64 0:4.4.7-11.el6 gcc-c++.x86_64 0:4.4.7-11.el6
- ncurses-devel.x86_64 0:5.7-3.20090208.el6
- 作为依赖被安装:
- cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.7-11.el6
- glibc-devel.x86_64 0:2.12-1.149.el6 glibc-headers.x86_64 0:2.12-1.149.el6
- kernel-headers.x86_64 0:2.6.32-504.el6 libarchive.x86_64 0:2.8.3-4.el6_2
- libgomp.x86_64 0:4.4.7-11.el6 libstdc++-devel.x86_64 0:4.4.7-11.el6
- mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6
- 完毕!
- [root@mysql ~]#
3、创建必要的目录,并授权
4、执行编译命令
点击(此处)折叠或打开
- [root@mysql mysql-5.7.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mysql/mysql_data/
- -- Running cmake version 2.8.12.2
- -- Could NOT find Git (missing: GIT_EXECUTABLE)
- -- Configuring with MAX_INDEXES = 64U
- -- The C compiler identification is GNU 4.4.7
- -- The CXX compiler identification is GNU 4.4.7
- -- Check for working C compiler: /usr/bin/cc
- -- Check for working C compiler: /usr/bin/cc -- works
- -- Detecting C compiler ABI info
- -- Detecting C compiler ABI info - done
- -- Check for working CXX compiler: /usr/bin/c++
- -- Check for working CXX compiler: /usr/bin/c++ -- works
- -- Detecting CXX compiler ABI info
- -- Detecting CXX compiler ABI info - done
- -- CMAKE_GENERATOR: Unix Makefiles
- -- Looking for SHM_HUGETLB
- -- Looking for SHM_HUGETLB - found
- -- Looking for sys/types.h
- -- Looking for sys/types.h - found
- -- Looking for stdint.h
- -- Looking for stdint.h - found
- -- Looking for stddef.h
- -- Looking for stddef.h - found
- -- Check size of void *
- -- Check size of void * - done
- -- SIZEOF_VOIDP 8
- -- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG
- -- Performing Test HAVE_C_SHIFT_OR_OPTIMIZATION_BUG - Failed
- -- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG
- -- Performing Test HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG - Failed
- -- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD
- -- Performing Test HAVE_C_FLOATING_POINT_FUSED_MADD - Failed
- -- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD
- -- Performing Test HAVE_CXX_FLOATING_POINT_FUSED_MADD - Failed
- -- Performing Test HAVE_C_FP_CONTRACT_FLAG
- -- Performing Test HAVE_C_FP_CONTRACT_FLAG - Failed
- -- Performing Test HAVE_CXX_FP_CONTRACT_FLAG
- -- Performing Test HAVE_CXX_FP_CONTRACT_FLAG - Failed
- -- MySQL 5.7.19
- -- Packaging as: mysql-5.7.19-Linux-x86_64
- -- Looked for boost/version.hpp in and
- -- BOOST_INCLUDE_DIR BOOST_INCLUDE_DIR-NOTFOUND
- -- LOCAL_BOOST_DIR
- -- LOCAL_BOOST_ZIP
- -- Could not find (the correct version of) boost.
- -- MySQL currently requires boost_1_59_0
- CMake Error at cmake/boost.cmake:81 (MESSAGE):
- You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
- This CMake script will look for boost in <directory>. If it is not there,
- it will download and unpack it (in that directory) for you.
- If you are inside a firewall, you may need to use an http proxy:
- export http_proxy=http://example.com:80
- Call Stack (most recent call first):
- cmake/boost.cmake:238 (COULD_NOT_FIND_BOOST)
- CMakeLists.txt:491 (INCLUDE)
- -- Configuring incomplete, errors
- See also "/root/mysql-5.7.19/CMakeFiles/CMakeOutput.log".
- See also "/root/mysql-5.7.19/CMakeFiles/CMakeError.log".
- [root@mysql mysql-5.7.19]#
执行结果中出现了
点击(此处)折叠或打开
- CMake Error at cmake/boost.cmake:81 (MESSAGE):
- You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>
- This CMake script will look for boost in <directory>. If it is not there,
- it will download and unpack it (in that directory) for you.**
并且给出了解决方法
点击(此处)折叠或打开
- [root@mysql mysql-5.7.19]# cmake -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/root/mysql-5.7.19/boost/boost_1_59_0/
- -- Running cmake version 2.8.12.2
- -- Could NOT find Git (missing: GIT_EXECUTABLE)
- -- Configuring with MAX_INDEXES = 64U
- -- CMAKE_GENERATOR: Unix Makefiles
- -- SIZEOF_VOIDP 8
- -- MySQL 5.7.19
- -- Packaging as: mysql-5.7.19-Linux-x86_64
- -- Local boost dir /root/mysql-5.7.19/boost/boost_1_59_0
- -- Found /root/mysql-5.7.19/boost/boost_1_59_0/boost/version.hpp
- -- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105900
- -- BOOST_INCLUDE_DIR /root/mysql-5.7.19/boost/boost_1_59_0
- -- Performing Test HAVE_LLVM_LIBCPP
- -- Performing Test HAVE_LLVM_LIBCPP - Failed
- 。。。。。。。。。。
- -- Looking for EVFILT_TIMER - not found
- -- Check if the system is big endian
- -- Searching 16 bit integer
- -- Check size of unsigned short
- -- Check size of unsigned short - done
- -- Using unsigned short
- --。。。。。。。。。。。。
- -- Performing Test HAVE_VISIBILITY_HIDDEN
- -- Performing Test HAVE_VISIBILITY_HIDDEN - Success
- -- Checking stack direction : -1
- -- Looking for include files time.h, sys/time.h
- -- Looking for include files time.h, sys/time.h - found
- --。。。。。。。。
- -- Searching 16 bit integer
- -- Using unsigned short
- -- Check if the system is big endian - little endian
- -- Found ZLIB: zlib (found version "1.2.3")
- -- Googletest 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 https proxy: export https_proxy=http://example.com:80
- -- Performing Test HAVE_MISLEADING_INDENTATION
- -- Performing Test HAVE_MISLEADING_INDENTATION - Failed
- CMake Warning at cmake/bison.cmake:20 (MESSAGE):
- Bison executable not found in PATH
- Call Stack (most recent call first):
- sql/CMakeLists.txt:548 (INCLUDE)
- CMake Warning at cmake/bison.cmake:20 (MESSAGE):
- Bison executable not found in PATH
- Call Stack (most recent call first):
- libmysqld/CMakeLists.txt:187 (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_LINK_FLAGS:
- -- CMAKE_CXX_LINK_FLAGS:
- -- 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 -DDBUG_OFF
- -- Configuring done
- -- Generating done
- -- Build files have been written to: /root/mysql-5.7.19
- [root@mysql mysql-5.7.19]#
OK!完成。重新执行上面的命令
点击(此处)折叠或打开
- [root@mysql mysql-5.7.19]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mysql/mysql_data/
- -- Running cmake version 2.8.12.2
- -- Could NOT find Git (missing: GIT_EXECUTABLE)
- -- Configuring with MAX_INDEXES = 64U
- -- CMAKE_GENERATOR: Unix Makefiles
- -- SIZEOF_VOIDP 8
- -- MySQL 5.7.19
- -- Packaging as: mysql-5.7.19-Linux-x86_64
- -- Local boost dir /root/mysql-5.7.19/boost/boost_1_59_0
- -- Found /root/mysql-5.7.19/boost/boost_1_59_0/boost/version.hpp
- -- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105900
- -- BOOST_INCLUDE_DIR /root/mysql-5.7.19/boost/boost_1_59_0
- -- NUMA library missing or required version not available
- -- WITH_PROTOBUF=bundled
- -- protobuf version is 2.6
- -- You need to set WITH_CURL. This variable needs to point to curl library.
- -- Using cmake version 2.8.12.2
- -- Disabling -Wunused-but-set-variable warning for building NDB
- -- Disabling -Wstrict-aliasing warning for building NDB
- -- Not building NDB
- -- Using Boost headers from /root/mysql-5.7.19/boost/boost_1_59_0
- -- MYSQLX - Text log of protobuf messages enabled
- -- Creating LDAP authentication SASL client library.
- -- Required SASL library is missing. Skipping the LDAP SASL client authentication plugin.
- -- Library mysqlclient depends on OSLIBS -lpthread;m;rt;dl
- -- Googletest 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 https proxy: export https_proxy=http://example.com:80
- CMake Warning at cmake/bison.cmake:20 (MESSAGE):
- Bison executable not found in PATH
- Call Stack (most recent call first):
- sql/CMakeLists.txt:548 (INCLUDE)
- CMake Warning at cmake/bison.cmake:20 (MESSAGE):
- Bison executable not found in PATH
- Call Stack (most recent call first):
- libmysqld/CMakeLists.txt:187 (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_LINK_FLAGS:
- -- CMAKE_CXX_LINK_FLAGS:
- -- 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 -DDBUG_OFF
- -- Configuring done
- -- Generating done
- -- Build files have been written to: /root/mysql-5.7.19
- [root@mysql mysql-5.7.19]#
完成!
5、编译安装
后续步骤一样,再不做说明,等的时间太长了,等不住了!
最后记:
在企业的生产环境中,追求的是稳定性,官方的二进制版本是经过了充分的验证的,虽然使用源码安装会带来性能方面的提升,但是编码复杂,如果不清楚编译的参数,依然推荐大家使用二进制的方式进行安装。
完成于2017 07 28
相比于传统行业,互联网浪潮中MySQL一直是数据库的主力军,无论是曾经的SUN,还是现在的Oracle,虽然可能商业策略不同,但发展方向还是平稳向前的,因此说自己不会MySQL,还真有些不好意思了。
我只能算是MySQL中的小小白,研究生毕设的时候,装过windows版本的MySQL,就像对Oracle一样,仅仅是用,但对于一门技术来说,没有深入理解运行的原理,就不算真正了解这门技术。又有一种说法,就是相似的技术是相通的,原理性质的知识,有些是可以复用学习和了解。
碰巧有一个旁支的项目,要用MySQL,借此机会逼着自己学习MySQL。为了学习MySQL,首先就要有一个MySQL的环境,第一步就是安装,这里说的安装,肯定不是Windows中“下一步”这种的安装。我们的环境是Linux 6.5,需要安装MySQL 5.7.19版本。
P.S. 以下只是我自己学习的体会,有不准确的地方,还请各位牛人指出来。
MySQL的安装主要有两种方式,一种就是利用源码,自行编译安装,这是开源相对于商业闭源软件,独特的风景线。另一种方式,就是使用二进制文件,又分为两种,一种是不针对特定平台,使用.tar.gz压缩文件来安装,一种是针对特定平台,使用.rpm文件安装。
官网中相应地有以上三种方式,对应的下载链接,其中源码安装,对应"Source Code",.tar.gz对应"Linux-Generic",.rpm则对应于"Red Hat Enterprise Linux/Oracle Linux",如下图所示,
这次我用rpm和源码,这两种方式进行安装。
1. rpm安装
首先需要选择对应平台,位数,下载完整版RPM Bundle,
解压缩安装包,
tar xvf mysql-5.7.19-1.el6.x86_64.rpm-bundle.tar
基本安装,只需要几个rpm包,但有顺序要求,
rpm -ivh mysql-community-common-5.7.19-1.el6.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el6.x86_64.rpm(依赖于common)
rpm -ivh mysql-community-client-5.7.19-1.el6.x86_64.rpm(依赖于libs)
rpm -ivh mysql-community-server-5.7.19-1.el6.x86_64.rpm(依赖于client、common)
安装完成后,会自动创建mysql用户和组,
[root@RAC2 rb]# id mysql
uid=27(mysql) gid=11002(mysql) groups=11002(mysql)
启动mysqld服务,记住不是mysql,默认3306端口打开,
[root@RAC2 mysql]# service mysqld start
Initializing MySQL database: test
[ OK ]
Starting mysqld: [ OK ]
[root@RAC2 mysql]# service mysqld status
mysqld (pid 30775) is running...
[root@DEPRAC2 mysql]# netstat -anp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 30775/mysqld
登录提示错误,
[root@RAC2 mysql]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
参考了周老师的书,这是因为MySQL5.7新版本中,调整了安全策略,默认情况下root不能没有密码,数据库启动的时候,会自动为root随机生成一个密码,从error日志中可以看见,注意这由于采用了默认安装,因此error日志默认路径是/var/log,/etc/my.cnf是默认的配置文件路径,
[root@RAC2 mysql]# cat /var/log/mysqld.log | more
2017-08-24T06:24:04.897029Z 1 [Note] A temporary password is generated for root@localhost: MDjfrXl;E9hp
临时强密码为“MDjfrXl;E9hp”。
再次登录,
[root@RAC2 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.19
Copyright (c) 2000, 2017, 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>
执行报错,提示需要改密码才能继续,
mysql> show variables like "%sock%";
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
一般的密码策略,会认为是不符合规范,
mysql> alter user 'root'@'localhost' identified by 'mysql';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by 'Mysql@admin';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> alter user 'root'@'localhost' identified by 'My@38@sql';
Query OK, 0 rows affected (0.01 sec)
此时,就可以执行任何指令了,
mysql> select user from mysql.user;
+---------------+
| user |
+---------------+
| mysql.session |
| mysql.sys |
| root |
+---------------+
至此,完成了rpm安装。
若需要卸载,可以不按顺序执行以下指令,
rpm -e mysql-community-common-5.7.19-1.el6.x86_64 --nodeps
rpm -e mysql-community-client-5.7.19-1.el6.x86_64 --nodeps
rpm -e mysql-community-server-5.7.19-1.el6.x86_64 --nodeps
rpm -e mysql-community-libs-5.7.19-1.el6.x86_64 --nodeps
此时,/etc/my.cnf配置文件、mysql用户和组,都会被删除。
2. 源码安装
整个过程,对于第一次接触的人来说,还是比较曲折,尤其是中间碰见了各种坑,需要一一化解。
Source Code中一种是针对版本的src.rpm包,一种是tar.gz包,前者包含的组件比较完整,我们下载这包,
由于这种安装,不会像rpm自动完成配置,因此需要先创建用户,
[root@RAC2 mysql-5.7.19]# groupadd mysql
[root@RAC2 mysql-5.7.19]# useradd -r -g mysql mysql
其中-r表示用户是系统用户,不可登录系统。
源码安装前,还需要装一些辅助包,
yum install cmake
yum install bison
yum install libaio-devel*
安装src.rpm,
[root@RAC2 src]# rpm -ivh mysql-community-5.7.19-1.el6.src.rpm
warning: mysql-community-5.7.19-1.el6.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
1:mysql-community ########################################### [100%]
一开始我不清楚,本地目录下,未看见有解压的文件夹,再看上面有warning,以为是因为有错,实际并非如此。
问题1:warning: mysql-community-5.7.19-1.el6.src.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
这个错误是因为yum安装了旧版本的GPG keys造成,有帖子做法是rpm跟着--force --nodeps参数,或者rpm --import /etc/pki/rpm-gpg/RPM*再来安装。
可实际操作后,发现错误依旧。
参考官方
https://dev.mysql.com/doc/refman/5.7/en/checking-gpg-signature.html
,拷贝以下内容,作为mysql_pubkey.asc,
执行gpg --import指令,
[root@RAC2 src]# gpg --import mysql_pubkey.asc
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 5072E1F5: public key "MySQL Release Engineering " imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: no ultimately trusted keys found
执行导出gpg --export
[root@RAC2 src]# gpg --export -a 5072e1f5 > 5072e1f5.asc
之所以这么做,官方解释是,
If you are using RPM 4.1 and it complains about (GPG) NOT OK (MISSING KEYS: GPG#5072e1f5), even though you have imported the MySQL public build key into your own GPG keyring, you need to import the key into the RPM keyring first. RPM 4.1 no longer uses your personal GPG keyring (or GPG itself). Rather, RPM maintains a separate keyring because it is a system-wide application and a user's GPG public keyring is a user-specific file. To import the MySQL public key into the RPM keyring, first obtain the key, then use rpm --import to import the key.
RPM包有内置的GPG签名和MD5校验,用户和系统层级范围的问题,需要手工export、import操作。
如果之前未导入pubkey,则此时执行export会报错,没有需要导出的信息,
[root@RAC2 src]# gpg --export -a 5072e1f5 > 5072e1f5.asc
gpg: WARNING: nothing exported
执行导入,
[root@RAC2 src]# rpm --import 5072e1f5.asc
如果之前未导入pubkey,则此时执行import会报错,没有需要导入的信息,
[root@RAC2 src]# rpm --import 5072e1f5.asc
error: 5072e1f5.asc: import read failed(0).
此时执行,不会报错了,
[root@RAC2 src]# rpm --checksig mysql-community-5.7.19-1.el6.src.rpm
mysql-community-5.7.19-1.el6.src.rpm: (sha1) dsa sha1 md5 gpg OK
[root@RAC2 src]# rpm -ivh mysql-community-5.7.19-1.el6.src.rpm
1:mysql-community ########################################### [100%]
问题2:rpm ...src.rpm,到底安装在哪了?
实际存储在用户家目录中,此处使用root,则为/root目录,文件夹结构为,
rpmbuild
| SOURCE
| SPECS
SOURCE路径内容为,
[root@RAC2 SOURCES]# ls
boost_1_59_0.tar.bz2 filter-provides.sh filter-requires.sh mysql-5.1.72.tar.gz mysql-5.7.19.tar.gz
解压mysql-5.7.19.tar.gz,执行jar -jxvf boost_1_59_0.tar.bz2解压文件,放置mysql-5.7.19路径下,创建debug文件夹,用于存储安装的中间文件,
接下来就要出现各种坑了。
参考周老师的书,通过CMake生成编译环境。
[root@RAC2 debug]# cmake .. -DBUILD_CONFIG=mysql_release \
> -DINSTALL_LAYOUT=STANDLONE \
> -DCMAKE_BUILD_TYPE=RelWithDebInfo \
> -DENABLE_DTRACE=OFF \
> -DWITH_EMBEDDED_SERVER=OFF \
> -DWITH_INNODB_MEMCACHED=ON \
> -DWITH_SSL=bundled \
> -DWITH_ZLIB=system \
> -DWITH_PAM=ON \
> -DCMAKE_INSTALL_PREFIX=/var/mysql \
> -DINSTALL_PLUGINDIR="/var/mysql/lib/plugin" \
> -DDEFAULT_CHARSET=utf-8 \
> -DDEFAULT_COLLATION=utf8_general_ci \
> -DWITH_EDITLINE=bundled \
> -DFEATURE_SET=community \
> -DCOMPILATION_COMMENT="MySQL Server(GPL)" \
> -DWITH_DEBUG=OFF \
> -DWITH_BOOST=..
CMake Error at CMakeLists.txt:21 (CMAKE_MINIMUM_REQUIRED):
CMake 2.8.2 or higher is required. You are running version 2.6.4
提示错误,CMake版本需要2.8.2以上,当前仅为2.6.4。
下载高版本cmake,http://www.cmake.org/cmake/resources/software.html,解压缩cmake-2.8.12.2.tar.gz,依次执行,
./bootstrap
make
make install
报了一些错误,
[root@RAC2 cmake-2.8.12.2]# ./bootstrap
---------------------------------------------
CMake 2.8.12.2, Copyright 2000-2012 Kitware, Inc.
---------------------------------------------
Error when bootstrapping CMake:
Cannot find appropriate C compiler on this system.
Please specify one using environment variable CC.
See cmake_bootstrap.log for compilers attempted.
---------------------------------------------
Log of errors: /root/cmake-2.8.12.2/Bootstrap.cmk/cmake_bootstrap.log
---------------------------------------------
提示需要cc的编译环境,咱就安装,
[root@RAC2 cmake-2.8.12.2]# yum install gcc gcc-c++ make automake
执行完成,
[root@RAC2 cmake-2.8.12.2]# ./bootstrap
...
Curses libraries were not found. Curses GUI for CMake will not be built.
-- Looking for elf.h
-- Looking for elf.h - found
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - NOTFOUND
-- Found unsuitable Qt version "" from NOTFOUND
-- Performing Test run_pic_test
-- Performing Test run_pic_test - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /root/cmake-2.8.12.2
---------------------------------------------
CMake has bootstrapped. Now run gmake.
再执行指令make和make install,此时可以看出,已经升级为最新版本了,
[root@DEPRAC2 cmake-2.8.12.2]# ls -l /usr/local/bin/cmake
-rwxr-xr-x 1 root root 10204177 Aug 24 16:51 /usr/local/bin/cmake
[root@DEPRAC2 mysql-5.7.19]# /usr/local/bin/cmake -version
cmake version 2.8.12.2
再次执行上述cmake,又出现了几个错误,一个是STANDLONE拼错了,应该是STANDALONE,
-- Packaging as: mysql-5.7.19-Linux-x86_64
CMake Error at cmake/install_layout.cmake:107 (MESSAGE):
Invalid INSTALL_LAYOUT parameter:STANDLONE. Choose between
RPM;DEB;SVR4;FREEBSD;GLIBC;OSX;TARGZ;SLES;STANDALONE
Call Stack (most recent call first):
CMakeLists.txt:213 (INCLUDE)
一个是字符集utf-8,应该写为utf8(这个错误是安装完成后,初始化数据库时才报的),需要改正,重新执行cmake指令。
另一个是,
-- 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:519 (MYSQL_CHECK_EDITLINE)
删除原始CMakeCache.txt,安装ncurses-devel,
mv CMakeCache.txt CMakeCache.txt.k
yum install ncurses-devel*
再次执行,出现Configuring done和Generating done,安装完成,
-- 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 -DDBUG_OFF
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
WITH_PAM
-- Build files have been written to: /root/rpmbuild/SOURCES/mysql-5.7.19/debug
接下来执行make -j 30,启动30个线程,进行编译,否则编译慢,-j含义,
-j [jobs], --jobs[=jobs]
Specifies the number of jobs (commands) to run simultaneously. If there is more than one -j option, the last one is effective. If the -j option is given without an argument, make will not limit the number of jobs that can run simultaneously.
碰见了另一个坑,就是磁盘空间满了,
Linking CXX static library libsql.a
/usr/bin/ar: libsql.a: No space left on device
make[2]: *** [sql/libsql.a] Error 1
make[1]: *** [sql/CMakeFiles/sql.dir/all] Error 2
因为默认放在了/root下,将其mv至空闲磁盘中,再次执行,提示100%完成,
[100%] Building CXX object sql/CMakeFiles/udf_example.dir/udf_example.cc.o
Linking CXX shared module udf_example.so
[100%] Built target udf_example
[100%] Built target pfs_connect_attr-t
执行make install,
-- Installing: /var/mysql/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /var/mysql/support-files/mysqld_multi.server
-- Installing: /var/mysql/support-files/mysql-log-rotate
-- Installing: /var/mysql/support-files/magic
-- Installing: /var/mysql/share/aclocal/mysql.m4
-- Installing: /var/mysql/support-files/mysql.server
数据库默认安装于/var/mysql,
编辑配置文件my.cnf,
[mysqld]
port=3306
datadir=/DATA/mysql/data_3306
log_error=/DATA/mysql/data_3306/error.log
basedir=/DATA/mysql
创建数据库,指定使用mysql用户,
[root@RAC2 mysql]# /var/mysql/bin/mysqld --defaults-file=/DATA/mysql/my.cnf --initialize --user=mysql
此时可以看出,/DATA/mysql/data_3306目录属主是mysql,
启动数据库,注意不是用mysqld,而是mysql,
[root@RAC2 mysql]# /var/mysql/bin/mysql --defaults-file=/DATA/mysql/my.cnf --user=mysql
查看进程、端口,
[root@RAC2 data_3306]# ps -ef | grep mysql
mysql 26428 23453 0 18:56 pts/2 00:00:00 /var/mysql/bin/mysqld --defaults-file=/DATA/mysql/my.cnf --user=mysql
root 26527 29090 0 19:08 pts/1 00:00:00 grep mysql
[root@DEPRAC2 data_3306]# netstat -anp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 26428/mysqld
接下来和rpm安装相同,从error日志中找出临时密码,登录改密码,完成数据库初始化工作。注意此时error日志,存储于配置文件定义的log_error=/DATA/mysql/data_3306/error.log了。
总结:
1. rpm方式的安装,类似于Windows下安装,确实比较简单,容易上手。
2. 源码安装,过程比较繁琐,而且碰见不少坑,但这种方式,可以接触更多,学到不少东西,还是值得推荐。
当然,我这儿只是学了些皮毛,MySQL还是比较精深,需要学习的地方还有不少,一步一步来吧,有可能机会就在眼前了。
参考文献:
1. 《MySQL运维内参》
2. 《MySQL官方参考》
https://dev.mysql.com/doc/refman/5.7/en/checking-rpm-signature.html
https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
https://dev.mysql.com/doc/refman/5.7/en/installing-source-distribution.html
进入/usr/local/src
cd /usr/local/src
2.下载mysql 5.7.10
wget http://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.11.tar.gz
3.安装组件 cmake必须安装
yum -y install gcc-c++ ncurses-devel cmake make perl
yum -y gcc autoconf automake zlib libxml libgcrypt libtool bison
yum -y install gcc gcc-c++ gcc-g77 autoconf automake
yum -y zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake
4.添加用户
groupadd mysql
useradd -r -g mysql mysql
mysql安装的位置:
mkdir /usr/local/mysql
mysql data安装的位置:
mkdir /data/mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
chmod 777 /usr/local/mysql
chmod 777 /data/mysql
5.解压mysql安装包
cd /usr/local/src/
tar -zxvf mysql-5.7.11.tar.gz
cd mysql-5.7.11
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_USER=mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=./boost/
由于我们下载的是mysql带boost包的,因此解压后,boost目录就在mysql解压
包下,路径为./boost/ 注意,boost后的“/” 必须要添加。
由于我下载的是自带boost的mysql,所以只要制定路径就可以了。
参数详解:
常用参数:
CMAKE_INSTALL_PREFIX:指定MySQL程序的安装目录,默认/usr/local/mysql
DEFAULT_CHARSET:指定服务器默认字符集,默认latin1
DEFAULT_COLLATION:指定服务器默认的校对规则,默认latin1_general_ci
ENABLED_LOCAL_INFILE:指定是否允许本地执行LOAD DATA INFILE,默认OFF
WITH_COMMENT:指定编译备注信息
WITH_xxx_STORAGE_ENGINE:指定静态编译到mysql的存储引擎,MyISAM,MERGE,MEMBER
以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
SYSCONFDIR:初始化参数文件目录
MYSQL_DATADIR:数据文件目录
MYSQL_TCP_PORT:服务端口号,默认3306
MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock
------------------------------------------------------------------------------------------
网友的编译参数
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ [MySQL安装的根目录]
-DMYSQL_DATADIR=/mydata/mysql/data \ [MySQL数据库文件存放目录]
-DSYSCONFDIR=/etc \ [MySQL配置文件所在目录]
-DMYSQL_USER=mysql \ [MySQL用户名]
-DWITH_MYISAM_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_MEMORY_STORAGE_ENGINE=1 \ [MySQL的数据库引擎]
-DWITH_READLINE=1 \ [MySQL的readline library]
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \ [MySQL的通讯目录]
-DMYSQL_TCP_PORT=3306 \ [MySQL的监听端口]
-DENABLED_LOCAL_INFILE=1 \ [启用加载本地数据]
-DENABLE_DOWNLOADS=1 \ [编译时允许自主下载相关文件]
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \ [使MySQL支持所有的扩展字符]
-DDEFAULT_CHARSET=utf8 \ [设置默认字符集为utf8]
-DDEFAULT_COLLATION=utf8_general_ci \ [设置默认字符校对]
-DWITH_DEBUG=0 \ [禁用调试模式]
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \ [通讯时支持ssl协议]
-DWITH_ZLIB:STRING=bundled [允许使用zlib library]
-------------------------------------------------------------------------------------------
make && make install
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_USER=mysql \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/run/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 \
-DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled \
-DWITH_ZLIB:STRING=bundled \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=./boost/
3.初始化mysql
记住一定要先把权限给mysql用户,否则初始化会报错。
chown -R mysql:mysql /data
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql/bin
./mysqld --initialize --datadir=/data/mysql --basedir=/usr/local/mysql/ --user=mysql
2016-03-06T05:31:01.664510Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp
server option (see documentation for more details).
2016-03-06T05:31:05.188724Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-03-06T05:31:05.571415Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-03-06T05:31:05.689390Z 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: 9f7c61ff-e35c-11e5-9957-000c29d5b9a9.
2016-03-06T05:31:05.698274Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
此行为初始密码:
2016-03-06T05:31:05.700736Z 1 [Note] A temporary password is generated for root@localhost: Zi?gw66wnIgs
此行为初始密码:
2016-03-06T05:31:05.700736Z 1 [Note] A temporary password is generated for root@localhost: Zi?gw66wnIgs
4.拷贝标准启动脚本和配置文件
cd /usr/local/src/mysql-boost-5
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# mv /etc/my.cnf /etc/my.cnf.old
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql]#chmod 755 /etc/init.d/mysqld
5.配置启动脚本和配置文件
[root@localhost mysql]# vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
mysqld_pid_file_path=/usr/local/mysql/mysql.pid
[root@localhost mysql]# vim /etc/my.cnf
basedir=/usr/local/mysql
datadir=/data/mysql
6.设置mysql服务开机启动并启动mysql
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on
[root@localhost mysql]# service mysqld start
Starting MySQL.. SUCCESS!
7.设置环境变量
vim /etc/profile
最后添加一行:
export PATH=$PATH:/usr/local/mysql/bin
保存退出
然后:
source /etc/profile
8.初始化mysql密码
mysql -uroot -p
set password=password('yourpassword');
alter user 'root'@'localhost' password expire never;
flush privileges;
About Me
.............................................................................................................................................
● 本文整理自网络
● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、博客园(http://www.cnblogs.com/lhrbest)和个人微信公众号(xiaomaimiaolhr)上有同步更新
● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/
● 本文博客园地址:http://www.cnblogs.com/lhrbest
● 本文pdf版、个人简介及小麦苗云盘地址:http://blog.itpub.net/26736162/viewspace-1624453/
● 数据库笔试面试题库及解答:http://blog.itpub.net/26736162/viewspace-2134706/
● DBA宝典今日头条号地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826
.............................................................................................................................................
● QQ群号:230161599(满)、618766405
● 微信群:可加我微信,我拉大家进群,非诚勿扰
● 联系我请加QQ好友(646634621),注明添加缘由
● 于 2017-08-01 09:00 ~ 2017-08-31 22:00 在魔都完成
● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解
● 版权所有,欢迎分享本文,转载请保留出处
.............................................................................................................................................
● 小麦苗的微店:https://weidian.com/s/793741433?wfr=c&ifr=shopdetail
● 小麦苗出版的数据库类丛书:http://blog.itpub.net/26736162/viewspace-2142121/
.............................................................................................................................................
使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(xiaomaimiaolhr)及QQ群(DBA宝典),学习最实用的数据库技术。
小麦苗的微信公众号 小麦苗的DBA宝典QQ群1 小麦苗的DBA宝典QQ群2 小麦苗的微店
.............................................................................................................................................