Databases
How to install MySQL on Ubuntu
Install the latest MySQL on Ubuntu, secure it, and create your first database and user — the right way, from the official MySQL repository.
MySQL max_allowed_packet: packet too large
This error means a single query or row exceeded the maximum packet size MySQL accepts. It shows up most often when importing a large dump or storing big blobs.
MySQL ERROR 1205: Lock wait timeout exceeded
This error means a transaction waited too long for a row lock held by another transaction and gave up. Usually a long-running or stuck transaction is holding the lock.
MySQL ERROR 1040: Too many connections
This error means MySQL hit its max_connections limit and is refusing new clients. Raise the limit if it is genuinely too low, but first rule out leaked connections.
MySQL ERROR 1698: Access denied for user 'root'@'localhost'
On a fresh Ubuntu install, logging into MySQL as root fails even with the right password. The cause is the auth_socket plugin, not a wrong password.
SQLSTATE[23000] 1062 Duplicate entry
This MySQL error means you tried to insert or update a row with a value that already exists in a unique or primary key column. It is an integrity constraint doing exactly its job.
MySQL ERROR 2006: server has gone away
This error means the connection to MySQL was lost mid-query. The usual causes are an idle timeout, a query larger than max_allowed_packet, or the server restarting.
MySQL ERROR 1064: SQL syntax error
Error 1064 means MySQL could not parse your query. The message points at exactly where parsing failed, the cause is usually a reserved word, a typo, or a quoting problem.
SQLSTATE[HY000] [1045] Access denied for user
This MySQL error means the username, password or host your application uses to connect is wrong, or the user has no privileges on the database. It is the most common database connection error there is.
SQLSTATE[42S02] Base table or view not found
This MySQL error means your query references a table that does not exist in the connected database. In Laravel it almost always means migrations have not run, or you are connected to the wrong database.
SQLSTATE[HY000] [2002] Connection refused
This error means your application could not even reach the MySQL server. Unlike access denied, the credentials were never checked, the host or port is wrong or the database is not running.
How to rename a MySQL database
Unlike renaming a table, you can't rename a database in MySQL sadly enough. So there is no SQL query you can execute to achieve this. However, it is possible with a workaround.
Import MySQL database without timezone difference
When you import a MySQL database from a server to your local computer, you might notice that the dates and times are different.
How to install PostgreSQL with pgvector on Ubuntu
Turn PostgreSQL in a vector database using the pgvector extension on Ubuntu 22.
How to upgrade MySQL 5.7 to 8.0 on Ubuntu
Learn how to safely upgrade your database server from MySQL 5.7 to MySQL 8.0 on Ubuntu.
Backup MySQL databases in separate files
How to dump existing MySQL databases on a server in separate backup files.
Backup MySQL databases in single file
How to dump existing MySQL databases on a server in a single file.
Backup MySQL databases except system databases in a single file
How to dump all MySQL databases on a server in a single file with the exception of certain (system) databases.
Importing database in MySQL using command line
Importing a database in MySQL is quick & easy using the command line.
Export MySQL database using command line
Exporting a MySQL database is a task you will need very often when working with databases.
Stream MySQL backup directly to S3 bucket
Backing up your database is very important. Creating a backup in the most efficient way is essential when you do not have unlimited disk space.