Mac 安装配置MySQL(新手入门)

  原文链接: http://zl378837964.iteye.com/blog/2360610

 

记录如下操作:

1、官网下载mysql,传送门:https://dev.mysql.com/downloads/mysql/

安装dmg包 --- Mac OS X 10.12 (x86, 64-bit), DMG Archive 安装即可,当然你也可以使用tar压缩版。

 

2、安装完成后终端输入:

mysql --version

可能会显示-bash: command not found;

那么,”/usr/local/mysql/bin/mysql”为mysql默认安装路径:

$ cd /usr/local/bin/

$ sudo ln -fs /usr/local/mysql/bin/mysql mysql  建立软链,方便操作

 

3、开关mysql服务命令如下:

$ sudo /usr/local/mysql/support-files/mysql.server start

$ sudo /usr/local/mysql/support-files/mysql.server stop

提示:mysql服务开关可以在系统偏好设置里面操作的哦,此处先关闭mysql服务

 

4、配置root账号的密码,默认没有配置(安装过程中似乎提示有个随机的密码,没大注意)

 

### 在终端内输入(开启安全模式启动mysql):

$ sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

 

### 修改密码,终端逐行输入(注意修改为自己想要设置的密码):

$ mysql -u root

会显示如下:

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

Your MySQL connection id is 3

Server version: 5.7.17 MySQL Community Server (GPL)

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

。。。 。。。

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

mysql> 输入

  update mysql.user SET authentication_string=PASSWORD('root') WHERE User='root';

mysql> 输入

  flush privileges;

即可

 

5、配置完成后验证,在终端输入:

mysql -u root -p

 提示输入密码,进入mysql说明成功!

mysql> show databases;

 

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

对于这个提示,只需如下三步:

<1> SET PASSWORD = PASSWORD('root');

<2> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;

<3> flush privileges;

 

然后 mysql> show databases;

测试成功,可以查看到

mysql> select host,user from user;

+-----------+-----------+

| host      | user      |

+-----------+-----------+

| localhost | mysql.sys |

| localhost | root      |

 +-----------+-----------+

 

 

猜你喜欢

转载自zl378837964.iteye.com/blog/2360610
今日推荐