从本地的windows发布到云主机,本地是可以工作的(wnmp),在云主机上测试执行php artisan migrate
,报错如下:
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
env文件里填写了用户名和密码的:
DB_USERNAME=root
DB_PASSWORD=123456
在终端里面测试可以连接:
# mysql -uroot -p123456;
MariaDB [(none)]>
怎么一回事?
更新:
数据库更换用户也不行,好像没有用到env文件的内容:
给mariadb创建一个test用户:
MariaDB [(none)]> grant all privileges on *.* to test@localhost identified by 'mysql';
MariaDB [(none)]> flush privileges;
把env文件改为test用户:
APP_ENV=production
APP_KEY=base64:fzg/fitaaaaaaaaaaaaaaaaaaaaaaaa0=
APP_DEBUG=false
APP_LOG_LEVEL=debug
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=test
DB_PASSWORD=mysql
出现和以前同样的错误,错误信息中仍然是root用户,怎么的呢?好像没有用到env文件,在config/database.php中填入用户名密码也不行,好像是读取不到这些信息。
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)
看mysql.users表的root账号是否有密码为空的
select *from mysql.user where user='root';
`