Skip to content

Instantly share code, notes, and snippets.

@kaanra
Last active October 5, 2022 23:57
Show Gist options
  • Save kaanra/8971281c64ef41b30fe4b3e3fb272ed2 to your computer and use it in GitHub Desktop.
Save kaanra/8971281c64ef41b30fe4b3e3fb272ed2 to your computer and use it in GitHub Desktop.
[Homebrew mysql] #terminal #homebrew #mysql

brew install mysql@5.7 https://laravel.com/docs/6.x/valet#installation

brew services restart mysql@5.7
brew services start mysql@5.7
brew services stop mysql@5.7

List running services

brew services list

Create symlink

brew link mysql@5.7 --force

https://stackoverflow.com/questions/33268389/what-does-brew-link-do

Creates symlinks to installations you performed manually in Cellar. This allows you to have the flexibility to install things on your own but still have those participate as dependencies in homebrew formulas.

Remove symlink

brew unlink mysql@5.7


Dropbox Syncing

Database is at:

/usr/local/var/mysql

Symlink to Dropbox

ln -s "/my-dropbox/path/mysql" "/usr/local/var/mysql"


Fix -bash: mysql: command not found

After running brew install mysql@5.7 this error appeared.

Create symlink

brew link mysql@5.7 --force

$ brew link mysql@5.7 --force
Linking /opt/homebrew/Cellar/mysql@5.7/5.7.39... 87 symlinks created.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

Log into mysql

mysql -u root -p

List databases

show databases;


Find where databases are stored in Mac

mysql
SELECT @@datadir, @@innodb_data_home_dir

Something happened kill it all and reset

https://stackoverflow.com/questions/9695362/macosx-homebrew-mysql-root-password

$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot

Kill it all round 2 cause last answer didn't work

https://stackoverflow.com/questions/15016376/cant-connect-to-local-mysql-server-through-socket-homebrew

brew services stop mysql@5.7
brew uninstall mysql@5.7
pkill mysqld
rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!
rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf

brew install mysql@5.7
brew link --force mysql@5.7
brew services restart mysql@5.7

brew link mysql@5.7 --force
mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment