Skip to content

Commit c01678b

Browse files
Added option --read-only (Thanks to Markus Benning)
1 parent a46c0a7 commit c01678b

6 files changed

Lines changed: 29 additions & 9 deletions

File tree

myisam/myisamchk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ static const char *set_charset_name;
4545
static CHARSET_INFO *set_charset;
4646
static long opt_myisam_block_size;
4747
static const char *my_progname_short;
48+
static int stopwords_inited= 0;
4849

4950
static const char *type_names[]=
5051
{ "?","char","binary", "short", "long", "float",
@@ -861,7 +862,7 @@ static int myisamchk(MI_CHECK *param, my_string filename)
861862
}
862863
else
863864
{
864-
if (share->fulltext_index)
865+
if (share->fulltext_index && !stopwords_inited++)
865866
ft_init_stopwords();
866867

867868
if (!(param->testflag & T_READONLY))

sql/init.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,11 @@ void unireg_init(ulong options)
3838
init_my_atof(); /* use our atof */
3939
#endif
4040
my_abort_hook=unireg_abort; /* Abort with close of databases */
41-
f_fyllchar=' '; /* Input fill char */
4241

4342
VOID(strmov(reg_ext,".frm"));
4443
for (i=0 ; i < 6 ; i++) // YYMMDDHHMMSS
4544
dayord.pos[i]=i;
4645
specialflag=SPECIAL_SAME_DB_NAME;
47-
blob_newline='^'; /* Convert newline in blobs to this */
4846
/* Make a tab of powers of 10 */
4947
for (i=0,nr=1.0; i < array_elements(log_10) ; i++)
5048
{ /* It's used by filesort... */

sql/mysql_priv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,6 @@ extern char language[LIBLEN],reg_ext[FN_EXTLEN];
627627
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
628628
extern char pidfile_name[FN_REFLEN], time_zone[30], *opt_init_file;
629629
extern char log_error_file[FN_REFLEN];
630-
extern char blob_newline;
631630
extern double log_10[32];
632631
extern ulonglong keybuff_size;
633632
extern ulong refresh_version,flush_version, thread_id,query_id,opened_tables;
@@ -675,8 +674,8 @@ extern uint volatile thread_count, thread_running, global_read_lock;
675674
extern my_bool opt_sql_bin_update, opt_safe_user_create, opt_no_mix_types;
676675
extern my_bool opt_safe_show_db, opt_local_infile, lower_case_table_names;
677676
extern my_bool opt_slave_compressed_protocol, use_temp_pool;
677+
extern my_bool opt_readonly;
678678
extern my_bool opt_enable_named_pipe;
679-
extern char f_fyllchar;
680679

681680
extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log;
682681
extern FILE *bootstrap_file;

sql/mysqld.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ my_bool opt_enable_named_pipe= 0;
289289
my_bool opt_local_infile, opt_external_locking, opt_slave_compressed_protocol;
290290
uint delay_key_write_options= (uint) DELAY_KEY_WRITE_ON;
291291

292-
static bool opt_do_pstack = 0;
292+
static my_bool opt_do_pstack = 0;
293293
static ulong opt_specialflag=SPECIAL_ENGLISH;
294294

295295
static ulong opt_myisam_block_size;
@@ -306,6 +306,7 @@ my_bool opt_safe_user_create = 0, opt_no_mix_types = 0;
306306
my_bool lower_case_table_names, opt_old_rpl_compat;
307307
my_bool opt_show_slave_auth_info, opt_sql_bin_update = 0;
308308
my_bool opt_log_slave_updates= 0, opt_console= 0;
309+
my_bool opt_readonly = 0;
309310

310311
volatile bool mqh_used = 0;
311312
FILE *bootstrap_file=0;
@@ -376,7 +377,7 @@ const char *localhost=LOCAL_HOST;
376377
const char *delayed_user="DELAYED";
377378
uint master_port = MYSQL_PORT, master_connect_retry = 60;
378379
uint report_port = MYSQL_PORT;
379-
bool master_ssl = 0;
380+
my_bool master_ssl = 0;
380381

381382
ulong master_retry_count=0;
382383
ulong bytes_sent = 0L, bytes_received = 0L;
@@ -404,8 +405,7 @@ ulong slow_launch_threads = 0;
404405
char mysql_real_data_home[FN_REFLEN],
405406
language[LIBLEN],reg_ext[FN_EXTLEN],
406407
mysql_charsets_dir[FN_REFLEN], *charsets_list,
407-
blob_newline,f_fyllchar,max_sort_char,*mysqld_user,*mysqld_chroot,
408-
*opt_init_file;
408+
max_sort_char,*mysqld_user,*mysqld_chroot, *opt_init_file;
409409
char *language_ptr= language;
410410
char mysql_data_home_buff[2], *mysql_data_home=mysql_real_data_home;
411411
#ifndef EMBEDDED_LIBRARY
@@ -3143,6 +3143,7 @@ enum options {
31433143
OPT_QUERY_CACHE_TYPE, OPT_RECORD_BUFFER,
31443144
OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT,
31453145
OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
3146+
OPT_READONLY,
31463147
OPT_SORT_BUFFER, OPT_TABLE_CACHE,
31473148
OPT_THREAD_CONCURRENCY, OPT_THREAD_CACHE_SIZE,
31483149
OPT_TMP_TABLE_SIZE, OPT_THREAD_STACK,
@@ -3927,6 +3928,11 @@ replicating a LOAD DATA INFILE command",
39273928
"Number of seconds to wait for more data from a master/slave connection before aborting the read.",
39283929
(gptr*) &slave_net_timeout, (gptr*) &slave_net_timeout, 0,
39293930
GET_ULONG, REQUIRED_ARG, SLAVE_NET_TIMEOUT, 1, LONG_TIMEOUT, 0, 1, 0},
3931+
{"read-only", OPT_READONLY,
3932+
"Make all tables readonly, with the expections for replications (slave) threads and users with the SUPER privilege",
3933+
(gptr*) &opt_readonly,
3934+
(gptr*) &opt_readonly,
3935+
0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 1, 0},
39303936
{"slow_launch_time", OPT_SLOW_LAUNCH_TIME,
39313937
"If creating the thread takes longer than this value (in seconds), the Slow_launch_threads counter will be incremented.",
39323938
(gptr*) &slow_launch_time, (gptr*) &slow_launch_time, 0, GET_ULONG,

sql/set_var.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ sys_var_bool_ptr sys_slave_compressed_protocol("slave_compressed_protocol",
204204
&opt_slave_compressed_protocol);
205205
sys_var_long_ptr sys_slave_net_timeout("slave_net_timeout",
206206
&slave_net_timeout);
207+
sys_var_bool_ptr sys_readonly("read_only",
208+
&opt_readonly);
207209
sys_var_long_ptr sys_slow_launch_time("slow_launch_time",
208210
&slow_launch_time);
209211
sys_var_thd_ulong sys_sort_buffer("sort_buffer_size",
@@ -375,6 +377,7 @@ sys_var *sys_variables[]=
375377
&sys_slave_compressed_protocol,
376378
&sys_slave_net_timeout,
377379
&sys_slave_skip_counter,
380+
&sys_readonly,
378381
&sys_slow_launch_time,
379382
&sys_sort_buffer,
380383
&sys_sql_big_tables,
@@ -522,6 +525,7 @@ struct show_var_st init_vars[]= {
522525
#endif /* HAVE_QUERY_CACHE */
523526
{sys_server_id.name, (char*) &sys_server_id, SHOW_SYS},
524527
{sys_slave_net_timeout.name,(char*) &sys_slave_net_timeout, SHOW_SYS},
528+
{sys_readonly.name, (char*) &sys_readonly, SHOW_SYS},
525529
{"skip_external_locking", (char*) &my_disable_locking, SHOW_MY_BOOL},
526530
{"skip_networking", (char*) &opt_disable_networking, SHOW_BOOL},
527531
{"skip_show_database", (char*) &opt_skip_show_db, SHOW_BOOL},

sql/sql_parse.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,18 @@ mysql_execute_command(void)
13291329
(table_rules_on && tables && thd->slave_thread &&
13301330
!tables_ok(thd,tables)))
13311331
DBUG_VOID_RETURN;
1332+
1333+
/*
1334+
When option readonly is set deny operations which change tables.
1335+
Except for the replication thread and the 'super' users.
1336+
*/
1337+
if (opt_readonly &&
1338+
!(thd->slave_thread || (thd->master_access & SUPER_ACL)) &&
1339+
(uc_update_queries[lex->sql_command] > 0))
1340+
{
1341+
send_error(&thd->net,ER_CANT_UPDATE_WITH_READLOCK);
1342+
DBUG_VOID_RETURN;
1343+
}
13321344

13331345
statistic_increment(com_stat[lex->sql_command],&LOCK_status);
13341346
switch (lex->sql_command) {

0 commit comments

Comments
 (0)