您的位置:首页 > 数据库 > MySQL

Mac下安装新版MySQL5.7

2015-11-07 16:34 585 查看
(1) 停止 MySQL 服务

如果在
System Preferences
中有
MySQL
图标,则进入点击
Stop MySQL Server


如果
System Preferences
中没有
MySQL
,则在 Terminal 中

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


(2) 安装新版 MySQL

旧版目录如下

/usr/local/mysql
/usr/local/mysql-5.6.25-osx10.8-x86_64


下载并安装新版,安装过程中出现如下信息

2015-10-24T17:22:13.767265Z 1 [Note] A temporary password is generated for root@localhost: t?,oZi*5BwST

If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.


为 root 生成了一个随机密码。

新版目录如下

/usr/local/mysql-5.7.9-osx10.9-x86_64


(3) 启动 MySQL

如果在
System Preferences
中有
MySQL
图标,则进入点击
Stop MySQL Server
启动。

也可以使用命令启动

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


(4) 便捷设置

为方便使用 MySQL

cd /etc
sudo chmod +w bashrc
sudo vi bashrc
#在bashrc最后添加下面两行
alias mysql='/usr/local/mysql/bin/mysql'
alias mysqladmin='/usr/local/mysql/bin/mysqladmin'


重启终端生效

(6) 使用生成密码登录

WeiHeLi:~ weiheli$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 322
Server version: 5.7.9

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.

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

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.


需要修改密码。

(6) 修改密码

修改密码

# 设置新密码为`root`
mysqladmin -u root -p password root


然后要求输入老密码
t?,oZi*5BwST


mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
mysqladmin: unable to change password; error: 'File './mysql/user.MYD' not found (Errcode: 13 - Permission denied)'


需要设置权限

sudo chown -R mysql /usr/local/mysql/data/


然后,重新设置密码。

(7) 旧数据转移

将旧版本数据库的
data
文件复制到新版数据库的
data
中去。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: