mac os 安裝 MySQL

mysql

業務需要最近需要用nodejs爬數據,并把數據存儲在數據庫。于是選擇了mysql,在官網一頓下載,搞了半天沒下載下來。 學習到一種快速便捷的方式。 homebrew 是個不錯的工具

1. 使用Homebrew進行安裝

homebrew 是一款 Mac OS 平臺下的軟件包管理工具,擁有安裝、卸載、更新、查看、搜索等很多實用的功能。簡單的一條指令,就可以實現包管理,而不用你關心各種依賴和文件路徑的情況,十分方便快捷.

下載 homebrew 復制以下代碼復制以下代碼直接在終端回車執行即可;如果已有homebrew請忽略。

  /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

2. 安裝mysql

  brew install mysql
......
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start

3. mysql 初始化

  mysql_secure_installation

可能會出現這樣的問題

Securing the MySQL server deployment.

Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock'

先執行一下 mysql.server start 然后再執行 mysql_secure_installation 即可

4. All done!

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT 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 component?

Press y|Y for Yes, any other key for No: N
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

 ... 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
 - 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!

5. mysql

  # 登錄mysql
  mysql -u root -p
  # 然后輸入密碼,我的密碼是123456
  123456
  # 退出mysql
  exit
  # 啟動mysql
  brew services start mysql
  # 停止mysql
  brew services stop mysql
  # mysql 8.0 修改密碼
  ALTER user 'root'@'localhost' IDENTIFIED BY '111111';

好了什么都不說了,我要去擼*了??

雅蠛蝶

報錯1: MYSQL:ER_NOT_SUPPORTED_AUTH_MODE:Client does not support authentication protocol

報錯2:[解決MySQL8.0報錯:Unknown system variable 'validate_password_policy'](https://www.bbsmax.com/A/ke5j2ml95r/

)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容