3

I am new to sql. I know I can run script with absolute path:

mysql> source /absolute_path/file.sql;

Is there a way to use just relative path? Or to simplify the absolute path via some variable?

1 Answer 1

3

If you use a relative path, then it will be relative to the current working directory you were in when you ran the mysql client.

In other words, the following would work:

$ cd /absolute_path
$ mysql
mysql> source file.sql

I don't think you can use expressions or variables in the source command. It's a builtin command to the mysql client, and that has a simpler parser than the MySQL Server's SQL parser. Builtin commands don't support expressions or variables.

Here's a link to the code that parses the source command: https://github.com/mysql/mysql-server/blob/8.0/client/mysql.cc#L4187-L4197

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.