linux下安裝 sqlserver

來源:互聯網
上載者:User

標籤:nes   server   ase   database   key   sql   into   定序   firewall   

我使用的是Centos7在虛擬機器中完成測試

1、下載設定mssql的yum源,執行以下代碼,現在sqlserver的linux版本130多兆,網速慢的請等待

curl https://packages.microsoft.com/config/rhel/7/mssql-server.repo > /etc/yum.repos.d/mssql-server.reposudo yum install -y mssql-server

2、運行首次設定命令,設定密碼,如果你的記憶體小於3G,這一步將無法通過,如果你用虛擬機器搭建,請注意

/opt/mssql/bin/sqlservr-setup

3、關閉防火牆,或者允許防火的1433連接埠

systemctl stop firewalld

此時SQLSERVER已經安裝完成,如果以上代碼執行全部沒有出現錯誤,那麼可以在windows下,用sql server managerment studio來串連測試

4、由於linux和windows系統的盤符路徑格式不一樣,如果使用sql server圖形化管理工具來建立資料庫的話,我這裡資料庫預設建立到了/var/opt/mssql/data/目錄下,我想把資料庫建立到/var/mymssql下,但是預設情況下sqlserver服務沒有操作這個檔案夾的許可權,需要修改這個檔案夾的許可權

mkdir /var/mymssqlchown mssql:mssql /var/mymssql

5、然後建立資料庫,注意這裡的路徑格式,平時表達linux檔案/var/testdb.mdf這樣,這裡建立要用C:\開頭並且/左斜杠要改為\右斜杠

create database testdb on  primary(    name=‘testdb‘,     filename= N‘C:\var\testdb.mdf‘,     size=5mb,     maxsize=100mb,    filegrowth=15%)log on(    name=‘testdb_log‘,    filename=N‘c:\var\stuDB_log.ldf‘,    size=2mb,    filegrowth=1mb)

6、修改資料庫預設定序,否則資料庫中文會亂碼,執行這一步驟時,資料庫要是剛建立的,否則無法執行通過

ALTER DATABASE testdb COLLATE Chinese_PRC_CI_AS 

7、建表和測試

 

create table classtable(id int primary key identity(1,1) not null,classname nvarchar(max))goinsert into classtable values(‘班級1‘)insert into classtable values(‘班級2‘)gocreate table usertable(id int primary key identity(1,1) not null ,name nvarchar(max) not null,sex bit ,classid int foreign key references classtable(id))goinsert into usertable values(‘學生1‘ , 1 , 1)insert into usertable values(‘學生2‘ , 1 , 2)select * from classtableselect * from usertable

結束!

linux下安裝 sqlserver

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.