Permissions

全新安裝 mysql-server 後,無法使用 mysql root -u 登錄

  • April 30, 2021

編輯:我相信這實際上是https://askubuntu.com/questions/766334/cant-login-as-mysql-user-root-from-normal-user-account-in-ubuntu-16-04副本使用了該頁面的最佳答案,並且有效。


我剛剛安裝了一個新的 Linux Mint 18 MATE,並且正在嘗試安裝 Mysql。我這樣做如下:

sudo apt-get install mysql-server

已安裝

mysql  Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using  EditLine wrappe

這經歷了一些提示我輸入密碼的“gui”螢幕。我只是為每個輸入,我認為這就像在說“沒有密碼”。

但現在,我想我可以用 進入它mysql -u root,但它說

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

我嘗試重新啟動以防萬一。問題是我沒有使用正確的密碼,還是更根本的問題?如果是密碼,我如何找出它是什麼/重置它?謝謝,馬克斯

編輯:在下面f35的回答之後,我做了以下事情:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
mysql -u root

然後在 mysql 中,我嘗試更改密碼,但它無法辨識欄位名稱:我做了一個 desc 以查看其中的內容:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=PASSWORD("password") where User='root';
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> desc user;
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Field                  | Type                              | Null | Key | Default               | Extra |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
| Host                   | char(60)                          | NO   | PRI |                       |       |
| User                   | char(32)                          | NO   | PRI |                       |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Insert_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Update_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Delete_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Create_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Drop_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Reload_priv            | enum('N','Y')                     | NO   |     | N                     |       |
| Shutdown_priv          | enum('N','Y')                     | NO   |     | N                     |       |
| Process_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| File_priv              | enum('N','Y')                     | NO   |     | N                     |       |
| Grant_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| References_priv        | enum('N','Y')                     | NO   |     | N                     |       |
| Index_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Alter_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Show_db_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Super_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N                     |       |
| Lock_tables_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Execute_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Repl_slave_priv        | enum('N','Y')                     | NO   |     | N                     |       |
| Repl_client_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Create_view_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Show_view_priv         | enum('N','Y')                     | NO   |     | N                     |       |
| Create_routine_priv    | enum('N','Y')                     | NO   |     | N                     |       |
| Alter_routine_priv     | enum('N','Y')                     | NO   |     | N                     |       |
| Create_user_priv       | enum('N','Y')                     | NO   |     | N                     |       |
| Event_priv             | enum('N','Y')                     | NO   |     | N                     |       |
| Trigger_priv           | enum('N','Y')                     | NO   |     | N                     |       |
| Create_tablespace_priv | enum('N','Y')                     | NO   |     | N                     |       |
| ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |                       |       |
| ssl_cipher             | blob                              | NO   |     | NULL                  |       |
| x509_issuer            | blob                              | NO   |     | NULL                  |       |
| x509_subject           | blob                              | NO   |     | NULL                  |       |
| max_questions          | int(11) unsigned                  | NO   |     | 0                     |       |
| max_updates            | int(11) unsigned                  | NO   |     | 0                     |       |
| max_connections        | int(11) unsigned                  | NO   |     | 0                     |       |
| max_user_connections   | int(11) unsigned                  | NO   |     | 0                     |       |
| plugin                 | char(64)                          | NO   |     | mysql_native_password |       |
| authentication_string  | text                              | YES  |     | NULL                  |       |
| password_expired       | enum('N','Y')                     | NO   |     | N                     |       |
| password_last_changed  | timestamp                         | YES  |     | NULL                  |       |
| password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |
| account_locked         | enum('N','Y')                     | NO   |     | N                     |       |
+------------------------+-----------------------------------+------+-----+-----------------------+-------+
45 rows in set (0.00 sec)

不知道下一步該做什麼 - 另外,設置無密碼的語法是什麼?只是set password=''嗎?

注意:我也可以使用 debian-sys-main 使用者登錄,但仍然不確定如何更改 root 使用者的密碼。

我的mysql版本是:伺服器版本:5.7.16-0ubuntu0.16.04.1(Ubuntu)

1)您可以嘗試重新配置 mysql-server :

sudo dpkg-reconfigure mysql-server
  1. 檢查你是否有 debian-sys-maint passwd
cat /etc/mysql/debian.cnf

並檢查:

user     = debian-sys-maint
password = xxxxGx0fSQxxGa

debian-sys-maint 擁有 mysql 伺服器的所有權限

3)如果不能解決問題,你可以重置密碼:

sudo service mysql stop
sudo mysqld_safe --skip-grant-tables &
mysql -u root

mysql> use mysql;
mysql> update user set password=PASSWORD("NewPasswd") where User='root';
mysql> flush privileges;
mysql> quit

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

引用自:https://unix.stackexchange.com/questions/327120