mysql> show variables like 'hostname';
+---------------+--------------+
| Variable_name | Value |
+---------------+--------------+
| hostname | LW-REDWARDS2 |
+---------------+--------------+
1 row in set (0.00 sec)
mysql>
这适用于 MySQL 5.x
SELECT variable_value INTO @local_hostname
FROM information_schema.global_variables
WHERE variable_name = 'hostname';
查询直接在 mysql 客户端中工作:
mysql> SELECT variable_value INTO @local_hostname
-> FROM information_schema.global_variables
-> WHERE variable_name = 'hostname';
Query OK, 1 row affected (0.00 sec)
mysql> select @local_hostname;
+-----------------+
| @local_hostname |
+-----------------+
| LW-REDWARDS2 |
+-----------------+
1 row in set (0.00 sec)
mysql>
这是我在 PC 上的 MySQL 5.5.12 中编写的快速 SP
DELIMITER $$
DROP PROCEDURE IF EXISTS `junk`.`ShowHostName` $$
CREATE PROCEDURE `junk`.`ShowHostName` ()
BEGIN
SELECT variable_value INTO @local_hostname
FROM information_schema.global_variables
WHERE variable_name = 'hostname';
SELECT @local_hostname;
END $$
DELIMITER ;
DELIMITER $$
DROP FUNCTION IF EXISTS `junk`.`GetHostName` $$
CREATE FUNCTION `junk`.`GetHostName` () RETURNS VARCHAR(64)
DETERMINISTIC
BEGIN
DECLARE local_hostname VARCHAR(64);
SELECT variable_value INTO local_hostname
FROM information_schema.global_variables
WHERE variable_name = 'hostname';
RETURN local_hostname;
END $$
DELIMITER ;
现在,只需选择它:
mysql> SELECT junk.GetHostName();
+--------------------+
| junk.GetHostName() |
+--------------------+
| LW-REDWARDS2 |
+--------------------+
1 row in set (0.00 sec)
mysql>
我可以在我的电脑上看到我的主机名
这适用于 MySQL 5.x
查询直接在 mysql 客户端中工作:
这是我在 PC 上的 MySQL 5.5.12 中编写的快速 SP
然后运行
CALL junk.ShowHostName();
这是一个函数
现在,只需选择它:
试试看 !!!
怎么样: