Windows 使用VSCode遠端連線到Linux開發除錯MySQL

eric0435發表於2021-12-17

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

1.Linux系統上安裝相關開發工具

[root@gbase yum.repos.d]# yum install gdb-gdbserver

[root@gbase yum.repos.d]# yum install gdb

[root@gbase yum.repos.d]# yum install gcc

[root@gbase yum.repos.d]# yum install cmake

2.配置VSCode可以免密登入Linux

2.1在Windows上生成金鑰

C:\Users\Administrator>ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (C:\Users\Administrator\.ssh\id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in id_rsa.

Your public key has been saved in id_ras.pub.

The key fingerprint is:

SHA256:2ya72QX0JQBxKTLM+3S1H3FFYnHHrve1t0cSbqXJiqI mysql@gbase

The key's randomart image is:

+---[RSA 2048]----+

| o ooo. ++*|

| = .......o+|

| + ......+ |

| . .....oo o|

| oS.. .+ B |

| .o . X +|

| o o..o ++|

| .*... .+|

| E.+o. .+|

+----[SHA256]-----+

2.2 在Linux伺服器上生成金鑰

[root@gbase ~]# su - mysql

Last login: Sun Sep 26 09:24:11 CST 2021 on pts/5

[mysql@gbase ~]$ pwd

/home/mysql

[mysql@gbase ~]$ ls -lrt

total 0

drwxrwxr-x. 2 mysql mysql 6 Sep 24 16:19 perl5

[mysql@gbase ~]$ cd ~/.ssh

-bash: cd: /home/mysql/.ssh: No such file or directory

[mysql@gbase ~]$ mkdir ~/.ssh

[mysql@gbase ~]$ cd ~/.ssh

[mysql@gbase .ssh]$ pwd

/home/mysql/.ssh

[mysql@gbase .ssh]$ ls -lrt

total 0

增加root許可權:visudo 進入文字後找到root ALL=(ALL) ALL,另起一行,加入admin ALL=(ALL) NOPASSWD:ALL su admin 切換到新使用者 再使

用sudo su -切換回root,說明許可權正常,進行下一步

[root@gbase ~]# visudo

## Allow root to run any commands anywhere

root ALL=(ALL) ALL

mysql ALL=(ALL) NOPASSWD:ALL

[mysql@gbase ~]$ sudo su -

Last login: Sun Sep 26 11:41:38 CST 2021 on pts/1

[root@gbase ~]# su - mysql

Last login: Sun Sep 26 14:20:50 CST 2021 from 192.168.1.12 on pts/3

[mysql@gbase ~]$

2.3將windows中生成的公鑰上傳到/home/mysql/.ssh/目錄

C:\Users\Administrator>scp C:\Users\Administrator\.ssh\id_rsa.pud mysql@192.168.1.249:/home/mysql/.ssh/authorized_keys

[mysql@gbase ~]$ chmod 700 /home/mysql/.ssh

[mysql@gbase ~]$ chmod 600 /home/mysql/.ssh/authorized_keys

2.4切換到root,關閉root登入 sudo su - vim /etc/ssh/sshd_config 找到#PermitRootLogin yes去掉#把yes改為no systemctl restart sshd 重啟服務並生效

[root@gbase .ssh]# vim /etc/ssh/sshd_config

# $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file. See

# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with

# OpenSSH is to specify options with their default value where

# possible, but leave them commented. Uncommented options override the

# default value.

# If you want to change the port on a SELinux system, you have to tell

# SELinux about this change.

# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER

#

Port 22

#AddressFamily any

#ListenAddress 0.0.0.0

#ListenAddress ::

HostKey /etc/ssh/ssh_host_rsa_key

#HostKey /etc/ssh/ssh_host_dsa_key

HostKey /etc/ssh/ssh_host_ecdsa_key

HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying

#RekeyLimit default none

# Logging

#SyslogFacility AUTH

SyslogFacility AUTHPRIV

#LogLevel INFO

# Authentication:

#LoginGraceTime 2m

PermitRootLogin no #改成no

#StrictModes yes

#MaxAuthTries 6

#MaxSessions 10

RSAAuthentication yes #要開啟

PubkeyAuthentication yes #要開啟

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2

# but this is overridden so installations will only check .ssh/authorized_keys

AuthorizedKeysFile .ssh/authorized_keys

[root@gbase ~]# service sshd restart

Redirecting to /bin/systemctl restart sshd.service

在windows中測試ssh登入

C:\Users\Administrator>ssh mysql@192.168.1.249

Last login: Sun Sep 26 14:22:54 2021

]ysql@gbase:~[mysql@gbase ~]$ pwd

/home/mysql

2.5 配置vscode透過remote ssh連線Linux的配置檔案C:\Users\Administrator\.ssh\config

Host 192.168.1.249

HostName 192.168.1.249

User root

IdentityFile "D:\ssh\vscode"

2.6 透過vscode遠端連線Linux伺服器出現以下錯誤

> Waiting for client to transfer server archive...

> Waiting for /home/mysql/.vscode-server/bin/7f6ab5485bbc008386c4386d08766667e1552

> 44e/vscode-scp-done.flag and vscode-server.tar.gz to exist

>

[12:31:20.267] Got request to download on client for {"platform":"linux","arch":"x64","destFolder":"/home/mysql/.vscode-server/bin/7f6ab5485bbc008386c4386d08766667e155244e"}

[12:31:20.268] Downloading VS Code server locally...

[12:31:20.420] Resolver error: Error: Running the contributed command: '_workbench.downloadResource' failed.

[mysql@gbase /]$ cd /home/mysql

[mysql@gbase ~]$ ls -lrt .vscode-server

total 0

drwxrwxr-x. 3 mysql mysql 54 Sep 26 09:46 bin

[mysql@gbase ~]$ cd .vscode-server

[mysql@gbase .vscode-server]$ ls

bin

[mysql@gbase .vscode-server]$ cd bin

[mysql@gbase bin]$ ls

7f6ab5485bbc008386c4386d08766667e155244e

[mysql@gbase bin]$ cd 7f6ab5485bbc008386c4386d08766667e155244e/

[mysql@gbase 7f6ab5485bbc008386c4386d08766667e155244e]$ ls

vscode-remote-lock.mysql.7f6ab5485bbc008386c4386d08766667e155244e vscode-server.tar.gz

[mysql@gbase 7f6ab5485bbc008386c4386d08766667e155244e]$ ls -lrt

total 0

-rw-rw-r--. 1 mysql mysql 0 Sep 26 11:37 vscode-remote-lock.mysql.7f6ab5485bbc008386c4386d08766667e155244e

-rw-rw-r--. 1 mysql mysql 0 Sep 26 11:37 vscode-server.tar.gz

上面的7f開頭的資料夾稱為Commit Id,現在利用Commit ID下載遠端連線需要的檔案。對於Stabe Version(在VS Code報錯的的視窗中Ctrl+F

搜尋stable,有則為Stable Version)的Remote SSH外掛,如下圖,在“輸出”視窗中Ctrl+F搜尋“stable”。

[12:31:14.904] Using commit id "7f6ab5485bbc008386c4386d08766667e155244e" and quality "stable" for server

然後使用這個連結:下載所需檔案,注意連結中的

$COMMIT_ID這幾個字元(注意$不要忘記)需要換成自己的,比如我的是 7f6ab5485bbc008386c4386d08766667e155244e,那麼此時我通

過就可以下載到

我需要的檔案。

對於Insider版本,

透過這個連結下載相

應檔案。

下載完畢後,將下載的檔案upload到Remote Server的~/.vscode-server/bin/xxx資料夾下(也可以在Remote Server上直接

執行wget 即可下載,

這樣就不用進行上傳操作了),同時刪除其他檔案,最後再使用tar -xvf vscode-server-linux-x64.tar.gz --strip-components 1解壓檔案,

sftp> put D:\ssh\vscode-server-linux-x64.tar.gz

Uploading vscode-server-linux-x64.tar.gz to /home/mysql/vscode-server-linux-x64.tar.gz

100% 45296KB 45296KB/s 00:00:00

D:/ssh/vscode-server-linux-x64.tar.gz: 46383314 bytes transferred in 0 seconds (45296 KB/s)

[mysql@gbase 7f6ab5485bbc008386c4386d08766667e155244e]$ tar -xvf vscode-server-linux-x64.tar.gz --strip-components 1

然後使用chmod +x node server.sh為node和server.sh新增可執行許可權。

[mysql@gbase 7f6ab5485bbc008386c4386d08766667e155244e]$ chmod +x node server.sh

[mysql@gbase 7f6ab5485bbc008386c4386d08766667e155244e]$ ls -lrt

total 117512

-rwxr-xr-x. 1 mysql mysql 222 Sep 22 20:00 server.sh

-rw-r--r--. 1 mysql mysql 34147 Sep 22 20:00 product.json

-rw-r--r--. 1 mysql mysql 1255 Sep 22 20:00 package.json

-rw-r--r--. 1 mysql mysql 13380 Sep 22 20:00 LICENSE

-rwxr-xr-x. 1 mysql mysql 73873984 Sep 22 20:02 node

drwxr-xr-x. 3 mysql mysql 135 Sep 22 20:02 out

drwxr-xr-x. 3 mysql mysql 33 Sep 22 20:02 bin

drwxr-xr-x. 32 mysql mysql 4096 Sep 22 20:02 extensions

drwxr-xr-x. 78 mysql mysql 4096 Sep 22 20:02 node_modules

-rw-rw-r--. 1 mysql mysql 0 Sep 26 11:37 vscode-remote-lock.mysql.7f6ab5485bbc008386c4386d08766667e155244e

-rw-rw-r--. 1 mysql mysql 0 Sep 26 11:37 vscode-server.tar.gz

-rw-rw-r--. 1 mysql mysql 46383314 Sep 26 11:57 vscode-server-linux-x64.tar.gz

再次使用VS Code嘗試連結,這一步會連結成功。

3.vscode在遠端遠端伺服器上依次安裝 C/C++、CMake、CMake Tools外掛
Windows 使用VSCode遠端連線到Linux開發除錯MySQL
Windows 使用VSCode遠端連線到Linux開發除錯MySQL

在使用vscode 遠端除錯程式時出現以下資訊:

Updating C/C++ dependencies...

Downloading package 'C/C++ language components (Linux / x86_64)' Failed. Retrying... Failed. Retrying... Failed. Retrying...Waiting 8 seconds... Failed. Retrying...Waiting 15 seconds... Failed. Retrying...Waiting 15 seconds... Failed. Retrying...Waiting 15 seconds... Failed. Retrying...Waiting 15 seconds... Failed. Retrying...Waiting 15 seconds... Failed. Retrying...Waiting 15 seconds... Failed to download

Failed at stage: downloadPackages

Error: getaddrinfo ENOTFOUND go.microsoft.com

at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)

If you work in an offline environment or repeatedly see this error, try downloading a version of the extension with all the dependencies pre-included from then use the "Install from VSIX" command in VS Code to install it.

Windows 使用VSCode遠端連線到Linux開發除錯MySQL
安裝 C/C++ language components外掛失敗

我們只能手動安裝

開啟網址下載bin_linupwd

x.zip檔案

將bin_linux.zip檔案解壓

cpptools

cpptools-srv

LICENSE.txt

將這三個檔案複製到遠端Linux伺服器的/home/mysql/.vscode-server/extensions/ms-vscode.cpptools-1.6.0/bin目錄中

如果原先存在這個檔案的話先將其備份。

sftp> put F:\bin_linux\bin\*

Uploading cpptools to /home/mysql/.vscode-server/extensions/ms-vscode.cpptools-1.6.0/bin/cpptools

100% 19544KB 19544KB/s 00:00:00

F:/bin_linux/bin/cpptools: 20014008 bytes transferred in 0 seconds (19544 KB/s)

Uploading cpptools-srv to /home/mysql/.vscode-server/extensions/ms-vscode.cpptools-1.6.0/bin/cpptools-srv

100% 11508KB 11508KB/s 00:00:00

F:/bin_linux/bin/cpptools-srv: 11784664 bytes transferred in 0 seconds (11508 KB/s)

Uploading LICENSE.txt to /home/mysql/.vscode-server/extensions/ms-vscode.cpptools-1.6.0/bin/LICENSE.txt

100% 11KB 11KB/s 00:00:00

F:/bin_linux/bin/LICENSE.txt: 11972 bytes transferred in 0 seconds (11 KB/s)

但是沒有用,仍然報錯

如是透過vsix來進行安裝

github上release好多個版本,我遠端看程式碼的主機是redhat Linux系統,所有下載cpptools-linux.vsix。

先刪除我們上傳到/home/mysql/.vscode-server/extensions/ms-vscode.cpptools-1.6.0/bin的三個檔案

[mysql@gbase bin]$ ls -lrt

total 31188

-rw-rw-r--. 1 mysql mysql 11784664 Aug 23 22:29 cpptools-srv

-rw-rw-r--. 1 mysql mysql 20014008 Aug 23 22:29 cpptools

-rw-rw-r--. 1 mysql mysql 11972 Aug 23 22:34 LICENSE.txt

-rw-rw-r--. 1 mysql mysql 582 Sep 26 12:05 common.json

-rw-rw-r--. 1 mysql mysql 301 Sep 26 12:05 linux.clang.arm.json

-rw-rw-r--. 1 mysql mysql 310 Sep 26 12:05 linux.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 300 Sep 26 12:05 linux.clang.x64.json

-rw-rw-r--. 1 mysql mysql 291 Sep 26 12:05 linux.clang.x86.json

-rw-rw-r--. 1 mysql mysql 301 Sep 26 12:05 linux.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 310 Sep 26 12:05 linux.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 302 Sep 26 12:05 linux.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 291 Sep 26 12:05 linux.gcc.x86.json

-rw-rw-r--. 1 mysql mysql 284 Sep 26 12:05 macos.clang.arm.json

-rw-rw-r--. 1 mysql mysql 293 Sep 26 12:05 macos.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 283 Sep 26 12:05 macos.clang.x64.json

-rw-rw-r--. 1 mysql mysql 274 Sep 26 12:05 macos.clang.x86.json

-rw-rw-r--. 1 mysql mysql 284 Sep 26 12:05 macos.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 293 Sep 26 12:05 macos.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 283 Sep 26 12:05 macos.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 274 Sep 26 12:05 macos.gcc.x86.json

drwxrwxr-x. 15 mysql mysql 145 Sep 26 12:05 messages

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.arm.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.x64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.x86.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 89 Sep 26 12:05 windows.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.gcc.x86.json

-rw-rw-r--. 1 mysql mysql 299 Sep 26 12:05 windows.msvc.arm.json

-rw-rw-r--. 1 mysql mysql 324 Sep 26 12:05 windows.msvc.arm64.json

-rw-rw-r--. 1 mysql mysql 383 Sep 26 12:05 windows.msvc.x64.json

-rw-rw-r--. 1 mysql mysql 359 Sep 26 12:05 windows.msvc.x86.json

[mysql@gbase bin]$ rm -rf cpptools*

[mysql@gbase bin]$ rm -rf LICENSE.txt

[mysql@gbase bin]$ ls -lrt

total 116

-rw-rw-r--. 1 mysql mysql 582 Sep 26 12:05 common.json

-rw-rw-r--. 1 mysql mysql 301 Sep 26 12:05 linux.clang.arm.json

-rw-rw-r--. 1 mysql mysql 310 Sep 26 12:05 linux.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 300 Sep 26 12:05 linux.clang.x64.json

-rw-rw-r--. 1 mysql mysql 291 Sep 26 12:05 linux.clang.x86.json

-rw-rw-r--. 1 mysql mysql 301 Sep 26 12:05 linux.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 310 Sep 26 12:05 linux.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 302 Sep 26 12:05 linux.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 291 Sep 26 12:05 linux.gcc.x86.json

-rw-rw-r--. 1 mysql mysql 284 Sep 26 12:05 macos.clang.arm.json

-rw-rw-r--. 1 mysql mysql 293 Sep 26 12:05 macos.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 283 Sep 26 12:05 macos.clang.x64.json

-rw-rw-r--. 1 mysql mysql 274 Sep 26 12:05 macos.clang.x86.json

-rw-rw-r--. 1 mysql mysql 284 Sep 26 12:05 macos.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 293 Sep 26 12:05 macos.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 283 Sep 26 12:05 macos.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 274 Sep 26 12:05 macos.gcc.x86.json

drwxrwxr-x. 15 mysql mysql 145 Sep 26 12:05 messages

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.arm.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.x64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.clang.x86.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 89 Sep 26 12:05 windows.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 12:05 windows.gcc.x86.json

-rw-rw-r--. 1 mysql mysql 299 Sep 26 12:05 windows.msvc.arm.json

-rw-rw-r--. 1 mysql mysql 324 Sep 26 12:05 windows.msvc.arm64.json

-rw-rw-r--. 1 mysql mysql 383 Sep 26 12:05 windows.msvc.x64.json

-rw-rw-r--. 1 mysql mysql 359 Sep 26 12:05 windows.msvc.x86.json

透過vscode 從vsix來進行安裝,選擇本地目錄D:\ssh\cpptools-linux.vsix檔案
Windows 使用VSCode遠端連線到Linux開發除錯MySQL
Windows 使用VSCode遠端連線到Linux開發除錯MySQL

[mysql@gbase bin]$ ls -lrt

total 31188

-rw-rw-r--. 1 mysql mysql 582 Sep 26 15:01 common.json

-rw-rw-r--. 1 mysql mysql 20014008 Sep 26 15:01 cpptools

-rw-rw-r--. 1 mysql mysql 11784664 Sep 26 15:01 cpptools-srv

-rw-rw-r--. 1 mysql mysql 11972 Sep 26 15:01 LICENSE.txt

-rw-rw-r--. 1 mysql mysql 301 Sep 26 15:01 linux.clang.arm.json

-rw-rw-r--. 1 mysql mysql 310 Sep 26 15:01 linux.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 300 Sep 26 15:01 linux.clang.x64.json

-rw-rw-r--. 1 mysql mysql 291 Sep 26 15:01 linux.clang.x86.json

-rw-rw-r--. 1 mysql mysql 301 Sep 26 15:01 linux.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 310 Sep 26 15:01 linux.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 302 Sep 26 15:01 linux.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 291 Sep 26 15:01 linux.gcc.x86.json

-rw-rw-r--. 1 mysql mysql 284 Sep 26 15:01 macos.clang.arm.json

-rw-rw-r--. 1 mysql mysql 293 Sep 26 15:01 macos.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 283 Sep 26 15:01 macos.clang.x64.json

-rw-rw-r--. 1 mysql mysql 274 Sep 26 15:01 macos.clang.x86.json

-rw-rw-r--. 1 mysql mysql 284 Sep 26 15:01 macos.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 293 Sep 26 15:01 macos.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 283 Sep 26 15:01 macos.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 274 Sep 26 15:01 macos.gcc.x86.json

drwxrwxr-x. 15 mysql mysql 145 Sep 26 15:01 messages

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.clang.arm.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.clang.arm64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.clang.x64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.clang.x86.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.gcc.arm.json

-rw-rw-r--. 1 mysql mysql 89 Sep 26 15:01 windows.gcc.arm64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.gcc.x64.json

-rw-rw-r--. 1 mysql mysql 87 Sep 26 15:01 windows.gcc.x86.json

-rw-rw-r--. 1 mysql mysql 299 Sep 26 15:01 windows.msvc.arm.json

-rw-rw-r--. 1 mysql mysql 324 Sep 26 15:01 windows.msvc.arm64.json

-rw-rw-r--. 1 mysql mysql 383 Sep 26 15:01 windows.msvc.x64.json

-rw-rw-r--. 1 mysql mysql 359 Sep 26 15:01 windows.msvc.x86.json

重啟vscdoe

4.使用vscode遠端編譯Linux伺服器的MySQL原始碼,mysql原始碼在/soft/mysql-5.7.26/目錄

這裡需要配置Cmake 生成setting.json配置檔案 點選CMake Tool的設定按鈕,再點選Extention Settings
Windows 使用VSCode遠端連線到Linux開發除錯MySQL

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

這裡選擇Remote [SSH:192.168.1.249],我這對於Build Directory選擇使用預設配置,因為${workspaceFolder}就是/soft/mysql-5.7.26目錄,所以$${workspaceFolder}/build也就是/soft/mysql-5.7.26/build目錄

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

所以Source Directory目錄選擇使用預設的$workspaceFolder}目錄
Windows 使用VSCode遠端連線到Linux開發除錯MySQL

給Configure Args配置以下三個引數

-DWITH_BOOST=/soft/mysql-5.7.26/boost/boost_1_59_0

-DDOWNLOAD_BOOST=1

-DWITH_DEBUG=1

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

選擇編譯器

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

給CMake選擇Debug模式
Windows 使用VSCode遠端連線到Linux開發除錯MySQL

然後進行編譯
Windows 使用VSCode遠端連線到Linux開發除錯MySQL

編譯完成後,在Linux伺服器上初始化mysql資料庫

建立data,etc目錄用來分別存放資料檔案與配置檔案my.cnf

[mysql@gbase build]$ mkdir {data,etc}

[mysql@gbase build]$ cd etc

[mysql@gbase etc]$ vi my.cnf

[mysqld]

basedir=/soft/mysql-5.7.26/build

datadir=/soft/mysql-5.7.26/build/data

bind-address=0.0.0.0

user=mysql

port=3306

log-error=/soft/mysql-5.7.26/build/data/mysql.err

pid-file=/soft/mysql-5.7.26/build/data/mysqld.pid

socket = /soft/mysql-5.7.26/build/data/mysql.sock

character-set-server=utf8mb4

default-storage-engine=INNODB

explicit_defaults_for_timestamp = true

[mysql@gbase build]$ sql/mysqld --defaults-file=etc/my.cnf --initialize-insecure

[mysql@gbase build]$ cd data

[mysql@gbase data]$ ls

auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 mysql mysql.err performance_schema sys

[mysql@gbase data]$ ls -lrt

total 110632

-rw-r-----. 1 mysql mysql 50331648 Sep 26 15:43 ib_logfile1

-rw-r-----. 1 mysql mysql 56 Sep 26 15:43 auto.cnf

-rw-r-----. 1 mysql mysql 1046 Sep 26 15:43 mysql.err

drwxr-x---. 2 mysql mysql 8192 Sep 26 15:43 performance_schema

drwxr-x---. 2 mysql mysql 4096 Sep 26 15:43 mysql

drwxr-x---. 2 mysql mysql 8192 Sep 26 15:43 sys

-rw-r-----. 1 mysql mysql 419 Sep 26 15:43 ib_buffer_pool

-rw-r-----. 1 mysql mysql 50331648 Sep 26 15:43 ib_logfile0

-rw-r-----. 1 mysql mysql 12582912 Sep 26 15:43 ibdata1

[mysql@gbase data]$ more mysql.err

2021-09-26T07:43:43.288066Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)

2021-09-26T07:43:43.288312Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

2021-09-26T07:43:43.289227Z 0 [ERROR] Can't find error-message file '/soft/mysql-5.7.26/build/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.

2021-09-26T07:43:46.058883Z 0 [Warning] InnoDB: New log files created, LSN=45790

2021-09-26T07:43:46.360628Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2021-09-26T07:43:46.558161Z 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: 7b190ba6-1e9d-11ec-93d5-005056a31fca.

2021-09-26T07:43:46.567453Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2021-09-26T07:43:46.569018Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

[mysql@gbase mysql-5.7.26]$ gcc -v -E -x c++ -

Using built-in specs.

COLLECT_GCC=gcc

Target: x86_64-redhat-linux

Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl= --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux

Thread model: posix

gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)

COLLECT_GCC_OPTIONS='-v' '-E' '-mtune=generic' '-march=x86-64'

/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1plus -E -quiet -v -D_GNU_SOURCE - -mtune=generic -march=x86-64

ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include-fixed"

ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../x86_64-redhat-linux/include"

#include "..." search starts here:

#include < ...> search starts here:

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include

/usr/local/include

/usr/include

將下面的內容加入到c_cpp_properties.json中的includePath中

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/x86_64-redhat-linux

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../include/c++/4.8.5/backward

/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include

/usr/local/include

/usr/include

Windows 使用VSCode遠端連線到Linux開發除錯MySQL

加入後錯誤資訊消失


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26015009/viewspace-2848252/,如需轉載,請註明出處,否則將追究法律責任。

相關文章