Ubuntu 18.04安装Mariadb修改初始密码
在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)
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'
解决问题:
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