阿汤博客-承接中小企业服务器维护和网站维护,有意者可以联系博主!

Centos7.x编译安装Mysql5.7

运维文档 114℃ 0评论

1、安装依赖

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

#yum groupinstall -y "Development tools"

#wget https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.gz

#tar zxf boost_1_68_0.tar.gz 

#cd ../boost_1_68_0

#./bootstrap.sh

#./b2 install

2、编译安装

#mkdir -pv /usr/local/mysql

#mkdir -pv /opt/data/mysql 

#wget wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.24.tar.gz

#tar -zxvf mysql-5.7.24

#cd mysql-5.7.24

#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/opt/data/mysql/ -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGINE=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 -DDOWNLOAD_BOOST=1  -DWITH_BOOST=/usr/local/include/boost/

#make

#make install

3、创建mysql用户组

#groupadd -r mysql

#useradd -g mysql -r -s /sbin/nologin mysql

#chown -R mysql.mysql /usr/local/mysql

#chown -R mysql.mysql /opt/data/mysql

#mkdir /var/lib/mysql

#chown -R mysql.mysql /var/lib/mysql

4、配置mysql

#/usr/local/mysql/bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/opt/data/mysql #会生成一个随机密码

#echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh

#source /etc/profile.d/mysql.sh

#touch /etc/my.cnf #详细配置见末尾

#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #添加启动脚本

#chkconfig –add mysqld  #设置开机启动

#echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf  #导出库文件

#ldconfig -v     #建立库文件缓存

#ln -sv /usr/local/mysql/include/ /usr/include/mysql  #导出头文件

#mkdir /opt/data/mysql/bin_log

#chown -R mysql.mysql /opt/data/mysql/bin_log

#/etc/init.d/mysqld start

#mysql -uroot -p

>set password for 'root'@'localhost' =password('newpassword'); #修改初始密码

>update user set host='%' where user='root'; #开启远程连接

>create user 'tom'@'%' identified by '[email protected]';  #创建普通账号

>create database atang character set utf8; #创建数据库库

>grant all privileges on atang.* to 'tom'@'%';  #授权gdg账号最大权限访问atang库

>drop user ''@'localhost.domain';

>drop user ''@'localhost';

>drop user 'root'@'::1';

>flush privileges;

my.cnf参数

[client]

port = 3306

socket = /var/lib/mysql/mysql.sock

default-character-set = utf8mb4

#default-character-set = utf8

[mysql]

prompt="MySQL [\d]> "

no-auto-rehash

default-character-set = utf8mb4

#skip-ssl

[mysqld]

port = 3306

socket = /var/lib/mysql/mysql.sock

basedir = /usr/local/mysql

datadir = /opt/data/mysql

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

user = mysql

bind-address = 0.0.0.0

#mysql主从 slave设置

binlog-do-db = duoyun_community

server-id = 2

relay-log = relay-log

gtid_mode=ON     #开启gtid复制

enforce-gtid-consistency=on  #开启gtid复制

log_bin = /opt/data/mysql/bin_log/binlog

binlog_format = mixed

expire_logs_days = 7

binlog_cache_size = 4M

max_binlog_size = 100m

max_binlog_cache_size = 512m

character-set-server = utf8mb4

collation-server = utf8mb4_general_ci

init-connect = 'SET NAMES utf8mb4'

#init-connect = 'SET NAMES utf8'

#character-set-server = utf8

skip-name-resolve

#skip-networking

back_log = 300

max_connections = 5000

max_connect_errors = 6000

open_files_limit = 65535

table_open_cache = 1024

max_allowed_packet = 500M

max_heap_table_size = 8M

tmp_table_size = 128M

read_buffer_size = 2M

read_rnd_buffer_size = 8M

sort_buffer_size = 8M

join_buffer_size = 8M

key_buffer_size = 256M

thread_cache_size = 64

query_cache_type = 1

query_cache_size = 64M

query_cache_limit = 2M

ft_min_word_len = 4

log_error = /opt/data/mysql/mysql-error.log

slow_query_log = 1

long_query_time = 1

slow_query_log_file = /opt/data/mysql/mysql-slow.log

performance_schema = 0

explicit_defaults_for_timestamp

#lower_case_table_names = 1

skip-external-locking

default_storage_engine = InnoDB

innodb_file_per_table = 1

innodb_open_files = 500

innodb_buffer_pool_size = 1024M

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 = 64M

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

interactive_timeout = 28800

wait_timeout = 28800

[mysqldump]

quick

max_allowed_packet = 500M

[myisamchk]

key_buffer_size = 256M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

转载请注明:阿汤博客 » Centos7.x编译安装Mysql5.7

喜欢 (0)or分享 (0)