Found 6705 Articles for Database

How long is the SHA256 hash in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

3K+ Views

As the name “SHA256” suggest, it is 256 bits long. If we are using hexadecimal notation then digit codes represent 4 bits. In order to represent 256, we need 256/4 = 64 bits. We need a data type varchar(64) or char(64). Creating a table for our example. mysql> create table SHA256Demo   -> (   -> Password varchar(64)   -> ); Query OK, 0 rows affected (0.54 sec) Inserting records into table. mysql> insert into SHA256Demo values(' 4e2e1a39dba84a0b5a91043bb0e4dbef23970837'); Query OK, 1 row affected (0.18 sec) Displaying all records. mysql> select *From SHA256Demo; The following ... Read More

WHERE vs HAVING in MySQL?

George John
Updated on 30-Jul-2019 22:30:23

232 Views

We can use a conditional clause called the WHERE Clause to filter out the results. Using this WHERE clause, we can specify a selection criteria to select the required records from a table. The HAVING clause specify filter conditions for a group of rows or aggregates WHERE clause cannot be used with aggregate function while HAVING can be used with aggregate function. The following is an example − Let us now create a table. mysql> create table WhereDemo   -> (   -> Price int   -> ); Query OK, 0 rows affected (0.64 sec) Inserting records into table. ... Read More

What data type to use for hashed password field in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

6K+ Views

The hashed password data type depends upon which hashing algorithm we are using. The hashing algorithm does not depends upon the input size because it produces a result of the same length. It gives the result in a series of hexadecimal digits, and we can reduce the hexadecimal digits by half with the help of UNHEX() function. There are various algorithms and data types to store values. MD5 − It can use char(32) or BINARY(16). SHA-1 − It can use data type char(40) or BINARY(20). Example of MD5 The following is an example − mysql> select MD5('This ... Read More

Passing an array to a query using WHERE clause in MySQL?

George John
Updated on 30-Jul-2019 22:30:23

7K+ Views

We can pass an array with the help of where IN clause. Let us first create a new table for our example. mysql> create table PassingAnArrayDemo   -> (   -> id int,   -> Firstname varchar(100)   -> ); Query OK, 0 rows affected (1.60 sec) Let us now insert records. mysql> insert into PassingAnArrayDemo values(1, 'John'), (2, 'Carol'), (3, 'Smith'), (4, 'Bob'), (5, 'Johnson'), (6, 'David'), (7, 'Sam'), (8, 'Jessica'); Query OK, 8 rows affected (0.32 sec) Records: 8  Duplicates: 0  Warnings: 0 To display all records. mysql> select *from PassingAnArrayDemo; The ... Read More

How should I enable LOAD DATA LOCAL INFILE in my.cnf in MySQL?

Ankith Reddy
Updated on 30-Jul-2019 22:30:23

2K+ Views

We can enable it with the help of the SET command with GLOBAL. The first time, local infile will be off. The following is the syntax. mysql> SHOW GLOBAL VARIABLES LIKE 'local_infile'; Here is the output. +---------------+-------+ | Variable_name | Value | +---------------+-------+ | local_infile  | OFF | +---------------+-------+ 1 row in set (0.01 sec) We can enable the local infile with the help of ON or boolean value true or numeric value 1. The following is the syntax to enable the local infile. mysql> SET GLOBAL local_infile = 'ON'; Query OK, 0 ... Read More

How to prepend a string to a column value in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

5K+ Views

To prepend a string to a column value in MySQL, we can use the function CONCAT. The CONCAT function can be used with UPDATE statement. Creating a table. mysql> create table PrependStringOnCOlumnName   -> (   -> Id int,   -> Name varchar(200)   -> ); Query OK, 0 rows affected (1.35 sec) Inserting some records. mysql> insert into PrependStringOnCOlumnName values(1, 'John'); Query OK, 1 row affected (0.12 sec) mysql> insert into PrependStringOnCOlumnName values(2, 'Carol'); Query OK, 1 row affected (0.18 sec) mysql> insert into PrependStringOnCOlumnName values(3, 'Johnson'); Query OK, 1 row affected (0.45 sec) ... Read More

Get table names using SELECT statement in MySQL?

Chandu yadav
Updated on 30-Jul-2019 22:30:23

7K+ Views

To get table names using SELECT statement, use “information_schema.tables”. Let us see an example, wherein we have a database that contains 3 tables. The syntax to get all table names with the help of SELECT statement. SELECT Table_name as TablesName from information_schema.tables where table_schema = 'yourDatabaseName'; Using database “test”, and applying the above syntax to get the table names using SELECT mysql> use test; Database changed mysql> SELECT Table_name as TablesName from information_schema.tables where table_schema = 'test'; Output with the name of the three tables. +--------------------+ | TablesName ... Read More

MySQL error 1452 - Cannot add or update a child row: a foreign key constraint fails?

Chandu yadav
Updated on 14-Sep-2023 13:45:42

34K+ Views

This error comes whenever we add a foreign key constraint between tables and insert records into the child table. Let us see an example. Creating the child table. mysql> create table ChildDemo -> ( -> id int, -> FKPK int -> ); Query OK, 0 rows affected (0.86 sec) Creating the second table. mysql> create table ParentDemo -> ( -> FKPK int, -> Name varchar(100) -> , -> primary key(FKPK) ... Read More

mysql_fetch_array vs mysql_fetch_assoc vs mysql_fetch_object?

George John
Updated on 30-Jul-2019 22:30:23

2K+ Views

These mysql_* functions are deprecated and other functions are available that gives better security and functionality. Note: As an alternative, use either _assoc or _row though. mysql_fetch_assoc The function returns an associative array of strings that corresponds to the fetched row, or FALSE if there are no more rows. The associativity array tells us about the key value pair, whereas the key tells about any column name and the value tells about the row value. Here we can map the column name as key and value as row. For example. Key is ID and value is corresponding name. ... Read More

How to display all tables in MySQL with InnoDB storage engine?

Arjun Thakur
Updated on 30-Jul-2019 22:30:23

558 Views

To display all table names with ENGINE as InnoDB, implement the following query mysql> SELECT TABLE_SCHEMA as DATABASENAME ,TABLE_NAME as AllTABLENAME ,ENGINE as ENGINETYPE FROM information_schema.TABLES -> WHERE ENGINE = 'innoDB' -> AND TABLE_SCHEMA NOT IN('mysql', 'information_schema', 'performance_schema'); The following is the output. +--------------+------------------------------------------------------------------+------------+ | DATABASENAME | AllTABLENAME ... Read More

Advertisements