MySQL 安装magento,出现数据库连接错误。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17674195/
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
Installing magento, get database connection error.
提问by user1937185
I am trying to install magento onto my webhost, during install i get "database connection error" i have input all the values correctly (have contacted my webhost to be sure as I am stumped at this point) they said to refer to magento forums for extra support. I cannot find a fix. Any ideas / help would be MUCH appreciated.
我正在尝试将 magento 安装到我的网络主机上,在安装过程中我得到“数据库连接错误”我已经正确输入了所有值(已经联系了我的网络主机以确保我在这一点上被难住了)他们说要参考 magento 论坛额外的支持。我找不到解决办法。任何想法/帮助将不胜感激。
回答by gbe
Try this script which tests your connection and reports the actual MySQL error. It might be useful to determine whether the credentials you were given will work, or which part of the process is failing. Since you are using it on a remote webhost I recommend you hard-code the database username and password to avoid passing them in clear over the open Internet.
试试这个脚本,它测试你的连接并报告实际的 MySQL 错误。确定您获得的凭据是否有效,或者流程的哪个部分失败可能会很有用。由于您在远程虚拟主机上使用它,我建议您对数据库用户名和密码进行硬编码,以避免在开放的 Internet 上以明文方式传递它们。
(Note: Not my own work - script comes from webune.com)
(注意:不是我自己的作品 - 脚本来自 webune.com)
<?php
###################################### C O P Y R I G H T S ####################################
# THIS SCRIPT IS DISTRIBUTED BY WEBUNE.COM UNDER LICENSE UNDER THE GPL RULES
# PLEASE DO NOT REMOVE THIS MESSAGE IN SUPPORT OF OUR HARD WORK TO CONTINUE TO PROVIDE FREE SUPPORT
###############################################################################################
# OK, HERE WE GO
# Use this varialble if you are using an installation script
$step = $_GET['step'];
if (!$step) {
$page_title = 'Form';
}
else{
$page_title = 'Test MySQL step '.$step;
}
############## BEGIN FUNCTIONS ##############################
# FUNCTION TO TEST USERNAME AND PASSWORD IN MYSQL HOST
function db_connect($server, $username, $password, $link = 'db_link') {
global $$link, $db_error;
$db_error = false;
if (!$server) {
$db_error = 'No Server selected.';
return false;
}
$$link = @mysql_connect($server, $username, $password) or $db_error = mysql_error();
return $$link;
}
# FUNCTION TO SELECT DATABASE ACCESS
function db_select_db($database) {
echo mysql_error();
return mysql_select_db($database);
}
# FUNCTION TO TEST DATABASE ACCESS
function db_test_create_db_permission($database) {
global $db_error;
$db_created = false;
$db_error = false;
if (!$database) {
$db_error = 'No Database selected.';
return false;
}
if ($db_error) {
return false;
} else {
if (!@db_select_db($database)) {
$db_error = mysql_error();
return false;
}else {
return true;
}
return true;
}
}
function step1 ($error) {
echo '<h1 style="color:#FF0000">'.$error.'</h1><hr>';
?>
<form name="form1" method="post" action="<?php $_SERVER['PHP_SELF']; ?>?step=2">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td><div align="right">mysql hostname:</div></td>
<td><input name="server" type="text" value="<?php echo $_REQUEST['server']; ?>">
(usually "localhost" or enter IP Address of MySQL Server)</td>
</tr>
<tr>
<td><div align="right">mysql username:</div></td>
<td><input type="text" name="username" value="<?php echo $_REQUEST['username']; ?>"></td>
</tr>
<tr>
<td><div align="right">mysql username password:</div></td>
<td><input type="text" name="password" value="<?php echo $_REQUEST['password']; ?>"></td>
</tr>
<tr>
<td><div align="right">mysql database name:</div></td>
<td><input type="text" name="database" value="<?php echo $_REQUEST['database']; ?>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Webune MYSQL TEST - <?php echo $page_title; ?></title>
</head>
<body>
<h1><?php echo $page_title; ?></h1>
<?php
############## END FUNCTIONS ##############################
switch ($step) {
case '2':
if ($_REQUEST['server']) {
$db = array();
$db['DB_SERVER'] = trim(stripslashes($_REQUEST['server']));
$db['DB_SERVER_USERNAME'] = trim(stripslashes($_REQUEST['username']));
$db['DB_SERVER_PASSWORD'] = trim(stripslashes($_REQUEST['password']));
$db['DB_DATABASE'] = trim(stripslashes($_REQUEST['database']));
$db_error = false;
db_connect($db['DB_SERVER'], $db['DB_SERVER_USERNAME'], $db['DB_SERVER_PASSWORD']);
if ($db_error == false) {
if (!db_test_create_db_permission($db['DB_DATABASE'])) {
$error = $db_error;
}
} else {
$error = $db_error;
}
if ($db_error != false) {
$error = "failed";
echo step1($db_error);
} else {
echo '<h1 style="color:green">Congratulations!</h1>
Connected Successfuly to datbase <strong>
<a href="http://www.webune.com/forums/how-to-test-mysql-database-connection.html">Continue >> </a></strong>';
}
} else {
$error = "ERROR: please provide a hostanme";
echo step1($error);
}
break;
default:
echo step1('Step 1');
break;
}
?>
<div align="center">
<img src="http://www.webune.com/images/headers/default_logo.jpg">
</div>
<div align="center">
Script Courtesy of
<a href="http://www.webune.com">Webune PHP/Mysql Hosting</a></div>
</body>
</html>
回答by Nitin
I resolved this issue by creating database manually using phpMyAdmin before submitting database settings.
我通过在提交数据库设置之前使用 phpMyAdmin 手动创建数据库解决了这个问题。
回答by Vlad Ion
- Go to PhpMyAdmin
- Create a database (e.g. Magento-Madabase)
- Edit the properties of the database and add access to a new user (e.g. Magento-User@localhost with a password)
- Install Magento. When it asks for a database type Magento-Database and when it asks for user and password chose Magento-User and the set password.
- 转到 PhpMyAdmin
- 创建数据库(例如 Magento-Madabase)
- 编辑数据库的属性并添加对新用户的访问权限(例如,带有密码的 Magento-User@localhost)
- 安装 Magento。当它询问数据库类型 Magento-Database 并且当它询问用户和密码时选择 Magento-User 和设置的密码。
... installation will continue without problems !
...安装将继续没有问题!
回答by Vidz
Check if you have created a database name with the value you specified in the database name textfield
检查您是否使用在数据库名称文本字段中指定的值创建了数据库名称
回答by user4776472
at time of magento installation when you entering username and password , type in the username field 'root' instead of your own username and password field must be blank. "this solution is work successfully".........
在 magento 安装时输入用户名和密码时,在用户名字段中键入“root”而不是您自己的用户名和密码字段必须为空。“此解决方案成功运行”........
回答by gbe
There are lots of possible reasons for this error, but if your database name, username and password are all correct, and assuming your database is on the same host, you could try swapping the hostname and IP address:
这个错误有很多可能的原因,但如果你的数据库名称、用户名和密码都正确,并且假设你的数据库在同一台主机上,你可以尝试交换主机名和 IP 地址:
That is, if you are currently trying "localhost" as your hostname, try "127.0.0.1" instead. If you are already trying "127.0.0.1", try "localhost".
也就是说,如果您当前正在尝试使用“localhost”作为主机名,请尝试使用“127.0.0.1”。如果您已经在尝试“127.0.0.1”,请尝试“localhost”。
回答by Jaydip Patel
1) Go to xampp\php\php.ini and remove the ";"sign before "extension=php_curl.dll"
1) 转到xampp\php\php.ini并删除“;” 在“extension=php_curl.dll”前签名
2 ) just go to following location and replace the code :
2)只需转到以下位置并替换代码:
file location : app/code/core/Mage/Install/etc/config.xml
文件位置:app/code/core/Mage/Install/etc/config.xml
find code :<pdo_mysql>
查找代码:<pdo_mysql>
and
和
replace with :
用。。。来代替 :
<pdo_mysql> 1 </pdo_mysql>
回答by Mukesh Chapagain
- Go to
app/code/core/Mage/Install/Model/Installer/Db.php
- Find the
checkDatabase($data)
function At the end of this function, there is the following code:
Mage::throwException(Mage::helper('install')->__('Database connection error.'));
Change it to the following:
Mage::throwException(Mage::helper('install')->__($e->getMessage()));
Go to your browser, where you are installing Magento, click the
Continue
button- Now, you should be able to see some proper error message
- 去
app/code/core/Mage/Install/Model/Installer/Db.php
- 查找
checkDatabase($data)
函数 在这个函数的最后,有如下代码:
Mage::throwException(Mage::helper('install')->__('Database connection error.'));
将其更改为以下内容:
Mage::throwException(Mage::helper('install')->__($e->getMessage()));
转到您要安装 Magento 的浏览器,单击
Continue
按钮- 现在,您应该能够看到一些正确的错误消息
In my case, I got the following error message:
就我而言,我收到以下错误消息:
Database server does not support the InnoDB storage engine.
数据库服务器不支持 InnoDB 存储引擎。
So, to solve this, I commented the InnoDB check in the same checkDatabase
function.
所以,为了解决这个问题,我在同一个checkDatabase
函数中注释了 InnoDB 检查。
// check InnoDB support
/*if (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') {
Mage::throwException(Mage::helper('install')->__('Database server does not support the InnoDB storage engine.'));
}*/
After that, I was able to install Magento.
之后,我就可以安装 Magento。