25

I use Mysql Workbench to connect my database,[Hostname Port and Username are as shown in figure ,and password is right[1]

Hostname Port and Username are as shown in figure ,and password is right.When I click Test Connection ,it show as above.But if i use 3307 in place of 3306 as port,it connect sucessfully. What matter lead that and how I fix it?

I use macbook pro and I don't know check which my.cnf. I use sudo vim /usr/local/mysql/my.cnf in terminal .
And the my.cnf is as below:

[mysqld] 
 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES            

And I rewite it as below:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=8M 
[mysqldump]
quick 

But it does not work.

shengfu zou
  • 560
  • 1
  • 7
  • 16
  • Is your your `mysql` running on `3307` or `3306` port??? – Darshan Patel Aug 15 '15 at 07:47
  • 1
    please check your mysql configuration `my.cnf` the port should be `port=3306` [https://dev.mysql.com/](https://dev.mysql.com/doc/refman/5.1/en/option-files.html) – ichadhr Aug 15 '15 at 07:47
  • @DarshanPatel yes, it is running – shengfu zou Aug 15 '15 at 07:48
  • 1
    but on which port??? check my.cnf as @ichadhr suggested – Darshan Patel Aug 15 '15 at 07:49
  • @ichadhr I use macbook pro and I don't know check which my.cnf. I use sudo vim /usr/local/mysql/my.cnf in terminal . And the my.cnf is as below: [mysqld] sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES And I rewite it as below: [client] port=3306 socket=/tmp/mysql.sock [mysqld] port=3306 socket=/tmp/mysql.sock key_buffer_size=16M max_allowed_packet=8M [mysqldump] quick But – shengfu zou Aug 15 '15 at 08:20
  • 2
    @Sajad You must be kidding. That is the standard port for an HTTP server. This is a database. – user207421 Aug 15 '15 at 08:39
  • @EJP but I use 3306 successfully before. – shengfu zou Aug 15 '15 at 08:41
  • @shengfuzou you can specify the option file you have created by using the `--defaults-file` parameter. e.g `--defaults-file=[cnf path]` [dev.mysql](http://dev.mysql.com/doc/refman/5.1/en/option-file-options.html) – ichadhr Aug 15 '15 at 09:05
  • @shengfuzou also make sure no other programs running on same port `netstat -lnp | grep 3306` – ichadhr Aug 15 '15 at 09:10
  • @shengpfuzou And what changed since? That's the question. – user207421 Aug 15 '15 at 10:01
  • @EJP I forget, it is long ago. – shengfu zou Aug 15 '15 at 10:05

17 Answers17

42

Steps:

1 - Right click on your task bar -->Start Task Manager

2 - Click on Services button (at bottom).

3 - Search for MYSQL57

4 - Right Click on MYSQL57 --> Start

Now again start your mysql-cmd-prompt or MYSQL WorkBench

Abhishek Singh
  • 421
  • 4
  • 3
7

Open System Preference > MySQL > Initialize Database > Use Legacy Password Encription

Hau Le
  • 121
  • 1
  • 5
7

I had this exact problem after my last windows update and none of the above solutions worked. I know it's an old question, but if anyone has this problem in the future:

I managed to solve it by going to windows control panel > administrative tools > Component Services and finding "MySQL57" in the Services(local) list (I assume your server might have a slightly different name).

There I went to properties by right clicking and changed the Startup Type to Automatic under the General tab. Then I went on the Log On tab and checked "Allow Service to interact with Desktop".

If none of that works, you can try checking the "This account" box and filling both password fields with the root password you set up after installing the server (leave account blank).

I know it's a lot to do and most of these steps must be innefective, but I did it all at once and frankly have no clue which one solved the problem. Good luck I hope it helps.

DatarturoRV
  • 71
  • 1
  • 1
  • This issue if its not your password. Is most certainly that the MySQL80 services is not running. So, that's the one that solves the issue. ...checkout out your services window and start service for MySQL80 – kings Jul 04 '23 at 10:01
6

Try to execute below command in your terminal :

mysql -h localhost -P 3306 -u root -p

If you successfully connect to your database, then same thing has to happen with Mysql Workbench.

If you are unable to connect then I think 3306 port is acquired by another process.

Find which process running on 3306 port. If required, give admin privileges using sudo.

netstat -lnp | grep 3306

Kill/stop that process and restart your MySQL server. You are good to go.


Execute below command to find my.cnf file in macbook.

mysql --help | grep cnf

You can change MySQL port to any available port in your system. But after that, make sure you restart MySQL server.

Darshan Patel
  • 2,839
  • 2
  • 25
  • 38
  • I use your command and show as below : ` order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf ` I check the four file ,and all then are empty.Why and what to do for me? – shengfu zou Aug 15 '15 at 08:53
  • I use mysql -h localhost -P 3306 -u root -p to connect , but it show Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) I use mysql --help | grep cnf it show nothing. – shengfu zou Aug 15 '15 at 09:38
  • then use `netstat` commnad to find out which process is running for port `3306` and also execute `mysql -h localhost -P 3307 -u root -p`. If you got success with 3307 then your MySQL server is running on 3307 port. – Darshan Patel Aug 15 '15 at 09:59
  • This works well on PC, but the command is : netstat -a -n -o ... on the command line (you may need admin privs) ... and then take the PID from the last column and look it up on the details pane of Task Manager (CTL+SHIFT+ESC) I was able to determine that yes, MySql is on that port ... Sadly, that doesn't mean that I actually solved the problem, but it's a great diagnostic step. ++ – Sean Munson Nov 19 '18 at 16:55
  • 1
    This worked for CLI but I still can't connect in workbench. What might my issue be? – Daniel C Jacobs May 04 '20 at 23:08
  • Check port is open or not if you are using AWS. Another possible configuration you might check similar to this https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql – Darshan Patel May 05 '20 at 09:00
3

It worked for me this way:

Step1: Open System Preference > MySQL > Initialize Database.

Step2: Put password you used while installing MySQL.

Step3: Start MySQL server.

Step4: Come back to MySQL Workbench and double connect/ create a new one.

iminiki
  • 2,549
  • 12
  • 35
  • 45
2

Go to system preferences, then "MySQL"

Click on "Start MySQL Server"

Go to system preferences, then "MySQL". Click on "Start MySQL Server".

almawhoob
  • 382
  • 3
  • 5
2

On window, work for me.

1 - Open "Service"

2 - Search for MYSQL

3 - Right Click on MYSQL80 --> Start

Hope it work in your MySQL Workbench

Thank you!!!

enter image description here

cng.buff
  • 405
  • 4
  • 5
1

MySQL default port is 3306 but it may be unavailable for some reasons, try to restart your machine. Also sesrch for your MySQL configuration file (should be called "my.cnf") and check if the used port is 3306 or 3307, if is 3307 you can change it to 3306 and then reboot your MySQL server.

J0ker98
  • 447
  • 5
  • 18
1

Go to >system preferences >mysql >initialize database

-Change password -Click use legacy password -Click start sql server

it should work now

1

I re-downloaded many times and found out it's so simple!

THERE ARE TWO DOWNLOADS NEEDED

1. SQL Community Server https://dev.mysql.com/downloads/mysql/ This is what shows up in "System Preferences" and allows you to start the instance!

2. MYSQL Workbench https://dev.mysql.com/downloads/workbench/ This is what you're trying to fix.. Once the Instance is on you can successfully connect :)

(for macOS system users)

0

At rigth side in Navigator -> Instance-> Click on Startup/Shutdown -> Click on Start Server

It will work surely

0
  1. go to apple icon on the top left corn and click "System Preference"

  2. find "Mysql" at the bottom and click it

  3. "start Mysql server"

Haris Bouchlis
  • 2,366
  • 1
  • 20
  • 35
Yan Xu
  • 11
  • 3
0

It failed because there is no server install on your computer. You need to Download 'MySQL Community Server 8.0.17' & restart your server.

Jackie Santana
  • 1,290
  • 14
  • 15
0
  1. set root user to mysql_native_password

$ sudo mysql -u root -p # I had to use "sudo" since is new installation

mysql:~ USE mysql;
mysql:~ SELECT User, Host, plugin FROM mysql.user;
mysql:~ UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql:~ FLUSH PRIVILEGES;
mysql:~ exit;

$ service mysql restart

Dime
  • 1
0

I got the same problem on MACOS. I did the following. Make sure MySQL Server is installed.

  1. Command + Space -> Type mysql. Open the option mysql.prefPane
  2. Click on the button Stop MySQL Server. Let the server stop.
  3. Click on Initialize Database button
  4. A new Popup will open. Type the password you want for root user.
  5. Once the password is long enough, OK button will get enabled. Click on OK button
  6. Do Test Connection from MySQL WorkBench and enter the password you set in above step. It should work.
0

For those of you getting this on an SQL Server container on docker, when you do the run command, be sure you put -p 3306:3306 so for example, my run command looks like docker run --name test-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=your_password -d mysql

nak
  • 1
-1

in my.ini check option skip-networking under [mysqld]. It should be off.

[mysqld]
skip-networking = OFF
  • 1
    see: https://superuser.com/questions/578678/mysql-cant-turn-off-skip-networking. The `= OFF` is not needed, this is default and `skip-networking` is also not needed because default this option is disabled (see: [skip-networking](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_skip_networking) ) – Luuk Mar 04 '23 at 16:02
  • When I install maria db I turned off this feature and got this problem. When I look in doc - I found this valiarble and after look in my ini and found it with ON value. – MrKirill1232 Mar 04 '23 at 16:44
  • The linke `skip-networking` does not need not exist, when you need network access to MySQL. There is only a need for adding `skip-networking` when you set it to `ON` (or `1`) – Luuk Mar 04 '23 at 16:51