把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