首先准备安装环境:
yum install gcc gcc-c++ openssl openssl-devel libaio libaio-devel ncurses ncurses-deve
yum -y install numactl
到官网下载压缩文件或者使用如下命令下载:
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
得到xz的压缩包(也能下载tar压缩包)进行解压:
xz -d mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar
然后将解压后的文件夹重命名到/usr/local/mysql
mv mysql-8.0.13-linux-glibc2.12-x86_64 /usr/local/mysql
在/data下创建数据存放目录:
mkdir -p /data/mysql/{3307/{data,tmp,binlog,innodb_ts,innodb_log}}{3306/{data,tmp,binlog,innodb_ts,innodb_log}}...
在对应目录创建my.cnf文件(/data/mysql/330*)下面为3306实例的配置文件,其他的做相应更改即可:
[client]
port = 3306
socket = /data/mysql/3306/mysql.sock
# The MySQL server
[mysqld]
port = 3306
mysqlx_port = 33060
user = root
socket = /data/mysql/3306/mysql.sock
mysqlx_socket=/data/mysql/3306/mysqlx.sock
pid-file = /data/mysql/3306/mysql.pid
basedir = /usr/local/mysql
datadir = /data/mysql/3306/data
tmpdir = /data/mysql/3306/tmp
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 3306
lower_case_table_names = 1
character-set-server = utf8
federated #sql_mode=STRICT_TRANS_TABLES
max_connections = 1000
max_connect_errors = 100000
interactive_timeout = 86400
wait_timeout = 86400
back_log=100
default-storage-engine = InnoDB
#skip-grant-tables
#*********** GTID settting*******************
log_slave_updates = 1
gtid_mode=ON
enforce-gtid-consistency=true
innodb_flush_log_at_trx_commit=2
binlog_format= row
skip-slave-start=1
sync_binlog=5
#*********** Logs related settings ***********
log-bin = /data/mysql/3306/binlog/mysql-bin
binlog_cache_size=32m
max_binlog_cache_size=64m
max_binlog_size=512m
long_query_time = 1
log_output = FILE
log-error = /data/mysql/3306/mysql-error.log
slow_query_log = 1
slow_query_log_file = /data/mysql/3306/slow_statement.log
#log_queries_not_using_indexes
general_log = 0
general_log_file = /data/mysql/3306/general_statement.log
#expire-logs-days = 14
binlog_expire_logs_seconds = 1728000
relay-log = /data/mysql/3306/binlog/relay-bin
relay-log-index = /data/mysql/3306/binlog/relay-bin.index
#****** MySQL Replication New Feature*********
master-info-repository=TABLE
relay-log-info-repository=TABLE
relay-log-recovery
#*********** INNODB Specific options ***********
innodb_buffer_pool_size = 2048M
transaction-isolation=REPEATABLE-READ
innodb_buffer_pool_instances = 8
innodb_file_per_table = 1
innodb_data_home_dir = /data/mysql/3306/innodb_ts
innodb_data_file_path = ibdata1:2048M:autoextend
innodb_thread_concurrency = 8
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_log_group_home_dir = /data/mysql/3306/innodb_log
innodb_flush_log_at_trx_commit = 2
innodb_max_dirty_pages_pct = 70
innodb_flush_method=O_DIRECT
[mysql]
no-auto-rehash
default-character-set=gbk
prompt = (\u@\h) [\d]>\_
初始化3306实例的文件环境:
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysqldata/3306/my.cnf --initialize --user=mysql
启动实例(可能会报错,可以到目录下查看错误日志):
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql/3306/my.cnf --user=mysql &
登录:
mysql -u root -p -S /data/mysqldata/3306/mysql.sock
因为my.cnf中配置了skip-grant-tables所以随便输入密码进入:
修改用户的登录密码设置远程连接:
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>ALTER USER 'root'@'%' IDENTIFIED BY 'MyNewPass4!' PASSWORD EXPIRE NEVER;
mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'MyNewPass4!';
mysql>flush privileges;
修改my.cnf注释skip-grant-tables,重启服务(没有找到重启带个实例的方法,直接killall mysqld再重新的启动服务即可)