一、安裝、卸載mysql
安裝mysql:brew install mysql
卸載mysql:brew uninstall mysql
二、啓動mysql
進入到mysql目錄:默認會在usr/local下
啓動mysql:/usr/local/Cellar/mysql/8.0.18_1/support-files/mysql.server start
停止mysql:/usr/local/Cellar/mysql/8.0.18_1/support-files/mysql.server stop
重啓mysql:/usr/local/Cellar/mysql/8.0.18_1/support-files/mysql.server restart
三、使用mysql
進入mysql:mysql -uroot -p
默認沒有密碼,直接回車
查看數據庫:show databases;
查看數據表: show tables;
增刪改查:select delete update .......等命令,每個命令後需要加分號進行結束
四、修改mysql密碼
ALTER
user
'root'
@
'localhost'
IDENTIFIED
BY
'新密碼';
修改密碼後重新啓動mysql。
網上有很多使用password()函數進行修改密碼的,看到一篇文字寫道:
查閱很多才知道在mysql 5.7.9以後廢棄了password字段和password()函數
若忘記密碼的情況下想要修改密碼:
需要跳過權限認證:--skip-grant-tables
方法:網上有直接的命令,我這裏說的是另外一種,在文件中添加--skip-grant-tables,mac在/usr/local/etc/my.cnf文件中添加。
五、報錯
1、Column count of mysql.user is wrong. Expected 50, found 49. Created with MySQL 80012, now running 80013. Please use mysql_upgrade to fix this error.
解決:使用命令mysql_upgrade -u root -p 回車即可。
2、mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'Test123#';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
需要將--skip-grant-tables去掉,再重新啓動,進行修改密碼。
3. idea 上連接mysql時,沒有密碼連接不上
mysql設置個密碼即可,具體沒了解