[ACCEPTED]-MySQL: can't access root account-mysql-error-1045
You can use the init files. Check the MySQL 11 official documentation on How to Reset the Root Password (including comments 10 for alternative solutions).
So basically 9 using init files, you can add any SQL queries 8 that you need for fixing your access (such 7 as GRAND
, CREATE
, FLUSH PRIVILEGES
, etc.) into init file (any file).
Here 6 is my example of recovering root account:
echo "CREATE USER 'root'@'localhost' IDENTIFIED BY 'root';" > your_init_file.sql
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;" >> your_init_file.sql
echo "FLUSH PRIVILEGES;" >> your_init_file.sql
and 5 after you've created your file, you can 4 run:
killall mysqld
mysqld_safe --init-file=$PWD/your_init_file.sql
then to check if this worked, press 3 Ctrl+Z and type: bg
to run the process from the 2 foreground into the background, then verify 1 your access by:
mysql -u root -proot
mysql> show grants;
+-------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' |
See also:
This worked for me:
https://blog.dotkam.com/2007/04/10/mysql-reset-lost-root-password/
Step 1: Stop MySQL daemon 8 if it is currently running
ps -ef | grep mysql - checks if mysql/mysqld is one of the running processes.
pkill mysqld - kills the daemon, if it is running.
Step 2: Run MySQL 7 safe daemon with skipping grant tables
mysqld_safe --skip-grant-tables &
mysql -u root mysql
Step 6 3: Login to MySQL as root with no password
mysql -u root mysql
Step 5 4: Run UPDATE query to reset the root password
UPDATE user SET password=PASSWORD("value=42") WHERE user="root";
FLUSH PRIVILEGES;
In 4 MySQL 5.7, the 'password' field was removed, now 3 the field name is 'authentication_string':
UPDATE user SET authentication_string=PASSWORD("42") WHERE
user="root";
FLUSH PRIVILEGES;
Step 2 5: Stop MySQL safe daemon
Step 6: Start MySQL 1 daemon
There is a section in the MySQL manual on 1 how to reset the root password which will solve your problem.
I got the same problem when accessing mysql 13 with root. The problem I found is that some 12 database files does not have permission 11 by the mysql user, which is the user that 10 started the mysql server daemon.
We can 9 check this with ls -l /var/lib/mysql
command, if the mysql user 8 does not have permission of reading or writing 7 on some files or directories, that might 6 cause problem. We can change the owner or 5 mode of those files or directories with 4 chown/chmod
commands.
After these changes, restart 3 the mysqld daemon and login with root with 2 command:
mysql -u root
Then change passwords or create 1 other users for logging into mysql.
HTH
This code is solution for me
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pWKQiSdwMBZDJfWZEnxgEHCPl4GgkJ';
0
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.