Mssql 2017修改master默認排序規則


將sqlserver數據庫從Windows服務器遷移到了linux服務器,經過一番折騰終於是安裝好了。數據庫也正常運行,但下午的時候同事告訴我說,軟件在做操作的時候提示排序規則有問題。部分中文亂碼,顯示為問號,如下圖所示

經過對比遷移前后的數據庫master,發現:Windows下Sqlserver排序規則為:Chinese_PRC_CI_AS,Linux系統下則為SQL_Latin1_General_CP1_CI_AS。於是就想到了修改排序規則,很快查到一些資料。

1.網上所說的方法,在sqlcmd命令下執行

ALTER DATABASE [數據庫名] COLLATE Chinese_PRC_CI_AS;

這種方法對於master這類系統級別的表沒有任何作用,該命令只適用於系統表除外的表。

修改失敗后,繼續查找能修改系統表排序規則的方法。問過很多人,查找過很多資料,沒啥用。

無意間發現之前自己安裝mssql時寫了一篇博客:里面有用到mssql-conf這個工具,然后就查看了一下該命令用法。發現里面有個參數(set-collation)可以直接修改系統表排序規則

具體參數如下

root@newings:/opt/mssql/bin# sudo /opt/mssql/bin/mssql-conf
usage: mssql-conf [-h] [-n]  ...

positional arguments:
  
    setup          初始化並設置 Microsoft SQL Server。
    set            設置某個設置的值
    unset          取消設置某個設置的值
    list           列出受支持的設置
    traceflag      啟用/禁用一個或多個跟蹤標志
    set-sa-password
                   設置系統管理員(SA)密碼
    set-collation  設置系統數據庫的排序規則
    validate       驗證配置文件
    set-edition    設置 SQL Server 實例的版本

optional arguments:
  -h, --help       show this help message and exit
  -n, --noprompt   不提示用戶並使用環境變量或默認值。

第一次沒成功。如下所示

root@newings:/opt/mssql/bin# sudo /opt/mssql/bin/mssql-conf set-collation
Enter the collation: Chinese_PRC_CI_AS
正在配置 SQL Server...

2019-04-19 13:07:06.51 Server      Microsoft SQL Server 2017 (RTM-CU13) (KB4466404) - 14.0.3048.4 (X64) 
    Nov 30 2018 12:57:58 
    Copyright (C) 2017 Microsoft Corporation
    Developer Edition (64-bit) on Linux (Ubuntu 16.04.6 LTS)
2019-04-19 13:07:06.52 Server      UTC adjustment: 8:00
2019-04-19 13:07:06.52 Server      (c) Microsoft Corporation.
2019-04-19 13:07:06.52 Server      All rights reserved.
2019-04-19 13:07:06.52 Server      Server process ID is 4124.
2019-04-19 13:07:06.52 Server      Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2019-04-19 13:07:06.52 Server      Registry startup parameters: 
     -d /var/opt/mssql/data/master.mdf
     -l /var/opt/mssql/data/mastlog.ldf
     -e /var/opt/mssql/log/errorlog
2019-04-19 13:07:06.52 Server      Command Line Startup Parameters:
     -q "Chinese_PRC_CI_AS"
2019-04-19 13:07:06.52 Server      Error: 17113, Severity: 16, State: 1.
2019-04-19 13:07:06.52 Server      Error 5(Access is denied.) occurred while opening file '/var/opt/mssql/data/master.mdf' to obtain configuration information at startup. An invalid startup option might have caused the error. Verify your startup options, and correct or remove them if necessary.

看到這個東西也是一頭霧水啊,完全不知道從哪里下手,又折騰了好半天。還是沒搞定,這時候想到了,如果我重新裝一個數據庫直接修改應該成功吧。

果然,裝完數據庫,啥都沒干我就直接執行了下面的命令。成功了

sudo /opt/mssql/bin/mssql-conf set-collation

結合第二次和第三次操作過程,發現。執行該命令,數據庫必須處於停止狀態,如果在運行狀態是會報錯的!!!

第三次執行如下所示,命令顯示不全,但不影響。

     -e /var/opt/mssql/log/errorlog
2019-04-19 12:41:20.81 Server      Command Line Startup Parameters:
     -q "Chinese_PRC_CI_AS"
2019-04-19 12:41:20.81 Server      SQL Server detected 1 sockets with 4 cores per socket and 8 logical processors per socket, 8 total logical processors; using 8 logical processors based on SQL Server licensing. This is an informational message; no user action is required.
2019-04-19 12:41:20.81 Server      SQL Server is starting at normal priority base (=7). This is an informational message only. No user action is required.
2019-04-19 12:41:20.81 Server      Detected 25706 MB of RAM. This is an informational message; no user action is required.
2019-04-19 12:41:20.81 Server      Using conventional memory in the memory manager.
2019-04-19 12:41:20.81 Server      Large Page Allocated: 32MB 
2019-04-19 12:41:20.90 Server      Buffer pool extension is already disabled. No action is necessary. 
2019-04-19 12:41:20.95 Server      Perfmon counters for resource governor pools and groups failed to initialize and are disabled.
2019-04-19 12:41:20.96 Server      InitializeExternalUserGroupSid failed. Implied authentication will be disabled.
2019-04-19 12:41:20.96 Server      Implied authentication manager initialization failed. Implied authentication will be disabled.
2019-04-19 12:41:20.97 Server      Successfully initialized the TLS configuration. Allowed TLS protocol versions are ['1.0 1.1 1.2']. Allowed TLS ciphers are ['ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:!DHE-RSA-AES256-GCM-SHA384:!DHE-RSA-AES128-GCM-SHA256:!DHE-RSA-AES256-SHA:!DHE-RSA-AES128-SHA'].
2019-04-19 12:41:20.98 Server      The maximum number of dedicated administrator connections for this instance is '1'
2019-04-19 12:41:20.98 Server      Node configuration: node 0: CPU mask: 0x00000000000000ff:0 Active CPU mask: 0x00000000000000ff:0. This message provides a description of the NUMA configuration for this computer. This is an informational message only. No user action is required.
2019-04-19 12:41:20.99 Server      Using dynamic lock allocation.  Initial allocation of 2500 Lock blocks and 5000 Lock Owner blocks per node.  This is an informational message only.  No user action is required.
2019-04-19 12:41:20.99 Server      In-Memory OLTP initialized on standard machine.
2019-04-19 12:41:21.09 Server      Database Instant File Initialization: enabled. For security and performance considerations see the topic 'Database Instant File Initialization' in SQL Server Books Online. This is an informational message only. No user action is required.
ForceFlush is enabled for this instance. 
2019-04-19 12:41:21.09 Server      Database Mirroring Transport is disabled in the endpoint configuration.
2019-04-19 12:41:21.09 spid5s      Warning ******************
2019-04-19 12:41:21.09 spid5s      SQL Server started in single-user mode. This an informational message only. No user action is required.
2019-04-19 12:41:21.10 Server      Query Store settings initialized with enabled = 1, 
2019-04-19 12:41:21.10 spid5s      Starting up database 'master'.
2019-04-19 12:41:21.10 Server      Software Usage Metrics is disabled.
ForceFlush feature is enabled for log durability.
2019-04-19 12:41:21.44 spid5s      SQL Server Audit is starting the audits. This is an informational message. No user action is required.
2019-04-19 12:41:21.44 spid5s      SQL Server Audit has started the audits. This is an informational message. No user action is required.
2019-04-19 12:41:21.61 spid5s      SQL Trace ID 1 was started by login "sa".
2019-04-19 12:41:21.72 spid5s      Server name is 'newings'. This is an informational message only. No user action is required.
2019-04-19 12:41:21.72 spid5s      Always On Availability Groups was not started because the SQL Server instance is running in single-user mode.  This is an informational message.  No user action is required.
2019-04-19 12:41:21.72 spid23s     Starting up database 'jsswak-jinhua'.
2019-04-19 12:41:21.72 spid22s     Starting up database 'jsswak-hn'.
2019-04-19 12:41:21.72 spid9s      Starting up database 'mssqlsystemresource'.
2019-04-19 12:41:21.72 spid21s     Starting up database 'jsswak-hz'.
2019-04-19 12:41:21.73 spid27s     Starting up database 'jsswak-jx'.
2019-04-19 12:41:21.72 spid20s     Starting up database 'msdb'.
2019-04-19 12:41:21.72 spid25s     Starting up database 'jsswak-zh'.
2019-04-19 12:41:21.73 spid26s     Starting up database 'KSSTHLYDB'.
2019-04-19 12:41:21.73 spid9s      The resource database build version is 14.00.3048. This is an informational message only. No user action is required.
2019-04-19 12:41:21.72 spid24s     Starting up database 'jsswak-sjs'.
2019-04-19 12:41:21.74 spid9s      Starting up database 'model'.
2019-04-19 12:41:21.85 spid18s     A self-generated certificate was successfully loaded for encryption.
2019-04-19 12:41:21.85 spid18s     Server is listening on [ 'any' <ipv6> 1433].
2019-04-19 12:41:21.85 spid18s     Server is listening on [ 'any' <ipv4> 1433].
2019-04-19 12:41:21.86 Server      Server is listening on [ ::1 <ipv6> 1434].
2019-04-19 12:41:21.86 Server      Server is listening on [ 127.0.0.1 <ipv4> 1434].
2019-04-19 12:41:21.86 Server      Dedicated admin connection support was established for listening locally on port 1434.
2019-04-19 12:41:21.87 spid18s     SQL Server is now ready for client connections. This is an informational message; no user action is required.
2019-04-19 12:41:22.18 spid22s     Parallel redo is started for database 'jsswak-hn' with worker pool size [4].
2019-04-19 12:41:22.77 spid23s     Parallel redo is started for database 'jsswak-jinhua' with worker pool size [4].
2019-04-19 12:41:22.84 spid5s      Parallel redo is shutdown for database 'jsswak-hn' with worker pool size [4].
2019-04-19 12:41:22.87 spid24s     Parallel redo is started for database 'jsswak-sjs' with worker pool size [4].
2019-04-19 12:41:23.24 spid21s     Parallel redo is started for database 'jsswak-hz' with worker pool size [4].
2019-04-19 12:41:23.27 spid26s     Parallel redo is started for database 'KSSTHLYDB' with worker pool size [4].
2019-04-19 12:41:23.28 spid5s      Parallel redo is shutdown for database 'jsswak-jinhua' with worker pool size [4].
2019-04-19 12:41:23.49 spid5s      Parallel redo is shutdown for database 'jsswak-sjs' with worker pool size [4].
2019-04-19 12:41:23.70 spid5s      Parallel redo is shutdown for database 'jsswak-hz' with worker pool size [4].
2019-04-19 12:41:23.70 spid27s     Parallel redo is started for database 'jsswak-jx' with worker pool size [4].
2019-04-19 12:41:23.90 spid9s      Polybase feature disabled.
2019-04-19 12:41:23.90 spid9s      Clearing tempdb database.
2019-04-19 12:41:24.07 spid24s     Parallel redo is shutdown for database 'KSSTHLYDB' with worker pool size [4].
2019-04-19 12:41:24.17 spid25s     Parallel redo is started for database 'jsswak-zh' with worker pool size [4].
2019-04-19 12:41:24.21 spid5s      Parallel redo is shutdown for database 'jsswak-jx' with worker pool size [4].
2019-04-19 12:41:24.64 spid20s     Parallel redo is shutdown for database 'jsswak-zh' with worker pool size [4].
2019-04-19 12:41:25.41 spid9s      Starting up database 'tempdb'.
2019-04-19 12:41:25.67 spid9s      The tempdb database has 1 data file(s).
2019-04-19 12:41:25.77 spid5s      Error: 49958, Severity: 21, State: 1.
2019-04-19 12:41:25.77 spid5s      The server collation cannot be changed with user databases attached. Please detach user databases before changing server collation.
2019-04-19 12:41:25.77 spid5s      Error: 2745, Severity: 16, State: 2.
2019-04-19 12:41:25.77 spid5s      Process ID 5 has raised user error 49958, severity 21. SQL Server is terminating this process.
2019-04-19 12:41:25.77 spid5s      SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.

執行到tempdb的時候,就報錯了!請留這句話

The server collation cannot be changed with user databases attached. Please detach user databases before changing server collation.

這句話,大概意思就是,在修改系統庫排序規則的時候,請將將數據庫(系統庫除外的庫)分離后再執行操作!!!

最后一次,在做完數據庫分離后執行命令果然是成功了。

2019-04-19 12:50:15.62 spid5s      SQL Trace was stopped due to server shutdown. Trace ID = '1'. This is an informational message only; no user action is required.
服務器排序規則已更改。
請運行 "sudo systemctl start mssql-server" 以啟用 SQL Server。

執行成功提示。

mssql 2017 ubuntu安裝篇:https://www.cnblogs.com/Roobbin/p/9626508.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM