無論是sqlserver localdb還是 sqlServer 的其它版本,在windows11下,安裝后都無法啟動 sqlservr.exe, 總之就是各種錯誤
后來多方搜索查詢,發現好像是三星的m.2 ssd問題..我用的是三星980 m.2 恰好中招
再后來,經過多方搜索和查詢發現下面這個帖子
https://docs.microsoft.com/en-us/answers/questions/668708/ssd-showing-incorrect-bytes-per-sector-win-11-sql.html
用powershell運行下面這個命令,果然顯示的異常(這兩個32768導致的sqlserver出錯)
fsutil fsinfo sectorinfo c:
PS C:\Windows\system32> fsutil fsinfo sectorinfo c: LogicalBytesPerSector : 512 PhysicalBytesPerSectorForAtomicity : 32768 PhysicalBytesPerSectorForPerformance : 32768 FileSystemEffectivePhysicalBytesPerSectorForAtomicity : 4096 設備校准 : 已校准(0x000) 設備上的分區校准: 已校准(0x000) 無搜尋懲罰 支持剪裁 不支持 DAX 未精簡預配 PS C:\Windows\system32>
解決方案就是執行以下命令(powershell或者bat都行,但是要以管理員身份)
reg add "HKLM\SYSTEM\CurrentControlSet\Services\stornvme\Parameters\Device" /v "ForcedPhysicalSectorSizeInBytes" /t reg_multi_sz /d "* 4095" /f
重啟之后再看 fsutil fsinfo sectorinfo c: 就正常了...
PS C:\Windows\system32> fsutil fsinfo sectorinfo c: LogicalBytesPerSector : 512 PhysicalBytesPerSectorForAtomicity : 4096 PhysicalBytesPerSectorForPerformance : 4096 FileSystemEffectivePhysicalBytesPerSectorForAtomicity : 4096 設備校准 : 已校准(0x000) 設備上的分區校准: 已校准(0x000) 無搜尋懲罰 支持剪裁 不支持 DAX 未精簡預配 PS C:\Windows\system32>
接下來隨便怎么安裝啟動都沒有問題了..
還有一個就是localdb,可能需要把當前登錄的用戶,加入到users用戶組,否則可能還會出現各種異常
1.將當前的用戶名加入到Users組里
2.使用這個命令 sqllocaldb d MSSQLLocalDB 將之前的默認數據庫刪除
3.使用這個命令 重新建立一個數據庫 sqllocaldb c MSSQLLocalDB -s
4.打開 ssms, 服務器名稱里填 (localdb)\MSSQLLocalDB 身份驗證使用 windows身份驗證
5.enjoy