对于某些人来说,一种更简单的方法是: 如果您只是想检查 MySQL 是否在某个端口上,那么您可以在终端中使用以下命令。在 Mac 上测试。3306是默认端口。
mysql --host=127.0.0.1 --port=3306
如果您成功地登录到 MySQL shell 终端,那么就很好!这是我在成功登录时获得的输出。
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9559
Server version: 5.6.21 Homebrew
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
$ mysql -u root@localhost -e "SHOW GLOBAL VARIABLES LIKE 'PORT';"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+