mysql 5.7.24的单机部署步骤

下载 MySQL

本文采用的Linux为是腾讯云 标准型S2 (1 核 1 GB) Centos 7.5 64位

 1.1 官网下载地址:

https://dev.mysql.com/downloads/mysql/5.7.html#downloads

 1.2 选择64位的

 1.3 说明

  该文档仅供参考,更多详细文档请查看官方文档

https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

2. 上传文件并解压到安装目录

 2.1  解压

[root@k8s-master3 ~]# cd /application/
[root@k8s-master3 application]# ls
mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
[root@k8s-master3 application]# tar zxf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz

 2.2 复制到指定目录

[root@k8s-master3 application]# mv mysql-5.7.36-linux-glibc2.12-x86_64 /usr/local/
[root@k8s-master3 application]# cd /usr/local/
[root@k8s-master3 local]# ln -s mysql-5.7.36-linux-glibc2.12-x86_64/ mysql

 2.4 解压目录结构

3. 添加用户组,用专门管理mysql,提高安全

 3.1 新建组

groupadd mysql

 3.2 新建用户

useradd -r -g mysql mysql

4. 修改mysql目录权限

 4.1 修改拥有者为mysql用户

[root@k8s-master3 mysql]# chown -fR mysql:mysql /usr/local/mysql/*
[root@k8s-master3 mysql]# ll /usr/local/mysql/
总用量 272
drwxr-xr-x  2 mysql mysql   4096 2月   8 09:39 bin
drwxr-xr-x  2 mysql mysql     55 2月   8 09:39 docs
drwxr-xr-x  3 mysql mysql   4096 2月   8 09:39 include
drwxr-xr-x  5 mysql mysql    230 2月   8 09:39 lib
-rw-r--r--  1 mysql mysql 259199 9月   7 13:26 LICENSE
drwxr-xr-x  4 mysql mysql     30 2月   8 09:39 man
-rw-r--r--  1 mysql mysql    566 9月   7 13:26 README
drwxr-xr-x 28 mysql mysql   4096 2月   8 09:39 share
drwxr-xr-x  2 mysql mysql     90 2月   8 09:39 support-files

 

5. 配置mysql服务

 5.1 将mysql/support-files下的mysql.server 复制到 /etc/init.d/下并自定义为mysql

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

 

 6. 配置mysql的配置文件

在其他版本的mysql 里面 support-files下有默认的配置文件,而5.7.24这个版本没有,需要自己准备,下面提供一份简单基本配置

在/etc/ 下新建my.cnf ,有些可能会提示已经存在,因为默认装的数据库配置文件也在,直接覆盖就行

 6.1  新建数据目录

[root@k8s-master3 mysql]# mkdir -p /data/mysql
[root@k8s-master3 init.d]# mkdir -p /data/mysql_binlogs
[root@k8s-master3 init.d]# mkdir -p /data/mysql_tmp
[root@k8s-master3 mysql]# chown -fR mysql:mysql /data
[root@k8s-master3 local]#  mkdir -p /var/log/mysql
[root@k8s-master3 local]# chown -fR mysql:mysql  /var/log/mysql

 6.2 编辑的内容

cat >/etc/my.cnf << EOF
[client]
##########################################################################
##                                                                       #
##                         MySQL Client                                  #
##                                                                       #
##########################################################################
port = 3306
socket = /data/mysql/mysql.sock
default-character-set = utf8
[mysql]
###########################################################################
###                                                                       #
###                         MySQL CMD                                     #
###                                                                       #
###########################################################################
default-character-set = utf8
prompt = \\u(\\d) \\R:\\m:\\s > \

[mysqld]
##########################################################################
##                                                                       #
##                         MySQL Server                                  #
##                                                                       #
##########################################################################
#
#########################################
##                                      #
##               General                #
##                                      #
#########################################
port = 3306
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/mysql3306.pid
basedir = /usr/local/mysql
datadir = /data/mysql
tmpdir = /data/mysql_tmp
character-set-server = utf8 
sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
transaction_isolation = READ-COMMITTED
#skip-locking
#skip-host-cache
skip-name-resolve
lower_case_table_names = 1
server-id = 1
#replicate-same-server-id = 0
#auto-increment-increment = 1
#auto-increment-offset    = 1
#log-slave-updates
#replicate-ignore-db = mysql  
log-bin-trust-function-creators = 1

#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=3000
#rpl_semi_sync_slave_enabled=1

#binlog-do-db=nmsdb
#binlog-ignore-db=mysql
binlog_cache_size = 2M
binlog_format = row
log-queries-not-using-indexes
log-bin = /data/mysql_binlogs/mysql-bin.log
relay-log = /data/mysql/slave-relay.log
relay-log-index = /data/mysql/slave-relay-log.index
expire_logs_days        = 10
max_binlog_size         = 50M
sync_binlog = 1
group_concat_max_len = 102400
innodb_print_all_deadlocks = 1
max_length_for_sort_data = 8M

#########################################
##                                      #
##       Network & Connection           #
##                                      #
#########################################
connect_timeout = 60
wait_timeout = 28800
max_connections = 2048
max_allowed_packet = 64M
max_connect_errors = 1000
tmp_table_size = 512M
max_heap_table_size = 256M
table_open_cache = 512
table_open_cache_instances = 4
open_files_limit = 5000
max_allowed_packet = 256M

#########################################
##                                      #
##                 Logs                 #
##                                      #
#########################################
#
###################     Error Log   #####################
log_error = error.log
log_error_verbosity = 2

###################     Slow Log   ######################
slow_query_log_file = /var/log/mysql/mysql-slow.log
slow_query_log = 1
long_query_time = 3
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_throttle_queries_not_using_indexes = 10
min_examined_row_limit = 100

#########################################
##                                      #
##                InnoDB                #
##                                      #
#########################################
innodb_data_home_dir = /data/mysql
innodb_data_file_path = ibdata1:128M;ibdata2:128M:autoextend
innodb_file_per_table = 1
innodb_status_file = 1
#innodb_additional_mem_pool_size = 128M
innodb_buffer_pool_size = 13G
innodb_flush_method = O_DIRECT
innodb_io_capacity = 500
innodb_io_capacity_max = 800
innodb_flush_log_at_trx_commit = 1
innodb_support_xa = 1
innodb_log_file_size = 1024M 
innodb_log_buffer_size = 16M
innodb_log_files_in_group = 3
#innodb_stats_update_need_lock = 0

#########################################
##                                      #
##          Thread & Buffer             #
##                                      #
#########################################
event_scheduler = 1
query_cache_size = 64M
query_cache_type = 1
thread_cache_size = 8
####
sort_buffer_size = 33554432
join_buffer_size = 134217728
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
innodb_flush_neighbors=2

[mysql.server]
user = mysql

[mysqldump]
quick
default-character-set = utf8
max_allowed_packet = 256M
EOF

 

7. 初始化数据库

 7.1 进入mysql/bin目录下,执行初始化

[root@k8s-master3 bin]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
## 查看初始化日志与root密码
[root@k8s-master3 bin]# cat  /data/mysql/error.log 
 100
 100
 100 200 300 400 500 600 700 800 900 1000
 100 200 300 400 500 600 700 800 900 1000
 100 200 300 400 500 600 700 800 900 1000
2022-02-08T03:13:10.098929Z 0 [Warning] InnoDB: New log files created, LSN=45791
2022-02-08T03:13:10.133257Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-02-08T03:13:10.216052Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0b401d9e-888d-11ec-806f-005056898ae5.
2022-02-08T03:13:10.216431Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-02-08T03:13:11.868158Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-02-08T03:13:11.868172Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-02-08T03:13:11.868930Z 0 [Warning] CA certificate ca.pem is self signed.
2022-02-08T03:13:12.086642Z 1 [Note] A temporary password is generated for root@localhost: ;dG9hmvhM=<L

 

8. 启动mysql服务

 8.1 执行启动命令

[root@k8s-master3 bin]# /etc/init.d/mysql start
Starting MySQL... SUCCESS!

 

9. 登录及远程配置

 9.1 登录

进入mysql/bin目录下执行

 9.2  修改密码

set password=password('新密码');

 9.4 设置远程访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '访问密码';

flush privileges;

 10.2 环境变量

  10.2.1 为了不用在mysql/bin目录下才能连接mysql 将mysql/bin目录设置到环境变量中

vi /etc/profile

  10.2.2 修改的内容

# mysql environment
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin

  10.2.3 更新环境变量

source /etc/profile

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章