DB

プランナ統計情報リストア

DB

MySQL (8.0.34) 調べた限りなし Oracle (23c)https://docs.oracle.com/cd/F19136_01/tgsql/managing-historical-optimizer-statistics.html#GUID-F1399D77-7E2E-434F-A67C-6ADB4C648D95 https://blog.usize-tech.com/oracledb_stats_restore/ RESTORE_TABLE_…

insert/update/delete returning

DB

MySQL (8.0.34) 調べた限りない模様 Oracle (23c)https://tech.excite.co.jp/entry/2023/10/27/100350https://docs.oracle.com/cd/F82042_01/lnpls/RETURNING-INTO-clause.html#GUID-38F735B9-1100-45AF-AE71-18FB74A899BEhttp://www.mitene.or.jp/~rnk/TIPS…

numeric→integerキャスト時端数扱い

DB

SQL Serverのみ切り捨て MySQL (8.0.34) select cast(1.4 as UNSIGNED );select convert(1.4 , UNSIGNED ); select cast(1.5 as UNSIGNED );select convert(1.5 , UNSIGNED ); select cast(2.4 as UNSIGNED );select convert(2.4 , UNSIGNED ); select cast(…

DB初期設定 

DB

MySQL (8.0.35) OS: Rocky Linux 8.9CPU : 2メモリ : 4GB -- 1. ラージページ設定 https://support.oracle.com/knowledge/Oracle%20Database%20Products/2118592_1.html https://dev.mysql.com/doc/refman/8.0/en/large-page-support.html -- 1.1 /proc/sys/…

DBパラメータ設定

DB

MySQL (8.0.35) OS: Rocky Linux 8.9CPU : 2メモリ : 4GB ※サーバーを初期化する前に設定必要(初期化はサーバーのデータディレクトリが空の場合に実施される)lower_case_table_names = 1 cp /etc/my.cnf /etc/my.cnf.bk$(date "+%Y%m%d") vim /etc/my.cnf [m…

CREATE OR REPLACE TABLE

DB

MySQL(8.0.34)サポートしていない Oracle(23c)サポートしていない PostgreSQL(15)サポートしていない SQL Server(2022)サポートしていない AWS Redshiftサポートしていない Azure Synapse Analyticsサポートしていない GCP BigQuery -- 1. 前作業 gcloud ini…

LATERAL

DB

MySQL (8.0.34)https://mita2db.hateblo.jp/entry/MySQL_8%E3%81%AE%E6%96%B0%E6%A9%9F%E8%83%BD_LATERAL%E5%8F%A5%E3%81%AB%E3%82%88%E3%82%8BSQL%E3%83%81%E3%83%A5%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0 -- 1. テストデータ作成 drop table tab2 ;drop ta…

CLONE

DB

MySQL (8.0.34)https://gihyo.jp/dev/serial/01/mysql-road-construction-news/0127https://dev.mysql.com/doc/refman/8.0/ja/clone-plugin-installation.html -- 1. CLONE plugin をインストール show plugins;INSTALL PLUGIN clone SONAME 'mysql_clone.so…

システム変数永続化

DB

MySQL (8.0.33)https://gihyo.jp/dev/serial/01/mysql-road-construction-news/0094https://dev.mysql.com/doc/refman/8.0/ja/option-files.html 「mysqld-auto.cnf」が「my.cnf」よりも優先 (1) my.cnf Default options are read from the following files …

メモリ状況確認

DB

MySQL (8.0.33) https://gihyo.jp/article/2022/10/mysql-rcn0183https://dev.mysql.com/doc/refman/8.0/ja/performance-schema-statement-tables.html SELECT *FROM performance_schema.setup_consumersWHERE NAME LIKE '%statements%'; UPDATE performance…

索引圧縮

DB

MySQL (8.0.33) https://dev.mysql.com/doc/refman/8.0/ja/innodb-compression.html テーブル圧縮やページ圧縮(transparent page compression)によりインデックスデータも圧縮されるため、セカンダリインデックスを含むテーブルでは利点も増幅されます。 Ora…

予約語

DB

MySQL (8.0.33)https://dev.mysql.com/doc/refman/8.0/en/keywords.html#keywords-in-current-series ACCESSIBLEACCOUNTACTIONACTIVEADDADMINAFTERAGAINSTAGGREGATEALGORITHMALLALTERALWAYSANALYSEANALYZEANDANYARRAYASASCASCIIASENSITIVEATATTRIBUTEAUTHENT…

パスワード使用可能文字

DB

Oracle -> ダブルクォート不可MySQL,PostgreSQL,SQL Server -> シングルクォート不可 MySQL (8.0.33)https://dev.mysql.com/doc/refman/8.0/ja/create-user.html パスワードをシングルクォートで囲むため、シングルクォートは使用不可 その他、\ も使用不可★…

パスワード有効期限

DB

MySQL (8.0.33)https://dev.mysql.com/doc/refman/8.0/ja/alter-user.html drop user if exists user2; create user user2@'%' identified by 'user2';grant process on *.* to 'user2'@'%'; select Host, User, password_expired, password_last_changed, p…

DBアカウントロック

DB

MySQL (8.0.33)https://dev.mysql.com/doc/refman/8.0/ja/account-locking.htmlhttps://dev.mysql.com/doc/refman/8.0/ja/alter-user.html drop user if exists user1; create user user1@'%' identified by 'user1';grant process on *.* to 'user1'@'%'; s…

プロシージャ引数の名前表記法

DB

MySQL (8.0.33)https://dev.mysql.com/doc/refman/8.0/en/call.htmlhttps://stackoverflow.com/questions/4245530/named-parameters-for-stored-procedures-in-mysql 名前表記法はできない模様 念のため使用できないことを確認 drop procedure proc1; delimi…

ビュー定義

DB

ビューのアスタは展開されて保存される MySQL (8.0.32) drop table if exists tab17 ;drop view if exists view17;drop view if exists view18; create table tab17(col1 int, col2 varchar(100), col3 datetime);create view view17 as select * from tab17…

最大インデックス数

DB

MySQL 64Oracle 無制限PostgreSQL 無制限SQL Server 999 MySQL (8.0.32)https://dev.mysql.com/doc/refman/8.0/en/innodb-limits.html 64 secondary indexes 1017カラムのテーブルを作成 : > a.sql for i in $(seq 1 65); do echo "create index ind1_${i} o…

最大カラム数

DB

MySQL 1017Oracle 1000 or 4096PostgreSQL 1600SQL Server 1024 MySQL (8.0.32)https://dev.mysql.com/doc/refman/8.0/en/column-count-limit.htmlhttps://dev.mysql.com/doc/refman/8.0/en/innodb-limits.html 1017 ※ 65,535 バイトの MySQL 最大行サイズ制…

カラムデフォルト値

DB

MySQL (8.0.32)drop table tab1 ;create table tab1( col1 bigint, col2 bigint default -1, col3 varchar(100), col4 varchar(100) default 'A', col5 datetime, col6 datetime default now()); select ordinal_position , column_name , data_type , chara…

DDL -> JSON作成ツール (create table)

DB

MySQL (8.0.32) drop procedure ddl2json;delimiter //create procedure ddl2json( in p_schema_name varchar(4000), in p_table_name varchar(4000))begin declare v_comments varchar(4000); declare v_partition_type varchar(4000); declare v_partition…

JSON -> DDL作成ツール (create table)

DB

MySQL (8.0.32) -- テーブル定義のJSONファイル vim tab1.json { "schema_name": "test", "table_name": "tab1", "table_desc": "テストテーブル1", "cols": [ { "col_name": "col1", "col_type": "bigint", "not_null": "true", "col_desc": "カラム1" }, {…

日時演算

DB

MySQL (8.0.32)https://dev.mysql.com/doc/refman/8.0/ja/date-and-time-functions.html 文字列→日時 SELECT STR_TO_DATE('2023-04-18 21:49:11','%Y-%m-%d %H:%i:%s'); 日時→文字列 SELECT DATE_FORMAT( now(), '%Y-%m-%d %H:%i:%s'); 年select extract(yea…

データ・ウェアハウスにおける集計のためのSQL

DB

rollupcubegrouping setsgroupinggrouping_id MySQL (8.0.32)https://dev.mysql.com/doc/refman/8.0/en/group-by-modifiers.html rollup、grouping、grouping_id -> 使用可能cubeとgrouping sets -> 使用不可★ ※grouping_id関数はgrouping関数と同じ名前 dro…

add_months挙動確認

DB

MySQL (8.0.32)https://blog.peacois.me/archives/171https://dev.mysql.com/doc/refman/8.0/ja/date-and-time-functions.html select date_add('2023-03-31', interval -1 month); +-------------------------------------------+| date_add('2023-03-31', …

テーブルが存在するファイルの確認

DB

MySQL (8.0.32) 基本的にテーブルはインデックスも含めてテーブルごとにibdファイルに格納特にサイズ上限はない模様 Oracle (19c) drop tablespace tbs1 including contents and datafiles; create tablespace tbs1 datafile '/u01/app/oracle/oradata/orcl/…

複数カラム追加削除

DB

MySQL (8.0.32) drop table tab1;create table tab1(col1 int,col2 int);show create table tab1; alter table tab1 add col3 int ;alter table tab1 add ( col4 int );alter table tab1 add ( col5 int,col6 int ); alter table tab1 drop col3 ; カラム追…

group by の数値指定

DB

MySQL (8.0.32) drop table tab1;create table tab1(col1 int);insert into tab1 values(1);insert into tab1 values(1);insert into tab1 values(2);insert into tab1 values(2); select * from tab1;select col1,count(*) from tab1 group by 1;select cou…

PHP+Apache+sqlmap

DB

MySQL (8.0.31) https://qiita.com/shyamahira/items/9f80d16c3436f9dea753https://happyquality.com/2013/02/11/2587.htm 前提:攻撃元と攻撃先は同一サーバ (OS: CentOS7)DB作成済み -- 1. phpインストール yum -y install epel-releaseyum -y install htt…

JSONデータを扱う

DB

MySQL (8.0.31)http://atudc.blogspot.com/2018/09/rdbmsoraclesql-servermysqljson.html -- 1. テストテーブルとデータ作成 drop table tab1; create table tab1 ( col1 bigint, col2 json, constraint tab1pk primary key (col1)); insert into tab1 value…