Linux 如何在windows中从命令行查找mysql数据目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17968287/
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 find the mysql data directory from command line in windows
提问by Prabhu
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.
在 linux 中,我可以使用命令找到 mysql 安装目录which mysql
。但是我在windows中找不到任何东西。我试过了echo %path%
,它导致了许多路径以及 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?
我想从 Windows 的命令行中找到 mysql 数据目录以用于批处理程序。我还想从 linux 命令行中找到 mysql 数据目录。是否可以?或者我们怎么做?
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.
就我而言,mysql 数据目录位于安装文件夹中,即..MYSQL\mysql server 5\data
它可以安装在任何驱动器上。我想从命令行返回它。
采纳答案by hek2mgl
You can issue the following query from the command line:
您可以从命令行发出以下查询:
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name LIKE "%dir"'
Output (on Linux):
输出(在 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 |
+---------------------------+----------------------------+
Output (on macOS Sierra):
输出(在 macOS Sierra 上):
+---------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+---------------------------+-----------------------------------------------------------+
| basedir | /usr/local/mysql-5.7.17-macos10.12-x86_64/ |
| character_sets_dir | /usr/local/mysql-5.7.17-macos10.12-x86_64/share/charsets/ |
| datadir | /usr/local/mysql/data/ |
| innodb_data_home_dir | |
| innodb_log_group_home_dir | ./ |
| innodb_tmpdir | |
| lc_messages_dir | /usr/local/mysql-5.7.17-macos10.12-x86_64/share/ |
| plugin_dir | /usr/local/mysql/lib/plugin/ |
| slave_load_tmpdir | /var/folders/zz/zyxvpxvq6csfxvn_n000009800002_/T/ |
| tmpdir | /var/folders/zz/zyxvpxvq6csfxvn_n000009800002_/T/ |
+---------------------------+-----------------------------------------------------------+
Or if you want only the data dir use:
或者,如果您只想要数据目录,请使用:
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"'
These commands work on Windows too, but you need to invert the single and double quotes.
这些命令也适用于 Windows,但您需要反转单引号和双引号。
Btw, when executing which mysql
in Linux as you told, you'll not get the installationdirectory 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.
顺便说一句,当which mysql
你说在 Linux 中执行时,你不会在 Linux 上获得安装目录。您只会获得/usr/bin
Linux 上的二进制路径,但您会看到 mysql 安装使用多个文件夹来存储文件。
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:
如果您需要 datadir 的值作为输出,仅此而已,没有列标题等,但您没有 GNU 环境 (awk|grep|sed ...),请使用以下命令行:
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.
该命令将仅从 mysql 的内部information_schema
数据库中选择值并禁用表格输出和列标题。
Output on Linux:
Linux 上的输出:
/var/lib/mysql
回答by Amrit Shrestha
if you want to find datadir in linux or windows you can do following command
如果你想在 linux 或 windows 中找到 datadir 你可以执行以下命令
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"'
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"'
if you are interested to find datadir you can use grep & awk command
如果你有兴趣找到 datadir 你可以使用 grep & awk 命令
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"' | grep 'datadir' | awk '{print }'
回答by As_913
You can try this-
你可以试试这个——
mysql> select @@datadir;
PS- It works on every platform.
PS-它适用于每个平台。
回答by GigolNet Guigolachvili
public function variables($variable="")
{
return empty($variable) ? mysql_query("SHOW VARIABLES") : mysql_query("SELECT @@$variable");
}
/*get datadir*/
$res = variables("datadir");
/*or get all variables*/
$res = variables();
回答by xgqfrms
回答by Eugene Yarmash
You can see the complete list of MySQL server options by running
您可以通过运行查看 MySQL 服务器选项的完整列表
mysqld --verbose --help
For example, to find out the path to the data directoryon Linux, you can run:
例如,要查找Linux 上数据目录的路径,您可以运行:
mysqld --verbose --help | grep ^datadir
Example output:
示例输出:
datadir /var/lib/mysql/
回答by bluegrounds
Check if the Data
directory is in "C:\ProgramData\MySQL\MySQL Server 5.7\Data"
. This is where it is on my computer. Someone might find this helpful.
检查Data
目录是否在"C:\ProgramData\MySQL\MySQL Server 5.7\Data"
. 这是它在我电脑上的位置。有人可能会发现这很有帮助。
回答by Rakib
Use bellow command from CLI interface
从 CLI 界面使用波纹管命令
[root@localhost~]# mysqladmin variables -p<password> | grep datadir