MySQL编译/安装/配置

MySQL-源码编译/安装/配置

本文基于MySQL8.0, MySQL 8.0源代码允许使用c++ 14的特性

编译

编译依赖

(1) 安装cmake
(2) SSL库: 
      链接:https://dev.mysql.com/doc/refman/8.0/en/source-ssl-library-configuration.html
      作用:支持加密连接、随机数生成的熵以及其他与加密相关的操作。
      CMake时使用WITH_SSL选项, 执行: cmake . -DWITH_SSL=system or cmake . -DWITH_SSL=path_name
      mysql server查看是否支持加密连接: SHOW VARIABLES LIKE 'have_ssl';
(3) Boost C++:  
      链接: https://dev.mysql.com/doc/refman/8.0/en/source-installation-prerequisites.html
      cmake . -DWITH_BOOST=/usr/local/boost_version_number
       版本获取: https://www.boost.org/
(4) ncurses library: 
      链接: https://invisible-island.net/ncurses/announce.html 登入终端设备(tty)
(5) bison 2.1 or higher
(6) Perl 
(7) libaio

Cmake编译

(1) MySQL二进制版本编译选项和配置: 
      链接: https://dev.mysql.com/doc/refman/8.0/en/source-installation.html
      查看:
      If you are interested in building MySQL from a source distribution using build options the same as or similar to
      those use by Oracle to produce binary distributions on your platform, obtain a binary distribution, unpack it, and
      look in the **docs/INFO_BIN** file, which contains information about how that MySQL distribution was configured
      and compiled.
(2) cmake编译选项: 
      链接:https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html
      对cmake有影响的环境变量:https://dev.mysql.com/doc/refman/8.0/en/environment-variables.html
      关于cmake编译: https://dev.mysql.com/doc/internals/en/cmake.html
      编译指令(以编译debug):https://dev.mysql.com/doc/internals/en/cmake-howto-quick-debug-configuration.html
        mkdir bld_debug
        cd bld_debug
        cmake .. -DCMAKE_BUILD_TYPE=Debug or cmake ..  -DWITH_DEBUG=1
        make
        make VERBOSE=1 : 要查看在编译阶段执行了哪些命令,请使用此命令
        make package : 创建二进制包
     编译选项查询指令:
        cmake . -LH : Short form plus description
        cmake . -LA : Long form (lists lots of options, including internal and advanced ones)
        cmake . -LAH
     CMakeCache.txt
        CMake将平台检查的结果缓存到CMakeCache.txt中
     cmake编译命令总结: 
        debug版本: cmake ..  -DCMAKE_BUILD_TYPE=Debug  -DWITH_BOOST=path_name
     cmake编译错误处理:
        make clean
        rm CMakeCache.txt

配置

(1) mysqld配置
    配置文件说明链接:https://dev.mysql.com/doc/refman/8.0/en/option-files.html
    配置文件: 在Unix和类Unix系统上,MySQL程序按照指定的顺序从下表所示的文件中读取启动选项(先列出的文件优先读取,后读取的文件优先)。
File NamePurpose
/etc/my.cnfGlobal options
/etc/mysql/my.cnfGlobal options
SYSCONFDIR/my.cnfGlobal options
$MYSQL_HOME/my.cnfServer-specific options (server only)
defaults-extra-fileThe file specified with --defaults-extra-file, if any
~/.my.cnfUser-specific options
~/.mylogin.cnfUser-specific login path options (clients only)
DATADIR/mysqld-auto.cnfSystem variables persisted with SET PERSIST or SE PERSIST_ONLY (server only)
(2) 配置文件语法
        语法适用于手动编辑的文件配置文件
        不适用: .mylogin.cnf,它是使用mysql_config_editor创建的,并且是加密的,以及mysqld-auto.cnf,它是由服务器以JSON格式创建的
        语法
            用于注释#comment, ;comment
            [group]: 组是要为其设置选项的程序或组的名称。在组行之后,任何选项设置行都应用于指定的组,直到给出配置文件结束或另一个组行。选项组名称不区分大小写。
            opt_nameThis is equivalent to --opt_name on the command line.
            opt_name=value这相当于命令行上的--opt_name=value;在配置文件中,可以在=字符周围使用空格。
 (3) 命令行与配置文件配置项
        Any long option that may be given on the command line when running a MySQL program can
        be given in an option file as well. To get the list of available options for a program, run it with the
        --help option. (For mysqld, use --verbose and --help.)
        当运行MySQL程序时,任何可能在命令行上给出的**长选项**也可以在选项文件中给出。要获取程序的可用选项列表,请使用--help选项运行它。(对于mysqld,使用--verbose和--help)配置文件中指定配置项的语法类似于命令行语法。但是,在选项文件中,您省略了选项名称的前两个破折号,并且每行只指定一个选项。
        命令行配置项: https://dev.mysql.com/doc/refman/8.0/en/command-line-options.html
 (4) 安装后的配置: https://dev.mysql.com/doc/refman/8.0/en/postinstallation.html
    在Unix和类Unix系统上从通用二进制和源代码发行版安装, 
    手动初始化数据目录.(https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html)
    数据目录初始化:
        创建mysql用户组和用户
            groupadd mysql
            useradd -r -g mysql -s /bin/false mysql : 因为用户只用于所有权目的,而不是登录目的,所以useradd命令使用-r和-s /bin/false选项来创建一个对服务器主机没有登录权限的用户。如果您的useradd不支持这些选项,则省略它们。
            数据目录初始化:(https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html#data-directory-initialization-procedure)
            bin/mysqld --initialize --user=mysql : 生成随机初始root密码   ----> 连接mysql服务器: mysql -u root -p
            bin/mysqld --initialize-insecure --user=mysql : 不会生成root密码 ----> 连接mysql服务器: mysql -u root --skip-password
            root密码重新设置: ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
    myqld启动
            bin/mysqld_safe --user=mysql &
    mysql系统表
           https://dev.mysql.com/doc/refman/8.0/en/system-schema.html

安装

默认安装路径: /usr/local/mysql
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值