2014-04-03 122 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 
相關問題