mysql二進位安裝腳本部署

来源:https://www.cnblogs.com/tushanbu/archive/2022/09/20/16711987.html
-Advertisement-
Play Games

mysql二進位安裝腳本部署 單實例 [root@localhost ~]# mkdir mysql //創建存放腳本目錄 [root@localhost ~]# ls anaconda-ks.cfg mysql [root@localhost ~]# cd mysql/ [root@localho ...


mysql二進位安裝腳本部署


目錄

單實例

[root@localhost ~]# mkdir mysql   //創建存放腳本目錄
[root@localhost ~]# ls
anaconda-ks.cfg  mysql
[root@localhost ~]# cd mysql/
[root@localhost mysql]# mkdir files  //創建安裝包目錄
[root@localhost mysql]# ls
files
[root@localhost mysql]# ls files/
mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@localhost mysql]# touch mysql_install.sh  //創建腳本文件
[root@localhost mysql]# chmod +x mysql_install.sh  //賦予執行許可權
[root@localhost mysql]# ll
total 0
drwxr-xr-x. 2 root root 56 Sep 19 21:16 files
-rwxr-xr-x. 1 root root  0 Sep 19 21:18 mysql_install.sh
[root@localhost mysql]# vim mysql_install.sh 
[root@localhost mysql]# cat mysql_install.sh 
#!/bin/bash

#設置執行許可權
if [ $UID -ne 0 ];then
        echo "請以管理員用戶進行執行"
        exit
fi
read -p "請輸入要創建的實例個數: " count
read -p "請輸入數據存放目錄(預設路徑: /opt/xbz): " datadir
read -p "請輸入要為資料庫設置的密碼: " passwd
read -p "請輸入安裝目錄,(預設路徑:/usr/local/mysql):" mysql_install_dir
#判斷安裝目錄合法性
echo $mysql_install_dir | grep -E '^/[a-z][a-z]*(/[a-z][a-z]*)*$' &> /dev/null
if [ $? -eq 0 ];then
    if [ ! -d $mysql_install_dir ];then
        mkdir -p $mysql_install_dir
    fi
else
    mysql_install_dir=/usr/local/mysql
fi
#判斷安裝目錄是否為空
if [ -z $mysql_install_dir ];then
    mysql_install_dir=/usr/local/mysql
fi

#創建用戶
id mysql &> /dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
    else
            echo "用戶已存在"
fi
#安裝依賴包
dnf -y install ncurses-compat-libs 
#解壓軟體包,修改目錄和所屬組
if [ ! -d $mysql_install_dir ];then
    echo "解壓軟體包"
    tar xf files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    cd /usr/local
    mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
fi
chown -R mysql.mysql ${mysql_install_dir}
#設置環境變數
echo 'export PATH=${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
#做頭文件
ln -s ${mysql_install_dir}/include /usr/include/mysql
#配置lib
echo '${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
#設置man文檔
grep '${mysql_install_dir}/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
        sed -i "22a MANDATORY_MANPATH                       ${mysql_install_dir}/man" /etc/man_db.conf
fi
#建立數據存放目錄
for i in $(seq $count);do
    if [ $count -eq 1 ];then
            if [ -z $datadir ];then
                datadir=/opt/xbz
            fi
            if [ ! -d $datadir ];then
                mkdir -p $datadir
            fi      
            chown -R mysql.mysql $datadir
            ${mysql_install_dir}/bin/mysqld --initialize --user mysql --datadir $datadir &> /tmp/passwd
#生成數據配置文件
            cat > /etc/my.cnf << EOF
[mysqld]
basedir = ${mysql_install_dir}
datadir = $datadir
socket = /tmp/mysql.sock 
port = 3306 
pid-file = $datadir/mysql.pid 
user = mysql 
skip-name-resolve 
EOF
#配置服務啟動腳本
if [ ! -f /etc/init.d/mysqld ];then
        cp  -a   ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
        sed -ri  '/^basedir=/c basedir=${mysql_install_dir}' /etc/init.d/mysqld
        sed -ri  "/^datadir=/c datadir=$datadir" /etc/init.d/mysqld
fi
chmod +x /etc/init.d/mysqld
#啟動mysql並設置開機自啟
service mysqld start
sleep 6
chkconfig --add mysqld
ln -s ${mysql_install_dir}/bin/mysql /usr/bin
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
mysql -uroot -p$password --connect-expired-password -e "set password = password('$passwd');"
echo "資料庫的密碼是: $passwd"
    fi
done
驗證:
[root@localhost mysql]# mysql -uroot -p'lnh@321'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit
Bye

使用函數的單實例

[root@localhost mysql]# cat mysql_install.sh 
#!/bin/bash

#設置執行許可權
if [ $UID -ne 0 ];then
        echo "請以管理員用戶進行執行"
        exit
fi

function init(){
id mysql &> /dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
    else
            echo "用戶已存在"
fi
#安裝依賴包
dnf -y install ncurses-compat-libs 
#解壓軟體包,修改目錄和所屬組
if [ ! -d $mysql_install_dir ];then
    echo "解壓軟體包"
    tar xf files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    cd /usr/local
    mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
else
    echo 'mysql已安裝,不需要重覆安裝'
    exit
fi
chown -R mysql.mysql ${mysql_install_dir}
#設置環境變數
echo 'export PATH=${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
#做頭文件
ln -s ${mysql_install_dir}/include /usr/include/mysql
#配置lib
echo '${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
#設置man文檔
grep '${mysql_install_dir}/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
        sed -i "22a MANDATORY_MANPATH                       ${mysql_install_dir}/man" /etc/man_db.conf
fi
}
function init2(){

            if [ -z $datadir ];then
                datadir=/opt/xbz
            fi
            if [ ! -d $datadir ];then
                mkdir -p $datadir
            fi
            chown -R mysql.mysql $datadir
}

function single(){
    init        
#建立數據存放目錄
for i in $(seq $count);do
    if [ $count -eq 1 ];then
        init2           
#判斷是否已格式化           
            content=$(ls -l $datadir | grep -v total | wc -l)
            if [ $content -eq 0 ];then
                ${mysql_install_dir}/bin/mysqld --initialize --user mysql --datadir $datadir &> /tmp/passwd
            else
                echo '不需要重覆初始化'
                exit
            fi
#生成數據配置文件
            cat > /etc/my.cnf << EOF
[mysqld]
basedir = ${mysql_install_dir}
datadir = $datadir
socket = /tmp/mysql.sock 
port = 3306 
pid-file = $datadir/mysql.pid 
user = mysql 
skip-name-resolve 
EOF
#配置服務啟動腳本
if [ ! -f /etc/init.d/mysqld ];then
        cp  -a   ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
        sed -ri  '/^basedir=/c basedir=${mysql_install_dir}' /etc/init.d/mysqld
        sed -ri  "/^datadir=/c datadir=$datadir" /etc/init.d/mysqld
fi
chmod +x /etc/init.d/mysqld
#啟動mysql並設置開機自啟
service mysqld start
sleep 6
chkconfig --add mysqld
ln -s ${mysql_install_dir}/bin/mysql /usr/bin
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
mysql -uroot -p$password --connect-expired-password -e "set password = password('$passwd');"
echo "mysql安裝成功,資料庫的密碼是: $passwd"
    fi
done
}
read -p "請輸入要創建的實例個數: " count
read -p "請輸入安裝目錄,(預設路徑:/usr/local/mysql):" mysql_install_dir
read -p "請輸入數據存放目錄(預設路徑: /opt/xbz): " datadir
read -p "請輸入要為資料庫設置的密碼(預設密碼123456): " passwd
#判斷安裝目錄合法性
echo $mysql_install_dir | grep -E '^/[a-z][a-z]*(/[a-z][a-z]*)*$' &> /dev/null
if [ $? -eq 0 ];then
    if [ ! -d $mysql_install_dir ];then
        mkdir -p $mysql_install_dir
    fi
else
    mysql_install_dir=/usr/local/mysql
fi
#判斷安裝目錄是否為空
if [ -z $mysql_install_dir ];then
    mysql_install_dir=/usr/local/mysql
fi
#判斷數據存放目錄是否為空
if [ -z $datadir ];then
    datadir=/opt/xbz
fi
#判斷數據存放目錄是否合法
echo $datadir | grep "^/[a-z][a-z]*\(/[a-z][a-z]*\)*$" &> /dev/null
if [ $? -ne 0 ];then
    datadir=/opt/xbz
fi
#設置資料庫密碼格式
if [ -z $passwd ];then
    passwd=123456
else
    echo $passwd | grep -E '[a-z]+' | grep -E '[A-Z]+' | grep -E '[0-9]+' | grep -E '_+' &> /dev/null
    if [ $? -ne 0 ] || [ ${#passwd} -lt 8 ];then
        passwd=123456
    fi
fi
#創建用戶
if [ $count -eq 1 ];then
    single        
else
    echo "多實例"       
fi
驗證:               
[root@localhost mysql]# mysql -uroot -p'123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit
Bye

使用函數的單實例或者多實例

[root@localhost mysql]# cat mysql_install.sh 
#!/bin/bash

#設置執行許可權
if [ $UID -ne 0 ];then
        echo "請以管理員用戶進行執行"
        exit
fi

function init(){
id mysql &> /dev/null
if [ $? -ne 0 ];then
        useradd -r -M -s /sbin/nologin mysql
    else
            echo "用戶已存在"
fi
#安裝依賴包
dnf -y install ncurses-compat-libs perl 
#解壓軟體包,修改目錄和所屬組
if [ ! -d $mysql_install_dir ];then
    echo "解壓軟體包"
    tar xf files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    cd /usr/local
    mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
fi
chown -R mysql.mysql ${mysql_install_dir}
#設置環境變數
echo 'export PATH=${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
#做頭文件
ln -s ${mysql_install_dir}/include /usr/include/mysql
#配置lib
echo '${mysql_install_dir}/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
#設置man文檔
grep '${mysql_install_dir}/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
        sed -i "22a MANDATORY_MANPATH                       ${mysql_install_dir}/man" /etc/man_db.conf
fi
}
function init2(){

            if [ -z $datadir ];then
                datadir=/opt/xbz
            fi
            if [ ! -d $datadir ];then
                mkdir -p $datadir
            fi
            chown -R mysql.mysql $datadir
}
#單實例
function single(){
    init        
#建立數據存放目錄
for i in $(seq $count);do
    if [ $count -eq 1 ];then
        init2           
#判斷是否已格式化           
            content=$(ls -l $datadir | grep -v total | wc -l)
            if [ $content -eq 0 ];then
                ${mysql_install_dir}/bin/mysqld --initialize --user mysql --datadir $datadir &> /tmp/passwd
            else
                echo '不需要重覆初始化'
                exit
            fi
#生成數據配置文件
            cat > /etc/my.cnf << EOF
[mysqld]
basedir = ${mysql_install_dir}
datadir = $datadir
socket = /tmp/mysql.sock 
port = 3306 
pid-file = $datadir/mysql.pid 
user = mysql 
skip-name-resolve 
EOF
#配置服務啟動腳本
if [ ! -f /etc/init.d/mysqld ];then
        cp  -a   ${mysql_install_dir}/support-files/mysql.server /etc/init.d/mysqld
        sed -ri  '/^basedir=/c basedir=${mysql_install_dir}' /etc/init.d/mysqld
        sed -ri  "/^datadir=/c datadir=$datadir" /etc/init.d/mysqld
fi
chmod +x /etc/init.d/mysqld
#啟動mysql並設置開機自啟
service mysqld start
sleep 6
chkconfig --add mysqld
ln -s ${mysql_install_dir}/bin/mysql /usr/bin
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
mysql -uroot -p"$password" --connect-expired-password -e "set password = password('$passwd');"
echo "mysql安裝成功,資料庫的密碼是: $passwd"
    fi
done
}
#多實例
function multi(){
    init
    init2
    port=3306
#配置配置文件/etc/my.cnf
    cat > /etc/my.cnf <<EOF
[mysqld_multi]
mysqld = ${mysql_install_dir}/bin/mysqld_safe
mysqladmin = ${mysql_install_dir}/bin/mysqladmin
EOF
#創建各實例數據存放的目錄並初始化各實例
    for i in $(seq $count);do
        mkdir -p ${datadir}/$port
        chown -R mysql.mysql ${datadir}
        content=$(ls -l ${datadir}/$port | grep -v total | wc -l)
        if [ $content -eq 0 ];then
                echo "正在初始化各實例"
                ${mysql_install_dir}/bin/mysqld --initialize --user=mysql --datadir=${datadir}/$port &> /tmp/passwd
#取出臨時資料庫密碼
            password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
        else
            let port++
            continue        
        fi
#配置配置文件/etc/my.cnf
        cat >> /etc/my.cnf << EOF
[mysqld$port]
datadir = ${datadir}/$port
port = $port
socket = /tmp/mysql{$port}.sock
pid-file = ${datadir}/${port}/mysql_${port}.pid
log-error=/var/log/${port}.log
EOF
#啟動各實例並修改資料庫密碼
        ln -s ${mysql_install_dir}/bin/my_print_defaults /usr/bin
        ${mysql_install_dir}/bin/mysqld_multi start ${port}
        sleep 6
        ln -s ${mysql_install_dir}/bin/mysql /usr/bin
        mysql -uroot -p"$password" -h127.0.0.1 -P${port} --connect-expired-password -e "set password = password('$passwd');"
        let port++
    done
    echo "mysql安裝成功,資料庫的密碼是: $passwd"
}

read -p "請輸入要創建的實例個數: " count
read -p "請輸入安裝目錄,(預設路徑:/usr/local/mysql):" mysql_install_dir
read -p "請輸入數據存放目錄(預設路徑: /opt/xbz): " datadir
read -p "請輸入要為資料庫設置的密碼(預設密碼123456): " passwd
#判斷安裝目錄合法性
echo $mysql_install_dir | grep -E '^/[a-z][a-z]*(/[a-z][a-z]*)*$' &> /dev/null
if [ $? -eq 0 ];then
    if [ ! -d $mysql_install_dir ];then
        mkdir -p $mysql_install_dir
    fi
else
    mysql_install_dir=/usr/local/mysql
fi
#判斷安裝目錄是否為空
if [ -z $mysql_install_dir ];then
    mysql_install_dir=/usr/local/mysql
fi
#判斷數據存放目錄是否為空
if [ -z $datadir ];then
    datadir=/opt/xbz
fi
#判斷數據存放目錄是否合法
echo $datadir | grep "^/[a-z][a-z]*\(/[a-z][a-z]*\)*$" &> /dev/null
if [ $? -ne 0 ];then 
    datadir=/opt/xbz
fi
#設置資料庫密碼格式
if [ -z $passwd ];then
    passwd=123456
else
    echo $passwd | grep -E '[a-z]+' | grep -E '[A-Z]+' | grep -E '[0-9]+' | grep -E '_+' &> /dev/null
    if [ $? -ne 0 ] || [ ${#passwd} -lt 8 ];then
        passwd=123456
    fi
fi
#創建用戶
if [ $count -eq 1 ];then
    single
    ss -antl    
else
    multi
    ss -antl
fi
驗證:
[root@localhost mysql]# mysql -uroot -p'123456' -h127.0.0.1 -P3306
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit
Bye
[root@localhost mysql]# mysql -uroot -p'123456' -h127.0.0.1 -P3307
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit
Bye
[root@localhost mysql]# mysql -uroot -p'123456' -h127.0.0.1 -P3308
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> exit
Bye


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 學習網站: http://seaborn.pydata.org/examples/scatterplot_matrix.html 一、Anscombe's quartet(安斯庫姆四重奏) 1973年,統計學家F.J. Anscombe構造出了四組奇特的數據。它告訴人們,數據分析之前,描繪數據所對應 ...
  • 類型載入器設計(Type Loader Design) 原文:https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/type-loader.md 作者: Ladi Prosek - 2007 翻譯:幾秋 (https ...
  • 最近在項目中啟用了Nullable 可為空的類型,這個特性確實很好用,在 WebAPI 的入參上可以直接採用 ? 來標記一個欄位是否允許為空,但是使用過程中遇到瞭如下一個問題,比如創建部門介面 我們定義入參模型如下: public class DtoDepartment { /// <summary ...
  • .NET 6 EFCore WebApi 使用 JMeter 進行吞吐量測試 開發環境 VS2022 .NET 6 測試環境 測試工具 介面壓力測試工具:JMeter 資料庫 MySQL 5.7 資料庫和WebApi服務在同一臺伺服器上,JMeter在本人筆記本上。 測試設置 200個線程併發,每個 ...
  • 一、 環境準備 本次配置基於DR負載均衡模式,設置一個VIP(Virtual IP)為19.50.67.173,用戶只需要訪問這個IP地址即可獲得後端服務 其中,負載均衡主機為19.50.67.165(LVS1),備機為 19.50.67.169(LVS2)。Web伺服器A為19.50.67.171 ...
  • forklift Mac版是一款強大的文件管理程式,彌補了Finder文件管理比較單一的功能,強大到能遠程連接Ftp,SFTP,Amazon S3,WebDAV,SMB,NIS,AFP等網路共用服務協議。相對其他文件管理器如Path Finder,forklift mac更加小巧快速。 除此之外Fo ...
  • PowerPoint 無法打開文件 出現的問題 今天下載老師放在學習通的ppt,居然不能打開,記錄一下 點擊修複後出現: 這並不是文件損壞了,而是powerpoint出於安全的考慮,為了保護我們的電腦,不能打開其他電腦的文件。 解決辦法 右鍵選擇屬性,進入常規界面,勾選解除鎖定,點擊引用,點擊確 ...
  • 個人超級電腦是一個新概念,目前這個市場類似上世紀70年的PC革命時代。本篇是回答一位用戶提問,LAXCUS分散式操作系統如何成為一臺“個人超級電腦”。 ...
一周排行
    -Advertisement-
    Play Games
  • 一、openKylin簡介 openKylin(開放麒麟) 社區是在開源、自願、平等和協作的基礎上,由基礎軟硬體企業、非營利性組織、社團組織、高等院校、科研機構和個人開發者共同創立的一個開源社區,致力於通過開源、開放的社區合作,構建桌面操作系統開源社區,推動Linux開源技術及其軟硬體生態繁榮發展。 ...
  • 簡介 Flurl是一個用於構建基於HTTP請求的C#代碼的庫。它的主要目的是簡化和優雅地處理網路請求(只用很少的代碼完成請求)。Flurl提供了一種簡單的方法來構建GET、POST、PUT等類型的請求,以及處理響應和異常。它還提供了一些高級功能,如鏈式調用、緩存請求結果、自動重定向等。本文將介紹Fl ...
  • 一:背景 1. 講故事 最近也挺奇怪,看到了兩起 CPU 爆高的案例,且誘因也是一致的,覺得有一些代表性,合併分享出來幫助大家來避坑吧,閑話不多說,直接上 windbg 分析。 二:WinDbg 分析 1. CPU 真的爆高嗎 這裡要提醒一下,別人說爆高不一定真的就是爆高,我們一定要拿數據說話,可以 ...
  • 剛開始寫文章,封裝Base基類的時候,添加了trycatch異常塊,不過當時沒有去記錄日誌,直接return了。有小伙伴勸我不要吃了Exception 其實沒有啦,項目剛開始,我覺得先做好整體結構比較好。像是蓋樓一樣。先把樓體建造出來,然後再一步一步的美化完善。 基礎的倉儲模式已經ok,Autofa ...
  • 框架目標 什麼是框架,框架能做到什麼? 把一個方向的技術研發做封裝,具備通用性,讓使用框架的開發者用起來很輕鬆。 屬性: 通用性 健壯性 穩定性 擴展性 高性能 組件化 跨平臺 從零開始-搭建框架 建立項目 主鍵查詢功能開發 綁定實體 一步一步的給大家推導: 一邊寫一邊測試 從零開始--搭建框架 1 ...
  • 大家好,我是沙漠盡頭的狼。 本方首發於Dotnet9,介紹使用dnSpy調試第三方.NET庫源碼,行文目錄: 安裝dnSpy 編寫示常式序 調試示常式序 調試.NET庫原生方法 總結 1. 安裝dnSpy dnSpy是一款功能強大的.NET程式反編譯工具,可以對.NET程式進行反編譯,代替庫文檔的功 ...
  • 在`Windows`操作系統中,每個進程的虛擬地址空間都被劃分為若幹記憶體塊,每個記憶體塊都具有一些屬性,如記憶體大小、保護模式、類型等。這些屬性可以通過`VirtualQueryEx`函數查詢得到。該函數可用於查詢進程虛擬地址空間中的記憶體信息的函數。它的作用類似於`Windows`操作系統中的`Task... ...
  • 背景介紹 1,最近有一個大數據量插入的操作入庫的業務場景,需要先做一些其他修改操作,然後在執行插入操作,由於插入數據可能會很多,用到多線程去拆分數據並行處理來提高響應時間,如果有一個線程執行失敗,則全部回滾。 2,在spring中可以使用@Transactional註解去控制事務,使出現異常時會進行 ...
  • 線程(thread)是操作系統能夠進行運算調度的最小單位。它被包含在進程之中,是進程中的實際 運作單位。一條線程指的是進程中一個單一順序的控制流,一個進程中可以併發多個線程,每條線 程並行執行不同的任務。 ...
  • 發現Java 21的StringBuilder和StringBuffer中多了repeat方法: /** * @throws IllegalArgumentException {@inheritDoc} * * @since 21 */ @Override public StringBuilder ...