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.
Output on Windows:
you can just use this command,it is very easy!
1. no password of MySQL:
2. have password of MySQL:
You can see the complete list of MySQL server options by running
For example, to find out the path to the data directory on Linux, you can run:
Example output:
if you want to find datadir in linux or windows you can do following command
mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"'
if you are interested to find datadir you can use grep & awk command
Use bellow command from CLI interface
You can issue the following query from the command line:
Output (on Linux):
Output (on macOS Sierra):
Or if you want only the data dir use:
These commands work on Windows too, but you need to invert the single and double quotes.
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:
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: