How to connect from windows command prompt to mysq

2019-01-21 16:38发布

I'm trying to connect to mysql server command line from my windows prompt

I write the next line in cmd but i get an error.

cd C:\MYSQL\bin\

And then i execute

mysql.exe -u=root -p=admin

but i getting this error

ERROR 1045: <28000>: Access denied for user 'root'@'localhost' <using password:YES>

Thanks,

14条回答
Summer. ? 凉城
2楼-- · 2019-01-21 16:56

You are logging in incorrectly; you should not include = in your login. So to log in, type:

mysql.exe -uroot -padmin

If that doesn't work, then you may not have your system configured. If so, then here's a good tutorial on getting started with the MySQL prompt: http://breakdesign.blogspot.com/2007/11/getting-started-with-php-and-mysql-in_11.html

查看更多
ら.Afraid
3楼-- · 2019-01-21 16:57

Your have to go on mysql installed path is on drive C:, then your commands need to be:

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql.exe -u root -p

OR

C:\>cd \MYSQL\Bin
C:\MYSQL\Bin>mysql -u root -p

That will ask your MySql password over command prompt:

Enter password: ******

Put the password and you will get mysql dashboard.

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4622
Server version: 5.7.14-log MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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>
查看更多
叼着烟拽天下
4楼-- · 2019-01-21 17:00

Go to your MySQL directory. As in my case its...

cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysql -uroot -p

root can be changed to your user whatever MySQL user you've set.

It will ask for your password. If you have a password, Type your password and press "Enter", If no password set just press Enter without typing. You will be connected to MySQL.

There is another way to directly connect to MySQL without every time, going to the directory and typing down the commands.

Create a .bat file. First, add your path to MySQL. In my case it was,

cd C:\Program Files\MySQL\MySQL Server 8.0\bin

Then add these two lines

net start MySQL 
mysql -u root -p

If you don't want to type password every time you can simply add password with -p e.g. -proot (in case root was the password) but that is not recommended.

Also, If you want to connect to other host than local (staging/production server). You can also add -h22.345.80.09 E.g. 22.345.80.09 is your server ip.

net start MySQL 
mysql -u root -p -h22.345.80.0

Save the file. Just double click to open and connect directly to MySQL.

查看更多
你好瞎i
5楼-- · 2019-01-21 17:03

Use this :

mysql -u user_name -p  then press_enter_key

then type password

i.e.

line-1 : mysql -u root -p

line-2 : admin
查看更多
我命由我不由天
6楼-- · 2019-01-21 17:04

first type cmd then the windows command prompt will appear:

PATH C:\XAMPP\MYSQL\BIN;%PATH%;
mysql -u root -p

where:

  • -u is the user id
  • -p is the password, if you will not using a password just leave it blank.
查看更多
放我归山
7楼-- · 2019-01-21 17:04
  1. Start your MySQL server service from MySQL home directory. Your one is C:\MYSQL\bin\ so choose this directory in command line and type: NET START MySQL
    (After that you can open Windows Task Manager and verify in Processes tab is mysqld.exe process running. Maybe your problem is here.)
  2. Type: mysql -u user -p [pressEnter]
  3. Type your password [pressEnter]

or make a start.bat file:

  1. add C:\MYSQL\bin\ to your PATH
  2. write a start.bat file
  3. My start.bat file has only two lines like below:
    net start MySQL
    mysql -u root -p

Good luck!

P.S.This is an answer from Poland.My president Lech Kaczyński was murdered 10.04.2010 in Smoleńsk. You need to know about this. Please read about it in the net.

查看更多
登录 后发表回答