当前位置:网站首页>Based on authorized access, cross host, and permission allocation under sqlserver

Based on authorized access, cross host, and permission allocation under sqlserver

2022-07-06 14:21:00 Code siege lion

1. Open the remote access rights of the installed database ;
To the server to be accessed , The login mode set in security is sql server and windows Authentication mode login
 Insert picture description here

Sign in sa After account , In the status bar , Allow connections to the database engine
 Insert picture description here

2. Create a user , Grant them access to the database ;
– Create a login account
create login xuniji with password=‘123456’
 Insert picture description here

When the host acts as a client , use sa Account login to access the server of the virtual machine

It uses the host's (192.168.1.2) Of DBMS, Account sa, The address to visit is 192.168.1.3

use xuniji When logging in to this account , It is forbidden to log in and access the database without authorization
 Insert picture description here

After authorization :
use Company This sentence is indispensable , If it is to let the login user access a specific database
– Create database users
create user xuniji for login xuniji with default_schema=dbo

Access all databases : Access all databases without adding use company
EXEC sp_grantdbaccess ‘xuniji’
GO
 Insert picture description here

You can visit

3. The query and insert permissions of one or more specific tables form a role , And grant it to the user ;
grant select,insert on Department to xuniji
grant select,insert on Employees to xuniji
 Insert picture description here

This statement gives the permission to query and insert to xuniji The name of this character , It can also be called login , Because I created one before xuniji The role name of and the login name of a virtual machine , Mapping relationship has been established , So there is no need to map here
 Insert picture description here
 Insert picture description here

After authorization, both insert and query can be executed successfully , The authorization here is to use the host sa Account authorization , And I insert and query with xuniji This account .

4. Choose a partner in the class or group , Let it access remotely through the set user , And complete and insert
operation ;
I used it 3 Middle method implementation :
One 、 The first is to establish a simulated environment through virtual machines (windows7x64 position ,sqlserver2012).
Two 、 The second is to connect the computer directly with two network cables
3、 ... and 、 The third way is to connect through the LAN under the router
1、 The two machines to establish remote access must be in the same network segment .
Hosts and virtual machines ( Machines that need access ) Both must be in the same network segment
The gateway I set is 192.168.1.1
host IP The address is 192.168.1.2
virtual machine IP The address is 192.168.1.3
among 192.168.1.0 Cannot set , Because this is the broadcast address
The subnet mask is set to 255.255.255.0( Subnet mask is used to allocate address space )
My address space allocation space is 2~254 All the machines in the segment can access each other .
virtual machine :IP Address
 Insert picture description here
 Insert picture description here

W1064 Bit host IP Address :
 Insert picture description here

( After the environment is established, pass the command ping Conduct ping through )
 Insert picture description here

2、 commonly windows7 In the environment , There is no need to change the port. The default is 1433 port , But my host (windows10,sqlserver12) Port is not 1433 Need to use sqlserver Configure in the configuration manager

 Insert picture description here

 Insert picture description here
 Insert picture description here
 Insert picture description here

Windows10 Generally, the default port is empty , Can be in IPall Set in the for 1433.

3、 Login with user name and password sa Login is usually the user with the highest permission , Generally, the login name is set in the target machine that needs to be accessed ( This login name is usually not sa):
 Insert picture description here

virtual machine (192.168.1.3) Go to the database Company323 There is no table

5. Withdraw the insert permission of the table .
 Insert picture description here

When I finish deleting authorization , You cannot insert any more :
 Insert picture description here

原网站

版权声明
本文为[Code siege lion]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131404131390.html