一、安装依赖

[root@test1 tmp]# yum install gcc gcc-c++ cmake ncurses-devel bison -y
[root@test1 tmp]# tar -zxvf boost_1_59_0.tar.gz -C /usr/local/
[root@test1 tmp]# cd /usr/local/boost_1_59_0/
[root@test1 boost_1_59_0]# ./bootstrap.sh
[root@test1 boost_1_59_0]# ./b2 install

二、创建MySQL账号

[root@test1 tmp]# groupadd mysql
[root@test1 tmp]# useradd -r -g mysql -s /bin/false mysql

三、编译MySQL

[root@test1 tmp]# tar -zxvf mysql-5.7.17.tar.gz
[root@test1 tmp]# mkdir -p /data/mysql/data     //创建mysql数据库存储目录
[root@test1 tmp]# mkdir /data/mysql/log         //创建mysql数据库日志目录
[root@test1 tmp]# mkdir /data/mysql/tmp         //创建mysql数据库临时目录
[root@test1 tmp]# rpm -qa |grep mysql           //检查系统是否原先有安装过mysql-libs之类,卸载
[root@test1 tmp]# cd mysql-5.7.17
cmake \
-DMYSQL_USER=mysql \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DINSTALL_DATADIR=/data/mysql/data \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0/ \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0

[root@test mysql]# make && make install

四、MySQL初始化

[root@test mysql]# rm -rf /etc/my.cnf
[root@test mysql]# vi /usr/local/mysql/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/mysql.sock

[mysqld_safe]
pid-file=/data/mysql/data/mysql.pid


[mysql]
port=3306
prompt=\\u@\\d \\R:\\m:\\s>
default-character-set=utf8
no-auto-rehash


[mysqld]
#server
port=3306
bind-address=0.0.0.0
skip-name-resolve
skip-ssl
#sqlmod="STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE"
max_connections=4500
max_user_connections=4000
max_connect_errors=65536
max_allowed_packet=128M
connect_timeout=8
net_read_timeout=30
net_write_timeout=60
back_log=1024

default-storage-engine=INNODB
character-set-server=utf8mb4
lower_case_table_names=1
skip-external-locking
open_files_limit=65536
safe-user-create
local-infile=1
performance_schema=0

log_slow_admin_statements=1
log_warnings=1
long_query_time=1
slow_query_log=1
general_log=0

query_cache_type=0
query_cache_limit=1M
query_cache_min_res_unit=1K

table_definition_cache=65536
table_open_cache=65536

thread_stack=512K
thread_cache_size=256
read_rnd_buffer_size=128K
sort_buffer_size=256K
join_buffer_size=128K
read_buffer_size=128K

#dir
basedir=/usr/local/mysql
datadir=/data/mysql/data
tmpdir=/data/mysql/tmp
slow_query_log_file=/data/mysql/data/slow.log
#general_log_file=/data/mysql/log/general.log
socket=/usr/local/mysql/mysql.sock

#binlog
log-bin=/data/mysql/log/mysql-bin
server_id=1
binlog_cache_size=32K
max_binlog_cache_size=1G
max_binlog_size=500M
binlog-format=ROW
#log-slave-updates=1
expire_logs_days=30

#replication
master-info-file=/data/mysql/log/master.info
relay-log=/data/mysql/log/relaylog
relay_log_info_file=/data/mysql/log/relay-log.info
relay-log-index=/data/mysql/log/mysqld-relay-bin.index
slave_load_tmpdir=/data/mysql/tmp
slave_net_timeout=4


#innodb
innodb_data_home_dir=/data/mysql/data
innodb_log_group_home_dir=/data/mysql/data
#innodb_data_file_path=ibdata1:2G;ibdata2:16M:autoextend
innodb_data_file_path=ibdata1:10M:autoextend
innodb_buffer_pool_size=128M
innodb_buffer_pool_instances=4
innodb_log_files_in_group=2
innodb_log_file_size=1G
innodb_log_buffer_size=200M
innodb_flush_log_at_trx_commit=2
innodb_max_dirty_pages_pct=60
innodb_io_capacity=1000
innodb_thread_concurrency=16
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_open_files=60000
innodb_file_format=Barracuda
innodb_file_per_table=1
innodb_flush_method=O_DIRECT
innodb_change_buffering=inserts
innodb_adaptive_flushing=1
innodb_old_blocks_time=1000
innodb_stats_on_metadata=0
innodb_use_native_aio=0
innodb_lock_wait_timeout=5
innodb_rollback_on_timeout=0
innodb_purge_threads=1
innodb_strict_mode=1
innodb_autoinc_lock_mode=0

#myisam
key_buffer_size=64M
myisam_sort_buffer_size=64M
concurrent_insert=2
delayed_insert_timeout=300

[root@test1 mysql]# chown -R mysql. /usr/local/mysql
[root@test mysql]# chown -R mysql. /data/mysql
[root@test mysql-5.7.17]# cd /usr/local/mysql/
[root@test mysql]# chmod a+x bin/mysql_install_db
[root@test1 mysql]# bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql

五、服务脚本管理

[root@test mysql]# cp /tmp/mysql-5.7.17/support-files/mysql.server /etc/init.d/mysql
[root@test mysql]# chmod 700 /etc/init.d/mysql
[root@test mysql]# chkconfig --level 35 mysql on

六、配置环境变量

[root@test mysql]# vim /etc/profile //添加如下内容:
export PATH=/usr/local/mysql/bin/:$PATH

[root@test mysql]# source /etc/profile

七、数据库管理

[root@test mysql]# systemctl start mysql
[root@test mysql]# mysql -uroot -p      //设置root密码,根据自己需求设置
mysql> update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
mysql> alter user 'root'@'localhost' identified by '123456';
mysql> flush privileges ;
#注意:mysql5.7安全认证做了调整所以需要两次认证密码

最后修改日期: 2019年10月15日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。