简体   繁体   English

在终端中运行mysql命令时如何在mac OS中指定默认用户?

[英]How to specify default user in mac OS when running the mysql command in terminal?

I'm on mac OS Catalina 10.15.2 with a fresh install of mysql.我在 mac OS Catalina 10.15.2 上使用全新安装的 mysql。 I'm getting the following output when running the commands mysql or mysql -v :运行命令mysqlmysql -v时,我得到以下输出:

ERROR 1045 (28000): Access denied for user 'timothyfisher'@'localhost' (using password: NO)

This is because the user isn't set to root in my case.这是因为在我的情况下,用户没有设置为root MySQL works just fine as I can enter with mysql -u root , so this isn't really causing any problems but it gets kind of annoying. MySQL 工作得很好,因为我可以输入mysql -u root ,所以这并没有真正引起任何问题,但它有点烦人。

How can I set the mysql command to use the root user instead of my computer user?如何将 mysql 命令设置为使用 root 用户而不是我的计算机用户?

Create file ~/.my.cnf and add following lines.创建文件 ~/.my.cnf 并添加以下行。

[client]
user=<your_user>
password=<your_password>

More info can see https://easyengine.io/tutorials/mysql/mycnf-preference/ .更多信息可以查看https://easyengine.io/tutorials/mysql/mycnf-preference/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM