Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac mysql 安装及初始配置 #36

Open
weekeight opened this issue Nov 4, 2015 · 0 comments
Open

mac mysql 安装及初始配置 #36

weekeight opened this issue Nov 4, 2015 · 0 comments
Labels

Comments

@weekeight
Copy link
Owner

mac mysql 安装及初始配置

安装

通过安装包安装

访问官网MySQL Community Server的下载页面,如果对性能或者簇群的特别需要选这个版本就好,不用选择下载MySQL Cluster Community Edition

通过 homebrew 安装

// 如果尚未安装过homebrew
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
brew install git
brew update

// 安装mysql
brew install mysql

安装完成后,若是Unix系统一般会把常用的命令都软连接到了 /usr/local/bin 里方便在命令行下直接使用

初始配置

初始化数据目录

注意:通过二进制文件或者源码编译安装的方式数据目录没有自动初始化配置的,需要手动处理,而通过 dmg等方式安装的则默认初始化好了数据目录。

具体步骤请查看Initializing the Data Directory

启动mysql服务

// 以 root 身份启动服务
mysqld_safe --user=root &

测试mysql服务器

// 查看mysqladmin 当前版本
mysqladmin version

// 将会输出类似如下结果
mysqladmin  Ver 8.42 Distrib 5.6.27, for osx10.10 on x86_64
Copyright (c) 2000, 2015, 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.

Server version      5.6.27
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /tmp/mysql.sock
Uptime:         8 min 11 sec

Threads: 1  Questions: 23  Slow queries: 0  Opens: 87  Flush tables: 1  Open tables: 80  Queries per second avg: 0.046

可通过下面命令来查看当前有哪些数据库

mysqlshow --user=root

// 将会输出类似一下的结果
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+

修改初始账号密码

mysql 的账号密码是记录在mysql的系统数据库user表里面的
所有命令都参考自官网Securing the Initial MySQL Accounts

mysql 安装完成后,初始默认有 root 账号及匿名账号并且其密码为空。可通过下面命令查看初始账号密码列表

mysql -e "SELECT User, Host, password FROM mysql.user" mysql --user=root

// 输出结果应该类似下面
+------+-----------+----------+
| User | Host      | password |
+------+-----------+----------+
| root | localhost |          |
| root | 127.0.0.1 |          |
| root | ::1       |          |
|      | localhost |          |
+------+-----------+----------+

通过下面命令来重设root账号的密码

// 将下面的 newpwd 替换成自己的密码
shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'::1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

因为此时还存在匿名账号,建议不允许匿名登录,那么可以通过下面命令来移除匿名账号

shell> mysql -u root -p
Enter password: (enter root password here)
mysql> DROP USER ''@'localhost';

注: 上面命令为官方所介绍,但是在 [email protected] mysql@Ver 14.14 Distrib 5.6.27下设置后再查看发现 [email protected] 并没有改掉了密码,但是实际已经生效,此外匿名账号也没有删除,后来通过可视化工具直接删除了(下面有介绍)

完成这一切后,再次使用root账号登录mysql就需要加入参数 -p 及输入密码了

添加管理用户

若要添加额外的管理用户及做好各数据库的权限管理,具体请查看官网Adding User Accounts

可视化工具

首推sequel pro可以方便快捷地通过可视化界面来操作数据库

@weekeight weekeight changed the title nodejs mysql nodejs mysql mac mysql 安装及初始配置 Nov 4, 2015
@weekeight weekeight changed the title nodejs mysql mac mysql 安装及初始配置 mac mysql 安装及初始配置 Nov 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant