Mac下安裝MariaDB. 連接出現Access denied for user 'root'@'localhost' (using password: YES)

brew配置正常後輸入命令:

brew install mariadb

 

如果提示以下則說明安裝成功了

 

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
    mysql -uroot

To have launchd start mariadb at login:
  ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
  mysql.server start

大致意思是你可以利用上面的命令, 來設置自啓動服務.

如果你不需要自啓動, 可以用mysql.server start來啓動

本人是不喜歡自啓動的, 所以就用mysql.server start

➜  ~ mysql.server start
Starting MySQL
. SUCCESS! 
➜  ~ 

提示如下的話, 說明啓動成功了!下面開始操作數據庫

 

➜  ~ mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.0.21-MariaDB Homebrew

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MariaDB [(none)]> exit
Bye
➜  ~ 

至此,MariaDB就可以正常用了.

MariaDB跟MySQL用起來是一樣一樣的, 好久沒有大量操作數據庫, 這次想自己搞個東西, 可能以後會遇到很多坑, 這裏也提醒自己到時候要及時記錄下來.

最後

 

➜  ~ mysql.server stop
Shutting down MySQL
.. SUCCESS! 
➜  ~ 

上面說的是理想狀態下mysql的啓動,啓動後登陸不進去的情況:

錯誤信息爲:Access denied for user 'root'@'localhost' (using password: YES)

解決方法:

第一步:蘋果->系統偏好設置->MySQL,關閉mysql服務

第二步:

進入終端

輸入(cd /usr/local/mysql/bin/)回車

輸入(sudo su)回車以獲取管理員權限

輸入(./mysqld_safe --skip-grant-tables &)回車以禁止mysql驗證功能,mysql會自動重啓,偏好設置中的mysql狀態會變成running

第三步:

新建一個終端窗口(cmd+T),

輸入命令(./mysql)回車

輸入命令(flush privileges;)分號別忘記輸了

輸入命令(set password for 'root'@'localhost' = password('root');) password('root')中的root爲新密碼,自己隨便設置,分號別忘記輸入

至此,密碼修改成功,可以正常登入了。

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