0

If importing a SQL dump file using the mysql command line client, if it wasn't created by the superuser and guaranteed to not have been modified, for security it's best practice to not execute it as the root user.

I know this can be done using the -u and -p arguments, but is there a way to not have to know the password for the user if you already have the ability to log in as root (e.g. the root password is in /root/.my.cnf)? Like is there some way to log in as root then switch to the particular user, or some other easy way to accomplish this?

  • You can put the password for a given user to their ~/.my.cnf and use only -u <user>. – jkavalik Oct 20 '15 at 14:47
  • @jkavalik That sounds like a decent solution if i'm going to be doing it often for the same user, but I'm hoping to avoid having to look up their password altogether. – user101203 Oct 20 '15 at 14:49
  • you can as well encrypt the password and use that as a string in your command line. – tesla747 Oct 20 '15 at 16:07
  • @tesla747 it would be nice to not have to do anything with the user's password since I already have root privileges. For example, in bash on Linux if you're root, you can change to any user using su without having to know their password. – user101203 Oct 20 '15 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.