MySQL is an open-source, relational database management system.

learn more… | top users | synonyms

23
votes
8answers
16k views

Why is my database import losing text widget data?

I've created a site in WordPress on our development machine. In the theme we're using there are numerous widget zones to display text in (sidebar and front page). I've used simple Text widgets in all ...
20
votes
6answers
23k views

Using wpdb to connect to a separate database

I want to connect wpdb to another database. How do I create the instance and pass it the database name/username/password? Thanks
15
votes
3answers
9k views

MySQL Database User: Which Privileges are needed?

The short installation instruction for WordPress ("5 Minutes") state that: Create a database for WordPress on your web server, as well as a MySQL user who has all privileges for accessing and ...
10
votes
2answers
4k views

Wordpress Database Slow - should I switch to InnoDB?

I have a WordPress site with well over 10k posts, and things are starting to get very slow whenever I am adding and editing posts. Pages load nice and fast for users, along with the admin lists of ...
9
votes
3answers
640 views

What's a good strategy for planning WordPress DB growth?

Hoping for some feedback on the topic of optimizing and staying on top of performance as a WordPress database grows... to paint a picture.... let's say you have a WordPress / Buddypress MU site that ...
9
votes
2answers
4k views

The MySQL alternatives: Do Percona Server and MariaDB work well with WordPress, and do they make WordPress go better?

Lately I've been reading about MariaDB and Percona Server, two strong alternatives to MySQL that have gained popularity since Oracle bought Sun. As far as I know, both of them could be used with ...
8
votes
8answers
9k views

How to replace the domain name in a Wordpress database?

I have a Wordpress database which was installed in a development environment... thus, all references to the site itself have a fixed IP address (say 192.168.16.2). Now, I have to migrate that database ...
8
votes
6answers
38k views

What SQL Query to do a simple find and replace

Whenever I create a new website I first create a staging site on a subdomain like "stage.domain-name.com". After everything works correctly I export the database, open it in notepad++ and do a ...
8
votes
1answer
1k views

Why are simple updates to wp_postmeta's “_edit_lock” so slow?

In our MySQL slow query log, the cumulatively slowest query is a simple update to wp_postmeta. Here's an example: UPDATE `wp_postmeta` SET `meta_value` = '1392835505:386' WHERE `post_id` = 94705 ...
7
votes
4answers
3k views

the_date() not working

I am using wordpress 3.2 and I did a query post like this: <?php query_posts("posts_per_page=1post=type&page=post_parent=10");?> Then I try to echo out the date of this post I queried ...
7
votes
1answer
7k views

Should I use wpdb prepare?

I'm new to SQL and am wondering if I need to use wpdb->prepare for the following query to a table I've created global $wpdb; $tablename = $wpdb->prefix . "my_custom_table"; $sql = "SELECT * ...
7
votes
4answers
3k views

How can I find the source of slow queries in Wordpress?

I have a WordPress site with more than 8000 posts and everytime I add a new one the site becomes unresponsive. I checked the MySQL slow queries log and found out that it is performing a select that ...
7
votes
1answer
186 views

How do I optimize a custom post type admin page with 25,000 posts?

I'm getting the occasional excessive resource limit error to due to loading so many posts at once. We had set the PHP limit to 128 but just loading the list of posts for a couple of the post types is ...
6
votes
1answer
102 views

Reset Post IDs to less than 64bit integer

I have been running Wordpress for many years and have about 26000 posts. At some point my post ids have exceeded a 32bit integer and I am now locked into using Wordpress on a 64 bit system. I am ...
6
votes
1answer
706 views

Would switching to InnoDB from MyISAM improve performance of comments table?

A site I've built gets lots of comments in a short space of time - so perhaps 100 comments might be left in 5 or 10 minutes. This seems to cause a pretty heavy load on the database, especially when ...
6
votes
1answer
546 views

dbDelta support for FOREIGN KEY

On PHP 5.3.13/MySQL 5.5.21 the following code doesn't work: if($check_custom_fields_form!=1){ $sql = "CREATE TABLE IF NOT EXISTS ". $table_custom_fields_form ." ( `form_name` ...
5
votes
3answers
8k views

How do you properly prepare a %LIKE% SQL statement?

I'd like to use a LIKE %text% statement while still using the WordPress $wpdb class to sanitize and prepare input. SELECT column_1 from `prefix_my_table` WHERE column_2 LIKE '%something%'; I've ...
5
votes
2answers
322 views

WordPress database scalability from the code perspective

I have read through multiple questions here on StackExchange that concern WordPress scaling and the common opinion is that WordPress is indeed highly scalable provided you have the infrastructure to ...
5
votes
2answers
296 views

Lack of composite indexes for meta tables

Why wp_commentmeta table does not have a composite index (comment_id, meta_key) by default? I believe it's the only useful index for that table, am I wrong? Instead, it has a strange set of indexes: ...
5
votes
2answers
778 views

Can i use php sql functions instead of $wpdb?

I'm new to WordPress and was wondering why in WordPress API do they tell you to use functions such as prepare(), insert(), get_col(), get_row(), query(), etc. when technically I can use the built-in ...
5
votes
3answers
732 views

Resetting comment count

Recently, I had to move to another domain and had to recreate all my MySQL tables on the enw server. I noticed that for some posts, the number of comments is doubled. Example - ...
5
votes
3answers
4k views

is it possible to run some php code within a wordpress page?

I'd like to access a DB table and render it in some data grid format using php on a dedicated wordpress page, accessible to members of a certain group. Is this at all possible with wordpress or is ...
5
votes
4answers
8k views

What are the recommended database permissions for WordPress?

I just got WP running on my own server. I am not trying to lock things down more. What permissions should the db user have to my WP db?
5
votes
1answer
640 views

How does Wordpress handle MySQL row lock errors?

If there is a WordPress plugin which updates rows in a custom table, but that update encounters a row lock, what happens? E.g. two users simultaneously fire an update on TABLE1, one setting AGE=1 and ...
5
votes
2answers
4k views

Checking if Database Table exists

I read the wordpress codex and professional wordpress. It seems both use something like if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { to determine if the table exists. Is ...
5
votes
2answers
135 views

Ordering posts by day (not time) AND meta value

I would like to have a list of posts that is first ordered by day, and then within that day ordered user votes (stored as a meta field). Would it be better to convert each timestamp to the day at ...
5
votes
3answers
2k views

Complex meta query with 3 keys

I think the problem essentially relates to sql query structure and I am not an expert.... I need to search for posts (custom post type) by 2 parameters: pd_city pd_country Please note that ...
5
votes
3answers
763 views

MySQL Replication Latency Issues in wp-admin pages

I have an environment running WP 3.0.1 with a Master db and two slaves. I am using HyperDB to force all writes to go to the Master, and all reads to read from the two slaves. I am experiencing a ...
5
votes
1answer
350 views

Slow wp_term_relationships query

I'm running a large WP instance (currently has 28,000+ posts in custom types) and have been experiencing some odd slowdowns. Upon analyzing the MySQL slow query log, one of the problem queries is: ...
4
votes
3answers
2k views

Optimize Multiple Taxonomy Term MySQL Query?

(Moderator's note: Title was originally: "query/database optimisation") I'm written a function for a custom "filter" search panel that allows users to select terms from up to four custom taxonomies. ...
4
votes
2answers
301 views

Is it possible to define two databases for one installation?

Is it possible to define 2 database for one wp installation, I have searched but there are options for one database and 2 installations. I want this because, one of my clients site is hosted on ...
4
votes
2answers
2k views

Get posts by menu ID

I'm a little stuck here. I have a menu in Wordpress with some posts in it. What I would like is to retrieve all the posts as objects. I think I'm pretty close, but the SQL query doesn't seem to work ...
4
votes
2answers
412 views

How to log mysql errors from wordpress core?

I am developing a wordpress site and I would like to be able to log and handle mysql errors from wordpress core. My site has a mix of wordpress pages and posts + a few php pages that run under the ...
4
votes
1answer
1k views

Set page template for all pages?

I know the page template is set in the wpdb as meta_key = _wp_page_template and meta_value = template.php. How can I write a SQL script to set each post where post_type = 'page' to a specific ...
4
votes
1answer
222 views

Custom query to get post names beginning with a digit

I'm implementing an A-Z index for a custom post type. I've got my links printing out the page and the query working for the letters. However, the numbers are tripping me up because I don't want them ...
4
votes
1answer
424 views

What specific database privileges does WordPress need?

I want to create a new database user for my WordPress installation. Usually on localhost, i can just use root, but it is good practice to use a user with as little rights as possible. What are those ...
4
votes
1answer
348 views

find a random blogid across my multisite network that has at least one post published

I need to find a random blog across my multisite network that has at least one post published of a certain post_type, and return its blogid as a variable so I can use it in a switch_to_blog() call. I ...
4
votes
1answer
1k views

Searching users with WP_List_Table plug-in

I am trying to devlope a plugin that will search and return my users so I can edit some other metatdata that belongs to them. I have been using the plug-in listed on the Codex as my starting point. I ...
4
votes
1answer
256 views

Built to scale, or worry later?

I'm starting a service that offers websites that runs on a giant Wordpress multi-site. I have a cloud based vps with nginx-php5-php-fpm-mysql. Storage with Amazon S3, distribution with MaxCDN. WP ...
3
votes
3answers
2k views

How To Export/Import WordPress (MySQL) Database Properly Via Command-Line?

Normally, a MySQL database can be exported and imported using these simple SSH commands: Export: mysqldump -u USERNAME -p DATABASE_NAME > filename.sql Import: mysql -u USERNAME -p ...
3
votes
7answers
1k views

WordPress MySQL & PHP Performance

have a website (www.americanbankingnews.com) that gets 40,000-50,000 page views today. It's currently sitting on a dedicated quad-core Xeon server with 8GB of ram. The site is powered by WordPress and ...
3
votes
2answers
786 views

How to prevent execution of default query, while preserving ability to use WP_Query in template?

PROBLEM: I'am trying to prevent execution of default WordPress query for custom category template. I have found a possible solution, but looks like it preventing execution of all post queries: ...
3
votes
1answer
582 views

Using source control with WordPress

I just recovered from a pretty bad crash using Server 2008 Shadow copy. Ultimatly I didn't lose more than a few hours of work but a loss is a loss. I've decided to move to version control to prevent ...
3
votes
1answer
124 views

Can I explicitly specify ENGINE=InnoDB in Wordpress?

I converted all my tables to InnoDB, but the MySQL server (which I can't access, as I'm on shared hosting) has MyISAM as the default, so every new table that Wordpress creates (e.g. when I add a new ...
3
votes
1answer
652 views

Extending search query with additional $sentence value

Next in my quest to extend WordPress is altering how WordPress uses the the $sentence variable in posts_search to include an additional string, when the $sentence variable meets a certain criteria. ...
3
votes
2answers
736 views

WordPress use innodb by default?

I just created a new WordPress site in my server. Normally, WordPress uses MyISAM as the database type. But this time, it created all InnoDB tables! Is this normal? Has WordPress switched to InnoDB in ...
3
votes
2answers
267 views

Search multiple meta keys at once

How would I modify the following SQL Query to allow me to search multiple meta keys at once? e.g. user_business AND user_about In the end I'll be searching about 40 - 50 different meta keys; or if ...
3
votes
2answers
631 views

mysql custom wp query

this code is designed to select posts with selected meta value in wordpress query <?php $values = $wpdb->get_results("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = ...
3
votes
1answer
3k views

delete unused postmeta

I love the comment by s_ha_dum : http://wordpress.org/support/topic/sql-query-to-delete-postmeta and havent tried it yet, but Im wondering just how 'clever' this actually is? Does the unused postmeta ...
3
votes
2answers
88 views

Wordpress will not operate correctly

My website is ImASpy.com. If you click on the link, Findings, this takes you to my first Wordpress page. It appears to work fine until you click on comments, or you try to go to the about page, which ...