I'm using sudo su to start mysql and do some homework with it.
When I finish with mysql (or any other command), then I'm still in sudo.
How do I "log out", so my prompt changes back from # to $?
5 Answers
You don't need to use sudo and su together--su switches your user account (without arguments it switches you to root). sudo just elevates your privileges to root for the current command.
It's reccomended to use sudo instead of su if possible, but to return to your normal account after calling su, simply use the exit command
Use
su usernameto get back to your user level (or a different user)
Or just press Ctrl+D to exit out of root
5logoutif usedsudo su -exitif usedsudo -s
if your stuck after using sudo su as root: to exit use this command
su -l <user_name> There isn't any reason to use sudo or su to run the MySQL command-line client. It defaults to using your current Unix user as your MySQL user, but instead you should pass it the user you want to connect to as arguments:
$ mysql -u root # connect as MySQL's root user (without password)
$ mysql -u root -p # -p means prompt for a passwordHopefully, your MySQL root account has a password, and you'll need to use the second form.
Other than that, if you need to run MySQL under sudo (e.g., for file permissions) then do it like this:
$ sudo -u unix-user mysql -u mysql-user -pYou can leave out the arguments (sudo will default to user root, MySQL will default to using the same user as sudo).