cmd设置mysql表只读,SQL Server AlwaysOn 可用性组副本只读设置

SQL Server AlwaysOn 可用性组副本是允许只读的,默认情况下不可读。

其中副本的可读性有几个选项:

NO : 不可连接到副本数据库,因此也不可读。默认设置。

Read-intent only:只有限定 “read-only” 时才能访问数据库,但只读。

Yes:所有连接都有可访问数据库,但只读。

7f87bb3557c622c5186d3d539d9bff69.png

如果设置为 “Read-intent only” ,客户端查询该数据库对象时提示以下错误:

Msg 976, Level 14, State 1, Line 1

The target database, 'TestDB',

is participating in an availability group and is currently not accessible for queries.

Either data movement is suspended or the availability replica is not enabled for read access.

To allow read-only access to this and other databases in the availability group,

enable read access to one or more secondary availability replicas in the group.

For more information, see the ALTER AVAILABILITY GROUP statement in SQL Server Books Online.

若设置为“Read-intent only”,又打算可读副本数据库数据,客户端连接设置如下:

连接时加上 ReadOnly 参数: ApplicationIntent=ReadOnly

f83a270a5f584a0f1385171917a2e495.png

其他程序连接设置如:ApplicationIntent=readonly

("Driver={SQL Server Native Client 11.0};server=AGListener;Database=dbname;trusted_connection=yes;ApplicationIntent=readonly”)

aa71bfca94f157c7f6847a8fc3d56338.png

("Driver={SQL Server Native Client 11.0};server=AGListener;Database=dbname;trusted_connection=yes;ApplicationIntent=readonly”)

使用 sqlcmd 工具连接需要设置参数 “-K”

sqlcmd -SAGListener -E -dDBName -Kreadonly

sqlcmd -SAGListener -E -dDBName -Kreadonly

若都允许只读,选择 “Yes” 即可更改,或使用命令更改:

USE [master]

GO

ALTER AVAILABILITY GROUP [AGName]

MODIFY REPLICA ON N'InstanceName' WITH (SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL))

GO

f61ffbf2af32a7cebe13890b5f3b69f0.png

USE [master]

GO

ALTER AVAILABILITY GROUP [AGName]

MODIFY REPLICA ON N'InstanceName' WITH (SECONDARY_ROLE(ALLOW_CONNECTIONS = ALL))

GO

参考:

0b1331709591d260c1c78e86d0c51c18.png

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值