How Can I Execute an SQL File Correctly Within MySQL in Windows 10 Command Prompt?(如何在Windows 10命令提示符下在MySQL中正确执行SQL文件?)
问题描述
我已经尝试了将近30分钟,试图弄清楚如何从Win 10命令提示符执行SQL文件,但我仍然找不到方法。
我在mysql>目录中,我找不到文件路径之前的‘source’是什么。在MySQL文件的路径之前需要键入的"源"是什么?
以下是我尝试执行的bookorama.sql文件的文件路径: C:wamp64inmysqlmysql5.7.23inbookorama.sql位于最后一个"bin"文件夹的文件路径中。
这是我到目前为止一直在努力寻找的,但我一直在尝试针对这些帖子中的答案提出很多建议,但我仍然无法找到正确的答案。
Can't run MySQL from command prompt
Executing a SQL file
How to import an SQL file using the command line in MySQL?
execute .sql file using command line
https://tecadmin.net/run-sql-text-file-on-mysql-command-prompt/
以下是尝试执行SQL文件的命令提示符的副本:
C:wamp64inmysqlmysql5.7.23in>mysql -hlocalhost -uroot -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 22
Server version: 5.7.23 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.
Type 'help;' or 'h' for help. Type 'c' to clear the current input
mysql> use books
Database changed
mysql> -u bookorama -d books < bookoroma.sql
-> ;
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 '-u bookorama -d books < bookoroma.sql' at line 1
mysql> mysql
-> ;
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' at line 1
mysql> mysql -h localhost - u bookorama -p < bookorama.sql
-> ;
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 -h localhost - u bookorama -p < bookorama.sql' at line 1
mysql> cd..
-> ;
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 'cd..' at line 1
mysql> mysql -h localhost -u bookorama -D books -p < bookorama.sql
->
-> CREATE TABLE Customers
-> ;
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 -h localhost -u bookorama -D books -p < bookorama.sql
CREATE TABLE Custom' at line 1
mysql> -u bookorama -D books -P < bookorama.sql
-> ;
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 '-u bookorama -D books -P < bookorama.sql' at line 1mysql> -u root
-> -p Oscar545* -D bookorama < bookorama.sql
-> ;
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 '-u root
-p Oscar545* -D bookorama < bookorama.sql' at line 1
mysql> mysql -h localhose u-root -D bookorama <
C:wamp64inmysqlmysql5.7.23in.bookorama.sql
Show warnings disabled.
ERROR:
Unknown command ''.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command ''.
-> ;
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 -h localhose u-root -D bookorama <
C:amp64inmysqlmysql5.7.23in.booko' at line 1
mysql> mysql -h localhose u-root -D bookorama < bookorama.sql
-> ;
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 -h localhose u-root -D bookorama < bookorama.sql' at line 1
mysql> mysql -u root -p books < bookorama.sql
-> ;
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 -p books < bookorama.sql' at line 1
mysql> use books
Database changed
mysql> mysql -u root -p books < bookorama.sql
-> ;
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 -p books < bookorama.sql' at line 1
mysql> C:wamp64inmysqlmysql5.7.23in bookorama.sql
Show warnings disabled.ERROR:
Unknown command ''.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command ''.
-> ;
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 'C:amp64inmysqlmysql5.7.23in bookorama.sql' at line 1
mysql> source C:wamp64inmysqlmysql5.7.23in;
Show warnings disabled.
ERROR:
Unknown command ''.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command ''.
ERROR:
Failed to open file 'C:amp64inmysqlmysql5.7.23in', error: 2
mysql> C:wamp64inmysqlmysql5.7.23inookorama.sql
Show warnings disabled.
ERROR:
Unknown command ''.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command 'm'.
ERROR:
Unknown command ''.
ERROR:
Unknown command ''.
-> ;
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 'C:amp64inmysqlmysql5.7.23inookorama.sql' at line 1
mysql> mysql -h localhost -u root
-> ;
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 -h localhost -u root' at line 1
mysql> -h localhost -root -pOscar545* books < bookorama.sql
-> ;
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 '-h localhost -root -pOscar545* books < bookorama.sql' at line 1
mysql> mysql -u root -p books < bookorama.sql
-> ;
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 -p books < bookorama.sql' at line 1
mysql>
推荐答案
在mysql>
提示符下使用:
use books;
source bookorama.sql;
在命令提示符下使用:
mysql.exe -h localhost -root -pOscar545* books < bookorama.sql
这篇关于如何在Windows 10命令提示符下在MySQL中正确执行SQL文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在Windows 10命令提示符下在MySQL中正确执行SQL文件?
基础教程推荐
- Sql Server 字符串到日期的转换 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01