- 官网下载:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-i686.tar.xz
- 创建用户:
groupadd mysql
useradd -g mysql mysql
- 创建目录,并修改所属用户:
mkdir -p /data/mysql
mkdir -p /data/mysql_data
mkdir -p /data/mysql_log
mkdir -p /data/mysql_tmp
mkdir -p /var/run/mysqld
chown -R mysql.mysql /data/mysql*
chown -R mysql.mysql /var/run/mysqld
- 解包:
tar -xvf mysql-8.0.13-linux-glibc2.12-i686.tar.xz
cp -R mysql-8.0.13-linux-glibc2.12-i686/* /data/mysql/
- 配置环境变量
vim /etc/bashrc
export PATH=/data/mysql/bin:$PATH
- 检查
$ mysql --version
bash: /data/mysql/bin/mysql: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
$ yum install -y glibc.i686
$ mysql --version
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
$ yum install -y libtinfo.so.5
$ mysql --version
mysql Ver 8.0.13 for linux-glibc2.12 on i686 (MySQL Community Server - GPL)
- 开始导入配置文件(以下配置文件可以直接使用):
Master:
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[client]
port = 3306
socket = /data/mysql/mysqld.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
log-error = /data/mysql_log/mysqld.err
nice = 0
[mysqld]
user = mysql
pid-file = /data/mysql/mysqld.pid
socket = /data/mysql/mysqld.sock
log-error = /data/mysql_log/error.err
port = 3306
basedir = /usr/share/mysql
datadir = /data/mysql_data
tmpdir = /data/mysql_tmp
lc-messages-dir = /usr/share/mysql
interactive_timeout = 120
wait_timeout = 120
max_allowed_packet = 32M
# mysqld character
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
# when innodb_buffer_pool_size too big, the container is shutdown
innodb_buffer_pool_size = 1024M
explicit_defaults_for_timestamp
# innodb_flush_log_at_trx_commit=2
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
max_connections=10240
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#master-slave config
log-bin=mysql-bin
server-id=19
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
#!includedir /etc/mysql/conf.d/
Slave:
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[client]
port = 3306
socket = /data/mysql/mysqld.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
log-error = /data/mysql_log/mysqld.err
nice = 0
[mysqld]
user = mysql
pid-file = /data/mysql/mysqld.pid
socket = /data/mysql/mysqld.sock
log-error = /data/mysql_log/error.err
port = 3306
basedir = /usr/share/mysql
datadir = /data/mysql_data
tmpdir = /data/mysql_tmp
lc-messages-dir = /usr/share/mysql
interactive_timeout = 120
wait_timeout = 120
max_allowed_packet = 32M
# mysqld character
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
# when innodb_buffer_pool_size too big, the container is shutdown
innodb_buffer_pool_size = 1024M
explicit_defaults_for_timestamp
# innodb_flush_log_at_trx_commit=2
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
max_connections=10240
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#master-slave config
server-id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
#slave-slave config
#server-id=2
#log-bin=slave-bin
#log-bin-index=slave-bin.index
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
#!includedir /etc/mysql/conf.d/
- 初始化
$ /data/mysql/bin/mysqld --initialize --user=mysql
/data/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
$ yum install -y libaio.so.1
$ /data/mysql/bin/mysqld --initialize --user=mysql
/data/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
$ yum install -y libnuma.so.1 --setopt=protected_multilib=false
$ /data/mysql/bin/mysqld --initialize --user=mysql
- 启动实例
/data/mysql/bin/mysqld --user=mysql --port=3306 &
- 修改root密码
$ cat /data/mysql_log/error.err | grep pass
2018-12-30T08:31:19.029232Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: temppass #查询临时密码
$ mysqladmin -u root -p password 'temppass'
- 安装完成, 最后一步
配置主从
#主库执行
> create user 'slave_sync'@'slaveip' identified by 'pass'; #创建用于同步的账户
> GRANT REPLICATION SLAVE ON *.* to 'slave_sync'@'slaveip';
> flush privileges;
> show master status;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 27
Current database: *** NONE ***
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000007 | 1596 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.01 sec)
# 从库执行 记录下主库当前日志和position,从此处开始同步
> change master to master_host='masterip',master_user='slave_sync',master_password='pass',master_log_file='mysql-bin.000007',master_log_pos=1596;
###重启mysql,检查服务
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: masterip
Master_User: slave_sync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000007
Read_Master_Log_Pos: 1596
Relay_Log_File: slave-relay-bin.000003
Relay_Log_Pos: 503
Relay_Master_Log_File: mysql-bin.000007
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
...
...
Slave_IO_Running为Yes,到主库创建test数据库检查同步结果,安装完成
网友评论