1. 程式人生 > >CentOS 7.4 RPM安裝Mysql8

CentOS 7.4 RPM安裝Mysql8

一 系統配置

1 安裝依賴包

yum -y install wget  cmake gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  openssl openssl-devel perl net-tools

2 關閉SELinux和防火牆

systemctl stop firewalld 
systemctl disable firewalld 
vi /etc/selinux/config
SELINUX=disabled

在這裡插入圖片描述 重啟電腦

二 解除安裝mariadb

rpm -qa | grep mariadb

在這裡插入圖片描述 有幾個解除安裝幾個

yum -y remove mariadb-libs-5.5.56-2.el7.x86_64

三 安裝Mysql

tar -xvf mysql-8.0.12-1.el7.x86_64.rpm-bundle.tar
rpm -ivh --force mysql-community-common-8.0.12-1.el7.x86_64.rpm
rpm -ivh --force mysql-community-libs-8.0.12-1.el7.x86_64.rpm
rpm -ivh --force mysql-community-libs-compat-8.0.12-1.el7.x86_64.rpm
rpm -ivh --force mysql-community-devel-8.0.12-1.el7.x86_64.rpm
rpm -ivh --force mysql-community-client-8.0.12-1.el7.x86_64.rpm
rpm -ivh --force mysql-community-server-8.0.12-1.el7.x86_64.rpm

四 啟動Mysql服務

1 建立資料夾

mkdir -p /app/mysql/mysqldata/{3306/{data,tmp,binlog,innodb_ts,innodb_log,undo},backup,scripts}
chown -R mysql:mysql /app/mysql/

2 修改配置檔案

echo '' > /etc/my.cnf
vi /etc/my.cnf


[client]
port = 3306
socket = /app/mysql/mysqldata/3306/mysql.sock
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld_multi]  
mysqld = /usr/bin/mysqld_safe  
mysqladmin = /usr/bin/mysqladmin  
log = /app/mysql/mysqldata/mysqld_multi.log  


[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
default-authentication-plugin=mysql_native_password
port = 3306
mysqlx_port = 33060
user = mysql
socket = /app/mysql/mysqldata/3306/mysql.sock
mysqlx_socket=/app/mysql/mysqldata/3306/mysqlx.sock
pid-file = /app/mysql/mysqldata/3306/mysql.pid
datadir = /app/mysql/mysqldata/3306/data
tmpdir = /app/mysql/mysqldata/3306/tmp
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 21203306
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
#*********** 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 = /app/mysql/mysqldata/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 = /app/mysql/mysqldata/3306/mysql-error.log
slow_query_log = 1
slow_query_log_file = /app/mysql/mysqldata/3306/slow_statement.log
#log_queries_not_using_indexes
general_log = 0
general_log_file = /app/mysql/mysqldata/3306/general_statement.log
#expire-logs-days = 14
binlog_expire_logs_seconds = 1728000
relay-log = /app/mysql/mysqldata/3306/binlog/relay-bin
relay-log-index = /app/mysql/mysqldata/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 = 256M
transaction-isolation=REPEATABLE-READ
innodb_buffer_pool_instances = 8
innodb_file_per_table = 1
innodb_data_home_dir = /app/mysql/mysqldata/3306/innodb_ts
innodb_data_file_path = /app/mysql/mysqldata/3306/innodb_ts/ibdata1:2048M:autoextend
innodb_thread_concurrency = 8
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_undo_tablespaces=3
innodb_undo_directory =/app/mysql/mysqldata/3306/undo
innodb_log_group_home_dir = /app/mysql/mysqldata/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=utf8
prompt = (\
[email protected]
\h) [\d]>\_

3 啟動服務

service mysqld restart

4 配置Mysql

4.1 修改密碼

vi /app/mysql/mysqldata/3306/mysql-error.log 

在這裡插入圖片描述

mysql -uroot -p

輸入上圖密碼 在這裡插入圖片描述

4.2 重置密碼

alter user user() identified by "root";
use mysql;
update user set authentication_string = '' where user = 'root';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
update user set host = '%' where user = 'root';
flush privileges;

若重置密碼報錯

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 執行如下SQL

set global validate_password.policy=0;
set global validate_password.length=4;
set global validate_password.check_user_name=OFF;
set global validate_password.number_count=0;
set global validate_password.special_char_count=0;
flush privileges;