5

I started MySQL with its PrefPane in System Preferences:

enter image description here

When I enter ps aux | grep mysql I get the following output:

ldl              33675   0.0  0.0  2432804    772 s003  S+   11:01上午   0:00.00 grep mysql
_mysql           33474   0.0  0.1  2829668   8108   ??  Ss   10:55上午   0:00.54 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid

But how do I know which port MySQL is using on my Mac? Entering lsof -i tcp:3306 I find nothing.

5
  • What do the installation instructions say? Did you try to just run a client and see whether it can connect?
    – nohillside
    Commented Aug 17, 2017 at 4:09
  • If you disallow network access to mysql either from your local or a remote host no ports are opened and only the socket file is used.
    – klanomath
    Commented Aug 17, 2017 at 4:10
  • @patrix To be honest, I forget the MySQL's password, if I don't know the place of it, I can not change the password.
    – aircraft
    Commented Aug 17, 2017 at 4:11
  • How is resetting the password related to knowing the port? Which instructions on password reset are you following?
    – nohillside
    Commented Aug 17, 2017 at 4:30
  • If you don't know the password, you won't be able to connect. By default, MySQL doesn't allow any access except from localhost. You will need to reset the password and create users that can access MySQL over the network.
    – Allan
    Commented Aug 17, 2017 at 12:36

3 Answers 3

4

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
6

Assuming that mysql is on your $PATH then in the terminal:

mysql server status
3

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:

phpinfo() info about mysqli

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:

MySQL port shown here

2
  • The Mac (Unix) should have the method to check the port.
    – aircraft
    Commented Aug 17, 2017 at 7:36
  • 1
    if you just want to know the port, then I've given you two options. If you want a command-line way to get that information, then you might want to rephrase your question to focus on that element of your question. Commented Aug 17, 2017 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .