Electron: 如何以 Vue.js, Vuetify 開始應用

  • Electron: 使用 JavaScript, HTML 和 CSS 等 Web 技術創建原生程序的框架
  • Vue.js: Web 前端用於構建用戶界面的漸進式框架
  • Vuetify: Vue.js 的 Material Design 組件框架

看完以上介紹,也明白了本文要做的事:用 Vue.js 與 Vuetify 組件,基於 Electron 來創建原生桌面應用。

  • 環境準備
    • Visual Studio Code
    • Node.js
    • Yarn
    • Vue CLI
  • 創建 Vue.js 應用
  • 添加 Vuetify 組件
  • 添加 Electron 構建
  • 發布 Electron 應用
  • 參考
  • 結語

環境準備

Visual Studio Code

建議使用的 VS Code 編輯代碼,下載地址: https://code.visualstudio.com/ 。

同時可安裝如下些擴展:

  • ESLint: 代碼檢查
  • Prettier – Code formatter: 代碼格式化
  • Vetur: Vue 代碼工具
  • Vue 2 Snippets: Vue 代碼提示(可選)

查看 VS Code 版本:

$ code -v
1.46.1
cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
x64

Node.js

Node.js 開發環境,下載地址: https://nodejs.org/en/download/ 。

建議選擇 Latest LTS Version ,因為 Electron v9 仍舊使用的 Node.js v12 。

查看 Node, NPM 版本:

$ node -v
v12.18.1

$ npm -v
6.14.5

Yarn

Yarn 包管理工具,相比 NPM 而言: Fast, Reliable, Secure 。

GitHub: https://github.com/yarnpkg/yarn

全局安裝 Yarn :

npm config set registry https://registry.npm.taobao.org
npm install -g yarn

查看 Yarn 版本:

$ yarn -v
1.22.4

Vue CLI

Vue CLI 是 Vue.js 開發的標準工具。

GitHub: https://github.com/vuejs/vue-cli

全局安裝 Vue CLI :

yarn global add @vue/cli

查看 Vue CLI 版本:

$ vue -V
@vue/cli 4.4.6

創建 Vue.js 應用

vue create my-app

跟隨引導進行工程配置,如下:

Vue CLI v4.4.6
? Please pick a preset: Manually select features
? Check the features needed for your project: Babel, TS, Router, Vuex, Linter
? Use class-style component syntax? Yes
? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes
? Use history mode for router? (Requires proper server setup for index fallback in production) Yes
? Pick a linter / formatter config: Prettier
? Pick additional lint features: Lint on save
? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files
? Save this as a preset for future projects? No
? Pick the package manager to use when installing dependencies: Yarn

~/.vuerc 會保存一些可復用的 preset :

$ cat ~/.vuerc
{
  "useTaobaoRegistry": true,
  "packageManager": "yarn"
}

運行應用:

cd my-app
yarn serve

瀏覽器打開 http://localhost:8080/

添加 Vuetify 組件

Vuetify 是 Vue.js 的 Material Design 組件庫。也可以換用其他的,如 Element 等。

GitHub: https://github.com/vuetifyjs/vuetify

添加 Vuetify :

cd my-app
vue add vuetify

preset 選擇 Default

? Choose a preset: Default (recommended)

添加完成后,編輯下 tsconfig.json

{
  "compilerOptions": {
    ...
    "types": [
-      "webpack-env"
+      "webpack-env",
+      "vuetify"
    ],
    ...
  },
  ...
}

運行應用:

yarn serve

瀏覽器打開 http://localhost:8080/

編輯 tsconfig.json 是為了修正如下錯誤

ERROR in /Users/John/Codes/ikuokuo/start-electron/my-app/src/plugins/vuetify.ts(2,21):
2:21 Could not find a declaration file for module 'vuetify/lib'. '/Users/John/Codes/ikuokuo/start-electron/my-app/node_modules/vuetify/lib/index.js' implicitly has an 'any' type.
  Try `npm install @types/vuetify` if it exists or add a new declaration (.d.ts) file containing `declare module 'vuetify/lib';`
    1 | import Vue from "vue";
  > 2 | import Vuetify from "vuetify/lib";
      |                     ^
    3 |
    4 | Vue.use(Vuetify);
    5 |

添加 Electron 構建

如果你可以建一個網站,你就可以建一個桌面應用程序。 Electron 負責將 Web 構建成原生桌面應用。

而將 Vue.js 應用構建成 Electron 應用,現在用 Vue CLI Plugin Electron Builder 即可。

首先,指明下 node 版本:

yarn add @types/node@12 --dev

之後,添加 Electron Builder :

cd my-app
vue add electron-builder

Electron 版本選擇 9.0.0

? Choose Electron Version ^9.0.0

添加完成后,編輯下 src/router/index.ts

...
const router = new VueRouter({
-  mode: "history",
+  mode: process.env.IS_ELECTRON ? "hash" : "history",
  base: process.env.BASE_URL,
  routes
});

export default router;

運行應用:

yarn electron:serve

現在是桌面窗口了:

命令定義在了 package.json

{
  ...
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "electron:build": "vue-cli-service electron:build",
    "electron:serve": "vue-cli-service electron:serve",
    "postinstall": "electron-builder install-app-deps",
    "postuninstall": "electron-builder install-app-deps"
  },
  ...
}

yarn 執行即可,如下:

$ yarn lint
yarn run v1.22.4
$ vue-cli-service lint
 DONE  No lint errors found!
  Done in 3.17s.

yarn add @types/node@12 --dev 是為了修正如下錯誤

ERROR in /Users/John/Codes/ikuokuo/start-electron/my-app/node_modules/electron/electron.d.ts(1659,31):
1659:31 Cannot extend an interface 'NodeJS.EventEmitter'. Did you mean 'implements'?
...

編輯 src/router/index.ts 是為了修正如下警告

 WARN  It is detected that you are using Vue Router. If you are using history mode, you must push the default route when the root component is loaded. Learn more at https://goo.gl/GM1xZG .

發布 Electron 應用

Vue 應用了 Electron Builder 插件,所以直接用此工具即可。

GitHub: https://github.com/electron-userland/electron-builder

yarn electron:build 編譯發布:

# 淘寶鏡像,國內下載 Electron 更快
export ELECTRON_MIRROR="https://cdn.npm.taobao.org/dist/electron/"

# macOS 下禁用簽名。若要簽名,見最後參考
export CSC_IDENTITY_AUTO_DISCOVERY=false

cd my-app
yarn electron:build

dist_electron/ 下即是發布內容。

例如 macOS 可見打包好的 dmg

雙擊 dmg 試用或安裝:

若要修改發布格式或內容,見 Electron Builder 文檔: https://www.electron.build/ 。

export CSC_IDENTITY_AUTO_DISCOVERY=false 是為了避免如下錯誤

...
  • signing         file=dist_electron/mac/my-app.app identityName=gdb_codesign identityHash=BC899AF362F80B3FDB39F966A1601E2AFAFA100B provisioningProfile=none
(node:10223) UnhandledPromiseRejectionWarning: Error: Command failed: codesign --sign BC899AF362F80B3FDB39F966A1601E2AFAFA100B --force --timestamp --options runtime --entitlements /Users/John/Workspace/Codes/start-electron/my-app/node_modules/app-builder-lib/templates/entitlements.mac.plist /Users/John/Workspace/Codes/start-electron/my-app/dist_electron/mac/my-app.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Helpers/chrome_crashpad_handler
error: The specified item could not be found in the keychain.
...
(node:10223) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10223) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

參考

  • electron-app
  • start-electron
  • Electron
    • Application Distribution
  • Electron Builder
    • Code Signing
    • Notarize app for macOS

結語

Go coding!

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※為什麼 USB CONNECTOR 是電子產業重要的元件?

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想要讓你的商品成為最夯、最多人討論的話題?網頁設計公司讓你強力曝光

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

新北清潔公司,居家、辦公、裝潢細清專業服務

GraphicsLab Project 之 Screen Space Planar Reflection

作者:i_dovelemon

日期:2020-06-23

主題:Screen Space Planar Reflection, Compute Shader

引言

        前段時間,同事發來一篇講述特化版本的 Screen Space Reflection 實現 Planar Reflection 的文章。出於好奇,實驗了下,看看效果如何。如下是目前實現出來的基礎版本的效果:

 原理

        對於上圖來說, Water Plane 表示水面,上半部分為實際場景的山體,下半部分為以水面為鏡像進行反射之後的山體效果。

        對於山體上某一個點(圖中白色點)來說,它對應的鏡像點為黃色點。

        我們可以從 Screen Position 以及 Depth Texture 信息,計算出來白點的世界坐標位置 WorldPosition

        然後可以以 Water Plane 所在的平面對該 WorldPosition 作鏡像操作,得到 ReflectionPosition

        得到 ReflectionPosition 之後,我們就能夠計算出來 ReflectionPostion 所對應的屏幕坐標 Reflection Screen Position

        根據前面的操作,我們就可以知道,此時 Reflection Screen Position 所反射的顏色即為 Screen Positon 所表示的顏色。

        基礎原理十分簡單,但是實際實現的時候,會發現有很多問題。接下里一一講述。

問題

閃爍

        根據上面的原理,可以想到,有多個像素可能會被反射到相同的位置,如下圖所示:

         這樣由於 GPU 執行順序的不確定性,就會導致畫面出現閃爍,如下所示:

        針對這樣的問題,我們實際需要的反射點是最近的反射點。可以考慮使用 HLSL 中提供的 InterlockedMin/InterlockedMax (參考[1],[2]) 之類的指令,在寫入數據時進行大小比較,從而實現保存最近反射點的功能。

        前面的指令雖然能夠實現大小比較,以此進行排序。但是根據前面的描述,我們實際保存的是反射點的顏色。沒有辦法只根據顏色進行排序,所以我們需要保存其他便於排序的信息,這裏選擇使用反射點的 Screen Position。並且按照如下方式進行編碼,從而實現獲取最近反射點的效果:

                        uint2 SrcPosPixel = uint2(DepthPos.x, DepthPos.y);
                        uint2 ReflPosPixel = ReflPosUV * uint2(ReflectWidth, ReflectHeight);

                        int Hash = SrcPosPixel.y << 16 | SrcPosPixel.x;
                        int dotCare = 0;
                        InterlockedMin(HashResult[ReflPosPixel], Hash, dotCare);

Encode and Sort

孔洞

        根據先前算法的描述,我們知道,我們先要根據 Depth 信息和 Screen Position 信息計算出 World Positon,然後鏡像之後,在轉化為新的屏幕坐標。在這一系列操作中,由於數值計算的不精確性,導致有些地方沒有存儲到有效的反射點位置信息,從而導致最終显示時畫面上有孔洞的情況,如下圖所示:

        幸運的是,從結果看這些孔洞並不會聚集在一起,形成大塊的黑塊。對於這種情況,我們只要在生成反射貼圖的時候,檢測到沒有保存有效位置信息時,遍歷下周圍的像素,尋找到一個擁有有效像素的值即可解決這個問題,如下代碼所示:

        uint Hash = HashTexture[id.xy].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x, id.y + 1)].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x, id.y - 1)].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x + 1, id.y)].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x - 1, id.y)].x;

        if (Hash != 0x0FFFFFFF)
        {
            uint x = Hash & 0xFFFF;
            uint y = Hash >> 16;
            ReflectionTexture[id.xy] = ColorTexture[uint2(x, y)];
        }
        else
        {
            ReflectionTexture[id.xy] = float4(0.0f, 0.0f, 0.0f, 0.0f);
        }

Hole

        如下是修正孔洞之後的效果:

實現

        本文的代碼是使用 Unity 實現的,實現起來比較簡單。比較坑的地方在於 Unity 裏面獲取 Projection Matrix 要通過 GL.GetGPUProjectionMatrix (文獻[3]) 轉化一下才能變成傳遞到 GPU 上用於渲染的投影矩陣。如下是功能核心的 Compute Shader 代碼:

// Each #kernel tells which function to compile; you can have many kernels
#pragma enable_d3d11_debug_symbols
#pragma kernel SSPRClear_Main
#pragma kernel SSPRHash_Main
#pragma kernel SSPRResolve_Main

//-----------------------------------------------------------------
float4x4 VPMatrix;
float4x4 InvVPMatrix;
uint Width;
uint Height;
uint ReflectWidth;
uint ReflectHeight;

//--------------------------------------------------------------------
RWTexture2D<int> ClearHashTexture;

[numthreads(8, 8, 1)]
void SSPRClear_Main(uint3 id : SV_DispatchThreadID)
{
    if (id.x < ReflectWidth && id.y < ReflectHeight)
    {
        ClearHashTexture[id.xy] = 0x0FFFFFFF;
    }
}

//---------------------------------------------------------------
Texture2D<float> DepthTex;
RWTexture2D<int> HashResult;

#define DownSampleFactor (1)

float3 Unproject(float3 clip)
{
    float4 clipW = float4(clip, 1.0f);
    clipW = mul(InvVPMatrix, clipW);
    clipW.xyz = clipW.xyz / clipW.w;
    return clipW.xyz;
}

float2 Project(float3 world)
{
    float4 worldW = float4(world, 1.0f);
    worldW = mul(VPMatrix, worldW);
    worldW.xy = worldW.xy / worldW.w;
    worldW.xy = (worldW.xy + float2(1.0f, 1.0f)) / 2.0f;
    return worldW.xy;
}

[numthreads(8, 8, 1)]
void SSPRHash_Main(uint3 id : SV_DispatchThreadID)
{
    for (uint i = 0; i < DownSampleFactor; i++)
    {
        for (uint j = 0; j < DownSampleFactor; j++)
        {
            uint2 DepthPos = uint2(id.x * DownSampleFactor + i, id.y * DownSampleFactor + j);
            if (DepthPos.x < Width && DepthPos.y < Height)
            {
                float depth = DepthTex.Load(int3(DepthPos.x, DepthPos.y, 0)).x;

                if (depth > 0.0f)
                {
                    float2 uv = (DepthPos.xy * 1.0f) / float2(Width, Height);
                    uv = uv * 2.0f - float2(1.0f, 1.0f);
                    uv.y = -uv.y;

                    float3 PosWS = Unproject(float3(uv, depth));

                    if (PosWS.y > 0.0f)
                    {
                        float3 ReflPosWS = float3(PosWS.x, -PosWS.y, PosWS.z);
                        float2 ReflPosUV = Project(ReflPosWS);

                        uint2 SrcPosPixel = uint2(DepthPos.x, DepthPos.y);
                        uint2 ReflPosPixel = ReflPosUV * uint2(ReflectWidth, ReflectHeight);

                        int Hash = SrcPosPixel.y << 16 | SrcPosPixel.x;
                        int dotCare = 0;
                        InterlockedMin(HashResult[ReflPosPixel], Hash, dotCare);
                    }
                }
            }
        }
    }
}

//------------------------------------------------------------------------------
Texture2D<int> HashTexture;
Texture2D<float4> ColorTexture;
RWTexture2D<float4> ReflectionTexture;

[numthreads(8, 8, 1)]
void SSPRResolve_Main(uint3 id : SV_DispatchThreadID)
{
    if (id.x < ReflectWidth && id.y < ReflectHeight)
    {
        uint Hash = HashTexture[id.xy].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x, id.y + 1)].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x, id.y - 1)].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x + 1, id.y)].x;
        if (Hash == 0x0FFFFFFF)
            Hash = HashTexture[uint2(id.x - 1, id.y)].x;

        if (Hash != 0x0FFFFFFF)
        {
            uint x = Hash & 0xFFFF;
            uint y = Hash >> 16;
            ReflectionTexture[id.xy] = ColorTexture[uint2(x, y)];
        }
        else
        {
            ReflectionTexture[id.xy] = float4(0.0f, 0.0f, 0.0f, 0.0f);
        }
    }
}

ScreenSpacePlanarReflection

結論

        本文只是探索這個方法的可能性,更加複雜的實現,更加高效的優化可以參考文獻[4][5],這也是本文主要參考的對象。

        相比於傳統的繪製場景兩邊的方法來說,這個方案的性能更加高效,同時也沒有 SSR 那樣的高需求。在條件滿足的情況下,使用該方案能夠帶來顯著的效果提升,推薦可以嘗試。

        完整代碼在這裏:https://github.com/idovelemon/UnityProj/tree/master/ScreenSpacePlanarReflection

參考文獻

[1] HLSL-InterlockedMax

[2] HLSL-InterlockedMin

[3] GL.GetGPUProjectionMatrix

[4] Screen Space Planar Reflection

[5] Optimized Pixel Projected Reflections for Planar Reflectors

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

復育有望!首隻體外受精孵化的波多黎克鳳頭蟾蜍

摘錄自2019年11月25日自由時報德克薩斯州報導

美國研究人員多次嘗試復育瀕臨絕種的波多黎各鳳頭蟾蜍(Puerto Rican crested toad),日前沃思堡動物園(Fort Worth Zoo,Texas)利用從野外收集的冷凍精液通過體外受精首次成功地孵化了一隻蟾蜍。這次的成功也為全球僅存2400隻的波多黎各鳳頭蟾蜍復育計畫帶來一絲希望。

首隻由體外受精出生的蟾蜍雪寶(Olaf)。德州沃思堡動物園的外溫動物館長巴柏(Diane Barber)表示,園方通常不會為蟾蜍取名,但在經歷了多次的失敗後,雪寶的出生成為一個值得紀念的時刻。這隻蟾蜍是命名自冰雪奇緣(Frozen)中的角色雪寶,以紀念他來自冷凍精子。

波多黎各自然資源部(Department of Natural Resources)臨時秘書奧特羅(Armando Otero)表示,對於瀕臨滅絕的物種而言,這是一個重大進步,因為這項計畫將允許動物園、研究人員和其他保育人員擴大其遺傳種群,以增加總種群,同時又將蟾蜍留在其野生棲息地。

自2006年以來,沃斯堡動物園研究人員,配合執行波多黎各鳳頭蟾蜍保護計劃。 通過這項合作計劃,預計將300隻體外受精的蟾蜍,其中100隻透過圈養繁殖計劃送往其他動物園,其餘200頭蟾蜍將在12月通過聯邦快遞送往波多黎各以釋放到野外。

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※帶您來了解什麼是 USB CONNECTOR  ?

※自行創業 缺乏曝光? 下一步"網站設計"幫您第一時間規劃公司的門面形象

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

※綠能、環保無空污,成為電動車最新代名詞,目前市場使用率逐漸普及化

※廣告預算用在刀口上,網站設計公司幫您達到更多曝光效益

※教你寫出一流的銷售文案?

教宗東京彌撒 向使節演說談地球暖化

摘錄自2019年11月26日中央通訊社東京報導

教宗方濟各26日上午拜會日皇德仁,下午在東京巨蛋望彌撒,約5萬人參加。晚上到首相官邸(行政中心)與首相安倍晉三會談,之後出席與各國駐日使節的交流會並發表演說。

這是82歲的方濟各從2013年就任以來首度訪問日本,也是天主教教宗時隔38年訪日。

教廷派使節駐日今年是100週年,教廷希望能與日本加強邦誼,同時在裁軍、氣候變遷等國際課題上加強合作。方濟各與安倍在交流會上表示,日本與教廷在歷史上有許多交流機會,透過文化交流、外交使節往來,雙方關係深化,克服了很大的困難和緊張。

教宗也談到地球暖化的課題,表示地球不僅有大自然的災害,也受人類的手貪婪地榨取。世人不該把地球當成榨取之物,而是要把地球當成是要傳承給下一代的寶貴遺產。

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※為什麼 USB CONNECTOR 是電子產業重要的元件?

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想要讓你的商品成為最夯、最多人討論的話題?網頁設計公司讓你強力曝光

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

新北清潔公司,居家、辦公、裝潢細清專業服務

野豬殺人!美德州婦女遭多頭豬隻襲擊慘死

摘錄自2019年11月26日自由時報報導

美國德州錢伯斯郡阿納瓦克(Anahuac)發生罕見的動物襲擊案,幫忙照料一對老夫妻的59歲看護羅林斯(Christine Rollins)於24日上班時間遲遲沒有現身,84歲的屋主等不下去外出查看時,驚見她陳屍在屋外,目前當局認為她遭到多隻野豬攻擊死亡。

據《CNN》報導,錢伯斯郡警長霍桑(Brian Hawthorne)於25日的新聞發布會指出,羅林斯於24日清晨6時至6時30分左右,遭遇不同野豬的襲擊,當時外面天色還很黑。

霍桑指出,這是他從警35年以來所見過最糟糕的事情之一,法醫里弗斯(Selly Rivers)確認現場有多頭豬隻犯案,因為羅林斯身上的咬傷傷口大小不一。

德州公園和野生動物局的資料顯示,成年野豬的體重在100磅至400磅之間(約45.3公斤至181公斤)。霍桑則透露,野豬的確在德州造成問題,但很少出現襲擊人類的案件。

※ 本文與 行政院農業委員會 林務局   合作刊登

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

奧迪拚轉型電動車 六年內裁員9500人

摘錄自2019年11月26日聯合新聞網報導

德國車廠奧迪(Audi)今(26日)宣布,計劃在2025年底前裁減9500個職位。這項行動包括在奧迪的大規模企業重組計畫內,目標在2029年底前省下數十億歐元成本。

屬於德國福斯汽車集團(Volkswagen Group)的奧迪,正在進行昂貴且痛苦的企業轉型,由發展內燃機引擎動力車轉向發展電動車。

奧迪表示,將透過優退方案和自然人力更替達成裁員目標,但同時也會在電動車和數位化領域繼續雇用新人。減少人力的行動將讓奧迪「在德國的兩座工廠產能最佳化」。

奧迪還說:「因此產生的60億歐元(約新台幣2018億元)經費,將確保達成公司策略鎖定的9%-11%報酬率區間,並投入電動化和數位化等未來計畫。」

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※帶您來了解什麼是 USB CONNECTOR  ?

※自行創業 缺乏曝光? 下一步"網站設計"幫您第一時間規劃公司的門面形象

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

※綠能、環保無空污,成為電動車最新代名詞,目前市場使用率逐漸普及化

※廣告預算用在刀口上,網站設計公司幫您達到更多曝光效益

※教你寫出一流的銷售文案?

聯合國:2020起 每年需減碳7.6%才有機會避免氣候危機

環境資訊中心綜合外電;姜唯 編譯;林大利 審校

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※為什麼 USB CONNECTOR 是電子產業重要的元件?

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想要讓你的商品成為最夯、最多人討論的話題?網頁設計公司讓你強力曝光

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

新北清潔公司,居家、辦公、裝潢細清專業服務

野火過後恐現泥石流 加州聖巴巴拉發疏散警告

摘錄自2019年11月28日中央通訊社綜合報導

暴雨今天(27日)襲擊洛杉磯北部地區,讓與野火奮鬥的救災人員得以舒緩,但也帶來新的泥石流危險,迫使當局向17.5平方公里地區內的居民發布疏散警告。

「華爾街日報」(Wall Street Journal)報導,根據與消防員合作的氣象學家,190毫米的大雨凌晨1時開始襲擊加州聖巴巴拉(Santa Barbara),預料將降下更多雨勢。

因可能發生泥石流,聖巴巴拉郡警察局向凱夫大火(Cave Fire)及太平洋中間17.5平方公里內的居民發布疏散警告。泥石流可能發生在大雨過後、泥沙土石鬆軟的野火區域,並以危險的速度向下滑。

當局表示,本週到今天下午沒有發生泥石流,但威脅可能持續整個冬天,直到灌木叢重新開始在火災過後的地區生長。

聖巴巴拉郡消防局的蓋里(Tim Gailey)警告消防員,在路上保持警惕,特別是許多火災撤離者今天獲准返家時。他在大雨中表示:「會產生逕流、泥濘、砂石與樹木之類的東西,一起流到路上。」

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

※幫你省時又省力,新北清潔一流服務好口碑

※別再煩惱如何寫文案,掌握八大原則!

【String註解驅動開發】困擾了我很久的AOP嵌套調用終於解決了!

寫在前面

最近在分析Spring源碼時,在同一個類中寫了嵌套的AOP方法,測試時出現:Spring AOP在同一個類里自身方法相互調用時無法攔截。哎,怎麼辦?還能怎麼辦呢?繼續分析Spring源碼,解決問題唄。於是乎,有了本文。

項目工程源碼已經提交到GitHub:https://github.com/sunshinelyz/spring-annotation

問題闡述

Spring AOP在同一個類里自身方法相互調用時無法攔截。比如下面的代碼:

public class SomeServiceImpl implements SomeService  {  
    public void someMethod()  {  
        someInnerMethod();  
    }  
    public void someInnerMethod(){  
    }  
} 

兩個方法經過AOP代理,執行時都實現系統日誌記錄。單獨使用someInnerMethod時,沒有任何問題。但someMethod就有問題了。someMethod里調用的someInnerMethod方法是原始的,未經過AOP增強的。我們期望調用一次someMethod會記錄下兩條系統日誌,分別是someInnerMethod和someMethod的,但實際上只能記錄下someMethod的日誌,也就是只有一條。在配置事務時也可能會出現問題,比如someMethod方法是REQUIRED,someInnerMethod方法是REQUIRES_NEW,someInnerMethod的配置將不起作用,與someMethod方法會使用同一個事務,不會按照所配置的打開新事務。

問題分析

由於java這個靜態類型語言限制,最後想到個曲線救國的辦法,出現這種特殊情況時,不要直接調用自身方法,而通過AOP代理后的對象。在實現里保留一個AOP代理對象的引用,調用時通過這個代理即可。例如下面的代碼。

//從beanFactory取得AOP代理后的對象  
SomeService someServiceProxy = (SomeService)beanFactory.getBean("someService");   

//把AOP代理后的對象設置進去  
someServiceProxy.setSelf(someServiceProxy);   

//在someMethod裏面調用self的someInnerMethod,這樣就正確了  
someServiceProxy.someMethod();  

但這個代理對象還要我們手動set進來。有沒有更好的方式解決呢?

問題解決

幸好SpringBeanFactory有BeanPostProcessor擴展,在bean初始化前後會統一傳遞給BeanPostProcess處理,繁瑣的事情就可以交給程序了,代碼如下,首先定義一個BeanSelfAware接口,實現了此接口的程序表明需要注入代理后的對象到自身。

public class SomeServiceImpl implements SomeService,BeanSelfAware{  
	//AOP增強后的代理對象  
    private SomeService self;
    //實現BeanSelfAware接口  
    public void setSelf(Object proxyBean){  
        this.self = (SomeService)proxyBean  
    }  
    public void someMethod(){  
        //注意這句,通過self這個對象,而不是直接調用的  
        someInnerMethod();
    }  
    public void someInnerMethod(){  
    }  
}  

再定義一個BeanPostProcessor,beanFactory中的每個Bean初始化完畢后,調用所有BeanSelfAware的setSelf方法,把自身的代理對象注入自身。

public class InjectBeanSelfProcessor implements BeanPostProcessor  {     
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException{ 
        if(bean instanceof BeanSelfAware){  
            System.out.println("inject proxy:" + bean.getClass());  
            BeanSelfAware myBean = (BeanSelfAware)bean;  
            myBean.setSelf(bean);  
            return myBean;  
        }  
        return bean;  
    }  
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException{  
        return bean;  
    }  
}

最後,在BeanFactory配置中組合起來,只需要把BeanPostProcesser加進去就可以了,比平常多一行配置而已。

<!-- 注入代理后的bean到bean自身的BeanPostProcessor... -->  
<bean class=" org.mypackage.InjectBeanSelfProcessor"></bean>  

<bean id="someServiceTarget" class="org.mypackage.SomeServiceImpl" />   

<bean id="someService" class="org.springframework.aop.framework.ProxyFactoryBean">  
    <property name="target">  
        <ref local="someServiceTarget" />  
    </property>  
    <property name="interceptorNames">  
        <list>  
            <value>someAdvisor</value>  
        </list>  
    </property>  
</bean>  
<!-- 調用spring的DebugInterceptor記錄日誌,以確定方法是否被AOP增強 -->  
<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor" />  

<bean id="someAdvisor" class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">  
    <property name="advice">  
        <ref local="debugInterceptor" />  
    </property>  
    <property name="patterns">  
        <list>  
            <value>.*someMethod</value>  
            <value>.*someInnerMethod</value>  
        </list>  
    </property>  
</bean>  

這裏的someService#someInnerMethod就表現出預期的行為了,無論怎樣,它都是經過AOP代理的,執行時都會輸出日誌信息。

注意事項

用XmlBeanFactory進行測試需要注意,所有的BeanPostProcessor並不會自動生效,需要執行以下代碼:

XmlBeanFactory factory = new XmlBeanFactory(...);  
InjectBeanSelfProcessor postProcessor = new InjectBeanSelfProcessor();  
factory.addBeanPostProcessor(postProcessor);  

好了,咱們今天就聊到這兒吧!別忘了給個在看和轉發,讓更多的人看到,一起學習一起進步!!

項目工程源碼已經提交到GitHub:https://github.com/sunshinelyz/spring-annotation

寫在最後

如果覺得文章對你有點幫助,請微信搜索並關注「 冰河技術 」微信公眾號,跟冰河學習Spring註解驅動開發。公眾號回復“spring註解”關鍵字,領取Spring註解驅動開發核心知識圖,讓Spring註解驅動開發不再迷茫。

參考:iteye.com/blog/fyting-109236

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※帶您來了解什麼是 USB CONNECTOR  ?

※自行創業 缺乏曝光? 下一步"網站設計"幫您第一時間規劃公司的門面形象

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!!

※綠能、環保無空污,成為電動車最新代名詞,目前市場使用率逐漸普及化

※廣告預算用在刀口上,網站設計公司幫您達到更多曝光效益

※教你寫出一流的銷售文案?

Mariadb之日誌相關配置

  前面我們聊到了mariadb的事務,以及事務隔離級別,回顧請參考https://www.cnblogs.com/qiuhom-1874/p/13198186.html;今天我們來聊一聊mariadb的日誌相關話題;mariadb日誌有6種,分別是查詢日誌(general_log),慢查詢日誌(log_slow_queries),錯誤日誌(log_error,log_warnings),二進制日誌(binlog),中繼日誌(relay_log)和事務日誌(innodb_log);

  1、查詢日誌,主要記錄查詢語句,日誌存儲位置可放在表中,也可以放在文件中,這個要根據自己的配置,當然也可以同時放在表和文件中;一般情況服務器IO壓力不大的情況下是可以開啟查詢日誌的,如果服務器IO壓力大,建議不要開啟查詢日誌;具體配置方法如下

  把查詢日誌放在mysql庫的general_log 表中的配置方法:

  在/etc/my.cnf.d/server.cnf中的server配置段下添加如下配置,並重啟mariadb服務即可

  提示:以上配置表示開啟查詢日誌,日誌輸出到表;默認會把查詢日誌存放在mysql庫中的general_log表中;

  重啟服務,然後查看general_log表是否有數據?

[root@lxc my.cnf.d]# systemctl restart mariadb
[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select * from mysql.general_log ;
+----------------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
| event_time                 | user_host                 | thread_id | server_id | command_type | argument                         |
+----------------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
| 2020-06-28 09:14:33.402211 | [root] @ localhost []     |         3 |         3 | Connect      | root@localhost on  using Socket  |
| 2020-06-28 09:14:33.409731 | root[root] @ localhost [] |         3 |         3 | Query        | select @@version_comment limit 1 |
| 2020-06-28 09:14:38.087307 | root[root] @ localhost [] |         3 |         3 | Query        | SELECT DATABASE()                |
| 2020-06-28 09:14:38.087952 | root[root] @ localhost [] |         3 |         3 | Init DB      | mysql                            |
| 2020-06-28 09:14:38.091356 | root[root] @ localhost [] |         3 |         3 | Query        | show databases                   |
| 2020-06-28 09:14:38.092713 | root[root] @ localhost [] |         3 |         3 | Query        | show tables                      |
| 2020-06-28 09:14:38.094222 | root[root] @ localhost [] |         3 |         3 | Field List   | column_stats                     |
| 2020-06-28 09:14:38.095628 | root[root] @ localhost [] |         3 |         3 | Field List   | columns_priv                     |
| 2020-06-28 09:14:38.096401 | root[root] @ localhost [] |         3 |         3 | Field List   | db                               |
| 2020-06-28 09:14:38.097869 | root[root] @ localhost [] |         3 |         3 | Field List   | event                            |
| 2020-06-28 09:14:38.099603 | root[root] @ localhost [] |         3 |         3 | Field List   | func                             |
| 2020-06-28 09:14:38.100382 | root[root] @ localhost [] |         3 |         3 | Field List   | general_log                      |
| 2020-06-28 09:14:38.101266 | root[root] @ localhost [] |         3 |         3 | Field List   | global_priv                      |
| 2020-06-28 09:14:38.101867 | root[root] @ localhost [] |         3 |         3 | Field List   | gtid_slave_pos                   |
| 2020-06-28 09:14:38.102563 | root[root] @ localhost [] |         3 |         3 | Field List   | help_category                    |
| 2020-06-28 09:14:38.103556 | root[root] @ localhost [] |         3 |         3 | Field List   | help_keyword                     |
| 2020-06-28 09:14:38.104430 | root[root] @ localhost [] |         3 |         3 | Field List   | help_relation                    |
| 2020-06-28 09:14:38.105328 | root[root] @ localhost [] |         3 |         3 | Field List   | help_topic                       |
| 2020-06-28 09:14:38.106362 | root[root] @ localhost [] |         3 |         3 | Field List   | index_stats                      |
| 2020-06-28 09:14:38.107459 | root[root] @ localhost [] |         3 |         3 | Field List   | innodb_index_stats               |
| 2020-06-28 09:14:38.109085 | root[root] @ localhost [] |         3 |         3 | Field List   | innodb_table_stats               |
| 2020-06-28 09:14:38.110367 | root[root] @ localhost [] |         3 |         3 | Field List   | plugin                           |
| 2020-06-28 09:14:38.111098 | root[root] @ localhost [] |         3 |         3 | Field List   | proc                             |
| 2020-06-28 09:14:38.112958 | root[root] @ localhost [] |         3 |         3 | Field List   | procs_priv                       |
| 2020-06-28 09:14:38.113798 | root[root] @ localhost [] |         3 |         3 | Field List   | proxies_priv                     |
| 2020-06-28 09:14:38.114734 | root[root] @ localhost [] |         3 |         3 | Field List   | roles_mapping                    |
| 2020-06-28 09:14:38.115476 | root[root] @ localhost [] |         3 |         3 | Field List   | servers                          |
| 2020-06-28 09:14:38.116419 | root[root] @ localhost [] |         3 |         3 | Field List   | slow_log                         |
| 2020-06-28 09:14:38.118138 | root[root] @ localhost [] |         3 |         3 | Field List   | table_stats                      |
| 2020-06-28 09:14:38.119065 | root[root] @ localhost [] |         3 |         3 | Field List   | tables_priv                      |
| 2020-06-28 09:14:38.120027 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone                        |
| 2020-06-28 09:14:38.120907 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_leap_second            |
| 2020-06-28 09:14:38.121914 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_name                   |
| 2020-06-28 09:14:38.122718 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_transition             |
| 2020-06-28 09:14:38.123713 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_transition_type        |
| 2020-06-28 09:14:38.124958 | root[root] @ localhost [] |         3 |         3 | Field List   | transaction_registry             |
| 2020-06-28 09:14:38.126722 | root[root] @ localhost [] |         3 |         3 | Field List   | user                             |
| 2020-06-28 09:14:48.615477 | root[root] @ localhost [] |         3 |         3 | Query        | select * from mysql.general_log  |
+----------------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
38 rows in set (0.002 sec)

MariaDB [mysql]> 

  提示:可以看到重啟服務后,general_log表中就有數據了,此時查詢日誌記錄到表中就配置好了;通常不建議開啟查詢日誌,這個很消耗服務器性能;

  配置查詢日誌記錄到文件

  提示:以上配置表示明確開啟查詢日誌,並把日誌記錄到/var/lib/mysql/general_log中;

  重啟服務,看看對應目錄下是否生成日誌文件,連接到數據,執行查詢操作,看看是否把日誌記錄到相應文件中哦?

[root@lxc my.cnf.d]# systemctl restart mariadb
[root@lxc my.cnf.d]# ll /var/lib/mysql/general_log 
-rw-rw---- 1 mysql mysql 143 Jun 28 09:22 /var/lib/mysql/general_log
[root@lxc my.cnf.d]# cat /var/lib/mysql/general_log
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| first_db           |
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.001 sec)

MariaDB [(none)]> \q
Bye
[root@lxc my.cnf.d]# cat /var/lib/mysql/general_log
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
200628  9:22:32      3 Connect  root@localhost on  using Socket
                     3 Query    select @@version_comment limit 1
200628  9:22:37      3 Query    show databases
200628  9:22:38      3 Quit
[root@lxc my.cnf.d]# 

  提示:可以看到我們在數據庫中執行了一個show databases; 在對應日誌文件中是能夠記錄對應語句的;

  配置查詢日誌記錄同時記錄到表和文件中

  提示:以上配置表示開啟查詢日誌功能,並把日誌同時記錄到表和文件中,文件路徑為/var/lib/mysq/general_log;

  重啟mariadb,執行查詢操作,看看對應表和文件中是否有記錄?

[root@lxc my.cnf.d]# systemctl restart mariadb     
[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select * from mysql.general_log;
+----------------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
| event_time                 | user_host                 | thread_id | server_id | command_type | argument                         |
+----------------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
| 2020-06-28 09:14:33.402211 | [root] @ localhost []     |         3 |         3 | Connect      | root@localhost on  using Socket  |
| 2020-06-28 09:14:33.409731 | root[root] @ localhost [] |         3 |         3 | Query        | select @@version_comment limit 1 |
| 2020-06-28 09:14:38.087307 | root[root] @ localhost [] |         3 |         3 | Query        | SELECT DATABASE()                |
| 2020-06-28 09:14:38.087952 | root[root] @ localhost [] |         3 |         3 | Init DB      | mysql                            |
| 2020-06-28 09:14:38.091356 | root[root] @ localhost [] |         3 |         3 | Query        | show databases                   |
| 2020-06-28 09:14:38.092713 | root[root] @ localhost [] |         3 |         3 | Query        | show tables                      |
| 2020-06-28 09:14:38.094222 | root[root] @ localhost [] |         3 |         3 | Field List   | column_stats                     |
| 2020-06-28 09:14:38.095628 | root[root] @ localhost [] |         3 |         3 | Field List   | columns_priv                     |
| 2020-06-28 09:14:38.096401 | root[root] @ localhost [] |         3 |         3 | Field List   | db                               |
| 2020-06-28 09:14:38.097869 | root[root] @ localhost [] |         3 |         3 | Field List   | event                            |
| 2020-06-28 09:14:38.099603 | root[root] @ localhost [] |         3 |         3 | Field List   | func                             |
| 2020-06-28 09:14:38.100382 | root[root] @ localhost [] |         3 |         3 | Field List   | general_log                      |
| 2020-06-28 09:14:38.101266 | root[root] @ localhost [] |         3 |         3 | Field List   | global_priv                      |
| 2020-06-28 09:14:38.101867 | root[root] @ localhost [] |         3 |         3 | Field List   | gtid_slave_pos                   |
| 2020-06-28 09:14:38.102563 | root[root] @ localhost [] |         3 |         3 | Field List   | help_category                    |
| 2020-06-28 09:14:38.103556 | root[root] @ localhost [] |         3 |         3 | Field List   | help_keyword                     |
| 2020-06-28 09:14:38.104430 | root[root] @ localhost [] |         3 |         3 | Field List   | help_relation                    |
| 2020-06-28 09:14:38.105328 | root[root] @ localhost [] |         3 |         3 | Field List   | help_topic                       |
| 2020-06-28 09:14:38.106362 | root[root] @ localhost [] |         3 |         3 | Field List   | index_stats                      |
| 2020-06-28 09:14:38.107459 | root[root] @ localhost [] |         3 |         3 | Field List   | innodb_index_stats               |
| 2020-06-28 09:14:38.109085 | root[root] @ localhost [] |         3 |         3 | Field List   | innodb_table_stats               |
| 2020-06-28 09:14:38.110367 | root[root] @ localhost [] |         3 |         3 | Field List   | plugin                           |
| 2020-06-28 09:14:38.111098 | root[root] @ localhost [] |         3 |         3 | Field List   | proc                             |
| 2020-06-28 09:14:38.112958 | root[root] @ localhost [] |         3 |         3 | Field List   | procs_priv                       |
| 2020-06-28 09:14:38.113798 | root[root] @ localhost [] |         3 |         3 | Field List   | proxies_priv                     |
| 2020-06-28 09:14:38.114734 | root[root] @ localhost [] |         3 |         3 | Field List   | roles_mapping                    |
| 2020-06-28 09:14:38.115476 | root[root] @ localhost [] |         3 |         3 | Field List   | servers                          |
| 2020-06-28 09:14:38.116419 | root[root] @ localhost [] |         3 |         3 | Field List   | slow_log                         |
| 2020-06-28 09:14:38.118138 | root[root] @ localhost [] |         3 |         3 | Field List   | table_stats                      |
| 2020-06-28 09:14:38.119065 | root[root] @ localhost [] |         3 |         3 | Field List   | tables_priv                      |
| 2020-06-28 09:14:38.120027 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone                        |
| 2020-06-28 09:14:38.120907 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_leap_second            |
| 2020-06-28 09:14:38.121914 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_name                   |
| 2020-06-28 09:14:38.122718 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_transition             |
| 2020-06-28 09:14:38.123713 | root[root] @ localhost [] |         3 |         3 | Field List   | time_zone_transition_type        |
| 2020-06-28 09:14:38.124958 | root[root] @ localhost [] |         3 |         3 | Field List   | transaction_registry             |
| 2020-06-28 09:14:38.126722 | root[root] @ localhost [] |         3 |         3 | Field List   | user                             |
| 2020-06-28 09:14:48.615477 | root[root] @ localhost [] |         3 |         3 | Query        | select * from mysql.general_log  |
| 2020-06-28 09:19:46.865108 | root[root] @ localhost [] |         3 |         3 | Quit         |                                  |
| 2020-06-28 09:28:29.542343 | [root] @ localhost []     |         3 |         3 | Connect      | root@localhost on  using Socket  |
| 2020-06-28 09:28:29.549997 | root[root] @ localhost [] |         3 |         3 | Query        | select @@version_comment limit 1 |
| 2020-06-28 09:28:44.924061 | root[root] @ localhost [] |         3 |         3 | Query        | select * from mysql.general_log  |
+----------------------------+---------------------------+-----------+-----------+--------------+----------------------------------+
42 rows in set (0.002 sec)

MariaDB [(none)]> \q
Bye
[root@lxc my.cnf.d]# cat /var/lib/mysql/general_log 
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
200628  9:22:32      3 Connect  root@localhost on  using Socket
                     3 Query    select @@version_comment limit 1
200628  9:22:37      3 Query    show databases
200628  9:22:38      3 Quit
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
200628  9:28:29      3 Connect  root@localhost on  using Socket
                     3 Query    select @@version_comment limit 1
200628  9:28:44      3 Query    select * from mysql.general_log
200628  9:28:47      3 Quit
[root@lxc my.cnf.d]# 

  提示:可以看到mysql.general_log表中和/var/lib/mysql/general_log文件中是可以記錄我們執行的查詢語句;

  2、慢查詢日誌,這個日誌對於運維來講是比較重要的,通常我們可以利用慢查詢日誌來判斷哪些語句執行時間超出指定時間;慢查詢日誌主要記錄運行時間超出指定時長度查詢語句;這個日誌同查詢日誌類似,它也是可以存儲在表和文件中的;具體配置方式如下

  配置慢查詢日誌存放在表中

  提示:以上配置表示開啟慢查詢日誌,並把日誌記錄到表中,默認是mysql.slow_log表中;log_slow_filter用來定義過濾哪些語句不記錄的;log_slow_rate_limit表示開啟慢查詢日誌記錄速率;log_slow_verbosity開啟慢查詢日誌詳細記錄;long_query_time定義時長,超出我們指定的時長就會視為慢查詢;配置好以上配置以後重啟服務,我們就可以在mariadb中看到對應變量的值;

[root@lxc my.cnf.d]# systemctl restart mariadb;
[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show global variables like 'slow%';
+---------------------+--------------+
| Variable_name       | Value        |
+---------------------+--------------+
| slow_launch_time    | 2            |
| slow_query_log      | ON           |
| slow_query_log_file | lxc-slow.log |
+---------------------+--------------+
3 rows in set (0.003 sec)

MariaDB [(none)]> show global variables like 'log_slow%';
+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name                | Value                                                                                                                                |
+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| log_slow_admin_statements    | ON                                                                                                                                   |
| log_slow_disabled_statements | sp                                                                                                                                   |
| log_slow_filter              | admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk |
| log_slow_rate_limit          | 1                                                                                                                                    |
| log_slow_slave_statements    | ON                                                                                                                                   |
| log_slow_verbosity           | innodb                                                                                                                               |
+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
6 rows in set (0.002 sec)

MariaDB [(none)]> show global variables like 'long%';    
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 3.000000 |
+-----------------+----------+
1 row in set (0.003 sec)

MariaDB [(none)]>

  提示:從上面的信息可以看到我們配置的相關參數已經生效;

  測試:執行select sleep(5);看看mysql.slow_log表中是否有記錄?

MariaDB [(none)]> select sleep(5) ;               
+----------+
| sleep(5) |
+----------+
|        0 |
+----------+
1 row in set (5.001 sec)

MariaDB [(none)]> select * from mysql.slow_log\G
*************************** 1. row ***************************
    start_time: 2020-06-28 10:32:19.643885
     user_host: root[root] @ localhost []
    query_time: 00:00:05.000700
     lock_time: 00:00:00.000000
     rows_sent: 1
 rows_examined: 0
            db: 
last_insert_id: 0
     insert_id: 0
     server_id: 3
      sql_text: select sleep(5)
     thread_id: 3
 rows_affected: 0
1 row in set (0.001 sec)

MariaDB [(none)]> 

  提示:可以看到slow_log表中已經記錄了我們執行的select sleep(5)語句,執行時長為5.007秒;

  配置慢查詢日誌記錄到文件;

  提示:以上配置表示把慢查詢日誌保存在/var/lib/mysql/slow_query_log文件中;

  測試:重啟mariadb,執行select sleep(5)語句,看看對應文件是否記錄?

[root@lxc my.cnf.d]# systemctl restart mariadb
[root@lxc my.cnf.d]# ll /var/lib/mysql/slow_query_log
-rw-rw---- 1 mysql mysql 143 Jun 28 10:39 /var/lib/mysql/slow_query_log
[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show global variables like 'slow%';
+---------------------+-------------------------------+
| Variable_name       | Value                         |
+---------------------+-------------------------------+
| slow_launch_time    | 2                             |
| slow_query_log      | ON                            |
| slow_query_log_file | /var/lib/mysql/slow_query_log |
+---------------------+-------------------------------+
3 rows in set (0.003 sec)

MariaDB [(none)]> show global variables like 'log_slow%';
+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name                | Value                                                                                                                                |
+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
| log_slow_admin_statements    | ON                                                                                                                                   |
| log_slow_disabled_statements | sp                                                                                                                                   |
| log_slow_filter              | admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk |
| log_slow_rate_limit          | 1                                                                                                                                    |
| log_slow_slave_statements    | ON                                                                                                                                   |
| log_slow_verbosity           | innodb                                                                                                                               |
+------------------------------+--------------------------------------------------------------------------------------------------------------------------------------+
6 rows in set (0.003 sec)

MariaDB [(none)]> show global variables like 'long%';    
+-----------------+----------+
| Variable_name   | Value    |
+-----------------+----------+
| long_query_time | 3.000000 |
+-----------------+----------+
1 row in set (0.002 sec)

MariaDB [(none)]> select sleep(5);
+----------+
| sleep(5) |
+----------+
|        0 |
+----------+
1 row in set (5.001 sec)

MariaDB [(none)]> \q
Bye
[root@lxc my.cnf.d]# cat /var/lib/mysql/slow_query_log
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
# Time: 200628 10:40:50
# User@Host: root[root] @ localhost []
# Thread_id: 3  Schema:   QC_hit: No
# Query_time: 5.000553  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0
# Rows_affected: 0  Bytes_sent: 64
SET timestamp=1593355250;
select sleep(5);
[root@lxc my.cnf.d]# 

  提示:可以看到我們配置的參數在mariadb中已經可正常查詢到,對應的文件中已經記錄我們執行select sleep(5)這條語句執行了5.000553秒;

  配置慢查詢日誌記錄到表和文件中

  提示:紅框中的內容表示把慢查詢日誌同時記錄到文件和表中;

  測試:重啟mariadb服務,執行select sleep(5)語句看看是否在表和文件中都記錄了?

[root@lxc my.cnf.d]# systemctl restart mariadb       
[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> select sleep(5);                   
+----------+
| sleep(5) |
+----------+
|        0 |
+----------+
1 row in set (5.002 sec)

MariaDB [(none)]> select * from mysql.slow_log\G
*************************** 1. row ***************************
    start_time: 2020-06-28 10:32:19.643885
     user_host: root[root] @ localhost []
    query_time: 00:00:05.000700
     lock_time: 00:00:00.000000
     rows_sent: 1
 rows_examined: 0
            db: 
last_insert_id: 0
     insert_id: 0
     server_id: 3
      sql_text: select sleep(5)
     thread_id: 3
 rows_affected: 0
*************************** 2. row ***************************
    start_time: 2020-06-28 10:45:37.720365
     user_host: root[root] @ localhost []
    query_time: 00:00:05.000784
     lock_time: 00:00:00.000000
     rows_sent: 1
 rows_examined: 0
            db: 
last_insert_id: 0
     insert_id: 0
     server_id: 3
      sql_text: select sleep(5)
     thread_id: 3
 rows_affected: 0
2 rows in set (0.001 sec)

MariaDB [(none)]> \q
Bye
[root@lxc my.cnf.d]# cat /var/lib/mysql/slow_query_log
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
# Time: 200628 10:40:50
# User@Host: root[root] @ localhost []
# Thread_id: 3  Schema:   QC_hit: No
# Query_time: 5.000553  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0
# Rows_affected: 0  Bytes_sent: 64
SET timestamp=1593355250;
select sleep(5);
/usr/sbin/mariadbd, Version: 10.5.4-MariaDB-log (MariaDB Server). started with:
Tcp port: 0  Unix socket: (null)
Time                Id Command  Argument
# Time: 200628 10:45:37
# User@Host: root[root] @ localhost []
# Thread_id: 3  Schema:   QC_hit: No
# Query_time: 5.000784  Lock_time: 0.000000  Rows_sent: 1  Rows_examined: 0
# Rows_affected: 0  Bytes_sent: 64
SET timestamp=1593355537;
select sleep(5);
[root@lxc my.cnf.d]# 

  提示:可以看到slow_log表和我們指定文件中都記錄;

  用mysqldumpslow來統計慢查詢日誌

[root@lxc my.cnf.d]# mysqldumpslow 
Can't determine datadir from 'my_print_defaults instances' output: --slow_query_log=on
--log_output=file,table
--slow_query_log_file=/var/lib/mysql/slow_query_log
--log_slow_filter=admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk
--log_slow_rate_limit=1
--log_slow_verbosity=1
--long_query_time=3
--server_id=3
--read_only
--relay_log_purge=0
--skip_name_resolve=1
[root@lxc my.cnf.d]# mysqldumpslow /var/lib/mysql/slow_query_log

Reading mysql slow query log from /var/lib/mysql/slow_query_log
Count: 2  Time=5.00s (10s)  Lock=0.00s (0s)  Rows_sent=1.0 (2), Rows_examined=0.0 (0), Rows_affected=0.0 (0), root[root]@localhost
  select sleep(N)

Count: 1  Time=4.02s (4s)  Lock=0.00s (0s)  Rows_sent=1.0 (1), Rows_examined=2.0 (2), Rows_affected=0.0 (0), root[root]@localhost
  select sleep(N),count(id) from first_db.test_tb

Count: 3  Time=4.00s (12s)  Lock=0.00s (0s)  Rows_sent=1.0 (3), Rows_examined=5.0 (15), Rows_affected=0.0 (0), root[root]@localhost
  select sleep(N),count(start_time) from mysql.slow_log

Count: 1  Time=4.00s (4s)  Lock=0.00s (0s)  Rows_sent=1.0 (1), Rows_examined=0.0 (0), Rows_affected=0.0 (0), root[root]@localhost
  select sleep(N)as a, N as b

[root@lxc my.cnf.d]# 

  提示:默認mysqldumpslow 不加任何選項和參數 它會打印配置文件內容,mysqldumpslow 後面給指定的slow日誌 它會統計出那些命令執行了幾次,總時長是多少等等;

  使用日誌分析工具mysqlsla工具分析慢查詢日誌

  安裝mysqlsla

[root@lxc my.cnf.d]# yum install perl-DBI perl-DBD-MySQL perl-devel -y
Loaded plugins: fastestmirror
base                                                                                                                                                | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                    | 3.5 kB  00:00:00     
epel                                                                                                                                                | 4.7 kB  00:00:00     
extras                                                                                                                                              | 2.9 kB  00:00:00     
mariadb-main                                                                                                                                        | 2.9 kB  00:00:00     
mariadb-maxscale                                                                                                                                    | 2.4 kB  00:00:00     
mariadb-tools                                                                                                                                       | 2.9 kB  00:00:00     
updates                                                                                                                                             | 2.9 kB  00:00:00     
(1/3): updates/7/x86_64/primary_db                                                                                                                  | 2.9 MB  00:00:00     
(2/3): epel/x86_64/updateinfo                                                                                                                       | 1.0 MB  00:00:00     
(3/3): epel/x86_64/primary_db                                                                                                                       | 6.8 MB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package perl-DBI-1.627-4.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.023-5.el7 will be updated
---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be an update
---> Package perl-devel.x86_64 4:5.16.3-295.el7 will be installed
……省略部分內容
Installed:
  perl-devel.x86_64 4:5.16.3-295.el7                                                                                                                                       

Dependency Installed:
  gdbm-devel.x86_64 0:1.10-8.el7                           glibc-devel.x86_64 0:2.17-307.el7.1                      glibc-headers.x86_64 0:2.17-307.el7.1                  
  kernel-headers.x86_64 0:3.10.0-1127.13.1.el7             libdb-devel.x86_64 0:5.3.21-25.el7                       perl-ExtUtils-Install.noarch 0:1.58-295.el7            
  perl-ExtUtils-MakeMaker.noarch 0:6.68-3.el7              perl-ExtUtils-Manifest.noarch 0:1.61-244.el7             perl-ExtUtils-ParseXS.noarch 1:3.18-3.el7              
  perl-Test-Harness.noarch 0:3.28-3.el7                    pyparsing.noarch 0:1.5.6-9.el7                           systemtap-sdt-devel.x86_64 0:4.0-11.el7                

Updated:
  perl-DBD-MySQL.x86_64 0:4.023-6.el7                                                                                                                                      

Dependency Updated:
  glibc.x86_64 0:2.17-307.el7.1          glibc-common.x86_64 0:2.17-307.el7.1          libdb.x86_64 0:5.3.21-25.el7          libdb-utils.x86_64 0:5.3.21-25.el7         

Complete!
[root@lxc my.cnf.d]#cd
[root@lxc ~]#wget  ftp://ftp.tw.freebsd.org/pub/distfiles/mysqlsla-2.03.tar.gz
--2020-06-28 11:07:02--  ftp://ftp.tw.freebsd.org/pub/distfiles/mysqlsla-2.03.tar.gz
           => ‘mysqlsla-2.03.tar.gz’
Resolving ftp.tw.freebsd.org (ftp.tw.freebsd.org)... 140.113.17.209
Connecting to ftp.tw.freebsd.org (ftp.tw.freebsd.org)|140.113.17.209|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /pub/distfiles ... done.
==> SIZE mysqlsla-2.03.tar.gz ... 33674
==> PASV ... done.    ==> RETR mysqlsla-2.03.tar.gz ... done.
Length: 33674 (33K) (unauthoritative)

100%[=================================================================================================================================>] 33,674      --.-K/s   in 0s      

2020-06-28 11:07:10 (195 MB/s) - ‘mysqlsla-2.03.tar.gz’ saved [33674]
[root@lxc ~]# ls
192.168.0.22  lxc_br_set.sh  LXC-Web-Panel  mysqlsla-2.03.tar.gz
[root@lxc ~]# tar xf mysqlsla-2.03.tar.gz 
[root@lxc ~]# cd mysqlsla-2.03/
[root@lxc mysqlsla-2.03]# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for mysqlsla
[root@lxc mysqlsla-2.03]# make
cp lib/mysqlsla.pm blib/lib/mysqlsla.pm
cp bin/mysqlsla blib/script/mysqlsla
/usr/bin/perl -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/mysqlsla
Manifying blib/man3/mysqlsla.3pm
[root@lxc mysqlsla-2.03]# make install
Installing /usr/local/share/perl5/mysqlsla.pm
Installing /usr/local/share/man/man3/mysqlsla.3pm
Installing /usr/local/bin/mysqlsla
Appending installation info to /usr/lib64/perl5/perllocal.pod
[root@lxc mysqlsla-2.03]#

  使用mysqlsla分析慢查詢日誌/var/lib/mysql/slow_query_log

[root@lxc mysqlsla-2.03]# mysqlsla -lt slow /var/lib/mysql/slow_query_log  
Report for msl logs: /var/lib/mysql/slow_query_log
7 queries total, 4 unique
Sorted by 't_sum'
Grand Totals: Time 30 s, Lock 0 s, Rows sent 7, Rows Examined 17


______________________________________________________________________ 001 ___
Count         : 3  (42.86%)
Time          : 12.003227 s total, 4.001076 s avg, 4.000803 s to 4.001615 s max  (39.97%)
Lock Time (s) : 595 otal, 198 vg, 151 o 257 ax  (26.81%)
Rows sent     : 1 avg, 1 to 1 max  (42.86%)
Rows examined : 5 avg, 4 to 6 max  (88.24%)
Database      :   QC_hit: No
Users         : 
        root@localhost  : 100.00% (3) of query, 100.00% (7) of all users

Query abstract:
SELECT sleep(N),COUNT(start_time) FROM mysql.slow_log;

Query sample:
select sleep(4),count(start_time) from mysql.slow_log;

______________________________________________________________________ 002 ___
Count         : 2  (28.57%)
Time          : 10.001337 s total, 5.000668 s avg, 5.000553 s to 5.000784 s max  (33.31%)
Lock Time (s) : 0 total, 0 avg, 0 to 0 max  (0.00%)
Rows sent     : 1 avg, 1 to 1 max  (28.57%)
Rows examined : 0 avg, 0 to 0 max  (0.00%)
Database      :   QC_hit: No
Users         : 
        root@localhost  : 100.00% (2) of query, 100.00% (7) of all users

Query abstract:
SELECT sleep(N);

Query sample:
select sleep(5);

______________________________________________________________________ 003 ___
Count         : 1  (14.29%)
Time          : 4.023146 s total, 4.023146 s avg, 4.023146 s to 4.023146 s max  (13.40%)
Lock Time (s) : 1.624 ms total, 1.624 ms avg, 1.624 ms to 1.624 ms max  (73.19%)
Rows sent     : 1 avg, 1 to 1 max  (14.29%)
Rows examined : 2 avg, 2 to 2 max  (11.76%)
Database      :   QC_hit: No
Users         : 
        root@localhost  : 100.00% (1) of query, 100.00% (7) of all users

Query abstract:
SELECT sleep(N),COUNT(id) FROM first_db.test_tb;

Query sample:
select sleep(4),count(id) from first_db.test_tb;

______________________________________________________________________ 004 ___
Count         : 1  (14.29%)
Time          : 4.000851 s total, 4.000851 s avg, 4.000851 s to 4.000851 s max  (13.32%)
Lock Time (s) : 0 total, 0 avg, 0 to 0 max  (0.00%)
Rows sent     : 1 avg, 1 to 1 max  (14.29%)
Rows examined : 0 avg, 0 to 0 max  (0.00%)
Database      :   QC_hit: No
Users         : 
        root@localhost  : 100.00% (1) of query, 100.00% (7) of all users

Query abstract:
SELECT sleep(N)AS a, N AS b;

Query sample:
select sleep(4)as a, 1 as b;
[root@lxc mysqlsla-2.03]# 

  提示:可以看到msyqlsla把慢查詢日誌更具體的分析了一次,每個語句執行了多少次,總時間,平均時間等等信息;

  3、錯誤日誌,該日誌記錄了mairadbd啟動關閉過程中的輸出信息,mariadbd運行中產生的錯誤信息,事件調度產生的信息,和主從複製架構中,從服務器複製線程啟動時產生的信息;配置錯誤日誌如下

  提示:以上紅框中的內容表示啟動錯誤日誌功能,並保持到/var/log/mariadb/mariadb_error.log;並開啟記錄警告信息到錯誤日誌中;

  重啟服務看看對應文件中是否會記錄mariadb啟動信息?

[root@lxc my.cnf.d]# systemctl restart mariadb
[root@lxc my.cnf.d]# ll /var/log/mariadb/mariadb_error.log
-rw-rw---- 1 mysql mysql 2411 Jun 28 11:35 /var/log/mariadb/mariadb_error.log
[root@lxc my.cnf.d]# cat /var/log/mariadb/mariadb_error.log
2020-06-28 11:35:44 0 [Note] /usr/sbin/mariadbd (initiated by: unknown): Normal shutdown
2020-06-28 11:35:44 0 [Note] Event Scheduler: Purging the queue. 0 events
2020-06-28 11:35:44 0 [Note] InnoDB: FTS optimize thread exiting.
2020-06-28 11:35:44 0 [Note] InnoDB: Starting shutdown...
2020-06-28 11:35:44 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
2020-06-28 11:35:44 0 [Note] InnoDB: Buffer pool(s) dump completed at 200628 11:35:44
2020-06-28 11:35:45 0 [Note] InnoDB: Shutdown completed; log sequence number 91510; transaction id 181
2020-06-28 11:35:45 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
2020-06-28 11:35:45 0 [Note] /usr/sbin/mariadbd: Shutdown complete

2020-06-28 11:35:45 0 [Note] InnoDB: Using Linux native AIO
2020-06-28 11:35:45 0 [Note] InnoDB: Uses event mutexes
2020-06-28 11:35:45 0 [Note] InnoDB: Compressed tables use zlib 1.2.7
2020-06-28 11:35:45 0 [Note] InnoDB: Number of pools: 1
2020-06-28 11:35:45 0 [Note] InnoDB: Using SSE4.2 crc32 instructions
2020-06-28 11:35:45 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
2020-06-28 11:35:45 0 [Note] InnoDB: Completed initialization of buffer pool
2020-06-28 11:35:45 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2020-06-28 11:35:45 0 [Note] InnoDB: 128 rollback segments are active.
2020-06-28 11:35:45 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-06-28 11:35:45 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-06-28 11:35:45 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-06-28 11:35:45 0 [Note] InnoDB: 10.5.4 started; log sequence number 91510; transaction id 180
2020-06-28 11:35:45 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2020-06-28 11:35:45 0 [Note] Plugin 'FEEDBACK' is disabled.
2020-06-28 11:35:45 0 [Note] InnoDB: Buffer pool(s) load completed at 200628 11:35:45
2020-06-28 11:35:45 0 [Note] Server socket created on IP: '::'.
2020-06-28 11:35:45 0 [Warning] 'proxies_priv' entry '@% root@lxc' ignored in --skip-name-resolve mode.
2020-06-28 11:35:45 0 [Note] /usr/sbin/mariadbd: ready for connections.
Version: '10.5.4-MariaDB-log'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
[root@lxc my.cnf.d]# 

  提示:可以看到我們手動指定的文件是可以正常記錄mariadb啟動過程中產生的日誌信息和警告信息;

  測試:故意把配置文件配置錯誤,重啟服務,看看是否反映到錯誤日誌中?

  提示:紅框中內容是我故意多寫了一個i ,接下來我們重啟服務,看看錯誤日中是否會反饋出來;

  提示:可以看到在錯誤日誌文件中,它告訴我們未知的變量;

  4、二進制日誌:用於記錄引起數據改變或存在引起數據改變的潛在可能性的語句(STATEMENT)或改變后的結果(ROW),也可能是二者混合;這個日誌在主從複製架構中非常重要,主要功能就是記錄增刪改語句,用於“重放”實現從節點和主節點數據相同的目的;配置如下

  提示:以上紅框中的配置表示開啟二進制日誌,並保持到/var/lib/mysql/下,以mysql-bin開頭命名;二進制文件的最大容量是1G;sync_binlog=1表示只要有二進制文件產生就立刻同步到磁盤;

  測試:重啟服務,看看對應文件是否產生?

  提示:可以看到/var/lib/mysql/目錄下有一個mysql-bin.000001的文件產生了;

  連接數據庫,查看二進制文件列表

[root@lxc my.cnf.d]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.4-MariaDB-log MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show master logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       513 |
+------------------+-----------+
1 row in set (0.001 sec)

MariaDB [(none)]> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       513 |
+------------------+-----------+
1 row in set (0.000 sec)

MariaDB [(none)]> 

  提示:以上語句都表示查看二進制日誌文件列表;

  查看當前正在使用的二進制日誌文件

MariaDB [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      513 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> 

  提示:可以看到當前正在使用mysql-bin.000001這個文件,當前位置是328

  查看二進制日誌文件中的事件

MariaDB [first_db]> show binlog events;
+------------------+-----+-------------------+-----------+-------------+-----------------------------------------------------------+
| Log_name         | Pos | Event_type        | Server_id | End_log_pos | Info                                                      |
+------------------+-----+-------------------+-----------+-------------+-----------------------------------------------------------+
| mysql-bin.000001 |   4 | Format_desc       |         3 |         256 | Server ver: 10.5.4-MariaDB-log, Binlog ver: 4             |
| mysql-bin.000001 | 256 | Gtid_list         |         3 |         285 | []                                                        |
| mysql-bin.000001 | 285 | Binlog_checkpoint |         3 |         328 | mysql-bin.000001                                          |
| mysql-bin.000001 | 328 | Gtid              |         3 |         370 | BEGIN GTID 0-3-1                                          |
| mysql-bin.000001 | 370 | Query             |         3 |         482 | use `first_db`; insert into test_tb values(3,"wangwu",22) |
| mysql-bin.000001 | 482 | Xid               |         3 |         513 | COMMIT /* xid=17 */                                       |
+------------------+-----+-------------------+-----------+-------------+-----------------------------------------------------------+
6 rows in set (0.001 sec)

MariaDB [first_db]> 

  提示:以上是在數據庫上用語句查看二進制日誌事件;我們也可以在shell中使用mysqlbinlog命令來查看二進制文件內容;

  使用msyqlbinlog命令查看二進制日誌內容

[root@lxc ~]# mysqlbinlog /var/lib/mysql/mysql-bin.000001 
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#200628 11:58:31 server id 3  end_log_pos 256 CRC32 0x9afc2aa7  Start: binlog v 4, server v 10.5.4-MariaDB-log created 200628 11:58:31 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
J774Xg8DAAAA/AAAAAABAAABAAQAMTAuNS40LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAnvvheEzgNAAgAEgAEBAQEEgAA5AAEGggAAAAICAgCAAAACgoKAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAEEwQADQgICAoKCgGnKvya
'/*!*/;
# at 256
#200628 11:58:31 server id 3  end_log_pos 285 CRC32 0x516669db  Gtid list []
# at 285
#200628 11:58:31 server id 3  end_log_pos 328 CRC32 0x8395a8cd  Binlog checkpoint mysql-bin.000001
# at 328
#200628 12:13:13 server id 3  end_log_pos 370 CRC32 0xd9b2a8a4  GTID 0-3-1 trans
/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
/*!100001 SET @@session.server_id=3*//*!*/;
/*!100001 SET @@session.gtid_seq_no=1*//*!*/;
BEGIN
/*!*/;
# at 370
#200628 12:13:13 server id 3  end_log_pos 482 CRC32 0x5737f424  Query   thread_id=5     exec_time=0     error_code=0
use `first_db`/*!*/;
SET TIMESTAMP=1593360793/*!*/;
SET @@session.pseudo_thread_id=5/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0/*!*/;
SET @@session.sql_mode=1411383296/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test_tb values(3,"wangwu",22)
/*!*/;
# at 482
#200628 12:13:13 server id 3  end_log_pos 513 CRC32 0x43126028  Xid = 17
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@lxc ~]# 

  提示:可以看到我們往test_tb表中插入的數據,在二進制文件中有記錄,但是沒有查詢語句;二進制日誌文件是不會記錄查詢語句,它只會記錄對數據有變動的語句;

  用mysqlbinlog工具查看指定位置後端日誌內容

[root@lxc ~]# mysqlbinlog -j 370 /var/lib/mysql/mysql-bin.000001 
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#200628 11:58:31 server id 3  end_log_pos 256 CRC32 0x9afc2aa7  Start: binlog v 4, server v 10.5.4-MariaDB-log created 200628 11:58:31 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
J774Xg8DAAAA/AAAAAABAAABAAQAMTAuNS40LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAnvvheEzgNAAgAEgAEBAQEEgAA5AAEGggAAAAICAgCAAAACgoKAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAEEwQADQgICAoKCgGnKvya
'/*!*/;
# at 370
#200628 12:13:13 server id 3  end_log_pos 482 CRC32 0x5737f424  Query   thread_id=5     exec_time=0     error_code=0
use `first_db`/*!*/;
SET TIMESTAMP=1593360793/*!*/;
SET @@session.pseudo_thread_id=5/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0/*!*/;
SET @@session.sql_mode=1411383296/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test_tb values(3,"wangwu",22)
/*!*/;
# at 482
#200628 12:13:13 server id 3  end_log_pos 513 CRC32 0x43126028  Xid = 17
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@lxc ~]# 

  用mysqlbinlog查看指定起始位置的日誌信息

[root@lxc ~]# mysqlbinlog --start-position=370 --stop-position=482 /var/lib/mysql/mysql-bin.000001      
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#200628 11:58:31 server id 3  end_log_pos 256 CRC32 0x9afc2aa7  Start: binlog v 4, server v 10.5.4-MariaDB-log created 200628 11:58:31 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
J774Xg8DAAAA/AAAAAABAAABAAQAMTAuNS40LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAnvvheEzgNAAgAEgAEBAQEEgAA5AAEGggAAAAICAgCAAAACgoKAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAEEwQADQgICAoKCgGnKvya
'/*!*/;
# at 370
#200628 12:13:13 server id 3  end_log_pos 482 CRC32 0x5737f424  Query   thread_id=5     exec_time=0     error_code=0
use `first_db`/*!*/;
SET TIMESTAMP=1593360793/*!*/;
SET @@session.pseudo_thread_id=5/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0/*!*/;
SET @@session.sql_mode=1411383296/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test_tb values(3,"wangwu",22)
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@lxc ~]# 

  用mysqlbinlog查看指定開始時間以後的日誌

[root@lxc ~]# mysqlbinlog --start-datetime="2020-06-28 12:39:05" /var/lib/mysql/mysql-bin.000001
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#200628 11:58:31 server id 3  end_log_pos 256 CRC32 0x9afc2aa7  Start: binlog v 4, server v 10.5.4-MariaDB-log created 200628 11:58:31 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
J774Xg8DAAAA/AAAAAABAAABAAQAMTAuNS40LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAnvvheEzgNAAgAEgAEBAQEEgAA5AAEGggAAAAICAgCAAAACgoKAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAEEwQADQgICAoKCgGnKvya
'/*!*/;
# at 513
#200628 12:39:05 server id 3  end_log_pos 555 CRC32 0xf924553d  GTID 0-3-2 trans
/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
/*!100001 SET @@session.server_id=3*//*!*/;
/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
BEGIN
/*!*/;
# at 555
#200628 12:39:05 server id 3  end_log_pos 668 CRC32 0x496c0f4f  Query   thread_id=6     exec_time=0     error_code=0
use `first_db`/*!*/;
SET TIMESTAMP=1593362345/*!*/;
SET @@session.pseudo_thread_id=6/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0/*!*/;
SET @@session.sql_mode=1411383296/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test_tb values (4,"wukong",99)
/*!*/;
# at 668
#200628 12:39:05 server id 3  end_log_pos 699 CRC32 0xf5032d63  Xid = 27
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@lxc ~]# 

  用mysqlbinlog查看指定時間段的日誌信息

[root@lxc ~]# mysqlbinlog --start-datetime="2020-06-28 12:13:13" --stop-datetime="2020-06-28 12:43:42" /var/lib/mysql/mysql-bin.000001        
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#200628 11:58:31 server id 3  end_log_pos 256 CRC32 0x9afc2aa7  Start: binlog v 4, server v 10.5.4-MariaDB-log created 200628 11:58:31 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG '
J774Xg8DAAAA/AAAAAABAAABAAQAMTAuNS40LU1hcmlhREItbG9nAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAnvvheEzgNAAgAEgAEBAQEEgAA5AAEGggAAAAICAgCAAAACgoKAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAEEwQADQgICAoKCgGnKvya
'/*!*/;
# at 328
#200628 12:13:13 server id 3  end_log_pos 370 CRC32 0xd9b2a8a4  GTID 0-3-1 trans
/*!100101 SET @@session.skip_parallel_replication=0*//*!*/;
/*!100001 SET @@session.gtid_domain_id=0*//*!*/;
/*!100001 SET @@session.server_id=3*//*!*/;
/*!100001 SET @@session.gtid_seq_no=1*//*!*/;
BEGIN
/*!*/;
# at 370
#200628 12:13:13 server id 3  end_log_pos 482 CRC32 0x5737f424  Query   thread_id=5     exec_time=0     error_code=0
use `first_db`/*!*/;
SET TIMESTAMP=1593360793/*!*/;
SET @@session.pseudo_thread_id=5/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1, @@session.check_constraint_checks=1, @@session.sql_if_exists=0/*!*/;
SET @@session.sql_mode=1411383296/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
insert into test_tb values(3,"wangwu",22)
/*!*/;
# at 482
#200628 12:13:13 server id 3  end_log_pos 513 CRC32 0x43126028  Xid = 17
COMMIT/*!*/;
# at 513
#200628 12:39:05 server id 3  end_log_pos 555 CRC32 0xf924553d  GTID 0-3-2 trans
/*!100001 SET @@session.gtid_seq_no=2*//*!*/;
BEGIN
/*!*/;
# at 555
#200628 12:39:05 server id 3  end_log_pos 668 CRC32 0x496c0f4f  Query   thread_id=6     exec_time=0     error_code=0
SET TIMESTAMP=1593362345/*!*/;
insert into test_tb values (4,"wukong",99)
/*!*/;
# at 668
#200628 12:39:05 server id 3  end_log_pos 699 CRC32 0xf5032d63  Xid = 27
COMMIT/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@lxc ~]# 

  提示:根據上面時間或者位置指定範圍后,我們就可以過濾我們需要的信息來做處理;如下,過濾insert語句

[root@lxc ~]# mysqlbinlog --start-datetime="2020-06-28 12:13:13" --stop-datetime="2020-06-28 12:43:42" /var/lib/mysql/mysql-bin.000001|grep insert
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
insert into test_tb values(3,"wangwu",22)
insert into test_tb values (4,"wukong",99)
[root@lxc ~]# 

  提示:可以看到通過過濾關鍵字就可以很快定位到我們日誌中記錄了那些語句,一眼就能清楚知道之前執行過什麼語句;

  5、中繼日誌,該日誌主要是在主從複製架構中記錄從主服務器的二進制日誌文件同步過來的事件信息;開啟中繼日誌配置如下

  提示:以上配置表示開啟中繼日誌並保持到/var/lib/mysql/relay_log中;

  確定配置中繼日誌是否開啟成功,方法一,搭建主從複製,開啟主從複製線程,在對應目錄看是否有對應文件生成,方法二,直接在數據庫里查看reay_log變量的值,如果是我們配置的路基,表示開啟成功,否則失敗

  提示:從上面的截圖可以看到關於中繼日誌參數的配置有以上幾種,max_relay_log_size表示中繼日誌的最大容量;relay_log表示中繼日誌存放路徑和中繼日誌以那個名稱開頭,這個和二進制日誌的配置邏輯差不多;relay_log_basename表示已那個名字作為中繼日誌的基名;relay_log_index表示relay_log.index文件存放地;relay_log_info_file表示relay_log.info 文件名;relay_log_purge表示是否開啟修剪中繼日誌;relay_log_recovery表示是否開啟中繼日誌恢復功能(是否隨mariadb服務啟動而創建一個新的relay_log,將sql線程的位置初始化到新的relay log,並將i/o線程初始化到sql線程位置。)relay_log_space_limit表示是否開啟中繼日誌空間限制;sync_relay_log表示多少次事務同步一次中繼日誌到磁盤;sync_relay_log_info表示多少次事務同步一次relay-log.info;

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※為什麼 USB CONNECTOR 是電子產業重要的元件?

網頁設計一頭霧水??該從何著手呢? 找到專業技術的網頁設計公司,幫您輕鬆架站!

※想要讓你的商品成為最夯、最多人討論的話題?網頁設計公司讓你強力曝光

※想知道最厲害的台北網頁設計公司推薦台中網頁設計公司推薦專業設計師”嚨底家”!!

新北清潔公司,居家、辦公、裝潢細清專業服務