MySQLはバージョン8.
sql_require_primary_keyについて
sql_
mysql> SELECT @@sql_require_primary_key; +---------------------------+ | @@sql_require_primary_key | +---------------------------+ | 1 | +---------------------------+ 1 row in set (0.00 sec) mysql> SHOW VARIABLES LIKE 'sql_require_primary_key'; +-------------------------+-------+ | Variable_name | Value | +-------------------------+-------+ | sql_require_primary_key | ON | +-------------------------+-------+ 1 row in set (0.08 sec)
sql_
mysql> CREATE TABLE no_pktable ( id int, name varchar(256) ); ERROR 3750 (HY000): Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
もし、
ALTER TABLE構文とCREATE TEMPORARY TABLE構文
sql_
- ALTER TABLE構文で主キーを削除する
- CREATE TEMPORARY TABLE構文で一時テーブルを作成する
ALTER TABLE構文で主キーを削除しようとした場合でも、
また、
対応のストレージエンジン
対応するストレージエンジンですが、
各テーブルで利用しているストレージエンジンはinfomation_
mysql> CREATE TABLE csv_pktable(id int primary_key, name varchar(256)) ENGINE=CSV; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'primary_key, name varchar(256)) ENGINE=CSV' at line 1 mysql> CREATE TABLE csv_pktable(id int , name varchar(256)) ENGINE=CSV; ERROR 3750 (HY000): Unable to create or change a table without a primary key, when the system variable 'sql_require_primary_key' is set. Add a primary key to the table or unset this variable to avoid this message. Note that tables without a primary key can cause performance problems in row-based replication, so please consult your DBA before changing this setting.
レプリケーション
sql_
マスター側で生成されたバイナリログを確認すると、/*!80013 SET @@session.
というイベントを確認することができます。これはMySQLのバージョンが8.
コメントを使ったMySQLバージョンによる実行については、
ただし、
# at 714
#191029 9:28:06 server id 39355 end_log_pos 859 CRC32 0xc904510f Query thread_id=13 exec_time=0 error_code=0 Xid = 48
SET TIMESTAMP=1572308886/*!*/;
/*!80013 SET @@session.sql_require_primary_key=0*//*!*/;
CREATE TABLE pktable(id int primary key, name varchar(256))
/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
まとめ
今回はsql_