1
votes

I want to connect to a local MySQL database with PhpStorm. But there is an error occurs:

Connection to MySQL - @localhost failed. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.

I tried to check if mysql service is running or not.

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-07-28 11:26:31 CDT; 24min ago
  Process: 9809 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
  Process: 9772 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
 Main PID: 9811 (mysqld)
    Tasks: 29 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─9811 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

And appears to be active.

Then I tried to check port listening status with netstat cmd.

netstat -tlnpo

I find the port 3306 is listened by an unknown program.

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name     Timer

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -                    off (0.00/0/0)

But when I tried isof, there seems no program listening port 3306:

lsof -i:3306

So I begin to wonder if port 3306 is occupied by some other program, so I changed the port of MySQL to 3307 and restart MySQL. Then I found that the unknown program is also reset to 3307. By far, I can make sure that unknown program is MySQL.

I really need help on this problem.

1

1 Answers

0
votes

Looking at the information you provided, it appears that you are trying to connect to @localhost within PhpStorm. Have you tried connecting to @127.0.0.1?

If you start a mysql shell and issue the command SHOW GLOBAL VARIABLES LIKE 'PORT'; at the mysql> prompt you can confirm your port.

It could also be that the driver in PhpStorm is out of date. You can check if there is an update by going to the Database panel, clicking the + icon and selecting Driver from the menu.