本文以 Mac OS 平台通过 homebrew 方式安装的 MariaDB 为例
mariadb版本: stable 10.4.11
1. 编辑my.cnf
配置文件
$ vi /usr/local/etc/my.cnf
在文件尾部添加以下内容
[mysqld]
skip-grant-tables
注:如果该文件中存在 [mysqld],则直接添加第二行内容即可
2. 重启 MariaDB
3. 进入MariaDB修改root密码
$ mysql -uroot
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE user SET Password = password('123456') WHERE User = 'root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> quit;
4. 移除my.cnf
中配置的skip-grant-tables
,重启MariaDB
关键步骤,一定不能忘记!!!