迁移时用户 root@localhost 的 Laravel 5.4 访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45471494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5.4 access denied for user root@localhost on migrate
提问by night-gold
I have a stange one with Laravel. I have a bad habit of creating projects on virtual box with laravel project for testing. (debian last stable currently 9.1, nginx, php7.1, MariaDB).
我有一个与 Laravel 的 stange 。我有一个坏习惯,就是用 laravel 项目在 virtual box 上创建项目进行测试。(debian last stable 目前是 9.1、nginx、php7.1、MariaDB)。
Before you tell me to go read another post somewhere, please read everything, I mays have missed the post but I tried quite à lot I tried most of the solution that may have worked for others, but they don't in my case (thanks).
在你告诉我去某个地方阅读另一篇文章之前,请阅读所有内容,我可能错过了这篇文章,但我尝试了很多我尝试了大多数可能对其他人有用的解决方案,但在我的情况下却没有(谢谢)。
I tried different thing and always end breaking everything and doing hover (that's normal...).
我尝试了不同的事情,但总是以打破一切并悬停(这是正常的......)而告终。
I have already tried a number of installation and never had any problem with
我已经尝试过多次安装,但从未遇到任何问题
php artisan migrate
That is until today. I prepared my migrations files and tried the migrate and I got this message :
直到今天。我准备了我的迁移文件并尝试了迁移,我收到了这条消息:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: sele
ct * from information_schema.tables where table_schema = test and table_nam
e = migrations)
And this one:
和这个:
[PDOException]
SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'
I did everything as always, I checked my credentials that are in the .env file and tested them. No problem there.
我像往常一样做了所有事情,我检查了 .env 文件中的凭据并对其进行了测试。没有问题。
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=Password2
The database does exist, can't be wrong with this name :
数据库确实存在,这个名字不能错:
SHOW DATABASEs;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
When looking for code error 1698 in MariaDB, they tell me that this code appear when it's trying to connect without password.
在 MariaDB 中查找代码错误 1698 时,他们告诉我当它尝试不使用密码进行连接时会出现此代码。
So my question is why is it doing this? I tried with a new project, just installed and doing the artisan command line, it changes nothing.
所以我的问题是为什么要这样做?我尝试了一个新项目,刚刚安装并执行了 artisan 命令行,它没有任何改变。
I would like to avoid doing a fresh os install.
我想避免进行全新的操作系统安装。
Thanks in advance for your help and sorry for my poor english.
预先感谢您的帮助,并为我糟糕的英语感到抱歉。
采纳答案by night-gold
So I solved my problem... It seems that I need to create a new database account to write in the database and can't use root...
于是我的问题就解决了。。。看来是要新建一个数据库账号在数据库里写,不能用root。。。
I tested it with another virtual machine and if I create a new account it works as it should...
我用另一台虚拟机测试了它,如果我创建一个新帐户,它可以正常工作......
Seems that the issue is with MariaDB... I can connect with or without password to root even after mysql_secure_installation command... I will work on this...
似乎问题出在 MariaDB 上……即使在 mysql_secure_installation 命令之后,我也可以使用或不使用密码连接到 root ……我会处理这个问题……
Thanks a lot.
非常感谢。
回答by mate.gwozdz
For me 'root' user could not connect. Here's how to solve it:
对我来说,'root' 用户无法连接。以下是解决方法:
1.login to mysql console $ mysql -u root -p
1.登录mysql控制台 $ mysql -u root -p
2.create new user
2.创建新用户
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
3.grant privilages to your laravel database
3.grant privilages 给你的 Laravel 数据库
GRANT ALL PRIVILEGES ON database.* TO 'user'@'localhost';
or grant privilages to all tables
或授予所有表的特权
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost';
4.flush privilages for changes to take place
4.flush 特权以进行更改
FLUSH PRIVILEGES;
5.exit mysql console
5.退出mysql控制台
exit
6.edit .env
file, update your MASTER_DB_USER
and MASTER_DB_PASS
to match your new user
6.编辑.env
文件,更新你的MASTER_DB_USER
和MASTER_DB_PASS
匹配你的新用户
7.run migration to test things out
7. 运行迁移来测试
php artisan migrate
回答by AddWeb Solution Pvt Ltd
Please once you can clear the cache:
请一旦您可以清除缓存:
php artisan config:cache
php artisan config:clear
php artisan cache:clear
Hope this work for you!
希望这对你有用!
回答by lstonon
You can try to run the following artisan command:
您可以尝试运行以下工匠命令:
php artisan config:cache
回答by giolliano sulit
Have you updated the password from when you first tried to run php artisan ?
您是否从第一次尝试运行 php artisan 时更新了密码?
Could be as easy as clearing the config cache
可能就像清除配置缓存一样简单
php artisan config:clear