I was trying to execute script in mysql from server level, was stuck at displaying hostname in output file. Many of you must have faced similar situation, here are different ways to achieve the same.
I have listed number of methods for the displaying hostname/server name while logged in mysql database but please note that this is not the limit, you can discover number of ways to do the same
I have listed number of methods for the displaying hostname/server name while logged in mysql database but please note that this is not the limit, you can discover number of ways to do the same
- select hostname as variable
mysql> show variables like 'hostname';
+---------------+----------------------------+
| Variable_name | Value
|
+---------------+----------------------------+
| hostname | testsrv5215 |
+---------------+----------------------------+
1 row in set (0.00 sec)
- Pulling data from information_schema.global_variables into a user defined variable and displaying its value
mysql> SELECT variable_value INTO
@local_hostname
-> FROM
information_schema.global_variables
-> WHERE variable_name =
'hostname';
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql>
mysql> select @local_hostname;
+----------------------------+
| @local_hostname
|
+----------------------------+
| testsrv5215 |
+----------------------------+
1 row in set (0.00 sec)
- Same method as above with small query
mysql> select @@hostname into
@local_hostname;
Query OK, 1 row affected (0.00 sec)
mysql> select @local_hostname;
+----------------------------+
| @local_hostname
|
+----------------------------+
| testsrv5215 |
+----------------------------+
1 row in set (0.00 sec)
mysql>
- select , assigning and displaying hostname in single step
mysql> SELECT @@hostname hostname;
+----------------------------+
| hostname
|
+----------------------------+
| testsrv5215 |
+----------------------------+
1 row in set (0.00 sec)
Feel free to comment or give feedback