Oleg9 Oleg9 - 7 months ago 13
SQL Question

MySQL: Trying set a password for root, Error in SQL Syntax

This piece of code is from the Learning MySQL and MariaDB book:

mysql -u root -p -e "SET PASSWORD FOR 'root'@'127.0.0.1' PASSWORD('new_pwd');"


And I'm getting this error:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for th
e right syntax to use near 'PASSWORD('new_pwd')' at line 1


Is this book correct? Isn't this syntax old? What's the problem?

Answer

try with:

mysql -u root -p -e "SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('new_pwd');"