CentOS6.9编译安装MySQL5.7.16

前端之家收集整理的这篇文章主要介绍了CentOS6.9编译安装MySQL5.7.16前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS6.9编译安装MysqL5.7.16

部署环境:

系统CentOS6.9,MysqL5.7.16,boost库

系统为2G内存

1、安装依赖包,使用yum安装cmake,6.9默认yum源自带

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

2、创建MysqL用户

useradd -U -s /sbin/nologin MysqL

3、创建必要的文件夹,并修改其目录用户所有者:

mkdir -pv /usr/local/MysqL/etc

mkdir -pv /data/{boost/boost_1_59_0,MysqL/{data,log}}

chown -R MysqL:MysqL /usr/local/MysqL/

chown -R MysqL:MysqL /data/MysqL/

4、将boots库拷贝到boost目录下

cp /tmp/boost/boost_1_59_0/* /data/boost/boost_1_59_0

chown -R MysqL:MysqL /data/boost/

5、编译安装MysqL5.7

cd /tmp

tar xf MysqL-5.7.16.tar.gz

cd MysqL-5.7.16

cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/MysqL \

-DMysqL_DATADIR=/data/MysqL/data \

-DSYSCONFDIR=/usr/local/MysqL/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMysqL_UNIX_ADDR=/data/MysqL/log/MysqL.sock \

-DMysqL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_BOOST=/data/boost/boost_1_59_0


make && make install

时间比较长

chown -R MysqL:MysqL /usr/local/MysqL

6、配置文件my.cnf

[client]

port = 3306

socket = /data/MysqL/log/MysqL.sock


[MysqL]

default-character-set = utf8


[MysqLd]

# file

datadir =/data/MysqL/data

basedir = /usr/local/MysqL

pid-file =/data/MysqL/log/MysqLd.pid

log_error = /data/MysqL/log/MysqL.err

port = 3306

socket=/data/MysqL/MysqL.sock

user=MysqL

character_set_server = utf8

character_set_server = utf8

slow_query_log = 1

slow_query_log_file = /data/MysqL/log/slowq.log

long_query_time = 1

log-bin=/data/MysqL/log/MysqL-bin.log

# temp

max_tmp_tables = 64

tmp_table_size = 512M

slave_load_tmpdir = /data/MysqL/log

tmpdir = /data/MysqL/log


# session

back_log = 512

skip-name-resolve

max_allowed_packet = 32M

max_connections = 16000

max_connect_errors = 10000

wait_timeout = 28800


table_open_cache = 216

thread_cache_size = 128



query_cache_type = 0

query_cache_size = 0

key_buffer_size = 128M

myisam_sort_buffer_size = 16M

read_buffer_size = 16M

read_rnd_buffer_size = 16M

sort_buffer_size = 16M

join_buffer_size = 16M


# innodb

default_storage_engine = InnoDB

innodb_data_home_dir = /data/MysqL/data

innodb_data_file_path = ibdata1:256M:autoextend

innodb_log_group_home_dir = /data/MysqL/log

innodb_log_files_in_group = 4

innodb_log_file_size = 256M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 2

innodb_flush_method = O_DIRECT

innodb_lock_wait_timeout = 50

#innodb_thread_concurrency = 24 16

innodb_buffer_pool_size = 1G

innodb_io_capacity = 1500

innodb_use_native_aio = 1

innodb_file_per_table = 1

innodb_open_files = 3000


# others

memlock = 1

performance_schema = 0


# replication

server-id = 150

binlog_format = row

expire_logs_days = 7

relay_log = /data/MysqL/log/relay-bin

#replicate_ignore_db = MysqL

#slave_skip_errors = 1062

log_slave_updates = 1

skip-slave-start

read_only = 0

sync_binlog = 1


[MysqLdump]

default-character-set = utf8


[MysqLd-5.7]

innodb_buffer_pool_dump_pct = 40

innodb_undo_log_truncate = 1

innodb_undo_tablespaces = 3

innodb_max_undo_log_size = 1G

innodb_purge_rseg_truncate_frequency = 128

binlog_gtid_simple_recovery=1

log_timestamps=system

show_compatibility_56=on

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

7、初始化数据库

版本在5.7.6前用的是MysqL_install_db

版本5.7.6之后使用的MysqLd --initialize

#####################官网标注#####################################

shell> bin/MysqL_install_db --user=MysqL # MysqL 5.7.5

shell> bin/MysqLd --initialize --user=MysqL # MysqL 5.7.6 and up

shell> bin/MysqL_ssl_rsa_setup # MysqL 5.7.6 and up

#####################官网标注#####################################

/usr/local/MysqL/bin/MysqLd --initialize --user=MysqL --datadir=/data/MysqL/data --basedir=/usr/local/MysqL

可能会出现内存不够的报错,自己优化下调节一下buffer大小就行了

/usr/local/MysqL/bin/MysqL_ssl_rsa_setup


没有打印日志,临时密码不能用,只好破解了,后面有方法

8、启动数据库

vim /usr/local/MysqL/support-files/MysqL.server

加上绝对路径

basedir=/usr/local/MysqL

datadir=/data/MysqL/data

cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd

service MysqLd start

9、配置环境变量

vim /etc/profile

export PATH=/usr/local/MysqL/bin:$PATH

source /etc/profile

10、查看MysqL临时密码,这项我这不用了,不好使,直接破解了。

cat /root/.MysqL_secret

MysqL -uroot -p`cat /root/.MysqL_secret`

如果能进去,基本上到这就截止了,可以正常使用了。

**不能正常登录,使用临时密码无法登进去**

11、破解密码

MysqLd_safe --defaults-file=/usr/local/MysqL/etc/my.cnf --skip-grant-tables --skip-networking&

update MysqL.user set authentication_string=password('123456') where user='root';

11.1、查找进程号,杀掉MysqL进程

ps aux | grep MysqL

kill -9 pid

service MysqLd start

11.2、登录MysqL

MysqL -u root -p 'password'

提示修改密码

MysqL> alter user root@localhost identified by '123456';

ok了

原文链接:https://www.f2er.com/centos/377797.html

猜你在找的CentOS相关文章