美文网首页运维MySQLMySQL我爱编程
基于Centos6.5源码编译安装mysql-5.7.17过程详

基于Centos6.5源码编译安装mysql-5.7.17过程详

作者: 冬天里的懒喵 | 来源:发表于2017-03-03 16:08 被阅读1006次

    由于工作需要,需要在centos6.5服务器上安装mysql5.7,如下是详细安装过程。

    一.安装环境

    CentOS release 6.5 (Final)

    Linux version 2.6.32-431.el6.x86_64

    二.安装准备

    需要下载mysql、boost, 并在yum中升级相关依赖包。

    mysql

    https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz

    boost

    https://jaist.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

    yum依赖

    yum install -y gcc-c++ readline-devel zlib-devel bison  cmake

    设置用户权限

    groupadd mysql
    useradd -g mysql mysql

    另外需要修改limits.conf

    vim /etc/security/limits.conf

    增加如下内容:

    mysql soft nproc 16384
    mysql hard nproc 16384
    mysql soft nofile 65535
    mysql hard nofile 65535

    三.编译boost

      boost是一个c++函数库,mysql5.7.5版本之后,必须安装boost,因此需要先编译boost。root用户下 ,将安装文件放在/opt/software目录。boost安装到/usr/local目录。

    cd /opt/software/ tar -zxvf boost_1_59_0.tar.gz -C /usr/local mv boost_1_59_0 boost cd boost/ ./bootstrap.sh  ./b2 install

    四.安装mysql

    由于服务器分区关系,所有软件都需要安装在/opt目录,因此mysql安装在/opt/mysql目录。

    cd /opt/software/ tar -zxvf mysql-5.7.17.tar.gz cd mysql-5.7.17/

    预编译

    [root@m162p49 mysql-5.7.17]# cmake \ > -DCMAKE_INSTALL_PREFIX=/opt/mysql \ > -DMYSQL_UNIX_ADDR=/opt/mysql/data/mysql.sock \ > -DMYSQL_DATADIR=/opt/mysql/data \ > -DDEFAULT_CHARSET=utf8 \ > -DDEFAULT_COLLATION=utf8_general_ci \ > -DWITH_MYISAM_STORAGE_ENGINE=1 \ > -DWITH_INNOBASE_STORAGE_ENGINE=1  \ > -DWITH_ARCHIVE_STORAGE_ENGINE=1  \ > -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ > -DWITH_MEMORY_STORAGE_ENGINE=1 \ > -DWITH_READLINE=1 \ > -DENABLED_LOCAL_INFILE=1 \ > -DMYSQL_USER=mysql  \ > -DMYSQL_TCP_PORT=3306 \ > -DENABLE_DOWNLOADS=1 \ > -DDOWNLOAD_BOOST=1 \ > -DWITH_BOOST=/usr/local/boost

    编译安装

    预编译成功之后,可以进行make,时间比较长,至少30分钟以上。

    make && make install

    如下是make过程

    至此,mysql编译和安装就成功了。

    修改权限:

    mkdir /opt/mysql/data

    chown -R  mysql:mysql  /opt/mysql

    五.新增配置文件

    在/etc目录下,新增my.cnf文件,文件内容如下:

    [client] port = 3306 socket = /opt/mysql/data/mysql.sock [mysqld] port = 3306 socket = /opt/mysql/data/mysql.sock basedir = /opt/mysql datadir = /opt/mysql/data #pid-file = /opt/mysql/mysql.pid user = mysql bind-address = 0.0.0.0 server-id = 1 init-connect = 'SET NAMES utf8' character-set-server = utf8 #skip-name-resolve #skip-networking back_log = 300 max_connections = 1000 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 128 max_allowed_packet = 4M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 16M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 4M thread_cache_size = 8 query_cache_type = 1 query_cache_size = 8M query_cache_limit = 2M ft_min_word_len = 4 log_bin = mysql-bin binlog_format = mixed expire_logs_days = 30 log_error = /opt/mysql/log/mysql-error.log slow_query_log = 1 long_query_time = 1 slow_query_log_file = /opt/mysql/log/mysql-slow.log performance_schema = 0 explicit_defaults_for_timestamp #lower_case_table_names = 1 skip-external-locking default_storage_engine = InnoDB #default-storage-engine = MyISAM innodb_file_per_table = 1 innodb_open_files = 500 innodb_buffer_pool_size = 64M innodb_write_io_threads = 4 innodb_read_io_threads = 4 innodb_thread_concurrency = 0 innodb_purge_threads = 1 innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 2M innodb_log_file_size = 32M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 90 innodb_lock_wait_timeout = 120 bulk_insert_buffer_size = 8M myisam_sort_buffer_size = 8M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 interactive_timeout = 28800 wait_timeout = 28800 [mysqldump] quick max_allowed_packet = 16M [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M read_buffer = 4M write_buffer = 4M

    六.初始化数据库

    cd /opt/mysql 执行如下命令 bin/mysqld --initialize --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql

    七.新增boot服务

    cd /opt/mysql cp support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld  chkconfig --add mysqld

    八.启动数据库

    service mysqld start

    九.设置mysql环境变量

    echo -e '\n\nexport PATH=/opt/mysql/bin:$PATH\n' >> /etc/profile && source /etc/profile

    十.修改root密码

      临时密码在日志中可以查看,如果没有配置日志或者无法找到临时密码,则需要通过如下步骤操作:

    1.关闭mysql

    service mysqld stop

    2.修改MySQL授权登录方式

    cd  /opt/mysql bin/mysqld_safe --skip-grant-tables &

    之后登陆mysql,则不再需要密码。

    3.切换到mysql库执行修改语句

    mysql>  use mysql; mysql>  update user set password=password('') where user='root'; ERROR 1054 (42S22): Unknown column 'password' in 'field list'

    可见mysql5.7的用户密码与5.6不同,查看mysql的user表结构可知。

    desc user;
    select user,host,authentication_string,password_expired from user;

    可以发现,除root用户外,还存在一个mysql.sys用户。此时root用户password_expired状态为Y。为已过期状态。密码字段变成了authentication_string 。

    4.修改密码

    update user set authentication_string=password('mysql') where user='root'; flush privileges; exit

    5.重启登陆

    service mysqld restart

    之后用重新修改的root密码即可登录。

    6.  异常1820

    登陆后如果查询数据库出现错误:

    mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    则需要重新设置一下root密码

    SET PASSWD = PASSWD('mysql');

    重新登陆即可。

    十一.创建数据库

    现在mysql安装完毕,可以创建自己需要的数据库。

    create database demo DEFAULT CHARACTER SET utf8 COLLATE  utf8_general_ci;   grant all privileges on demo.* to demo@'%.%.%.%' identified by 'demo123'; flush privileges;

    相关文章

      网友评论

        本文标题:基于Centos6.5源码编译安装mysql-5.7.17过程详

        本文链接:https://www.haomeiwen.com/subject/dzxrgttx.html