percona 5.7二进制安装
1、建立用户和组
sudo groupadd mysql
sudo useradd -g mysql -s /sbin/nologin mysql
2、下载二进制包Percona-Server-5.7.25-28-Linux.x86_64.ssl101.tar.gz。解压,并移至安装目录
tar -zxvf Percona-Server-5.7.25-28-Linux.x86_64.ssl101.tar.gz sudo mv Percona-Server-5.7.25-28-Linux.x86_64.ssl101 /usr/local/mysql
3、卸载本机自带的数据库
sudo yum remove mariadb-libs
4、编辑配置文件
sudo vim /etc/my.cnf
[mysqld]
default_time_zone = "+8:00"
skip-name-resolve
basedir=/usr/local/mysql
datadir=/data/mysql_data
socket=/data/mysql_log/mysql.sock
server-id=216130
event_scheduler=1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
##############################################################################################################
#LOGS CONFIG
##############################################################################################################
log_timestamps = SYSTEM
slow_query_log
long_query_time = 2
slow_query_log_file=/data/mysql_log/slow.log
binlog_format=ROW
log_bin=mysql-binlog
log_slave_updates
sync_binlog = 1
expire_logs_days=3
log-bin = /data/mysql_log/mybinlog
log-error = /data/mysql_log/error.log
innodb_max_undo_log_size = 512M
innodb_undo_directory = /data/mysql_log/undolog
innodb_undo_tablespaces = 95
innodb_undo_logs = 128
##############################################################################################################
#CONNECTION && SESSION CONFIG
##############################################################################################################
max_connections = 512
back_log = 500
max_connect_errors = 100
interactive_timeout=1000
connect_timeout=1000
wait_timeout=100
character_set_server=utf8mb4
thread_stack = 192K
thread_cache_size=64
##############################################################################################################
#TABLE && QUERY CONFIG
##############################################################################################################
table_open_cache = 40960
max_allowed_packet = 32M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
query_cache_type = 0
query_cache_size = 0
query_cache_limit = 2M
ft_min_word_len = 2
default-storage-engine = innodb
transaction_isolation = REPEATABLE-READ
tmp_table_size = 32M
innodb_open_files=40960
open_files_limit=82930
##############################################################################################################
#MYISAM CONFIG
##############################################################################################################
key_buffer_size = 32M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 500M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 2
explicit_defaults_for_timestamp
##############################################################################################################
#INNODB CONFIG
##############################################################################################################
innodb_buffer_pool_size = 512M # 重要参数,物理内存的75%左右
innodb_buffer_pool_instances=4
innodb_page_cleaners=4
innodb_purge_threads = 4
innodb_data_file_path = ibdata1:256M:autoextend
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_thread_concurrency = 0
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 8M
innodb_log_files_in_group=5
innodb_log_file_size=500m
innodb_flush_method = O_DSYNC
innodb_lock_wait_timeout = 120
innodb_file_per_table=1
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
internal_tmp_disk_storage_engine = InnoDB
innodb_rollback_on_timeout = 1
#############################################################################################################
#REPLICATION CONFIG
##############################################################################################################
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%
replicate-wild-ignore-table=dbcfg.%
replicate-wild-ignore-table=test.%
skip-slave-start
[mysqld_safe]
log-error=/data/mysql_log/error.log
pid-file=/data/mysql_log/mysqld.pid
[client]
socket = /data/mysql_log/mysql.sock
[mysql]
prompt="\u@db01 [\d]> "
5、创建相应文件夹,并赋权限
sudo mkdir -p /data/{mysql_log,mysql_data}
sudo chown mysql. -R /data sudo chown mysql. -R /usr/local/mysql/
6、初始化
cd /usr/local/mysql/bin
sudo ./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
其中初始化密码打印屏幕中
2019-04-17T02:49:06.361433Z 1 [Note] A temporary password is generated for root@localhost: pp!NIfqgG1ZO
7、配置环境变量
sudo vim /etc/bashrc
添加
export PATH=$PATH:/usr/local/mysql/bin
生效
source /etc/bashrc
8、配置服务
sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
更改其中的
sudo vim /etc/init.d/mysqld ======= basedir=/usr/local/mysql datadir=/data/mysql_data
9、启动服务,加入自启
sudo service mysqld start
sudo chkconfig --add mysqld
10、发现连接报错
mysql -uroot -p -S /data/mysql_log/mysql.sock Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/data/mysql_log/mysql.sock' (13)
原因是/data/mysql,我的用户无法连接到该目录中。所以需要赋权
sudo chmod 755 /data/mysql_log/
ok,问题解决
11、
/usr/local/mysql/bin/mysql --socket=/data/mysql_log/mysql.sock -uroot -p
输入密码,更改初始密码
alter user root@localhost identified by '1234';
创建一个主从复制账户
create user 'DB101'@'192.168.20.101' identified by '1234'; grant REPLICATION SLAVE on *.* to 'DB101'@'192.168.20.101';
12、在192.168.20.101中操作,发现无法连接。
mysql -h192.168.20.100 -uDB101 -p Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.20.100' (113)
使用telnet,发现3306端口无法通信。所以需要更改防火墙策略
sudo firewall-cmd --zone=public --add-port=3306/tcp --permanent sudo firewall-cmd --reload
问题解决
安装遇到问题:
1、初始化时候报错
sudo ./mysqld --initialize --user=mysql ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决办法
sudo yum localinstall ~/libaio-0.3.109-13.el7.x86_64.rpm
我这边是无网络环境,所以先从其他地方下载安装包,本地进行安装
2、percona提供的安装文件,密码是不会打印在屏幕中的,需要自己查找。路径是数据目录的err.log
cat /data/mysql_log/error.log