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
1275
votes
26 answers

How do I connect to a MySQL Database in Python?

How do I connect to a MySQL database using a python program?
Marc Lincoln
1172
votes
23 answers

MySQL error code: 1175 during UPDATE in MySQL Workbench

I'm trying to update the column visited to give it the value 1. I use MySQL workbench, and I'm writing the statement in the SQL editor from inside the workbench. I'm writing the following command: UPDATE tablename SET columnname=1; It gives me the…
Jury A
  • 19,192
  • 24
  • 69
  • 93
1142
votes
12 answers

Insert into a MySQL table or update if exists

I want to add a row to a database table, but if a row exists with the same unique key I want to update the row. For example: INSERT INTO table_name (ID, NAME, AGE) VALUES(1, "A", 19); Let’s say the unique key is ID, and in my Database, there is a…
Keshan
  • 14,251
  • 10
  • 48
  • 72
1136
votes
46 answers

How do I rename a MySQL database (change schema name)?

How do I quickly rename a MySQL database (change its schema name)? Usually I just dump a database and re-import it with a new name. This is not an option for very big databases. Apparently RENAME {DATABASE | SCHEMA} db_name TO new_db_name; does bad…
deadprogrammer
  • 11,253
  • 24
  • 74
  • 85
1130
votes
19 answers

How to get the sizes of the tables of a MySQL database?

I can run this query to get the sizes of all tables in a MySQL database: show table status from myDatabaseName; I would like some help in understanding the results. I am looking for tables with the largest sizes. Which column should I look at?
JPashs
  • 13,044
  • 10
  • 42
  • 65
1105
votes
12 answers

INNER JOIN ON vs WHERE clause

For simplicity, assume all relevant fields are NOT NULL. You can do: SELECT table1.this, table2.that, table2.somethingelse FROM table1, table2 WHERE table1.foreignkey = table2.primarykey AND (some other conditions) Or else: SELECT …
JCCyC
  • 16,140
  • 11
  • 48
  • 75
1085
votes
20 answers

Join vs. sub-query

I am an old-school MySQL user and have always preferred JOIN over sub-query. But nowadays everyone uses sub-query, and I hate it; I don't know why. I lack the theoretical knowledge to judge for myself if there is any difference. Is a sub-query as…
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
1068
votes
11 answers

How can I do 'insert if not exists' in MySQL?

I started by googling and found the article How to write INSERT if NOT EXISTS queries in standard SQL which talks about mutex tables. I have a table with ~14 million records. If I want to add more data in the same format, is there a way to ensure…
warren
  • 32,620
  • 21
  • 85
  • 124
1037
votes
14 answers

How do I specify unique constraint for multiple columns in MySQL?

I have a table: table votes ( id, user, email, address, primary key(id), ); Now I want to make the columns user, email, address unique (together). How do I do this in MySql? Of course the example is just... an example. So please…
Niyaz
  • 53,943
  • 55
  • 151
  • 182
1033
votes
26 answers

How do you set a default value for a MySQL Datetime column?

How do you set a default value for a MySQL Datetime column? In SQL Server it's getdate(). What is the equivalant for MySQL? I'm using MySQL 5.x if that is a factor.
Brian Boatright
  • 36,294
  • 34
  • 81
  • 102
1025
votes
11 answers

How can I find all the tables in MySQL with specific column names in them?

I have 2-3 different column names that I want to look up in the entire database and list out all tables which have those columns. Is there any easy script?
Jobi Joy
  • 49,102
  • 20
  • 108
  • 119
1002
votes
31 answers

mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc... expects parameter 1 to be resource

I am trying to select data from a MySQL table, but I get one of the following error messages: mysql_fetch_array() expects parameter 1 to be resource, boolean given This is my code: $username = $_POST['username']; $password =…
iamjonesy
  • 24,732
  • 40
  • 139
  • 206
945
votes
12 answers

"INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"

While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear to be the use of either: ON DUPLICATE KEY UPDATE which implies an unnecessary update at…
Thomas G Henry LLC
  • 10,887
  • 8
  • 30
  • 32
927
votes
27 answers

Finding duplicate values in MySQL

I have a table with a varchar column, and I would like to find all the records that have duplicate values in this column. What is the best query I can use to find the duplicates?
Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168
927
votes
4 answers

TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT maximum storage sizes

Per the MySQL docs, there are four TEXT types: TINYTEXT TEXT MEDIUMTEXT LONGTEXT What is the maximum length that I can store in a column of each data type assuming the character encoding is UTF-8?
Lalith B
  • 11,843
  • 6
  • 29
  • 47