Reputation: 23322
I'm following Vogella's tutorial on MySQL and I'm hitting a brick wall when I try to imitate the example. I've installed MySQL, and as he instructs I run it from the command line. When I do so, I get this error:
C:\Program Files (x86)\MySQL\MySQL Workbench CE 6.0.9>mysql -u root -p
Enter password: ******
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
C:\Program Files (x86)\MySQL\MySQL Workbench CE 6.0.9>
Does anyone know why?
Upvotes: 1
Views: 46738
Reputation: 11
Before running the command:
mysql -u user_name -p
There are few steps to take.
Assuming you don't have XAMPP
installed
Approach 1
Navigate to bin
folder of MySQL.
cd 'C:\Program Files\MySQL\MySQL Server 8.0\bin'
NOTE: Check for the version of MySQL Server
on your machine. To do this, run:
cd 'C:\Program Files\MySQL\'
ls
You'll see the version installed, then navigate to the bin
folder. It will look like this:
cd 'MySQL Server 8.0\bin'
Then run the command:
mysqld -u root -p
mysql -u root -p
This should take you into MySQL Shell.
Approach 2
To make it easier to invoke MySQL program anywhere in the terminal, add MySQL bin directory path to the Windows system PATH environment variable. Visit MySQL documentation
Now, MySQL command can be run from anywhere using git bash
.
If you have XAMPP
installed, start MySQL associated with it
Navigate to its directory:
cd 'C:\xampp\mysql\bin'
Then try the command:
mysqld -u root -p
mysql -u root -p
This should take you inside MySQL Shell.
If it does'nt work, start MySQL from the
XAMPP
Control Panel and run:
mysql -u root -p
It worked! Exit the Shell:
\q
Upvotes: 1
Reputation: 69
I got the same error, I started MySQL server with the below command as an administrator in one cmd window and then tried connecting mysql in another cmd window, it worked !!
cmd window 1: C:\Program Files\MySQL\MySQL Server 8.0\bin>mysqld
cmd window 2: C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p Enter password: ************ Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.26
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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>
Upvotes: 1
Reputation: 1169
Open the Xampp control panel and start the mysql module. For wamp, do the same. This is the simplest ever solution I've got !
Upvotes: 1
Reputation: 764
The solution is very simple. The problem is the mysql service is not started. So we first need to start the mysql service before 'mysql -u user_name -p' command. To do that, navigate to 'bin' folder of mysql in command prompt. E.g:
C:\Program Files\MySQL\MySQL Server 5.7\bin>
In your case probably,
C:\Program Files (x86)\MySQL\MySQL Workbench CE 6.0.9\bin>
or
C:\Program Files (x86)\MySQL\bin>
or
If you have XAMPP installed, then to start mysql associated with it, navigate to
C:\xampp\mysql\bin>
then type the command mysqld -u root -p
It will output:
'2017-04-04 13:40:27 8536 [Note] mysqld (mysqld 10.1.21-MariaDB) starting as process 5640 ...'
This shows mysql is started.
Now type your command mysql -u root -p
, it will work for sure.
Upvotes: 10
Reputation: 4533
Go to Start->Run and type services.msc. That's how you get to windows services window. Look for MySQL Server, Right Click, Start Service.
You could also get to Windows Services Window by Start -> Control Panel -> Administrative Tools -> Services
If there's no such service MySQL Server, then install MySQL Server from here https://dev.mysql.com/downloads/mysql/
Upvotes: 0
Reputation: 11
try restarting the MYSQL app in the XAMPP control panel. It worked for me. Good luck!
Upvotes: 1