<p>I lost my MySQL username and password. How do I retrieve it?</p>

[{'answer_id': 4376, 'author': 'Xenph Yan', 'author_id': 264, 'author_profile': 'https://Stackoverflow.com/users/264', 'pm_score': 9, 'selected': True, 'text': "<blockquote>\n<p>Stop the MySQL process.</p>\n<p>Start the MySQL process with the --skip-grant-tables option.</p>\n<p>Start the MySQL console client with the -u root option.</p>\n</blockquote>\n<p>List all the users;</p>\n<pre><code>SELECT * FROM mysql.user;\n</code></pre>\n<p>Reset password;</p>\n<pre><code>UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';\n</code></pre>\n<hr />\n<p>But <strong>DO NOT FORGET</strong> to</p>\n<blockquote>\n<p>Stop the MySQL process</p>\n<p>Start the MySQL Process normally (i.e. without the --skip-grant-tables option)</p>\n</blockquote>\n<p>when you are finished.  Otherwise, your database's security could be compromised.</p>\n"}, {'answer_id': 4403, 'author': 'jake', 'author_id': 389, 'author_profile': 'https://Stackoverflow.com/users/389', 'pm_score': 6, 'selected': False, 'text': '<p>Unfortunately your user password is irretrievable. It has been hashed with a one way hash which if you don\'t know is irreversible. I recommend go with Xenph Yan above and just create an new one.</p>\n\n<p>You can also use the following procedure from <a href="http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html" rel="noreferrer">the manual</a> for resetting the password for any MySQL <em>root</em> accounts on Windows:  </p>\n\n<ol>\n<li>Log on to your system as Administrator.  </li>\n<li>Stop the MySQL server if it is running. For a server that is running as a Windows service, go to\nthe Services manager:          </li>\n</ol>\n\n<blockquote>\n  <p>Start Menu -> Control Panel -> Administrative Tools -> Services</p>\n</blockquote>\n\n<p>Then find the MySQL service in the list, and stop it. If your server is\nnot running as a service, you may need to use the Task Manager to force it to stop.</p>\n\n<ol start="3">\n<li><p>Create a text file and place the following statements in it. Replace the password with the password that you want to use.</p>\n\n<pre><code>UPDATE mysql.user SET Password=PASSWORD(\'MyNewPass\') WHERE User=\'root\';\nFLUSH PRIVILEGES;\n</code></pre>\n\n<p>The <em>UPDATE</em> and <em>FLUSH</em> statements each must be written on a single line. The <em>UPDATE</em> statement resets the password for all existing root accounts, and the <em>FLUSH</em> statement tells the server to reload the grant tables into memory.</p></li>\n<li>Save the file. For this example, the file will be named <em>C:\\mysql-init.txt.</em></li>\n<li><p>Open a console window to get to the command prompt:      </p>\n\n<blockquote>\n  <p>Start Menu -> Run -> cmd</p>\n</blockquote></li>\n<li><p>Start the MySQL server with the special <em>--init-file</em> option:</p>\n\n<pre><code>C:\\&gt; C:\\mysql\\bin\\mysqld-nt --init-file = C:\\mysql-init.txt\n</code></pre>\n\n<p>If you installed MySQL to a location other than <em>C:\\mysql</em>, adjust the command accordingly.</p>\n\n<p>The server executes the contents of the file named by the <em>--init-file</em> option at startup, changing each <em>root</em> account password.</p>\n\n<p>You can also add the <em>--console</em> option to the command if you want server output to appear in the console window rather than in a log file.</p>\n\n<p>If you installed MySQL using the MySQL Installation Wizard, you may need to specify a <em>--defaults-file</em> option:</p>\n\n<pre><code>C:\\&gt; "C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqld-nt.exe" --defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini" --init-file=C:\\mysql-init.txt\n</code></pre>\n\n<p>The appropriate <em>--defaults-file</em> setting can be found using the Services Manager:</p>\n\n<blockquote>\n  <p>Start Menu -> Control Panel -> Administrative Tools -> Services</p>\n</blockquote>\n\n<p>Find the MySQL service in the list, right-click on it, and choose the Properties option. The Path to executable field contains the <em>--defaults-file</em> setting.</p></li>\n<li>After the server has started successfully, delete <em>C:\\mysql-init.txt</em>.</li>\n<li>Stop the MySQL server, then restart it in normal mode again. If you run the server as a service, start it from the Windows Services window. If you start the server manually, use whatever command you normally use.</li>\n</ol>\n\n<p>You should now be able to connect to MySQL as root using the new password. </p>\n'}, {'answer_id': 8078308, 'author': 'ThinkingMonkey', 'author_id': 858515, 'author_profile': 'https://Stackoverflow.com/users/858515', 'pm_score': 5, 'selected': False, 'text': '<p>An improvement to the most useful answer here:<br/></p>\n\n<blockquote>\n  <p>1] No need to restart the mysql server <br/>\n  2] Security concern for a MySQL server connected to a network<br/></p>\n</blockquote>\n\n<p>There is no need to restart the MySQL server.</p>\n\n<p>use <code>FLUSH PRIVILEGES;</code> after the update mysql.user statement for password change.</p>\n\n<blockquote>\n  <p>The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.</p>\n</blockquote>\n\n<p>The <code>--skip-grant-options</code> enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to </p>\n\n<blockquote>\n  <p>use <em>--skip-grant-tables</em> in conjunction with <em>--skip-networking</em> to prevent remote clients from connecting. </p>\n</blockquote>\n\n<p>from: reference: <a href="http://dev.mysql.com/doc/refman/5.6/en/resetting-permissions.html#resetting-permissions-generic" rel="noreferrer">resetting-permissions-generic</a></p>\n'}, {'answer_id': 27244876, 'author': 'Syeful Islam', 'author_id': 1468773, 'author_profile': 'https://Stackoverflow.com/users/1468773', 'pm_score': 2, 'selected': False, 'text': "<p>Login MySql from windows cmd using existing user:</p>\n\n<blockquote>\n  <blockquote>\n    <p>mysql -u username -p<br>\n            Enter password:****</p>\n  </blockquote>\n</blockquote>\n\n<p>Then run the following command:</p>\n\n<pre><code>mysql&gt; SELECT * FROM mysql.user;\n</code></pre>\n\n<p>After that copy encrypted md5 password for corresponding user and there are several online password decrypted application available in web. Using this decrypt password and use this for login in next time.\nor update user password using flowing command:</p>\n\n<pre><code>mysql&gt; UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';\n</code></pre>\n\n<p>Then login using the new password and user.</p>\n"}, {'answer_id': 30655524, 'author': 'shine', 'author_id': 4599830, 'author_profile': 'https://Stackoverflow.com/users/4599830', 'pm_score': -1, 'selected': False, 'text': '<p>Although a strict, logical, computer science\'ish interpretation of the op\'s question would be to require <strong>both</strong> "How do I retrieve my MySQL username" <strong>and</strong> "password" - I thought It might be useful to someone to also address the <strong>OR</strong> interpretation. In other words ...</p>\n\n<p>1) How do I retrieve my MySQL username?</p>\n\n<p><strong>OR</strong></p>\n\n<p>2) password</p>\n\n<p>This latter condition seems to have been amply addressed already so I won\'t bother with it. The following is a solution for the case "How do i retreive my MySQL username" alone. HIH.</p>\n\n<p>To find your mysql username run the following commands from the mysql shell ...</p>\n\n<p>SELECT User FROM mysql.user;</p>\n\n<p>it will print a table of all mysql users.</p>\n'}, {'answer_id': 33506775, 'author': 'snemarch', 'author_id': 430360, 'author_profile': 'https://Stackoverflow.com/users/430360', 'pm_score': 3, 'selected': False, 'text': '<p>While you can\'t directly recover a MySQL password without bruteforcing, there might be another way - if you\'ve used MySQL Workbench to connect to the database, and have saved the credentials to the "vault", you\'re golden.</p>\n\n<p>On Windows, the credentials are stored in <strong>%APPDATA%\\MySQL\\Workbench\\workbench_user_data.dat</strong> - encrypted with <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380261%28v=vs.85%29.aspx" rel="noreferrer">CryptProtectData</a> (without any additional entropy). Decrypting is easy peasy:</p>\n\n<pre><code>std::vector&lt;unsigned char&gt; decrypt(BYTE *input, size_t length) {\n    DATA_BLOB inblob { length, input };\n    DATA_BLOB outblob;\n\n    if (!CryptUnprotectData(&amp;inblob, NULL, NULL, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &amp;outblob)) {\n            throw std::runtime_error("Couldn\'t decrypt");\n    }\n\n    std::vector&lt;unsigned char&gt; output(length);\n    memcpy(&amp;output[0], outblob.pbData, outblob.cbData);\n\n    return output;\n}\n</code></pre>\n\n<p>Or you can check out this <a href="https://www.donationcoder.com/forum/index.php?topic=41860.msg391762#msg391762" rel="noreferrer">DonationCoder thread</a> for source + executable of a quick-and-dirty implementation.</p>\n'}, {'answer_id': 34945832, 'author': 'Sajjad Ashraf', 'author_id': 1131673, 'author_profile': 'https://Stackoverflow.com/users/1131673', 'pm_score': 3, 'selected': False, 'text': '<p>If you have root access to the server where mysql is running you should stop the mysql server using this command</p>\n\n<pre><code>sudo service mysql stop\n</code></pre>\n\n<p>Now start mysql using this command</p>\n\n<pre><code>sudo /usr/sbin/mysqld --skip-grant-tables  --skip-networking &amp;\n</code></pre>\n\n<p>Now you can login to mysql using </p>\n\n<pre><code>sudo mysql\nFLUSH PRIVILEGES;\nSET PASSWORD FOR \'root\'@\'localhost\' = PASSWORD(\'MyNewPass\');\n</code></pre>\n\n<p>Full instructions can be found here <a href="http://www.techmatterz.com/recover-mysql-root-password/" rel="noreferrer">http://www.techmatterz.com/recover-mysql-root-password/</a></p>\n'}, {'answer_id': 47018488, 'author': 'samplesize1', 'author_id': 3524173, 'author_profile': 'https://Stackoverflow.com/users/3524173', 'pm_score': 0, 'selected': False, 'text': '<p>IF you happen to have ODBC set up, you can get the password from the ODBC config file.  This is in /etc/odbc.ini for Linux and in the Software/ODBC folder in the registry in Windows (there are several - it may take some hunting)</p>\n'}, {'answer_id': 49207760, 'author': 'S.M.Mousavi', 'author_id': 1074799, 'author_profile': 'https://Stackoverflow.com/users/1074799', 'pm_score': 3, 'selected': False, 'text': "<h2>Do it without down time</h2>\n\n<p>Run following command in the Terminal to connect to the DBMS (you need root access):  </p>\n\n<pre><code>sudo mysql -u root -p;\n</code></pre>\n\n<p>run update password of the target user (for my example username is <code>mousavi</code> and it's password must be <code>123456</code>):  </p>\n\n<pre><code>UPDATE mysql.user SET authentication_string=PASSWORD('123456') WHERE user='mousavi';  \n</code></pre>\n\n<p>at this point you need to do a flush to apply changes:  </p>\n\n<pre><code>FLUSH PRIVILEGES;\n</code></pre>\n\n<p>Done! You did it without any stop or restart mysql service.</p>\n"}, {'answer_id': 58515936, 'author': 'user12261119', 'author_id': 12261119, 'author_profile': 'https://Stackoverflow.com/users/12261119', 'pm_score': 0, 'selected': False, 'text': '<p>Save the file. For this example, the file will be named C:\\mysql-init.txt.\nit asking administrative permisions for saving the file</p>\n'}, {'answer_id': 72846018, 'author': 'Raikish', 'author_id': 8018902, 'author_profile': 'https://Stackoverflow.com/users/8018902', 'pm_score': 0, 'selected': False, 'text': "<p><strong>After MySQL 5.7.6 and MariaDB 10.1.20 (currently in 2022) you can:</strong></p>\n<p>Update a mysql user password having access to root user</p>\n<pre><code>ALTER USER 'some_user_name'@'localhost' IDENTIFIED BY 'a_super_secure_password';\n</code></pre>\n<p>Update mysql root user</p>\n<pre><code>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'mynewpassword';\n</code></pre>\n<p>List all users</p>\n<pre><code>select user from mysql.user;\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/4371', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/131/']