Mac下使用 brew 安裝mysql

1、打開mac控制檯mysql

brew install mysql@5.7 複製代碼
修改環境變量複製代碼
vi ~/.zshrc

export PATH=${PATH}:/usr/local/Cellar/mysql@5.7/5.7.24/bin

source ~/.zshrc複製代碼

2、啓動mysql服務git

mysql.server start複製代碼

3、初始化mysql配置sql

mysql_secure_installation複製代碼
WXiangQianMacBook-Pro:~ wxq$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N   // 這個選yes的話密碼長度就必需要設置爲8位以上,但我只想要6位的
Please set the password for root here.

New password:             // 設置密碼

Re-enter new password:     // 再一次確認密碼
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y    // 移除不用密碼的那個帳戶
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n  //不接受root遠程登陸帳號

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y  //刪除text數據庫
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!複製代碼

設置密碼時提示:ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number;數據庫

使用其餘語句時, 老是會提示 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement. 意思就是說必須先設置一個密碼bash

而設定密碼時又提示 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number ;ui

這是由於 你輸入的密碼是明文, 不容許這麼輸入. 能夠在其餘已安裝過mysql的終端使用 select password('你想輸入的密碼');查詢出你的密碼對應的字符串, 而後用這個字符串替換你的密碼.this

這樣mysql就安裝成功了spa

mysql -u root -p 輸入密碼之後i就能夠正常進入了code

相關文章
相關標籤/搜索