MacOS high Sierra安装最新版本MySQL

时间:2024-03-20 22:20:54

MacOS high Sierra安装最新版本MySQL

MacOS high Sierra安装最新版本MySQL

      建议使用Homebrew安装和维护MySQL,这种方法容易升级,并且还包括启动MySQL的能力。Homebrew是一个第三方的软件包管理器,类似于yum或apt。类似Linux软件包管理器。它提供了一种简单的方式来安装第三方软件,并且保持软件自动更新到最新版本。

        在装MySQL之前,必须具备三个条件:

  • Mac必须安装Xcode,可以从Apple Store中安装;
  • 当前系统不能有MySQL。如已经安装了MySQL,要确保MySQL完全被卸载删除,连同它的所有文件和目录。


第一件事就是打开一个终端窗口,确保你已接受Xcode许可协议,用以下命令:

 sudo xcodebuild -license

安装Homebrew:

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

现在安装MySql

brew install mysql

如果本机已经有MySql,可以用以下命令升级mysql到最新版本

brew upgrade mysql

一旦安装完成,我们将要处理更多的事情。首先,让我们在重启系统时告诉它自动启动:

brew services start mysql

默认情况下,MySQL是安装在没有root密码的情况下。这被认为是不安全的,所以让我们得到一套:

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: Y


There are three levels of password validation policy:


LOW    Length >= 8

MEDIUM Length >= 8, numeric, mixed case, and special characters

STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file


Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Please set the password for root here.


New password: 


Re-enter new password: 


Estimated strength of the password: 50 

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

 ... Failed! Error: Your password does not satisfy the current policy requirements


New password: 


Re-enter new password: 


Estimated strength of the password: 50 

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

 ... Failed! Error: Your password does not satisfy the current policy requirements


New password: 


Re-enter new password: 


Estimated strength of the password: 50 

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

 ... Failed! Error: Your password does not satisfy the current policy requirements


New password: 


Re-enter new password: 


Estimated strength of the password: 100 

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

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) : n


 ... skipping.

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!


  • 验证密码插件-您可以通过启用MySQL来强制执行强密码,这是可选的。
  • 删除匿名用户-建议这样做。
  • 禁止root远程登录–建议这样做,如果需要远程访问你的数据库,应该给特定用户添加数据库权利。
  • 删除测试数据库并访问它——推荐。
  • 现在重新加载权限表-选择Yes。

一旦我们完成了这项工作,MySQL就在我们的系统上运行。现在我们可以测试它了:

mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 4

Server version: 5.7.21 Homebrew


Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>

现在可以通过命令行来管理MySQL数据库和用户;或者我们也可推荐作为图形界面的Sequel Pro

将来升级Homebrew and MySQL ,使用如下命令:

brew update

brew upgrade




------------------------------------------------------------------------------------

⚠️ Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷。

援引官方的一句话:又提示缺少套件啦?别担心,Homebrew 随时守候。Homebrew – OS X 不可或缺的套件管理器。

⏰:可以用以下步骤卸载HomeBrew

$cd `brew --prefix`

$rm -rfCellar

$brew prune

$rm `git ls-files`

$rm -rLibrary/HomebrewLibrary/AliasesLibrary/FormulaLibrary/Contributions

$rm -rf .git

$rm -rf ~/Library/Caches/Homebrew



[email protected]