You are writing incorrect command. Please write below command:
grant all privileges on *.* to root@localhost IDENTIFIED BY 'root' WITH GRANT OPTION;
Also, you are writing this command in the terminal, not in MySQL window. So, first, log in to MySQL and then write the command mentioned above.