컨테이너 생성할 때 Mysql을 체크하면 설치되어 있으나 설치되어 있지 않으면
sudo apt-get install mysql-server |
설치되어 있으면 이미 설치되어 있다는 message가 나옴
mysql 서비스 시작
sudo service mysql start |
mysql 접속 : 최초 root 계정의 password는 없으므로 비번없이 접속
mysql -uroot |
접속시 다음에러가 나면
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' mysql -uroot 로 접속해본다 |
mysql start가 되어있지 않으면 php laravel 에서 db migrate 했을 때 오류가 난다.
php artisan migrate 1 PDOException::("SQLSTATE[HY000] [2002] Connection refused") /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70 |
mysql db에 권한이 없으면
php artisan migrate Illuminate\Database\QueryException : SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations and table_type = ... |
그래서
mysql 접속한 뒤 DB 생성, 권한주기
create database blog;
GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost';
FLUSH PRIVILEGES;
그런데... 그래도 접속이 안된다.
이유는 DB 접속파일인 env에 있다.
.env 파일에 db접속정보가 있다.
여기에
DB_HOST=127.0.0.1 로 되어있으면
위에서 grant 'root'@'127.0.0.1' 를 추가
또는
DB_HOST=localhost 로 바꿔주면 정상적으로 접속된다.
table 없다는 오류가 나오면
php artisan migrate 으로 table 생성하면 됨