skip to Main Content

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).

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search