How do I log out of `sudo su`?

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 $?

3

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

6

Use

su username

to get back to your user level (or a different user)

Or just press Ctrl+D to exit out of root

5
  • logout if used sudo su -
  • exit if used sudo -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 password

Hopefully, 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 -p

You can leave out the arguments (sudo will default to user root, MySQL will default to using the same user as sudo).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like