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

来源:互联网 发布:推荐淘宝靠谱的代购店 编辑:程序博客网 时间:2024/06/09 21:07

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 configurationof the plugin.Using existing password for root.  Estimated strength of the password: 100Change 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 havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.  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 atthe 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' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.  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 changesmade 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 2Server version: 5.7.16 HomebrewCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.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教程↗(^ω^)↗传送门走你

原创粉丝点击