All versions of MySQL (not Microsoft SQL Server). Please also add a version-specific tag like mysql-5.7 if that is relevant to the question.

learn more… | top users | synonyms

2
votes
1answer
1k views

Is there a product to auto-build indexes based on slow queries?

I'm looking to either find, purchase, or write a script to identify slow queries, identify potential missing indexes, and when needed create the appropriate index within a reasonable amount of time of ...
2
votes
1answer
473 views

inserting large quantity of data into mysql table

I need to insert about 400 000 000 rows of test data into the InnoDB table. Table is quite simple: CREATE TABLE IF NOT EXISTS `tgt` ( `id_1` int(10) unsigned NOT NULL, `id_2` int(10) unsigned NOT ...
2
votes
3answers
5k views

Count null and not null values in a column

How to count and retrieve null and not null on same column in MySQL? mytable --------------------------------------------------- id | name | visited | registDate | ...
2
votes
2answers
145 views

My query fails to segment the results as intended. What am I doing wrong?

Update: Re-phrasing the question. Below are the results and the desired results. What do I need to do to get the desired results? See http://sqlfiddle.com/#!2/d0e13c/69 Thank you SELECT ...
2
votes
1answer
716 views

MySQL Seconds behind Master fluctuation

I have two servers set up in Master-Master with one additional Slave connected to the first master. Lately I've started getting alerts from monyog that Master 1 has a seconds_behind_master value of ...
2
votes
2answers
579 views

MySQL 5.6 showing wrong “second_behind_master”

mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.10.7.98 ...
2
votes
2answers
22 views

Cause of delay after use `$database`

For a certain project, it seems like the command use <database>; takes an extraordinarily long time (often a minute or more). (This seems to be the case across a couple of different instances on ...
2
votes
1answer
188 views

What happens when CREATE INDEX gets interrupted (manually or accidentally)?

It takes hours or even days to create an index for a table of millions of rows. What happens to the database / data when CREATE INDEX gets interrupted? Such as when I manually used Ctrl-C or when ...
2
votes
1answer
876 views

Vacuum in postgresql and Purge in mysql

Do the vacuum operation in postgresql and purging operation in mysql perform the same tasks?
2
votes
3answers
2k views

Altering table Foreign Keys produces an error (errno:150) (MySQL)

This is the first database I set up so I apologize if my problem is something obvious. I'm playing around with my table design and tried to create some link tables with FKs to avoid redundant data. ...
2
votes
1answer
4k views

How do I tune MySQL with results from mysqltuner?

I ran mysqltuner and got this: -------- General Statistics -------------------------------------------------- [--] Skipped version check for MySQLTuner script [OK] Currently running supported MySQL ...
2
votes
1answer
1k views

Increment value in row if it exists, otherwise create row with value?

Below is the MySQL table layout that I'm working with. Basically, I'd like to increment views, watchers, and inquiries as they occur through the front end of the website. My question is how would I ...
2
votes
1answer
6k views

MySQL rebuild after Corrupt ibdata1

I have a MySQL server that serves a couple of databases including a Magento e-commerce store. We have been suffering with corruption in the ibdata1 file for a while, but it has now reached a critical ...
2
votes
2answers
3k views

What are definer and invoker rights in database, Oracle and MysQL?

What are definer and invoker rights in database, Oracle and MysQL? I just don't get it
2
votes
1answer
5k views

Multiple “root” users in MySQL

Mysql is showing 5 root users: | root | % | | root | 127.0.0.1 | | root | ::1 | | root | localhost | | root | mysrverhostname | What are these 5 for? Are there some I can ...
2
votes
1answer
745 views

Can I configure MySQL replication to break when I run a “drop database” or “drop table” command on the master?

Basically, what the title says. This would enhance the failover quality of our systems, becuase we have run into issues of people thinking that they were in a test environment running drop statements ...
2
votes
1answer
78 views

Get results ordered by a specific column in a looping way

I have heavy difficulties in getting rows ordered in an special way. Two tables are part in this: Table 1 - WORDS: id | char | word | categoryid (<- id of a row in CATEGORY) Table 2 - CATEGORY: ...
2
votes
1answer
6k views

Recursive Query in MySQL using stored proceedure and CURSOR

I'm expanding our user/group system to allow for dynamic groups which are made up of other groups members. I have three tables users, groups, and relationships. For simplicity sake, lets say users ...
2
votes
2answers
612 views

Can anyone offer an opinion on handlersocket vs memcached performance in MySQL 5.6

I must say I was a little mis(un)-informed about the MySQL Memcached plugin which offers the same NoSQL like access to InnoDB tables as HandlerSocket, I had only had experience with entirely ...
2
votes
2answers
10k views

My.cnf with 64GB RAM

May the following my.cnf file be fine for a dedicated server with 64GB of RAM (on Debian)? I'm running just one website on the server and on high load data insert in some table takes centuries...it ...
2
votes
2answers
6k views

Mysql match on two columns and get count

How do I get a count of? +---------+-------------+ | col1 | col2 | +---------+-------------+ | Joe | April | | Fred | May | | Sam | April | | Joe | ...
2
votes
2answers
1k views

How to SELECT rows with time duration stored in varchar column?

There is a column in table defined like this : duration varchar(10) It has value for duration of a MP3 file stored in it like : 52:19 (Minutes : Seconds) How can I create a SQL query, for ...
2
votes
1answer
368 views

Database structure for multiple users sharing one dataset, but also many users with their own dataset

I'm building a web app with php/mysql, and I'm trying to figure out how to set up multiple users sharing data. Here's the best analogy I can come up with on what I'm trying to do: You have a ...
2
votes
4answers
3k views

How To Update Random ID to a table in mysql?

I have table like this: ID | City | Prize | ---------------------------- 1 |Surabaya | HP 2 |Surabaya | Watch 3 |Surabaya | Bag 4 |Semarang | 5 |Semarang |Watch 6 |Semarang | 7 ...
2
votes
1answer
106 views

How is the number of records on a select determined as high or low by optimizer?

What is the threshold between using the index and doing an direct access to the database? I assume this decision is related to the number of index access (and subsequent access to the tables). If this ...
2
votes
3answers
197 views

How to include Innodb_trx_id in MySQL slow log

Evaluating MySQL's slow query log with pt-query-digest from the Percona Toolkit, I need to group queries by transaction. As it seems, the easiest way to do this is to group by the Innodb_trx_id ...
2
votes
1answer
7k views

Not able to login on MySQL in AWS RDS using root

I am trying to connect my MySQL RDS from EC2. Under security groups I have made sure permissions are in place. $ mysql -h xxx.xyz.ap-southeast-1.rds.amazonaws.com -P 3306 -p Enter password: I am ...
2
votes
1answer
3k views

MySQL Mistake with GRANT OPTION

I am unsure reading the MySQL documentation if creating a user with the GRANT option will give them the power to create users and grant privileges, or change the privileges of other users databases. ...
2
votes
1answer
5k views

Where EVENTS history are logged/recorded in MySql?

I just setup some stored procedures to run in the event scheduler using CREATE EVENT. I'm trying to find where (if somewhere) the history of it running is stored. I looked at the docs but couldn't ...
2
votes
2answers
1k views

MySQL Cluster - Got error 1601 'Out extents, tablespace full' from NDB

I am trying to do some tests on MySQL Cluster. I am creating my database using following commands: CREATE DATABASE test1; use test1; CREATE LOGFILE GROUP lg1 ADD UNDOFILE 'undofile.dat' ENGINE = NDB; ...
2
votes
1answer
1k views

How to optimize a query that includes counts of rows in multiple tables?

My query looks like this: EXPLAIN SELECT ... FROM USER u LEFT OUTER JOIN (SELECT COUNT(*) notified_count, user_id FROM user_email_tracking ON u.id = email_tracking WHERE email_type_id = 4 ...
2
votes
1answer
985 views

Issue moving database between servers (cannot find .frm file even though it's there)

I used MAMP on my local machine to make a little site with a mysql database. I moved all the site files over the to server. Great. The name of my database is roster and it has one table called users. ...
2
votes
1answer
8k views

MySQL query to evaluate ranges in date and time elements of a datetime column separately

TABLE EventID, EventTime (DATETIME) 1 2013-09-29 23:55:00.0 2 2013-10-01 00:05:00.0 3 2013-09-29 23:55:00.0 4 2013-09-29 23:45:00.0 5 2013-10-02 23:05:00.0 6 ...
2
votes
1answer
198 views

Can Unicode columns include non-Unicode values in SQL Server?

I need to convert Unicode column values from UTF16-LE to UTF-8 to then import into MySQL. Is it safe to assume columns of NVARCHAR, NTEXT, NCHAR, BIT, INT, DECIMAL, FLOAT, and DATETIME all must be ...
2
votes
2answers
3k views

Select the latest changed row in a table

I have a Mysql table test with the fields id, changedate, name. some names have multiple changedates. I can select all rows with SELECT id, changedate, name FROM `test` ORDER BY changedate; How ...
2
votes
2answers
140 views

Optimize query or model, to get an population overview in time

I think I've got a very simple model and query, but I cannot find a way to make use of indexes to boost performance. I wonder if there is a trick in my model, or MySQL query, to speed up the ...
2
votes
1answer
3k views

MySQL: sysbench test - InnoDB vs Memory tables

I've done some tests in order to investigate performance issue on the new HP Gen8 server (Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz) I've created two tables, first one is using InnoDB storage engine ...
2
votes
1answer
1k views

mysql innodb space x did not exist in memory

Into my innodb log I got the errors below. How to fix? What did it mean? Some tables are corrupted but not all. InnoDB: space id 1753 did not exist in memory. Retrying an open. 130906 16:31:27 ...
2
votes
2answers
2k views

How to use OR in query with priority?

In a simple query like SELECT * FROM table WHERE id='x' OR id='y' How to give a priority to get only one of the WHERE clauses? I mean getting rows with id='x'. Only if there is no row, get row ...
2
votes
2answers
212 views

Get missed transactions from slave

I'm trying to write a disaster recovery plan, I have one way replication with 1 master(A) and 3 slaves(B,C,D) A /|\ / | \ B C D Let's say my master crash, and I loose all data on ...
2
votes
1answer
456 views

Mysql foreign key cascade delete

Does mysql have a way to delete all sub links if a row was deleted from a "parent" table? Example table setup is below, the issue I am trying to avoid is having to maintain a script that deletes the ...
2
votes
1answer
3k views

“Use Database” command inside a stored procedure

I would like to dynamically use a database inside a stored procedure but the use database_name command is not supported inside procedures. What alternatives are there?
2
votes
2answers
206 views

MySQL - unique constraints design

I am using MySQL and looking to solve a problem with relational data. I am not sure it is possible but wanted to ask the community. Please consider the diagram: I would like to add a unique ...
2
votes
1answer
127 views

Need to Rewrite/optimize Slow Query

I have a query with following explain plan EXPLAIN SELECT COUNT(applicant.id) as applicantCount, application.name,applicant.application_id,application.id FROM applicant LEFT JOIN application ...
2
votes
1answer
5k views

MySQL Query: Delete from 'table2' where column = 'value' IF column in 'table1' = 'value'

I am trying to execute a MySQL query to delete rows from 'table2' where column = 'value' IF column in 'table1' = 'value' I have 2 tables... Table 1 is called accounts Table 2 is called ...
2
votes
1answer
1k views

Would adding indexes to my foreign keys improve performance on this MySQL query?

Consider the following query: SELECT `locations`.`id` AS `location_id`, `locations`.`address`, `locations`.`lat`, `locations`.`lng`, `tickets`.`status_id`, `customers`.`name`, ...
2
votes
2answers
187 views

MySQL #1064 error on line 2 [closed]

I'm quite new on learning SQL and I seem to be running into an issue with the following code: CREATE TABLE `read` (`order` NOT NULL UNIQUE AUTO_INCREMENT, `title` VARCHAR(50) NOT NULL, `url` ...
2
votes
3answers
1k views

index mysql concatenated columns

I have a table for author names with two fields, first_name & last_name, both varchar(55), both nullable (for crazy business logic reasons) although in reality last_name is unlikely to ever be ...
2
votes
2answers
151 views

MySQL Security permissions

Is it possible in MySQL to block users from executing these statements? DESC "table" SHOW TABLES SHOW CREATE TABLE "table" Or I need to write a MySQL transport port wrapper ? GRANT ON TABLE does ...
2
votes
2answers
4k views

Create multiple columns from a single column filtering criteria?

thanks in advance for your time, what I need to achieve is generate multiple columns result from a single query, the thing is this: I got a table were is storing the next: id | user_id | revision 1 ...