1: https://dev.mysql.com/downloads/ Download the Community version "Mac OS X 10.12 (x86, 64-bit), DMG Archive"
2: Double-click the last step of the installation to generate a random database password. Be sure to remember it. Otherwise it will be very troublesome
3: Open the terminal and enter mysql --version to check the installation status.
4: If the query fails, you need to configure the environment variable. Modify the .bash_profile file and add the following content
: export PATH=${PATH}:/usr/local/mysql/bin
Save and execute source ~/.bash_profile to make the environment variable take effect
5: Log in to the database
mysql -u root -p
The login is successful, but an error will be reported when running the command, prompting us to reset the password. (The password is the password in the second step)
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement
before executing this statement.
mysql>
modify the password, the new password is 123456
set PASSWORD =PASSWORD(' 123456');
execute show databases again; it will be normal.
6: Code set settings
mysql> show variables like '%char%';
+--------------------------+--------------------------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.18-macos10.12-x86_64/share/charsets/ |
+------------- ------------+-------------------------------------- -------------------+
8 rows in set (0.00 sec)
character_set_database is latin1 by default. If you input Chinese, there will be garbled characters. The my.cnf file needs to be modified. It is not available under /etc by default. You need to create one yourself. The content of the file is as follows:
[mysqld]
character-set-server=utf8mb4
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
Restart the mysql service and query
again
+--------------------------+-----------------------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------------------+
| character_set_client | utf8mb4 |
| character_set_connection | utf8mb4 |
| character_set_database | utf8mb4 |
| character_set_filesystem | binary |
| character_set_results | utf8mb4 |
| character_set_server | utf8mb4 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql-5.7.18-macos10.12-x86_64/share/charsets/ |
+------------- ------------+-------------------------------------- ----------------------+
8 rows in set (0.00 sec)
Modified complete#
mac mysql 5.7 installation process
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326265213&siteId=291194637
Ranking