» Access MySQL without Password
If you want to do command-line MySQL administration like restoring databases or dumping statistics, you need the root account and it's password. Or do you?
On Ubuntu / Debian, you don't. This is usefull if you
- Have lost your password (reset it this way)
- Want to automate tasks (it's a bad idea to pass around root passwords)
So how does this work
Well normally you would access MySQL like this right?
mysql -h localhost -u root -p
# Enter password: XYZ
Or you can automate it by supplying it in the same command:
mysql -h localhost -u root -pXYZ
Pretty messy if you ask me.
What a lot of people don't know is that there is an account that's used by debian related systems to restart the service, perform checks, etc.
The account is called debian-sys-maint, it's credentials are stored in
/etc/mysql/debian.cnf and if you have root access on a database server's shell
you're in business. You can either look up the account, or tell mysql to do it
for you:
mysql --defaults-file=/etc/mysql/debian.cnf
And Bob's your uncle.
You probably shouldn't follow me
Like this Article?
| I'd appreciate it if you leave a comment, spread the word, or consider a small donation |
RelatedArticles like this one» Create short IDs with PHP - Like Youtube or TinyURL |
tags: mysql, password, database, security
category: Howto - MySQL
read: 9,820 times
Add Comment
Comments have been automatically closed because of the age of the article. If you need to, you can still contact me on the subject.
tagcloud
#8. laptop guide on 21 November 2010
#7. Jerry Michael on 17 June 2010
#6. Kevin on 29 March 2010
#5. CrazyCat on 28 March 2010
#4. Kevin on 24 March 2010
@ CrazyCat: You are right: -p xyz doesn't work. -pxyz does however. I've updated the article accordingly.
#3. CrazyCat on 23 March 2010
-p means "ask for password", and -p xyz means "ask password and select xyz base".
#2. Tim on 22 March 2010
#1. Tim on 22 March 2010
[mysql]
user=yourmysqlusername
password=xyz
... [more] [mysqldump]
user=root
password=xyz
this is not Debian specific.