craftcms / nitro

Speedy local dev environment for @craftcms.
https://getnitro.sh
MIT License
178 stars 24 forks source link

nitro add does not create database #351

Closed toyflish closed 2 years ago

toyflish commented 3 years ago

Description

I brew installed nitro, ran nitro init for setting up nitro, ran nitro add from inside craft project directory, typed in database name, database creation was confirmed 💪. Could not import database exit with error, logged into mysql container with mysql-cli, only informaition_schema and nitro db present. But my "oneworld" db was missing.

    $ nitro init                                                                                                                                                                                      
    Setting up Nitro…                                                                                                                                                                                                     
    Would you like to use MySQL [Y/n]? Y                                                                                                                                                                                  
    Select the version of MySQL                                                                                                                                                                                           
      1. 8.0                                                                                                                                                                                                              
      2. 5.7                                                                                                                                                                                                              
      3. 5.6                                                                                                                                                                                                              
    Enter your selection: 1                                                                                                                                                                                               
    Would you like to use PostgreSQL [Y/n]? n                                                                                                                                                                             
    Would you like to use Redis [Y/n]? Y                                                                                                                                                                                  
      … adding redis service ✓                                                                                                                                                                                            
    Checking Nitro…                                                                                                                                                                                                       
      … creating network ✓                                                                                                                                                                                                
      … pulling image ✓                                                                                                                                                                                                   
      … creating volume ✓                                                                                                                                                                                                 
      … creating proxy ✓                                                                                                                                                                                                  
    Checking network…                                                                                                                                                                                                     
      ✓ network ready                                                                                                                                                                                                     
    Checking proxy…                                                                                                                                                                                                       
      ✓ proxy ready                                                                                                                                                                                                       
    Checking databases…                                                                                                                                                                                                   
      … checking mysql-8.0-3306.database.nitro   … downloading mysql:8.0 ✓                                                                                                                                                
    Checking services…                                                                                                                                                                                                    
      … checking dynamodb service ✓                                                                                                                                                                                       
      … checking mailhog service ✓                                                                                                                                                                                        
      … checking redis service ✓                                                                                                                                                                                          
    Checking proxy…                                                                                                                                                                                                       
      … updating proxy ✓                                                                                                                                                                                                  
    Updating hosts file (you might be prompted for your password)                                                                                                                                                         
    Password:                                                                                                                                                                                                             
      … getting Nitro’s root site certificate ✓                                                                                                                                                                           
    Installing certificate (you might be prompted for your password)                                                                                                                                                      
    Nitro certificates are now trusted 🔒                                                                                                                                                                                 ]
    Nitro is ready! 🚀 

adding the site with database named "oneworld"

    $ nitro add                                                                                                                                                                                       
    Adding site…                                                                                                                                                                                                          
    Enter the hostname [api.nitro]: oneworld.nitro                                                                                                                                                                        
      ✓ setting hostname to oneworld.nitro                                                                                                                                                                                
      ✓ adding site ~/dev/blackroll/oneworld/api                                                                                                                                                                          
    Enter the webroot for the site [web]: web                                                                                                                                                                             
      ✓ using webroot web                                                                                                                                                                                                 
    Choose a PHP version:                                                                                                                                                                                                 
      1. 8.0                                                                                                                                                                                                              
      2. 7.4                                                                                                                                                                                                              
      3. 7.3                                                                                                                                                                                                              
      4. 7.2                                                                                                                                                                                                              
      5. 7.1                                                                                                                                                                                                              
      6. 7.0                                                                                                                                                                                                              
    Enter your selection: 2                                                                                                                                                                                               
      ✓ setting PHP version 7.4                                                                                                                                                                                           
    Add a database for the site [Y/n] Y                                                                                                                                                                                   
    Enter the new database name: oneworld                                                                                                                                                                                 
      … creating database oneworld ✓                                                                                                                                                                                      
    Database added 💪                                                                                                                                                                                                     ]
    Should we update the env file? [y/N] y                                                                                                                                                                               ]
    .env updated!                                                                                                                                                                                                         
    New site added! 🎉                                                                                                                                                                                                    ]
    Apply changes now [Y/n]? Y                                                                                                                                                                                           ]
    Checking network…                                    
      ✓ network ready                                    
    Checking proxy…                                      
      ✓ proxy ready                                      
    Checking databases…                                  
      … checking mysql-8.0-3306.database.nitro ✓
    Checking services…                                   
      … checking dynamodb service ✓
      … checking mailhog service ✓
      … checking redis service ✓
    Checking sites…                                      
      … checking oneworld.nitro ✓
    Checking proxy…                                      
      … updating proxy ✓                                 
    Updating hosts file (you might be prompted for your password)

trying to import

    nitro db import cur.sql
      … detecting backup type ✓
    Detected mysql backup
    Enter the database name: oneworld
    Preparing import…
      … importing database "oneworld" into "mysql-8.0-3306.database.nitro" ✗
    Error: rpc error: code = Internal desc = error importing the database Exit Status: 1

connecting to mysql container listing the databases

    mysql -u nitro -p -h mysql-8.0-3306.database.nitro
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 8.0.25 MySQL Community Server - GPL
    ...
    mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | nitro              |
    +--------------------+
    2 rows in set (0,01 sec)

trying to create database

    nitro db add
    Enter the new database name: oneworld
      … creating database oneworld Error: rpc error: code = Internal desc = error creating database: Exit Status: 1
    Commands: --user=nitro --host=mysql-8.0-3306.database.nitro -pnitro -e CREATE DATABASE IF NOT EXISTS oneworld;

Steps to reproduce

  1. init nitro with mysql-8
  2. nitro add from project directory
  3. try to connect to database that is not present

Additional info

I nitro destroyed and tried with mysql-5.7 , same problem , no database created

shornuk commented 3 years ago

I've just installed Nitro and I'm getting this too.

jasonmccallister commented 3 years ago

Can you run nitro ls and verify the database container is running?

@shornuk are you also using mysql v8?

ben-callaway commented 3 years ago

I can vouch for @shornuk, yes he is. Fresh install of Docker, Nitro and MySQL 8, PHP 7.4. Valet still present (not sure if that makes any difference). Docker all green and running in the dashboard. Port was originally blocked by Valet on install, but valet service stopped and nitro init completed.

toyflish commented 3 years ago

reinstalled with mysql 5.7 , same behaviour as described above. looks like all run

nitro ls
Hostname                               Type              Status           
mysql-5.7-3306.database.nitro          database          running          
nitro-proxy                            proxy             running          
oneworld.nitro                         site              running 

when I try adding a database it fails, if I try to send the same command with my mysql-cli it fails as well because the user nitro in the mysql-server not has the right privileges

nitro db add                                                                                                
Enter the new database name: oneworld
  … creating database oneworld Error: rpc error: code = Internal desc = error creating database: Exit Status: 1
Commands: --user=nitro --host=mysql-5.7-3306.database.nitro -pnitro -e CREATE DATABASE IF NOT EXISTS oneworld;

mysql --user=nitro --host=mysql-5.7-3306.database.nitro -pnitro -e "CREATE DATABASE IF NOT EXISTS oneworld;"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1044 (42000) at line 1: Access denied for user 'nitro'@'%' to database 'oneworld'

if I log in as root to the mysql container and grant privileges to nitro it works mysql> GRANT ALL PRIVILEGES ON . TO 'nitro'@'%';

nitro db add                                      
Enter the new database name: oneworld
  … creating database oneworld ✓
Database "oneworld" added to "mysql-5.7-3306.database.nitro" successfully 💪
toyflish commented 3 years ago

Since I‘m not into go I just can give hints. So I think this command is not executed by setting up the database container:

{"mysql", "-uroot", "-pnitro", fmt.Sprintf(`-e GRANT ALL PRIVILEGES ON *.* TO '%s'@'%s' WITH GRANT OPTION;`, "nitro", "%")},
jasonmccallister commented 2 years ago

Hi, we are closing this issue as we have decided to retire Nitro, so no additional work will occur on this project. You can read the official blog post here https://craftcms.com/blog/retiring-craft-nitro. We appreciate everyones feedback and involvement and we look forward to refocusing our efforts on Cloud!

If you're looking for a new local development environment, we recommend DDEV and have a knowledge base article to help you with the transition: https://craftcms.com/knowledge-base/migrating-from-craft-nitro-to-ddev.