Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, December 19, 2016

Update SQL Server on RHEL - CentOS

Sourced from the Microsoft support documents:

Notes:  


1) No restart/reboot after running the update command
2) Microsoft's posted command uses yum update, not yum upgrade.


    "In order to upgrade the mssql-server package, execute the following command:

   sudo yum update mssql-server

These commands will download the newest package and replace the binaries located under /opt/mssql/. The user generated databases and system databases will not be affected by this operation."


Source:

Monday, December 12, 2016

Linux - SQL Server Service: Status - Stop - Start - Restart Commands

A listing of commands to check the status of the SQL Server service, along with stopping, starting and restarting the service (RHEL):


Status Check

                 systemctl status mssql-server -l

Start Service


                 sudo systemctl start mssql-server

Re-start Service


                 sudo systemctl restart mssql-server

Stop Service

                 sudo systemctl stop mssql-server



Monday, November 28, 2016

SSMS & Linux - Use the Wizard to RESTORE Database

You can use SQL Server Management Studio (SSMS) to RESTORE a backup file to your Linux based SQL Server installation.  While the most control comes from T-SQL commands, we want to know just how far we can use the SSMS GUI and its related wizards.

Once connected, our Locate Backup File pop-up takes us to the C:\var\opt\mssql\data folder. Interestingly, on our Linux machine, the folder is simply addressed as:  /var/opt/mssql/data. No leading C:\, and the slashes are reversed.  The wizard pop-up looks like this:





For this preview release, the location wizard limits our access to various files and folders. It's not good form, but we'll move the file to the /data/ folder.


Copy / Move



Here we move our backup file to the folder where SSMS is expecting it to be on our Linux machine. For production, you really will not do this, but just so we can see our backup file display in our wizard, we'll place a copy of the backup file in the default data folder used by SSMS.

Using a terminal, use the copy command cp, to move the file:


But my Backup file is still not visible in the wizard!


Permissions.  If you drill down into the folders in Linux, we found that the files already present in the /data/ folder are owned by the user mssql.  Our recently copied backup file is NOT owned by mssql, and it not accessible to other users. So, our wizard cannot see the file. Options:

  1. Permissions.  Once we changed access permissions on our backup file, our wizard could access the backup file.
  2. Don't use the folder: /var/opt/mssql/data. This folder holds the live database files (.mdf, .ldf, etc) so it's best to create a new folder to hold your backup files. The location wizard will let you type in a different folder directory.




Change Permissions on Test.bak


If you need to change permissions on the file, you most likely will have to start the file viewer "Nautilus" as a root user.  In a terminal, 

  1. sudo su ( and enter root password)
  2. nautilus

This brings up the file viewer as root.  Navigate to /var/opt/mssql/data, and then adjust the file permissions:



Once done, you should be able to see your backup file in the Location wizard.







Tuesday, November 22, 2016

Permissions blocking SQL Server on Linux to open file

You're attempting to RESTORE a SQL Server database backup to your Linux installation and you get the message:

Msg 3201, Level 16, State 2, Line 17
Cannot open backup device 'C:\home\user\Downloads\AdventureWorks2012.bak'.
Operating system error 2(The system cannot find the file
specified.).
Msg 3013, Level 16, State 1, Line 17
RESTORE HEADERONLY is terminating abnormally.


Check Permissions


Chances are, file and folder permissons are blocking access to the file. 

In our example, we placed the backup file in our Download folder. Regardless of the folder used, you'll need to make sure SQL Server can access the file, and that includes access to the folder. In both our CentOS 7 (1511) and Ubuntu setups, we needed to open up access starting at the top folder - Home, open up access to the Downloads folder, and finally to the backup file itself.

  • Home folder           - Allow Others to Access files
  • Downloads folder  - Allow Others to Access files
  • backup file             - Allow Others to Access files
Once you have made these changes, SQL Server should be able to access the file successfully. Below is a sample where we changed permissions on the file. Folder permissions follow a similar approach.




Naturally, for production, you'll want to use a more sophisticated approach, and probably not use the Downloads folder of a user.  Something more along the lines of:

  $ sudo chown mssql /home/user/Downloads/AdventureWorks2012.bak

  $ sudo chgrp mssql /home/user/Downloads/AdventureWorks2012.bak



Also see how to RESTORE to SQL Server on Linux:  Restore a SQL Server database to Linux.


CentOS pre-built VirtualBox VM

We found a recent site with several pre-built CentOS virtual images. The site has both VirtualBox and VMware images, for not only CentOS, but also many other distro's.

You can find the CentOS images here:  https://www.osboxes.org/centos/

You can also find many at Virtualbox:  https://virtualboxes.org/images/centos/

CentOS 7 - install VirtualBox Guest Additions

With a fresh CentOS VM up and running in VirtualBox, our next step was to add in GuestAdditions. But, it failed.  Unlikc the install on Ubuntu, CentOS kicked back with this message:


       

The gcc utility was not found. If the following module compilation fails
then this could be the reason and you should try installing it.
The headers for the current running kernel were not found. If the following module compilation fails then this could be the reason. The missing package can be probably installed with yum install kernel-devel-3.10.0-327.el7.x86_64
Building the main Guest Additions module[FAILED] (Look at /var/log/vboxadd-install.log to find out what went wrong)Doing non-kernel setup of the Guest Additions[  OK  ]Press Return to close this window...^CSignal caught, cleaning upPress Return to close this window...

Fortunately, the answer has already been posted.
You can find it here:  How To Install VirtualBox 5 Additions on CentOS 7.

In summary, the steps were:
  1. $ sudo yum -y update
  2.    reboot
  3. $ sudo yum install epel-release
  4. $ sudo yum install dkms kernel-devel
  5.    install GuestAdditions from CD
    1. via auto-installer, or
    2. terminal
      1. $ cd /run/media/<yourid>/VBOXADDITIONS_x_x_x_xxxxx
      2. $ sudo ./VBoxLinuxAdditions.run
  6.   reboot


CentOS - settings to Connect automatically

Curiously, with a fresh install of CentOS (we're using v7 (1511) the network configuration does not automatically connect at startup.  We found two ways to change this. One, via the GNOME GUI interface, the other using a terminal.

Terminal


On the TechnologyTales.com website, we found a terminal setting adjustment. You can read about it here:  Automatically enabling your network connection at startup on CentOS 7.


Desktop Interface


While ideal for production, GUI's are great for one-off adjustments that don't require the user to know explicitly what command and its flags should be used. So for those users, here is an alternative.

Using the toolbar, top right, click on the down arrow, and then select the Wired section:


Next, select the Wired Settings section:


In the bottom right, click on the system/properties icon:


Finally, in the properties box, first, select the "Identity" menu item, and on this page, check the "connect automatically" box.









Monday, November 21, 2016

Restore a SQL Server database to Linux

For this posting, we have an on-premises virtual machine with SQL Server vNext on Ubuntu. SQL Server vNext is up and running, and we're using the SQL Server Management Studio for vNext to both backup our source database and then restore the database to Ubuntu.  Since all of the tasks were performed via T-SQL scripts, they could just as easily been run from SQurrill SQL, sqlcmd, or any other tool.
(  see Use SSMS to connect to Linux SQL Server v.Next
   and Use SQuirrel SQL to Connect to Linux SQL Server v.Next  )

Overview


Overall, the process was straight forward, especially since we were using SSMS. File and folder permissions was the one area that caused us the most problems.

First, back up the database


We used an older version of AdventureWorks for this task.  We explicitly used the NO_COMPRESSION option for this demo - to keep it simple.  

       
    BACKUP DATABASE [AdventureWorks2012] 
       TO  DISK = N'H:\Data\AdventureWorks2012.bak' 
      WITH NOFORMAT, NOINIT,  NAME = N'AdventureWorks2012-Full Database Backup'
        , SKIP, NOREWIND, NOUNLOAD, NO_COMPRESSION,  STATS = 10, CHECKSUM
    GO   
 

Next, change Permissions to Read-only


Copy/move the backup file to your Ubuntu virtual machine. To keep permissions simple, just copy the file to the Downloads folder on Ubuntu. Once the file has been moved, adjust the file permissions so that the file can be read.  For demo purposes, the quickest approach is to change the "Others" section and change Access to "Read-only".



File and folder permissions can fail the restore, so if you use another folder, just make sure all folder and file permissions allow access.

Test the file HEADER and FILELIST


To verify we could read the backup file, we ran both RESTORE HEADER and RESTORE FILELISTONLY.


       
      USE [master]
      RESTORE HEADERONLY
        FROM  DISK =  N'C:\home\user\Downloads\AdventureWorks2012.bak' 
 
      USE [master]
      RESTORE FILELISTONLY
       FROM  DISK = N'C:\home\user\Downloads\AdventureWorks2012.bak'

       
 

On one of our earlier failed restore attempts, it was clear there was a problem with the backup file. From further examination of the backup, it was clear the backup file had issues:





If you are not sure of the actual Ubuntu file location, use properties:



Swap backslash/forward slash


Notice the different slash orientation: 

Ubuntu:                 /home/user/Downloads/AdventureWorks2012.bak
SSMS:               C:\home\user\Downloads\AdventureWorks2012.bak



Restore Database to Linux


To control the process, we used the MOVE option, and reviewed all target folder permissions to ensure that our restore would be successful.

       
 USE [master]
 RESTORE DATABASE AdventureWorks2012 
  FROM  DISK = N'C:\home\user\Downloads\AdventureWorks2012.bak'
 
  WITH  FILE = 1
, MOVE N'AdventureWorks2012_Data' TO N'C:\media\user\Data\SQLServer\AdventureWorks2012_Data.mdf'   
, MOVE N'AdventureWorks2012_Log'  TO N'C:\media\user\Data\SQLServer\AdventureWorks2012_Log.ldf'   
, NOUNLOAD,  STATS = 5

GO
       
 






Use SQuirrel SQL to Connect to Linux SQL Server v.Next

Use your existing SQuirrel SQL setup to connect to SQL Server vNext for Linux. It's a standard connection using the jTDS Microsoft SQL Driver - just like any other SQL Server connection.

-- We also used this same driver to use Oracle's SQL Developer to connect to SQL Server vNext for Linux as well.

Here's the Alias configuration used to connect to SQL Server vNext on Linux:


Wednesday, November 16, 2016

SQL Server on Linux is now in public preview

Today, November 16, 2016,  Microsoft announced public preview availability of SQL Server on Linux. On the site, they have listed install instructions for the following distro's:


  • Red Hat Enterprise Linux 7.2   (we tested, it works with CentOS  [1])
  • Ubuntu Linux 16.04
  • SUSE Linux Enterprise Server v12 SP2 (listed as in-process )
Plus a bit of starter code. To get started, go to:



We've started to take a look.



You can also find a post on how to use SQL Server on Linux via Docker, along with VS and your Mac.  you can find it at SentryOne here:  VS Code on Mac meets SQL Server on Linux (in Docker)


[1]  CentOS release 7 (1511) is listed as based on RHEL 7.2.
      Reference: https://wiki.centos.org/Download.  No guarantees, but we tested it, and for us it works.


Saturday, March 12, 2016

SQL Server 2016 on Linux

SQL Server on Linux was announced Thursday, March 10, 2016 at the formal SQL Server 2016 event. It's expected to be released sometime in 2017, but based on the demo on Thursday, it is already running in at least an early Alpha state on Ubuntu.

Public preview is  now available.  See:  SQL Server on Linux is now in public preview!

Read our First Look over at Redmond Magazine:
       Open but Not Equal: Microsoft SQL Server 2016 vNext for Linux

How was it done?


Interested in how Microsoft got SQL Server up and running on Linux?  Centino Systems has an early post on how they think it was done. Check it out here: SQL Server on Linux – How I think they did it! - Centino Systems.

And, on the SQL Server blog, this:  SQL Server on Linux: How? Introduction
TechCrunch has an article posted July 17, 2017 - How Microsoft brought SQL Server to Linux
 - has come additional links

For many of us who have worked with SQL Server, The original SQL Server code base sourced from Sybase for UNIX. And in the early Microsoft SQL Server days (v. 6.5 and earlier) it ran on not just Intel, but other CPU based systems, such as PowerPC and Digital's Alpha chip.

You can sign up for the preview at https://www.microsoft.com/en-us/server-cloud/sql-server-on-linux.aspx.

We've started to take a look.



You can also find a post on how to use SQL Server on Linux via Docker, along with VS and your Mac.  you can find it at SentryOne here:  VS Code on Mac meets SQL Server on Linux (in Docker)