把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);
?>
THX以下。但如何獲得「數據庫內」?或者如何用$ mysql -u root -p -e'<數據庫命令行>'寫入多行?我不擅長unix命令,對不起:( – user2718671
查看完整示例 –
好的,謝謝!我沒有導入sql文件,但瀏覽器中仍然出現以下錯誤:「建立數據庫連接時出錯」。鍵入最後兩行,因爲我的根目錄應該已經擁有所有的權限,並且沒有密碼,所以我不知道該寫什麼,而不是「由......標識」。WP-config似乎也是正確的。我會檢查它可能是什麼。但非常感謝你解決了導入問題! – user2718671