MySQL Issues

Karl Auer kauer at
Tue Jan 24 21:58:54 UTC 2017

On Tue, 2017-01-24 at 09:33 -0600, Dr. Mikeal Hughes wrote:
> Ok here is one for you. I tried to enter the command sudo cd /root so
> I could go in and check the my.cnf file so I could see how my login
> information for MySQL is set. When I do I get Permission denied. I
> was asked for my sudo password put it in. 

Good one :-)

Sudo creates a new shell with a new environment, executes your command
in that new shell, then leaves the shell, drops root privileges and
returns you to your previous shell and your previous environment. So
after a sudo command you are back where you started.

With "cd" in particular though, it won't would work at all. You should
get "command not found", because cd is an internal shell command, not
an actual program that sudo can load and execute. I don't think it
worked for you, and suspect you missed that error message.

To use cd in sudo you would have to tell sudo explicitly to start a
shell with that command, i.e., use "sudo -i cd /root" or "sudo -s cd
/root". But because of the whole "new shell" thing, neither of those
would have the desired effect of leaving you in the specified

In short "sudo cd /root" won't work.

One solution is to become root for a while with "sudo - bash", being
very careful with your subsequent commands and remembering to exit

The other solution is to use sudo and specify /root in each desired
command. For example, if you wanted to list the files in /root you
would use "sudo ls /root".

If you need to do a lot of stuff in the /root directory, or if they are
destructive commands like rm, I'd recommend the former, in a separate
terminal window, with emphasis on the "be careful" part. If it's just
one or two commands or they are simple things like ls, I'd recommend
using sudo.

Regards, K.

Karl Auer (kauer at

GPG fingerprint: A52E F6B9 708B 51C4 85E6 1634 0571 ADF9 3C1C 6A3A
Old fingerprint: E00D 64ED 9C6A 8605 21E0 0ED0 EE64 2BEE CBCB C38B

More information about the ubuntu-users mailing list