ERROR 1698 (28000): Access denied for user 'root'@'localhost'

后端 未结 17 1584
执笔经年
执笔经年 2020-11-22 10:00

I\'m setting up a new server and keep running into this problem.

When I try to login to the MySQL database with the root user, I get the error:

相关标签:
17条回答
  • 2020-11-22 10:37

    step 1. sudo mysql -u root -p

    step 2. USE mysql;

    step 3. ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'admin';

    Here 'admin' is your new password, yo can change it.

    step 4. exit

    Thanks. You are done.

    0 讨论(0)
  • 2020-11-22 10:38

    That worked for me:

    mysql --user=root mysql
    CREATE USER 'some_user'@'%' IDENTIFIED BY 'some_pass';
    GRANT ALL PRIVILEGES ON *.* TO 'some_user'@'%' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    
    0 讨论(0)
  • 2020-11-22 10:41

    I would suggest to remove the Mysql connection -

    UPDATE-This is for Mysql version 5.5,if your version is different ,please change the first line accordingly

    sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5
    sudo rm -rf /etc/mysql /var/lib/mysql
    sudo apt-get autoremove
    sudo apt-get autoclean
    

    And Install Again But this time set a root password yourself. This will save a lot of effort.

    sudo apt-get update
    sudo apt-get install mysql-server
    
    0 讨论(0)
  • 2020-11-22 10:46

    I was having this issue on an Debian 8 VM that I was interacting with through Putty on my Windows 10 desktop.

    I tried the various suggestions on here but nothing quite worked and I am running MariaDB on the Debian host. In the end I found that I couldn't start the db server in safe mode but I didn't need to and the following commands actually worked for me i.e. allowing a newly created MySql user to log into the MySql/MariaDB server:

    sudo service mysql restart
    sudo mysql # logs in automatically into MariaDB
    use mysql;
    update user set plugin='' where user='your_user_name';
    flush privileges;
    exit;
    sudo service mysql restart # restarts the mysql service
    

    If the above doesn't quite work for you, follow the steps outlined in zetacu's post above (zetacu) then follow my steps.

    Now you should be able to use a remote terminal client and securely log into mysql using the command:

    mysql -u your_user_name -p
    

    *type in the password when prompted

    0 讨论(0)
  • 2020-11-22 10:46

    I also faced the same issue at the first time.

    Now it is fixed:

    First, you copy the /etc/mysql/mysql.conf.d/mysqld.cnf file and past in to /etc/mysql/my.cnf.

    You can do it by command:

    sudo cp /etc/mysql/mysql.conf.d/mysqld.cnf /etc/mysql/my.cnf
    

    Now let's Rest the password:

    Use the following commands in your terminal:

    sudo service mysql stop 
    sudo service mysql start
    sudo mysql -u root
    

    Now you are inside the mysql console.

    Then let's write some queries to reset our root password

    USE mysql
    update mysql.user set authentication_string=password('newpass') where user='root' and Host ='localhost';
    update user set plugin="mysql_native_password"; 
    flush privileges;
    quit
    

    Now we can clean /etc/mysql/my.cng

    Open the above file in your editor and remove the whole lines inside the file.

    After that let's restart mysql:

    sudo mysql service restart 
    

    Now let's use mysql with newly created password:

    sudo mysql -u root -p
    

    Finally enter your newly created password.

    0 讨论(0)
  • 2020-11-22 10:48

    After hours of struggle with no solution here, this worked for me then I found a youtube video where it says the password column is now called authentication_string . So I was able to change my password as follows: First get into mysql from terminal

    sudo mysql
    

    then inside mysql type whatever after mysql>

    mysql> use mysql
    mysql> update user set authentication_string=PASSWORD("mypass") where user='root';
    mysql> flush privileges;
    mysql> quit;
    

    at this point you are out of mysql back to your normal terminal place. You need to restart mysql for this to take effect. for that type the following:

    sudo service mysql restart
    

    Refer to this video link for better understanding

    0 讨论(0)
提交回复
热议问题