szgift.blogg.se

Mysql shell
Mysql shell







mysql shell
  1. Mysql shell how to#
  2. Mysql shell password#

sql file with the SOURCE command anyway, since that is not terminated by a as other MySQL commands are, and only one is allowed per line. You would need to use this for executing more than one. I don't know other shells, so I cannot say if they work therein as well.

mysql shell

The other option is to use the multi-line quoted strings allowed in Bash with the batch syntax version (with the -Bse). That pretty much removes the benefits of using a HEREDOC inside the shell script to begin with.

mysql shell mysql shell

It also removes the ability to use shell and environment variables within it. Removing shell expansion that way eliminates the need to escape the backticks, and other shell-special characters. Mysql -u $user -p$password $db_name -Be "SOURCE temp.sql" SELECT `column_name` FROM `table_name` WHERE `column_name`='constant_value' #!/bin/bashĬat >temp.sql temp.sql <<'SQL_STATEMENTS' sql file, even if it's a temporary one, and use that file as the "command" to execute with the MySQL batch line. If you need the functionality of HEREDOC, it would be better to use it in the creation of a. HEREDOC can be used in the redirection version syntax, (without the -Bse option), since I/O redirection is what HEREDOC is built around. To address a comment (question?) on the short answer I mentioned: No, it cannot be used with a HEREDOC syntax, as that shell command is given.

Mysql shell how to#

My favorite answer, from Danny, covers that, including how to handle the issue when dealing with cron jobs, or anything else.

Mysql shell password#

How to deal with the security issues around the password on the command line, or in a my.cnf file, etc., has been well addressed in other answers, with some excellent suggestions. The rules with respect to what needs to be escaped in an. By not having the file redirected, piped, or in any other manner handled by the shell, there is no issue with needing to escape any of the characters in the generated output because of the shell. The presumption here is that the generated file is valid as an. sql file, it can be dropped from the command. If the database name is included in the generated. Mysql -u$user -p$password $dbname -Bse "SOURCE ds_fbids.sql In short, modify the OP's command according to Kshitij Sood's syntax and replace the commands in that with the SOURCE command: #!/bin/bash The syntax in the short, but excellent, answer, from Kshitij Sood, gives the best starting point. sql file using the SOURCE command in MySQL. sql file, while avoiding all the traps that can be hidden in trying to pass files through stdin and stdout, just tell MySQL to execute the generated. To "automate" the process of importing the generated. I suggest you edit your original question above and provide examples of what goes wrong.Īlso when I'm troubleshooting a shell script I use the -x flag so I can see how it's executing each command: $ bash -x myscript.sh It's hard to diagnose what's wrong with your shell script, because you haven't shared the exact script or any error output. I run batch-mode mysql commands like the above on the command line and in shell scripts all the time. Then: $ mysql -h "server-name" "database-name" < "filename.sql" $ mysql -h "server-name" -u "root" "-pXXXXXXXX" "database-name" ĮRROR 1049 (42000): Unknown database 'XXXXXXXX'Īctually, I prefer to store the user and password in ~/.my.cnf so I don't have to put it on the command-line at all: And it's tricky because you must have no space between -p and the password. You need to use the -p flag to send a password.









Mysql shell