在Ubuntu环境下新安装Mariadb数据库之后,所有的配置文件里都没有默认密码,然后用root用户和空密码也登不进去,浪费了好长时间,将解决的过程记录一下。
MySQL版本:10.1.47-MariaDB-0+deb9u1 Debian 9.13
在StackOverflow上找到的解决方法 >>> ERROR 1698 (28000): Access denied for user ‘root‘@’localhost‘](https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| zhulongkun20@v2ray:mysqld_safe --skip-grant-tables
zhulongkun20@v2ray:sudo /etc/init.d/mysql restart
zhulongkun20@v2ray:sudo mysql
进入到 MySQL 后台 MariaDB [(none)]>
执行SQL修改密码 MariaDB [(none)]> update mysql.user set password=PASSWORD("root") where user="root";
刷新 MariaDB [(none)]> flush privileges; MariaDB [(none)]> exit Bye
重启 zhulongkun20@v2ray:/etc$ sudo /etc/init.d/mysql restart [ ok ] Restarting mysql (via systemctl): mysql.service.
登录然后还是报错 zhulongkun20@v2ray:mysql -uroot -p ERROR 1698 (28000): Access denied for user 'root'@'localhost'
|
解决问题:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| zhulongkun20@v2ray:mysqld_safe --skip-grant-tables
zhulongkun20@v2ray:sudo /etc/init.d/mysql restart
zhulongkun20@v2ray:sudo mysql
进入到 MySQL 后台 MariaDB [(none)]>
MariaDB [(none)]> use mysql; MariaDB [mysql]> SELECT User, Host, plugin FROM mysql.user; +------+-----------+-------------+ | User | Host | plugin | +------+-----------+-------------+ | root | localhost | unix_socket | +------+-----------+-------------+ 1 row in set (0.00 sec)
MariaDB [mysql]> UPDATE user SET plugin='mysql_native_password' WHERE User='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mysql]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.01 sec)
然后退出 MariaDB [mysql]> exit
杀掉所有进程后重启登录即可: zhulongkun20@v2ray:~$ mysql -uroot -p
|