0

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

4
  • What is "system pwd"? What you want do it?
    – starko
    Commented 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
    Commented Mar 2, 2015 at 4:54
  • And why would you need to know the current working directory of the server anyway?
    – Andriy M
    Commented 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
    Commented Mar 3, 2015 at 4:53

2 Answers 2

1

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
/tmp

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
/tmptest
$ 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/   |
...
0

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 you have read our privacy policy.

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