如何从 Windows 命令提示符连接到 mysql 命令行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13752424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect from windows command prompt to mysql command line
提问by Washu
I'm trying to connect to mysql server command line from my windows prompt
我正在尝试从 Windows 提示符连接到 mysql 服务器命令行
I write the next line in cmd but i get an error.
我在 cmd 中写下一行,但出现错误。
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,
谢谢,
回答by Ken White
The cd
in your question is invalid (quoting it here because you've removed it once, and it was there when this answer was posted):
在cd
你的问题中是无效的(在这里引用它,因为你一旦删除它,它是当这个答案被张贴那里):
cd CD:\MYSQL\bin\
You can't cd
to CD:\
anything, because CD:\
isn't a valid directory in Windows. CD:
would indicate a drive, except that drives are restricted to a single letter between A
and Z
.
你不能cd
做CD:\
任何事情,因为CD:\
它不是 Windows 中的有效目录。CD:
将表示一个驱动器,但驱动器仅限于A
和之间的单个字母Z
。
If your \MYSQL\BIN
is on drive C:
, then your commands need to be:
如果您\MYSQL\BIN
在 drive 上C:
,那么您的命令需要是:
C:\>cd \MYSQL\Bin
C:\MYSQL\Bin>mysql -u root -p admin
If you're not already on C:
(which you'll know by looking at the prompt in the cmd window), or your MySQL folder is on another drive (for instance, D:
), change to that drive too:
如果您还没有打开C:
(通过查看 cmd 窗口中的提示您会知道),或者您的 MySQL 文件夹在另一个驱动器上(例如,D:
),也更改到该驱动器:
C:\> cd /d D:\MYSQL\Bin
D:\MYSQL\Bin>mysql -u root -p admin
The .exe
after mysql
is optional, since .exe
is an executable extension on Windows. If you type mysql
, Windows will automatically look for an executable file with that name and run it if it finds it.
在.exe
后mysql
是可选的,因为.exe
是在Windows的可执行文件扩展名。如果您键入mysql
,Windows 将自动查找具有该名称的可执行文件,并在找到后运行它。
Note that in both my examples of running mysql
, there are no =
signs. You should just use -p
with no password, and wait to be prompted for it instead.
请注意,在我的两个 running 示例中mysql
,没有任何=
迹象。您应该只使用-p
没有密码,然后等待系统提示您输入密码。
回答by Raghvendra Parashar
Use this :
用这个 :
mysql -u user_name -p then press_enter_key
then type password
然后输入密码
i.e.
IE
line-1 : mysql -u root -p
line-2 : admin
回答by Paul Q. Alvarez
first type cmd
then the windows command prompt will appear:
首先键入cmd
然后将出现Windows命令提示符:
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.
- -u 是用户 ID
- -p 是密码,如果您不使用密码,请将其留空。
回答by Ramandeep Singh
回答by RonaldBarzell
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
如果这不起作用,那么您可能没有配置系统。如果是这样,那么这里有一个关于 MySQL 提示入门的好教程:http: //breakdesign.blogspot.com/2007/11/getting-started-with-php-and-mysql-in_11.html
回答by Tomasz
- 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.) - Type: mysql -u user -p [pressEnter]
- Type your password [pressEnter]
- 从 MySQL 主目录启动 MySQL 服务器服务。你的一个是 C:\MYSQL\bin\ 所以在命令行中选择这个目录并输入:
NET START MySQL
(之后你可以打开Windows任务管理器并在进程选项卡中验证 mysqld.exe 进程正在运行。也许你的问题就在这里。 ) - 输入: mysql -u user -p [pressEnter]
- 输入您的 密码 [pressEnter]
or make a start.batfile:
或制作一个start.bat文件:
- add C:\MYSQL\bin\ to your PATH
- write a start.bat file My start.bat file has only two lines like below:
net start MySQL
mysql -u root -p
- 将 C:\MYSQL\bin\ 添加到您的 PATH
- 写一个start.bat文件 我的 start.bat 文件只有如下两行:
net start MySQL
mysql -u root -p
Good luck!
祝你好运!
回答by ArifMustafa
Simply to login mysql
in windows
, if you know your username and password.
只需登录mysql
中windows
,如果你知道你的用户名和密码。
Open your command prompt, for me the username is root
and password is password
打开你的命令提示符,对我来说用户名是root
,密码是password
mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.11-log MySQL Community Server (GPL)
Hope it would help many one.
希望它能帮助很多人。
回答by Ravindra Kumar
Please perform the following steps
请执行以下步骤
- First, open your command prompt with Administrator.
Go to MySQL installed directory and copy path and past on command promptlike:- C:\Program Files\MySQL\MySQL Server 5.7\bin>
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p[-u for username -p for password]
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p Enter password: **** [enter your password here]
- 首先,使用 Administrator打开命令提示符。
转到 MySQL 安装目录并复制路径并在命令提示符下过去, 例如:- C:\Program Files\MySQL\MySQL Server 5.7\bin>
C:\Program Files\MySQL\MySQL Server 5.7\bin> mysql -uroot -p[-u 表示用户名 -p 表示密码]
C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -uroot -p 输入密码:****【在此处输入密码】
回答by Prashant Sahoo
I have used following command to connect MySQL Server 8.0in Windows command prompt.
我使用以下命令在 Windows 命令提示符下连接MySQL Server 8.0。
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p my_db
Enter password: ****
or
或者
C:\Program Files\MySQL\MySQL Server 8.0\bin>mysql -u root -p my_db -h localhost
Enter password: ****
Here my_dbis schema name.
这里my_db是模式名称。
回答by Syed Ehtsham Abbas
Go to your MySQL directory. As in my case its...
转到您的 MySQL 目录。就我而言,它的...
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.
无论您设置什么 MySQL 用户,root 都可以更改为您的用户。
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.
它会询问您的密码。如果您有密码,请输入您的密码并按“Enter”,如果没有设置密码,只需按 Enter 而不输入。您将连接到 MySQL。
There is another way to directly connect to MySQL without every time, going to the directory and typing down the commands.
还有另一种方法可以直接连接到 MySQL,而无需每次都进入目录并键入命令。
Create a .bat file. First, add your path to MySQL. In my case it was,
创建一个 .bat 文件。首先,将您的路径添加到 MySQL。就我而言,它是,
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.
如果您不想每次都输入密码,您可以简单地使用 -p 添加密码,例如 -proot(以防 root 是密码),但不建议这样做。
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.
此外,如果您想连接到本地主机(登台/生产服务器)以外的其他主机。您还可以添加 -h22.345.80.09 例如 22.345.80.09 是您的服务器 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.
保存文件。只需双击打开并直接连接到 MySQL。