Found 4219 Articles for MySQLi

Show MySQL host via SQL Command?

George John
Updated on 14-Sep-2023 21:09:02

27K+ Views

To display MySQL host via SQL command, use system variable "hostname".The following is the query to display the host −mysql> select @@hostname;Here is the output −+-----------------+ | @@hostname | +-----------------+ | DESKTOP-QN2RB3H | +-----------------+ 1 row in set (0.00 sec)Or you can use "show variables" command to show MySQL host via SQL command.show variables where Variable_name like '%host%';The following is the output −+-------------------------------+-----------------+ | Variable_name                 | Value           | +-------------------------------+-----------------+ | host_cache_size               | 279             | | hostname                      | DESKTOP-QN2RB3H | | performance_schema_hosts_size | -1 | | report_host                 | | +-------------------------------+-----------------+ 4 rows in set (0.07 sec)

Which rows are returned while using LIMIT with OFFSET in MySQL?

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

248 Views

Suppose the LIMIT is 4 and OFFSET is 6 then it will return the rows from 7 to 10 i.e. will end with row 10. The LIMIT 4 and OFFSET 6 returns row 7, 8, 9, 10.You can understand the above concept by implementing LIMIT and OFFSET. Let us create a table.mysql> create table LimitOffsettable -> ( -> Id int -> ); Query OK, 0 rows affected (0.60 sec)Let us insert some records in the table. The query is as follows −Mysql> insert into LimitOffsettable values(1); Query OK, 1 row affected ... Read More

Is there a MySQL command to convert a string to lowercase?

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

8K+ Views

Yes, you can use the LOWER() or LCASE() from MySQL to convert a string to lowercase. Both methods can be used to convert the string into lowercase.Here is the syntax of LOWER() −lower(‘yourStringValue);Or you can use LCASE().The syntax is as follows −lcase(‘yourStringValue);Let us see an example of LOWER(). The query is as follows −mysql> select lower('JOhN');Here is the output −+---------------+ | lower('JOhN') | +---------------+ | john | +---------------+ 1 row in set (0.00 sec)Let us see an example of LCASE(). The query is as follows −mysql> select lcase('JOhN');The following is the ... Read More

MySQL - Insert current date/time?

Chandu yadav
Updated on 02-Sep-2023 15:55:56

47K+ Views

To insert only date value, use curdate() in MySQL. With that, if you want to get the entire datetime, then you can use now() method.Let us first create a table −mysql> create table CurDateDemo -> ( -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.74 sec)Now you can insert only date with the help of curdate() method −mysql> insert into CurDateDemo values(curdate()); Query OK, 1 row affected (0.15 sec)Display the inserted date with the help of select statement. The query is as follows −mysql> select *from CurDateDemo;Here is the ... Read More

How do I show a MySQL warning that just happened?

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

287 Views

To show a MySQL warning, you can use the below syntax −SHOW WARNINGS;The above syntax only displays the immediate warning from MySQL prompt. Suppose you run another query between them or you have lost the MySQL connection, then SHOW WARNINGS will not work.Here is the query to display warnings −mysql> SHOW WARNINGS;Here is the output that displays immediate warning −+-------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Level | Code | Message ... Read More

How to subtract 30 days from the current datetime in MySQL?

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

4K+ Views

To subtract 30 days from current datetime, first we need to get the information about current date time, then use the now() method from MySQL. The now() gives the current date time.The method to be used for this is DATE_SUB() from MySQL. Here is the syntax to subtract 30 days from current datetime.The syntax is as follows −DATE_SUB(NOW(), INTERVAL 30 DAY);The above syntax calculates the current datetime first and in the next step, subtracts 30 days. Let us first seethe query to get the current datetime −mysql> select now();Here is the output −+---------------------+ | now() ... Read More

What is the best way to display in Terminal a MySQL SELECT returning too many fields?

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

106 Views

To achieve this, you can use the following syntax in MySQL −select *from yourTableName\G;Here, G can be used for vertical purpose. You need to add yourTableName.Let us create a table in order to understand the above syntax. Creating a table with the help of CREATE command.The following is the query to create a table −mysql> create table TooManyFieldsreturnDemo -> ( -> Id int, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (0.64 sec)Now you can insert records in the table ... Read More

How can I stop a running MySQL query?

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

495 Views

In order to stop a running MySQL query, we can use the KILL command with process id. The syntax is as follows −kill processId;Or you can stop a running MySQL query with the help of below syntax −call mysql.rds_kill(queryId);Let us first get the processId with the help of show command. The query is as follows −mysql> show processlist;Here is the output with the list of processes −+----+-----------------+-----------------+----------+---------+--------+------------------------+------------------+ | Id |  User           | Host            | db       | Command | Time   | State           ... Read More

MySQL: selecting rows where a column is null?

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

2K+ Views

To select rows where a column is null, you can use IS NULL from MySQL with the help of where clause.The syntax is as follows −select *from yourTableName where yourColumnName IS NULL;Let us first create a table to understand the concept −mysql> create table NULLDemo1 -> ( -> StudentId int, -> StudentName varchar(100) -> ); Query OK, 0 rows affected (1.48 sec)Inserting records into the table. The query to insert records is as follows −mysql> insert into NULLDemo1 values(NULL, 'John'); Query OK, 1 row affected (0.25 sec) mysql> ... Read More

What does “unsigned” in MySQL mean and when to use it?

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

11K+ Views

The “unsigned” in MySQL is a data type. Whenever we write an unsigned to any column that means you cannot insert negative numbers. Suppose, for a very large number you can use unsigned type.The maximum range with unsigned int is 4294967295.Note: If you insert negative value you will get a MySQL error.Here is the example demo of unsigned type. Let us first create a table with “unsigned” column. The following is the query to create a table −mysql> create table UnsignedDemoWithPositiveValue -> ( -> Distance int unsigned -> ); Query OK, ... Read More

Advertisements