How can I use 'system pwd' command with MySql CONCAT() function? I tried

select concat('test', system pwd);

gives me

ERROR 1583 (42000): Incorrect parameters in the call to native function 'concat'

Is there any way? My database version 5.1

  • What is "system pwd"? What you want do it?
    – starko
    Mar 1, 2015 at 16:02
  • 'system pwd' gives me the present working directory, when I run it from mysql command prompt, it works fine, but when I am trying to concatenate this command with concat() function, I can't find a way
    – Khalid
    Mar 2, 2015 at 4:54
  • And why would you need to know the current working directory of the server anyway?
    – Andriy M
    Mar 2, 2015 at 7:29
  • I just wondered if I could do that ;), anyway, thanks for your interest, jynus gives a good explanation of my query
    – Khalid
    Mar 3, 2015 at 4:53

2 Answers 2


system is not a recognized MySQL server command. This will only work on the MySQL command line interface "mysql". With a command like this:

mysql> system pwd

you will get the client's current directory, nothing to do with the server. You cannot use that information on server side, for executing queries. If you want to concat the pwd with something else, use a script at client side (bash, php). For example:

$ echo $(pwd)test
$ mysql  -e "SELECT concat('$(pwd)', 'test')" # there is not reason to do this at all
| concat('/tmp', 'test') |
| /tmptest               |

While there is a custom non-standard UDF library to make MySQL server interact with the operating system, I do not see a valid use in your case.

If you want to know the directory where MySQL is installed, where the datafiles are, etc., you can execute:

mysql> SHOW GLOBAL VARIABLES like '%dir';
| Variable_name             | Value                    |
| basedir                   | /usr/local/mysql         |
| datadir                   | /usr/local/mysql/data/   |

You cannot call outside programs from within MySQL code. It is not allowed because of the serious security issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.