亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

MySQL運(yùn)維實(shí)戰(zhàn)之使用二進(jìn)制安裝部署

 更新時(shí)間:2023年12月24日 12:02:41   作者:云掣科技?俊達(dá)  
這篇文章主要為大家介紹了MySQL運(yùn)維實(shí)戰(zhàn)之使用二進(jìn)制安裝部署示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

引言

上一篇我們使用了RPM進(jìn)行安裝部署,這是一種安裝快速、簡化部署和管理過程、與操作系統(tǒng)提供的包管理工具緊密集成的部署方法。此外,當(dāng)你需要更高的靈活性和自定義性,并且愿意承擔(dān)一些額外的手動(dòng)配置和管理工作,那么二進(jìn)制安裝是一個(gè)值得考慮選擇。

以下是二進(jìn)制安裝的一些優(yōu)勢(shì):

  • 處理單機(jī)多實(shí)例:在某些情況下,希望在一臺(tái)計(jì)算機(jī)上開啟多個(gè)不同的服務(wù)器 ,運(yùn)行多個(gè)MySQL服務(wù)進(jìn)程,同時(shí)保持現(xiàn)有的生產(chǎn)設(shè)置不受干擾。使用二進(jìn)制方式可以在單臺(tái)機(jī)器上部署多個(gè)實(shí)例,無需額外的配置。
  • 簡化升級(jí)過程:在生產(chǎn)環(huán)境中,MySQL的升級(jí)是一個(gè)重要且敏感的操作。使用二進(jìn)制安裝,原地升級(jí)的方式更加方便。只需關(guān)閉舊的 MySQL 服務(wù)器、用新的替換舊的 MySQL 二進(jìn)制文件或軟件包、在現(xiàn)有數(shù)據(jù)目錄上重新啟動(dòng) MySQL,以及升級(jí)現(xiàn)有安裝中需要升級(jí)的任何剩余部分即可。

自定義編譯:有時(shí)候,可能需要對(duì)MySQL進(jìn)行一些特定的定制或打補(bǔ)丁,以滿足特定的業(yè)務(wù)需求。通過自己編譯二進(jìn)制文件,可以靈活地添加或修改功能,并滿足特殊需求。這種自定義編譯的方式可以讓MySQL更好地適應(yīng)不同的環(huán)境和需求。

1 下載二進(jìn)制文件

根據(jù)操作系統(tǒng)版本,下載二進(jìn)制包

下載其中的Compressed TAR,如:

2 解壓

將下載的二進(jìn)制文件下載到某個(gè)目錄。

一般我們會(huì)將mysql二進(jìn)制文件放到/usr/local/mysql 或者 /opt/mysql。

tar xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz -C /opt
mv  mysql-8.0.32-linux-glibc2.12-x86_64 mysql
ls /opt/mysql/
bin  docs  include  lib  LICENSE  man  README  share  support-files

3 準(zhǔn)備配置文件

我們規(guī)劃將MySQL數(shù)據(jù)庫文件放在/data/mysql01路徑下。

mysql數(shù)據(jù)目錄: /data/mysql01/
配置文件:/data/mysql01/my.cnf

[mysqld]
#dir
basedir=/opt/mysql
lc_messages_dir=/opt/mysql/share
datadir=/data/mysql01/data
tmpdir=/data/mysql01/tmp
log-error=/data/mysql01/log/alert.log
slow_query_log_file=/data/mysql01/log/slow.log
general_log_file=/data/mysql01/log/general.log
socket=/data/mysql01/run/mysql.sock
#innodb
innodb_data_home_dir=/data/mysql01/data
innodb_log_group_home_dir=/data/mysql01/data
innodb_data_file_path=ibdata1:128M:autoextend

配置文件核心內(nèi)容是[mysqld]下的相關(guān)路徑配置:

basedir: mysql二進(jìn)制文件路徑
datadir: mysql數(shù)據(jù)目錄

這里只配置了啟動(dòng)MySQL需要的最基本的參數(shù)。

真實(shí)環(huán)境中,需要根據(jù)業(yè)務(wù)需求和服務(wù)器配置優(yōu)化配置,后續(xù)單獨(dú)講。

4初始化數(shù)據(jù)庫

-- 創(chuàng)建mysql用戶
groupadd mysql
useradd mysql -g mysql
-- 創(chuàng)建相關(guān)目錄
mkdir -p /data/mysql01/{data,binlog,log,run,tmp}
chown -R mysql:mysql /data/mysql01
-- 初始化數(shù)據(jù)庫
./bin/mysqld --defaults-file=/data/mysql01/my.cnf --initialize --user=mysql

初始化完成后,查看alert.log中的臨時(shí)密碼

tail /data/mysql01/log/alert.log

2021-03-29T11:20:45.693865Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-03-29T11:20:45.789596Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-03-29T11:20:45.865865Z 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: ce7101f3-9080-11eb-9d26-080027475f71.
2021-03-29T11:20:45.869311Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-03-29T11:20:46.234753Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-29T11:20:46.286920Z 1 [Note] A temporary password is generated for root@localhost: kguRrCbXw9;

5 啟動(dòng)實(shí)例

mysql服務(wù)器進(jìn)程是mysqld, 可以通過執(zhí)行mysqld命令直接啟動(dòng)數(shù)據(jù)庫,當(dāng)然通常我們會(huì)使用一些封裝過的腳本來啟動(dòng)mysql。
mysqld_safe就是一個(gè)常用的腳本,它能啟動(dòng)mysqld,并在mysqld異常退出后重新啟動(dòng)mysqld

[root@box1 ~]# ./bin/mysqld_safe --defaults-file=/data/mysql01/my.cnf &
[1] 27896
[root@box1 ~]# 2021-03-29T11:24:31.202499Z mysqld_safe Logging to '/data/mysql01/log/alert.log'.

通過ps,可以看到mysqld進(jìn)程,以及命令行參數(shù),mysqld_safe是mysqld的父進(jìn)程。

[root@box1 mysql]# ps -elf | grep mysqld
4 S root      6445  2276  0  80   0 - 28354 do_wai 05:20 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql01/my.cnf
4 S mysql     6738  6445  0  80   0 - 518211 poll_s 05:20 pts/0   00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql01/my.cnf --basedir=/usr/local --datadir=/data/mysql01/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql01/log/alert.log --pid-file=box1.pid --socket=/data/mysql01/run/mysql.sock
0 S root      6784  2276  0  80   0 - 28206 pipe_w 05:21 pts/0    00:00:00 grep --color=auto mysqld

可以看到mysqld命令行的關(guān)鍵參數(shù)

–defaults-file: 啟動(dòng)參數(shù)文件
–basedir: mysql軟件的basedir
–datadir: 數(shù)據(jù)目錄
–plugin-dir: mysql插件lib庫路徑
–user: 運(yùn)行mysql的OS賬號(hào)
–log-error: 錯(cuò)誤日志路徑
–socket: socket連接文件

如果不提供這些參數(shù),mysqld會(huì)使用編譯時(shí)的默認(rèn)參數(shù)。

默認(rèn)參數(shù):

[root@box1 mysql]# ./bin/mysqld  --print-defaults
./bin/mysqld would have been started with the following arguments:
--datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --symbolic-links=0

默認(rèn)參數(shù)文件路徑:

[root@box1 mysql]# ./bin/mysqld  --verbose --help | more
2021-03-31T09:33:30.820738Z 0 [ERROR] COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8mb4'
./bin/mysqld  Ver 5.7.32-debug for Linux on x86_64 (lazybug)
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.
Starts the MySQL database server.
Usage: ./bin/mysqld [OPTIONS]
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.7
The following options may be given as the first argument:
--print-defaults        Print the program argument list and exit.
--no-defaults           Don't read default options from any option file,
                        except for login file.
--defaults-file=#       Only read default options from the given file #.

通過mysqld --verbose --help可以看到參數(shù)文件搜索路徑:

/etc/my.cnf, /etc/mysql/my.cnf, /usr/local/mysql/etc/my.cnf, ~/.my.cnf

在運(yùn)維多實(shí)例mysql時(shí),我們通常會(huì)指定my.cnf的路徑,而不使用默認(rèn)路徑的配置文件。

避免讀取默認(rèn)配置參數(shù)文件中的配置,引起各種問題。

加了–defaults-file后,就只會(huì)從defaults-file指定文件中讀取配置。

日志文件

如果啟動(dòng)過程中有問題,可以通過alert日志文件查看具體的問題

$ tail -100 /data/mysql01/log/alert.log

2021-03-29T11:24:31.229330Z mysqld_safe Starting mysqld daemon with databases from /data/mysql01/data
2021-03-29T11:24:31.407665Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.32-debug) starting as process 28189 ...
2021-03-29T11:24:31.412908Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-03-29T11:24:31.412934Z 0 [Note] InnoDB: !!!!!!!! UNIV_DEBUG switched on !!!!!!!!!
2021-03-29T11:24:31.412939Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-03-29T11:24:31.412942Z 0 [Note] InnoDB: Uses event mutexes
2021-03-29T11:24:31.412947Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-03-29T11:24:31.412950Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-03-29T11:24:31.412954Z 0 [Note] InnoDB: Using Linux native AIO
2021-03-29T11:24:31.413276Z 0 [Note] InnoDB: Number of pools: 1
2021-03-29T11:24:31.413391Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-03-29T11:24:31.414823Z 0 [Note] InnoDB: Initializing buffer pool, total size = 512M, instances = 1, chunk size = 128M
2021-03-29T11:24:31.589281Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-03-29T11:24:31.594759Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-03-29T11:24:31.611389Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-03-29T11:24:31.667674Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-03-29T11:24:31.667861Z 0 [Note] InnoDB: Setting file '/data/mysql01/data/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-03-29T11:24:31.680116Z 0 [Note] InnoDB: File '/data/mysql01/data/ibtmp1' size is now 12 MB.
2021-03-29T11:24:31.685528Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-03-29T11:24:31.685540Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-03-29T11:24:31.689004Z 0 [Note] InnoDB: Waiting for purge to start
2021-03-29T11:24:31.741474Z 0 [Note] InnoDB: 5.7.32 started; log sequence number 2746702
2021-03-29T11:24:31.742643Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql01/data/ib_buffer_pool
2021-03-29T11:24:31.742725Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-03-29T11:24:31.752433Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210329  7:24:31
2021-03-29T11:24:31.757409Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-03-29T11:24:31.757426Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-03-29T11:24:31.758133Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-29T11:24:31.758185Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-03-29T11:24:31.758504Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2021-03-29T11:24:31.759379Z 0 [Note] IPv6 is available.
2021-03-29T11:24:31.759408Z 0 [Note]   - '::' resolves to '::';
2021-03-29T11:24:31.759434Z 0 [Note] Server socket created on IP: '::'.
2021-03-29T11:24:31.796451Z 0 [Note] Event Scheduler: Loaded 0 events
2021-03-29T11:24:31.796935Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.7.32-debug'  socket: '/data/mysql01/run/mysql.sock'  port: 3306  lazybug

日志文件最后一行顯示啟動(dòng)成功,提示本地socket文件路徑和監(jiān)聽端口。

6 修改密碼

mysql 5.7開始,需要先修改密碼,才能正常訪問數(shù)據(jù)庫:

[root@box1 run]# /usr/local/mysql/bin/mysql -uroot -h127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.32-debug
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> select 1;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by 'helloworld';
Query OK, 0 rows affected (0.00 sec)
mysql> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

以上就是MySQL運(yùn)維實(shí)戰(zhàn)之使用二進(jìn)制安裝部署的詳細(xì)內(nèi)容,更多關(guān)于MySQL二進(jìn)制安裝部署的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • MySQL數(shù)據(jù)庫事務(wù)與鎖深入分析

    MySQL數(shù)據(jù)庫事務(wù)與鎖深入分析

    這篇文章主要介紹了MySQL數(shù)據(jù)庫事務(wù)與鎖深入分析,內(nèi)容介紹的非常詳細(xì),有對(duì)這方面不懂的同學(xué)可以跟著小編一起研究下吧
    2020-12-12
  • Jmeter連接數(shù)據(jù)庫過程圖解

    Jmeter連接數(shù)據(jù)庫過程圖解

    這篇文章主要介紹了jmeter連接數(shù)據(jù)庫過程圖解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • MYSQL單表操作學(xué)習(xí)之DDL、DML及DQL語句示例

    MYSQL單表操作學(xué)習(xí)之DDL、DML及DQL語句示例

    DML、DDL、DCL和DQL是數(shù)據(jù)庫中常用的四種語言,分別用于數(shù)據(jù)操作、數(shù)據(jù)定義、數(shù)據(jù)控制和數(shù)據(jù)查詢,下面這篇文章主要給大家介紹了關(guān)于MYSQL單表操作學(xué)習(xí)之DDL、DML及DQL語句的相關(guān)資料,需要的朋友可以參考下
    2024-03-03
  • mysql 5.5 安裝配置圖文教程

    mysql 5.5 安裝配置圖文教程

    這篇文章主要為大家詳細(xì)介紹了mysql5.5安裝配置方法的圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • 一步步教你在Navicat上如何停止正在運(yùn)行的MYSQL語句

    一步步教你在Navicat上如何停止正在運(yùn)行的MYSQL語句

    很多時(shí)候我們會(huì)提交一些耗時(shí)比較長的sql,可能出現(xiàn)mysql服務(wù)器內(nèi)存或者CPU暴增,引起報(bào)警,甚至影響其他業(yè)務(wù),下面這篇文章主要給大家介紹了關(guān)于在Navicat上如何停止正在運(yùn)行的MYSQL語句的相關(guān)資料,需要的朋友可以參考下
    2023-03-03
  • MySQL動(dòng)態(tài)SQL拼接實(shí)例詳解

    MySQL動(dòng)態(tài)SQL拼接實(shí)例詳解

    動(dòng)態(tài)SQL呢?首先是SQL語句,是根據(jù)條件來拼接SQL,下面這篇文章主要給大家介紹了關(guān)于MySQL動(dòng)態(tài)SQL拼接的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • MySQL連接池DataSource的使用及實(shí)踐

    MySQL連接池DataSource的使用及實(shí)踐

    DruidDataSource作為一款優(yōu)秀的數(shù)據(jù)庫連接池組件,不僅提供了高效的連接管理,還包含了豐富的監(jiān)控和診斷功能,本文主要介紹了MySQL連接池DataSource的使用及實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • mysql?8.0.27?解壓版安裝配置方法圖文教程

    mysql?8.0.27?解壓版安裝配置方法圖文教程

    這篇文章主要為大家詳細(xì)介紹了mysql?8.0.27?解壓版安裝配置方法圖文教程,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • MySQL 隨機(jī)查詢數(shù)據(jù)與隨機(jī)更新數(shù)據(jù)實(shí)現(xiàn)代碼

    MySQL 隨機(jī)查詢數(shù)據(jù)與隨機(jī)更新數(shù)據(jù)實(shí)現(xiàn)代碼

    以下的文章主要講述的是MySQL隨機(jī)查詢數(shù)據(jù)、MySQL隨機(jī)更新數(shù)據(jù)的實(shí)際應(yīng)用以及對(duì)MySQL隨機(jī)查詢數(shù)據(jù)、MySQL隨機(jī)更新數(shù)據(jù)的實(shí)際應(yīng)用代碼的描述,以下就是文章的主要內(nèi)容描述,望你會(huì)有所收獲。
    2010-06-06
  • MYSQL WHERE語句優(yōu)化

    MYSQL WHERE語句優(yōu)化

    where優(yōu)化主要是在SELECT中,因?yàn)樗麄冏钪饕窃谀抢锸褂?,但是同樣的?yōu)化也可被用于DELETE和UPDATE語句。
    2009-03-03

最新評(píng)論