134

the MySQL service on local computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.

Can anyone resolve this issue? Thanks.

Sumithran
  • 6,217
  • 4
  • 40
  • 54
Kem Bardly
  • 1,585
  • 4
  • 12
  • 13
  • 3
    http://forums.mysql.com/read.php?11,638281,638401#msg-638401 – xlecoustillier Feb 27 '16 at 14:11
  • 1
    Does this answer your question? [The MySQL57 service on Local Computer started and then stopped](https://stackoverflow.com/questions/37910680/the-mysql57-service-on-local-computer-started-and-then-stopped) – Nazim Feb 11 '20 at 11:29
  • 3
    Please delete all the files in the data directory before you initialize. There could be error files in there that will stop you. – AturSams Jan 30 '21 at 09:57
  • I ended up reinstalling the MySQL server that was running as this service – gawkface Sep 29 '22 at 16:42

36 Answers36

190

After installing it by mysqld --install. Try this mysqld --initialize. We got the same problem but it's now working.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Alexa
  • 2,201
  • 1
  • 10
  • 15
  • 16
    @Tunaki. We need to open command prompt as an Administrator, to execute mysqld --install and mysqld --initialize commands. – Pankaj Shinde Apr 26 '16 at 07:28
  • 2
    if simple is not working, than: bin\mysqld --initialize-insecure (and latare add root password) – danielpopa Oct 01 '17 at 12:53
  • 3
    After using mysqld --initialize search for root password in MySQL error log file, the line would look like this: A temporary password is generated for root@localhost: Ok+ju;UT8%ED – Alex Khimich May 10 '19 at 15:20
  • I had used this `MYSQL80` service before. Somehow it's not starting, I usually start it manualy from Services but now its not functional from there – Waseem Ahmad Naeem May 13 '19 at 17:44
  • 2
    opened `cmd` as administrator, executed the commands `mysqld --install` and `mysqld -- initialize`. Then opened `mysql` in services and started the service. It worked this way – Suresh Jan 31 '20 at 18:15
  • After trying all of the above, the service still wouldn't start. I had to also manually create an `Uploads` subdirectory under my `data` subdirectory. Then, it started! – tonypdmtr May 02 '20 at 13:28
  • This is a one-shot solution to clear the my.ini file, check other solutions for specific solutions within the file – Raul Lapeira Herrero May 12 '22 at 06:23
  • Can't believe wamp didnt even include executing ---initialize on first run. – chitgoks Mar 18 '23 at 06:35
79

If using version 8 and you edit the my.ini I found that Notepad is putting 3 hex characters at the beginning of the my.ini file. EF BB BF. Deleting the 3 characters from the beginning of the file in a hex editor fixes the problem.

In version 8 they are accidentally putting Unicode characters in the ini file. This is causing Notepad to save the file with Byte order mark characters.

The following line in the file is the culprit "The line # range from 1 to 2^32 − 1. “Unique” means that each ID must be different." has 3 Unicode characters. This is causing notepad to append the byte order mark to the text file.

jhersey29
  • 959
  • 6
  • 6
  • 1
    Those three bytes called BOM https://en.wikipedia.org/wiki/Byte_order_mark. Stupid notepad for inserting that without asking, stupid MySQL for putting unicode chars in a windows config file, which is very likely to be edited by notepad. – Zar Shardan Mar 30 '20 at 23:25
  • My heart jumped out of my chest when the server went down. Thank you for helping! Stupid notepad! – user2219963 Mar 31 '23 at 20:45
42

Also remember to give NETWORK SERVICE permission to the folder:

  1. Right-click Data folder
  2. Select Properties
  3. Select Security tab
  4. Click Advanced
  5. Click Change Permissions...
  6. Click Add...
  7. Type NETWORK SERVICE
  8. Click Check Names
  9. Click OK
  10. Select Full Control
  11. Click OK – four times
  12. Start MySQL service
Warwick
  • 925
  • 1
  • 10
  • 22
  • 5
    2 hours almost and setting up permissions in windows did the trick, didn't thought this could be a problem as no such indication was there at all. thanks a lot buddy – Zaffar Saffee Oct 28 '17 at 20:43
  • I also had to make sure that MySQL service is "Network Service" account after this. – Nae May 19 '20 at 21:29
  • 1
    especially important when moving the datadir – CodeMonkey Oct 04 '21 at 09:54
  • Thankyou Thankyou Thankyou, I was tearing my hair out trying to work out why even giving the folder all permissions for EVERYONE still didn't allow me to restart the MySQL service but just adding permissions for NETWORK SERVICE did the trick. I followed other posts instructions exactly over and over without success until I noticed your comment and link to this post and applied your instructions and IT WORKS!, your my savior, thankyou so much :) – David Crawford Mar 12 '22 at 13:18
14

In my case, I tried to open a DOS prompt and go to the MySQL bin\ directory and issue the below command:

mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.0\my.ini" --standalone --console

And it shows me I was missing the "C:\Program Files\MySQL\MySQL Server 5.0\Uploads" folder; I built one and problem solved.

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
Han Xiong
  • 171
  • 1
  • 6
  • After messing with lots of permission settings it turned out I had an incorrect drive letter in my ini/cnf file. This answer helped me. – PadraigD Jul 09 '19 at 16:12
  • **On using above query, Try1**, It showed me that - "Operating system error number 32 in a file operation. [ERROR] [MY-012615] The error means that another program is using InnoDB's files. This might be a backup or antivirus software or another instance of MySQL.". **On using above query, Try2**, it Started crash recovery and started successfully :) – Himalaya Garg Jan 12 '20 at 09:53
  • 1
    This worked well to give us detailed errors to allow us to solve our problem, except our "my.ini" file is in the "ProgramData" directory path instead of the "Program Files" directory path `mysqld --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.0\my.ini" --standalone --console` – Abel Wenning Jul 12 '21 at 23:26
11

Using Community 8.0.17, upgraded from 8.0.16

There may be a more secure way of doing this, but since I'm just running a dev box:

  1. navigate to the \data folder
  2. make SURE the \data folder is EMPTY. If files exist the --initialize option will fail
  3. give SYSTEM Full Control permissions on the \data folder
  4. go back to your command prompt
  5. run mysqld --initialize

you should see all of the required data file structures in the data folder now. If they are not created, the mysqld process has contention or improper security to write into the folder correctly.

Now start your named service in whatever fashion you want (SC/NET/service.msc, etc)

Assuming all of the files were created properly by --initialize the service will start.

tom anderson
  • 111
  • 1
  • 2
7
  1. Open Service
  2. Right click on MYSQL service
  3. select Log on
  4. check local system account
  5. start service
5

This may be because of changing lower_case_table_names after a server has been already initialized.

From the docs:

lower_case_table_names can only be configured when initializing the server. Changing the lower_case_table_names setting after the server is initialized is prohibited.

The solution to this problem is to set lower_case_table_names parameter at server installation as described in the following answer:

Can't set lower_case_table_names in MySQL 8.x on Windows 10

vter
  • 1,881
  • 1
  • 20
  • 38
  • This is exactly my situation since I need the `lower_case_table_names` set to 2 to work with Prisma migration tools. Had to uninstall then reinstall everything. Fortunately I don't have a lot of data. – Bao Huynh Lam Mar 26 '23 at 03:28
4

I see this error when I install MySQL 8.x, edit the max_allowed_packet in the my.ini file, and then restart mysql on a Windows 10 machine. My recommendation, to avoid this issue, is to edit the my.ini file in a hex editor (something like Frhed). DO NOT USE NOTEPAD. It does something to the hex layout of the .ini file.

Wes Henderson
  • 117
  • 1
  • 7
3

Follow the below instruction as below to save your day:

If you modify my.ini not correct, you will find the trouble "the MySQL service on local computer started and then stopped". So you need to check your my.ini in "C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" again to make sure there is no strange command. If you don't know and want to restore to original, you can search on web with key word "my.ini configuration", download the latest and copy it to "C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"

For whom delete the SQL service on Window or Linux, You can follow these step below:

(Window)

Delete Current Service

You need to stop MySQL80/MySQLXX in Service before carry out the action below Open commandLine of Window and run as administrator

sc delete mysql80 <= If you use mysql80, it will delete MySQL80 in Service

sc delete mysql <= If you use "mysql --initliaze", it will delete MySQL in Service

The command mysqld --initialize just create MySQL in Service of Window or Linux

So when you check it Path Executable, it misses my.ini so you can't use you MySQL Server although MySQL Service is working

For MySQL80

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --install MySQL80 --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini"

For MySQLXX

"C:\Program Files\MySQL\MySQL Server X.X\bin\mysqld.exe" --install MySQLXX --defaults-file="C:\ProgramData\MySQL\MySQL Server X.X\my.ini"

=> It will create MySQLXX Service working with my.ini

Then MySQL works normally and you won't need to install your MySQL again.

I don't use Linux or Mac so I can't instruct - But you can find the answer above for reference

PhuVu94
  • 39
  • 2
3

This problem is so complicated and depend on MySQL Version.My problem was happened on MySQL 8.0.2. When I've config my.ini file on notepad and save it.I soleved following @jhersey29 solution https://stackoverflow.com/a/55519014/1764354 but little different approch.

my solution is restore my.ini file and edit config value via Option files on WorkBench Application. workBench Menu Example

tleaha
  • 31
  • 3
2

Search for services.msc and look up through your services that are running if there is a mysql service running already other than the one you want to run (it could be xampp or wamp) or another service (for example Skype) using the same port as mysql and stop the service so you can run your mysql service.

  • MySql on a godaddy VPS stopped loading. The MariaDb that comes with the server either turned itself back on or I never actually disabled it and MySQL managed to grab the port first for a year or so, until it didn't. Sometimes the error is exactly what it says it is. You are exactly right in that it could just be the port actually being in use. – user1544428 Jul 15 '22 at 18:15
2

This error happened in my case when secure-file-priv was pointing to unexistent folder, make sure it exists and readable.

The line of code example in my.ini: secure-file-priv="D:/MySQL/uploads"

Alex Khimich
  • 788
  • 9
  • 10
  • Yes, same here, this is the problem if you're moving the data directory of newer mysql and in the process moved uploads directory too. – J Rao Dec 14 '19 at 04:55
2

You also might have accidentally added some wrong text in my.ini file. Make sure no invalid character is added at the beginning of the file.

Srihari Karanth
  • 2,067
  • 2
  • 24
  • 34
  • 1
    Thank you, this got me on the right track... Apparently editing the my.ini file in Notepad will break the file. I made the same edits to the file in Visual Studio Code instead and it worked just fine. – justanotherguy Dec 03 '20 at 20:21
  • I edited the bind-address too with notepad and it starts to have a start-stop problem. Did you have the same problem with bind-address ? Just to know if Visual Stufio Code could also be the solution in my case. – user2305415 Jan 23 '22 at 19:47
2

Nothing was working for me but then I checked here. I ran that command qc sc mysql57 and copied the value of BINARY_PATH_NAME from it. After that I checked this and changed the value of lower_case_table_names from 0 to 2 in my.ini file. Then in the command prompt, I ran this command - << BINARY_PATH_NAME >> --install-manual. After that, I started the MySQL57 service and it worked.

Germa Vinsmoke
  • 3,541
  • 4
  • 24
  • 34
1

Rename or delete the folder under,

C:\ProgramData\MySQL\MySQL Server 5.7

folder name change as per your MYSQL version number.

1

I had this issue after my database was working fine for long time. It turned out it was some data corruption.

In the error log I had:

2017-02-07T10:11:42.270567Z 0 [ERROR] InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoint 44002250712 and the end 44002250240.
2017-02-07T10:11:42.270606Z 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
2017-02-07T10:11:42.577436Z 0 [ERROR] Plugin 'InnoDB' init function returned error.
2017-02-07T10:11:42.577470Z 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2017-02-07T10:11:42.577484Z 0 [ERROR] Failed to initialize plugins.
2017-02-07T10:11:42.577488Z 0 [ERROR] Aborting

Then I had to delete the 2 ib_logfile* files, and it restarted again.

Aris
  • 4,643
  • 1
  • 41
  • 38
  • `mysqld --initialize` doesn't work if there exist databases already. This solution worked for me. – Miron May 21 '21 at 02:36
1

my.ini file should save as (Encoding) ANSI not UTF-8 or others files.

user5816728
  • 61
  • 1
  • 3
1

I have faced the same situation. I have changed the server-id=2 and when saved got this error. After a lot of research, I have found the solution. In windows after

changing my.ini mysql configuration file, save the file as ANSI rather than UTF-8

This has worked for me well.

r Reddy
  • 49
  • 5
1

another instance of mysql like 5.6 or 8 run at the same time

and the 80 port was reserved

please > go to >> services>> stop all another instance >> disable them

in my case problem solved and service started as well

saber tabatabaee yazdi
  • 4,404
  • 3
  • 42
  • 58
1

Go to "C:\ProgramData\MySQL\MySQL Server 8.0\Data\[machine name].err" and check the last rows - it should tell you why it failed. In my case it was duplicated tablespace id between databases.

It looks like this:

2021-09-12T05:19:22.815152Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2021-09-12T05:19:22.818357Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.22) starting as process 30664
2021-09-12T05:19:22.866774Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-09-12T05:19:22.908983Z 1 [ERROR] [MY-012209] [InnoDB] Multiple files found for the same tablespace ID:
2021-09-12T05:19:22.911667Z 1 [ERROR] [MY-012202] [InnoDB] Tablespace ID: 124 = ['db1\accounts.ibd', 'db2\accounts.ibd'] 
2021-09-12T05:19:22.915514Z 1 [ERROR] [MY-012930] [InnoDB] Plugin initialization aborted with error Failed, retry may succeed.
2021-09-12T05:19:22.918627Z 1 [ERROR] [MY-010334] [Server] Failed to initialize DD Storage Engine
2021-09-12T05:19:22.927714Z 0 [ERROR] [MY-010020] [Server] Data Dictionary initialization failed.
2021-09-12T05:19:22.930912Z 0 [ERROR] [MY-010119] [Server] Aborting
2021-09-12T05:19:22.934432Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.22)  MySQL Community Server - GPL.
Qua285
  • 137
  • 1
  • 3
  • 12
  • This solved my problem. In my case I had a copy of a table that I did manually. When restarting the MySQL service there was duplicated tablespace ID. Thanks @Qua285. – f4d0 Jun 14 '23 at 18:36
1

Changing xampp folder's permission in windows to full control for 'authenticates user' fixed my problem.

0

In my case, mysqld was starting and stopping with no error message. I needed to open command prompt using "Run as Administrator", and then run mysqld.

I am only doing this for temporary development. I would not recommend running MySQL as an administrator in any case.

This was the final step after the above troubleshooting.

Robert Allurent
  • 187
  • 1
  • 2
  • 10
0

The same problem happened with me also, nothing worked... I first deleted the service (in my case MySQL80 and MySQL) by command:

sc delete MySQL80
sc delete MySql

and then reinstalled MySQL. Mine was MySQL 8.0. And then everything was back to normal.

Deepanshu
  • 141
  • 1
  • 5
0

Delete or rename the 2 following files from "C:\ProgramData\MySQL\MySQL Server 5.7\Data": ib_logfile0 ib_logfile1

0

the MySQL service on local computer started and then stopped

This Error happen when you modified my.ini in C:\ProgramData\MySQL\MySQL Server 8.0\my.ini not correct.

You can search my.ini original configuration or checking yours to make sure everything is OK

PhuVu94
  • 39
  • 2
0

If you came across this while installing WAMP64 on Windows 10. Check if data folder in MySQL folder is missing. My WAMP 3.2.3 version installation failed to create such a folder. So wamp icon was orange (1 of 2 services running).

A quick fix was to run this command from MySQL location.

C:\wamp64\bin\mysql\mysql5.7.31\bin\
mysqld --initialize-insecure
SMJ
  • 716
  • 1
  • 9
  • 23
0

non of the above actually works so delete mysql,reinstall mysql,restore back if any...enjoy

0

I had the exact same message as displayed in the question. I have tried many suggestions with little luck. I was about to install WAMP (I'm on Windows) and was about to uninstall MySql 8.0 first, when I noticed a program included in the installation: 'MySQL Installer - Community' so I tried that. With this installer I set up a new connection, added password to root, added another user with password, set my choice of locations for all logs and ran the install. The result was that it now totally works.

Rob Farquharson
  • 130
  • 1
  • 4
0

Such a problem can very often come due to configuration errors.

Vivek Sethi mentioned 20th December 2012 that it is possible to get logging in the console by running the following command:

C:\Windows\system32>"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld" --defaults-file="C:\Program Files\MySQL\MySQL Server 5.5\my.ini" --standalone --console

Right-clicking on my service in Windows 10, I recognized the --defaults-file= parameter, and with console logging I was able to see what was wrong in my configuration. In my case the path to datadir= and secure-file-priv= was wrong. I hope others can be empowered as well by being able to see logging details in the console. Good luck!

pekaaw
  • 2,309
  • 19
  • 18
0

make sure your data folder is fully empty before use command mysqld --initialize

0

This happened in my install when I added the parameter

audit-log = ON

On the my.ini file, add to remove it for it to work

0

I had to restart my pc :|

After restarting pc, start MySQL service manually.

(I don't know the real issue)

enter image description here

Lojith Vinsuka
  • 906
  • 1
  • 10
  • 8
0

In mycase how this worked.

  1. Enter the following folder: C:\ProgramData\MySQL\MySQL Server 8.0\Data
  2. Check for folder #innodb_redo
  3. Empty the above folder
  4. Restart the service and MySQL80 has started now.

I hope the above answer helps for someone.

user503285
  • 125
  • 3
  • 14
  • It did not work. Additionally, on your bullet point you mention "Restart", when this issue is related to an SQL server that is stopped, not running. You cannot restart something that is off. – f4d0 Jun 14 '23 at 18:33
  • Yeah I agree..its a start. Restart became common in Windows world. – user503285 Jun 19 '23 at 13:04
0

cmd>mysqld --install
cmd> mysqld --initialize
Go to services-> mysql - start the service. In case there is still error, go to mysql-8.0.32-winx64\data directory.There will be an error file with .err extension.

In my case, it said, there are alreay files under /data directory. So, I leaned this up, and re-run
cmd> mysqld --initialize followed by services->mysql - start the service

hmehandi
  • 356
  • 4
  • 11
-1

mysqld --initialize

Run the above after the install command. Then try to start the service - that should work.

-2

If you have changed data directory (the path to the database root in my.ini) to an external hard drive, make sure that the hard drive is connected.

Ehsan
  • 1
  • 1
  • Hello Ehsan. The question didn't mention that they are using an external drive. So, it is unlikely this is the problem. – Diego Malone Jun 04 '19 at 00:11