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

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