Mac 連接MySQL數據庫的坑

1. 安裝MySQL

大家可以官網下載一步步的安裝,我用的是Mac,直接用brew命令安裝了,比較方便。

(base) ➜  backend git:(master) ✗ brew reinstall mysql

2. 安裝完成之後可以嘗試啓動或者停止MySQL服務,MySQL會啓動一個服務到後臺

啓動服務:

(base) ➜  backend git:(master) ✗ mysql.server start

停止服務:

(base) ➜  backend git:(master) ✗ mysql.server stop

3. 修改root密碼

嘗試了UPDATE和SET都沒有Work,最後用的ALTER竟然解決了問題,大家也可以參考一下。

UPDATE和SET的提示如下:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('123456') WHERE User='root'' at line 1
mysql> FLUSH PRIVILEGES
    -> ;
Query OK, 0 rows affected (0.00 sec)

解決方法如下,初始密碼是空,直接敲回車即可:

4. 改好了密碼,我們來用MySQLWorkbench來登錄一下,填好一堆東西后報錯了。

Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found

網上找了一下,發現是我登錄的MySQLWorkbench的認證方式用的是mysql_native_password,而新裝的MySQL是用caching_sha2_password,所以需要用caching_sha2_password登錄會提示load不了。

可以把我們這個root賬號的登錄方式改一下:

(1)命令行登錄到mysql

(base) ➜  backend git:(master) ✗ mysql -uroot -p

(2)更改數據庫到mysql

mysql> use mysql

(3)查看用戶的狀態

mysql> select user,host,plugin,authentication_string from user;

(4)更改root的plugin

mysql> alter user 'root'@'%' identified with mysql_native_password by '123456';

(5)再次查看狀態

這個時候,我們已經更改成功了。讓我們再次嘗試用MySQLWorkbench登錄試試,發現成功了。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章