Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can issue the following query from the command line:</p> <pre><code>mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name LIKE "%dir"' </code></pre> <p>Output (on Linux):</p> <pre><code>+---------------------------+----------------------------+ | 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 | +---------------------------+----------------------------+ </code></pre> <p>Output (on macOS Sierra):</p> <pre><code>+---------------------------+-----------------------------------------------------------+ | 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/ | +---------------------------+-----------------------------------------------------------+ </code></pre> <p>Or if you want only the data dir use:</p> <pre><code>mysql -uUSER -p -e 'SHOW VARIABLES WHERE Variable_Name = "datadir"' </code></pre> <p>These commands work on Windows too, <strong>but you need to invert the single and double quotes</strong>.</p> <p>Btw, when executing <code>which mysql</code> in Linux as you told, you'll not get the <em>installation</em> directory on Linux. You'll only get the binary path, which is <code>/usr/bin</code> on Linux, but you see the mysql installation is using multiple folders to store files.</p> <hr> <p>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:</p> <pre><code>mysql -s -N -uUSER -p information_schema -e 'SELECT Variable_Value FROM GLOBAL_VARIABLES WHERE Variable_Name = "datadir"' </code></pre> <p>The command will select the value only from mysql's internal <code>information_schema</code> database and disables the tabular output and column headers.</p> <p>Output on Linux:</p> <pre><code>/var/lib/mysql </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload