Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

security

mysql

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?

like image 343
Andrew Grimm Avatar asked Jan 23 '23 18:01

Andrew Grimm


2 Answers

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
like image 198
Michael Kropat Avatar answered Jan 31 '23 08:01

Michael Kropat


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.

like image 32
martin clayton Avatar answered Jan 31 '23 08:01

martin clayton