Mac系统MySQL命令行操作
安装
brew install mysql
默认安装路径:
/usr/local/Cellar/mysql/8.0.19/bin
把上面的路径添加到~/.zshrc 文件中,方法参考这篇文章。
启动
bash mysql.server start
Start SQL Connection
mysql.server start
Close SQL Connection
mysqld stop
Open Bash Terminal for Local Development
mysql -u root -p
提示输入密码,没有密码直接回车
修改密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpassword');
退出命令行
exit或者quit
Error
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
brew doctor
brew remove mysql
brew install mysql
再启动即可。
Export Database
mysqldump -u root -p database_name > file_name.sql