在命令提示符下获取 MySQL 路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14805567/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 16:30:40  来源:igfitidea点击:

Getting MySQL path in command prompt

mysqlwindowscommand-prompt

提问by rakesh menon

How can I get the mysql installation path up to bin folder using command prompt in windows.Is there any command to get the location of mysql installation path?

如何在windows中使用命令提示符将mysql安装路径获取到bin文件夹。是否有任何命令可以获取mysql安装路径的位置?

回答by 1392023093user

(if I get your question correctly)Like you wold add any other directory to path

(如果我正确地回答了您的问题)就像您将任何其他目录添加到路径一样

set PATH=%PATH%;C:\DirectoryToAdd\ToPath

设置 PATH=%PATH%;C:\DirectoryToAdd\ToPath

It doesnt metter if you add %PATH% on, beginig or on the end, but you mustadd it, otherwise your path will only be your new directory.

如果在、beginig 或最后添加 %PATH% 并不重要,但您必须添加它,否则您的路径将只是您的新目录。

Find mySql installation directory ( for example C:\Program Files\MySQL\MySQL Server 5.6\bin) and then type the comand above set PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 5.6\bin

找到mySql安装目录(例如C:\Program Files\MySQL\MySQL Server 5.6\bin)然后输入上面的命令set PATH=%PATH%;C:\Program Files\MySQL\MySQL Server 5.6\bin

tips:

提示:

  • in cmd use PATH to see what is your path (I think every body knows this, but it cant hurt) And see something more about PATHcommand

  • Your mySql servce must be turned on to execute commands.

  • In Windows explorer if you type cmd.exe in Windwos Explorer Address Bar you will get cmd running from that directory.
  • 在 cmd 中使用 PATH 来查看您的路径是什么(我认为每个人都知道这一点,但不会造成伤害)并查看有关PATH命令的更多信息

  • 您的 mySql 服务必须打开才能执行命令。

  • 在 Windows 资源管理器中,如果您在 Windwos 资源管理器地址栏中键入 cmd.exe,您将从该目录运行 cmd。

回答by juacala

In a MySQL client you can get base and data directories by doing the following:

在 MySQL 客户端中,您可以通过执行以下操作来获取基本目录和数据目录:

select @@basedir
select @@datadir

You can prob reconstruct all other paths from those. So if you can get to MySQL at all, that should do it.

您可以从这些路径重建所有其他路径。因此,如果您完全可以使用 MySQL,那就应该这样做。

回答by Raul

Usually it is installed in side program file this is the normal path where you can find bin C:\Program Files\MySQL\MySQL Server 5.5\bin

通常它安装在侧程序文件中这是您可以找到bin的正常路径 C:\Program Files\MySQL\MySQL Server 5.5\bin

回答by Fathah Rehman P

If you install mysql properly then mysql path is automatically added to environment variables. To check this type pathin command prompt. If you can see mysql path in it, you can run mysql executable files from any command prompt location.

如果您正确安装了 mysql,那么 mysql 路径会自动添加到环境变量中。要path在命令提示符中检查此类型。如果您可以在其中看到 mysql 路径,则可以从任何命令提示符位置运行 mysql 可执行文件。

回答by Gabriel Teodósio

First of all:

首先:

Take extremelly care when editing your system Path variable; accidental deletion or modification of any portion of the existing Path value can leave you with a malfunctioning or even unusable system.

编辑系统路径变量时要格外小心;意外删除或修改现有路径值的任何部分都可能导致系统出现故障甚至无法使用。

As we follow, I think I'll need to explain a bit of how you can edit you Windows Path Variable. So, let's begin.

在我们接下来的过程中,我想我需要解释一下如何编辑 Windows 路径变量。那么,让我们开始吧。

Windows Path Variable

Windows 路径变量

To start, we need to edit the Path System Variable, but how do we can edit it? Simple! Go to your Computerand click on its icon, then click on Properties.

首先,我们需要编辑路径系统变量,但是我们如何编辑它呢?简单的!转到您的计算机并单击其图标,然后单击Properties

Step-01

步骤-01

Or you can just press Windows + Pause/Break, and then this window should open:

或者你可以直接按Windows + Pause/Break,然后这个窗口应该打开:

Step-01.1

步骤-01.1

Then click on Advanced System Settings, or something similar, like in the following image:

然后点击Advanced System Settings或类似的东西,如下图所示:

Step-02

Step-02

After that, click on the System Variablesbutton on the window that just opened.

之后,单击刚刚打开的窗口上的系统变量按钮。

Step-03

Step-03

At this new window you'll find two areas, being the top and bottom one; For now let's focus on the bottom one. Search for the variable, of name, Path. Click on it (select it), click on the Editbutton and a window like the following should appear.

在这个新窗口中,您会发现两个区域,分别是顶部和底部;现在让我们专注于底部。搜索名称为Path的变量。单击它(选择它),单击“编辑”按钮,应出现如下所示的窗口。

Step-04

Step-04

PS.: It's important to have in mind that a Window like this will not open to you if you are using a Windows Version older than the 8 or 8.1, as I remember. It can have been changed, but I don't know.

PS.:重要的是要记住,如果您使用的 Windows 版本早于 8 或 8.1,那么像这样的窗口将不会向您打开,我记得。它可以被改变,但我不知道。

If you see this window you can now edit your Path System Variable by Adding or Removig directories, for now click on the Edit Textbutton. At this new window that opened, on the value field, at the final of the text that already is there, you should put this:

如果您看到此窗口,您现在可以通过添加或删除目录来编辑路径系统变量,现在单击“编辑文本”按钮。在这个打开的新窗口中,在value 字段上,在已经存在的文本的最后,你应该输入:

C:\Program Files\MySQL\MySQL Server <version>\bin

Listen, this is the default install location of the MySQL Servers that I've used. Now your gonna need to know where did you installed it. If you installed in the default location but you don't know the version that you're using, you can go to:

听着,这是我使用过的 MySQL 服务器的默认安装位置。现在你需要知道你在哪里安装它。如果您安装在默认位置但不知道您使用的版本,您可以访问:

C:\Program Files\MySQL

And see for yourself the version that you've installed and then put on the path above. For me I've used the following:

并亲自查看您安装的版本,然后放在上面的路径上。对我来说,我使用了以下内容:

C:\Program Files\MySQL\MySQL Server 5.7\bin

I've used that because my MySQL version is 5.7. I hope you got it.

我使用它是因为我的 MySQL 版本是 5.7。我希望你明白了。

Now Click on the OkButton, until you don't see any of the windows that we have opened.

现在单击“确定”按钮,直到您看不到我们打开的任何窗口。

Reopen your CMD (or Powershell), and now you can use your MySQL directly from the CMD.

重新打开您的 CMD(或 Powershell),现在您可以直接从 CMD 使用您的 MySQL。

回答by Liko

This worked for me and is very simple.

这对我有用并且非常简单。

First I downloaded the mysql and did the full install, then performed the steps below.

首先,我下载了 mysql 并进行了完整安装,然后执行了以下步骤。

  1. On the Windows desktop, right-click the My Computer icon, and select Properties.

  2. Next select the Advanced tab from the System Properties menu that appears, and click the Environment Variables button.

  3. Under System Variables, select Path, and then click the Edit button. The Edit System Variable dialogue should appear.

  4. Place your cursor at the end of the text appearing in the space marked Variable Value. (Use the End key to ensure that your cursor is positioned at the very end of the text in this space.) Then enter the complete path name of your MySQL bin directory (for example, C:\Program Files\MySQL\MySQL Server 5.1\bin)

  1. 在 Windows 桌面上,右键单击我的电脑图标,然后选择属性。

  2. 接下来从出现的系统属性菜单中选择高级选项卡,然后单击环境变量按钮。

  3. 在系统变量下,选择路径,然后单击编辑按钮。应出现“编辑系统变量”对话框。

  4. 将光标放在标记为变量值的空间中出现的文本末尾。(使用 End 键确保光标位于此空间中文本的最后。)然后输入 MySQL bin 目录的完整路径名(例如,C:\Program Files\MySQL\MySQL Server 5.1 \bin)

Note

笔记

There must be a semicolon separating this path from any values present in this field.

必须有一个分号将该路径与该字段中存在的任何值分开。

Dismiss this dialogue, and each dialogue in turn, by clicking OK until all of the dialogues that were opened have been dismissed.

通过单击“确定”直到所有打开的对话都被解除,依次解除此对话和每个对话。

--

——

Now type "mysql - version" in the console, if it shows the installed version, everything went fine.

现在在控制台中输入“mysql - version”,如果它显示已安装的版本,则一切正常。

* You should not add the MySQL bin directory to your Windows PATH if you are running multiple MySQL servers on the same machine.

* 如果您在同一台机器上运行多个 MySQL 服务器,则不应将 MySQL bin 目录添加到 Windows PATH 中。

From the official website of MySQL: http://dev.mysql.com/doc/mysql-windows-excerpt/5.1/en/mysql-installation-windows-path.html

来自 MySQL 官网:http: //dev.mysql.com/doc/mysql-windows-excerpt/5.1/en/mysql-installation-windows-path.html

回答by Peter Lionhart

I know this question is VERY OLD. but i just wanted to POINT OUT how all the answers here have COMPLETELY MISUNDERSTOOD the question of the OP.

我知道这个问题很老了。但我只是想指出这里的所有答案如何完全误解了 OP 的问题。

Hes not asking HOW TO CHANGE THE PATH. he is asking if there is a way to get the path to the MYSQL INSTALL DIRECTORY ( BECAUSE IT CAN VARY FROM PC TO PC, x64 x86, driver letters ETC. ). the GOAL is similar to the @@basedir system variable in MySQL (BUT THIS REQUIRES you are connected to MySQL).

他不问如何改变路径。他在问是否有办法获得 MYSQL 安装目录的路径(因为它可能因 PC 到 PC、x64 x86、驱动程序字母等而异。)。目标类似于 MySQL 中的 @@basedir 系统变量(但这需要您连接到 MySQL)。

I think what the OP is trying to do and what i am trying to do is SIMILAR. WE wanted to get the BIN folder in MySQL directory in order to call mysqldump.exe. (please dont tell me to just use $ mysqldump.exe as this is used in the MySQL PROMPT not DOS PROMPT)

我认为 OP 正在尝试做的事情和我正在尝试做的事情很相似。我们想获取 MySQL 目录中的 BIN 文件夹,以便调用 mysqldump.exe。(请不要告诉我只使用 $ mysqldump.exe,因为它用于 MySQL PROMPT 而不是 DOS PROMPT)

For example %MYSQLDIRECTORY% / BIN / mysqldump.exe <--- %MYSQLDIRECTORY% is sample only

例如 %MYSQLDIRECTORY% / BIN / mysqldump.exe <--- %MYSQLDIRECTORY% 只是示例

  • we dont have to worry which PROGRAMFILES folder or DRIVE it is on
  • not worry if the INSTALLER changed the name of the MySQL folder upon install.
  • do not have to run MySQL COMMAND PROMPT to get the path. use WINDOWS DOS PROMPT only.
  • 我们不必担心它在哪个 PROGRAMFILES 文件夹或驱动器上
  • 如果安装程序在安装时更改了 MySQL 文件夹的名称,请不要担心。
  • 不必运行 MySQL COMMAND PROMPT 来获取路径。仅使用 WINDOWS DOS PROMPT。

we just simply need to run mysqldump.exe and throw in some parameters there. currently i just copy mysqldump.exe along in my application folder but even that is a bad idea because it may not be the same version as the one installed in the operating system.

我们只需要运行 mysqldump.exe 并在那里输入一些参数。目前我只是将 mysqldump.exe 复制到我的应用程序文件夹中,但即使这样也是一个坏主意,因为它可能与操作系统中安装的版本不同。

回答by odin

To make it easier to invoke MySQL programs, you can add the path name of the MySQL bin directory to your Windows system PATH environment variable:

为了更容易调用 MySQL 程序,您可以将 MySQL bin 目录的路径名添加到您的 Windows 系统 PATH 环境变量中:

? On the Windows desktop, right-click the My Computer icon, and select Properties.

? 在 Windows 桌面上,右键单击我的电脑图标,然后选择属性。

? Next select the Advanced tab from the System Properties menu that appears, and click the Environment Variables button.

? 接下来从出现的系统属性菜单中选择高级选项卡,然后单击环境变量按钮。

? Under System Variables, select Path, and then click the Edit button. The Edit System Variable dialogue should appear.

? 在系统变量下,选择路径,然后单击编辑按钮。应出现“编辑系统变量”对话框。

? Place your cursor at the end of the text appearing in the space marked Variable Value. (Use the End key to ensure that your cursor is positioned at the very end of the text in this space.) Then enter the complete path name of your MySQL bin directory (for example, C:\Program Files\MySQL\MySQL Server 5.1\bin)

? 将光标放在标记为变量值的空间中出现的文本末尾。(使用 End 键确保光标位于此空间中文本的最后。)然后输入 MySQL bin 目录的完整路径名(例如,C:\Program Files\MySQL\MySQL Server 5.1 \bin)

Reference= http://dev.mysql.com/doc/mysql-windows-excerpt/5.1/en/mysql-installation-windows-path.html

参考= http://dev.mysql.com/doc/mysql-windows-excerpt/5.1/en/mysql-installation-windows-path.html

回答by Aman Garg

To run mysql on command prompt follow the below steps:

要在命令提示符下运行 mysql,请按照以下步骤操作:

1. Run cmd command
2. Type c: or d: on command prompt. This will be based on your WAMP server installations.
3. Assuming you have installed wamp on c: drive.
4. c:\>cd wamp
4. c:\wamp>cd bin
5. c:\wamp\bin>cd mysql
6. c:\wamp\bin\mysql>cd mysql15.1.36
7. c:\wamp\bin\mysql\mysql15.1.36>cd bin
8. c:\wamp\bin\mysql\mysql15.1.36\bin>mysql.exe -u root

These are the main steps to run mysql on command line.

这些是在命令行上运行 mysql 的主要步骤。

Another way to run the mysql command directly to CMD:

另一种直接运行mysql命令到CMD的方法:

Be sure that your mysql\bin folder is part of your $PATH variable:

确保您的 mysql\bin 文件夹是 $PATH 变量的一部分:

1. Go to Control Panel -> System -> Advanced
2. Click Environment Variables
3. Under System Variables find PATH and click on it.
4. In the Edit windows, find the end of the string of paths (each path needs to be separated by a semi-colon ";" so you may need to add that to the end) add the path to your mysql\bin folder to the end paths.
5. Go back to Desktop
6. Close any command prompts you may have open Got to do this so the new $PATH variable will load.
7. Re-open command prompt. Try running mysql -uroot and if the path was set correctly, mysql will now run.

Let me know if this takes care of it!

如果这能解决问题,请告诉我!

回答by MDKT15

When you are using WAMPpath is this one C:\wamp\bin\mysql\mysql5.6.12\bin

当你使用WAMP路径是这个 C:\wamp\bin\mysql\mysql5.6.12\bin