无法使用Mysql root帐户登录,但可以在ubuntu 16.04中使用sudo命令时登录

时间:2016-09-02 05:52:35

标签: mysql ubuntu

无法使用Mysql root帐户登录,但可以在ubuntu 16.04中使用sudo命令时登录

bluebird:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
bluebird:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
bluebird:~$ sudo mysql -uroot
[sudo] password for bluebird: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

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> 

当我使用 mysql -u root -p 时,我无法登录。当我使用 sudo mysql -u root 时,我可以。

我没有MySQL用户的密码。

我不知道为什么。

2 个答案:

答案 0 :(得分:0)

我使用了以下命令:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.tcyonline.android.myapplication.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <ImageButton
        android:id="@+id/ntn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="right"
        android:layout_marginRight="15dp"
        android:layout_marginTop="25dp"
        android:background="@android:color/transparent"
        android:elevation="10dp"
        android:src="@drawable/calendar" />


    <include layout="@layout/content_main" />
</FrameLayout>

事实证明,不知怎的,我得到了根&#39; @&#39; XXXXX-aspire&#39; root&#39; @&#39; localhost&#39;和&#39; root&#39; @&#39;%&#39;。

当我删除&#39; root&#39; @&#39; XXXXX-aspire&#39;时,我可以use mysql; select User, Host from user; 轻松登录。

答案 1 :(得分:-1)

试试这个SUDO 然后尝试不使用sudo登录

GRANT ALL PRIVILEGES ON *.*  TO 'root'@'localhost';
FLUSH PRIVILEGES;