Found 4220 Articles for MySQLi

Is it necessary to select the database each time we begin a MySQL session?How can it be done?

Ayyan
Updated on 28-Jan-2020 10:23:55

57 Views

The database is created only once but it is necessary to select it each time we begin a MySQLsession. It can be done with the help of USE db_name statement on MySQL command line tool.mysql> Use Query; Database changedIt shows that we are now using query database.We can also select the database while invoking the MySQL from Windows command line. It can be done with the help of the following command −C:\Program Files\MySQL\bin>mysql -u root -p query Enter password: *****Here, query is the name of the database we are going to use for current MySQL sessionRead More

Are MySQL database and table names case-sensitive?

Monica Mona
Updated on 30-Jul-2019 22:30:21

749 Views

Actually, the case sensitivity of database and table name depends a lot on the case sensitivity of the underlying operating system. Hence, we can say that such names are not case sensitive in Windows but are case sensitive in most varieties of Unix.

How can we display a list of currently existing MySQL databases on the server?

Chandu yadav
Updated on 28-Jan-2020 10:24:46

64 Views

The SHOW DATABASES command is used to display the list of currently existing MySQL databases.mysql> Show Databases; +-----------------------------+ | Database                    | +-----------------------------+ | information_schema          | | gaurav                      | | mysql                       | | performance_schema          | | query                       | | query1                      | | sys                         | | tutorials                   | +-----------------------------+ 8 rows in set (0.02 sec)

What kind of output is produced by UNIX_TIMESTAMP() function?

Giri Raju
Updated on 28-Jan-2020 10:25:19

74 Views

The function UNIX_TIMESTAMP produce the output in seconds i.e this function will convert the specified date or datetime value into a total number of seconds.For example, the date ‘1970-05-15 05:04:30’ would be converted to total 11576070 seconds by UNIX_TIMESTAMP function.mysql> select UNIX_TIMESTAMP('1970-05-15 05:04:30'); +---------------------------------------+ | UNIX_TIMESTAMP('1970-05-15 05:04:30') | +---------------------------------------+ | 11576070                              | +---------------------------------------+ 1 row in set (0.09 sec)

How can we create our own choice MySQL database?

Anjana
Updated on 28-Jan-2020 10:28:48

84 Views

CREATE DATABASE db_name can be used to create our own choice MySQL database. For example to create a database named Sample, we should have to run the command as follows −mysql> CREATE DATABASE Sample; Query OK, 1 row affected (0.04 sec)

How can I store ‘0000-00-00’ as a date in MySQL?

Anvi Jain
Updated on 28-Jan-2020 10:31:35

1K+ Views

For storing the date like ‘0000-00-00’ in a column of MySQL table, we must have to set the SQL mode to ‘allow_invalid_date’. Following example will demonstrate it −mysql> SET sql_mode = 'allow_invalid_dates'; Query OK, 0 rows affected, 1 warning (0.03 sec) mysql> Create table test_date(date_order date); Query OK, 0 rows affected (0.45 sec) mysql> Insert into test_date(date_order) values('0000-00-00'); Query OK, 1 row affected (0.04 sec) mysql> Select * from test_date; +------------+ | date_order | +------------+ | 0000-00-00 | +------------+ 1 row in set (0.00 sec)

What is the difference between YEAR(2) and YEAR(4) in MySQL?

Sreemaha
Updated on 19-Jun-2020 13:41:15

438 Views

YEAR(2) stores a year in 2-digit format. For example, we can write 69 to store 1969 a year. In YEAR (2), the year can be specified from 1970 to 2069 (70 to 69).YEAR(4) stores a year in 4-digit format. For example, we need to write 19669 to store 1969 as a year. In YEAR (4), the year can be specified from 1901 to 2155.MySQL interprets 2-digit year values with the assistance of following rules:Year values within the vary 00-69 are converted to 2000-2069.Year values in the range 70-99 are converted to 1970-1999.We must not store date values as a 2-digit ... Read More

In MYSQL, how can we store a date where the day, month or both month & day are zero?day are zero?

Nitya Raut
Updated on 28-Jan-2020 10:34:35

216 Views

To store such kind of dates where the day, month or both month & day are zero we must have to set mode of sql to allow_invalid_dates mode.mysql> set sql_mode = 'allow_invalid_dates'; Query OK, 0 rows affected (0.00 sec) mysql> insert into check_date(OrderDate) values('2017-00-00'); Query OK, 1 row affected (0.06 sec) mysql> select * from check_date; +-------------+ | OrderDate | +-------------+ | 2017-00-00 | +-------------+ 1 row in set (0.00 sec)Above query will insert the date in which both month & day values are zero.mysql> insert into check_date(Orderdate) values ('2017-00-05'); Query OK, 1 row affected (0.07 sec) ... Read More

How can I calculate full 24hour days between two specified dates in MySQL?

varma
Updated on 28-Jan-2020 10:35:33

166 Views

In DATEDIFF() function only the date parts of the values are used in calculation hence we can use TIMESTAMPDIFF() function to calculate full 24 hour days between two specified dates.For example, if we want to find full 24hour days between ‘2017-05-27 11:59:00’ and 2017-05-23 12:00:00’ then following would be MySQL query −mysql> Select TIMESTAMPDIFF(DAY, '2017-05-23 12:00:00' , '2017-05-27 11:59:00'); +---------------------------------------------------------------------------+ | TIMESTAMPDIFF(DAY, '2017-05-23 12:00:00' , '2017-05-27 11:59:00')         | +---------------------------------------------------------------------------+ | 3                                                                         | +---------------------------------------------------------------------------+ 1 row in set (0.00 sec)

What is the way to find business days between two specified dates in MySQL?

Jennifer Nicholas
Updated on 28-Jan-2020 10:00:44

607 Views

With the help of DATEDIFF(expr1, expr2) we can find the business days between two specified dates.For example, if we want to find business days between ‘2017-05-27’ and ‘2017-05-23’ then following would be MySQL query −mysql> Select DATEDIFF('2017-05-27','2017-05-23') AS 'Total Business Days'; +----------------------+ | Total Business Days  | +----------------------+ | 4                    | +----------------------+ 1 row in set (0.00 sec)

Advertisements