如何在Windows中从命令行查找mysql数据目录 [英] How to find the mysql data directory from command line in windows

查看:396
本文介绍了如何在Windows中从命令行查找mysql数据目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在linux我可以找到mysql安装目录与命令其中mysql 。但我在窗户中找不到任何东西。我尝试了 echo%path%,它导致许多路径和mysql bin的路径。



我想在Windows中从命令行查找mysql数据目录,以便在批处理程序中使用。我也想从linux命令行找到mysql数据目录。是否可以?



在我的例子中,mysql数据目录位于安装文件夹ie .. MYSQL\mysql server 5 \data 但是,它可能安装在任何驱动器上。

解决方案

您可以从命令行发出以下查询:

  mysql -uUSER -p -e'SHOW VARIABLES WHERE Variable_Name LIKE%dir'



输出(在Linux上):

  -------------------------- + ----------------------- ----- + 
| Variable_name |价值|
+ --------------------------- + ----------------- ----------- +
| basedir | / usr
| character_sets_dir | / usr / share / mysql / charsets / |
| datadir | / var / lib / mysql /
| innodb_data_home_dir | |
| innodb_log_group_home_dir | ./ |
| lc_messages_dir | / usr / share / mysql /
| plugin_dir | / usr / lib / mysql / plugin / |
| slave_load_tmpdir | / tmp |
| tmpdir | / tmp |
+ --------------------------- + ----------------- ----------- +

或者如果只想使用数据目录:

  mysql -uUSER -p -e'显示变量WHERE Variable_Name =datadir'

这也适用于Windows。



Btw,当你在Linux中执行时,会出现mysql 目录。你只能得到二进制路径,在Linux上是 / usr / bin ,但是你看到mysql安装使用多个文件夹来存储文件。






如果你需要datadir的值作为输出,只有,没有列标题等,但是你没有GNU环境awk | grep | sed ...),然后使用以下命令行:

  mysql -s -N -uUSER -p information_schema -e'SELECT Variable_Value FROM GLOBAL_VARIABLES WHERE Variable_Name =datadir'

命令将仅选择值



在Linux上输出

  / var / lib / mysql 


In linux I could find the mysql installation directory with the command which mysql. But I could not find any in windows. I tried echo %path% and it resulted many paths along with path to mysql bin.

I wanted to find the mysql data directory from command line in windows for use in batch program. I would also like to find mysql data directory from linux command line. Is it possible? or how can we do that?

In my case, the mysql data directory is on the installation folder i.e. ..MYSQL\mysql server 5\data It might be installed on any drive however. I want to get it returned from the command line.

解决方案

You can issue the following query from the command line:

mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name LIKE "%dir"'

Output (on Linux):

+---------------------------+----------------------------+
| Variable_name             | Value                      |
+---------------------------+----------------------------+
| basedir                   | /usr                       |
| character_sets_dir        | /usr/share/mysql/charsets/ |
| datadir                   | /var/lib/mysql/            |
| innodb_data_home_dir      |                            |
| innodb_log_group_home_dir | ./                         |
| lc_messages_dir           | /usr/share/mysql/          |
| plugin_dir                | /usr/lib/mysql/plugin/     |
| slave_load_tmpdir         | /tmp                       |
| tmpdir                    | /tmp                       |
+---------------------------+----------------------------+

Or if you want only the data dir use:

mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"'

This will work on Windows as well.

Btw, when executing which mysql in Linux as you told, you'll not get the installation directory on Linux. You'll only get the binary path, which is /usr/bin on Linux, but you see the mysql installation is using multiple folders to store files.


If you need the value of datadir as output, and only that, without column headers etc, but you don't have a GNU environment (awk|grep|sed ...) then use the following command line:

mysql -s -N -uUSER -p information_schema -e 'SELECT Variable_Value FROM GLOBAL_VARIABLES WHERE Variable_Name = "datadir"'

The command will select the value only from mysql's internal information_schema database and disables the tabular output and column headers.

Output on Linux:

/var/lib/mysql

这篇关于如何在Windows中从命令行查找mysql数据目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆