天天看點

MySQL 5.7.17源碼編譯安裝說明

一、系統環境

CentOS release 6.5 (Final)

Linux 2.6.32-431.el6.x86_64

最小化安裝

關閉selinux, iptables,ip6tables

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

二、安裝準備

1.cmake

https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz

2.boost

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

3.mysql

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

三、preinstall

# cd cmake-3.7.2

# ./bootstrap 

-- Configuring done

-- Generating done

-- Build files have been written to: /home/soft/cmake-3.7.2

---------------------------------------------

CMake has bootstrapped.  Now run gmake.

# make && make install

# cmake --version

cmake version 3.7.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

# cd /home/soft/

# tar -zxvf boost_1_59_0.tar.gz -C /usr/local

# mv boost_1_59_0 boost

# cd boost/

# ./bootstrap.sh 

# ./b2 install

四、安裝mysql

user and group

# groupadd mysql

# useradd -r -g mysql -s /bin/false mysql

install,data,log,temp dir 

# mkdir -p /opt/mysql/data  /opt/mysql/logs /opt/mysql/temp

# vi /etc/profile  

# use for mysql 

export PATH=/opt/mysql/bin:/opt/mysql/lib:$PATH

# tar zxvf mysql-5.7.17.tar.gz

# cd mysql-5.7.17

# cmake \

-DCMAKE_INSTALL_PREFIX=/opt/mysql

-DMYSQL_UNIX_ADDR=/opt/mysql/data/mysql.sock

-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_DATADIR=/opt/mysql/data \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306 \

-DENABLE_DOWNLOADS=1 \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/usr/local/boost

# make && make install 

# chown -R mysql:mysql /opt/mysql

編輯配置檔案my.cnf

# vi /etc/my.cnf

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the

# *** default location during install, and will be replaced if you

# *** upgrade to a newer version of MySQL.

[mysqld]

# new add:explicit_defaults_for_timestamp

explicit_defaults_for_timestamp=true

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

# These are commonly set, remove the # and set as required.

# basedir = .....

# datadir = .....

# port = .....

# server_id = .....

# socket = .....

# Remove leading # to set options mainly useful for reporting servers.

# The server defaults are faster for transactions and fast SELECTs.

# Adjust sizes as needed, experiment to find the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

# new add: NO_AUTO_CREATE_USER,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO

# bin/mysqld --initialize --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql

2017-02-27T11:54:01.604788Z 0 [Warning] InnoDB: New log files created, LSN=45790

2017-02-27T11:54:01.930913Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2017-02-27T11:54:01.962973Z 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: 6e4c012a-fce3-11e6-aa31-000c29e3a907.

2017-02-27T11:54:01.967537Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2017-02-27T11:54:01.970198Z 1 [Note] A temporary password is generated for root@localhost: Q!0+tqhgQ(iI

ADD boot item

# cp support-files/mysql.server /etc/init.d/mysqld

# chmod +x mysqld

# chmod +x /etc/init.d/mysqld 

# chkconfig --add mysqld

啟動資料庫

# /etc/init.d/mysqld start

Starting MySQL.Logging to '/opt/mysql/data/localhost.localdomain.err'.

.. SUCCESS! 

#

五、使用臨時密碼登入,重置root密碼

# mysql -uroot -p

Enter password: (臨時生成的root密碼)

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.17

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 '123456';

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

mysql> \q

本文轉自 pgmia 51CTO部落格,原文連結:http://blog.51cto.com/heyiyi/1707904