Difference between Stored procedure and Function in SQL

Following are the main differences between Stored procedure and Function in SQL.

Continue reading Difference between Stored procedure and Function in SQL

Stored Procedure Function
Stored procedure may or may not return values A Function must return a value
Stored procedures can have input/output parameters Functions can have only input parameters
Stored Procedure may take 0 to n input parameters For a Function it is mandatory to take one input parameter

What is the difference between union and join

Following are the differences between union and join in relational database engines.
A union returns the results of two different queries as a single recordset and A join allows you to relate similar data in different tables.

UNION JOIN
UNION puts lines from queries after each other, JOIN makes a cartesian product and subsets it
Union Operation is combined result of the Vertical Aggregate of the rows JOIN Operation is combined result of the Horizontal Aggregate of the Columns
Union combines rows JOIN links the rows
Performed only on two similar structures Performed only on two dissimilar structures also
A union returns the results of two different queries as a single recordset. A join allows you to relate similar data in different tables.

Visual depiction of a join. Table A and B’s columns are combined into a single result:

Continue reading What is the difference between union and join

How to count the number of emails per domain in PostgreSQL MySQL Oracle

In this article, we will see how to count the number of emails per domain, we can use the following query in SQL Server or PostgreSQL or MySQL or Oracle or any RDBMS:

To count the number of emails per domain in PostgreSQL MySQL Oracle:

SELECT SUBSTRING( email, CHARINDEX('@', email)+1, LEN(email)-CHARINDEX('@', email) ) domain_name, COUNT(email) emails_count FROM sales.customers GROUP BY SUBSTRING( email, CHARINDEX('@', email)+1, LEN(email)-CHARINDEX('@', email) );

Continue reading How to count the number of emails per domain in PostgreSQL MySQL Oracle

How to connect to MySQL using Python on Linux

In this article, we will see how to connect to MySQL using Python on Linux.In this article, we will connect to MySQL Server from python using mysql-connector. Connect to Python contains below steps.

1. Install mysql connector.
2. Create connection variable in python script file.
3. Execute command on MySQL Server using python script file.

Connection to MySQL using Python Steps:

Step1: Install mysql connector.
Continue reading How to connect to MySQL using Python on Linux

How to connect to MySQL using Python on Windows

In this article, we will see how to connect to MySQL using Python on Windows. In this article, we will connect to MySQL Server from python using mysql-connector. Connect to Python contains below steps.

1. Install mysql connector.
2. Create connection variable in python script file.
3. Execute command on MySQL Server using python script file.

Connection to MySQL using Python Steps:

Step1: Install mysql connector.
Continue reading How to connect to MySQL using Python on Windows

Authentication plugin ‘caching_sha2_password’ is not supported

Below error occurred when connecting to mysql server from python.

mysql.connector.errors.NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported

Reason:
In MySQL 8.0, caching_sha2_password is the default authentication plugin rather than mysql_native_password.

Continue reading Authentication plugin ‘caching_sha2_password’ is not supported

ModuleNotFoundError: No module named ‘mysql’

When I tried to connect to MySQL from Python received below error.

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'mysql'

Reason:

We have to install mysql connector or corresponding mysql connector for Python version.

Continue reading ModuleNotFoundError: No module named ‘mysql’

How to change MySQL root password in Linux

In this article, we will see how to change MySQL root password in Linux. We can change the password with multiple methods, below are the few of them.

1. Update root user password using SET method:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD("admin@123"); flush privileges;

Continue reading How to change MySQL root password in Linux

ERROR 1698 (28000): Access denied for user root

This problem occurs from the mysql versions 5.7.+ on wards.
ERROR 1698 (28000): Access denied for user ‘root’@’localhost’.

1. It is because MySql 5.7 by default allow to connect with socket, which means you just connect with sudo mysql

use mysql;

2. Run the following select statement:

SELECT user,authentication_string,plugin,host FROM mysql.user;

Continue reading ERROR 1698 (28000): Access denied for user root

How to install MySQL on Ubuntu

In this article, we have explained how to install MySQL on Ubuntu Server. This article contains 4 steps.

Install MySQL on Ubuntu:

Prerequisites:
1. Must have internet conneciton.
2. Make sure you are logged in as a user with sudo privileges

1. Update Index Package:

sudo apt-get update

Continue reading How to install MySQL on Ubuntu