How to reset mysql root password in fedora 37?

Fedora 37 x64 # Mysql reset root password?

how to reset mysql root password ??
i have tried:

[kabir@fedora ~]$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

to reset password i have followed these instructions:

[kabir@fedora ~]$ sudo systemctl stop mysql
Failed to stop mysql.service: Unit mysql.service not loaded.

[kabir@fedora ~]$ sudo systemctl status mysql
Unit mysql.service could not be found.

[kabir@fedora ~]$ sudo mysqld_safe --skip-grant-tables --skip-networking &
[2] 8803
[kabir@fedora ~]$ sudo: mysqld_safe: command not found

[2]- Exit 1 sudo mysqld_safe --skip-grant-tables --skip-networking

[kabir@fedora ~]$ sudo mkdir -p /var/run/mysqld
[kabir@fedora ~]$ sudo chown -R mysql:mysql /var/run/mysqld
[kabir@fedora ~]$ sudo mysqld_safe --skip-grant-tables --skip-networking &
[2] 8830
[kabir@fedora ~]$ sudo: mysqld_safe: command not found

[2]- Exit 1 sudo mysqld_safe --skip-grant-tables --skip-networking
[kabir@fedora ~]$ mysql
ERROR 1045 (28000): Access denied for user ‘kabir’@‘localhost’ (using password: NO)

I am using FEDORA 37.

Try this:

1 Like

You would use sudo -u mysql before running these commands. They are meant to be ran as the mysql user and running them as root can cause permissions problems.

1 Like

Problem Not Solved

[kabir@fedora ~]$ sudo /etc/init.d/mysqld stop
[sudo] password for kabir:
sudo: /etc/init.d/mysqld: command not found
[kabir@fedora ~]$ sudo /etc/init.d/mysqld stop
sudo: /etc/init.d/mysqld: command not found
[kabir@fedora ~]$ mysql -uroot
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
[kabir@fedora ~]$ update user set password=PASSWORD(“0000”) where User=‘root’;
bash: syntax error near unexpected token `(’
[kabir@fedora ~]$ sudo /etc/init.d/mysqld stop
sudo: /etc/init.d/mysqld: command not found
[kabir@fedora ~]$ sudo /etc/init.d/mysqld start
sudo: /etc/init.d/mysqld: command not found
[kabir@fedora ~]$

[kabir@fedora ~]$ sudo -u mysql
usage: sudo -h | -K | -k | -V
usage: sudo -v [-ABknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-ABknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-ABbEHknPS] [-r role] [-t type] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s] []
usage: sudo -e [-ABknS] [-r role] [-t type] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file …
[kabir@fedora ~]$ sudo mysqld_safe
[sudo] password for kabir:
sudo: mysqld_safe: command not found
[kabir@fedora ~]$

First please tell us the source and version of your Mysql installation.

I have found this:

And here the manual to reset the root password:

https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html

1 Like

You should be starting/stopping with systemctl start mysql and systemctl stop mysql. Since you’ve been doing sudo mysql... without sudo -u mysql mysql..., you might need to run these commands to fix permissions:

sudo chown -R mysql:mysql /var/lib/mysql
sudo chown -R mysql:mysql /var/log/mariadb

If you installed Oracle’s mysql instead of the default mariadb distribution you might also need to sudo chown -R mysql:mysql /var/log/mysql .

Refer to the Fedora docs moving forward from here:

Here are the instructions for finding and changing the initial temporary password:

1 Like

[kabir@fedora ~]$ sudo rpm -e --nodeps mysql-community-libs mysql-community-common mysql-community-server
[sudo] password for kabir:
Removed “/etc/systemd/system/multi-user.target.wants/mysqld.service”.
[kabir@fedora ~]$ msql
bash: msql: command not found…

[kabir@fedora ~]$ sudo dnf remove mysql-community-client
[sudo] password for kabir:
Dependencies resolved.

Package Architecture Version Repository Size

Removing:
mysql-community-client x86_64 8.0.31-10.fc37 @mysql80-community 73 M
Removing dependent packages:
mysqltuner noarch 1.8.3-3.git.1333ea9.fc37 @fedora 297 k
Removing unused dependencies:
mysql-community-client-plugins x86_64 8.0.31-10.fc37 @mysql80-community 6.9 M

Transaction Summary

Remove 3 Packages

Freed space: 80 M
Is this ok [y/N]: y

[kabir@fedora ~]$ sudo dnf install mariadb-server
Last metadata expiration check: 2:49:01 ago on Tuesday 10 January 2023 12:44:19 PM.
Dependencies resolved.

Package Architecture Version Repository Size

Installing:
mysql-community-server x86_64 8.0.31-10.fc37 mysql80-community 20 M
Installing dependencies:
mysql-community-client x86_64 8.0.31-10.fc37 mysql80-community 4.2 M
mysql-community-client-plugins x86_64 8.0.31-10.fc37 mysql80-community 1.3 M
mysql-community-common x86_64 8.0.31-10.fc37 mysql80-community 537 k
mysql-community-libs x86_64 8.0.31-10.fc37 mysql80-community 1.5 M

Transaction Summary

Install 5 Packages

Total download size: 28 M
Installed size: 208 M
Is this ok [y/N]: y

[kabir@fedora ~]$ sudo systemctl enable mysqld
[kabir@fedora ~]$ sudo systemctl status mysqld
○ mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
Active: inactive (dead) since Tue 2023-01-10 15:28:54 IST; 10min ago
Duration: 3h 5min 32.331s
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 1340 (code=exited, status=0/SUCCESS)
Status: “Server shutdown complete”
CPU: 45.488s

Jan 10 12:23:16 fedora systemd[1]: Starting mysqld.service - MySQL Server…
Jan 10 12:23:21 fedora systemd[1]: Started mysqld.service - MySQL Server.
Jan 10 15:28:53 fedora systemd[1]: Stopping mysqld.service - MySQL Server…
Jan 10 15:28:54 fedora systemd[1]: mysqld.service: Deactivated successfully.
Jan 10 15:28:54 fedora systemd[1]: Stopped mysqld.service - MySQL Server.
Jan 10 15:28:54 fedora systemd[1]: mysqld.service: Consumed 45.488s CPU time.
[kabir@fedora ~]$ sudo systemctl start mysqld
[kabir@fedora ~]$ sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; preset: disabled)
Active: active (running) since Tue 2023-01-10 15:39:29 IST; 3s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 53538 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 53566 (mysqld)
Status: “Server is operational”
Tasks: 39 (limit: 9346)
Memory: 508.2M
CPU: 2.353s
CGroup: /system.slice/mysqld.service
└─53566 /usr/sbin/mysqld
[kabir@fedora ~]$ sudo grep ‘temporary password’ /var/log/mysqld.log
2023-01-08T15:46:32.266693Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: *********

[kabir@fedora ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.31

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> quit
Bye

[kabir@fedora ~]$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
The ‘validate_password’ component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

{Change your root password configure the installation…}

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : n

… skipping.

Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

… skipping.
By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n

… skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : n

… skipping.
All done!
[kabir@fedora ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> quit
Bye

Its working Now Thanks!

1 Like