Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change directory in mysql command line tool?

I am using mysql command line client under Linux to work with MySQL database. How can I change current working directory? I did not find it in the documentation.


EDIT: This is not duplicate of the mentioned question, because OP limited the solutions to using system, they are just answering how to run the system command instead and it obviously never works with system. It is not a good canonical question for how to cd in mysql. There will never be a good answer.

like image 567
Tomas Avatar asked Jul 13 '16 07:07

Tomas


Video Answer


1 Answers

If you start the MySQL command line tool from the terminal, your working directory will be wherever you executed the binary from. For example in Windows, start the command prompt and then run the following:

cd "C:\my scripts path\"    
"C:\Program Files (x86)\MySQL\MySQL Server 5.7\bin\mysql" -u root -p rootpassword

Now, you can execute source commands and just pass the script name rather than the entire absolute path. This is super useful for nesting scripts while using relative paths.

(I'm pretty certain this works in Linux too, but I only tested in Windows.)

like image 187
BuvinJ Avatar answered Oct 17 '22 14:10

BuvinJ