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

1. 首先安装Homebrew

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

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

2. 开始下载mysql

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

brew install mysql

3. 然后就等着

看网速了,网速好,几分钟就下好了,网速差就多等会,下载好了后差不多就会如下图所示,注意 红框框 里面写的,就是下一步

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)

    这个是因为mysql.server 没启动, 输入以下命令,回车

    mysql.server start

  • 错误二

    luoputekiMacBook-Air:~ luopu$ mysql -v
    ERROR 1045 (28000): Access denied for user ‘luopu’@’localhost’ (using password: NO)

    这个是因为’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
    这里写图片描述

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

7. 推荐

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值