$ sudo mysql -u root
$ 回車登錄數據庫
# 出現下面提示,表示成功
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.1.37-MariaDB-0+deb9u1 Raspbian 9.0
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
進入數據庫後進行修改(代碼如下)
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set plugin='mysql_native_password' where user='root';
MariaDB [mysql]> UPDATE user SET password=PASSWORD('root的密碼') WHERE user='root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit;
$ mysql -u root -p
$ 輸入密碼
MariaDB [(none)]> use mysql;
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root的密碼' WITH GRANT OPTION;
MariaDB [mysql]> flush privileges;