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
635
votes
6 answers

MySQL string replace

I have a column containing urls (id,…
n00b
  • 16,088
  • 21
  • 56
  • 72
630
votes
11 answers

What is the size of column of int(11) in mysql in bytes?

What is the size of column of int(11) in mysql in bytes? And Maximum value that can be stored in this columns?
Gaurav
  • 28,447
  • 8
  • 50
  • 80
613
votes
91 answers

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I installed LAMP on Ubuntu 12.04 LTS (Precise Pangolin) and then set root password on phpMyAdmin. I forgot the password and now I am unable to login. When I try to change password through terminal I get: ERROR 2002 (HY000): Can't connect to local…
sushmit sarmah
  • 7,508
  • 6
  • 21
  • 24
607
votes
13 answers

How can I view live MySQL queries?

How can I trace MySQL queries on my Linux server as they happen? For example I'd love to set up some sort of listener, then request a web page and view all of the queries the engine executed, or just view all of the queries being run on a production…
barfoon
  • 27,481
  • 26
  • 92
  • 138
603
votes
13 answers

How to do a regular expression replace in MySQL?

I have a table with ~500k rows; varchar(255) UTF8 column filename contains a file name; I'm trying to strip out various strange characters out of the filename - thought I'd use a character class: [^a-zA-Z0-9()_ .\-] Now, is there a function in MySQL…
Piskvor left the building
  • 91,498
  • 46
  • 177
  • 222
599
votes
21 answers

How to run SQL script in MySQL?

I want to execute a text file containing SQL queries, in MySQL. I tried to run source /Desktop/test.sql and received the error: mysql> . \home\sivakumar\Desktop\test.sql ERROR: Failed to open file '\home\sivakumar\Desktop\test.sql', error:…
user1160432
  • 6,091
  • 3
  • 14
  • 4
598
votes
23 answers

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

I'm setting up a new server and keep running into this problem. When I try to log into the MySQL database with the root user, I get the error: ERROR 1698 (28000): Access denied for user 'root'@'localhost' It doesn't matter if I connect through the…
Folkmann
  • 6,131
  • 3
  • 13
  • 14
595
votes
14 answers

How to see indexes for a database or table in MySQL?

How do I see if my database has any indexes on it? How about for a specific table?
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
594
votes
23 answers

How to retrieve the current version of a MySQL database management system (DBMS)?

What command returns the current version of a MySQL database?
pheromix
  • 18,213
  • 29
  • 88
  • 158
590
votes
14 answers

Delete with Join in MySQL

Here is the script to create my tables: CREATE TABLE clients ( client_i INT(11), PRIMARY KEY (client_id) ); CREATE TABLE projects ( project_id INT(11) UNSIGNED, client_id INT(11) UNSIGNED, PRIMARY KEY (project_id) ); CREATE TABLE…
GeekJock
  • 11,066
  • 13
  • 43
  • 44
580
votes
10 answers

How to shrink/purge ibdata1 file in MySQL

I am using MySQL in localhost as a "query tool" for performing statistics in R, that is, everytime I run a R script, I create a new database (A), create a new table (B), import the data into B, submit a query to get what I need, and then I drop B…
lokheart
  • 23,743
  • 39
  • 98
  • 169
567
votes
6 answers

Create a temporary table in a SELECT statement without a separate CREATE TABLE

Is it possible to create a temporary (session only) table from a select statement without using a create table statement and specifying each column type? I know derived tables are capable of this, but those are super-temporary (statement-only) and I…
700 Software
  • 85,281
  • 83
  • 234
  • 341
561
votes
27 answers

MySQL DROP all tables, ignoring foreign keys

Is there a nice easy way to drop all tables from a MySQL database, ignoring any foreign key constraints that may be in there?
bcmcfc
  • 25,966
  • 29
  • 109
  • 181
557
votes
9 answers

How to declare a variable in MySQL?

How to declare a variable in mysql, so that my second query can use it? I would like to write something like: SET start = 1; SET finish = 10; SELECT * FROM places WHERE place BETWEEN start AND finish;
cdub
  • 24,555
  • 57
  • 174
  • 303
551
votes
5 answers

MySQL: @variable vs. variable. What's the difference?

In another question I posted someone told me that there is a difference between: @variable and: variable in MySQL. He also mentioned how MSSQL has batch scope and MySQL has session scope. Can someone elaborate on this for me?
aarona
  • 35,986
  • 41
  • 138
  • 186