How to execute SQL command with parameters in bash script

e_scape

I would like to make a bash script which will add user to my custom table in MySQL database. I have username as script argument stored in variable $USERNAME and I need to execute this query into MySQL server:

INSERT INTO `user` VALUES ('$USERNAME', password)

I know how to execute a sql file but that won't help me when I have username in variable. The only way I can think of is to execute php file with GET values and execute sql command in php. And I'm not eve sure that with php will work as I think.

Is there any better way?

Thanks

EDIT: After your helpfull answers I went with this command which works:

mysql -ppassword --default-character-set=utf8 -e "INSERT INTO table VALUES (\"$USERNAME@\",\"password\")" database
hjpotter92

The command would be:

mysql -pyourpasswordwithoutspaces -e "Your insert query goes here with semicolon;"

I'm not sure if the semicolons are necessary or not, but it always good to provide them.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to execute custom command in bash script

From Dev

How to execute a command within a bash script?

From Dev

how to execute a bash command in a python script

From Dev

bash: get literal parameters passed to a script and execute them as a command

From Dev

Execute a command in multiple directories with variable parameters bash script

From Dev

Execute sed command in a bash script

From Dev

BASH script - execute command in variable

From Dev

Bash Script execute command with argument

From Dev

Execute command with sudo and execute Bash script with sudo

From Dev

How to execute a bash script?

From Dev

How to execute command with bash script inside Ubuntu, which was started with bash script?

From Dev

Bash script can't execute Go command

From Dev

Bash script to monitor file change and execute command

From Dev

Bash Script execute more than one command

From Dev

Bash script to monitor file change and execute command

From Dev

Bash script that execute command only if port is free

From Dev

Bash script for execute one command for many files

From Dev

Bash script with "execute" command and strange regexp

From Dev

Execute complex command from bash script

From Dev

Bash script to monitor file change and execute command

From Dev

bash script to read my files and execute the command

From Dev

Execute command with backquote in bash shell script

From Dev

How to execute command in Python script?

From Dev

How to redirect a command with parameters in bash?

From Dev

how to execute a script within a script in shell command

From Java

Execute a bash command in a pod that runs a python script in another script in Kubernetes

From Dev

How do I execute a xfconf-query command from a bash script launched with sudo?

From Dev

Bash script to execute jar with parameters and using file path variables

From Dev

How can I pass optional parameters to another command within a bash script?

Related Related

  1. 1

    How to execute custom command in bash script

  2. 2

    How to execute a command within a bash script?

  3. 3

    how to execute a bash command in a python script

  4. 4

    bash: get literal parameters passed to a script and execute them as a command

  5. 5

    Execute a command in multiple directories with variable parameters bash script

  6. 6

    Execute sed command in a bash script

  7. 7

    BASH script - execute command in variable

  8. 8

    Bash Script execute command with argument

  9. 9

    Execute command with sudo and execute Bash script with sudo

  10. 10

    How to execute a bash script?

  11. 11

    How to execute command with bash script inside Ubuntu, which was started with bash script?

  12. 12

    Bash script can't execute Go command

  13. 13

    Bash script to monitor file change and execute command

  14. 14

    Bash Script execute more than one command

  15. 15

    Bash script to monitor file change and execute command

  16. 16

    Bash script that execute command only if port is free

  17. 17

    Bash script for execute one command for many files

  18. 18

    Bash script with "execute" command and strange regexp

  19. 19

    Execute complex command from bash script

  20. 20

    Bash script to monitor file change and execute command

  21. 21

    bash script to read my files and execute the command

  22. 22

    Execute command with backquote in bash shell script

  23. 23

    How to execute command in Python script?

  24. 24

    How to redirect a command with parameters in bash?

  25. 25

    how to execute a script within a script in shell command

  26. 26

    Execute a bash command in a pod that runs a python script in another script in Kubernetes

  27. 27

    How do I execute a xfconf-query command from a bash script launched with sudo?

  28. 28

    Bash script to execute jar with parameters and using file path variables

  29. 29

    How can I pass optional parameters to another command within a bash script?

HotTag

Archive