Posts

Showing posts from May, 2024

How to clone MySQL database using SQL within same server?

Here is how to clone MySQL/MariaDB within same server. Core principle: use `Create TABLE <new_db>.<table_name> as select * from <old_db>.<table_name>`, and do it for all tables. If you have too many tables, you use the following SQL to generate a list of SQL. Steps: Use `CONCAT` to create SQL by selecting all tables from DB Get a list of `Create Table` and then run it all. SELECT CONCAT('CREATE TABLE my_database.20240510.', table_name, ' AS SELECT * FROM my_database.', table_name, ';') FROM information_schema.tables WHERE table_schema = 'my_database'; CREATE TABLE `my_database.20240510`.change_password_history AS SELECT * FROM my_database.change_password_history; CREATE TABLE `my_database.20240510`.children AS SELECT * FROM my_database.children; CREATE TABLE `my_database.20240510`.failed_jobs AS SELECT * FROM my_database.failed_jobs; CREATE TABLE `my_database.20240510`.interests AS SELECT * FROM my_database.interests; CR

Laravel 11: Encrypted string length for database (MySQL)

In Laravel, as of this writing, the encryption string length different for different length of source string. Here is the list Encrypted string length: 200 for 1 - 15 chars Encrypted string length: 228 for 16 - 31 chars Encrypted string length: 256 for 32 - 47 chars ... In other words, for every 15 chars increases in source string length, the encrypted string length increased 28 chars accordingly. Which also means: if your table column with set to 200, it stores maximum 15 chars of source string length. Hope it helps.

Plain Javascript to get current datetime with Timezone

That's why I hate javascript, it is too complicated. const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0'); const dateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; console.log(dateTime);