start mysql server mac code example

Example 1: install mysql on mac

Using Homebrew:
brew install mysql
brew tap homebrew/services
brew services start mysql
mysqladmin -u root password 'secretpaSSw0rd'

Using Docker:
docker pull mysql/mysql-server
docker run --name=mysql -d mysql/mysql-server

Example 2: stop mysql server mac

brew services stop mysql
brew services start mysql
brew services restart mysql

Example 3: start mysql server mac

sudo mysql.server start

Example 4: mac install mysql

brew install mysql

sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start

sudo mysql
// set password for root user, or change root to another user
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
FLUSH PRIVILEGES;

exit
mysql -u root -p

Example 5: restart mysql mac

alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'

Example 6: start mysql server mac

alias mysqlstart='sudo /usr/local/mysql/support-files/mysql.server start'
alias mysqlstop='sudo /usr/local/mysql/support-files/mysql.server stop'