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用起来是一样一样的, 好久没有大量操作数据库, 这次想自己搞个东西, 可能以后会遇到很多坑, 这里也提醒自己到时候要及时记录下来.

扫描二维码关注公众号,回复: 10607201 查看本文章

最后

➜  ~ 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为新密码,自己随便设置,分号别忘记输入

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

发布了172 篇原创文章 · 获赞 45 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/fish_study_csdn/article/details/104220715
今日推荐