centos 7 MysSQL 5.7.23 二进制安装

MySQL 5.7.23 二进制安装

CentOS 7 将默认数据库MySQL替换成了Mariadb
这里会从系统的环境准备开始一步一步安装。

环境准备

系统版本 内核版本 IP地址
Centos 7.5 4.18.9-1.el7.elrepo.x86_64 10.0.0.3

备注 该系统采用MINI最小化安装,安装之后对系统进行了最基础的优化操作,操作过程点击这里

删除系统自带的依赖包

[root@node soft]# rpm -qa | egrep 'mysql|mariadb'
mariadb-libs-5.5.56-2.el7.x86_64
[root@node soft]# rpm -qa | egrep 'mysql|mariadb' | xargs rpm -e --nodeps
[root@node soft]# rpm -qa | egrep 'mysql|mariadb'
[root@node soft]# 

创建MySQL运行用户

[root@node soft]# useradd -s /sbin/nologin -M mysql
[root@node soft]# grep mysql /etc/passwd
mysql:x:1000:1000::/home/mysql:/sbin/nologin

下载 MySQL

可以在mirrors.163.com的163源下载
下载地址
如果上面的下载地址失效了,则可以使用百度网盘:百度云盘
提取码:4qh6

[root@node soft]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@node soft]# ls
mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
# 解压
[root@node soft]# tar xf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz 
[root@node soft]# ls
mysql-5.7.23-linux-glibc2.12-x86_64  mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz

配置环境变量

[root@node soft]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /opt/mysql-5.7.23
[root@node soft]# cd /opt/
[root@node opt]# ls
mysql-5.7.23  soft
[root@node opt]# chown -R mysql.mysql mysql-5.7.23
[root@node opt]# ll
total 0
drwxr-xr-x 9 mysql mysql 129 Sep 30 10:33 mysql-5.7.23
drwxr-xr-x 2 root  root   56 Sep 30 10:34 soft
[root@node opt]# echo 'export PATH=$PATH:/opt/mysql-5.7.23/bin' >> /etc/profile
[root@node opt]# tail -1 /etc/profile
export PATH=$PATH:/opt/mysql-5.7.23/bin
[root@node opt]# source /etc/profile
[root@node opt]# mysql -V
mysql  Ver 14.14 Distrib 5.7.23, for linux-glibc2.12 (x86_64) using  EditLine wrapper

配置MySQL启动脚本并设置开机自启

二进制解压后的目录中,包括了MySQL的启动关闭脚本,可以使用,也可以自己写systemctl管理脚本

[root@node opt]# cd mysql-5.7.23/
[root@node mysql-5.7.23]# pwd
/opt/mysql-5.7.23
[root@node mysql-5.7.23]# ls
bin  COPYING  docs  include  lib  man  README  share  support-files
[root@node mysql-5.7.23]# cp support-files/mysql.server /etc/init.d/mysqld
[root@node mysql-5.7.23]# chmod +x /etc/init.d/mysqld
[root@node mysql-5.7.23]# sed -i 's#/usr/local/mysql#/opt/mysql-5.7.23#g' /etc/init.d/mysqld
[root@node mysql-5.7.23]# chkconfig --add mysqld
[root@node mysql-5.7.23]# chkconfig mysqld on
[root@node mysql-5.7.23]# chkconfig | grep mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off

初始化 MySQL

[root@node mysql-5.7.23]# pwd
/opt/mysql-5.7.23
[root@node mysql-5.7.23]# mkdir data
[root@node mysql-5.7.23]# mysqld --initialize  --user=mysql --basedir=/opt/mysql-5.7.23 --datadir=/opt/mysql-5.7.23/data

配置文件

[root@node mysql-5.7.23]# cat my.cnf 
[client]
socket = /tmp/mysql.sock
port=3306

[mysql]
default-character-set=utf8

[mysqld]
basedir=/opt/mysql-5.7.23
datadir=/opt/mysql-5.7.23/data
port=3306
pid-file=/opt/mysql-5.7.23/mysqld.pid
skip-name-resolve
socket = /tmp/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /opt/mysql-5.7.23/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log = 80
flush_time = 0
join_buffer_size = 128M
max_allowed_packet = 1024M
max_connect_errors = 2000
open_files_limit = 4161
query_cache_type = 0
sort_buffer_size = 32M
table_definition_cache = 1400
binlog_row_event_max_size = 8K
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error = /opt/mysql-5.7.23/error.log
pid-file = /opt/mysql-5.7.23/mysqld.pid

启动

[root@node mysql-5.7.23]# /etc/init.d/mysqld  start
Starting MySQL. SUCCESS! 
[root@node mysql-5.7.23]# ps aux|grep mysql
root       8356  1.2  0.1 113320  3128 pts/0    S    10:35   0:00 /bin/sh /opt/mysql-5.7.23/bin/mysqld_safe --datadir=/opt/mysql-5.7.23/data --pid-file=/opt/mysql-5.7.23/mysqld.pid
mysql      9102  5.2 14.4 1776888 291536 pts/0  Sl   10:35   0:00 /opt/mysql-5.7.23/bin/mysqld --basedir=/opt/mysql-5.7.23 --datadir=/opt/mysql-5.7.23/data --plugin-dir=/opt/mysql-5.7.23/lib/plugin --user=mysql --log-error=/opt/mysql-5.7.23/error.log --open-files-limit=4161 --pid-file=/opt/mysql-5.7.23/mysqld.pid --socket=/tmp/mysql.sock --port=3306
root       9132  0.0  0.1 112716  2188 pts/0    S+   10:35   0:00 grep --color=auto mysql
[root@node mysql-5.7.23]# mysql
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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>show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.                  # 使用默认密码第一次登录,需要重置 root 密码
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

查看日志

[root@node mysql-5.7.23]# cat error.log 
2018-10-08T02:35:19.046722Z 0 [Warning] '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.
2018-10-08T02:35:19.046763Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2018-10-08T02:35:19.046778Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-10-08T02:35:19.046792Z 0 [Note] /opt/mysql-5.7.23/bin/mysqld (mysqld 5.7.23) starting as process 9102 ...
2018-10-08T02:35:19.064739Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-10-08T02:35:19.064772Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-10-08T02:35:19.064775Z 0 [Note] InnoDB: Uses event mutexes
2018-10-08T02:35:19.064777Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
2018-10-08T02:35:19.064780Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-10-08T02:35:19.064782Z 0 [Note] InnoDB: Using Linux native AIO
2018-10-08T02:35:19.064794Z 0 [Note] InnoDB: Adjusting innodb_buffer_pool_instances from 8 to 1 since innodb_buffer_pool_size is less than 1024 MiB
2018-10-08T02:35:19.065357Z 0 [Note] InnoDB: Number of pools: 1
2018-10-08T02:35:19.065416Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-10-08T02:35:19.066693Z 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2018-10-08T02:35:19.077288Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-10-08T02:35:19.079399Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-10-08T02:35:19.090732Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-10-08T02:35:19.096688Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-10-08T02:35:19.096750Z 0 [Note] InnoDB: Setting file '/opt/mysql-5.7.23/data/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-10-08T02:35:19.107248Z 0 [Note] InnoDB: File '/opt/mysql-5.7.23/data/ibtmp1' size is now 12 MB.
2018-10-08T02:35:19.107796Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-10-08T02:35:19.107804Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-10-08T02:35:19.108372Z 0 [Note] InnoDB: 5.7.23 started; log sequence number 2589252
2018-10-08T02:35:19.108585Z 0 [Note] InnoDB: Loading buffer pool(s) from /opt/mysql-5.7.23/data/ib_buffer_pool
2018-10-08T02:35:19.109989Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181008 10:35:19
2018-10-08T02:35:19.110083Z 0 [Note] Plugin 'FEDERATED' is disabled.
2018-10-08T02:35:19.112065Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2018-10-08T02:35:19.112078Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2018-10-08T02:35:19.112110Z 0 [Note] IPv6 is available.
2018-10-08T02:35:19.112115Z 0 [Note]   - '::' resolves to '::';
2018-10-08T02:35:19.112145Z 0 [Note] Server socket created on IP: '::'.
2018-10-08T02:35:19.117779Z 0 [Note] /opt/mysql-5.7.23/bin/mysqld: ready for connections.
Version: '5.7.23'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)
原文地址:https://www.cnblogs.com/winstom/p/9753146.html