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
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.
mysql --skip-grant-tables
mysql_upgrade --force
ps -ef | grep mysql
followed bykill -9 <pid>
brew services start mariadb
I did first try
mysql_install_db
instead ofmysql_upgrade --force
as some site suggested, but that didn't work sincemysql.user
table still existed. It was just empty.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