WSL allows Windows users to develop and run applications within a GNU/Linux environment. Previous to this feature release we needed VM’s or a dual boot setup.
For more information, as always have a look at the Microsoft Docs. There’s a huge amount of tutorials and documentation on this area.
You’ll then be prompted to restart your local computer.
Downloading a Linux Distro
You can find all the Linux Distributions on the Microsoft Store and download from there. This may be restricted by Group Policy if you’re on a Domain, so you can download manually from this list on the documentation page.
As of the 2017 Edition of SQL Server we have been able to install SQL Server on Linux. Linux will likely be more of an unfamiliar environment for traditional Microsoft SQL DBAs. This guide should hopefully help you when you need to check the status of SQL Services and Stop/Start services on a Linux host.
The examples provided in this post utilise the systemctl command. Many Linux distributions use systemctl as a tool for managing services including CentOS, Ubuntu, Debian & RedHat.
Note that the systemctl command is not available in some Linux distributions, including if you are running Linux on WSL (Windows Subsystem for Linux). This is because Ubuntu WSL does not use the systemd init system, which is what systemctl is designed to manage.
To show all enabled services on a Linux system, use the following command:
systemctl list-unit-files | grep enabled
If your service is not on the list of enabled services, it will not start automatically on the next system reboot. To enable the SQL Server service with systemctl, use the following command : sudo systemctl enable mssql-server
Check Status of SQL Server Service on Linux
The systemctl status mssql-server command is used to check the current status of the SQL Server service on your system. This command will display information about the service, including whether its currently active or not.
sudo systemctl status mssql-server
If the SQL Service is active, the output of the command will include the text “active (running)” in green. This indicates that the service is currently running and is available to process requests.
If the service is not active, the output will include the text “inactive (dead)” in red. This indicates that the service is not currently running, and may need to be started or restarted in order to be used.
To stop, start, or restart the SQL Server service on Linux, you can use the systemctl command.
sudo systemctl stop mssql-server
To start the service again, use the following command:
sudo systemctl start mssql-server
To restart the service, use the following command:
sudo systemctl restart mssql-server
After running any of these commands, it is always a good idea to check the status of the service to make sure that the desired action was completed successfully. You can do this using the systemctl status mssql-server command as shown in the screenshot.
This post contains installation notes for installing Firewalld on an Amazon Linux 2 EC2 instance.
Firewalld is a Linux firewall tool that makes it easy to create custom firewall rules. It acts as a frontend for iptables, the packet filtering system, and lets you apply rules dynamically. This makes it a great tool for keeping your Linux system’s network secure. You can use the firewall-cmd command-line tool to manage your firewall rules and configurations. Check out the Firewalld documentation for more info.
Install Firewalld on Linux
To install Firewalld on an Amazon Linux 2 EC2 instance, you might need to first ensure that the epel-release package is installed on your system. This package provides access to the Extra Packages for Enterprise Linux (EPEL) repository, which contains the Firewalld package. You can install the epel-release package using the following command:
sudo yum install epel-release
To get started with the Firewalld install, log in to your EC2 instance and run the following commands:
sudo yum install firewalld
The command sudo systemctl start firewalld is used to start the Firewalld service on a Linux system. Once the above install is complete start the Firewalld service:
Firewalld should now be up and running on your Amazon Linux 2 EC2 instance. You can then use the firewall-cmd command-line tool to manage your firewall rules and configurations. For example, you can use the --list-all option to view all of the currently active firewall rules:
firewall-cmd --list-all
This will show you all of the rules that are currently in effect, along with information about which zones they apply to and the sources and destinations they apply to. This can be useful for troubleshooting and verifying that your firewall is configured as you expect.
This blog post is a guide on how to create databases and tables in MySQL, from a Windows and Linux computer. The information included here should help beginners who are new to MySQL.
To create a new database in MySQL, and many other relational database systems we use the CREATE DATABASE SQL Statement.
The meaning behind the word ‘database’ can vary, and often be referred to the same thing as a Schema. In MySQL, Databases and Schemas are both one of the same things.
We can create a MySQL Database by running CREATE DATABASE databaseName
The create database example below is being done using the GUI option, MySQL WorkBench. For more information on SQL syntax and parameters of the CREATE DATABASE statement in MySQL, we can refer to the MySQL Dev Docs.
After running the above, refresh Schemas within the Navigator to the left and open the new database.
If you’re instance running on Linux, database names are case-sensitive, whereas on Windows this isn’t an issue. Below, I’m creating a database on a local MySQL install (Windows 10) and then creating a MySQL table within it using a Capital letter on the schema/database name.
The above is us logging in with the ec2-user to an Amazon Linux EC2 instance. Then we create a new table using a Capital letter on the database schema name.
A common best practice is to stick to the one case for object naming in SQL for this reason. For example, use finance_database instead of Finance_Database, or use FINANCE_DATABASE.
The USE DATABASE command in SQL is used to set your statements to use the specified database as your default (current) database.
To show an example of USE in SQL, I create a new database and table MySQL Workbench below. The CREATE TABLE and INSERT INTO statements include the schema name (butter), and then I attempt to run a SELECT statement on the table without including the schema name.
The returns an error – Error Code: 1046. No database selected. Select the default DB to be used by double-clicking its name in the SCHEMAS list in the sidebar.
As described in this error message, we can set our default schema in the MySQL Workbench Navigator.
That’s one solution. The other is to use the USE DATABASE statement. I’m adding USE butter; to the TSQL in the MySQL Workbench query window.
All queries executed after running the USE command will assume the database specified when running queries without a schema name.
Semicolons are a way to determine when your SQL statement ends in MySQL.
A query does not run by hitting return in a MySQL terminal, it requires a semicolon to know when the SQL statement is complete.
The screenshot below shows a Linux client connected to MySQL. The first command includes a semicolon and returns a list of databases. The second command (DROP DATABASE) displays the example of a command not being executed.
The command does not run until we add a semicolon and hit return, as marked with a red cross on the screenshot.
To further help understand semicolons in MySQL I also will show an example in MySQL Workbench. I’m creating a new table and inserting a row of data into the table on the next row.
The CREATE TABLE statement returns an error message – Error Code: 1064: You have an error in your SQL syntax; check the manual that the corresponds to your MySQL...
The table did not get created here. If I add the semicolon at the end of the CREATE TABLE line the table will get created and a row will be inserted.
If you’re running queries line-by-line then the semicolon isn’t as much required. For more information, see this MySQL documentation link.