Download the MySQL installation package, if it is the first installation, we recommend downloading the DMG installation package
Open the DMG installation package and double-click the pkg file in the installation package
Click "Continue", and then click "Finish"
When the installation is complete, open system preferences and you can see a MySQL icon in multiple places,
Click on the "MySQL" icon, in the pop-up interface, we notice that MySQL has been started, and is powered on from boot.
Once installed, it is a good idea to create a MySQL shortcut command that can be used directly in the terminal.
Open terminal, enter command:
sudo vim/etc/bashrc
To add a command to create an alias in BASHRC:
Alias MySQL '/usr/local/mysql/bin/mysql '
Alias Mysqladmin '/usr/local/mysql/bin/mysqladmin '
After you finish editing, you need to use "wq!" command to force the content to be saved.
Restart the terminal, and then set the MySQL root account, enter the command
Mysqladmin-u Root Password 123456
Ps:
You may have an error when executing the above command:
Mysqladmin:connect to server at ' localhost ' failed
Error: ' Access denied for user ' root ' @ ' localhost ' (using Password:no) '
If encountered, refer to "Connect to server at ' localhost ' failed"
1connect to server at ' localhost ' failed
When MySQL is installed on the MacBook Pro, an error occurs when you execute mysqladmin to set the password for the root account.
Mysqladmin:connect to server at ' localhost ' failed
Error: ' Access denied for user ' root ' @ ' localhost ' (using Password:no) '
What to do?
Tools/Materials
Method/Step
Stop MySQL service first
Open "System Preferences", select "MySQL", in the Open dialog box click "Stop mysql Server"
Open terminal, enter command: Sudo/usr/local/mysql/bin/mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
--skip-grant-tables: Do not start grant-tables (authorization table), skip permission control.
--skip-networking: Skipping the TCP/IP protocol, only native access (this option is not required.) Can not be used)
Keep the terminal open Mysqld_safe, create a new terminal, enter the command: MySQL
At this point we can log in directly to the MySQL service.
To query MySQL user information, enter the SQL command:
Select host,user,authentication_string from user;
This step is familiar to the person can skip, in the previous version of MySQL 5.7, the password column of the English name is password, but in 5.7 version changed to Authentication_string, this is to be noted.
All we need to do is reset the username root password to enter the SQL command:
Update user set Authentication_string=password (' 123456 ') where user= ' root ' and host= ' localhost ';
After setting up the user or changing the password, flush privileges will be required to flush the MySQL system permission related tables, otherwise access is denied, and another way is to restart the MySQL server for the new settings to take effect
Restart the MySQL service, open the terminal, enter the command:
Mysql-uroot-p
Enter the password you just set to successfully log in
How to install MySQL on your MacBook