4

I am trying to start mariaDB on macOS with brew services.

I run brew services stop --all

jenkins-lts none        
mariadb     none        
memcached   none        
mysql       none        
mysql@5.7   none        
postgresql  none        
rabbitmq    none        
redis       none        
unbound     none 

If I try brew services start mariadb. I get:

==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)

But it's not:

jenkins-lts none                        
mariadb     stopped albert.montolioagua ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
memcached   none                        
mysql       none                        
mysql@5.7   none                        
postgresql  none                        
rabbitmq    none                        
redis       none                        
unbound     none 

Not sure how to debug this, who is stopping it. I removed mysql services, install everything again. If I have mysql service running, and try to start mariadb, I get following error:

brew services start mariadb
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/albertmontolio/Library/LaunchAgents/homebrew.mxcl.mariadb.plist` exited with 5.
Giacomo1968
  • 58,727

1 Answers1

2

Read the log file for clues: /usr/local/var/mysql/$(hostname).err

Review configuration files in case you have an old one interfering with the installation.

ls -l /etc/my.cnf
ls -l /etc/mysql/my.cnf
ls -l /opt/homebrew/etc/my.cnf
ls -l /usr/local/etc/my.cnf
ls -l /usr/local/var/mysql/.my.cnf
ls -l ~/.my.cnf
ls -l ~/Library/LaunchAgents/homebrew.mxcl.mariadb*

Remove log files. Sometimes the log files of InnoDB (ib_logfile0, ib_logfile1) can become corrupted or mismatched with what MariaDB expects. Remove them and restart. MariaDB will recreate them.

cd /usr/local/var/mysql
rm ib_logfile0
rm ib_logfile1

error 256. If brew services says mariadb failed with error 256 try this:

mysql.server start
mysql.server stop

Try recovery mode. The level ranges from 1 to 6. Levels 4 or higher may incur data lost so you should check that page linked. Higher levels will restrict functionality, with levels 4, 5, 6 starting in read-only mode. Read only mode is still useful to export your data.

Make a backup copy of your data before you use levels 4, 5, 6 !
Latest commits to the database could be lost!

$(brew --prefix)/opt/mariadb/bin/mariadbd-safe --innodb-force-recovery=1

Make a backup and reinstall

When you fully remove Homebrew you are also removing mariadb data. To safeguard against this let’s relocate the database to a folder in the current user account, and run the database under the current user. This is acceptable for local installations. If you need a dedicated user customize the user.

First, backup:

# start in mode 1 then raise up to 6. 
# 4 and higher is unsafe, but sometimes necessary.
$(brew --prefix)/opt/mariadb/bin/mariadbd-safe --innodb-force-recovery=6

mysqldump -u myUser
--password=myPassword
--single-transaction
-B myDatabaseName
> "mysql_$(date +%m_%d_%y)_myDatabaseName"

The following can be pasted on the terminal, but I suggest you paste one by one and follow what’s happening

# ignore comments
setopt INTERACTIVE_COMMENTS

your current macOS user and new location

export CURRENT_USER=$(whoami) export SAFE_PLACE="/Users/$CURRENT_USER/MySafePlace"

the folder holding the internal database files

mkdir -p "$SAFE_PLACE/database"

Verify the variables are set correctly

echo "Current user is: $CURRENT_USER" echo "Safe place location is: $SAFE_PLACE"

brew services stop mariadb

Check for running MySQL/MariaDB processes

ps aux | grep "([m]aria|[m]ysql)"

Use this to find a process parent if you need

ps -o ppid= -p <PID_OF_CHILD>

Crash resistant options

cat << EOF > "$SAFE_PLACE/my.cnf" [mysqld] default_storage_engine = InnoDB

each table goes in a separate file

innodb_file_per_table = 1

flush transaction logs after each commit

innodb_flush_log_at_trx_commit = 1

doublewrite buffer

innodb_doublewrite = 1 EOF

Create load configuration

cat << EOF > ~/Library/LaunchAgents/mariadb.plist <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>KeepAlive</key> <true/> <key>Label</key> <string>mariadb-load</string> <key>LimitLoadToSessionType</key> <array> <string>Aqua</string> <string>Background</string> <string>LoginWindow</string> <string>StandardIO</string> <string>System</string> </array> <key>ProgramArguments</key> <array> <string>/opt/homebrew/opt/mariadb/bin/mariadbd-safe</string> <string>--defaults-extra-file=$SAFE_PLACE/my.cnf</string> <string>--datadir=$SAFE_PLACE/database</string> <string>--user=$CURRENT_USER</string> <string>--log-error=$SAFE_PLACE/mariadb-error.log</string> </array> <key>RunAtLoad</key> <true/> <key>WorkingDirectory</key> <string>/opt/homebrew/var</string> <key>StandardErrorPath</key> <string>$SAFE_PLACE/mariadb-stderr.log</string> <key>StandardOutPath</key> <string>$SAFE_PLACE/mariadb-stdout.log</string> </dict> </plist> EOF

Set permissions for the plist files

chmod 644 ~/Library/LaunchAgents/mariadb.plist

Install system tables

mariadb-install-db
--user=$CURRENT_USER
--basedir=$(brew --prefix mariadb)
--datadir=$SAFE_PLACE/database

Launch MariaDB

launchctl load ~/Library/LaunchAgents/mariadb.plist

if you need to unload

launchctl unload ~/Library/LaunchAgents/mariadb.plist

Connect to MariaDB

sudo mysql -u root

Once inside the database, import the backup we did before, and restore the user permissions.

SOURCE my_backup_file;

CREATE USER 'myDatabaseName'@'localhost' IDENTIFIED BY 'myPassword'; GRANT ALL PRIVILEGES ON myDatabaseName.* TO 'myUser'@'localhost' WITH GRANT OPTION;

If you need to tail the log files:

tail -f "$SAFE_PLACE/mariadb-error.log"
tail -f "$SAFE_PLACE/mariadb-stdout.log"
tail -f "$SAFE_PLACE/mariadb-stderr.log"

A note for macOS 15.0 (Sequoia) users: mariadb versions 11.5.2 and above no longer experience corruption after restarting. Details.

Jano
  • 163