MySQL
安装MySQL
首先,在浏览器中输入如下网址,
http://dev.mysql.com/downloads/mysql/
点击Looking for previous GA versions? 笔者选择的是5.7.23 | macOS | x86 64-bit dmg版本, 点击Download,
下载完成后,按照提示一路安装, 中途默认会弹出一个提示框, 有密码信息. 需要保存下来,
2018-09-01T12:43:34.387205Z 1 [Note] A temporary password is generated for root@localhost: ifnu<,Zpd5jf
If you lose this password, please consult the section How to Reset the Root Password in the MySQL reference manual.
安装成功后, 在系统偏好设置这里,有MySQL
点击Start MySQL Server启动PHP
启动过后,在终端中输入如下命令,查看MySQL版本
mysql --version
在本机中版本信息如下
mysql Ver 14.14 Distrib 5.7.22, for macos10.13 (x86_64) using EditLine wrapper
如果提示command not found, 这是因为该命令默认访问/usr/local/bin/mysql路径下的mysql, 我们可以在终端输入如下命令,建立一个软链接即可
sudo ln -fs /usr/local/mysql/bin/mysql /usr/local/bin/mysql
登录MySQL服务, 输入如下命令回车
mysql -u root -p
终端要求输入密码
Enter password:
输入刚才安装MySQL保存的的密码
密码输入不会在终端显示占位符,输入完成后, 直接按回车键 /xb是笔者主机名/
![]()
显示欢迎信息, 表示登录成功.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
输入\s
mysql> \s
提示需要重置系统默认生成的密码
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing
更改密码
mysql> ALTER USER 'root'@'localhost' identified by '123456'
回车后, 要求再次输入系统默认生成的密码, 回车
Query OK, 0 rows affected (0.00 sec)
更改密码已经完成.
mysql> \s
mysql Ver 14.14 Distrib 5.7.22, for macos10.13 (x86_64) using EditLine wrapper
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.22 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 22 min 17 sec
退出MySQL连接
mysql> \q
MySQL的启动与停止
在系统偏好设置中启动与停止MySQL服务.
在命令行输入如下指令,启动与停止MySQL服务
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
phpMyAdmin
MySQL可视化管理方式
首先,在浏览器中输入如下网址,下载图中所示文件
https://www.phpmyadmin.net/downloads/
下载phpMyAdmin-4.8.4-all-languages.tar.gz
将压缩文件解压到/资源库/WebServer/Documents/路径下, 并重命名为phpMyAdmin, 再次,将文件夹中的config.sample.inc.php文件重命名为config.inc.php
再次,将config.inc.php文件中的如下代码进行修改
// 修改前:
$cfg['Servers'][$i]['host'] = 'localhost';
// 修改后:
$cfg['Servers'][$i]['host'] = '127.0.0.1';
最后,在浏览器中输入如下网址进行登录即可直接对MySQL进行可视化管理
注: 用户名: root 密码: 123456 (刚刚更改的密码) 至此, 配置Apache, Php, mySql结束.
如果不更改Php默认安装自动生成的密码, 在这里使用一样的密码也无法登录