发布网友 发布时间:2022-04-23 01:51
共3个回答
懂视网 时间:2022-05-02 10:14
如果使用SSMS客户端的UI界面去修改的话, 那么多服务器一台一台去修改,不仅费时费力,而且枯燥无聊。只能使用脚本,一旦写好一个脚本,而后使用Multiple Server Query Execution(极力推荐使用这个管理、维护数据库),执行一次脚本,全部搞定。剩下的时间你可以喝喝茶、学习下新知识!
DECLARE @EmailAccount sysname;
DECLARE @SmtpServer sysname;
DECLARE @EmailAddress NVARCHAR(120);
DECLARE @EmailSuffix NVARCHAR(32);
DECLARE @NewEamilAddress NVARCHAR(120);
--DECLARE @ActualEmailSuffix NVARCHAR(32)=‘xxxx.com‘; SQL Server 2005不支持此功能,会报Cannot assign a default value to a local variable.
DECLARE @ActualEmailSuffix NVARCHAR(32);
DECLARE @ActualSmtpServer sysname;
SET @ActualEmailSuffix=‘xxx.com‘;
SET @ActualSmtpServer=‘192.168.xxx.xxx‘;
DECLARE EmailAccount_Cursor CURSOR FAST_FORWARD
FOR
SELECT sa.[name]
,ss.[servername]
,sa.email_address
FROM [msdb].[dbo].[sysmail_server] ss
INNER JOIN [msdb].[dbo].[sysmail_account] sa
ON ss.[account_id]=sa.[account_id];
OPEN EmailAccount_Cursor;
FETCH NEXT FROM EmailAccount_Cursor INTO @EmailAccount, @SmtpServer,@EmailAddress;
WHILE @@FETCH_STATUS = 0
BEGIN
IF LTRIM(RTRIM(@SmtpServer))!=@ActualSmtpServer
BEGIN
EXECUTE msdb.dbo.sysmail_update_account_sp
@account_name = @EmailAccount
,@mailserver_name=@ActualSmtpServer;
PRINT @SmtpServer;
PRINT @EmailAccount;
END;
SET @EmailSuffix=SUBSTRING(@EmailAddress,CHARINDEX(‘@‘,@EmailAddress)+1, LEN(@EmailAddress) -CHARINDEX(‘@‘,@EmailAddress))
IF @EmailSuffix!=@ActualEmailSuffix
BEGIN
SET @NewEamilAddress= REPLACE(@EmailAddress,@EmailSuffix,@ActualEmailSuffix);
EXECUTE msdb.dbo.sysmail_update_account_sp
@account_name = @EmailAccount
,@email_address=@NewEamilAddress
,@mailserver_name=@SmtpServer;
PRINT @EmailAccount;
PRINT @NewEamilAddress;
END;
FETCH NEXT FROM EmailAccount_Cursor INTO @EmailAccount, @SmtpServer,@EmailAddress;
END
CLOSE EmailAccount_Cursor;
DEALLOCATE EmailAccount_Cursor;
批量修改所有服务器的dbmail配置
标签:max direct fetch ack als from 学习 out cannot
热心网友 时间:2022-05-02 07:22
如果不会用salt或者ansible的话,最简单的方法是找一台发布机器,将这台机器的公钥放在其他服务器中,然后就可以执行脚本了热心网友 时间:2022-05-02 08:40
使用自动化运维工具salt,怎么使用就自己去折磨一下吧。