Thursday, June 16, 2022

Introducing the MySQL SELECT statement

The series so far:

  1. Getting started with MySQL
  2. Working with MySQL tables
  3. Working with MySQL views
  4. Working with MySQL stored procedures
  5. Working with MySQL stored functions

Up to this point in the series, I’ve focused primarily on creating schema objects in a MySQL database. The SQL statements used to create these objects are typically categorized as data definition language (DDL). They include statements such as CREATE TABLE, CREATE VIEW, and CREATE PROCEDURE.

Beginning with this article, I’m switching my attention to data manipulation language (DML), which includes statements used to query and modify data. Four of the most common DML statements are SELECT, INSERT, UPDATE, and DELETE. You can use the SELECT statement to retrieve data, the INSERT statement to add data, the UPDATE statement to modify data, and the DELETE statement to remove data.

In this article, I focus on the SELECT statement, which is used extensively when working with relational databases. You can use the SELECT statement to return data from one or more MySQL tables, as well as to retrieve information about the server and database environment. The SELECT statement is one of the most commonly used SQL statements in MySQL. It is also one of the most complex.

You got a taste of the SELECT statement in earlier articles in this series, but it was included only to support the DDL examples in those articles. This article focuses exclusively on the SELECT statement and the basic elements that go into building one. I’ll be covering other DML statements later in this series.

Preparing your MySQL environment

For the examples in this article, I used the same database (travel) that you saw in the previous articles and the same two tables (manufacturers and airplanes). However, I added a lot more data this time around. If you want to try out the examples for yourself, you can download the MySQL_06_setup file and run it against your MySQL instance. The SQL in the file creates the database, adds the two tables, and inserts data in both tables.

For your convenience, I’ve included the two table definitions here so you can reference them when trying out the SELECT statements in the examples later in the article:

CREATE TABLE manufacturers (
  manufacturer_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  manufacturer VARCHAR(50) NOT NULL,
  create_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  last_update TIMESTAMP NOT NULL 
    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (manufacturer_id) ) 
ENGINE=InnoDB AUTO_INCREMENT=1001;
CREATE TABLE airplanes (
  plane_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  plane VARCHAR(50) NOT NULL,
  manufacturer_id INT UNSIGNED NOT NULL,
  engine_type VARCHAR(50) NOT NULL,
  engine_count TINYINT NOT NULL,
  max_weight MEDIUMINT UNSIGNED NOT NULL,
  wingspan DECIMAL(5,2) NOT NULL,
  plane_length DECIMAL(5,2) NOT NULL,
  parking_area INT GENERATED ALWAYS AS ((wingspan * plane_length)) STORED,
  icao_code CHAR(4) NOT NULL,
  create_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  last_update TIMESTAMP NOT NULL 
    DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (plane_id),
  CONSTRAINT fk_manufacturer_id FOREIGN KEY (manufacturer_id) 
    REFERENCES manufacturers (manufacturer_id) ) 
ENGINE=InnoDB AUTO_INCREMENT=101;

If you already have the database and tables on your MySQL instance and don’t want to re-create them, you can run just the INSERT statements in the MySQL_06_setup.sql script. However, you should first delete any data in the table because the data being added to the airplanes table references specific values in the manufacturers table. Starting with empty tables will also ensure that you’re seeing the same results as in my examples. When you run the INSERT statements, be sure to execute them in the order specified in the file.

The SELECT statement syntax

A MySQL SELECT statement is typically used to retrieve data from a single table or from multiple tables. The statement is made up of one or more clauses that together provide the logic needed to retrieve the necessary data. The statement’s syntax is fairly elaborate, but to help you get started, I’ve narrowed it down to the most fundamental elements:

SELECT [ALL | DISTINCT] select_list 
[FROM table_ref] 
[WHERE where_condition] 
[GROUP BY group_list] 
[HAVING having_condition]
[ORDER BY order_list]

The five clauses shown in the syntax are highly versatile and can be used to build a wide range of statements:

  • The SELECT clause is the only required clause in a SELECT statement. The clause typically specifies the columns from which to retrieve data from the target table or tables, but it can also be used to return the results of an expression, such as a system function or calculation.
  • The FROM clause specifies the target table or tables from which to retrieve data. If you specify multiple tables, you are performing a join.
  • The WHERE clause acts as a filter that limits the rows returned by the query. The clause defines one or more search conditions that must evaluate to true for a row to be returned. Multiple search conditions are linked together with logical operators that determine how to apply those conditions.
  • The GROUP BY clause groups the data based on one or more specified expressions, which are typically columns in the target tables.
  • The HAVING clause is similar to the WHERE clause because it defines one or more search conditions that limit the results. However, the HAVING clause is specific to grouped data and is processed after the GROUP by clause.
  • The ORDER BY clause sorts the data based on one or more specified expressions, which are typically the columns in the target tables.

There are a number of other clauses and options that I have not included here, and they are also important to understand, but for now, these five clauses provide a good starting point for learning how to use a SELECT statement to query a database.

The SELECT clause

At a minimum, the SELECT clause requires the SELECT keyword and the select list, which is made up of one or more expressions. An expression can be a column name, calculation, function, subquery, literal value, or other construction. The select list commonly includes columns from the tables referenced in the FROM clause (if one is included).

Unlike the other clauses in the SELECT statement, the SELECT clause can stand on its own to create a very simple statement. For example, the following SELECT statement includes only the SELECT clause, and the select list within that clause includes only one expression:

SELECT CURRENT_TIMESTAMP;

The expression, in this case, is the CURRENT_TIMESTAMP function, which returns the current date and time. If you run this statement, MySQL returns a single value that contains both the date and time in a format that depends on your location and server settings. For example, when I ran the statement, I received the following results:

2022-06-03 15:03:13

As you can see, a SELECT statement can be fairly basic, as long as it includes the SELECT clause and a select list with at least one expression.

The FROM clause

The FROM clause references the table or tables that contain the source data. Although it is an optional clause, most SELECT statements include the FROM clause. If you are targeting only one table, you need only specify the FROM keyword, followed by the table name. For example, the following SELECT statement retrieves data only from the airplanes table:

SELECT * FROM airplanes;

Notice that the SELECT clause specifies only an asterisk for the select list. In MySQL, like many relational database systems, you can use an asterisk to indicate that all columns should be returned from the table or tables referenced in the FROM clause, which in this case, points only to the airplanes table. Figure 1 shows part of the results returned by this statement. In all, the query should return 241 rows.

Table Description automatically generated Figure 1. Retrieving all rows and columns from the airplanes table

The SELECT statement in the preceding example demonstrates the basic construction needed to return all rows and columns from a table. However, you can narrow down your SELECT clause by specifying the exact columns to return. For example, the following SELECT statement returns the plane, engine_type, and engine_count columns from the airplanes table:

SELECT plane, engine_type, engine_count
FROM airplanes;

Notice that the expressions (column names) in the select list are separated with commas, but there is no comma after the SELECT clause itself. The SELECT statement still returns 241 rows from the airplanes table; however, the results now include only these three columns, as shown in Figure 2.

An image showing the query results. Columns plane, engine_type, engine_count

Figure 2. Retrieving specific columns from the airplanes table

You can refine your select list even further when retrieving data from the target table. For example, the select list in the following SELECT statement uses the ROUND system function to round the wingspan value to the nearest integer:

SELECT plane, ROUND(wingspan) AS wingspan_rnd
FROM airplanes;

The wingspan column is passed in as an argument to the ROUND function, which is followed by the AS keyword and then by the wingspan_rnd alias. The alias is assigned to the output column generated by the ROUND function, as shown in Figure 3. When assigning a column alias, you can omit the AS keyword, but it can be useful to retain for clarity.

An image showing the query results. Columns plane and wingspan_rnd

Figure 3. Using a system function in a select expression

The SELECT statement still returns 241 rows from the airplanes table, but now it includes only the plane and wingspan_rnd columns. As you can see from the examples in the section, the SELECT clause works hand-in-hand with the FROM clause in determining what column data to return. However, the FROM clause itself remained unchanged in all these examples. When a FROM clause is included in a SELECT statement, it serves as the foundation on which the rest of the SELECT statement is built.

The WHERE clause

In the previous section, you saw how the SELECT clause can be used to limit the columns returned from the table specified in the FROM clause. The WHERE clause is similar in this respect, except that it is used to limit the rows returned from the target table.

When defining the WHERE clause, you need to specify at least one search condition, which must evaluate to true for a row to be returned. For example, the following SELECT statement includes a WHERE clause that limits the returned rows to those with an engine_type value that equals turboprop:

SELECT plane, ROUND(wingspan) AS wingspan_rnd
FROM airplanes
WHERE engine_type = 'turboprop';

The WHERE clause search condition (engine_type = 'turboprop') states that the engine_type value must equal turboprop for a row to be returned. The expression uses the equal (=) comparison operator to compare the engine_type value to the turboprop string. If they are equal, the search condition evaluates to true, and the row is returned.

Figure 4 shows part of the results that the statement returns. The result set now includes only 26 rows because only those rows satisfy the search condition.

An image showing the query results with columns plane and wingspan_rnd

Figure 4. Using a WHERE clause to filter data

When you add a WHERE clause to your SELECT statement, you can define multiple search conditions. For example, the following SELECT statement again includes a WHERE clause, but this time it specifies that the engine_type value must equal turboprop and that the max_weight value must be greater than 10000:

SELECT plane, ROUND(wingspan) AS wingspan_rnd
FROM airplanes
WHERE engine_type = 'turboprop' AND max_weight > 10000;

The second search condition uses the greater than (>) operator rather than equal, but the basic concept is the same in terms of filtering data. However, notice that the two search conditions are connected by the AND logical operator. This means that both search conditions must evaluate to true for a row to be returned. Figure 5 shows the results after running the SELECT statement, which now returns only 15 rows.

An image showing the query results with columns plane and wingspan_rnd

Figure 5. Defining multiple search conditions in a WHERE clause

MySQL supports several types of logical operators. Although the AND operator is commonly used, you might want to define different logic. For example, you can use an OR operator to indicate that either of the two search conditions must evaluate to true, but not necessarily both. You can also string together more than two search conditions, but you need to be sure to implement the logic correctly, or you risk incorrect results. For more information about using logical operators, check out the MySQL documentation.

The ORDER BY clause

The ORDER BY clause lets you sort the results returned by your SELECT statement. You can specify one or more expressions, which are typically columns. You can also define the sort order as either ASC (ascending) or DESC (descending). For example, the following SELECT statement is the same as the preceding one except that it now includes an ORDER BY clause that sorts the results by the wingspan_rnd column, in descending order:

SELECT plane, ROUND(wingspan) AS wingspan_rnd
FROM airplanes
WHERE engine_type = 'turboprop' AND max_weight > 10000
ORDER BY wingspan_rnd DESC;

Figure 6 shows the results returned by this statement. As you can see, you can use a column alias defined in the select list within your ORDER BY clause.

An image showing the query results with columns plane and wingspan_rnd

Figure 6. Sorting the results by the wingspan_rnd column

When using an ORDER BY clause, you might discover that some values are duplicated. For example, the above results show that several planes have a wingspan of 55 feet and several others are 50 feet. In some cases, you might want to return a single column so you can view its range of values, such as in the following example:

SELECT ROUND(wingspan) AS wingspan_rnd
FROM airplanes
WHERE engine_type = 'turboprop' AND max_weight > 10000
ORDER BY wingspan_rnd DESC;

Now the SELECT statement returns only the wingspan_rnd column, as shown in Figure 7.

An image showing the query results with column wingspan_rnd

Figure 7. Returning a single column

If all you’re after is a range of values and don’t want the duplicate values, you can add the DISTINCT keyword to your SELECT clause. You might do this, for example, to populate an application’s drop-down list. The following SELECT statement uses DISTINCT to remove the duplicates in the wingspan_rnd column:

SELECT DISTINCT ROUND(wingspan) AS wingspan_rnd
FROM airplanes
WHERE engine_type = 'turboprop' AND max_weight > 10000
ORDER BY wingspan_rnd DESC;

Figure 8 shows the results of running the SELECT statement with DISTINCT included. Now the statement returns only eight rows, and each row is unique.

An image showing the query results with column wingspan_rnd

Figure 8. Removing duplicate rows

The SELECT clause supports both the DISTINCT and ALL options. As you have seen, the DISTINCT option species that all duplicate rows should be removed from the result set. The ALL option specifies that all rows should be returned. This is the default, so you do not need to include it.

Joining tables in the FROM clause

When retrieving data from a MySQL database, you might want to pull the data from multiple tables, in which case you can create a join that effectively merges the results from both tables together. MySQL, like other relational database systems, supports multiple ways to join tables, although they don’t necessarily approach joins in the same way.

When you’re first getting started with MySQL joins, it’s important to know that most joins fall into one of two basic categories:

  • Inner joins. Matches one or more columns in two tables and returns all rows with matching values.
  • Outer joins. Matches one or more columns in two tables and returns all rows with matching values, but also returns the non-matching rows from either the left table (left outer join) or the right table (right outer join).

The best way to understand how a join works is to see one in action. In the following example, I join the airplanes and manufacturers tables based on the manufacturer_id column in both tables:

SELECT m.manufacturer, a.plane, a.engine_type, 
  a.engine_count, a.parking_area
FROM airplanes a INNER JOIN manufacturers m
  ON a.manufacturer_id = m.manufacturer_id
WHERE a.parking_area > 1000 AND max_weight > 10000
ORDER BY a.parking_area DESC, m.manufacturer, a.plane;

This statement creates an inner join, as indicated by the INNER JOIN keywords in the FROM clause (in between the two table names). The FROM clause also includes the ON subclause, which specifies that the manufacturer_id value in the manufacturers table must equal the manufacturer_id value in the airplanes table.

Because this is an inner join, MySQL will find all the rows with matching manufacturer_id values. You must make sure that your column references in any of the SELECT statement clauses are not ambiguous in any way, which can occur if the two tables contain columns with the same name, as in manufacturer_id. This includes the FROM clause itself.

The easiest way to address any ambiguity is to assign aliases to the table names and then use those aliases when referencing the columns in the rest of the statement. For example, the FROM clause assigns the alias a to airplanes, so all column references are preceded by an a, followed by a period, and then followed by the column name.

Figure 9 shows part of the results returned by the SELECT statement, which includes 152 rows in all.

An image showing the query results with columns manufacturer, plane, engine_type, engine_count, parking_area

Figure 9. Creating an inner join between two tables

There is much more to joins than what I’ve shown you here, but this should at least give you a sense of how they work until we can spend more time on them. In the meantime, you might want to check out the MySQL documentation on joins. The information can be a little difficult to weed through, but it might help you better understand how they work.

The GROUP BY clause

Another important clause in the SELECT statement is GROUP BY, which makes it possible to group and aggregate data in the target tables. The clause requires at least one expression in addition to the GROUP BY keywords. The expression is usually one of the columns in the target tables. For example, the following SELECT statement includes a GROUP BY clause that groups the data based on the manufacturer_id column in the manufacturers table:

SELECT m.manufacturer, COUNT(*) AS plane_cnt
FROM airplanes a INNER JOIN manufacturers m
  ON a.manufacturer_id = m.manufacturer_id
WHERE max_weight < 1000000
GROUP BY m.manufacturer_id
ORDER BY plane_cnt DESC;

When using a GROUP BY clause, you typically limit the columns in the select list to those included in the GROUP BY clause or to those derived from aggregate expressions. This example does both.

The select list includes the manufacturer_id column, which is also referenced in the GROUP BY clause. The select list also includes the COUNT(*) aggregate function, which returns the total number of rows in each group. The COUNT function is a special type of function that takes an asterisk as its argument. The function provides a simple way to return the total number of rows (number of airplanes) for each manufacturer group. Figure 10 shows the statement’s results.

An image showing query results with columns manufacturer and plane_cnt

Figure 10. Grouping data

As you can see, the results show the total number of planes associated with each manufacturer. You can also group the data based on more than one column. For example, the GROUP BY clause in the following SELECT statement groups the data first by manufacturer_id and then by engine_type:

SELECT m.manufacturer, a.engine_type, COUNT(*) AS plane_cnt
FROM airplanes a INNER JOIN manufacturers m
  ON a.manufacturer_id = m.manufacturer_id
WHERE max_weight < 1000000
GROUP BY m.manufacturer_id, a.engine_type
ORDER BY m.manufacturer ASC, a.engine_type ASC;

The select list has also been updated to include the engine_type column, which is now in the GROUP BY clause. Figure 11 shows the results returned by the SELECT statement.

An image showing query results with columns manufacturer, engine_type, plane_cnt

Figure 11. Grouping data by multiple columns

The results now show the total number of airplanes for each engine type from each manufacturer. However, this time the results are sorted first by the manufacturer values and then by the engine_type values.

Working with the SELECT statement

The five clauses I’ve covered here—SELECT, FROM, WHERE, ORDER BY, and GROUP BY—can provide you with a good foundation for getting started with SELECT statements. With these five clauses, you can build very precise queries that retrieve exactly the data you need from your MySQL databases.

That said, this article only skims the surface of the SELECT statement. There is much more to each clause, and there are additional clauses. In fact, a full discussion of the SELECT statement could easily fill an entire volume—if not more. But this information should at least provide you with a launching off point. Just know that there is much more to the MySQL SELECT statement than can be described in a single article.

The post Introducing the MySQL SELECT statement appeared first on Simple Talk.



from Simple Talk https://ift.tt/vM7DZNY
via

Friday, June 3, 2022

The ultimate guide to web accessibility

An images showing a desktop with a laptop sitting on it. Above it says Web Accessibility

You brought cake for your family party but forgot to bring a vegan cake for Aunt Kara. You tell her, “Sorry, but I guess you can’t have any cake today.” Aunt Kara is upset, and she would think twice before coming to any future family gatherings hosted by you. This is how people with disabilities feel when they visit inaccessible websites. They are invited to a party where they cannot enjoy cake.  Making your website accessible for people with disabilities allows for an inclusive experience, allowing them to have their cake and eat it, too. This article will visit basic topics concerning web accessibility and guide you towards charting an inclusive path for your organization.

What does web accessibility mean?

Web accessibility, which is also known as digital accessibility, is a practice that involves removing or preventing any barriers that users may face while accessing or interacting with a web application.

Why should you care about web accessibility?

A girl staring at a blackboard above which contains the word: Why?

Did you know that it’s estimated that over 1 billion people around the world have some form of disability? Many people with disabilities often face significant difficulties while performing day-to-day activities. Fortunately, the advent of the internet and the availability of umpteen websites and apps help users with disabilities to perform their tasks easily. However, if websites and apps are not accessible, they are just becoming a part of the problem rather than the solution.

An accessible website helps create an all-inclusive environment where all users have equal access to information and functionality.

Here are some benefits of having an accessible website

  • Enhanced user experience
  • Broadens your audience reach
  • Boosts your SEO
  • Builds positive PR
  • Protects you against accessibility lawsuits

How is web accessibility enforced?

Closeup Shot of a Person Holding a Gavel on the Table

Now that you understand why web accessibility is important, the next step is to understand who enforces or manages web accessibility.

The World Wide Consortium or W3C is an internet community that develops open standards that ensure that the web attains its complete potential. In 1997, the W3C launched an initiative known as the Web Accessibility Initiative (WAI) ,which is focused on guiding people to build more accessible websites.

The WAI consists of industry, disability organizations, government, accessibility research organizations, and much more. They worked together and developed Web Content Accessibility Guidelines (WCAG).

The WCAG is a globally accepted standard that guides developers and organizations in building an accessible website.

Web accessibility standards to follow

A typical study table that contains folders standards and rules stacked on top of each other

The WCAG (Web Content Accessibility Guidelines) is the international standard for web accessibility. The WCAG recommends focusing on four main principles while building an accessible website. You can easily remember by their acronym POUR:

Perceivable(P)

Make the content on your website available to users in how they perceive information. In other words, make sure that your content can be perceived or recognized by multiple senses instead of just focusing on one sense.

For example, if there is an image on your website, make sure that users with vision impairments can access it by providing appropriate alt text so their screen readers can announce the image description.

Operable(O)

Make sure that all users can access all functions or are able to operate all controls on your website.

For example, if there is a video on your website, ensure that users can play, pause or stop the video even through a keyboard rather than using only a mouse to access the controls.

Understandable(U)

Keep it simple, i.e., users should easily understand the content on your website. Furthermore, ensure that users easily understand how to operate any functions of the interface elements.

For example, if there is too much jargon on your website, then it is difficult for users who are not aware of it to understand the content.

Robust(R)

The website content should be compatible with Assistive Technologies (AT) as the users with disabilities use them to access your website.

For example, if the content of your website is optimized for only one type of AT, it will deny others who are using a different technology.

 

Before jumping into the most common web accessibility issues, first try to understand the barriers faced by users with disabilities. Here are some of the common barriers

  1. Auditory: Users have partial or complete hearing loss, making it difficult for them to consume knowledge from content that relies on audio to convey the message
  2. Visual: Users have low vision, color blindness, or sometimes total vision loss which makes it difficult for them to consume knowledge for images, videos, gifs, etc.
  3. Motor: Users have partial or total loss of function in a body part such as limbs, making it difficult for them to navigate websites or complete tasks using devices such as a mouse
  4. Cognitive: Users have difficulty concentrating, learning, or remembering new things which makes it difficult for them to fill out forms if they don’t have clear instructions

Furthermore, some barriers may arise due to certain situations. For example, a user living in a cold region such as Alaska, where the average winter temperature is 20 to −10 °F (−7 to −23 °C), may sometimes rely on voice-activated commands as taking off their gloves might cause frostbite due to the cold weather.

Note: This is not the complete list of disabilities. However, they are the most common forms of disabilities that come under WCAG.

Here are the five most common accessibility issues to avoid

A signboard that reads: 5 common accessibility issues

Color and contrast

Some users may not comprehend the content if color is solely used to convey crucial information. Users with low eyesight or who use screen readers, for example, will not be able to differentiate colors and therefore may not understand the information as the author intended.

Use a color that meets the WCAG color contrast requirements, a visible focus, and a hover highlight to work towards achieving maximum accessibility.

Make sure there is adequate contrast between the background and foreground colors while designing. WCAG recommends a minimum contrast ratio of 4.5:1 for text and images and at least 3:1 for large text and images.

:

If you are unsure about contrast ratio or color schemes, fret not, I have got you covered. Here is my favorite tool to check color contrast on websites.

Screengrab of WebAim website

Images

Users with vision impairments have difficulties understanding the information if it is conveyed only through images. The WCAG recommends organizations or developers provide an alternative to images known as Alt-text.

Alt-text is a brief summary of the information conveyed through the image. The alt-text provided must be precise and convey all the relevant information to users. If the image used is purely for decorative purposes, then mark the image as decorative.

Two images. First: "Almost had a heart attack this morning" there is tiger next to the fence. Second: Moving closer, it's a dog with shadows from the fence.

Here is an example of how to write alt-text for the above image

Bad Alt-text: Tiger sleeping on a sidewalk

Good Alt-text: A dog lying on the sidewalk in front of a gate with the striped shadow of the rails falling on its back, making it appear as a tiger

Videos

Videos on the website should include captions so that it is easier for people with hearing impairments to easily understand the content. Furthermore, you can also provide an extended text description if the captions in the video are insufficient to convey the information.

Avoid using gifs or animations that have flashing lights or contrasting light and dark patterns that might trigger photosensitive epilepsy.

Tip: You can generate free captions for your videos by using websites like Youtube, Descript, etc.

Forms and labels

In order to help individuals fill out forms quickly, the usage of placeholder text is very common. Unfortunately, if placeholders are used entirely to designate form fields, it causes three issues.

  • Due to the poor or low color contrast, people with low vision may not be able to notice the placeholders as clearly as sighted users.
  • The keyboard is typically used by screen reader users to traverse the form fields. The screen reader will not announce the field requiring user input if the <label> tag is missing from the form field.
  • The tab order should be such that keyboard navigation is simple and that each field important to completing the form has labels.

Links

Many websites use links to guide users to a different web page or to provide sources of the acclaimed fact. Since links guide users to a different page, it might cause panic among users, especially people with vision impairments if they are not notified. Here is how you can make links accessible:

  • Notify users about the link’s destination so that they won’t panic if it is an accidental activation.
  • Avoid using words like “click here,” “read more,” etc., as they don’t make sense when read out of context.
  • Make sure that the links are accurate and descriptive so that users can easily understand the purpose behind the links.

For example, say you want to redirect your visitors to the Amazon website

Bad way to write links: To learn more about the product click here.

Good way to write links: To learn more about the product visit the Amazon website

Best free web accessibility testing tools

A person analyzing a program

Accessibility testing ensures that a website is user-friendly for everyone, including people with disabilities. A testing tool is your guardian angel that can conduct extensive testing and generate comprehensive reports that update you on the current accessibility status of the website.

 

WAVE

WAVE is a free accessibility evaluation tool developed by WebAIM.org that aids in the creating accessible content on websites. WAVE analyzes and matches content against the WCAG guidelines and provides you with a comprehensive visual report that contains all the accessibility violations.

 

Cynthia Says

The next one on the list is Cynthia Says, fun fact, Cynthia was developed to raise more awareness about web accessibility testing and its importance. The tool allows you to check the accessibility of every page and provides detailed feedback about the accessibility errors present on the pages.

 

Accessibility Checker by CKSource

The Accessibility Checker is extremely flexible and has one of the most user-friendly UI. It will assist you in inspecting all the compliance errors on the page and also can fix common accessibility issues with its “Quick Fix” function.

 

LERA

LERA is an automated web accessibility testing and reporting tool that provides you with a detailed report of your website’s accessibility issues. It can evaluate websites based on the WCAG 2.1 accessibility guidelines to identify the violations and suggest potential fixes.

LERA is the only fully automated web accessibility extension that provides both Accessibility Audits and Accessibility Reports for free.

There are many more tools available online that are free as well paid. Although these tools can recognize many accessibility issues, one must understand that the tools can only find up to 20% of accessibility errors. Organizations should try to have an in-house accessibility expert or outsource it to others to be on track towards the path of maximum accessibility.

Accessible website examples to inspire you

First, the W3C.

Screengrab of W3C website, an example of web accessibility

Can you imagine Domino’s not selling pizzas?

Exactly! It would be ironic if the community that developed the WCAG guidelines did not follow them. W3C is the greatest example of an accessible website. It also contains web accessibility guidelines and best practices that guide other websites to become more accessible.

 

The ACLU

Screengrab of ACLU website, an example of web accessibility

According to Wikipedia, the American Civil Liberties Union (ACLU) is a nonprofit organization founded in 1920 “to defend and preserve the individual rights and liberties guaranteed to every person in this country by the Constitution and laws of the United States.

In short, ACLU fights to preserve the rights of individuals as guaranteed by the Constitution and also files cases against discrimination of oppressed groups.

The ACLU website carefully uses structural elements such as headings, lists, header and footer, and navigational elements and ensures it is accessible to all users. It also provides an option to turn off the autoplay of the image slideshow and much more.

The World Wildlife Fund

Screengrab of WWF website, an example of web accessibility

The World Wildlife Fund or WWF conveys all the information such as its mission, initiatives, educational content, etc., in an accessible way. It also does not overload its web pages with content, which extremely benefits, the navigation and, in turn, boosts accessibility.

The world is constantly changing, and people depend on technology now more than ever. Therefore, it is essential for organizations to create web or mobile applications that offer more support to users with disabilities.

The ultimate guide to web accessibility

Think about it, how would you feel if there was an office chat group with everyone except you? It would make you feel bad, right? Furthermore, having an accessible digital application will help you avoid legal penalties. Lastly, make sure that your services are accessible to everyone regardless of their disabilities; it will not only boost the confidence of disabled people but also help them have a better quality of life.

 

 

The post The ultimate guide to web accessibility appeared first on Simple Talk.



from Simple Talk https://ift.tt/VKar3dg
via

Metrics that matter for IT organizations on an agile journey

Key Takeaways

  • Having a set of good metrics is essential for the success of agile teams and IT organizations.
  • Metrics are not numbers to beat. Understanding the value delivered by monitoring any metric is important for the team to truly embrace them.
  • A balance of six dimensions – Business delivery excellence, Operational excellence, Technical excellence, Innovation, Happiness, and Financial excellence is essential for the success of agile teams and IT organizations.

As IT organizations move towards an agile way of functioning, it is natural that teams undergo a major learning curve to understand and adapt to agile principles. It is also natural at this stage that teams lose focus on the “things that matter” to the top and bottom lines of the organization as their focus is more on adjusting and settling down in the new way of working. It is at this juncture that a set of “good metrics” would help teams navigate in the right direction. It is worthwhile to note that the standard agile tools like JIRA, Git, Jenkins, etc., provide a standard set of metrics. Teams should consider these as a starting point and continue to define further metrics that make sense to their team as well as the organization that they are part of. Rather than looking at metrics as a number to beat or something imposed by management, it is important that the teams understand the organization’s objectives and how metrics can help them to continuously improve while meeting the organization’s objectives. This article looks at what should typically be the dimensions on which IT organizations assess and fine tune their team performances and processes and how should the individual teams tailor their metrics to contribute to the overall IT organization goals.

Factors that are critical for the success of organizations of any nature or size are productivity, agility, predictability of the outcomes, quality of the work, and the happiness of the teams.

An IT organisation should focus on the following dimensions so that it is able to support the business, mission and vision of the organization.

  • Business delivery excellence
  • Operational excellence
  • Technical excellence
  • Innovation
  • Happiness of the teams
  • Financial excellence

While the CEO, CTO, and CIO establish objectives and key results around these dimensions, the various agile teams should establish OKRs at their team level that are aligned with and contribute to the organization level OKRs. Let us further look at what should be measured (metrics) at both an IT organization level and individual team level. At the onset, it is important to note that these metrics should not be used to compare one member against another or one team against another. They should rather be looked at holistically in the right spirit to identify areas of improvement, ultimately leading to truly agile teams.

1. Business delivery excellence

In simple terms, business delivery excellence objectively looks at how well the IT organization’s deliveries and outcomes are aligned to the business strategy. To successfully measure and improve business delivery excellence, IT organizations should have the means to measure alignment, agility, and predictability of the organization and teams within.

The set of metrics that would provide a good insight into business delivery excellence are as follows:

1.1 Alignment of IT team efforts to strategic business initiatives

The purpose of this metric is to provide visibility into

  1. The alignment of IT projects with strategic business initiatives
  2. Whether enough resources and funds are being invested to support business initiatives
  3. Whether there any projects/efforts that should be stopped or slowed down

At a team level, the following metrics should be used to report towards this organization metric.

  • Percentage of business requests accepted and committed for delivery by the team

This metric helps establish a dialogue between management and teams on identifying and addressing the root causes due to which team is able to commit only a set of business demands or to understand what the team is sacrificing to commit to business demands.

  • Team effort spread on strategic initiatives vs. technical upgrades vs. support requests
  • Team effort spread on the various strategic initiatives

The above two metrics help understand if sufficient resources are assigned to business initiatives and if there are any specific areas that the teams should divert their focus away from and towards strategic business initiatives. It also gives visibility into whether the team is spending too much of its efforts in handling routine upgrades or business-as-usual kind of support requests, which can then feed into identifying areas of automation that can reduce the need for such maintenance efforts.

1.2 Agility of IT organization in catering to business needs

The purpose of this metric is to provide visibility into how quickly the IT organization can adapt to the changing business needs and is also an indicator of how fungible IT teams are.

At a team level, following metrics should be used to report towards this organization metric.

  • Lead and cycle time to deliver new features to existing products or services
  • Lead and cycle time to deliver new products or services

These metrics give important insights into how fast a request is getting picked up by the team and how long it takes for the team to complete a request and deliver value after starting to work on the request.

Longer lead times indicate that there is either a long cycle time or a long time the request is waiting to be picked by the team. These metrics help establish a dialogue on identifying and addressing the root causes for the long lead or cycle times.

1.3 Predictability of IT deliveries

The Agile Alliance defines “Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.” as one of the principles based on the Agile Manifesto. A regular cadence of working software delivery is essential to build trust with customers. This metric helps the management and teams to measure and assess the predictability of releases and establish how confident they could be of the cadence vis-a-vis actions needed to fix any issues.

  • Team velocity variation measures how team velocity is varying over a period of time. Agile teams generally reach a near-constant velocity after a few sprint cycles. Any large deviations in the velocity are an indicator that there is a high chance of not meeting the commitments. Now the cause for such a deviation need not always be due to team inefficiencies. This could also happen when the team decides to implement pair programming or is learning new technology, all valid reasons that would ultimately improve team performance. Having this metric in place helps the team and management to align on the reasons why predictability could be impacted and stakeholder it appropriately with customers.
  • Planned to Done ratio measures the work that the team completes by the end of the sprint compared to the work the team committed to at the start. While there could be many valid reasons for work to spill over into the next sprints, a view of this ratio over a number of sprints would give a general idea of the estimation accuracy of the team and the predictability of their commitments. A review of this metric provides the team an opportunity to fine-tune the estimation rules they follow.

2. Operational excellence

The Institute for Operational Excellence defines operational excellence as a point in the organization’s continuous improvement journey where each and every employee can see the flow of value to the customer, and fix that flow before it breaks down.

In simple terms operational excellence objectively looks at how well the services are operating and how well the customers perceive the value delivered by those services.

Following are a set of metrics that would provide a good insight towards operational excellence:

2.1 Service Availability

Availability is generally expected as a percentage of time the service is operational within the reporting period. In organizations where there is a segmentation of the service offerings like core/non-core, critical/non-critical etc., this metric can be segmented to provide availability metrics per service segment.

At a team level, the following metrics should be used to report towards this organization metric.

  • Frequency of service downtime measuring when and the number of times the service went down during the reporting period
  • Frequency of scheduled vs. unscheduled deployments

The above two metrics together help answer whether the service downtime was expected (due to scheduled deployments, for instance) or if there is an underlying cause that needs to be looked at as it is causing the downtime with no clear, immediate explanation.

  • Service uptime measures the amount of time that the service was up and running during the reporting period.
  • Service downtime measures the amount of time that the service was down during the reporting period

Availability SLA compliance can be computed using the service uptime, downtime metrics, and customer committed SLAs. This is an important metric as it provides a clear indication of whether the customer is able to access and use the service as agreed upon contractually.

  • Service response time – simulating customer interactions with the service or the website and measuring the response time. This metric is typically captured for critical services. This metric gives a good indication of customer experience with the service and areas that would need to be addressed to further enhance this experience.

2.2 Service Reliability

Reliability measures the probability that a service maintains its performance standards in a specific period of time. Following are the most common reliability metrics that are to be monitored.

  • Mean Time Between Failures (MTBF) measures the average time between consecutive application or service failures. A failure could be a major incident like a total network outage or a small incident lasting a few seconds. Nature of the industry and business, customer service level agreements (SLAs) determine the tolerance for the frequency and duration of service failures. A lower value of MTBF could point to inefficiencies with code quality or hardware and other infrastructure issues. Regular review of this metric provides an opportunity to identify and improve upon these inefficiencies.
  • Mean Time to Recovery (MTTR) measures the average time needed to detect, troubleshoot, fix and return the service to a healthy state. It indicates the speed at which a service downtime is resolved. The review of this metric provides an opportunity to discuss and understand how the different processes leading up to the downtime resolution are working – Is the alerting mechanism working optimally? Is the team taking a long time to troubleshoot and fix the problem, and if so, why?
  • Mean Time to Resolve is the average time needed to return the service to a healthy state and ensure that the underlying cause is fully resolved so that the issue will not recur. As this metric aims at improving the long-term performance and reliability of the service, it is an important metric that can be strongly correlated with customer satisfaction.
  • SLA compliance ratio measuring the percentage of issues resolved within all the SLA parameters. While it is important to have a higher SLA compliance ratio, it does not necessarily mean the IT services are operating at optimal levels. In this context, SLOs (Service Level Objective) and SLIs (Service Level Indicator), which are more stringent, should be looked at. An SLO is a target value or range of values for a service level that is measured by an SLI. SLIs are measured internally to determine whether the SLO and hence SLA is being met. This enables the team to identify when they are nearing an SLA breach and hence respond and react quickly to avoid such a breach.

2.3 Customer service and satisfaction

  • Average first response time indicates the time it takes for the support team to reply to a customer request.
  • Average issue resolution time indicates the time it takes to solve an issue reported by the customer.

A shorter duration for the above two metrics provides a better customer experience and thus impacts customer satisfaction positively.

  • Net Promoter Score (NPS) measures how likely a customer is to recommend the product and services of your organization to others. This is an important metric as it gauges how strong customer engagement is and can have a direct impact on sales and revenue. It is worthwhile to note that Customer Service is not the only factor impacting the NPS. Other key factors that can have a direct impact on NPS are the quality of the product, price, and ease of use.

 

3 Technical excellence

This dimension should focus on measuring factors that impact technical excellence, namely quality of delivery, agility in the team, and team culture to adapt to industry technology evolution.

3.1 Quality of delivery

  • Escaped defects is the number of defects that have entered the live environment in a particular release. In an ideal situation, these defects should have been caught in test cycles and addressed. Hence, this metric is an indicator of the release quality and the rigor of the quality control processes followed by the teams.
  • Code coverage provides a view of the extent to which the code base is covered by automated tests. It is important to note that having a 100% code coverage metric does not necessarily assure zero defects, however, it is a good measure of untested code.
  • Functional test coverage which provides a view of which features in the release meet the acceptance criteria
  • Sprint Goal success which is an indicator of how often the team meets customer requirements and is also an indicator of the team’s agile maturity.

3.2 Agility in delivery and team culture

  • Lead and cycle time to deliver service requests and other business as usual activities (BAU) – The earlier sections of this article discussed a similar metric related to business deliveries. A typical agile team has to also focus on BAU requests, and this metric gives insights into how fast a request is getting picked up by the team and how long it takes for the team to complete a request and deliver value after starting to work on the request. This metric, when juxtaposed with the related metric for business delivery, gives insights into whether the team prefers business requests over BAU or vice-versa.
  • Average time builds stay “Red” is an indicator that the team is probably unable to focus on a work item till its completion. This could be due to the assignee multi-tasking or not giving priority to fix the build or that a dependency is not met due to which the build cannot be successful. In either case, this metric provides insights into patterns and behaviors involving team dynamics.
  • Technical debt is a tricky thing to measure and track. However, it can severely impact the team’s ability to maintain and enhance software easily. Many times, teams end up focusing on delivering business requests and will be unable to take dedicated time to refactor or re-architect the hot-spots. One common approach many teams follow is club refactoring when that portion of code needs changes to deliver business demands. A metric to monitor how technical debt is evolving from release to release gives a good indication of the team mindset – whether they are focused on delivering the best software or are content with delivering just the business needs.
  • Duration in which a new member of the team becomes productive is another tricky thing to measure and track. However, it is an important element that impacts the overall team productivity and gives insights into the effectiveness of the on-boarding process and team culture, and team dynamics.

4. Innovation

This dimension should focus on measuring factors that impact innovation advancements in the organization.

  • Innovative Culture gauges how conducive is the environment within the organization to promote innovation at all levels and how it is evolving over time. Some of the important metrics covering this aspect are:
    • Employee perception of organization’s innovativeness measured by periodic surveys across all departments of the organization
    • Number of employees who have undergone training related to innovation covering innovation frameworks, internal processes for managing innovation
    • Number of ideas converted into projects having an executive sponsorship
    • Number of ideas proposed by staff vs. executives
    • Effort spent by the teams on innovative ideas vs. other initiatives
  • Innovation pipeline

The focus here is to measure the efficiency of the innovation pipeline and ideation process. Some of the important metrics covering this aspect are:

    • Ratio of new ideas proposed to those implemented
    • Average time an idea stays in the different stages of the idea life cycle
    • How soon ideas that don’t get implemented are killed
  • Innovation outcomes

The focus here is to measure the effectiveness of the innovation process

    • Time to market measuring how long it takes for an idea to get implemented and released to customers
    • Innovation spending converted to new product sales measuring how much revenue each dollar spent on innovation is bringing in
    • Customer perception of the organization’s innovativeness measured by periodic customer surveys and other methods.

5. People growth and happiness

This dimension should focus on gauging how “happy” the teams are. At the most foundational level, a team’s success or failure is highly dependent on its team members.

  • Employee engagement: Employee satisfaction survey is a popular means that organizations have been using for a long time to gauge employee engagement. Net Promoter Score is another popular metric used. However, rather than asking a single question, “How likely are you to recommend others to work at our organization” or “How happy are you with the organization” which evokes a very subjective response, it is prudent to have a set of specific questions so that specific areas of improvement can be identified based on employee feedback.
  • Employee churn is a measure of how many people leave the organization in any given period. This is a strong indicator of how happy employees are, as happy employees are more likely to stay in the organization.
  • Employee upskilling and re-skilling is a measure of how the staff of the organisation are preparing for the future, which is a key factor for building a resilient and adaptable workforce.

6. Financial Excellence

IT Financial Excellence aims to optimize the IT spend while maximizing the value delivered by IT resources.

The following are a set of metrics that would provide a good insight into financial excellence. These metrics help put other key metrics of other dimensions (business delivery, operational and technical) in the context of IT resources and investment.

  • Budget spent on strategic initiatives vs. support requests vs. innovation provides a view of how much is being spent on growing, running and transforming the business and whether this aligns with the organisation’s objectives.
  • Total cost of ownership per service enables IT teams and managers to know the true cost of the service (human resources, infrastructure, and other IT resources including, CapEx and OpEx costs) and enables them to make better decisions on the IT spend considering the service criticality and current spend.

Conclusion

There are many metrics that could be measured. Ensuring a balanced focus on the six dimensions of Business delivery excellence, Operational excellence, Technical excellence, Innovation, Happiness, and Financial excellence and understanding the value each of the metrics brings in are essential for the success of agile teams.

References:

https://hbr.org/2017/09/what-your-innovation-process-should-look-like

https://innovation-leaders.co.uk/pipeline/

https://www.tmaworld.com/2017/11/18/how-create-successful-innovation-pipeline/

https://runway.is/blog/how-to-measure-innovation/

https://www2.planview.com/im3/docs/Planview-Innovation-Maturity-Model.pdf

https://www0.gsb.columbia.edu/mygsb/faculty/research/pubfiles/4566/firm%20innovativeness.pdf

https://www.forbes.com/sites/forbestechcouncil/2020/12/21/why-employee-upskilling-and-reskilling-is-so-important-right-now/?sh=2e0e0dbe3302

https://www.tbmcouncil.org

https://community.tbmcouncil.org/HigherLogic/System/DownloadDocumentFile.ashx?DocumentFileKey=67618692-dd95-4f03-a986-03bca89100b7&forceDialog=0

https://dsimg.ubm-us.net/envelope/151893/296392/1390318118_WP_-_Apptio_IT_Financial_Metrics_Primer.pdf

https://cloud.google.com/blog/products/devops-sre/sre-fundamentals-slis-slas-and-slos

https://sre.google/sre-book/service-level-objectives/

https://financesonline.com/10-important-kpis-and-metrics-your-customer-support-team-should-be-using/

https://www.agilealliance.org/agile101/12-principles-behind-the-agile-manifesto/

https://instituteopex.org

 

The post Metrics that matter for IT organizations on an agile journey appeared first on Simple Talk.



from Simple Talk https://ift.tt/akAN3QM
via

Thursday, June 2, 2022

One more about Star Trek

I can’t move on from editing Simple Talk without one  more editorial about Star Trek. There are over 600 hours of episodes and movies to watch, and despite being a fan, I don’t think I’ll ever catch up. Even worse, I haven’t watched most of what I’ve seen more than once.

Lately, I just completed watching Star Trek: Discovery and have caught a few episodes of Picard. I was planning to rewatch the original series after Discovery, but with news about many characters from The Next Generation joining Picard, my plans have changed. There are two animated series and another new one called Strange New Worlds. To make it even more difficult,  The Orville will be back with season 3 by the time this article is published. I agree with many Trekkies who say it’s a lot like Star Trek.

Star Trek depicts life across galaxies, universes, and time. In the future, it shows a united Earth where all countries and all people finally get along. Of course, there are still many villains like the  Cardassians, Romulans, The Borg, Terrans, and a host of others in the Delta and Gamma Quadrants.

One of my favorite things about Star Trek is that there are many powerful women, both good like Captain Janeway and evil like the Borg Queen. Discovery is a great example. The main Michael Burnham is a hero. Her mentor, Captain Philippa Georgiou ends up being a villain in another universe. I especially like when women are the engineers like Voyager. Captain Janeway, B’Elanna Torres, and Seven of Nine figure things out!

Of course, there are some Star Trek species that treat women with disdain, such as the Klingons and Ferengi. If you’ve ever seen an episode with a Klingon woman, you know they are fierce and worthy of lots of respect.

Thanks for reading my many editorials over the past four and a half years, and I hope the next editor feels just as appreciated as you have made me feel.    

Commentary Competition

Enjoyed the topic? Have a relevant anecdote? Disagree with the author? Leave your two cents on this post in the comments below, and our favourite response will win a $50 Amazon gift card. The competition closes two weeks from the date of publication, and the winner will be announced in the next Simple Talk newsletter.

The post One more about Star Trek appeared first on Simple Talk.



from Simple Talk https://ift.tt/HKUtnZV
via

Tuesday, May 31, 2022

The Job of a Technical Editor (as Louis sees it)

One of the most essential parts of producing a great technical article, blog, or even a book, (referred to from now on generally as a work) is having someone who can check your writing and make sure it is right. You can do a mediocre job with grammar, punctuation, etc. and still produce technical resources that people can get value out of. But when technical details are wrong…it is actually possible that a reader becomes less knowledgeable by reading what was supposed to be a technical resource.

In this blog, I want to put out a few guidelines that I use when am a technical editor for some piece of writing… sometimes even my own. Usually this kind of task will be done on non-academic work, sometimes called trade publications. There will be very  little new ideas put forth in the writing and the usual point is to take what can be a complex topic and simplify it for the reader. As such, it is not atypical that the writer is actually less knowledgeable about parts of the topic than desired. I know in the first version of my Database Design book (on version 6 now), I did a reasonably bad job of understanding some topics (both before and after the tech edit phase). The book overall was pretty good, with the help of some really good tech editing, but even today I have had a comment or two from academics on how my book doesn’t quite get it.

Let me clarify one point a little before proceeding with a few guidelines. I did say “even my own.” When I write a blog, I don’t have a tech editor, so I have to put a little space between myself and the writing and read the material a few times and say “is that really right?” Usually I am (and usually most writers I have worked with were too,) but usually isn’t the target. If I can’t say 100% in my mind that something is right, I still look it up.

The general process of doing a technical edit for a computer book, for me has been this:

  • Scan the document, to get an idea of structure
  • Read the material with a suspicious eye, like you think the author of the writing is dumber than toast. It is easier to do when it is your own work, admittedly.
  • Execute every piece of code, build every VM, set up everything that is described (To your limits)
  • Comment (usually in a Word document) on everything that doesn’t work
  • Comment everywhere you disagree technically
  • Give ideas on how to make the piece of work better
  • Give feedback on how things are good

It can be a daunting task and not everyone wants a tremendous amount of feedback. Ok, no one WANTS a lot of feedback, but I know I personally am more afraid of 0 comments than I am of 100s. The following are tips I suggest people consider when they are tech editing, as much as possible:

———

Be nice – I want to start here because this can be the hardest thing. But I have heard many times from an author “thank you for the nice comment”, usually because I was tearing up the rest of the work. If you have major concerns, pointing out what is working is a great idea. (Ideally not in one of those “yeah, this is great, but actually it is not” sort of ways. Fake niceness is, to me, worse than just getting told I am doing a bad job.

Be nitpicky – The whole job is really just being nitpicky. Like really nitcpicky. (Comment: not how nitpicky is spelled) (Comment: Good point, but while being annoyingly nitpicky is a lot of the job, it really isn’t all of it. Should probably be “Most of the job…”) (Comment: check with your author/book publisher to see how nitpicky. Sometimes the target audience is important to the level being targeted. Still, right is right and wrong is never right.)

No seriously, niceness is important – Because all that nitpickiness really builds up. Most technical authors probably have experienced some serious anger/anxiety/etc from a bunch of tech edits. When you finish working on a piece of work after a tech edit it is a great feeling, and usually I look back and say “That was great! Thank you tech editor”.

Along these lines, I would generally say not to be repetitive. If the writer says something wrong repeatedly, after a few times, maybe just note that it is repeated if it is clear enough along. Not only does it start to hurt, but it gets in the way of finding other stuff.

I like it when people are verbose and offer suggestions – Say I wrote “the sky is blue”. A comment might be, “not clear, explain.” Or it could be “This isn’t clear because I am not sure when you meant. What if you said ‘The sky is blue during clear skies because of… ‘ and then explained.” When the project is nearing the end, if the comment is unclear, it is probably ignored and you probably had a good point.

Suggestions may or may not be welcomed by an author. Don’t take it bad if you are involved in a second tech edit to see comments like “this is my book, that is not what I am doing”. You may not be the tech editor for that author in the future :). 

I feel like this is part of the value you provide as a tech editor if it is desired by your author. I like nothing more than to get back a chapter with lots of suggestions as to how to be more clear, or more right. Not everyone agrees and what makes your job “good enough” is a complex topic!

Make sure you KNOW you are right or make sure to note it as such – When you are going to tell the writer that their work is wrong, make sure you can back it up. When editing something I don’t really understand, I do searches for keywords found on the web. If I don’t see it in a few places so I am sure something is wrong,  I tend to say “I think this may be wrong based on ‘sentence from a document’ linked here: https://somewhere” or sometimes just from my memory (which I will also note!) Obviously a great technical document can be backed up with lots of external documentation, most of which you won’t be linking to or citing (unless this is actually a new idea and proof of that idea… which is not typically what I am talking about here.)

Make (at least) two passes through a document –  Start out skimming the work as much as is reasonable, looking for the topics covered. As the technical author, you might suggest that things are out of order, but the worst feeling is spending 10 minutes explaining how something needs to be said, only to find it a few pages later. Done this many times. Many.

Be as thorough as expected, but not too much more – It is not your work, and your name will probably just be a brief footnote in the book, but I try to think “if it was me, what would I want”. Nothing makes me more unhappy than to find glaring errors in a piece of work that supposedly was checked over. I don’t expect perfection, and I definitely don’t deliver it, but if I have written 10-1=0, I hope that is caught even in a casual read.

(My theory on how I miss such simple stuff in my initial submissions is that as an author I have read and modified parts of the material 5-20 times and I get blind to parts of the document. Seriously start to hate every word you have written until you can be away from it for a few weeks. When you are tech editing, you generally only want to make two passes and not get that connected to the work…though that is not always possible.) 

If something smells funny, check it out – Authors at times forget the lessons of high school English: “You have to write your own material.” In the real world the rule is more “You need to produce original material.”

Sometimes it can be a ghost writer situation (having someone else write for you may or may not be allowed) that causes it to seem like 2 people wrote something. But when this is the case, it is essential that the publisher is okay with multiple authors.

The other thing to look out for is plagiarism. Even if the publisher allowed for multiple people working on the work, the other writers need to have authorized the usage. Copying and pasting from random websites is often caught by pasting sections of text into a search engine.

On more than one occasion I have searched for a sentence to find large amounts of material from a vendor’s documentation repeated exactly in the text. Best case it was unintended. Worst case it gets through and the original work’s author sues the author (and probably only the author…read your writer’s contract, they make that clear!)

Don’t change the source material unless authorized – When I do my own tech editing, I change the text as I find issues. I really don’t like changing other people’s work, and I don’t like mine changed either (unless it is a work for hire and the person paying me makes the changes…It is essentially theirs anyhow. Posting suggested changes into comments puts the onus on the writer to agree without looking through change tracking.

NEVER change a document without change tracking/commenting – Even if authorized to make changes, even if you are the technical editor for the book/website, even if it is the simplest of things. Make sure the original author can see what changes have been made.

——-

This is just a few notes on what I like to do as a technical editor, I might add to them later, but the gist of it is this. If you are technical editing a piece of work, your job is to improve the technical correctness of the work some amount. This may just be a quick overview of the work, and it could be a line by line correction of every little issue.

Discuss how deep to check correctness with the people you are working with, possibly the author or book’s editor before you do too much or too little. I personally prefer to almost prove that everything stated in the work is correct if I can, but that may not be what you are requested to do.

The post The Job of a Technical Editor (as Louis sees it) appeared first on Simple Talk.



from Simple Talk https://ift.tt/eau2CBZ
via

Saturday, May 28, 2022

Summarizing data using GROUP BY and HAVING clauses

SQL Server provides the GROUP BY clause as a means to take a set of detailed values and summarize them into aggregated values. The detailed records can be aggregated based on one column, as well as expressions, which are specified in the GROUP BY clause. This article explores how to return summarized data using the GROUP BY and HAVING clauses.

Test data

In order to demonstrate how to use the GROUP BY and HAVING clauses, some test data will be needed. All of the examples in this article will use a table called Invoice that is created in tempdb, using the code in Listing 1.

Listing 1: Code to create test data

USE tempdb;
GO
CREATE TABLE Invoice (
InvoiceID INT,
InvDT DATE,
InvAmt DECIMAL(10,2),
PaymentDT Date, 
PaymentAmt DECIMAL(10,2),
ProductName VARCHAR(20)
)
GO
INSERT INTO Invoice VALUES
(1,'2021-02-14',121.11,'2021-03-01',121.11,'Thingamajig'),
(2,'2021-02-14',159.16,'2021-03-13',159.16,'Watchamacallit'),
(3,'2021-02-14',75.59,'2021-03-03',75.16,'Dohicky'),
(4,'2021-02-14',121.11,'2021-03-01',121.11,'Thingamajig'),
(5,'2021-02-14',75.59,'2021-02-21',75.16,'Dohicky'),
(6,'2021-03-03',159.16,Null,null,'Watchamacallit'),
(7,'2021-03-11',75.59,'2021-03-30',75.16,'Dohicky'),
(8,'2021-02-14',121.11,'2021-03-01',121.11,'Thingamajig'),
(9,'2021-03-11',159.16,null,null,'Watchamacallit');
GO

The code in Listing 1 created nine different invoice records in the Invoice table. Each row contains a single invoice record for one of three different ProductName’s: Thingamajig, Watchamacallit, and Dohicky. Each row has an InvDT, and an InvAmt, where the InvDT identifies the date the product was sold, and the InvAmt identifies the amount the product sold for. Each product sells for a different price, but each sale of a specific product sells for the same amount. The PaymentDT and PaymentAmt identify the date and amount each payment was made. A couple of the invoices have not been paid, hence why their PaymentDT and PaymentAmt are null.

A few different examples will be provided that use the test data in the Invoice table to demonstrate how the GROUP BY and HAVING clauses work. If you would like to run the example code provided in this article, you can use the code in Listing 1 to create the Invoice table on your instance of SQL Server.

Summarizing based on a single column

This first example shows how to write a GROUP BY clause that aggregates the rows in the Invoice table based on a single column grouping specification. This example calculates the total and average invoice amount for each product identified in the Invoice table by using the code in Listing 2.

Listing 2: Grouping based on a single column

USE tempdb;
GO
SELECT ProductName, 
SUM(InvAmt) TotalInvAmt, AVG(InvAmt) AvgInvAmt 
FROM Invoice
GROUP BY ProductName;

Report 1 shows the results when Listing 2 is executed.

Report 1: Results when Listing 2 is run

Image showing 3 rows. ProductName, TotalInvAmt, AvgInvAmt. Dohicky, 226.77, 75.599999; Thingamajig, 363.33, 121.110000, Watchamacallit, 477.48, 159.160000

In Listing 2, the GROUP BY clause identifies only a single column named ProductName. This told SQL Server to group the rows by ProductName when calculating the TotalInvAmt and the AvgInvAmt. The TotalInvAmt for each of the different products was calculated using the SUM function, whereas the AvgInvAmt was calculated using the AVG function. Since there were only three different products sold in the Invoice table, only three summarized amounts were returned, one for each ProductName.

When a SELECT statement contains a GROUP BY clause, the columns in the select list can only be those columns identified in the GROUP BY clause, or column values calculated using an aggregate function. If there is no GROUP BY clause, then only aggregate functions can be added to the SELECT list and ORDER BY clause. In this case, the query will return one row and provide summary calculations over the entire result set. If a non-group by column is identified in the select list or ORDER BY clause, and it is not contained in an aggregate function, an error similar to the error in Report 2 will be produced.

Report 2: Error received when a column listed that is not contained in an aggregate function

Msg 8120, Level 16, State 1, Line 31

Column 'Invoice.InvDT' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

The code Listing 3 was run to generate the error in Report 2.

Listing 3: Code containing selection list column not contained in aggregate function

USE tempdb;
GO
SELECT ProductName, InvDT, 
SUM(InvAmt) TotalInvAmt, AVG(InvAmt) AvgInvAmt 
FROM Invoice
GROUP BY ProductName;

Returning a subset of summarized values

If only a subset of the summarized rows needs to be returned, then a WHERE constraint can be used to identify the subset. The code in Listing 4 uses the WHERE clause to only return the summarized values for the ProductName Dohicky.

Listing 4: Constraining result set using WHERE clause

USE tempdb;
GO
SELECT ProductName, 
SUM(InvAmt) TotalInvAmt, AVG(InvAmt) AvgInvAmt 
FROM Invoice
WHERE ProductName = 'Dohicky'
GROUP BY ProductName;

When adding the WHERE constraint to a SQL statement that contains a GROUP BY clause, the WHERE clause needs to be placed prior to the GROUP BY clause. The results shown in Report 3 are produced when the code in Listing 4 is executed.

Report 3: Output produced when Listing 4 is executed

An image showing 1 ros. ProductName, TotalInvAmt, AvgInvAmt, Dohicky, 226.77, 75.590000

Grouping based on multiple columns

There are times when data summarization needs to produce summarized values with more granularity than a single column. When this is needed, multiple columns can be specified in the GROUP BY criteria, as shown in Listing 5.

Listing 5: Summarizing based on ProductName and InvDT

USE tempdb;
GO
SELECT ProductName, InvDT, 
SUM(InvAmt) TotalInvAmt, AVG(InvAmt) AvgInvAmt 
FROM Invoice
GROUP BY ProductName, InvDT;

In Listing 5, two columns, ProductName and InvDT, were identified in the GROUP BY clause. This tells SQL Server to summarize the test data based on each unique combination of these two column values. Report 4 contains the output created when Listing 5 is executed.

Report 4: Output when Listing 5 is run

An image showing 6 rows. ProductName, InvDT, TotalInvAmt, AvgInvAmt; Dohicky, 2021-02-14, 151.18, 75.590000; Thingamajig, 2021-02-14, 363.33, 121.110000; Watchamacallit, 2021-02-14, 159.16, 159.160000; Watchamacallit, 2021-03-03, 159.16, 159.160000; Dohicky, 2021-03-11, 75.59, 75.590000; Watchamacallit, 2021-03-11, 159.16, 159.160000

Sorting summarized data

You may have noticed that in the prior example, the output in Report 4 was not sorted by ProductName and InvDT, even though the data was grouped and summarized by ProductName and InvDT. The ordering of the output is based on the unique combination of the grouped columns, and not the individual values of the columns in the GROUP BY clause. The only way to guarantee the output’s order is to have an ORDER BY clause. The code in Listing 6 groups the data the same as in Listing 5, but the output is produced in a different order because an ORDER BY clause has been added in Listing 6.

Listing 6: Sorting summarized data

USE tempdb;
GO
SELECT ProductName, InvDT, 
SUM(InvAmt) TotalInvAmt, AVG(InvAmt) AvgInvAmt 
FROM Invoice
GROUP BY ProductName, InvDT
ORDER BY ProductName, InvDT;

When using the ORDER BY clause, it must be specified after the GROUP BY clause. Report 5 shows the output produced when the code in Listing 6 is executed.

Report 5: Output with Listing 6 is run

Same rows returned as last image, but this time they are sorted by ProductName and InvDt

By using the ORDER BY clause, the output in Report 5 is sorted by ProductName and InvDT.

Using an expression in the GROUP BY clause

Expressions can also be used in the GROUP BY clause to identify the values to summarize on. To show how an expression can be used in the GROUP BY clause, look at the code in Listing 7.

Listing 7: Using Expression in GROUP BY clause

USE tempdb;
GO
SELECT CAST(YEAR(InvDT) as CHAR(4)) + '-' + RIGHT(MONTH(InvDT) + 100,2) YearMonth,
SUM(InvAmt) TotalInvAmt , AVG(InvAmt) AvgInvAmt
FROM Invoice
GROUP BY  CAST(YEAR(InvDT) as CHAR(4)) + '-' + RIGHT(MONTH(InvDT) + 100,2);

The code in Listing 7 summarizes the rows in the Invoice table based on the year and month of the invoice. The year and month values are calculated from the InvDT using the following expression:

CAST(YEAR(InvDT) as CHAR(4)) + ‘-‘ + RIGHT(MONTH(InvDT) + 100,2);

This expression was specified on the GROUP BY clause to identify the values for summarizing. Remember that any column specified in the selection list either needs to be used with an aggregate function or by one of the GROUP BY values. Therefore, the expression identified can be included in the selection list, so the year and month values could be displayed in the result set, as shown in Report 6.

Report 6: Output when Listing 7 is run

An image showing 2 rows returned. YearMonth, TotalInvAmt, AvgInvAmt; 2021-02, 673.67, 112.278333; 2021-03, 393.91, 131.303333

Grouping NULL values

When comparing two different null values by design are not equal, but when grouping on a column that contain null values, the nulls are grouped together as if they are equal. To demonstrate, run the code in Listing 8.

Listing 8: GROUP ON column with null values

USE tempdb;
GO
SELECT PaymentDT, MIN(PaymentAmt) MinPaymentAmt
FROM Invoice 
GROUP BY PaymentDT;

Report 7 shows results when Listing 8 is run.

Report 7: Output when Listing 8 is executed

An image showing 6 rows returned. PaymentDT, MinPaymentAmt, NULL, NULL; 2021-02-21, 75.16; 2021-03-01, 121.11; 2021-03-03, 75.16; 2021-03-13, 159.16; 2021-03-30, 75.16

There is a row in Report 7 that has NULL for PaymentDT column. This row was created when grouping together the two rows that don’t have a PaymentDT value. The value of NULL under the MinPaymentAmt column occurred because null values are ignored for all aggregate functions, except the COUNT(*) function.

Because nulls are grouped together, and most aggregate functions ignore null values, summarizing results using a GROUP BY clause might create some summarized values that some might consider inaccurate. To see how aggregate functions ignore nulls, review the rows with null values in the sample data by running the code in Listing 9.

Listing 9: Displaying sample data

USE tempdb;
GO
SELECT ProductName, PaymentAmt
FROM Invoice 
WHERE ProductName = 'Watchamacallit';

Report 8 shows the output created when Listing 9 is executed.

Report 8: Output when Listing 9 is run

An image showing 3 rows returned. ProductName, PaymentAmt; Watchmacallit, 159.16; Watchamacallit, NULL; Watchamacallit, NULL

In Report 8, the PaymentAmt is null for two of the rows in the result set. To demonstrate how aggregate functions ignore nulls, consider the code in Listing 10.

Listing 10: Calculating average

USE tempdb;
GO
SELECT AVG(PaymentAmt) AvgPaymentAmt
FROM Invoice 
WHERE ProductName = 'Watchamacallit';

When Listing 10 is executed, it returns the value 159.160000 for the AvgPaymentAmt. Is that the correct average amount? If you expected the average to be calculated based on three rows with a ProductName of Watchamacallit, then it is not correct. Because SQL Server ignores nulls when using the AVG function, it doesn’t consider the two rows with nulls when determining the average amount. Since nulls are ignored when summarizing the data, the average value of 159.16 is correct.

Using the GROUP BY clause in conjunction with the AVG function to calculate the average for each ProductName also ignores the null values, as can be seen by reviewing the output created when the code in Listing 11 is executed.

Listing 11: Calculating the average for each ProductName

USE tempdb;
GO
SELECT ProductName, AVG(PaymentAmt) AvgPaymentAmt
FROM Invoice 
GROUP BY ProductName;

Report 9 shows out output when Listing 11 is run.

Report 9: Output when Listing 10 is executed

An image showing 3 rows returned. ProductName, AvgPaymentAmt; Dohicky, 75.160000; Thingamajig, 121.110000; Watchmacallit, 159.160000

If the rows with null values need to be considered when calculating the average, then the nulls need to be converted to 0.00 prior to the AVG function being processed, as is shown in Listing 12.

Listing 12: Considering rows with a null value when calculating average

USE tempdb;
GO
SELECT ProductName, AVG(ISNULL(PaymentAmt, 0.00)) AvgPaymentAmt
FROM Invoice 
GROUP BY ProductName;

Report 10 shows the output when Listing 12 is executed.

Report 10: Output when Listing 12 is run

An image showing 3 rows returned. ProductName, AvgPaymentAmt; Dohicky, 75.160000; Thingamajig, 121.110000; Watchamacallit, 53.053333

The code in Listing 12 used the ISNULL function to convert null values for the PaymentAmt column to 0.00 prior to the AVG function being applied to calculate the average amount. By doing this, the AVG function considered all rows with ProductName Watchamacallit rows when calculating the AvgPaymentAmt.

HAVING clause

The HAVING clause is used to filter out summarized rows created by the GROUP BY clause. The WHERE clause is similar to the HAVING clause. The difference is that the WHERE clause filters out rows prior to them being summarized, whereas the HAVING clause filters the rows after they have been summarized into the groups identified in the GROUP BY clause. To demonstrate how the HAVING clause filters out summarized rows, consider the code in Listing 13.

Listing 13: Using the HAVING clause

USE tempdb;
GO
SELECT ProductName, AVG(ISNULL(PaymentAmt, 0.00)) AvgPaymentAmt
FROM Invoice 
GROUP BY ProductName
HAVING AVG(ISNULL(PaymentAmt, 0.00)) > 60;

Report 11 shows output when Listing 13 is run.

Report 11: Output when Listing 13 is executed

An image showing 2 rows returned. ProductName, AvgPaymentAmt; Dohicky, 75.16000; Thingamajig, 121.110000

The HAVING clause in Listing 13 only returned summarized rows that had an AvgPaymentAmt greater than 60. By comparing Report 11 to Report 10, you can see the Whatchamacallit row was removed by the HAVING clause.

Summarizing data using GROUP BY and HAVING clauses

This article covered how to take detail data and roll it up to produce summarized data using the GROUP BY and HAVING clauses. Data can be summarized based on a single column or multiple columns, and even expressions can be used. Null values cannot be compared because they are unknown values. But when using the GROUP BY clause, null values are treated as if they are the same value for aggregation purposes. Using the GROUP BY clause does cause SQL Server to sort the detail rows to perform aggregation, but only by including the ORDER BY clause can the output order be guaranteed. Next time you need to summarize, filter, and display aggregated data, you will know how to use the GROUP BY and HAVING clauses in conjunction with the WHERE and ORDER BY clauses to produce the rolled-up data you require.

If you liked this article, you might also like  The ins and outs of joining tables in SQL Server .

The post Summarizing data using GROUP BY and HAVING clauses appeared first on Simple Talk.



from Simple Talk https://ift.tt/cruK8DX
via

Friday, May 27, 2022

Security in MySQL: Part Two

Welcome back to this series about improving the security in your MySQL infrastructure. The first part of this series touched upon the reasons why should you consider securing your MySQL environment and walked you through some of the security basics. It covered what happens after MySQL-related data breaches and also told you that the security of any MySQL infrastructure can be conveniently split into several parts, the main ones being:

  • Access control.
  • User security.
  • The components and plugins that help keep MySQL safe from cyber crooks.
  • Security considerations and general security guidelines.
  • Enterprise-level security controls.

The first article of the series went through access control and user security; the second part will cover the rest of the security concerns outlined above.

Components That Keep MySQL Safe

When thinking about components that keep MySQL safe, it’s absolutely crucial to understand what components are in the first place. In this case, the majority of attention should be directed toward security plugins. Some people immediately associate the phrase “security plugins” with the MySQL Enterprise Firewall, which is a firewall monitoring databases for any unauthorized activity (the article will touch upon it in the section about Enterprise-level security controls). Still, there’s so much more than meets the eye. MySQL is kept safe by the following components:

  • Plugins that control the authentication mechanism.
  • Plugins that guard who and how can connect to MySQL.
  • Plugins that help keep passwords secure.
  • Enterprise-level security components.

MySQL offers a couple of authentication plugins to help developers choose the most suitable authentication method for their use case. Connection-related plugins are suitable for developers who might want to introduce delays to responses once a specified number of requests have been sent, password security plugins can help ensure that passwords are safe, and enterprise-level security controls are suitable for enterprise-sized businesses that need to make use of auditing and real-time security capabilities offered by MySQL. There are more authentication plugins, but here’s what you need to know on a high level:

Plugin

What’s it About?

mysql_native_password

One of the “main” authentication plugins available in MySQL. This plugin, as suggested by the name, implements “native” authentication. Native means the authentication that was in place before pluggable authentication was introduced.

sha256_password [1] and caching_sha2_password [2] (among a couple of others, see explanation to the side *)

All of these plugins deal with pluggable authentication. Pluggable authentication essentially refers to the fact that connections are made through a local Unix file. SHA256 password-based pluggable authentication ([1]) implements SHA-256 hashing for passwords while caching SHA-2 pluggable authentication ([2]) does the same thing but also adds caching to boost performance.

* Pluggable authentication plugins also include plugins that enable the use of native Windows functions to authenticate users, enable users to send passwords to the server in plain text, and do a couple of other things. The full list of pluggable authentication plugins is available here.

As noted, though, there are also a couple of plugins that guard the connections to MySQL, and the main one is called CONNECTION_CONTROL. It essentially logs all connections to MySQL and, as of MySQL 5.7.17, logs them to a separate table called CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS which has two columns denoting who (what account) tried to connect (the column is called USERHOST) and how many failed connection attempts the account in question has incurred (the column is called FAILED_ATTEMPTS.)

To use this plugin, install it first – either run both of the commands specified below (use connection_control.dll instead of connection_control.so if you’re running Windows. This applies to all instances of *.so files):

INSTALL PLUGIN CONNECTION_CONTROL SONAME ‘connection_control.so’;

INSTALL PLUGIN CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS SONAME ‘connection_control.so’;

Alternatively, add a line into my.cnf under the [mysqld] section, and you will be golden (if you choose to go down this route, don’t forget to restart the server afterwards):

plugin-load-add=connection_control.so

After you install the plugin, come back to the documentation and configure it according to your needs – the documentation should be able to help you with that.

Once connections are under control, it’s time to take care of password security. You know the drill – use alphanumeric characters and symbols, consider using more than 8 (or, preferably 16) symbols for maximum security, etc.

MySQL, however, is able to take a different approach. To start with, simply add the line below [mysqld] inside of your my.cnf file, then restart the MySQL daemon (mysqld):

plugin-load-add=validate_password.so

This line will activate the password validation plugin. To check if the plugin is enabled, issue a query like SHOW VARIABLES LIKE 'validate_password%'; and if the plugin is enabled, you should see something similar to the following (the results may vary depending on the plugin’s configuration):

mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | ON     |
| validate_password_dictionary_file    |        |
| validate_password_length             | 16     |
| validate_password_mixed_case_count   | 3      |
| validate_password_number_count       | 2      |
| validate_password_policy             | LOW    |
| validate_password_special_char_count | 1      |
+--------------------------------------+--------+

The plugin can be very easily configured by adding options inside of my.cnf or inside of the command line. For all of the available options, head over to the documentation.

There are a couple of enterprise-based security components of interest as well:

Security Component

About

MySQL Enterprise Firewall

The firewall guards the perimeter of MySQL and monitors or blocks suspicious activity. The firewall is, unfortunately, not free and comes only with the enterprise edition of MySQL or more advanced counterparts – such licenses start from $5,000.

MySQL Enterprise Audit

Such a security component is also only available within the Enterprise edition of MySQL, and its primary purpose is to allow an organization to strengthen its security via security controls.

Enterprise security components will be covered in little more detail in a section dedicated to them, but before doing so, you should understand some general security guidelines and things you should consider before embarking on a longer security journey together with MySQL.

General Security Measures

No system is secure if the most basic – general – security measures are overlooked. The same goes for MySQL. Thankfully, securing infrastructure isn’t that hard and shouldn’t take much effort if you know what you’re doing. Here are some of the most important things to do:

Action That Needs Consideration

Why?

Consider running mysql_secure_installation prior to working with MySQL.

The script is especially important when configuring MySQL or its flavors (think MariaDB or Percona Server) for the first time. It allows setting a password for the root account, removes the test database (it can be accessed by anonymous users by default), and does a couple of other things.

Never run MySQL as root.

Such a path is dangerous because a root user has the FILE privilege, which enables reading and writing to files – see more details here.

Don’t store passwords inside of your database in plain text.

If the website you run MySQL on suffers a data breach (and that’s only a matter of time these days), all of your users’ passwords will be visible to an attacker. The attacker will use those passwords for identity theft and credential stuffing attacks to cause further harm. Instead, opt to use a one-way hashing function like Blowfish or BCrypt.

Only grant necessary privileges to users.

If any user has privileges that aren’t necessary for him to complete his duties, there’s a security risk. Should an attacker gain access to such an account via a data breach or a credential stuffing attack, the consequences can be very severe.

Lock accounts that are not in use.

If you are certain that you or anybody on your team won’t have a need to use an account neither now or in the future, it’s a good idea to lock it to prevent possible damage due to unauthorized access. Lock accounts by adding an ACCOUNT LOCK statement to a query, and then, if anybody tries to log in to a locked account, they will see the following message:
ERROR 3118 (HY000): Access denied for user ‘demo@localhost’. Account is locked.

Back up your data frequently.

This one is obvious, but you would be surprised how many people still neglect the power of backups; backups are sometimes thought of as a last resort, but if your server fails or electricity goes out mid-query, backups can be real saviors! Also, when backing your data up, don’t forget that it’s equally important to test the backups that you are taking. Otherwise, how can you know that you will be able to quickly restore them?

Make sure to follow these general security measures at any time you find yourself working with MySQL. Also, consider installing one or more components into MySQL to keep yourself on the safe side, and finally, don’t forget that there are also multiple enterprise-level security controls that you can employ if you wish to go down that path.

Enterprise-level Security Controls

This article discussed some of the enterprise security controls MySQL lets you use earlier on, however, there are some more things to cover. For example, you already know that the enterprise edition of MySQL offers you the ability to use a custom firewall, but did you know that the enterprise edition of MySQL also comes with:

  • MySQL Enterprise Backup capabilities – this tool is a beast in and of itself as it can offer hot backups without interrupting any of the transactions that are currently running in your MySQL instance, and it can also easily and quickly deal with all kinds of backups – no matter full, incremental, or partial. Not only that, it also offers backup encryption, compression, and validation, helping you make sure that your backups are in a top-notch shape both during the day and during the night.
  • MySQL Enterprise Masking capabilities – this solution is self-explanatory, and it can help developers adhere to regulations such as GDPR and HIPAA by de-identifying and masking sensitive user data as required.
  • MySQL Enterprise Authentication will let us authenticate all MySQL users by implementing Single Sign On (SSO) capabilities, so it’s worth taking a look into as well.
  • MySQL Enterprise Encryption – this capability of MySQL enterprise edition lets DBAs and developers encrypt sensitive data as it passes through MySQL. It lets businesses encrypt data stored in MySQL and secures the most important assets using a combination of keys. For more details, head over to the documentation.
  • MySQL Enterprise Monitor – what’s the use of top-notch security and performance tools when your database infrastructure isn’t even being monitored? The Enterprise Monitor capability will provide you and your business with an easy-to-understand way to manage and monitor what’s happening in your database clusters at any given moment, so you can be sure your data is safe whatever happens. Make sure to head over to MySQL and try the demo of the monitor yourself if you’re considering such an option beforehand, though.

To Recap

This series of MySQL security has gone through some of the aspects to help improve security in the aforementioned RDBMS. Take from these articles what you will, apply general security precautions to all of your MySQL-based architectures, and don’t forget that security is an always-evolving industry. To keep up with the news, make sure to read the documentation, stay around software engineering forums, and read blogs.

I sincerely hope that these two parts on MySQL security have provided you with an understanding of what security issues MySQL engineers face on a daily basis and how to best use them to your advantage. If you haven’t already, come back to the first part of this series, and I will see you in the next blog!

The post Security in MySQL: Part Two appeared first on Simple Talk.



from Simple Talk https://ift.tt/VtpnrGT
via