zoukankan      html  css  js  c++  java
  • LAMP之Mysql源码配置安装

    MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品。MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Database Management System,关系数据库管理系统) 应用软件。
    MySQL是一种关系数据库管理系统,关系数据库将数据保存在不同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。
    MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。
    由于其社区版的性能卓越,搭配 PHP 和 Apache 可组成良好的开发环境
    https://dev.mysql.com/doc/refman/5.7/en/source-installation.html  #mysql官网,源码安装Mysql,依靠Cmake

     下载安装Cmake

    [root@localhost1 cmake-3.9.6]# wget https://cmake.org/files/v3.9/cmake-3.9.6.tar.gz
    [root@localhost1 cmake-3.9.6]# tar zxf cmake-3.9.6.tar.gz 
    [root@localhost1 cmake-3.9.6]# cd cmake-3.9.6
    [root@localhost1 cmake-3.9.6]# ./configure 
    [root@localhost1 cmake-3.9.6]# gmake
    [root@localhost1 cmake-3.9.6]# gmake install

    [root@localhost1 cmake-3.9.6]# which gmake
    /usr/bin/gmake

    安装Mysql之前必须要安装的组件

    检查系统中是否有mysql,卸载掉:
    yum
    -y install gcc* libaio* ncurses-devel groupadd mysql useradd mysql -s /sbin/nologin -M -g mysql mkdir -p /opt/mysql5.7.21/{data/,tmp/}
    如果mysql没有正确安装,要在初始化时指定路径
    https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html  Mysql官网编译参数详解
    -DCMAKE_INSTALL_PREFIX=dir_name
    安装基础目录。
    该值可以在服务器启动时使用该--basedir选项进行设置 。
    
    -DMYSQL_DATADIR=dir_name
    MySQL数据目录的位置。
    该值可以在服务器启动时使用该--datadir选项进行设置 。
    
    -DMYSQL_UNIX_ADDR=file_name
    服务器侦听套接字连接的Unix套接字文件路径。这必须是绝对路径名称。默认是/tmp/mysql.sock。
    该值可以在服务器启动时使用该--socket选项进行设置 。
    
    -DDEFAULT_CHARSET=charset_name
    服务器字符集。默认情况下,MySQL使用 latin1(cp1252西欧)字符集。
    charset_name可以是一种 binary,armscii8, ascii,big5, cp1250,cp1251, cp1256,cp1257, cp850,cp852, cp866,cp932, dec8,eucjpms, euckr,gb2312, gbk,geostd8, greek,hebrew, hp8,keybcs2, koi8r,koi8u, latin1,latin2, latin5,latin7, macce,macroman, sjis,swe7, tis620,ucs2, ujis,utf8, utf8mb4,utf16, utf16le,utf32。允许的字符集在cmake/character_sets.cmake文件中被列为 值CHARSETS_AVAILABLE。
    该值可以在服务器启动时使用该--character_set_server选项进行设置 。
    
    -DDEFAULT_COLLATION=collation_name
    服务器整理。默认情况下,MySQL使用 latin1_swedish_ci。使用该 SHOW COLLATION语句来确定每个字符集可用的排序规则。
    该值可以在服务器启动时使用该--collation_server选项进行设置 。

    cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.7.21 -DMYSQL_DATADIR=/opt/mysql-5.7.21/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/opt/mysql-5.7.21/tmp/mysql.sock -DWITH_BOOST=/opt/boost这个参数是必须的 -DWITH_DEBUG=1#上面没写

    /etc/my.cnf配置:

    [root@localhost init.d]# cat /etc/my.cnf
    # Example MySQL config file for small systems.
    #
    # This is for a system with little memory (<= 64M) where MySQL is only used
    # from time to time and it's important that the mysqld daemon
    # doesn't use much resources.
    #
    # MySQL programs look for option files in a set of
    # locations which depend on the deployment platform.
    # You can copy this option file to one of those
    # locations. For information about these locations, see
    # http://dev.mysql.com/doc/mysql/en/option-files.html
    #
    # In this file, you can use all long options that a program supports.
    # If you want to know which options a program supports, run the program
    # with the "--help" option.
    # The following options will be passed to all MySQL clients
    #配置指令传递给与 MYSQL 服务器相关的客户端
    [client]#客户端
    #password = your_password #密码
    port = 3306 #服务的端口,如果需要修改,在确保所有配置文件中都修改
    socket = /application/mysql-5.1.72/tmp/mysql.sock #套接字文件的路径
    # Here follows entries for some specific programs
    # The MySQL server #MYSQL 服务器
    [mysqld] #启动命令脚本文件
    port = 3306 #端口
    socket = /application/mysql-5.1.72/tmp/mysql.sock #套接字文件的路径
    skip-locking
    key_buffer_size = 16K #索引块的缓冲区大小
    max_allowed_packet = 1M #服务能请求包的最大大小为 1M
    table_open_cache = 4 #所有线程所打开表的数量
    sort_buffer_size = 64K #排序使用的缓冲区大小
    read_buffer_size = 256K #读查询操作使用的缓冲区大小
    read_rnd_buffer_size = 256K #随机读取缓冲区的大小
    net_buffer_length = 2K #
    thread_stack = 128K
    # Don't listen on a TCP/IP port at all. This can be a security enhancement,
    # if all processes that need to connect to mysqld run on the same host.
    # All interaction with mysqld must be made via Unix sockets or named pipes.
    # Note that using this option without enabling named pipes on Windows
    # (using the "enable-named-pipe" option) will render mysqld useless!
    #
    #skip-networking
    server-id = 1 #本机的序号, master 进程
    # Uncomment the following if you want to log updates
    #log-bin=mysql-bin
    # binary logging format - mixed recommended
    #binlog_format=mixed
    # Uncomment the following if you are using InnoDB tables
    #innodb_data_home_dir = /application/mysql-5.1.72/data
    #innodb_data_file_path = ibdata1:10M:autoextend
    #innodb_log_group_home_dir = /application/mysql-5.1.72/data
    # You can set .._buffer_pool_size up to 50 - 80 %
    # of RAM but beware of setting memory usage too high
    #innodb_buffer_pool_size = 16M #INnodb 缓冲池的大小
    #innodb_additional_mem_pool_size = 2M
    # Set .._log_file_size to 25 % of buffer pool size
    #innodb_log_file_size = 5M #INnodb 日志文件大小
    #innodb_log_buffer_size = 8M #INnodb 日志缓冲区大小
    #innodb_flush_log_at_trx_commit = 1
    #innodb_lock_wait_timeout = 50 #INnodb 事务锁定前的超时时间
    [mysqldump]
    quick
    max_allowed_packet = 16M #服务器发送与接收的包的最大大小
    [mysql]
    no-auto-rehash
    # Remove the next comment character if you are not familiar with SQL
    #safe-updates
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    [mysqlhotcopy]
    interactive-timeout #服务器关闭连接前等待活动的时间

    错误总结:

    MySQL5.7.17在cmake的时候报错如下:
    
    点击(此处)折叠或打开
    
    CMake Error at cmake/boost.cmake:81 (MESSAGE):
    You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=
    This CMake script will look for boost in . 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:455 (INCLUDE)
    -- Configuring incomplete, errors occurred!
    See also "/root/mysqlsoftware/mysql-5.7.17/CMakeFiles/CMakeOutput.log".
    See also "/root/mysqlsoftware/mysql-5.7.17/CMakeFiles/CMakeError.log".
    解决办法是:
    1.在/usr/local下创建一个名为boost的文件夹
        mkdir -p /usr/local/boost
    2.进入这个新创建的文件夹然后下载boost
        wget http://www.sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
    3.解压
        tar -xvzf boost_1_59_0.tar.gz
    4.继续cmake,添加上红色部分
    
    cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 
    -DDEFAULT_CHARSET=utf8 
    -DDEFAULT_COLLATION=utf8_general_ci 
    -DENABLED_LOCAL_INFILE=ON 
    -DWITH_INNOBASE_STORAGE_ENGINE=1 
    -DWITH_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='Mysqlma' 
    -DWITH_READLINE=ON 
    -DWITH_BOOST=/usr/local/boost 
    -DSYSCONFDIR=/data/mysqldata/3306 
    -DMYSQL_UNIX_ADDR=/data/mysqldata/3306/mysql.sock
    -DWITH_BOOST=path_name
    
    Boost库是构建MySQL所必需的。这些 CMake选项可以控制库源位置,以及是否自动下载它:
    
    -DWITH_BOOST=path_name 指定Boost库目录位置。也可以通过设置BOOST_ROOT或 WITH_BOOST环境变量来指定Boost位置 。
    
    从MySQL 5.7.11开始,它 -DWITH_BOOST=system是允许的,并且表示在标准位置的编译主机上安装了正确版本的Boost。在这种情况下,使用的是Boost的安装版本,而不是MySQL源代码发行版中包含的任何版本。
    
    -DDOWNLOAD_BOOST=bool 指定是否在指定位置不存在的情况下下载Boost源。默认是 OFF。
    
    -DDOWNLOAD_BOOST_TIMEOUT=seconds 下载Boost库的超时时间(秒)。默认值是600秒。
    
    例如,如果您通常构建MySQL,将对象输出放置在bldMySQL源代码树的子目录中,则可以使用Boost构建,如下所示:
    
    mkdir bld
    cd bld
    cmake .. -DDOWNLOAD_BOOST=ON -DWITH_BOOST=$HOME/my_boost
    这会导致Boost被下载到 my_boost您的主目录下的目录中。如果所需的Boost版本已经存在,则不进行下载。如果所需的Boost版本更改,则会下载较新的版本。
    
    如果Boost已经在本地安装,并且编译器自己找到Boost头文件,则可能不需要指定前面的CMake选项。但是,如果MySQL所需的Boost版本发生更改并且本地安装的版本尚未升级,则可能会出现构建问题。使用CMake 选项应该给你一个成功的构建。
    
    通过上述允许将Boost下载到指定位置的设置,当所需的Boost版本发生更改时,您需要删除该bld文件夹并重新创建该文件夹,然后再次执行cmake步骤。否则,新的Boost版本可能无法下载,编译可能会失败。
    http://blog.csdn.net/cryhelyxx/article/details/47610247    问题的解决
    bin/mysqld --initialize --user=mysql  初始化mysql。指定用户   --initialize会自动生成密码    
    cp /opt/mysql-5.7.21/support-files/mysql.server /etc/init.d/mysqld
    /etc/init.d/mysqld start
    echo 'export PATH=/application/mysql/bin:$PATH'>>/etc/profile
    在不知道mysql root密码的情况下修改密码
    [root@cairui mysql]# bin/mysqld_safe --skip-grant-tables & 
    在mysql中输入一下命令
    update mysql.user set authentication_string=password('root') where user='root' ;
    加入开机启动
    [root@cairui ~]# chkconfig mysqld on    
    http://www.bubuko.com/infodetail-2167283.html  不需要/etc/my.cnf的解释

    You must SET PASSWORD before executing this statement的解决方法

    http://www.jb51.net/article/39187.htm

  • 相关阅读:
    第09组 Alpha冲刺(3/4)
    第09组 Alpha冲刺(2/4)
    第09组 Alpha冲刺(1/4)
    数值分析——多项式插值之Lagrange插值
    Deepin下安装搭建latex编写环境
    Deepin下安装Matlab2017a永久版
    数学建模方法-遗传算法(实战篇part 2)
    数学建模方法-遗传算法(实战篇part 1)
    数学建模方法-遗传算法(理论篇)
    Deepin系统下MATLAB中文字体乱码问题解决(加上字体美化)
  • 原文地址:https://www.cnblogs.com/caicairui/p/8485908.html
Copyright © 2011-2022 走看看