How to restore mysql to factory settings?
P粉436410586
P粉436410586 2023-12-13 12:36:19
0
2
569

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粉436410586
P粉436410586

reply all(2)
P粉986028039

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.

P粉600402085

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!