Questions tagged [mysql]

MySQL is a free, open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). DO NOT USE this tag for other DBs such as SQL Server, SQLite etc. Those are different DBs that all use their own dialects of SQL to manage the data. Always specify the exact version of the server in the question. Versions 5.x differ greatly in their capabilities from versions 8+.

MySQL is an Open Source RDBMS (Relational Database Management System) that runs as a server providing multi-user access to several databases. Its source code is available under the GNU GPL (General Public License). MySQL was acquired by Oracle in 2009.

MariaDB is a fork of MySQL using the same dialect of SQL and offering most of the same functions. See for fork-specific questions and answers.

MySQL offers standard database driver connectivity for using MySQL with applications and tools compatible with industry standards ODBC and JDBC.

How to ask a good and answerable question

Please see this post: Tips for asking a good Structured Query Language (SQL) question to get tips on how to ask a question about MySQL. Following some of these steps will help people to help you solve your problem.

Minimal, reproducible examples help the Stack Overflow community give good answers. Please read Why should I provide a Minimal Reproducible Example for a very simple SQL query?.

Always specify the exact version of the server in the question. Versions 5.x differ greatly in their capabilities from versions 8+.

Pronunciation

Officially it is /maɪˌɛskjuːˈɛl/ ("My S-Q-L"), but is often pronounced /maɪˈsiːkwəl/ ("My Sequel").

Latest Version (MySQL Community Server 8.0.27) and Version History

Example

SELECT * FROM users ORDER BY name

Resources

MySQL Tutorials

Popular questions

Popular administration tools

Chat Room

Related tags

661202 questions
908
votes
22 answers

How can I SELECT rows with MAX(Column value), PARTITION by another column in MYSQL?

I have a table of player performance: CREATE TABLE TopTen ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT, home INT UNSIGNED NOT NULL, `datetime`DATETIME NOT NULL, player VARCHAR(6) NOT NULL, resource INT NOT NULL ); What query will return…
Kaptah
  • 9,785
  • 4
  • 22
  • 19
899
votes
9 answers

MySQL: Large VARCHAR vs. TEXT?

I've got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or TEXT. I'm setting a front-end limit of 3000…
Tom
  • 30,090
  • 27
  • 90
  • 124
892
votes
25 answers

MyISAM versus InnoDB

I'm working on a projects which involves a lot of database writes, I'd say (70% inserts and 30% reads). This ratio would also include updates which I consider to be one read and one write. The reads can be dirty (e.g. I don't need 100% accurate…
user2013
  • 9,231
  • 5
  • 21
  • 8
866
votes
38 answers

Disable ONLY_FULL_GROUP_BY

I accidentally enabled ONLY_FULL_GROUP_BY mode like this: SET sql_mode = 'ONLY_FULL_GROUP_BY'; How do I disable it?
ZviBar
  • 9,758
  • 6
  • 25
  • 30
859
votes
15 answers

How can I do a FULL OUTER JOIN in MySQL?

I want to do a full outer join in MySQL. Is this possible? Is a full outer join supported by MySQL?
Spencer
  • 21,348
  • 34
  • 85
  • 121
855
votes
29 answers

Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

This should be dead simple, but I cannot get it to work for the life of me. I'm just trying to connect remotely to my MySQL server. Connecting as: mysql -u root -h localhost -p works fine, but trying: mysql -u root -h 'any ip address here'…
concept47
  • 30,257
  • 12
  • 52
  • 74
833
votes
15 answers

How to truncate a foreign key constrained table?

Why doesn't a TRUNCATE on mygroup work? Even though I have ON DELETE CASCADE SET I get: ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, CONSTRAINT instance_ibfk_1 FOREIGN KEY (GroupID) REFERENCES…
user391986
  • 29,536
  • 39
  • 126
  • 205
829
votes
15 answers

Duplicating a MySQL table, indices, and data

How do I copy or clone or duplicate the data, structure, and indices of a MySQL table to a new one? This is what I've found so far. This will copy the data and the structure, but not the indices: create table {new_table} select * from…
xkcd150
  • 8,767
  • 3
  • 23
  • 17
816
votes
17 answers

MySQL Error 1093 - Can't specify target table for update in FROM clause

I have a table story_category in my database with corrupt entries. The next query returns the corrupt entries: SELECT * FROM story_category WHERE category_id NOT IN ( SELECT DISTINCT category.id FROM category INNER JOIN …
Sergio del Amo
  • 76,835
  • 68
  • 152
  • 179
808
votes
10 answers

How can I temporarily disable a foreign key constraint in MySQL?

Is it possible to temporarily disable constraints in MySQL? I have two Django models, each with a foreign key to the other one. Deleting instances of a model returns an error because of the foreign key constraint: cursor.execute("DELETE FROM…
jul
  • 36,404
  • 64
  • 191
  • 318
791
votes
11 answers

What is the best collation to use for MySQL with PHP?

Is there a collation type which is officially recommended by MySQL, for a general website where you aren't 100% sure of what will be entered? I understand that all the encodings should be the same, such as MySQL, Apache, the HTML and anything inside…
Darryl Hein
  • 142,451
  • 95
  • 218
  • 261
787
votes
18 answers

MySQL Query GROUP BY day / month / year

Is it possible to make a simple query to count how many records I have in a determined period of time like a year, month, or day, having a TIMESTAMP field, like: SELECT COUNT(id) FROM stats WHERE record_date.YEAR = 2009 GROUP BY…
Fernando Barrocal
  • 12,584
  • 9
  • 44
  • 51
786
votes
17 answers

MySQL: Get character-set of database or table or column?

What is the (default) charset for: MySQL database MySQL table MySQL column
Amandasaurus
  • 58,203
  • 71
  • 188
  • 248
778
votes
10 answers

How to get size of mysql database?

How to get size of a mysql database? Suppose the target database is called "v3".
Newbie
  • 8,075
  • 4
  • 20
  • 13
773
votes
4 answers

SQL injection that gets around mysql_real_escape_string()

Is there an SQL injection possibility even when using mysql_real_escape_string() function? Consider this sample situation. SQL is constructed in PHP like this: $login = mysql_real_escape_string(GetFromPost('login')); $password =…
Richard Knop
  • 81,041
  • 149
  • 392
  • 552