mysql多實例部署

来源:https://www.cnblogs.com/Their-own/archive/2022/07/29/16532585.html
-Advertisement-
Play Games

1.軟體下載 [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86 ...


目錄

1.軟體下載

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-07-29 13:28:14--  https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.2.84.230
Connecting to cdn.mysql.com (cdn.mysql.com)|23.2.84.230|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 674830866 (644M) [application/x-tar-gz]
Saving to: 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz'

mysql-5.7.38-linux-glibc2.12-x 100%[==================================================>] 643.57M  3.35MB/s    in 4m 15s  

2022-07-29 13:32:30 (2.52 MB/s) - 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866]
[root@localhost src]# ls
debug  kernels  mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz

2.配置用戶和組並解壓二進位程式至/usr/local下

[root@localhost src]# useradd -M -r -s /sbin/nologin mysql
[root@localhost src]# id mysql
uid=995(mysql) gid=992(mysql) groups=992(mysql)
[root@localhost src]# tar xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost src]# cd
[root@localhost ~]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql-5.7.38-linux-glibc2.12-x86_64  sbin  share  src
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64'
[root@localhost local]# ll
total 0
drwxr-xr-x. 2 root root   6 Jun 22  2021 bin
drwxr-xr-x. 2 root root   6 Jun 22  2021 etc
drwxr-xr-x. 2 root root   6 Jun 22  2021 games
drwxr-xr-x. 2 root root   6 Jun 22  2021 include
drwxr-xr-x. 2 root root   6 Jun 22  2021 lib
drwxr-xr-x. 3 root root  17 Jul 12 21:45 lib64
drwxr-xr-x. 2 root root   6 Jun 22  2021 libexec
lrwxrwxrwx. 1 root root  35 Jul 29 13:39 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 9 root root 129 Jul 29 13:38 mysql-5.7.38-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root root   6 Jun 22  2021 sbin
drwxr-xr-x. 5 root root  49 Jul 12 21:45 share
drwxr-xr-x. 2 root root   6 Jun 22  2021 src

//修改目錄/usr/local/mysql的屬主屬組
[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 35 Jul 29 13:39 /usr/local/mysql -> mysql-5.7.38-linux-glibc2.12-x86_64

//配置環境變數
[root@localhost local]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh 
[root@localhost local]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin

//創建頭文件
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ls
LICENSE  README  bin  docs  include  lib  man  share  support-files

[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql		//配置軟鏈接
'/usr/include/mysql' -> '/usr/local/mysql/include/'		
[root@localhost ~]# chown -R mysql.mysql /usr/include/mysql
[root@localhost ~]# ll -d /usr/include/mysql
lrwxrwxrwx. 1 mysql mysql 25 Jul 29 14:37 /usr/include/mysql -> /usr/local/mysql/include/

[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib/
[root@localhost ~]# ldconfig
[root@localhost ~]# vim /etc/man_db.conf 
#MANDATORY_MANPATH                      /usr/src/pvm3/man
#
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man		//添加一行

3.創建各實例數據存放的目錄

[root@localhost ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 29 13:45 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 29 13:45 3307
drwxr-xr-x. 2 mysql mysql 6 Jul 29 13:45 3308
[root@localhost ~]# tree /opt/data/
/opt/data/
|-- 3306
|-- 3307
`-- 3308

4.初始化各示例

//初始化3306
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3306
2022-07-29T05:48:04.206397Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T05:48:04.369296Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T05:48:04.403256Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T05:48:04.462960Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 03b0e61e-0f02-11ed-b4ce-000c296d5362.
2022-07-29T05:48:04.464340Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-29T05:48:04.643259Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:48:04.643284Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:48:04.643585Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T05:48:04.717924Z 1 [Note] A temporary password is generated for root@localhost: ,dASzpwwE3RJ
[root@localhost ~]# echo ',dASzpwwE3RJ' > 3306
[root@localhost ~]# ls
3306  anaconda-ks.cfg


//初始化3307
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2022-07-29T05:49:29.037700Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T05:49:29.195218Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T05:49:29.224130Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T05:49:29.281903Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 363f3e1c-0f02-11ed-8fdd-000c296d5362.
2022-07-29T05:49:29.283175Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-29T05:49:29.523082Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:49:29.523118Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:49:29.523503Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T05:49:29.581009Z 1 [Note] A temporary password is generated for root@localhost: )MhldlF<o23j
[root@localhost ~]# echo ')MhldlF<o23j' > 3307
[root@localhost ~]# ls
3306  3307  anaconda-ks.cfg


//初始化3308
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3308
2022-07-29T05:50:14.735254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-29T05:50:14.892190Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-29T05:50:14.915269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-29T05:50:14.973272Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 517b3121-0f02-11ed-a3f6-000c296d5362.
2022-07-29T05:50:14.974697Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-29T05:50:15.340479Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:50:15.340510Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-29T05:50:15.341068Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-29T05:50:15.368072Z 1 [Note] A temporary password is generated for root@localhost: tkdnhiEk>5vh
[root@localhost ~]# echo 'tkdnhiEk>5vh' > 3308
[root@localhost ~]# ls
3306  3307  3308  anaconda-ks.cfg

5.配置配置文件/etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf
[root@localhost ~]# cat /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin

[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log

[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3307.pid
log-error=/var/log/3307.log

[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log

6.啟動各示例

[root@localhost ~]# mysqld_multi start 3306
-bash: /usr/local/mysql/bin/mysqld_multi: /usr/bin/perl: bad interpreter: No such file or directory				//需要下載perl包
[root@localhost ~]# dnf -y install perl
[root@localhost mysql]# yum install ncurses-compat-libs
[root@localhost mysql]# file /usr/local/mysql/bin/mysqld_multi
/usr/local/mysql/bin/mysqld_multi: Perl script text executable
[root@localhost ~]# mysqld_multi start 3306
[root@localhost ~]# mysqld_multi start 3307
[root@localhost ~]# mysqld_multi start 3308
[root@localhost ~]# ss -anlt
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             80                               *:3308                          *:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             80                               *:3306                          *:*                          
LISTEN        0             80                               *:3307                          *:*                          

7.使用system控制啟動

//需要先把mysql服務停止 //mysqld_mulit 命令停止不了只能殺進程
[root@localhost ~]# ps -ef | grep 3306 | grep -v grep
root       77016       1  0 13:55 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306 --port=3306 --socket=/tmp/mysql3306.sock --pid-file=/opt/data/3306/mysql_3306.pid --log-error=/var/log/3306.log
mysql      77152   77016  0 13:55 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data/3306 --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/log/3306.log --pid-file=/opt/data/3306/mysql_3306.pid --socket=/tmp/mysql3306.sock --port=3306
[root@localhost ~]# ps -ef | grep 3306 | grep -v grep | awk '{print$2}'
77016
77152
[root@localhost ~]# ps -ef | grep 3306 | grep -v grep | awk '{print$2}' | xargs kill -9
[root@localhost ~]# ss -anlt
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             80                               *:3308                          *:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             80                               *:3307                          *:*                          
[root@localhost ~]# ps -ef | grep 3307 | grep -v grep | awk '{print$2}' | xargs kill -9
[root@localhost ~]# ss -anlt
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             80                               *:3308                          *:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
[root@localhost ~]# ps -ef | grep 3308 | grep -v grep | awk '{print$2}' | xargs kill -9
[root@localhost ~]# ss -anlt
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             128                           [::]:22                         [::]:*                         

//找個一個系統預設可以使用system控制的配置文件進行cp一下,併進行修改
[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/3306.service

//配置3306
[root@localhost ~]# vim /usr/lib/systemd/system/3306.service
[Unit]
Description=3306 server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306
ExecStop=ps -ef | grep 3306 | grep -v grep | awk '{print$2}' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

//配置3307
[root@localhost ~]# cp /usr/lib/systemd/system/3306.service /usr/lib/systemd/system/3307.service
[root@localhost ~]# vim /usr/lib/systemd/system/3307.service    //使用:% s/6/7/g一鍵替換
[Unit]
Description=3307 server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3307
ExecStop=ps -ef | grep 3307 | grep -v grep | awk '{print$2}' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target


//配置3308
[root@localhost ~]# cp /usr/lib/systemd/system/3306.service /usr/lib/systemd/system/3308.service
[root@localhost ~]# vim /usr/lib/systemd/system/3308.service     //使用:% s/6/7/g一鍵替換
[Unit]
Description=3308 server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3308
ExecStop=ps -ef | grep 3308 | grep -v grep | awk '{print$2}' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target

//刷新一下
[root@localhost ~]# systemctl daemon-reload		

//關閉防火牆和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config 
SELINUX=disabled

//啟動3306,3307,3308
[root@localhost ~]# systemctl start 3306
Job for 3306.service failed because the control process exited with error code.
See "systemctl status 3306.service" and "journalctl -xe" for details.  //沒有找到my_print_defaults這個文件

//創建一個軟鏈接到/usr/bin下
[root@localhost ~]# ln -s /usr/local/mysql/bin/my_print_defaults /usr/bin/my_print_defaults
[root@localhost ~]# systemctl start 3306
[root@localhost ~]# systemctl start 3307
[root@localhost ~]# systemctl start 3308
[root@localhost ~]# ss -anlt
State         Recv-Q        Send-Q               Local Address:Port               Peer Address:Port        Process        
LISTEN        0             128                        0.0.0.0:22                      0.0.0.0:*                          
LISTEN        0             80                               *:3308                          *:*                          
LISTEN        0             128                           [::]:22                         [::]:*                          
LISTEN        0             80                               *:3306                          *:*                          
LISTEN        0             80                               *:3307                          *:*                          

8.初始化密碼

//3306
[root@localhost ~]# mysql -uroot -p',dASzpwwE3RJ' -S /tmp/mysql.sock
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

//3307
[root@localhost ~]# mysql -uroot -p')MhldlF<o23j' -S /tmp/mysql3307.sock
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

//3308
[root@localhost ~]# mysql -uroot -p'tkdnhiEk>5vh' -S /tmp/mysql3308.sock
mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

-Advertisement-
Play Games
更多相關文章
  • 如何對Linux進行擴容: 1、在VM上添加硬碟 2、使用lsblk,查看新增的磁碟 3、使用fdisk /dev/sdd,對新增磁碟sdd進行磁碟分區 依次輸入,n,p,w 4、查看新創建出來的分區 lsblk 5、對新創建出來的分區,創建PV,pvcreate /dev/sdd1 6、使用 pv ...
  • Linux系統基礎(一) Linux的基本原則: 由目的單一的小程式組成,組合小程式完成複雜任務; 一切皆文件; 配置文件保存為純文本格式。 1、shell 1.1 shell簡介 Shell俗稱殼(用來區別於核),是指“為使用者提供操作界面”的軟體(命令解析器)。它類似於DOS下的command. ...
  • 1、文件目錄結構 /:是Linux系統的根目錄 /bin:存放用戶經常使用的命令 /boot:啟動載入程式的靜態文件 /dev:設備文件目錄,不能單獨分區 /etc:系統配置文件目錄 /home:普通用戶的家目錄 /root:系統管理員的家目錄 /run:進程的運行數據存放的目錄 /sbin:存放系 ...
  • Logic Pro X Mac版是一款專業音頻製作軟體,作為Mac上功能完備的專業錄音室,Logic Pro X為音樂人提供了從創作第一個音符到完成最後的母帶所需的一切。它為您帶來的軟體樂器與音頻處理插件足以讓您製作任何風格的音樂! 詳情:Logic Pro X for Mac(專業級音頻製作軟體) ...
  • MDK ARM 5.28 之後包括 5.37 的版本. 這些版本即使勾選 Reset And Run, 在燒錄後也不會自動重啟執行 需要做以下設置 Debug -> ST-Link Debugger -> Settings 切換到 Pack 標簽頁, 取消勾選 Enable 點擊 OK 保存. 不能... ...
  • 寫在前面 本系列的文章是博主邊學邊記錄的,可能不是特別的正確,因為會加上博主自己的理解,僅供參考。 正文: 為了能夠將用戶程式裝入記憶體,必須為它分配一定大小的記憶體空間。常見的分配方式有: 1.連續分配 連續分配方式是最早出現的一種存儲器分配方式,該分配方式為一個用戶程式分配一個連續的記憶體空間。常見的 ...
  • 文本編輯工具VIM 1.vi/vim介紹 我們要學會如何去新建文件、刪除文件、修改文件等等,那麼做這些操作就需要一個文本編輯工具。而在linux中最經典最流行的文本編輯工具就是vi/vim,當然也有一些其他的文本編輯工具。 例如 emacs pico nano joe jed 諸如此類,但我們只需要 ...
  • SiteSucker for Mac是一款運行在Mac平臺上的整站下載工具,在SiteSucker Mac版中輸入網址就能離線下載一個網站里的所有內容,包括HTML、圖片、CSS 樣式表、JS 文件、Flash 文件等,SiteSucker for mac版的操作十分簡單,非常的實用。 詳情:Sit ...
一周排行
    -Advertisement-
    Play Games
  • 1. 說明 /* Performs operations on System.String instances that contain file or directory path information. These operations are performed in a cross-pla ...
  • 視頻地址:【WebApi+Vue3從0到1搭建《許可權管理系統》系列視頻:搭建JWT系統鑒權-嗶哩嗶哩】 https://b23.tv/R6cOcDO qq群:801913255 一、在appsettings.json中設置鑒權屬性 /*jwt鑒權*/ "JwtSetting": { "Issuer" ...
  • 引言 集成測試可在包含應用支持基礎結構(如資料庫、文件系統和網路)的級別上確保應用組件功能正常。 ASP.NET Core 通過將單元測試框架與測試 Web 主機和記憶體中測試伺服器結合使用來支持集成測試。 簡介 集成測試與單元測試相比,能夠在更廣泛的級別上評估應用的組件,確認多個組件一起工作以生成預 ...
  • 在.NET Emit編程中,我們探討了運算操作指令的重要性和應用。這些指令包括各種數學運算、位操作和比較操作,能夠在動態生成的代碼中實現對數據的處理和操作。通過這些指令,開發人員可以靈活地進行算術運算、邏輯運算和比較操作,從而實現各種複雜的演算法和邏輯......本篇之後,將進入第七部分:實戰項目 ...
  • 前言 多表頭表格是一個常見的業務需求,然而WPF中卻沒有預設實現這個功能,得益於WPF強大的控制項模板設計,我們可以通過修改控制項模板的方式自己實現它。 一、需求分析 下圖為一個典型的統計表格,統計1-12月的數據。 此時我們有一個需求,需要將月份按季度劃分,以便能夠直觀地看到季度統計數據,以下為該需求 ...
  • 如何將 ASP.NET Core MVC 項目的視圖分離到另一個項目 在當下這個年代 SPA 已是主流,人們早已忘記了 MVC 以及 Razor 的故事。但是在某些場景下 SSR 還是有意想不到效果。比如某些靜態頁面,比如追求首屏載入速度的時候。最近在項目中回歸傳統效果還是不錯。 有的時候我們希望將 ...
  • System.AggregateException: 發生一個或多個錯誤。 > Microsoft.WebTools.Shared.Exceptions.WebToolsException: 生成失敗。檢查輸出視窗瞭解更多詳細信息。 內部異常堆棧跟蹤的結尾 > (內部異常 #0) Microsoft ...
  • 引言 在上一章節我們實戰了在Asp.Net Core中的項目實戰,這一章節講解一下如何測試Asp.Net Core的中間件。 TestServer 還記得我們在集成測試中提供的TestServer嗎? TestServer 是由 Microsoft.AspNetCore.TestHost 包提供的。 ...
  • 在發現結果為真的WHEN子句時,CASE表達式的真假值判斷會終止,剩餘的WHEN子句會被忽略: CASE WHEN col_1 IN ('a', 'b') THEN '第一' WHEN col_1 IN ('a') THEN '第二' ELSE '其他' END 註意: 統一各分支返回的數據類型. ...
  • 在C#編程世界中,語法的精妙之處往往體現在那些看似微小卻極具影響力的符號與結構之中。其中,“_ =” 這一組合突然出現還真不知道什麼意思。本文將深入剖析“_ =” 的含義、工作原理及其在實際編程中的廣泛應用,揭示其作為C#語法奇兵的重要角色。 一、下劃線 _:神秘的棄元符號 下劃線 _ 在C#中並非 ...