search

Home  >  Q&A  >  body text

How to restore mysql to factory settings?

So I deleted all users in mysql.user and restarted mysql database. Now I can't seem to get into mysql again or how to reset it as if it was a fresh install. I tried uninstalling it using brew uninstall mariadb and then reinstalling it using brew install mariadb but that didn't fix the problem. The only resources I can find are on how to restore a user from within mysql (which I'm struggling to get into) or how to completely remove mysql by deleting files in certain directories (that don't exist in the first place). < /p>

P粉436410586P粉436410586395 days ago684

reply all(2)I'll reply

  • P粉986028039

    P粉9860280392023-12-14 10:11:56

    I finally found a solution to the problem. I didn't end up getting it from one source, but cobbled together a bunch of different things until I figured out that this worked.

    1. Stop the server: `brew services stop mariadb
    2. Start it using the following command: mysql --skip-grant-tables
    3. Run this command to repair tables without users: mysql_upgrade --force
    4. Force terminate mysql: ps -ef | grep mysql followed by kill -9
    5. Start the server again: brew services start mariadb

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

    reply
    0
  • P粉600402085

    P粉6004020852023-12-14 09:05:11

    There are two methods:
    method one:
    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 and needs to be changed according to your own data directory

    reply
    0
  • Cancelreply