记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

Centos7离线安装MySQL8 glibc数据库

一,背景说明。

1,客户经常有安装MySQL5.7或是MySQL8的服务请求,但是主机又无法上外网。所以只能通过安装glibc版本的mysql,如果使用RPM包安装,需要依赖不少软件包。

2,系统是Centos7,再安装MySQL5.7或是MySQL8。

二,安装方法。

1,下载mysql的软件包。

使用华为源下载,地址:(https://repo.huaweicloud.com/mysql/Downloads/MySQL-8.0/)

https://repo.huaweicloud.com/mysql/Downloads/MySQL-8.0/mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz

2,mysql glibc版本安装。

1.配置规划
默认安装目录:/data/mysql
数据文件目录:/data/mysql/data
MySQL占用端口:3306
默认socket文件存放路径:/tmp/mysql.sock,用于客户端与服务端通信的套接字文件
注意:需要关闭selinux。
2.命令使用
#创建目录并解压文件
mkdir /data
tar xvf mysql-8.0.29-linux-glibc2.12-x86_64.tar.xz -C /data

cd /data
mv mysql-8.0.29-linux-glibc2.12-x86_64  mysql

#创建数据目录与日志目录
mkdir -p /data/mysql/{data,logs}

#创建mysql用户组,mysql数据库用户
groupadd mysql
useradd -r -s /sbin/nologin mysql

#修改数据目录权限
chown -R mysql:mysql /data/mysql/data
chown -R mysql:mysql /data/mysql/logs


3,添加my.cnf配置文件.

#修改数据库配置文件 /etc/my.cnf
[mysqld]
#设置3306端口#port=3306
port=3306
user=mysql
#设置mysql的安装目录
basedir=/data/mysql
#设置mysql数据库的数据的存放目录
datadir=/data/mysql/data
#允许最大连接数
max_connections=500
#允许连接失败的次数。
max_connect_errors=10
#服务端使用的字符集默认为
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
#创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
#默认使用“mysql_native_password”插件认证#mysql_native_password#
default_authentication_plugin=mysql_native_password
lower_case_table_names=1
max_allowed_packet=16M
socket=/tmp/mysql.sock
log-error=/data/mysql/logs/error.log
pid-file=/data/mysql/mysql.pid
transaction_isolation=REPEATABLE-READ
sql_mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
[mysql]
#设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
#设置mysql客户端连接服务端时默认使用的端口
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8mb4

4,初始化数据库

#初始化命令
/data/mysql/bin/mysqld --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data --initialize

5,查看mysql的root账号密码

cat /data/mysql/logs/error.log  |grep password | awk '{print $NF}'

6, 启动服务文件配置

cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld

#将配置文件中的/usr/local/mysql 修改成 /data/mysql,这里不再具体说了。

#mysqld服务开机启动
chkconfig mysqld on

#启动数据库
/etc/init.d/mysqld start 

7,环境变量添加mysql执行命令

#根据情况添加,如下
vi /etc/profile

export PATH=/data/mysql/bin:$PATH

#启用环境变量
source /etc/profile

 

8,启动数据库并修改密码与权限。

/etc/init.d/mysqld start
#启动数据库服务.

mysql -u root -p  
#提示输入密码时直接敲回车,刚刚已经将密码置空了

use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'abc132451@';	
# 修改密码,密码形式过于简单则会报错

update user set host = '%'  where user ='root';
# 修改root账号远程登陆权限。

MySQL> flush privileges;
#再使用[flush privileges]从mysql数据库的grant表中重新加载权限数据

/etc/init.d/mysqld restart
#重启数据库服务.

9,开启防火墙端口

firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload

10,附加bt面板使用的my.cnf配置文件内容,也是本次安装所使用的配置配置文件内容。

[client]
#password	= your_password
port		= 3306
socket		= /tmp/mysql.sock

[mysqld]

#skip-grant-tables

port		= 3306
socket		= /tmp/mysql.sock
basedir= /data/mysql
datadir = /data/mysql/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 64M
max_allowed_packet = 100G
table_open_cache = 256
sort_buffer_size = 1M
net_buffer_length = 4K
read_buffer_size = 1M
read_rnd_buffer_size = 256K
myisam_sort_buffer_size = 16M
thread_cache_size = 32
tmp_table_size = 64M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

log-error=/data/mysql/logs/error.log

log-bin=mysql-bin
binlog_format=mixed
server-id = 1
binlog_expire_logs_seconds = 600000
slow_query_log=1
slow-query-log-file=/data/mysql/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""

innodb_data_home_dir = /data/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /data/mysql/data
innodb_buffer_pool_size = 256M
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 64M
sort_buffer_size = 1M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

 

10,4-8G内存的主机mysql优化方案,mysql需要使用3.5G内存。


[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock


[mysqld]
binlog_cache_size = 128K
thread_stack = 256K
join_buffer_size = 2048K
max_heap_table_size = 512M
port = 3306
socket = /tmp/mysql.sock
log_timestamps=SYSTEM
datadir = /www/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
skip-external-locking
key_buffer_size = 384M
max_allowed_packet = 100G
table_open_cache = 384
sort_buffer_size = 1024K
net_buffer_length = 4K
read_buffer_size = 1024K
read_rnd_buffer_size = 768K
myisam_sort_buffer_size = 8M
thread_cache_size = 128
tmp_table_size = 512M
default_authentication_plugin = mysql_native_password
lower_case_table_names = 1
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES


explicit_defaults_for_timestamp = true
#skip-name-resolve
max_connections = 300
max_connect_errors = 100
open_files_limit = 65535


log-bin=mysql-bin
binlog_format=mixed
server-id = 1
binlog_expire_logs_seconds = 600000
slow_query_log=1
slow-query-log-file=/www/data/mysql-slow.log
long_query_time=3
#log_queries_not_using_indexes=on
early-plugin-load = ""


innodb_data_home_dir = /www/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /www/data
innodb_buffer_pool_size = 512M
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_max_dirty_pages_pct = 90
innodb_read_io_threads = 2
innodb_write_io_threads = 2


[mysqldump]
quick
max_allowed_packet = 500M


[mysql]
no-auto-rehash


[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 768K
read_buffer = 2M
write_buffer = 2M


[mysqlhotcopy]
interactive-timeout



转载请标明出处【Centos7离线安装MySQL8 glibc数据库】。

《www.92cto.com》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论