Cannot connect to MYSQL Server using workbench [duplicate] - mysql

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

Related

How to reset MySQL root password using xampp/phpmyadmin? [duplicate]

I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts.
Since it is impossible to connect without the error:
# 1045 - Access denied for user 'root' # 'localhost' (using password: NO)
I have search a little on the net before, and even the technic:
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
does not work, or I didn't understood how it worked.
I'm on FreeBSD 8.1, my version of PhpMyadmin is 2.11.
Thank you in advance for your answers.
I summarised my solution here: http://snippets.dzone.com/posts/show/13267
sudo stop mysql
sudo mysqld --skip-grant-tables --skip-networking
mysql
mysql> update mysql.user set password = password('your_new_password') where user = 'root';
mysql> flush privileges;
mysql> exit;
sudo mysqladmin shutdown
sudo start mysql
For mysql 5.7.16 or later I found this (from mysql.com) to be the working solution. Below are some points which are different compared to previous older versions
1) I used the below command to run mysql in safe mode as per some other references which actually worked fine for me (mysql 5.7.16 ubuntu 16.04).
mysqld_safe --skip-grant-tables --skip-networking
2) The below update stmt is NOT working for later version (ie. 5.7 and above)
-- NOT Working for 5.7 and later
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
INSTEAD use below for 5.7.6 and later
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
OR user below for 5.7.5 or earlier versions.
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
I am Using MySQL Server 8 and this is how I solved this problem.
create a file and name it accordingly. I've named it as reset.txt. put below content in the file but change MyNewPass. This will be your new SQL password
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
Stop my SQL server (Go to services and search MYSQL and right-click on it and stop )
Now open a cmd in your bin folder of My SQLserver directory. in my case it's
C:\Program Files\MySQL\MySQL Server 8.0\bin
execute the following command.
mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\reset.txt'
NOTE: my reset.txt file is in the c drive. Give the correct path. Check my.ini file is in the directory. In my case, it is in
C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
Finally, restart the SQL Server. Check with your new password.
Please follow the instruction from the below link to reset your root password.You have to do it from outside mysql.
Resetting MySql Password
Forgetting your MySQL password can be a real headache for you.Here are some easy steps that you can follow to recover MySql password under Windows
Stop MySql
You have to stop MySql service before you proceed.In Windows environment, go to 'Task Manager' and Under 'Service' tab find MySQL and stop it.
Write Sql to change your password
All you need to do is to create a text file and put the below two lines into that. UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES; Save it under C:\ drive and give it a name 'mysql-init.txt'
Time to restart MySQL by your own.
Now it's time to restart your MySQl which you stopped in before but this time from command line. C:> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
Finishing up!
Now you can log in with your new password. When you finish remove the file that you created in the previous stage.
Also there is a link (http://kaziprogrammingblog.osinweb.com/article/showarticle/Resetting-MySql-Password) where I have explained the same thing.
Hope this will help..:)
Answer for XAMPP on Windows:
Edit C:\xampp\mysql\bin\my.ini and insert skip-grant-tables below [mysqld]
Restart MySQL from Control Panel interface
In the phpMyAdmin window, select SQL tab from the top panel. This will open the SQL tab where we can run the SQL queries. Now type the following query in the text area and click Go
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
Remove the skip-grant-tables in the my.ini file
Restart MySQL from Control Panel interface
DONE!
Be awared that mysql root user password does not have to be the same as password for phpmyadmin.
here is what I did and it worked:
After you install (rpm installation), do a vi /etc/my.cnf.
This will give you a path where your datadir is set. For me it was datadir=/var/lib/mysql.
Add a line there user=root, and remove all the content inside the datadir path: rm -rf /var/lib/mysql/*.
Now hit the command: mysqld --initialize.
A temporary password is generated at a location. For this:
grep "A temporary password" /var/log/*.
You will get a line that says:
/var/log/mysqld.log:2018-05-01T15:13:47.937449Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root#localhost: &uosjoGfi9:K. So for me &uosjoGfi9:K was my temporary password.
Now do a mysql -u root -p. Paste your temporary password from what you got from above.
You will be in your mysql cli mode. Now do:
mysql> use mysql;
You will be asked to reset your password:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Run your ALTER command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPswd';
And you are done.
in my case its a frustrating Windows Server installation (iis/php/mysql) so this is what i did:
PART 1: remove the old MYSQL :
NOTE: if you already have data you should back it up!
Step 1
Uninstall MySQL from Control Panel. (you should know how to do this)
Step 2
Run Command Prompt as Admini and execute the following commands to stop and remove MySQL service.
Net stop MySQL
Sc delete MySQL
Step 3
Delete these folders:
C:\Program Files\MySQL
C:\Program Files (x86)\MySQL
C:\ProgramData\MySQL
And if it exists:
C:\Users\[User-Name]\AppData\Roaming\MySQL
PART 2: Install MYSQL
Download installer from https://dev.mysql.com/downloads/installer/ and install
-MySQL Server 8.0.23
open cmd as admin and go to
c:\Program Files\MySQL\MySQL Server 8.0\bin\
run
mysqld --initialize --console
mysqld --install
now start the service (type services.msc in run panel)
now back to console run:
mysql -u root -p
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
that's it
mysql80:
update user SET authentication_string='your password after encode to sha256' where User='root';

Resetting mysql server root password on OS X

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'

Mysql to find password is forgetten

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.

mysql root password forgotten

I did not use PHP MySQL for quite a while and now I need to use it again. But the problem is I forget the password for the MySQL console. and getting error #1045 when trying to login in to PHPMyAdmin.
In the MySQL site I saw an article how to reset root password( http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html#resetting-permissions-windows)
Steps are
create a mysql-init.txt file containing UPDATE mysql.user SET Password=PASSWORD('newpass') WHERE User='root';
FLUSH PRIVILEGES;
I saved it as C:\me\mysql-init
and in command prompt I wrote--
C:\wamp\bin\mysql\mysql5.5.8\bin\mysqld --init-file=C:\me\mysql-init.txt
I tried with double backslashes also..but it is not working. MySQL console is asking for a password and it's not taking the new-one. What am I doing wrong? I have several tables there.what to do?
Thanks in advance.
Here are the steps to be followed:
Locate the MySQL configuration file using: $ mysql --help | grep -A 1 "Default options"
On Ubuntu 16, the file location is typically /etc/mysql/mysql.conf.d/mysqld.cnf
Edit the configuration file using: $ sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Add skip-grant-tables under [mysqld] block and save the changes.
Restart MySQL service using: sudo service mysql restart
Check MySQL service status: sudo service mysql status
Login to mysql with: $ mysql -u root
And change the root password:
mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH
mysql_native_password BY 'MyNewPass';
Revert back the MySQL configuration file changes by removing skip-grant-tables line or commenting it with a # (hash).
Finally restart the MySQL service and you are good to go.
I couldn't get mysqld in Adelave's answer to work. But this worked for me instead
stop and start mysql with --skip-grant-tables
service mysql.server stop
service mysql.server start --skip-grant-tables
then connect to your mysqld without username/password
mysql
then update the password on mysql command line
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> \q
then restart mysql normally
service mysql.server restart
try to start mysql with --skip-grant-tables
mysqld --skip-grant-tables
then connect to your mysqld without username/password using mysql command line
shell> mysql
then issue command
> mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
> WHERE User='root'; mysql> FLUSH PRIVILEGES;
If other answer could not help, you can try to uninstall/re-install mysql. It works on my ubuntu server:
$sudo apt-get purge mysql*
$sudo apt-get autoremove
$sudo apt-get autoclean
Update distribution
$sudo apt-get dist-upgrade
And re-install
$sudo apt-get install mysql-server
Mac OS Mojave
$ brew services stop mysql
$ pkill mysqld
// warning: deletes all tables
$ rm -rf /usr/local/var/mysql/
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'p4ssword';
Query OK, 0 rows affected (0.04 sec)
mysql> exit
Bye
Then you are back to normal for dev.
$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
I don't like to see the word root in my .env files, so I usually do this after, if making a site such as www.hockeysticks.net:
#
CREATE DATABASE hockeysticks;
CREATE USER 'hockeysticks'#'localhost' IDENTIFIED BY 'hockeysticks';
GRANT ALL PRIVILEGES ON hockeysticks.* TO 'hockeysticks'#'localhost';
Then your localdev .env file is simple:
DB_DATABASE=hockeysticks
DB_USERNAME=hockeysticks
DB_PASSWORD=hockeysticks
Note: If you need to retain your databases, use the skip-grant-tables method. That has 3 hard parts:
Make sure MySQL is stopped, so you can restart it with skip-grant-tables
Make sure your password update SQL syntax is correct for your MySQL version
Make sure you append the end of the query with FLUSH PRIVELEGES;
Using windows command prompt you can change the password
Go to windows+R and run services.msc and then stop the MySQL services and see the properties of MySQL by right click and copy the path --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" as it required later.
Create text file reset.txt with the text ALTER USER 'root'#'localhost' IDENTIFIED BY 'Your New Password'; and save in C drive.
open the command prompt as administrator then change the directory where your MySQL is installed "C:\Program Files\MySQL\MySQL Server 8.0\bin".
Type the command mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file=C:\\reset.txt
Using SQLYog you can execute commands
User Creation
CREATE USER 'tester'#'localhost' IDENTIFIED BY 'Pass123#d'
Authorization
GRANT ALL PRIVILEGES ON sakila.* TO 'tester'#'localhost'
Changing Password in MySQL 8.0
ALTER USER 'tester'#'localhost' IDENTIFIED BY 'Pass123#d'
(or if u know the authentication_string directly set it to update)
UPDATE mysql.user
SET authentication_string='*F9B62579F38BE95639ACB009D79427F2D617158F'
WHERE USER='root'***
Changing password in lower versions of mysql
GRANT USAGE ON *.\* TO 'tester'#'localhost' IDENTIFIED BY 'Pass123#d'
SET PASSWORD FOR 'tester'#'localhost' = PASSWORD('Pass123#d');**

How to reset mysql root password?

I have a little problem with my phpmyadmin, in fact I accidentally delete multiple user accounts.
Since it is impossible to connect without the error:
# 1045 - Access denied for user 'root' # 'localhost' (using password: NO)
I have search a little on the net before, and even the technic:
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
does not work, or I didn't understood how it worked.
I'm on FreeBSD 8.1, my version of PhpMyadmin is 2.11.
Thank you in advance for your answers.
I summarised my solution here: http://snippets.dzone.com/posts/show/13267
sudo stop mysql
sudo mysqld --skip-grant-tables --skip-networking
mysql
mysql> update mysql.user set password = password('your_new_password') where user = 'root';
mysql> flush privileges;
mysql> exit;
sudo mysqladmin shutdown
sudo start mysql
For mysql 5.7.16 or later I found this (from mysql.com) to be the working solution. Below are some points which are different compared to previous older versions
1) I used the below command to run mysql in safe mode as per some other references which actually worked fine for me (mysql 5.7.16 ubuntu 16.04).
mysqld_safe --skip-grant-tables --skip-networking
2) The below update stmt is NOT working for later version (ie. 5.7 and above)
-- NOT Working for 5.7 and later
UPDATE mysql.user SET Password = PASSWORD ('') WHERE User = 'root';
FLUSH PRIVILEGES;
INSTEAD use below for 5.7.6 and later
UPDATE mysql.user
SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
OR user below for 5.7.5 or earlier versions.
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
I am Using MySQL Server 8 and this is how I solved this problem.
create a file and name it accordingly. I've named it as reset.txt. put below content in the file but change MyNewPass. This will be your new SQL password
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
Stop my SQL server (Go to services and search MYSQL and right-click on it and stop )
Now open a cmd in your bin folder of My SQLserver directory. in my case it's
C:\Program Files\MySQL\MySQL Server 8.0\bin
execute the following command.
mysqld.exe --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --init-file="C:\reset.txt'
NOTE: my reset.txt file is in the c drive. Give the correct path. Check my.ini file is in the directory. In my case, it is in
C:\ProgramData\MySQL\MySQL Server 8.0\my.ini
Finally, restart the SQL Server. Check with your new password.
Please follow the instruction from the below link to reset your root password.You have to do it from outside mysql.
Resetting MySql Password
Forgetting your MySQL password can be a real headache for you.Here are some easy steps that you can follow to recover MySql password under Windows
Stop MySql
You have to stop MySql service before you proceed.In Windows environment, go to 'Task Manager' and Under 'Service' tab find MySQL and stop it.
Write Sql to change your password
All you need to do is to create a text file and put the below two lines into that. UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root'; FLUSH PRIVILEGES; Save it under C:\ drive and give it a name 'mysql-init.txt'
Time to restart MySQL by your own.
Now it's time to restart your MySQl which you stopped in before but this time from command line. C:> C:\mysql\bin\mysqld-nt --init-file=C:\mysql-init.txt
Finishing up!
Now you can log in with your new password. When you finish remove the file that you created in the previous stage.
Also there is a link (http://kaziprogrammingblog.osinweb.com/article/showarticle/Resetting-MySql-Password) where I have explained the same thing.
Hope this will help..:)
Answer for XAMPP on Windows:
Edit C:\xampp\mysql\bin\my.ini and insert skip-grant-tables below [mysqld]
Restart MySQL from Control Panel interface
In the phpMyAdmin window, select SQL tab from the top panel. This will open the SQL tab where we can run the SQL queries. Now type the following query in the text area and click Go
UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
Remove the skip-grant-tables in the my.ini file
Restart MySQL from Control Panel interface
DONE!
Be awared that mysql root user password does not have to be the same as password for phpmyadmin.
here is what I did and it worked:
After you install (rpm installation), do a vi /etc/my.cnf.
This will give you a path where your datadir is set. For me it was datadir=/var/lib/mysql.
Add a line there user=root, and remove all the content inside the datadir path: rm -rf /var/lib/mysql/*.
Now hit the command: mysqld --initialize.
A temporary password is generated at a location. For this:
grep "A temporary password" /var/log/*.
You will get a line that says:
/var/log/mysqld.log:2018-05-01T15:13:47.937449Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root#localhost: &uosjoGfi9:K. So for me &uosjoGfi9:K was my temporary password.
Now do a mysql -u root -p. Paste your temporary password from what you got from above.
You will be in your mysql cli mode. Now do:
mysql> use mysql;
You will be asked to reset your password:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
Run your ALTER command:
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPswd';
And you are done.
in my case its a frustrating Windows Server installation (iis/php/mysql) so this is what i did:
PART 1: remove the old MYSQL :
NOTE: if you already have data you should back it up!
Step 1
Uninstall MySQL from Control Panel. (you should know how to do this)
Step 2
Run Command Prompt as Admini and execute the following commands to stop and remove MySQL service.
Net stop MySQL
Sc delete MySQL
Step 3
Delete these folders:
C:\Program Files\MySQL
C:\Program Files (x86)\MySQL
C:\ProgramData\MySQL
And if it exists:
C:\Users\[User-Name]\AppData\Roaming\MySQL
PART 2: Install MYSQL
Download installer from https://dev.mysql.com/downloads/installer/ and install
-MySQL Server 8.0.23
open cmd as admin and go to
c:\Program Files\MySQL\MySQL Server 8.0\bin\
run
mysqld --initialize --console
mysqld --install
now start the service (type services.msc in run panel)
now back to console run:
mysql -u root -p
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
that's it
mysql80:
update user SET authentication_string='your password after encode to sha256' where User='root';