暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

MySQL5.7.17 编译安装

5003 2024-10-31
116

MySQL5.7.17 编译安装

 

如果安装到CentOS 7上,至少需要3G内存,20G硬盘,否则可能卡死,不能继续。

 

关闭防火墙、selinux

yum install lrzsz.x86_64 -y

 

1.清理环境

yum list installed *mysql*

yum remove installed *mysql*

 

2.创建mysql组和用户

groupadd mysql

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

# 注:mysql 用户设置为禁止登陆,分配有限资源,以便限制访问

 

3、创建数据库使用目录

mkdir -pv /export/data/mysql/data

mkdir -pv /export/data/mysql/log

mkdir -pv /export/data/mysql/tmp

mkdir -pv /export/servers/mysql/etc

chown -R mysql:mysql /export/data/mysql

 

4、下载mysql、boost,及安装依赖环境

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.17.tar.gz

wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz

yum -y install gcc gcc-c++ ncurses ncurses-devel cmake make

tar -zxvf boost_1_59_0.tar.gz

mv boost_1_59_0 /export/servers/

 

5、编译安装

tar -zxvf mysql-5.7.17.tar.gz

cd mysql-5.7.17

# cmake . -LAH  #查看cmake选项

 

cmake \

-DCMAKE_INSTALL_PREFIX=/export/servers/mysql \

-DMYSQL_DATADIR=/export/data/mysql/data \

-DWITH_BOOST=/export/servers/boost_1_59_0/ \

-DMYSQL_UNIX_ADDR=/export/servers/mysql/mysql.sock \

-DSYSCONFDIR=/export/servers/mysql/etc \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DMYSQL_TCP_PORT=3358

 

# 成功了:

-- Running cmake version 2.8.12.2

-- Configuring with MAX_INDEXES = 64U

-- SIZEOF_VOIDP 8

-- MySQL 5.7.17

-- Packaging as: mysql-5.7.17-Linux-x86_64

-- Local boost dir /export/servers/boost_1_59_0

-- Found /export/servers/boost_1_59_0/boost/version.hpp

-- BOOST_VERSION_NUMBER is #define BOOST_VERSION 105900

-- BOOST_INCLUDE_DIR /export/servers/boost_1_59_0

-- NUMA library missing or required version not available

-- WITH_PROTOBUF=bundled

-- protobuf version is 2.6

-- 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 /export/servers/boost_1_59_0

-- MYSQLX - Text log of protobuf messages enabled

-- 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

-- 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_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: /software/mysql-5.7.17

 

 

make                       # 这步比较慢

make install             # 一定要注意磁盘空间,装完需要4G

 

 

6、mysql 命令添加到环境变量中

vi /etc/profile

加入以下内容:

# mysql env

PATH=/export/servers/mysql/bin:$PATH

export PATH

 

source /etc/profile

 

7、启动脚本,设置开机自启动

chown -R mysql.mysql /export/servers/mysql/

/bin/cp /export/servers/mysql/support-files/mysql.server /etc/init.d/mysql

chmod 755 /etc/init.d/mysql

chkconfig --add mysql

chkconfig mysql on

chkconfig --list

 

8、初始化数据库

cd /export/servers/mysql

# ./mysql_install_db --user=mysql --datadir=/export/data/mysql/data

bin/mysql_install_db --user=mysql --datadir=/export/data/mysql/data

bin/mysqld --initialize --user=mysql --datadir=/export/data/mysql/data                # MySQL5.7要用这个

 

 

9、创建配置文件

vim /export/servers/mysql/etc/my.cnf  

[client]

port                             = 3358

socket                           = /export/data/mysql/tmp/mysql.sock

prompt                           = (\u@\h) [\d] >

 

 

[mysqld]

port                            = 3358

socket                          = /export/data/mysql/tmp/mysql.sock

datadir                         = /export/data/mysql/data

 

 

#--- GLOBAL ---#

#transaction-isolation           = READ-COMMITTED

default-storage-engine          = INNODB

character-set-server            = utf8

lower_case_table_names          = 1

log-error                       = /export/data/mysql/log/error.log

 

general_log                     = 0

general_log_file                = /export/data/mysql/log/general.log

pid-file                        = /export/data/mysql/data/mysql.pid

slow-query-log

slow_query_log_file             = /export/data/mysql/log/slow.log

#log                             = /export/data/mysql/log/log.log        # 将被取消的参数

tmpdir                          = /export/data/mysql/tmp

long_query_time                 = 5

#enable slave slow log

log_slow_slave_statements       = 1

#log_output                      = FILE

 

thread_cache_size               = 512

table_open_cache                = 16384

table_definition_cache          = 16384

 

sort_buffer_size                = 256K

join_buffer_size                = 256K

read_buffer_size                = 256K

read_rnd_buffer_size            = 256K

key_buffer_size                 = 64M

myisam_sort_buffer_size         = 64M

tmp_table_size                  = 32M

max_heap_table_size             = 32M

open_files_limit                = 65535

query_cache_size                = 0

query_cache_type                = 0

log_bin_trust_function_creators = 1

log_slow_admin_statements       = 1

log_queries_not_using_indexes   = 1

log_throttle_queries_not_using_indexes = 60

slave_preserve_commit_order     = 1

 

#--- NETWORK ---#

back_log                        = 2000

max_allowed_packet              = 16M

interactive_timeout             = 600

wait_timeout                    = 600

max-connections                 = 2000

skip-name-resolve

read_only                       = OFF

 

#--- REPL ---#

server-id                       = serverid     # ##############要改为ID################

log-bin                         = /export/data/mysql/data/mysql-bin

binlog_format                   = row

expire_logs_days                = 14

relay-log                       = /export/data/mysql/data/relay-log

log_slave_updates

slave_net_timeout               = 30

skip-slave-start

sync_binlog                     = 1

#flush disk

sync_master_info                = 1

sync_relay_log_info             = 1

sync_relay_log                  = 1

relay_log_recovery              = 1

 

#-- HALF REPL --#

#rpl_semi_sync_slave_enabled    = 1

#rpl_semi_sync_master_enabled   = 1

#rpl_semi_sync_master_timeout   = 1000

 

#--- INNODB ---#

innodb_adaptive_flushing        = ON

innodb_adaptive_hash_index      = ON

innodb_data_home_dir            = /export/data/mysql/data

innodb_file_per_table           = ON

innodb_log_group_home_dir       = /export/data/mysql/data

innodb_log_files_in_group       = 3

innodb_log_file_size            = 512M

innodb_log_buffer_size          = 32M

innodb_flush_log_at_trx_commit  = 1

innodb_lock_wait_timeout        = 60

innodb_flush_method             = O_DIRECT

innodb_max_dirty_pages_pct      = 75

innodb_buffer_pool_size         = 128M

#innodb_additional_mem_pool_size = 128M    # 没有这个参数

innodb_buffer_pool_instances    = 3

#innodb_data_file_path           = ibdata1:256M:autoextend       # 这个参数就不要了,如果要加,会因为ibdata1文件大小与此设置不一致,导致启动失败

#[ERROR] InnoDB: The Auto-extending innodb_system data file '/export/data/mysql/data/ibdata1' is of a different size 768 pages (rounded down to MB) than

#specified in the .cnf file: initial 16384 pages, max 0 (relevant if non-zero) pages!

 

innodb_change_buffering         = all

innodb_thread_concurrency       = 128

innodb_open_files               = 65535

innodb_old_blocks_time          = 30

innodb_write_io_threads         = 8

innodb_read_io_threads          = 8

innodb_io_capacity              = 800

innodb_purge_threads            = 1

innodb_purge_batch_size         = 300

innodb_file_format              = Barracuda

 

innodb_large_prefix             = ON

#innodb_force_load_corrupted    = OFF

#innodb_force_recovery          = 0

 

[mysqldump]

quick

max_allowed_packet              = 16M

 

[mysql]

# auto-rehash

# Remove the next comment character if you are not familiar with SQL

# safe-updates

no-auto-rehash

default-character-set           = utf8

 

[myisamchk]

key_buffer_size                 = 128M

sort_buffer_size                = 128M

read_buffer                     = 2M

write_buffer                    = 2M

 

[mysqlhotcopy]

interactive-timeout

 

 

10、再次授权、启动数据库

rm -rf /etc/my.cnf

touch /export/data/mysql/log/error.log

chown -R mysql.mysql /export/data/mysql

chown -R mysql.mysql /export/servers/mysql

/etc/init.d/mysql start   # 或       service mysql start    启动数据库

ps -Aef | grep mysqld

 

11、登录并修改数据库密码

cat /root/.mysql_secret

内容类似如下:

# Password set for user 'root@localhost' at 2016-12-29 11:54:31

Iuydn%wy.>dd    # 这就是密码

 

登录:

mysql -u root -p

mysql -S /export/data/mysql/tmp/mysql.sock -u root -p    # 使用sock登录

 

登录后,一定要先更改root密码,否则什么事情也干不了。

alter user 'root'@'localhost' identified by 'mysqlrootpwd';

 

 

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论