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
80
votes
2 answers

How to select count with Laravel's fluent query builder?

Here is my query using fluent query builder. $query = DB::table('category_issue') ->select('issues.*') ->where('category_id', '=', 1) ->join('issues', 'category_issue.issue_id', '=', 'issues.id') …
Alex Naspo
  • 2,052
  • 1
  • 20
  • 37
80
votes
5 answers

NULL value in multi-column primary key

I've got a table with several columns making up the primary key. The nature of the data stored allows some of these fields to have NULL values. I have designed my table as such: CREATE TABLE `test` ( `Field1` SMALLINT(5) UNSIGNED NOT NULL, …
simbabque
  • 53,749
  • 8
  • 73
  • 136
79
votes
14 answers

Create mysql table directly from CSV file using the CSV Storage engine?

I just learned that MySQL has a native CSV storage engine which stores data in a Comma-Separated-Value file per table. Is it possible to create a table directly from a uploaded CSV file, something like: CREATE TABLE USERS < PATH/USERS.CSV where…
Jonathan DS
  • 2,050
  • 5
  • 25
  • 48
79
votes
4 answers

Difference in MySQL JOIN vs LEFT JOIN

I have this cross-database query... SELECT `DM_Server`.`Jobs`.*, `DM_Server`.servers.Description AS server, digital_inventory.params, products.products_id, products.products_pdfupload, …
Ben
  • 60,438
  • 111
  • 314
  • 488
79
votes
5 answers

Deleting records before a certain date

How would I go about deleting all records from a MySQL table from before a certain date, where the date column is in DATETIME format? An example datetime is 2011-09-21 08:21:22.
Hard worker
  • 3,916
  • 5
  • 44
  • 73
79
votes
7 answers

Why can Java not connect to MySQL 5.7 after the latest JDK update and how should it be fixed? (ssl.SSLHandshakeException: No appropriate protocol)

In the latest update to the JDK in April 2021 (11.0.11+9-0ubuntu2~18.04) support for TLSv1 and TLSv1.1 was dropped, presumably because since March 2021 those versions are no longer supported. This is evident by the diff in the java.security…
bersling
  • 17,851
  • 9
  • 60
  • 74
79
votes
12 answers

How do I find out my root MySQL password?

I just installed MySQL on Ubuntu and the root user can't log in :) How can I recover or find out my password? Using blank for password does not work.
Genadinik
  • 18,153
  • 63
  • 185
  • 284
79
votes
7 answers

How to use mysqldump for a portion of a table?

So I can export only a table like this: mysqldump -u root -p db_name table_name > table_name.sql Is there any way to export only a portion of a table with mysqldump? For example, 0 - 1,000,000 rows, 1,000,000 - 2,000,000 rows, etc. Should I do this…
datasn.io
  • 12,564
  • 28
  • 113
  • 154
79
votes
7 answers

Best way to check if mysql_query returned any results?

I'm looking for the best way to check and see if any results were returned in a query. I feel like I write this part of code a lot and sometimes I get errors, and sometimes I don't. For example, I run this query to check if a username exists before…
timroman
  • 1,384
  • 1
  • 10
  • 18
79
votes
4 answers

MySQL InnoDB foreign key between different databases

I would like to know if it's possible in InnoDB in MySQL to have a table with foreign key that references another table in a different database ? And if so, how this can be done ?
Alaa
  • 4,471
  • 11
  • 50
  • 67
79
votes
5 answers

WooCommerce: Finding the products in database

I'm creating a website using WooCommerce and I want to restrict the available products to users depending on the postcode that they enter in the search form on my home page. To be able to achieve that I'll have to specify the conditions of each…
T.Doe
  • 1,969
  • 8
  • 27
  • 46
79
votes
10 answers

How to execute MySQL command from the host to container running MySQL server?

I have followed the instruction in https://registry.hub.docker.com/_/mysql/ to pull an image and running a container in which it runs a MySQL server. The container is running in the background and I would like to run some commands. Which is the best…
Mazzy
  • 13,354
  • 43
  • 126
  • 207
79
votes
5 answers

Most efficient way to store IP Address in MySQL

What is the most efficient way to store and retrieve IP addresses in MySQL? Right now I'm doing: SELECT * FROM logins WHERE ip = '1.2.3.4' Where ip is a VARCHAR(15) field. Is there a better way to do this?
ensnare
  • 40,069
  • 64
  • 158
  • 224
79
votes
7 answers

Search for string within text column in MySQL

I have mysql table that has a column that stores xml as a string. I need to find all tuples where the xml column contains a given string of 6 characters. Nothing else matters--all I need to know is if this 6 character string is there or not. So it…
user94154
  • 16,176
  • 20
  • 77
  • 116
79
votes
10 answers

CURRENT_DATE/CURDATE() not working as default DATE value

Pretty straight forward question here, I think this should work but it doesn't. Why doesn't it? CREATE TABLE INVOICE( INVOICEDATE DATE NOT NULL DEFAULT CURRENT_DATE )
inControl
  • 2,215
  • 4
  • 24
  • 39