In MySQL, by default, the username is root and there's no password.
Note that since MySQL 5.7, the installer may generate a temporary password for root instead. You can find it on the last screen of the installer or in the error log.
If during the installation process, you accidentally put a password in and don't remember, here is how to reset the password:
- Stop the MySQL server if it is running, then restart it with the --skip-grant-tables option.
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
It allows you to connect without a password and with all privileges and disables account-management statements such as ALTER USER and SET PASSWORD, which will be used later on to reset password. --skip-networking is enabled automatically to prevent remote connections since it's very insecure.
- Then connect to the MySQL Server using the
mysqlclient:
mysql -u root
- Then run this command to reload the grant tables:
FLUSH PRIVILEGES;
- Now you can set a new password for the
rootaccount:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
It's done, stop the server and restart it normally. Now you can connect to the MySQL Server with the new password.
*Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more. *
Download TablePlus for Mac. It's free anyway!
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.
