Apple - How to get MySQL's port on Mac through the terminal?
If you have turned on Apache on your Mac and also enabled PHP, you can run the phpinfo()
command which will give you tons of information such as:
Based on what I've read, 3306 is the default, so if you didn't specifically change it, then it's probably that.
You can also use MySQL Workbench from Oracle. When I launch it, it shows:
There are a few options:
You can list the ports that are being "listened on" with netstat
netstat -ap tcp | grep -i "listen"
tcp4 0 0 localhost.4380 *.* LISTEN
tcp4 0 0 localhost.4370 *.* LISTEN
tcp4 0 0 localhost.5945 *.* LISTEN
tcp4 0 0 localhost.25035 *.* LISTEN
(I only run MySQL on VMs so it won't show up on my Mac, but this illustrates the output)
You can also just look and see what port is configured for MySQL to use by examining the /etc/my.cnf
file. Under the [mysqld]
section.
[mysqld]
# Connection and Thread variables
port = 3306
Assuming that mysql is on your $PATH then in the terminal:
mysql server status