Andrew Grimm
Andrew Grimm

Reputation: 81510

Is there a secure way to set up a mysql root password?

In this how-to geek article, the author talked about using

mysqladmin -u root -h host_name password “newpassword”

To set a new password. A person replied that that may leave the password in the shell's history file, and suggested using

mysql -u root mysql
mysql> SET PASSWORD FOR root@localhost=PASSWORD(’newpasswordgoeshere’);

but another person said that it'd leave the password in the .mysql_history file.

Security isn't an issue for me (no-one else should have access to my computer), but is there a better alternative?

Upvotes: 4

Views: 927

Answers (4)

ww12z
ww12z

Reputation: 63

$ mysqladmin -p -u root password seems to be the best way.

Upvotes: 0

Michael Kropat
Michael Kropat

Reputation: 15207

As of MySQL 5.5.3, the simplest way is with mysqladmin:

$ mysqladmin -p -u root password
Enter password:                     # ← current root password
New password:                       # ← new root password
Confirm new password:               # ← again

Upvotes: 7

martin clayton
martin clayton

Reputation: 78105

You can turn off MySQL history by setting

export MYSQL_HISTFILE=/dev/null

in your shell before starting mysql.

MySQL environment vars reference.

According to wikipedia the windows equivalent of /dev/null is \Device\Null or NUL.

Upvotes: 2

Noon Silk
Noon Silk

Reputation: 55082

Why don't you just use one of the options and delete the relevant history file.

Upvotes: 0

Related Questions