128

My computer is Windows XP.

I need to find my.cnf to get all privileges back to the root user. I accidentally removed some privileges of the root user. I still have the password and there is no problem for me to log in to MySQL as the root user. But I can not alter a table.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Steven
  • 24,410
  • 42
  • 108
  • 130

6 Answers6

239

Here is my answer:

  1. Win+R (shortcut for 'run'), type services.msc, Enter
  2. You should find an entry like 'MySQL56', right click on it, select properties
  3. You should see something like "D:/Program Files/MySQL/MySQL Server 5.6/bin\mysqld" --defaults-file="D:\ProgramData\MySQL\MySQL Server 5.6\my.ini" MySQL56

Full answer here: https://stackoverflow.com/a/20136523/1316649

Richard
  • 4,341
  • 5
  • 35
  • 55
fstang
  • 5,607
  • 4
  • 25
  • 26
  • 1
    what happens if mysql is not running as a service? where is the my.ini located? I can see my-default.ini on C:\Program Files\MySQL\MySQL Server 5.6 but I don't know if the server is using it. – Pablo Pazos Oct 24 '17 at 00:01
  • @PabloPazos Same question, what happens if we run it *not as a service*, but rather from cmdline: `mysqld --console`? – Basj Apr 19 '23 at 18:13
84

To answer your question, on Windows, the my.cnf file may be called my.ini. MySQL looks for it in the following locations (in this order):

  • %PROGRAMDATA%\MySQL\MySQL Server 5.7\my.ini, %PROGRAMDATA%\MySQL\MySQL Server 5.7\my.cnf
  • %WINDIR%\my.ini, %WINDIR%\my.cnf
  • C:\my.ini, C:\my.cnf
  • INSTALLDIR\my.ini, INSTALLDIR\my.cnf

See also http://dev.mysql.com/doc/refman/5.7/en/option-files.html

Then you can edit the config file and add an entry like this:

[mysqld]
skip-grant-tables

Then restart the MySQL Service and you can log in and do what you need to do. Of course you want to disable that entry in the config file as soon as possible!

See also http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

Zitrax
  • 19,036
  • 20
  • 88
  • 110
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
13

Windows 7 location is: C:\Users\All Users\MySQL\MySQL Server 5.5\my.ini

For XP may be: C:\Documents and Settings\All Users\MySQL\MySQL Server 5.5\my.ini

At the tops of these files are comments defining where my.cnf can be found.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Alberto
  • 131
  • 1
  • 4
6

You can find the basedir (and within maybe your my.cnf) if you do the following query in your mysql-Client (e.g. phpmyadmin)

SHOW VARIABLES
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
digitaldonkey
  • 2,431
  • 1
  • 20
  • 16
0

you can search this file : resetroot.bat

just double click it so that your root accout will be reset and all the privileges are turned into YES

Treby
  • 1,328
  • 6
  • 18
  • 26
-6

Start->Search->For Files and Folders->All Files and Folders

type "my.cnf" and hit search.

Jeremy Morgan
  • 3,314
  • 23
  • 23