Home > Back-end >  How to reset mysql to factory settings?
How to reset mysql to factory settings?

Time:12-12

So I dropped all the users in mysql.user and restarted the mysql database. Now I can't seem to get into the mysql again or how to reset it as if it was a clean install. I tried uninstalling it with brew uninstall mariadb and then reinstalling it with brew install mariadb, but that didn't fix it. The only resources I can find is about how to restore a user from inside mysql (which I am struggling to get into) or how to delete mysql completely by deleting files in certain directories (which don't exist in the first place).

CodePudding user response:

There are two methods:
method 1:
1.Uninstall the mysql database, delete the data files in the /data directory, and then reinstall

Method 2:
1.Stop the mysql service (systemctl stop mysqld)
2.Delete the files in the /data directory (rm -fr /data/*)
3.Initialize mysql (mysqld --defaults-file=/mysql/my.cnf --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data/3306/data/)

PS1: The path may be different from yours, you need to change it according to your own data directory

CodePudding user response:

I did end up finding a solution to my problem. I didn't end up getting it from one source, but more cobbled a bunch of different stuff together until I figured out that this worked.

  1. Stop the server: `brew services stop mariadb
  2. Start it with this command: mysql --skip-grant-tables
  3. Run this command to fix the table with no users: mysql_upgrade --force
  4. Force kill mysql: ps -ef | grep mysql followed by kill -9 <pid>
  5. Start up the server again: brew services start mariadb

I did first try mysql_install_db instead of mysql_upgrade --force as some site suggested, but that didn't work since mysql.user table still existed. It was just empty.

  • Related