Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am semi-new to Ubuntu and I am using sudo su to start mysql and do some homework with it. When I quit mysql I then am still in sudo. How do I "log out", so my prompt changes back from # to $?

share|improve this question

migrated from stackoverflow.com Apr 5 '12 at 18:03

This question came from our site for professional and enthusiast programmers.

    
Use exit command .. –  Vutukuri Apr 5 '12 at 17:50
1  
exit or a simple Ctrl+D. I remember when I first discovered the latter and my life got ten times simpler :-D . –  Daniel Andersson Apr 6 '12 at 9:42
1  
Apart from the good answers below there remains one point: if you need a shell with root permissions on Ubuntu you type sudo -i (and leave it with CTRL+D) –  guntbert Jul 13 '13 at 21:12

3 Answers 3

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

share|improve this answer
    
sudo su will switch to the root account even if you don't know the root password. –  Rob Apr 5 '12 at 18:19
    
There are differences between sudo su, sudo and su, and it's worth knowing those differences for safety reasons but also for your convenience. johnkpaul.tumblr.com/post/19841381351/su-vs-sudo-su-vs-sudo-u-i –  Jeff Welling Apr 5 '12 at 18:22
    
@Rob but still it may not set the environment in a desired way - use sudo -i instead (in Ubuntu the root account is disabled by default = there exists no valid password) –  guntbert Jul 13 '13 at 21:15

Use

su username

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

Or just press Ctrl-D to exit out of root

share|improve this answer
    
you don't want to su deeper... Ctrl-D or exist or logout are all good choices –  Ram Apr 5 '12 at 20:08
    
@Ram - you made an important point. But there's a typo in your comment. It should be exit (not exist). –  MountainX Jul 13 '13 at 18:08
    
typo indeed @MountainX ... CTRL-D, exit, logout etc. –  Ram Jul 13 '13 at 20:39

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).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.