Access denied for user 'root'@'localhost' (using password: YES) after new installation on Ubuntu

前端 未结 8 784
一个人的身影
一个人的身影 2020-12-04 06:09

Today I did a login as root into Ubuntu 14.04.1 LTS ll

and then apt-get install mariadb-server (without sudo but as root).

With mySQL -h l

相关标签:
8条回答
  • 2020-12-04 06:17

    System like Ubuntu prefers to use auth_socket plugin. It will try to authenticate by comparing your username in DB and process which makes mysql request; it is described in here

    The socket plugin checks whether the socket user name (the operating system user name) matches the MySQL user name specified by the client program to the server, and permits the connection only if the names match.

    Instead you may want to back with the mysql_native_password, which will require user/password to authenticate.

    About the method to achieve that, I recommend this instead.

    0 讨论(0)
  • 2020-12-04 06:18

    I had to be logged into Ubuntu as root in order to access Mariadb as root. It may have something to do with that "Harden ..." that it prompts you to do when you first install. So:

    $ sudo su
    [sudo] password for user: yourubunturootpassword
    # mysql -r root -p
    Enter password: yourmariadbrootpassword
    

    and you're in.

    0 讨论(0)
  • 2020-12-04 06:21

    Run mysql_upgrade.

    Check that

    SHOW GRANTS FOR 'root'@'localhost';
    

    says

    GRANT ALL PRIVILEGES ON ... WITH GRANT OPTION 
    

    Check that the table exists _mysql.proxies_priv_.

    Access denied for user 'root'@'localhost' while attempting to grant privileges. How do I grant privileges?

    0 讨论(0)
  • 2020-12-04 06:25

    In clean Ubuntu 16.04 LTS, MariaDB root login for localhost changed from password style to sudo login style...

    so, just do

    sudo mysql -u root
    

    since we want to login with password, create another user 'user'

    in MariaDB console... (you get in MariaDB console with 'sudo mysql -u root')

    use mysql
    CREATE USER 'user'@'localhost' IDENTIFIED BY 'yourpassword';
    \q
    

    then in bash shell prompt,

    mysql-workbench
    

    and you can login with 'user' with 'yourpassword' on localhost

    0 讨论(0)
  • 2020-12-04 06:27

    Try the command

    sudo mysql_secure_installation
    

    press enter and assign a new password for root in mysql/mariadb.

    If you get an error like

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

    enable the service with

    service mysql start
    

    now if you re-enter with

    mysql -u root -p
    

    if you follow the problem enter with sudo su and mysql -u root -p now apply permissions to root

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '<password>';

    this fixed my problem in MariaDB.

    Good luck

    0 讨论(0)
  • 2020-12-04 06:33

    The new command to flush the privileges is:

    FLUSH PRIVILEGES

    The old command FLUSH ALL PRIVILEGES does not work any more.

    You will get an error that looks like that:

    MariaDB [(none)]> FLUSH ALL PRIVILEGES; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ALL PRIVILEGES' at line 1

    Hope this helps :)

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