安装
在终端执行以下命令即可完成mysql的安装
brew install mysql
安装成功提示:
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.19: 322 files, 233MB
登录
mysql -uroot -p
退出
mysql> exit
mysql> quit
常用命令
- 显示服务版本号
select Version(); - 显示当前日期时间
select now(); - 显示当前用户
select user();
常用操作
- 创建数据库
指定了数据库的默认编码格式
CREATE DATABASE mydb CHARACTER SET utf8;
- 显示数据库
mysql> SHOW DATABASES;
- 删除数据库
DROP DATABASE mydb;
- 修改数据
ALTER DATABASE mydb set ...