The installation

Brew install mysql brew install mysql@ Version (installation version) mysql --version Check whether the installation is successfulCopy the code

The following figure shows the successful installation

Start and stop the MySQL service

sudo mysql.server start
Copy the code

`sudo mysql.server stop`
Copy the code

Configuring user root

MySQL has its own user system, the default user is root, no password. You can set the password by using the following command

mysqladmin -u root password 
New password: 
Confirm new password: Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.`
Copy the code

Mysql > select * from mysqladmin where user = ‘root’; mysql > select * from mysqladmin where user = ‘root’;

Connect to the database as user root

By default, no secret login is required

Mysql -u root If you have a password, run the following command: mysql -u root -pCopy the code

Exit the MySQL

exit;

Mysql > delete mysql(MAC)

ps -ax | grep mysql
# stop and kill any MySQL processes
brew remove mysql
brew cleanup
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
# edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
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*
# restart your computer just to ensure any MySQL processes are killed
# try to run mysql, it shouldn't work

Copy the code

Some problems may occur when the preceding command is executed:

  • Save failed startup attempt at startup plus sudo
  • If sudo does not work, mysql may not have permissions on some folders
sudo chown -R _mysql /usr/local/var/mysql
sudo chmod -R o+rwx /usr/local/var/mysql
Copy the code

Some problems occurred during MySQl connection

Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

Error cause: Mysql8.0 or higher encryption mode, Node does not support.

Solution:

Open MySql command line terminal and enter (SQL is my local login MySql account)

  1. alter user ‘root’@’localhost’ identified with mysql_native_password by ‘sql’;
  2. flush privileges;

Then you’re done. If that doesn’t work, you can download a lower version of mysql

Description:

The Flush PRIVILEGES command essentially extracts user information/permission Settings from the current User and Privilige tables into memory from the mysql library, the built-in library of the mysql database. Often used to change passwords and authorize superusers

Question 2: ERROR! The server quit without updating PID file (/usr/local/var/mysql/XX.local.pid)

Solution:

  1. Enter the sudo chown -r _mysql /usr/local/var/mysql command
  2. Run the following command to restart mysql: sudo mysql.server restart