2014-04-03 43 views
1

我创建了一个Wordpress网站离线,完成后我想将其移动到服务器。用所有文件移动wordpress目录很容易。我还将我的wp数据库与localhost/phpmyadmin导出到一个sql文件。有一些服务器支持phpmyadmin,这将使服务器上的数据库导入变得容易。但如何用unix命令来做到这一点?如何将wordpress安装从xampp localhost移至linux服务器?

根据this site我必须先在服务器上创建一个数据库,然后导入sql文件。

$ mysql -u root -p -e 'create database salesdb1;' 
$ mysql -u salesdb1 -p sales < sales.sql 

我发现“-p”代表密码,我不需要它,因为没有密码。在我做错任何事情之前,我有一个问题 - 我的sql文件放在服务器上以及如何导入它?

$ mysql -u <my_unix_user> ... 

回答

1

把SQL油底壳文件在您/tmp目录或在用户上有充分的权利任何其他文件夹。
从unix comd行:
- 改变cmd并输入您自己的值。

unix cmd line:> mysql -u root -p <passwrd> -e 'create database db_name; use db_name; source /tmp/dump_file.sql; grant all on db_name.* to [email protected]'% - or an ip address' identified by 'password'; flush privileges; 

从数据库中:

unix cmd line:> mysql -u root -p <passwrd> 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 58208 
Server version: 5.6.10 MySQL Community Server (GPL) 

Copyright (c) 2000, 2011, 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 statement. 

create database db_name; 
use db_name; 
source /tmp/dump_file.sql --full path to the dump file 
grant all on db_name.* to [email protected]'% - or an ip address' identified by 'password'; 
flush privileges; 
  • 确保数据库的用户有权限create database
  • [email protected]'% - or an ip address'这里需要说明的应用程序服务器的IP地址,如果是在同一台计算机数据库使用localhost上,如果你想让它从任何地方连接使用通配符'%”

要使用无密码添加一个用户按照此处:
(我不建议这一点 - 但要回答你的问题)

unix cmd line:>mysql -uroot -p passwd -e 'grant all on *.* to [email protected]'%' identified by ''; flush privileges; 

下连接到数据库:

[[email protected] ~]# mysql -utest123 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 60722 
Server version: 5.6.10 MySQL Community Server (GPL) 

Copyright (c) 2000, 2011, 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 statement. 

mysql> 

要测试你的数据库连接:
- 创建和调用PHP与此内容!

<?php 
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
echo 'Connected successfully'; 
mysql_close($link); 
?> 
+0

THX以下。但如何获得“数据库内”?或者如何用$ mysql -u root -p -e'<数据库命令行>'写入多行?我不擅长unix命令,对不起:( – user2718671

+1

查看完整示例 –

+0

好的,谢谢!我没有导入sql文件,但浏览器中仍然出现以下错误:“建立数据库连接时出错”。键入最后两行,因为我的根目录应该已经拥有所有的权限,并且没有密码,所以我不知道该写什么,而不是“由......标识”。WP-config似乎也是正确的。我会检查它可能是什么。但非常感谢你解决了导入问题! – user2718671

-1

请看看来自WordPress的网站

http://codex.wordpress.org/Moving_WordPress 
相关问题