苹果电脑 Mac brew 安装 MySQL 和 MariaDB 后,默认下面的命令是无法登陆的
mysql -u root
输出结果如下
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
一般情况下,这是缺少密码,但是我们并不知道密码是什么啊
mysql -uroot -p
输出结果如下
Enter password: ERROR 1698 (28000): Access denied for user 'root'@'localhost'
安装的时候也没啥提示啊
==> Downloading https://homebrew.bintray.com/bottles/mariadb-10.4.6.high_sierra.bottle.tar.gz ==> Downloading from https://akamai.bintray.com/b4/b4466c2e19ab1e71f29f1b2a864869840c1ad1ff3c37a4e7a68573d503d30a00?__gda__=exp=156405 ######################################################################## 100.0% ==> Pouring mariadb-10.4.6.high_sierra.bottle.tar.gz ==> /usr/local/Cellar/mariadb/10.4.6/bin/mysql_install_db --verbose --user=yufei --basedir=/usr/local/Cellar/mariadb/10.4.6 --datadir= ==> Caveats A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. MySQL is configured to only allow connections from localhost by default To connect: mysql -uroot To have launchd start mariadb now and restart at login: brew services start mariadb Or, if you don't want/need a background service you can just run: mysql.server start ==> Summary ???? /usr/local/Cellar/mariadb/10.4.6: 745 files, 179.3MB
好吧,没办法了
经过千辛万苦,终于在 MariaDB 的官网上找到答案了
In this case, the following defaults apply: The host name is localhost. The user name is either your Unix login name, or ODBC on Windows. No password is sent. The client will connect to the server, but not any particular database on the server.
大概的意思是说,默认情况下, MariaDB 的默认 host 是 localhost
,默认的登陆用户名是电脑的登陆用户名,也就是开机的登陆用户名,比如我的是 yufei
,默认的密码是空的。
于是,登陆就改成了下面这个
mysql -u yufei
输出结果如下
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 12 Server version: 10.4.6-MariaDB Homebrew Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
哈哈,终于连接上了。
目前尚无回复