MySQL 使用Putty将sql文件导入数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19050717/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Putty to import a sql file into the database
提问by the_summer_bee
I want to import an .sql file into a database on the server through command line.
我想通过命令行将 .sql 文件导入服务器上的数据库。
I understand that I should use the follow line:
我知道我应该使用以下行:
mysql -u username -p database_name < textfilewithsqlstatments.sql
mysql -u 用户名 -p 数据库名称 < textfilewithsqlstatments.sql
the sql file is currently in my local folder, shall I upload it to the server first? how should I specify the directory for this file?
sql 文件目前在我的本地文件夹中,我应该先将它上传到服务器吗?我应该如何指定这个文件的目录?
Thanks
谢谢
回答by Othrayte
The line
线
mysql -u username -p database_name < textfilewithsqlstatments.sql
Assumes that the file is in the same directory that you are running the command from.
假设该文件与您从中运行命令的目录相同。
You should upload the file to the server and specify the path as
您应该将文件上传到服务器并将路径指定为
mysql -u username -p database_name < /path/to/file/on/server/textfilewithsqlstatments.sql
回答by Celso Marigo Jr
U can use the putty utility PLINK.EXE
你可以使用putty工具PLINK.EXE
Preferred configure the session with a key, to not need to put the password in all the connections, so simple use:
首选使用密钥配置会话,无需在所有连接中都输入密码,因此使用简单:
plink mysql -u username -p database_name < textfilewithsqlstatments.sql
plink mysql -u 用户名 -p database_name < textfilewithsqlstatments.sql
Considering that the file
考虑到文件
textfilewithsqlstatments.sql
带有sqlstatments.sql的文本文件
is in your /home/user.
在您的 /home/user 中。
More information about PLINK: http://the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html
有关 PLINK 的更多信息:http: //the.earth.li/~sgtatham/putty/0.58/htmldoc/Chapter7.html
It works fine!
它工作正常!
回答by OpenWebWar
STEP1: enter your Hostname or I.P address and use port 22 @ putty. If you are entering your hostname, leave out the http://wwwand simply enter yourdomain.com.
STEP1:输入您的主机名或 IP 地址并使用端口 22 @ putty。如果您要输入主机名,请省略http://www,只需输入 yourdomain.com。
STEP2: You can then enter your cPanel username and click enter
STEP2:然后您可以输入您的 cPanel 用户名并单击 Enter
STEP3: Then enter your cPanel password and click enter.
STEP3:然后输入您的 cPanel 密码并单击 Enter。
STEP4: finally step is to enter the command line below
STEP4:最后一步是进入下面的命令行
mysql -u database_user_name -p database_db_name < /home/alphabettechnologies/public_html/alphabet_webz.sql
and click enter. (make sure to replace the path with the correct address to your database. The filename for your SQL database file, You'll also need to replace with your new database username and password.
然后点击进入。(确保将路径替换为正确的数据库地址。SQL 数据库文件的文件名,您还需要替换为新的数据库用户名和密码。
mysql -u database_user_name -p database_db_name < /home/alphabet/public_html/db-backup.sql
STEP5: enter the db user password
STEP5:输入db用户密码
Thats All, will be db imported
就是这样,将导入数据库