AmitDiwan has Published 10744 Articles

Check user rights before attempting to CREATE MySQL DATABASE?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:46:23

185 Views

To display grants, the syntax is as follows −show grants for yourUserName;Let us implement the above syntax in order to check user rights before attempting to create database.Case 1 −This is for current user which is root. Following is the syntax −mysql> show grants for current_user;This will produce the following output ... Read More

How to select from table where conditions are set for id and name in MySQL?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:44:38

2K+ Views

Let us first create a table −mysql> create table DemoTable819(    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(100) ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable819(StudentName) values('Chris'); Query OK, 1 row affected (0.20 sec) mysql> ... Read More

MySQL query to convert YYYY-MM-DD to DD Month, YYYY date format

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:42:25

2K+ Views

Let us first create a table −mysql> create table DemoTable845(AdmissionDate date); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert command −mysql> insert into DemoTable845 values('2018-01-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable845 values('2016-12-12'); Query OK, 1 row affected (0.13 sec) ... Read More

Can we convert MD5 to SHA256 in a MySQL table with user password column?

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:41:35

1K+ Views

Use SHA2() to convert the MD5 password to SHA256. It calculates the SHA-2 family of hash functions i.e. SHA-224, SHA-256, SHA-384, and SHA-512).Let us first create a table −mysql> create table DemoTable818(UserPassword text); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert command −mysql> insert ... Read More

How to display only the column values whose sum is less than 150 in MySQL? Arrange the result in descending order

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:39:54

167 Views

For this, you can use subquery. Let us first create a table −mysql> create table DemoTable844(    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Amount int ); Query OK, 0 rows affected (0.95 sec)Insert some records in the table using insert command −mysql> insert into DemoTable844(Amount) values(80); Query OK, ... Read More

Set value only for NULL values in a MySQL table

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:38:27

182 Views

Use IFNULL to check for NULL values and set a value using the SET command. Let us first create a table −mysql> create table DemoTable817(Value int); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable817 values(10); Query OK, 1 row ... Read More

Display all grants for user in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:34:00

234 Views

Use INFORMATION_SCHEMA.SCHEMA_PRIVILEGES to display all grants for a user −select *from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES;Let us implement the above syntax to show all grants for a user −mysql> select *from INFORMATION_SCHEMA.SCHEMA_PRIVILEGES;This will produce the following output −+-----------------------------+---------------+--------------------+-------------------------+--------------+ | GRANTEE                     | TABLE_CATALOG | TABLE_SCHEMA ... Read More

Set particular value of column without using update and while inserting values in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:18:32

209 Views

Here, we will see an example wherein we are inserting dates and updating them while using the INSERT query.Let us first create a table −mysql> create table DemoTable816(DueDate datetime); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using the insert command. Here is the query to ... Read More

Extract gender values as a string when it is stored in the table as a Boolean in MySQL

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:16:28

431 Views

Let us first create a table −mysql> create table DemoTable815(Gender BOOLEAN); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable815 values(true); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable815 values(false); Query OK, 1 row affected (0.16 sec) ... Read More

Add 30 days to date in a MySQL table with arrival date records

AmitDiwan

AmitDiwan

Updated on 03-Sep-2019 11:12:00

300 Views

Use INTERVAL to update the days for all the dates in a MySQL table column. Let us first create a table −mysql> create table DemoTable814(ArrivalDate date); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable814 values('2018-12-02'); Query OK, 1 row ... Read More

Advertisements