diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index ec4c7c9b2aa..cfe2f04c94d 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -903,6 +903,14 @@ select @@&; ERROR 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 '&' at line 1 select @@@; ERROR 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 '@' at line 1 +select @@hostname; +@@hostname +# +set @@hostname= "anothername"; +ERROR HY000: Variable 'hostname' is a read only variable +show variables like 'hostname'; +Variable_name Value +hostname # End of 5.0 tests set global binlog_cache_size =@my_binlog_cache_size; set global connect_timeout =@my_connect_timeout; diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 4f91b75ced1..16fcae380b2 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -689,6 +689,17 @@ select @@&; --error ER_PARSE_ERROR select @@@; +# +# Bug#20166 mysql-test-run.pl does not test system privilege tables creation +# +# Don't actually output, since it depends on the system +--replace_column 1 # +select @@hostname; +--error 1238 +set @@hostname= "anothername"; +--replace_column 2 # +show variables like 'hostname'; + --echo End of 5.0 tests # This is at the very after the versioned tests, since it involves doing diff --git a/sql/log.cc b/sql/log.cc index 5e9ebfcb902..72baecaf7a6 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2297,7 +2297,7 @@ const char *MYSQL_LOG::generate_name(const char *log_name, TODO: The following should be using fn_format(); We just need to first change fn_format() to cut the file name if it's too long. */ - strmake(buff, glob_hostname, FN_REFLEN - 5); + strmake(buff, pidfile_name, FN_REFLEN - 5); strmov(fn_ext(buff), suffix); return (const char *)buff; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index cbba3a93458..4ffdc8a75f6 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2677,9 +2677,15 @@ static int init_common_variables(const char *conf_file_name, int argc, */ mysql_bin_log.init_pthread_objects(); - if (gethostname(glob_hostname,sizeof(glob_hostname)-4) < 0) - strmov(glob_hostname,"mysql"); - strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5); + if (gethostname(glob_hostname,sizeof(glob_hostname)) < 0) + { + strmake(glob_hostname, STRING_WITH_LEN("localhost")); + sql_print_warning("gethostname failed, using '%s' as hostname", + glob_hostname); + strmake(pidfile_name, STRING_WITH_LEN("mysql")); + } + else + strmake(pidfile_name, glob_hostname, sizeof(pidfile_name)-5); strmov(fn_ext(pidfile_name),".pid"); // Add proper extension /* diff --git a/sql/set_var.cc b/sql/set_var.cc index 8a31cdf32ce..1e41618e08d 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -655,6 +655,10 @@ sys_var_thd_time_zone sys_time_zone("time_zone"); /* Read only variables */ +/* Global read-only variable containing hostname */ +sys_var_const_str sys_hostname("hostname", glob_hostname); + + sys_var_have_variable sys_have_compress("have_compress", &have_compress); sys_var_have_variable sys_have_crypt("have_crypt", &have_crypt); sys_var_have_variable sys_have_csv_db("have_csv", &have_csv_db); @@ -779,6 +783,7 @@ SHOW_VAR init_vars[]= { {sys_var_general_log.name, (char*) &opt_log, SHOW_MY_BOOL}, {sys_var_general_log_path.name, (char*) &sys_var_general_log_path, SHOW_SYS}, {sys_group_concat_max_len.name, (char*) &sys_group_concat_max_len, SHOW_SYS}, + {sys_hostname.name, (char*) &sys_hostname, SHOW_SYS}, {sys_have_compress.name, (char*) &have_compress, SHOW_HAVE}, {sys_have_crypt.name, (char*) &have_crypt, SHOW_HAVE}, {sys_have_csv_db.name, (char*) &have_csv_db, SHOW_HAVE},