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?
CodePudding user response:
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