安裝
在終端執(zhí)行以下命令即可完成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
常用命令
- 顯示服務(wù)版本號(hào)
select Version(); - 顯示當(dāng)前日期時(shí)間
select now(); - 顯示當(dāng)前用戶
select user();
常用操作
- 創(chuàng)建數(shù)據(jù)庫(kù)
指定了數(shù)據(jù)庫(kù)的默認(rèn)編碼格式
CREATE DATABASE mydb CHARACTER SET utf8;
- 顯示數(shù)據(jù)庫(kù)
mysql> SHOW DATABASES;
- 刪除數(shù)據(jù)庫(kù)
DROP DATABASE mydb;
- 修改數(shù)據(jù)
ALTER DATABASE mydb set ...