sql如何重命名实例_重命名Ubuntu Linux上SQL Server实例

sql如何重命名实例

In my previous articles, we installed the SQL Server 2019 CTP 2.1 on Ubuntu Linux. You can follow the below articles to prepare the SQL instance on Linux.

在我之前的文章中,我们在Ubuntu Linux上安装了SQL Server 2019 CTP 2.1。 您可以按照以下文章在Linux上准备SQL实例。

Sometimes we build the server without worrying about the server name. This might be just for the testing purpose. We give it some name but later we might need to change the hostname of the server. It might be due to the naming convention being followed up in the organization. If we rename the hostname of the instance in the Linux operating system, we might need to worry about the SQL instance as well. By default, SQL instance runs on the hostname of the server. Therefore, if we change the hostname, will there be any impact on the application connecting with the SQL Server with the hostname? If we change the hostname of the server, we will definitely want to change the SQL Server name as well to avoid any confusion.

有时,我们在构建服务器时无需担心服务器名称。 这可能只是出于测试目的。 我们给它起一个名字,但是稍后我们可能需要更改服务器的主机名。 这可能是由于组织中遵循了命名约定。 如果在Linux操作系统中重命名实例的主机名,则可能还需要担心SQL实例。 默认情况下,SQL实例在服务器的主机名上运行。 因此,如果我们更改主机名,对使用该主机名与SQL Server连接的应用程序有什么影响? 如果我们更改服务器的主机名,那么我们肯定也会更改SQL Server名称,以免造成混淆。

In this article, we will explore these scenarios

在本文中,我们将探讨这些场景

  • Temporary and Permanent methods to change the hostname of the Ubuntu server

    临时和永久方法来更改Ubuntu服务器的主机名
  • Rename SQL Server instance on Ubuntu

    在Ubuntu上重命名SQL Server实例
  • View the system error logs

    查看系统错误日志

You need to launch the virtual machine configured earlier with SQL instance on it. Launch the terminal from the applications in Ubuntu server.

您需要启动之前配置了SQL实例的虚拟机。 从Ubuntu服务器中的应用程序启动终端。

Run the command ‘hostname’ to get the current hostname. We can see here our current hostname is ‘rajendra-VirtualBox’

运行命令“主机名”以获取当前主机名。 我们可以在这里看到我们当前的主机名是“ rajendra-VirtualBox”

We can change the hostname of Ubuntu with the two methods

我们可以通过两种方法更改Ubuntu的主机名

  1. Temporary change

    临时变更
  2. Permanent change

    永久变更

在Ubuntu中临时更改主机名 (Temporary change the hostname in Ubuntu )

We can change the hostname using the command ‘hostname NewName’. This command needs to be run under the root permissions i.e. sudo. We will get below error message if we try to run the command without sudo permission ‘hostname: you must be root to change the hostname’

我们可以使用命令“主机名NewName”来更改主机名。 该命令需要在root权限(即sudo)下运行。 如果我们尝试在没有sudo权限的情况下运行命令,则会收到以下错误消息:“主机名:您必须是root用户才能更改主机名”

Let us change the hostname from ‘rajendra-VirtualBox’ to ‘rajendra-SQLLinux’ with the below command.

让我们使用以下命令将主机名从“ rajendra-VirtualBox”更改为“ rajendra-SQLLinux”。

$ Sudo hostname rajendra-SQLLinux

$ Sudo主机名rajendra-SQLLinux

Verify the hostname and we can see the new name for the server. You can notice here the command line still says ‘rajendra@rajendra-VirtualBox’

验证主机名,我们可以看到服务器的新名称。 您可以在此处注意到命令行仍然显示“ rajendra @ rajendra-VirtualBox”

If we try to connect the SQL Server with the new hostname, we get an error message that the server was not found or not accessible. This is due to the instance name is not configured with the SQL Server.

如果尝试使用新的主机名连接SQL Server,则会收到一条错误消息,指出找不到或无法访问该服务器。 这是由于没有使用SQL Server配置实例名称。

We can connect to the SQL instance using the IP address and the old instance name ‘rajendra-VirtualBox’ in SQL Server Management Studio as shown below. This shows there is no impact on SQL Server even we have changed the Ubuntu hostname.

我们可以使用IP地址和SQL Server Management Studio中的旧实例名称“ rajendra-VirtualBox”连接到SQL实例,如下所示。 这表明即使我们更改了Ubuntu主机名,对SQL Server也没有影响。

Let us restart the server using the command ‘shutdown -r’. This command schedules the restart of the server. You can see the message ‘Shutdown scheduled for sat 2018-12-08 08:28:56 IST, use shutdown -c to cancel’

让我们使用命令'shutdown -r'重新启动服务器。 此命令安排服务器的重新启动。 您可以看到以下消息:``计划于2018年12月8日星期六停产IST,请使用shutdown -c取消''

If we want to cancel the shutdown, we can run the command ‘shutdown -c’

如果要取消关闭,可以运行命令'shutdown -c'

We get the broadcast message at the scheduled time and the system starts the reboot process.

我们在计划的时间收到广播消息,系统开始重新启动过程。

Once the server reboot is completed, verify the hostname and we are again back to old hostname ‘rajendra-VirtualBox’

服务器重新启动完成后,验证主机名,然后我们又回到旧的主机名'rajendra-VirtualBox'

Ubuntu中的永久更改主机名 (Permanent change hostname in Ubuntu)

We can change hostname permanently using the GUI as well as the command line mode. Click on the ‘system settings’ icon in Ubuntu followed by the details.

我们可以使用GUI和命令行模式永久更改主机名。 单击Ubuntu中的“系统设置”图标,然后单击详细信息。

In details, it opens the device detail and you can see device name as highlighted.

在详细信息中,它将打开设备详细信息,您可以看到突出显示的设备名称。

Device name section is having a text box, therefore enter the new name and close it with the ‘x’ icon on top left side.

设备名称部分有一个文本框,因此请输入新名称并使用左上角的“ x”图标将其关闭。

We are done now. We are having the new server name for our virtual machine.

现在完成。 我们正在为虚拟机使用新的服务器名称。

From the command line, we can run the below command and edit the hostname.

在命令行中,我们可以运行以下命令并编辑主机名。

sudo vi /etc/hostname

须藤vi / etc / hostname

You can restart the server again and verify it. It changes the hostname permanently.

您可以再次重新启动服务器并进行验证。 它将永久更改主机名。

Now, connect to the SQL instance and check the instance name using command ‘select @@servername’. We are still having an old hostname for the SQL Server.

现在,连接到SQL实例,并使用命令'select @@ servername'检查实例名称。 我们仍然有一个旧SQL Server主机名。

We need to drop this server name using the command

我们需要使用以下命令删除该服务器名称

sp_dropserver ‘server name’

sp_dropserver'服务器名称'

In our case, execute the below command in the SSMS.

在我们的情况下,在SSMS中执行以下命令。

Sp_dropserver ‘rajendra-VirtualBox’

Sp_dropserver'rajendra-VirtualBox'

Now, register the new instance name using the sp_addserver command.

现在,使用sp_addserver命令注册新的实例名称。

Sp_addserever ‘server name’,’local’

Sp_addserever'服务器名称','本地'

Therefore run the command as below

因此,如下运行命令

Sp_addserver ‘rajendra-sqllinuxDemo’,’local’

Sp_addserver'rajendra-sqllinuxDemo','本地'

We need to restart SQL Server on Linux to apply this new hostname.

我们需要在Linux上重新启动SQL Server才能应用此新主机名。

Restart the mssql-server services

重新启动mssql服务器服务

Sudo systemctl restart mssql-server

Sudo systemctl 重新启动 mssql-server

Verify the service status, it should be ‘active (running)’

验证服务状态,它应该是“活动的(正在运行)”

Sudo systemctl status mssql-server

sudo systemctl 状态 mssql-server

Connect to SQL instance and verify the instance name. Yes, it is now pointing the new hostname similar to the hostname we have configured at the operating system level.

连接到SQL实例并验证实例名称。 是的,它现在指向的新主机名类似于我们在操作系统级别配置的主机名。

You can now connect to SQL Server using both IP address and the new hostname.

现在,您可以使用IP地址和新的主机名连接到SQL Server。

If you look at the SQL Server logs and filter the results for the server name, you get the below message.

如果查看SQL Server日志并过滤服务器名称的结果,则会收到以下消息。

I found out the issue with this message in the SQL Server logs. If you look carefully, the message says ‘ Server name is ‘rajendra-sqllin’. This is an informational message only. No user action is required.’

我在SQL Server日志中发现了此消息的问题。 如果仔细查看,该消息将显示“服务器名称为'rajendra-sqllin'。 这仅是参考消息。 无需用户操作。'

It shows the server name ‘rajendra-sqllin’ while our actual server name is ”rajendra-sqllinuxDemo’. We can connect to the server name ”rajendra-sqllinuxDemo”’ as shown above. It truncates the server name in the error logs. This feature might be improved in the upcoming releases of SQL Server.

它显示了服务器名称“ rajendra-sqllin”,而我们的实际服务器名称是“ rajendra-sqllinuxDemo”。 我们可以连接到服务器名称“ rajendra-sqllinuxDemo”,如上所示。 它会在错误日志中截断服务器名称。 即将发布SQL Server版本中可能会改进此功能。

We can verify the new instance name using the ‘sp_helpserver’ command as well. In below screenshot, we can see both the commands return the new hostname.

我们也可以使用“ sp_helpserver”命令来验证新实例名称。 在下面的屏幕截图中,我们可以看到两个命令都返回了新的主机名。

结论 (Conclusion)

It is an important thing for the database administrators to know the process of changing the SQL Server instance name. You should explore this article in your test instance. Please note this article applies on the standalone SQL Server instance only. If you are running cluster SQL instance, you need to follow additional steps that I will explore in my future articles.

对于数据库管理员来说,了解更改SQL Server实例名称的过程是很重要的。 您应该在测试实例中浏览本文。 请注意,本文仅适用于独立SQL Server实例。 如果您正在运行群集SQL实例,则需要执行其他步骤,这些步骤我将在以后的文章中进行探讨。

目录 (Table of contents)

SQL Server 2019 on Linux with Ubuntu and Azure Data Studio
SQL Server 2019 on Linux with a Docker container on Ubuntu
SQL Server 2019 on Linux with Ubuntu
SQL Server 2019 installation on Ubuntu without a Docker Container
Renaming Logical and Physical file names in SQL Server on Linux
Rename SQL Server instance on Ubuntu Linux
具有Ubuntu和Azure Data Studio的Linux上SQL Server 2019
Linux上SQL Server 2019和Ubuntu上的Docker容器
Linux与Ubuntu上SQL Server 2019
在没有Docker容器的Ubuntu上安装SQL Server 2019
在Linux上SQL Server中重命名逻辑和物理文件名
在Ubuntu Linux上重命名SQL Server实例

翻译自: https://www.sqlshack.com/renaming-a-sql-server-instance-on-ubuntu-linux/

sql如何重命名实例

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值