数据库用户的Laravel访问被拒绝
我创建了一个MySQL用户,授予了权限,并创建了一个数据库:数据库用户的Laravel访问被拒绝,laravel,Laravel,我创建了一个MySQL用户,授予了权限,并创建了一个数据库: mysql> CREATE USER 'karaoke'@'localhost' IDENTIFIED BY '86v#...'; Query OK, 0 rows affected (0.05 sec) mysql> GRANT ALL PRIVILEGES ON *.* TO 'karaoke'@'localhost'; Query OK, 0 rows affected (0.04 sec) mysql> FL
mysql> CREATE USER 'karaoke'@'localhost' IDENTIFIED BY '86v#...';
Query OK, 0 rows affected (0.05 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'karaoke'@'localhost';
Query OK, 0 rows affected (0.04 sec)
mysql> FLUSH PRIVILEGES;
$ mysql -ukaraoke -h localhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
...
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| karaoke |
+--------------------+
2 rows in set (0.01 sec)
mysql> use karaoke;
Database changed
mysql> show tables;
Empty set (0.01 sec)
我已使用db凭据更新了.env文件:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=karaoke
DB_USERNAME=karaoke
DB_PASSWORD=86v#...
但是,当我尝试运行迁移时,出现以下错误:
$ php artisan migrate
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'karaoke'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = karaoke and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678
674▕ // If an exception occurs when attempting to run a query, we'll format the error
675▕ // message to include the bindings with SQL, which will make this exception a
676▕ // lot more helpful to the developer instead of just the database's errors.
677▕ catch (Exception $e) {
➜ 678▕ throw new QueryException(
679▕ $query, $this->prepareBindings($bindings), $e
680▕ );
681▕ }
682▕
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
出什么事了?我可以从命令行以卡拉OK用户的身份登录,但Laravel遇到了问题
==
您是否尝试过
php artisan optimize:clear
?现在尝试过,但没有修复。您的密码包含#
字符,可能会被误解为.env
中的注释。尝试使用引号:DB_PASSWORD=“86v”…“
Ah,很好地发现了。是的,这就是问题所在。您是否尝试过php artisan optimize:clear
?现在尝试过,但没有解决。您的密码包含#
字符,可能会被误解为.env
中的注释。尝试使用引号:DB_PASSWORD=“86v”…“
Ah,很好地发现了。是的,这就是问题所在。
$ php artisan --version
Laravel Framework 8.17.0
$ mysql --version
mysql Ver 8.0.22-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))
$ php -v
PHP 7.4.3 (cli) (built: Oct 6 2020 15:47:56) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies