mysqlmysql-cli

mysql command line sql execution mystery, only part of the string is considered


from command line from my Mac terminal:

mysql --host=127.0.0.1 --port=3306 -uroot -p"mypass" wordpress -e "update users set user_pass = '$1$Hat7oFty$mA.L2vsQdD3MxvxAuDFKp0';"

completes successfully...

however.... only .L2vsQdD3MxvxAuDFKp0 is written to the user_pass field in every row. Whiskey Tango Foxtrot?

enter image description here

Needless to say when I issue update users set user_pass = '$1$Hat7oFty$mA.L2vsQdD3MxvxAuDFKp0'; directly to the DB from an application like DataGrip it takes the whole string correctly....


Solution

  • The $ are part of shell variables, which are unintentionally get replaced. You have to escape the $ character to keep it in the string as a literal $.

    $ echo "$1$Hat7oFty$mA.L2vsQdD3MxvxAuDFKp0"
    .L2vsQdD3MxvxAuDFKp0
    $ echo "\$1\$Hat7oFty\$mA.L2vsQdD3MxvxAuDFKp0"
    $1$Hat7oFty$mA.L2vsQdD3MxvxAuDFKp0