欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Mac下安装mysql及简单错误处理

程序员文章站 2024-01-18 08:43:04
...

1. 首先安装Homebrew

打开终端, 输入以下一行命令,等着下载完成。顺带一提, homebrew是Mac下的一款下载神器。

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

2. 开始下载mysql

还是使用终端,输入以下一行命令

brew install mysql

3. 然后就等着

看网速了,网速好,几分钟就下好了,网速差就多等会,下载好了后差不多就会如下图所示,注意 红框框 里面写的,就是下一步
Mac下安装mysql及简单错误处理

4. 在终端输入mysql_secure_installation

输入完msyql_secure_installation后,会让你做一些设置密码类的简单操作,密码最好由字母、符号和数字组成,不然好像系统会觉得你密码不够安全,会让你重输入,这个密码需要记住, 以后要用的

luoputekiMacBook-Air:~ luopu$ mysql_secure_installation  
Securing the MySQL server deployment.  
Enter password for user root: # 输入密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.  
Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n    # 选no就行了, 不用改,就是刚刚的密码  
... skipping.
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) : y   # 禁止远程登陆
Success.  
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!
luoputekiMacBook-Air:~ luopu$    

5. 搞定 + 进入mysql

luoputekiMacBook-Air:~ luopu$ mysql.server start  # 启动mysql服务
Starting MySQL
. SUCCESS!
luoputekiMacBook-Air:~ luopu$ mysql -uroot -p  # 相当于你即将进入一个可执行sql语句的地方
Enter password:  # 输入之前设置的密码
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 Homebrew
Copyright (c) 2000, 2016, 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> # 此处可以输入sql语句,分号结尾, 回车执行

6. 简单错误处理

  • 错误一

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
    Mac下安装mysql及简单错误处理
    这个是因为mysql.server 没启动, 输入以下命令,回车

    mysql.server start

  • 错误二

    luoputekiMacBook-Air:~ luopu$ mysql -v
    ERROR 1045 (28000): Access denied for user ‘luopu’@’localhost’ (using password: NO)
    Mac下安装mysql及简单错误处理
    这个是因为’luopu’没有权限,mysql下有个超级用户’root’,可以使用root解决该错误。举例:将图片中的 mysql -v 改为 mysql -uroot -p -v 即可。

  • 错误三

    ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘rsion’ at line 1
    Mac下安装mysql及简单错误处理

    在你写的sql语句中的rsion附近由语法错误。

7. 推荐

慕课网mysql教程↗(^ω^)↗传送门走你

相关标签: mysql Mac