Mac下Brew 卸载MySql以及安装Mysql 阿星小栈

卸载:

brew remove mysql


brew cleanup


launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysqld.plist


rm ~/Library/LaunchAgents/com.mysql.mysqld.plist


sudo rm -rf /usr/local/var/mysql

 

brew uninstall mysql@5.7
rm -rf /usr/local/var/mysql
rm /usr/local/etc/my.cnf

--- 然后安装

brew install mysql@5.7  // 安装
brew link --force mysql@5.7 // 链接
brew services start mysql@5.7 // 启动服务
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc // 输出到环境变量

 

安装:

搜索一下mysql版本:

brew search mysql
==> Formulae
automysqlbackup       mysql-cluster         mysql-search-replace  mysql@5.7
mysql                 mysql-connector-c     mysql-utilities       mysqltuner
mysql++               mysql-connector-c++   mysql@5.5
mysql-client          mysql-sandbox         mysql@5.6
 
 
==> Casks
homebrew/cask/mysql-connector-python         homebrew/cask/navicat-for-mysql
homebrew/cask/mysql-shell                    homebrew/cask/sqlpro-for-mysql
homebrew/cask/mysql-utilities

安装mysql:

 brew install mysql@5.7

 ln -sfv /usr/local/opt/mysql@5.7/*.plist ~/Library/LaunchAgents

启动mysql服务

$ mysql.server start

继续执行mysql_secure_installation

cometdeMacBook-Pro:~ comet
$ 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
 
 ... 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!

 

 

修改root密码

以前修改mysql密码字段是Password这个字段,但是mysql5.7没有这个字段而是使用了authentication_string替代

如果操作过程中报下面的错误

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

那么使用首先关闭mysql服务,然后以安全模式启动
mysql.server start --skip-grant-tables

  1. use mysql

  2. update user set authentication_string = password('root') where User='root';

  3. Query OK, 1 row affected, 1 warning (0.00 sec)

  4. Rows matched: 1 Changed: 1 Warnings: 1

  5. mysql> flush privileges;

  6. Query OK, 0 rows affected (0.00 sec)

最后可以参考:

https://blog.csdn.net/cheng649090216/article/details/79246333

https://blog.csdn.net/Bobdragery/article/details/90068643

https://blog.csdn.net/cheng649090216/article/details/79246333

https://www.jianshu.com/p/12e885cb6e33


版权声明:本文为u010244476原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。