
#MYSQL SET ROOT PASSWORD HOW TO#
SEE: Password management policy (TechRepublic Premium) How to change MySQL root user password To use this command, simply type:Īnswer the presented questions, and your password will be set, making your database a bit more secure. Not only will this command set the root user password, but it will allow you to remove anonymous users, disallow remote root login, and remove the test database. Now, when you log into MySQL, with the command mysql -u root -p, you will be prompted to enter the newly configured password.Īn alternative method for setting the root password for the first time, one that also adds a bit of security to your MySQL database, is to use the mysql_secure_connection command. Where NEWPASSWORD is the password to be used.

To do that, open up a terminal window and issue the following command: If, for whatever reason that didn’t happen, you will need to set a password for the first time. Typically, during the installation of MySQL and MariaDB, you are asked to set an initial password. How to set MySQL password for the first timeĭo note, I will refer to MySQL with the idea that everything will work for both MySQL and MariaDB.

We may be compensated by vendors who appear on this page through methods such as affiliate links or sponsored partnerships. This article walks you through these steps, so you'll never be at a loss for that database root user password. If you never set, forgot or need to change your MySQL password, you're in luck. This is beyond the scope of the question but next I would be looking into hooking the unix user creation process to automatically creating a matching MySQL user account.How to set, change, and recover your MySQL root password I also created a MySQL account with the same username as my unix account, again with no password, and using the root account I granted it access to the tables I needed, then I could also connect from apps from my user account without changing to root.

To test open a new Terminal and do sudo su then mysql and check if it connects with no password (this didn't work when a password was set). I connected as root using the password then ran:

I also created a root password at installation and wanted to change back to using unix authentication once I understood that if I run commands or launch apps as root they can connect to the database without any password which is much simpler than having another password.
