Last active
June 30, 2020 18:55
-
-
Save guigmaster/540794e41023559bd5f3 to your computer and use it in GitHub Desktop.
MySQL tips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT CONCAT("ALTER TABLE ", TABLE_NAME," CHARSET=utf8, COLLATE=utf8_general_ci;") AS ExecuteTheString | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_SCHEMA="dababase" | |
AND TABLE_TYPE="BASE TABLE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements | |
FROM information_schema.tables AS tb | |
WHERE table_schema = @DATABASE_NAME | |
AND `ENGINE` = 'MyISAM' | |
AND `TABLE_TYPE` = 'BASE TABLE' | |
ORDER BY table_name DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) | |
AS statement FROM information_schema.tables | |
WHERE table_schema = 'database_name' AND table_name LIKE 'myprefix_%'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT * | |
FROM information_schema.columns | |
WHERE table_schema = 'database_name' | |
AND column_key = 'PRI' | |
AND column_name LIKE 'prefix_%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT datetime(data_column/1000, 'unixepoch', 'localtime') AS data_t FROM table; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT Concat('TRUNCATE TABLE `',table_schema,'`.`',TABLE_NAME, '`;') | |
FROM INFORMATION_SCHEMA.TABLES where table_schema in ('db1_name','db2_name'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET FOREIGN_KEY_CHECKS=0; | |
TRUNCATE table1; | |
TRUNCATE table2; | |
SET FOREIGN_KEY_CHECKS=1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment