Is it possible to create a user in mysql without logging in?

1k views Asked by At

I have a root and test user which I don't remember the password for either one in mysql database. is it possible to create a new user from outside? I could not find answers for this in the internet. Thanks.

1

There are 1 answers

0
eggyal On

Restart mysqld with the --init-file option specifying the path to a file that contains your desired commands. For example, to create a new superuser:

GRANT ALL ON *.*
  TO 'new_user'@'localhost' IDENTIFIED BY 'new_password'
  WITH GRANT OPTION;

Of course, you could also use this method to simply reset the passwords of the existing accounts:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');