http://siwei.me/blog/posts/mysql--9

使用这个方法:(参考: https://stackoverflow.com/a/52674808/445908

sudo mysql -u root

可以正常进入数据库,但是使用rake db:create/migrate不能正常进行操作提示user@localhost不正确。

可以创建user然后继续操作:

首先创建了数据库:first_database, first_database_test

Then create a normal user, set a password, then use that user to work.

create user &#39;user&#39;@&#39;localhost&#39; identified by &#39;user1234&#39;;<br />
grant all on your_database.* to &#39;user&#39;@&#39;localhost&#39;;

(例如: grant all on first_database.* to &#39;user&#39;@&#39;localhost&#39;;)

(grant all on first_database._test* to &#39;user&#39;@&#39;localhost&#39;;)<br />
select host, user from mysql.user;

Then try to access:

mysql -u user -puser1234

然后在config/database.yml修改user和password就可以migrate了

user: user

password: user1234