在 WordPress 上建立数据库连接时出错
我有一个使用 WordPress 的博客,但有时我遇到问题,
出现错误
建立数据库连接时出错 这要么意味着 wp-config.php
文件中的用户名和密码信息不正确,或者我们无法联系位于 %s
的数据库服务器。这可能意味着您主机的数据库服务器已关闭。
您确定您的用户名和密码正确吗? 您确定输入了正确的主机名吗? 您确定数据库服务器正在运行吗? 如果您不确定这些术语的含义,您应该联系您的房东。如果您仍然需要帮助,您可以随时访问 WordPress 支持论坛
,这是我的配置文件
define('WP_HOME','http://www.mysite.com');
define('WP_SITEURL','http://www.mysite.come');
define('DB_NAME', 'mydbname');
/** MySQL database username */
define('DB_USER', 'dbusername');
/** MySQL database password */
define('DB_PASSWORD', 'dbpassword');
/** MySQL hostname */
define('DB_HOST', 'mysite.com');
,为什么我有时会收到此错误,您对此问题有何看法?
我联系我的管理员服务器,他们说“我们的服务器和 mysql 服务没有任何问题”
是我的服务器有问题还是我的配置有问题?
i have a blog with wordpress but sometimes i have problem with that
i got blow error
Error establishing a database connection
This either means that the username and password information in your wp-config.php
file is incorrect or we can't contact the database server at %s
. This could mean your host's database server is down.
Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums
and this is my config file
define('WP_HOME','http://www.mysite.com');
define('WP_SITEURL','http://www.mysite.come');
define('DB_NAME', 'mydbname');
/** MySQL database username */
define('DB_USER', 'dbusername');
/** MySQL database password */
define('DB_PASSWORD', 'dbpassword');
/** MySQL hostname */
define('DB_HOST', 'mysite.com');
why i got this error sometimes what do you think about this problem?
i contact with my admins server and they said "we dont have any problem with server and mysql service"
does my server have problem or my config have problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果您没有为 MySql 使用默认端口 3306,请提供带有端口号的主机名。
这会起作用
If your are not using default port 3306 for MySql, do give the host name with port number.
This would work
这就是关键;如果它只是有时发生,则这是网络主机的间歇性问题。虚拟主机需要在 MySQL 日志和 PHP 日志中查找连接错误、超时、MySQL 崩溃等,以及任何可以指出间歇性问题原因的内容。
如果您始终出现“建立数据库连接时出错”的情况,则表明您在
wp-config.php
中犯了明确的错误。告诉网络主机和管理员查看他们的日志,了解 MySQL 服务器何时停机以及原因。
如果这是您自己的服务器,您需要了解操作系统和其他详细信息,以便可以在 Stack Overflow 中搜索信息。日志位置因操作系统而异。
That's the key; if it only happens sometimes, it's an intermittent issue at the webhost. The webhost needs to look in the MySQL logs and PHP logs for connection errors, timeouts, MySQL crashes, etc, anything that will point to the cause of the intermittent issues.
If you had "Error establishing a database connection" all the time, that points to a definite error you made in
wp-config.php
.Tell the webhost and administrator to look at their logs to see when the MySQL server is going down and why.
If this is your own server, you need to know the OS and other details so you can search Stack Overflow for the information. Log locations vary, depending on the OS.
如果您得到它'有时',那么这意味着 PHP Scrpt 无法连接到数据库。各种原因之一可能是数据库服务器关闭了一段时间。
If you get it 'sometimes' then it means the PHP Scrpt wasn't able to connect to the database. One of the various reasons could be database server down for a while.
首先输入mysql -u root -p并输入你的mysql密码
然后输入将 mydbname.* 上的所有权限授予 dbusername@localhost;
然后刷新权限;
最后退出
first type mysql -u root -p and enter the your mysql password
then type GRANT ALL PRIVILEGES ON mydbname.* TO dbusername@localhost;
then FLUSH PRIVILEGES;
and finally exit
我刚刚在我的 xampp 上新安装了 wordpress,它显示了同样的错误!我通过正确传递数据库名称解决了这个问题,用户名应该是root,并让密码字段为空,然后继续下一步有助于解决我的问题!
i just newly installed wordpress on my xampp it shows me same error! i solved it by passing database name correctly, and for username should be root, and by let the pssword field empty and then preceed next helps to fix my issue!
尝试将您的 DB_HOST 更改为 localhost
此外,您是否设置了数据库并填写了用户名、密码和密码?你的配置中的数据库?
Try changing your DB_HOST to localhost
Furthermore, have you set up the database and filled in the username, password & database in your config?
您应该做的第一件事是确保您在网站的前端和网站的后端(wp-admin)上遇到相同的错误。如果两个页面上的错误消息相同“建立数据库连接时出错”,则继续执行下一步。如果您在 wp-admin 上遇到不同的错误,例如“一个或多个数据库表不可用。数据库可能需要修复”,那么你需要修复你的数据库。
您可以通过在 wp-config.php 文件中添加以下行来完成此操作:
define('WP_ALLOW_REPAIR', true);
http://cdn4.wpbeginner.com/wp2-9/dbrepair.gif
请记住,设置此定义后,用户无需登录即可访问此功能。这是因为它的主要目的是修复损坏的数据库,当数据库损坏时用户通常无法登录。因此,一旦完成数据库的修复和优化,请确保将其从 wp-config.php 中删除。
看待
LatestTutorial.com
First thing you should do is to make sure that you are getting the same error on both the front-end of the site, and the back-end of the site (wp-admin). If the error message is the same on both pages “Error establishing a database connection”, then proceed onto the next step. If you are getting a different error on the wp-admin for instance something like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.
You can do this by adding the following line in your wp-config.php file:
define('WP_ALLOW_REPAIR', true);
http://cdn4.wpbeginner.com/wp2-9/dbrepair.gif
Remember, the user does not need to be logged in to access this functionality when this define is set. This is because its main intent is to repair a corrupted database, Users can often not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php.
Regard
LatestTutorial.com
从数据库中获取正确的数据库主机名
,使用以下 mysql 查询
选择@@主机名;
将 DB_HOST 的值更改为上述查询的输出
get the correct DB host name from the database
use following quesry for mysql
select @@hostname;
change the value of the DB_HOST to output of above query
有时会发生这种情况,只是因为凭据不正确,因此请检查您的凭据或尝试重置您的用户名和密码,有时主机问题或者您可以修复数据库,只需转到您的 wp-config 文件并写入
定义('WP_ALLOW_REPAIR',true);
并修复它,修复后不要忘记删除这条线。
Some time this happen , just because of incorrect credentials so check your credentials or try to reset your user name and passward , some time host issue or you can repair the database just go to your wp-config file and write
define ( 'WP_ALLOW_REPAIR' , true);
and repair it and don't forget to remove this line after repair.
如果您只是有时出现错误,则问题的原因有很多
如果您的数据库很大,它无法处理查询。 (您可能会在错误日志中看到“数据库连接太多”或“用户已拥有超过 'max_user_connections' 活动连接”错误。因此请尝试减小数据库表的大小。
如果两者都出现错误后端和前端,检查您的数据库凭据是否正确。
如果仅前端出现错误,请尝试修复数据库。在wp-config.php中添加以下代码行
define('WP_ALLOW_REPAIR', true) 来修复数据库。 ;
然后转到 'http://www.yoursite.com/wp-admin /maint/repair.php',然后单击“修复和优化数据库”按钮。
There are many reason for the issue if you get the error only sometimes
If your database is very big, it can not handle the queries. ( You probably see 'too many database connections' or 'user already has more than 'max_user_connections' active connections' errors on error logs. So try to reduce database tables size.
If you got the error on both backend and frontend, check your database credentials are correct.
If the error only on the front end. try to repair database by adding the following line of code in wp-config.php
define('WP_ALLOW_REPAIR', true);
Then go to 'http://www.yoursite.com/wp-admin/maint/repair.php' and click 'repair and optimize database' button.