Mac 安装 mysql, Sequel Pro 辅助处理数据库
2018-03-01 本文已影响593人
喜欢书的女孩
2018-1-1.jpg
[1] In Terminal , install mysql
➜ ~ brew install mysql //[1] 安装
==> Installing mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.20.sierra.bottle.
######################################################################## 100.0%
==> Pouring mysql-5.7.20.sierra.bottle.tar.gz
==> /usr/local/Cellar/mysql/5.7.20/bin/mysqld --initialize-insecure --user=sweet
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/5.7.20: 324 files, 233.7MB
➜ ~ where is mysql //[2] 查看安装位置
is not found
/usr/local/bin/mysql
➜ ~ brew info mysql //[3] 查看sql 的版本信息
mysql: stable 5.7.20 (bottled)
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
Conflicts with:
mariadb (because mysql, mariadb, and percona install the same binaries.)
mariadb-connector-c (because both install plugins)
mysql-cluster (because mysql, mariadb, and percona install the same binaries.)
mysql-connector-c (because both install MySQL client libraries)
percona-server (because mysql, mariadb, and percona install the same binaries.)
/usr/local/Cellar/mysql/5.7.20 (324 files, 233.7MB) *
Poured from bottle on 2017-10-29 at 23:35:53
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
==> Dependencies
Build: cmake ✘
Required: openssl ✔
==> Requirements
Required: macOS >= 10.7 ✔
==> Options
--with-archive-storage-engine
Compile with the ARCHIVE storage engine enabled
--with-blackhole-storage-engine
Compile with the BLACKHOLE storage engine enabled
--with-debug
Build with debug support
--with-embedded
Build the embedded server
--with-local-infile
Build with local infile loading support
--with-test
Build with unit tests
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
➜ ~ mysql.server start //[4] 开启服务
Starting MySQL
. SUCCESS!
➜ ~ mysql.server stop //[5] 停止服务
Shutting down MySQL
.. SUCCESS!
➜ ~ sudo mysql //[打开数据库报错]
Password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
➜ ~ mysql.server start //[开启服务]
Starting MySQL
. SUCCESS!
➜ ~ mysql //[没有设置密码]
ERROR 1045 (28000): Access denied for user 'sweetgirl'@'localhost' (using password: NO)
➜ ~ mysql.server stop //[关闭服务]
Shutting down MySQL
.. SUCCESS!
➜ ~ mysql.server shutdown //[没有这个命令]
Usage: mysql.server {start|stop|restart|reload|force-reload|status} [ MySQL server options ]
➜ ~ mysql.server status //[查看服务的状态]
ERROR! MySQL is not running
➜ ~ cd /usr/local/mysql/bin/ //[6]进入bin目录
cd: no such file or directory: /usr/local/mysql/bin/
➜ ~ which mysqld_safe //[7]查看地址
/usr/local/bin/mysqld_safe
➜ bin sudo /usr/local/bin/mysqld_safe //[8]进入
Password:
2017-10-30T01:46:34.6NZ mysqld_safe Logging to '/usr/local/var/mysql/SweetdeMacBook-Air.local.err'.
2017-10-30T01:46:34.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/var/mysql
2017-10-30T01:46:34.6NZ mysqld_safe mysqld from pid file /usr/local/var/mysql/SweetdeMacBook-Air.local.pid ended
➜ ~ mysql.server start //[9]启动服务
Starting MySQL
. SUCCESS!
➜ ~ sudo mysql //[10]打开数据库
Password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20 Homebrew
Copyright (c) 2000, 2017, 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 //[11]显示数据库
->
->
-> \q //[12]放弃编辑
Bye
➜ ~ mysql.server status //[13] 查看编辑状态
SUCCESS! MySQL running (3451)
➜ ~ mysql.server stop //[14]关闭服务
Shutting down MySQL
.. SUCCESS!
➜ ~
[2] 编辑数据库的命令
1.1 create 创建数据库
1.2 show 查看所有数据库
1.3 alter 修改数据库
1.4 use 使用数据库
1.5 查看当前使用的数据库
1.6 drop 删除数据库
2、数据表(table)管理
2.1 create 创建表
2.2 show 显示表
2.3 desc 查看表结构
2.4 alter 修改表结构(增、删、改)
2.4.1 insert 在表中添加列(字段)
2.4.2 alter 修改表(列)字段
2.4.3 delete 删除表(列)字段
2.4.4 rename 重命名表名
2.5 create 利用已有数据创建新表
3、数据的操作及管理
3.1 增加数据(增)
3.2 删除数据(删)
3.3 修改数据(改)
3.4 查询数据(查)
4、管理视图
[3] Sequel Pro
- 下载
- 打开软件
image.png
- connect mysql
image.png
[4] 做为 android 程序媛
还是要知道多一些数据库的知识。有时间就多学点。