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

CREATE TEMPORARY TABLE IF NOT EXISTS table2 AS (SELECT * FROM table1) From the manual found at http://dev.mysql.com/doc/refman/5.7/en/create-table.html You can use the TEMPORARY keyword when creating a table. A TEMPORARY table is visible only to the current session, and is dropped automatically when the session is closed. This means that two different sessions can use … Read more

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

Try this function – SELECT VERSION(); -> ‘5.7.22-standard’ VERSION() Or for more details use : SHOW VARIABLES LIKE “%version%”; +————————-+——————————————+ | Variable_name | Value | +————————-+——————————————+ | protocol_version | 10 | | version | 5.0.27-standard | | version_comment | MySQL Community Edition – Standard (GPL) | | version_compile_machine | i686 | | version_compile_os | pc-linux-gnu … Read more

Delete with Join in MySQL

You just need to specify that you want to delete the entries from the posts table: DELETE posts FROM posts INNER JOIN projects ON projects.project_id = posts.project_id WHERE projects.client_id = :client_id EDIT: For more information you can see this alternative answer

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

I once had this problem and solved it by installing mysql-server, so make sure that you have installed the mysql-server, not the mysql-client or something else. That error means the file /var/run/mysqld/mysqld.sock doesn’t exists, if you didn’t install mysql-server, then the file would not exist. So in that case, install it with sudo apt-get install … Read more

How to shrink/purge ibdata1 file in MySQL

That ibdata1 isn’t shrinking is a particularly annoying feature of MySQL. The ibdata1 file can’t actually be shrunk unless you delete all databases, remove the files and reload a dump. But you can configure MySQL so that each table, including its indexes, is stored as a separate file. In that way ibdata1 will not grow … Read more

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

To see the index for a specific table use SHOW INDEX: SHOW INDEX FROM yourtable; To see indexes for all tables within a specific schema you can use the STATISTICS table from INFORMATION_SCHEMA: SELECT DISTINCT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = ‘your_schema’; Removing the where clause will show you all indexes in all schemas.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)