Mysql(dmg installation) preference setting of MacOS fails to start

Posted by Vasudhevan on Thu, 03 Mar 2022 19:34:48 +0100

First, let's talk about my version information

Operating system MacOS Big Bur 11.2.2

Mysql 8.0.24

Note: I installed it through the official dmg package, not through homebrew. If it is a problem in homebrew installation, it can also be used as a reference.

Current date: April 21, 2021

If you want to directly test the results, you can jump to the solution. There are many words in the front ha-ha

concrete problems

Since the Big Bur system was updated, many development environments have problems. Before the test project needed mysql, I habitually clicked MySQL and start mysql server in the preference settings (I didn't do the back-end, so I didn't set Mysql to self start), but I couldn't start the MySQL service after clicking several times. Because the situation was urgent, I directly google d and started the MySQL service with the command

The emergency start command is:

$ sudo /usr/local/mysql/support-files/mysql.server start

I can start successfully. And mysql in the preference settings is also displayed as running status

When I finish using mysql, I can't stop the MySQL service by clicking stop MySql server in the preference settings. But I don't really care about this. Until recently, I was learning SpringBoot and needed a database. That's why I pay attention to it.

discover problems

First, try the command to enter the data without starting mysql server

# xxx @ xxxMacBook-Pro in ~ [9:57:07] 
$ mysql -uroot -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
Question 1: no / TMP / MySQL Sock file

Prompt: unable to log in to mysql through socket.

I went to the / tmp / directory and found that there was no / tmp / MySQL Sock file.

However, when mysql server is started (through the above start command, you must have root permission), / TMP / MySQL The sock file will be generated.

# xxx @ xxxMacBook-Pro in ~ [10:02:28] 
$ ps aux|grep mysql
xxx               3629   0.0  0.0  4277640    600 s003  R+   10:02 0 am:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox mysql
_mysql            3610   0.0  2.1  4923136 355552   ??  Ss   10:02 0 am:00.52 /usr/local/mysql/bin/mysqld --user=_mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --log-error=/usr/local/mysql/data/mysqld.local.err --pid-file=/usr/local/mysql/data/mysqld.local.pid --keyring-file-data=/usr/local/mysql/keyring/keyring --early-plugin-load=keyring_file=keyring_file.so

# xxx @ xxxMacBook-Pro in ~ [10:02:44] 
$ ls /tmp 
com.apple.launchd.A5Mtzx3D97 foo.err                      mysql.sock                   mysqlx.sock                  powerlog
com.google.Keystone          fseventsd-uuid               mysql.sock.lock              mysqlx.sock.lock
Reason for problem 1:

/tmp/mysql. The sock file is generated by starting mysql server. Only when / TMP / MySQL Only when the sock exists can you log in to MySQL through the mysql -uroot -p command. That is, you can log in to MySQL through socket only when MySQL service is started.

I checked a lot of this question before, and many posts said it was my CNF file, and I don't have this file at all. I don't know if it's a problem with them. Anyway, I have to make complaints about it for a long time.

Main problems

The above problem is just that I was careless and didn't start mysql server.

The key problem is that you can't click to start.

Use root permission to enter / usr/local/mysql/data: there is one named xxxmacbook pro local. Err log file, which records some mysql errors. Most of the prompts are the following paths

/usr/local/mysql/bin/mysqld 

Check the path( Introduction to mysqld on mysql official website ), it doesn't seem to be the problem.

So I went to find other error logs. Finally, I found one in the previous / tmp / directory

/tmp/foo.err

The error messages are like this

NSAppleScriptErrorBriefMessage = "/Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist: CoulLoad failed: 119: Service is disabled";ysql.mysqld.plist: Service is disabled

I went to my / Library/LaunchDaemons / directory and found that there was no com.com in this directory oracle. oss. mysql. mysqld. Plist file. All files in this directory are self starting files. And also found xxmacbook pro local. The err file also records that MySQL cannot link to com oracle. oss. mysql. mysqld. Plist file and other related information.

I didn't know, so I copied it directly to google and finally let me find it mysql official introduction

Discovery com oracle. oss. mysql. mysqld. Plist file is used to start MySQL startup daemon

I dare speculate that if MySQL in the preference setting needs to start and stop MySQL by clicking, it must start the MySQL daemon to run. All reference to official methods

Solution

Manually load the startup file.

shell> cd /Library/LaunchDaemons
shell> sudo launchctl load -F com.oracle.oss.mysql.mysqld.plist

Then, click start mysql server in preferences. It's no use finding out. Ah ~.

Ha ha, I'm also a silly batch. As mentioned earlier, the self startup file is in the / Library/LaunchDaemons directory. Of course, you have to restart the computer to start the program.

After restarting the computer, it is found to be successful.

Everyone's environment is different and may not be able to solve your problem.

Finally, a mysql uninstall script is provided

#!/bin/bash
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*

reference resources

https://dev.mysql.com/doc/refman/8.0/en/mysqld.html

https://dev.mysql.com/doc/mysql-osx-excerpt/8.0/en/osx-installation-launchd.html

http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-10-yosemite/#mysql

Topics: MySQL macOS