Importante

Você está vendo a versão anterior da nova experiência da Alura que estamos preparando para você. Em breve, ela ganha uma identidade visual novinha totalmente pensada em potencializar seus estudos!

14
respostas

Erro ao executar dump.sql

Ao executar o comando "mysql -u root estoque_laravel < dump.sql;" no windows 10, retorna o erro abaixo.

Estou utilizando o Mysql 5.7

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysql -u root estoque_laravel < dump.sql' at line 1

14 respostas

Boa tarde,

Este comando deve ser executado fora do MySQL, ou seja sem conectar ao MySQL. Percebi também que você não passou o caminho do dump.sql, o exemplo abaixo é se o arquivo estiver no c:.

Acesse o terminal,ainda no terminal acesse a pasta bin do MySQL, lá você executa o comando.

mysql -h localhost -u root estoque_laravel < c:\dump.sql

Qualquer coisa comunique.

Atenciosamente.

Olá Danilo, tudo bem ?

Aparentemente não há nada de errado com o comando executado mysql -u root estoque_laravel < dump.sql, como é possível ver pelo próprio manual de referência aqui.

Verifique se existe o arquivo dump.sql exatamente no diretório onde você logou no mysql, ou se não existe nenhum erro de sintaxe no conteúdo sql do arquivo.

Oi pessoal,

Bem observado pelo William, o comando deve ser executado direto no cmd. O comando vai se encarregar de logar no mysql já usando a base de dados informada e executar o sql contido no dump.

Abraços

Executei o comando na basta bin, está me retornando as opções abaixo, o que pode ser?

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -u root -p toor estoque_laravel < C:\Users\danil\estoque\dump.sql
mysql  Ver 14.14 Distrib 5.7.18, for Win64 (x86_64)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
                      (Defaults to on; use --skip-auto-rehash to disable.)
  -A, --no-auto-rehash
                      No automatic rehashing. One has to use 'rehash' to get
                      table and field completion. This gives a quicker start of
                      mysql and disables rehashing on reconnect.
  --auto-vertical-output

Bom dia o que está faltando é o caminho do servidor que provavelmente é localhost.

Tenco copiar e colar este comando.

mysql -hlocalhost -uroot -ptoor estoque_laravel < C:\Users\danil\estoque\dump.sql

Atenciosamente.

William, retorna a mesma coisa:

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -h localhost -u root -p toor estoque_laravel < C:\Users\danil\estoque\dump.sql
mysql  Ver 14.14 Distrib 5.7.18, for Win64 (x86_64)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
                      (Defaults to on; use --skip-auto-rehash to disable.)
  -A, --no-auto-rehash
                      No automatic rehashing. One has to use 'rehash' to get
                      table and field completion. This gives a quicker start of
                      mysql and disables rehashing on reconnect.
  --auto-vertical-output
                      Automatically switch to vertical output mode if the
                      result is wider than the terminal width.
  -B, --batch         Don't use history file. Disable interactive behavior.
                      (Enables --silent.)
  --bind-address=name IP address to bind to.
  --character-sets-dir=name
                      Directory for character set files.
  --column-type-info  Display column type information.
  -c, --comments      Preserve comments. Send comments to the server. The
                      default is --skip-comments (discard comments), enable
                      with --comments.
  -C, --compress      Use compression in server/client protocol.
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  --debug-check       This is a non-debug version. Catch this and exit.
  -T, --debug-info    This is a non-debug version. Catch this and exit.
  -D, --database=name Database to use.
  --default-character-set=name
                      Set the default character set.
  --delimiter=name    Delimiter to be used.
  --enable-cleartext-plugin
                      Enable/disable the clear text authentication plugin.
  -e, --execute=name  Execute command and quit. (Disables --force and history
                      file.)
  -E, --vertical      Print the output of a query (rows) vertically.
  -f, --force         Continue even if we get an SQL error.
  --histignore=name   A colon-separated list of patterns to keep statements
                      from getting logged into syslog and mysql history.
  -G, --named-commands
                      Enable named commands. Named commands mean this program's
                      internal commands; see mysql> help . When enabled, the
                      named commands can be used from any line of the query,
                      otherwise only from the first line, before an enter.
                      Disable with --disable-named-commands. This option is
                      disabled by default.
  -i, --ignore-spaces Ignore space after function names.
  --init-command=name SQL Command to execute when connecting to MySQL server.
                      Will automatically be re-executed when reconnecting.
  --local-infile      Enable/disable LOAD DATA LOCAL INFILE.
  -b, --no-beep       Turn off beep on error.
  -h, --host=name     Connect to host.
  -H, --html          Produce HTML output.
  -X, --xml           Produce XML output.

Oi.

Retire o -p toor.

Provavelmente ele te pedirá a senha.

Sem o -p toor retona:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Da forma abaixo, pede a senha, mas não retorna nada, conferi no Workbench, e o banco está vazio.

C:\Program Files\MySQL\MySQL Server 5.7\bin>mysql -h localhost -u root -p estoque_laravel < C:\Users\danil\estoque\dump.sql Enter password: **

Tentei também o comando abaixo, sem sucesso.

mysqldump -h localhost -u root -p toor estoque_laravel  > C:\Users\danil\estoque\dump.sql

Tenta desta forma

mysql -h localhost -u root estoque_laravel < C:\Users\danil\estoque\dump.sql

Atenciosamente.

Já foi feito Wiliam, sem sucesso.

Você executou a solução do Rafael?

Abra o terminal e log no mysql. mysql -u root estoque_laravel < dump.sql

o arquivo dump.sql deve estar no diretório onde logou no mysql.

Boa tarde,

Como está este caso, funcionou?

Atenciosamente.

Eu conseguir entrando na pasta onde está instalado o mysql, e rodando o comando passando o usuário e a senha, conforme o código:

mysql --user=root --password=suasenha estoque_laravel < dump.sql;