I forgot MySql root password. How can I find it?
How can I back up database and import new database?
I tried to change root password and authority in user password, in this file;
"c:/Program Data/MySql/MySql Server 5.6/data/mysql/user.frm"
enter image description here
Mysql change forgotted password
0) shut down service mysql56
1) go to C:\ProgramData\MySQL\MySQL Server 5.6
(note that ProgramData is a hidden folder)
2) look for file my.ini, open it and add one line skip-grant-tables below [mysqld],
save [mysqld]
skip-grant-tables
3) start service mysql56
4) by right, you can access the database, and use the query below to update the password
update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';
5) shun down the service again, remove the line skip-grant-tables save it, and start the service again. try to use the password you set to login.
To reset the password
Follow these steps (can be helpful if you really forget your password and you can try it anytime, even if you're not in the situation at the moment):
Stop mysql
sudo /etc/init.d/mysql stop
or for other distro versions
sudo /etc/init.d/mysqld stop
Start MySQL in safe mode
sudo mysqld_safe --skip-grant-tables &
Log into MySQL using root
mysql -uroot
Select the MySQL database to use
use mysql;
Reset the password
update user set password=PASSWORD("mynewpassword") where User='root';
Flush the privileges
flush privileges;
Restart the server
quit
Stop and start the server again
ubuntu and debian
sudo /etc/init.d/mysql stop
...
sudo /etc/init.d/mysql start
On CentOS and Fedora and RHEL
sudo /etc/init.d/mysqld stop
...
sudo /etc/init.d/mysqld start
Login with new password
mysql -u root -p
Type new password and enjoy your server again like nothing happened
taken from mysql-resetting-a-lost-mysql-root-password
The wiki also explains other ways to reset the password using a text file.
Related
I have been following these instructions for resetting root password for local installation of MySQL 5.6 on Windows 7 laptop.
I stopped the service, created init-file, and ran the following command (as Administrator):
"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqld" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.6\my.ini" --init-file=C:\\MySQL-misc\\mysql-init.txt
I got the following warning:
2014-02-08 15:44:10 0 [Warning] TIMESTAMP with implicit DEFAULT value
is deprecated. Please use --explicit_defaults_for_timestamp server
option (see documentation for more details).
Since it's a warning I'm not sure whether I need to fix anything and then redo the process again.
Currently the command window is still on and does not accept any input. Should I force-close it or is there anything I can do to complete the process gracefully?
UPDATE
I killed the Command window and tried to restart the service. Got an error.
Restarted Windows and the service automatically started. The new root password seems to work. I was successfully able to use various functions of Workbench that require the password.
So, the warning was indeed just a warning.
On Windows:
0) shut down service mysql56
1) go to C:\ProgramData\MySQL\MySQL Server 5.6, note that ProgramData is a hidden folder
2) looking for file my.ini, open it and add one line skip-grant-tables below [mysqld],save
[mysqld]
skip-grant-tables
3) start service mysql56
4) by right, you can access the database, run mysql
5) and use the query below to update the password
update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';
note: for newer version, use authentication_string instead of password
6) shut down the service again, remove the line skip-grant-tables save it, and start the service again. try to use the password you set to login.
On Mac:
0) stop the service
sudo /usr/local/mysql/support-files/mysql.server stop
1) skip grant table
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
once it's running, don't close it, and open a new terminal window
2) go into mysql terminal
/usr/local/mysql/bin/mysql -u root
3) update the password
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
for newer version like 5.7, use
UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';
4) run FLUSH PRIVILEGES;
5) run \q to quit
6) start the mysql server
sudo /usr/local/mysql/support-files/mysql.server start
Stop Mysql service by going into Administrative tools > Services
Open Start > Run > cmd (Run as administrator)
Start the server manually using this line:
mysqld -P3306 --skip-grant-tables
In new cmd (Run as administrator) execute :
mysql -P3306 mysql
Execute the following query in mysql client:
update mysql.user set authentication_string=password('new_password') where user='root';
That's it!!
The issue has been resolved.
As stated in my question I followed instructions from MySQL manual.
The process did not go exactly as described (and this was the reason for my original post) but it worked nevertheless (see UPDATE section in my post).
Updating this answer regarding to changes at MySQL 5.7:
0) shut down service mysql57
1) go to C:\ProgramData\MySQL\MySQL Server 5.7, note that ProgramData is a hidden folder
2) looking for file my.ini, open it and add one line skip-grant-tables below [mysqld],save
[mysqld]
skip-grant-tables
3) start service mysql57
4) by right, you can access the database, run mysql
5) and use the query below to update the password
update mysql.user set authentication_string=password('NEW_PASSWORD') where user='root';
6) shut down the service again, remove the line skip-grant-tables save it, and start the service again. try to use the password you set to login.
First stop mysql server and follow below steps:
Go to mysql bin directory on cmd i,e. cd C:\ProgramData\MySQL\MySQL Server 5.6\bin (Its a hidden directory)
skip grant tables will allow you enter into mysql
mysqld.exe --skip-grant-tables
Open new command prompt or on same command prompt
mysql.exe -uroot -p (without any password you can login to mysql)
run below query to change mysql root password
UPDATE mysql.user set password=password('root password') WHERE user='root';
flush privileges
Thats it, Restart mysql and good to go with new password..!!
If you are getting this error: mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. when attempting to reset your root password. You might try:
sudo service mysql stop
sudo mkdir -p /var/run/mysqld
sudo chown mysql:mysql /var/run/mysqld
sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
mysql -uroot
update mysql.user set authentication_string=password('your_password') where user='root';
flush privileges;
quit
sudo killall mysql
sudo service mysql start
mysql -u root -pyour_password
Tested in MySQL 5.7 running in Ubuntu 18.04
In case if you have Xampp installed.
Goto C:\xampp\mysql\bin
Open my.ini file
Put skip-grant-tables under [mysqld]
Goto windows services and stop mysql service
Trigger this command from command prompt C:\xampp\mysql\bin\mysql
Now, reset the root password with the MySQL query update mysql.user set password=PASSWORD('root') where user='root';
Exit the command prompt.
Restart the mysql windows service that was turned off in step 4.
Now you will be able to login to mysql using password as root.
For MySQL 5.6 on Windows I had to run this statement to make it work.
UPDATE mysql.user
SET Password=PASSWORD('NEW PASSWORD'),
authentication_String=PASSWORD('NEW PASSWORD')
WHERE User='root';
Without editing mi.ini:
service mysql stop
mysqld_safe --skip-grant-tables
on a separate ssh session:
update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';
no need to flush privileges, just restart the server
I have a problem with MySQL. I forgot the password I used when I installed it
so, I can not access to the server now.
I tried deleting the MySQL and install it again but it didn't show the password again.
So I tried to do it by the terminal and this is the result ...
first i stopped the MySQL server
then i put sudo /usr/local/mysql/bin/mysqld_safe –skip-grant-tables in the terminal
after that in new terminal window i wrote sudo /usr/local/mysql/bin/mysql -u root
UPDATE mysql.user SET Password=PASSWORD('root') WHERE User='root';
FLUSH PRIVILEGES;
\q
the result was "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)"
these are all the commands
Try this command. I believe you should have mysql running. If that doesn't work try with mysql stopped.
sudo mysql_secure_installation
Hopefully should get you to prompt a password change.
Also, for the socket error, you can try following this link.
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
You can try reseting the root password by running MySQL in Safe Mode.
Here are the steps:
Stop MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables
This will be an ongoing command until the process is finished so open another shell/terminal window, and..
Log in without a password as root:
mysql -u root
Update root (and any other user's) password)
FLUSH PRIVILEGES;
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
\q
Restart MySQL in normal mode
sudo /usr/local/mysql/support-files/mysql.server start
Reference: https://coolestguidesontheplanet.com/how-to-change-the-mysql-root-password/
Note: this is pretty standard reset procedure, but just documented better in the above guide compared to mysql reference docs.
First of all, I know there are several threads, but I have tried so many solutions and I cant get anything to work.
I dont have any experience with mysql server and Terminal.
I downloaded mysql server 5.7.19
Following the answer from redtek, here: Setting the MySQL root user password on OS X
I open mysql from system setting, click stop server. Then I open the terminal and write
sudo mysqld_safe --skip-grant-tables
I asks me for my password (I assume this is the same when I start my computer). I get a message that command not found.
MacBook-Pro:~ XXXXXX$ sudo mysqld_safe --skip-grant-tables
Password:
sudo: mysqld_safe: command not found
MacBook-Pro:~ XXXXXX$
UPDATE: When I run the solution below, after opening a new window I get the following errors:
Last login: Sun Aug 13 16:51:49 on ttys002
MacBook-Pro:~ XXXXX$ mysql -u root
-bash: mysql: command not found
MacBook-Pro:~ XXXXX$ UPDATE mysql.user SET Password=PASSWORD('my-new-password') WHERE User='root';
-bash: syntax error near unexpected token `('
MacBook-Pro:~ XXXXX$ FLUSH PRIVILEGES;
-bash: FLUSH: command not found
MacBook-Pro:~ XXXXX$ \q
Stop the MySQL server.
sudo /usr/local/mysql/support-files/mysql.server stop
Restart it with the --skip-grant-tables option.
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
Open another terminal to connect to the MySQL server using the mysql client.
cd /usr/local/mysql/bin
mysql
Tell the server to reload the grant tables so that account-management statements work.
FLUSH PRIVILEGES;
Now reset the password for root user
MySQL 5.7.6 and later:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
Stop the server and restart it normally
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start
First step is to stop MySQL service.
sudo /usr/local/mysql/support-files/mysql.server stop
Then you need to start it in safe mode
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
secondly: let's open another shell/terminal window, log in with no password
mysql -u root
UPDATE mysql.user SET Password=PASSWORD('my-new-password') WHERE User='root';
FLUSH PRIVILEGES;
\q
Because in MySQL 5.7, the password field in mysql.user table is removed, now the field name is 'authentication_string'.
mysql -u root
UPDATE mysql.user SET authentication_string=PASSWORD('my-new-password') WHERE User='root';
FLUSH PRIVILEGES;
\q
Now again yu need to start the MySQL server
sudo /usr/local/mysql/support-files/mysql.server start
The command is not found because MySQL installation folder ( /usr/local/mysql/ ) is not included in the system variable PATH.
You can add to PATH
OR you can use full path /usr/local/mysql/bin/mysqld_safe
It took me a while in resolving this, considering most solutions around are for versions lower than MySQL version 5.7
Follow this below and it could help get you sorted as well.
For Safely ensuring process:
- Turn off the tick on "Automatically Start MySQL Server on Startup" inside System Preferences of MySQL (spotlight - mysql)
Open Terminal and type sudo /usr/local/mysql/support-files/mysql.server start -PS: This is for ensuring its in-line, times were that the next processes were breaking on me.
Now shut the MySQL service: sudo /usr/local/mysql/support-files/mysql.server stop
Type sudo mysqld_safe --skip-grant-tables
This will have now bypassed the security for MySQL - not safe for operations and not a permanent solution to always allow you to use MySQL.
Currently, as you would see, its in a process... This will allow us to do following steps. Leave this tab of Terminal OPEN throughout remaining process!!
Now Cmd+N (new terminal window), and in the new terminal:
- sudo /usr/local/mysql/support-files/mysql.server start
- update user set authentication_string=password(‘jj’) where user='root'
This on older version would have been as update user set password=PASSWORD(“jj”) where user='root’;
- FLUSH PRIVILEGES; //This is essential (updates disk instead of cache) to ensuring the next time around when you close mysql and get back it stays accessible as you setup.
- \q or quit
Close it all down - All terminals, give your computer a restart, and ensure everything is in order (ofcourse this entails - restart - open terminal - mysql -u root -p (enter) - respond with password you gave on steps above).
In my answer: jj was the password set
Cool-Stuff for General knowledge of fairly new (this somehow immediately worked for me after saying Password is not a field or something of sorts, on going in this new Terminal at update user set authentication_string=password(‘jj’) where user='root', so if you had the same, go at it in following steps - in >mysql itself where you are..):
- use mysql;
- show tables;
- describe user;
and then continue as steps above from the point of update user set authentication_string=password(‘jj’) where user='root'
I using mariadb and my mysql root user lost all of privelages. so everything gives me the "access denied" now.
I tried to reinstall mysql but it's looks like the configure files not deleted.
how can I fix it when I can't access to mysql table and even can't have another fress install.
by the way I using ubuntu 16.04 and according to this question
How do I restore the MySQL root user's privileges?
I think I can't do any thing except remove mariadb completely with all configure files.
------------------update------------------
I have no problem with my password, the problem is my root user has no privelages.
please don't send solutions about changing password
Enter the following lines in your terminal.
Stop the MySQL Server.
sudo /etc/init.d/mysql stop
Start the mysqld configuration.
sudo mysqld --skip-grant-tables &
Login to MySQL as root.
mysql -u root mysql
Replace YOURNEWPASSWORD with your new password!
UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
In my php my admin(mysql) was a password,but I change it and marked AllowNoPassword in ubuntu12.04.
After then I am unable to enter my phpmyadin it shows "Login without a password is forbidden by configuration (see AllowNoPassword)".
Please help me how can i access my mysql data or change my password.
You can run following command from the terminal for changing the user password:-
mysqladmin -u root -p PASSWORD YOUR_NEW_PASSWORD
Press Enter
It will ask for current password
Give current password there
Done
TQ, Ok the problem is solved.
For this I have used a command, for you I mentioned it to below:
**Stop the MySQL Server.
sudo /etc/init.d/mysql stop
Start the mysqld configuration.
sudo mysqld --skip-grant-tables &
Login to MySQL as root.
mysql -u root mysql
Replace YOURNEWPASSWORD with your new password!
UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
**
The problem is solved. For this I have used a command, for you I mentioned it below:
Stop the MySQL Server.
sudo /etc/init.d/mysql stop
Start the mysqld configuration.
sudo mysqld --skip-grant-tables &
Login to MySQL as root.
mysql -u root mysql
Replace YOURNEWPASSWORD with your new password!
UPDATE user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
you should have the following lines in your config
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = true;
link
Stop the mysql demon process using this command :
sudo /etc/init.d/mysql stop
Start the mysqld demon process using the --skip-grant-tables option with this command
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
Because you are not checking user privs at this point, it's safest to disable networking. In Dapper, /usr/bin/mysqld... did not work. However, mysqld --skip-grant-tables did.
start the mysql client process using this command
mysql -u root
from the mysql prompt execute this command to be able to change any password
FLUSH PRIVILEGES;
Then reset/update your password
SET PASSWORD FOR root#'localhost' = PASSWORD('password');
If you have a mysql root account that can connect from everywhere, you should also do:
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
link