因客户要求升级mysql5.6版本,且服务不能停,服务器没网络环境,所以只能同时安装一个mysql8.0.22版本,对数据恢复后,再停止老服务。 此处记下在同一台服务器安装第二版mysql(mysql8)的步骤
1. 创建目录,创建data目录,赋权限
[root@MySQL-Test soft]# mv mysql-8.0.22-linux-glibc2.12-x86_64/ mysql8
[root@MySQL-Test soft]# mv mysql8/ /usr/local/
[root@MySQL-Test soft]# mkdir data
[root@MySQL-Test soft]# chown -R mysql:mysql /var/lib/mysql8
[root@MySQL-Test mysql]#chown -R mysql:mysql ./ #修改当前目录拥有者为mysql用户
2. 初始化数据库
[root@MySQL-Test mysql8]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql8 --datadir=/usr/local/mysql8/data
2021-01-28T17:35:34.719103Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2021-01-28T17:35:34.719186Z 0 [System] [MY-013169] [Server] /usr/local/mysql8/bin/mysqld (mysqld 8.0.22) initializing of server in progress as process 2776
2021-01-28T17:35:34.720308Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
2021-01-28T17:35:34.725807Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-01-28T17:35:35.405836Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-01-28T17:35:37.156546Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -vHpdA8LOnxy
记下上面的
-vHpdA8LOnxy临时密码,下面连接mysql中会用到
MySQL8.0.22的
my.cnf配置(路径可自定义,建议放在$base/etc/路径下)。在启动时需要指定my.cnf文件路径
[client]
port = 3307
socket = /var/lib/mysql/mysql.sock
# The MySQL server
[mysqld]
default-authentication-plugin=mysql_native_password #MySQL8的加密规则改变,如果要用老版的,需要加此句
port = 3307
mysqlx_port = 33070
user = root
socket = /var/lib/mysql/mysql.sock
mysqlx_socket=/var/lib/mysql/mysqlx.sock
pid-file = /usr/local/DBdatas/mysql8/mysql.pid
basedir = /usr/local/DBdatas/mysql8/
datadir = /usr/local/DBdatas/mysql8/data
tmpdir = /usr/local/DBdatas/mysql8/tmp
open_files_limit = 60000
explicit_defaults_for_timestamp
server-id = 1203307
lower_case_table_names = 1
character-set-server = utf8mb4
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 = /usr/local/DBdatas/mysql8/log/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 = /usr/local/DBdatas/mysql8/log/mysql-error.log
#slow_query_log = 1
#slow_query_log_file = /usr/local/DBdatas/mysql8/log/slow_statement.log
#log_queries_not_using_indexes
#general_log = 0
#general_log_file = /usr/local/DBdatas/mysql8/log/general_statement.log
#expire-logs-days = 14
#binlog_expire_logs_seconds = 1728000
#relay-log = /usr/local/DBdatas/mysql8/log/binlog/relay-bin
#relay-log-index = /usr/local/DBdatas/mysql8/log/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 = /usr/local/DBdatas/mysql8/innodb_ts
innodb_data_home_dir = /usr/local/DBdatas/mysql8/data
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 = /usr/local/DBdatas/mysql8/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 = (\u@\h) [\d]>\_
3. 启动数据库
#启动8
/usr/local/DBdatas/mysql8/bin/mysqld_safe --defaults-file=/usr/local/DBdatas/mysql8/my.cnf --datadir=/usr/local/DBdatas/mysql8/data --socket=/var/lib/mysql/mysql.sock --basedir=/usr/local/DBdatas/mysql8 --user=mysql --port=3307
如果需要跳过密码认证,可以修改my.cnf配置文件,添加skip-grant-tables,或在启动时添加参数—-skip-grant-tables
4. 连接数据库
==注意此处需要先进入对应版本的bin目录,再连接数据库。遇到的坑为在安装8.0版本后,没有进入bin目录启动mysql8,导致启动后密码校验规则一直为
caching_sha2_password,无法变更为兼容老版的mysql_native_password,导致登陆时一直报错。只有这样,在my.cnf中配置的default-authentication-plugin=mysql_native_password参数才会生效== 报错如下:查看简要规则如下:
mysql> use mysql; --切换到mysql库 mysql>SELECT Host, User, plugin from user;
正式执行下面代码:
#因为多版本,启动时需要先进入bin目录,防止引用了其他版本的配置文件
[root@WXB-QZ-1-5 database_bak]# cd /usr/local/DBdatas/mysql8/bin/
#进入bin目录后,指定mysql8的sock文件登陆
[root@WXB-QZ-1-5 bin]# ./mysql -u root -p -S /var/lib/mysql/mysql.sock
Enter password: #此处输入前面的临时密码登陆
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>alter user user() identified by "root";
mysql>use mysql;
# 不修改原root的localhost的远程权限,单独创建一个root@%
mysql> CREATE USER 'root'@'%' IDENTIFIED BY 'password';
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION ;
mysql>flush privileges; #刷新权限