diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index c3d7d5ac4eb..60010183d32 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -752,6 +752,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 5edb8fb754b..697e55945ef 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -639,6 +639,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 1961a5b6f88..9b47de05c86 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -452,7 +452,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 2842d2e8b2f..1f65b50b98d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2636,9 +2636,15 @@ static int init_common_variables(const char *conf_file_name, int argc, mysql_slow_log.init_pthread_objects(); 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 load_defaults(conf_file_name, groups, &argc, &argv); @@ -3087,7 +3093,7 @@ server."); if (opt_error_log) { if (!log_error_file_ptr[0]) - fn_format(log_error_file, glob_hostname, mysql_data_home, ".err", + fn_format(log_error_file, pidfile_name, mysql_data_home, ".err", MY_REPLACE_EXT); /* replace '.' by '.err', bug#4997 */ else fn_format(log_error_file, log_error_file_ptr, mysql_data_home, ".err", diff --git a/sql/set_var.cc b/sql/set_var.cc index 29917f2f83c..b3a9305132a 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -590,6 +590,10 @@ sys_var_readonly sys_have_innodb("have_innodb", OPT_GLOBAL, /* Global read-only variable describing server license */ sys_var_const_str sys_license("license", STRINGIFY_ARG(LICENSE)); +/* Global read-only variable containing hostname */ +sys_var_const_str sys_hostname("hostname", glob_hostname); + + /* List of all variables for initialisation and storage in hash @@ -642,6 +646,7 @@ sys_var *sys_variables[]= &sys_foreign_key_checks, &sys_group_concat_max_len, &sys_have_innodb, + &sys_hostname, &sys_identity, &sys_init_connect, &sys_init_slave, @@ -874,6 +879,7 @@ struct show_var_st init_vars[]= { {"have_raid", (char*) &have_raid, SHOW_HAVE}, {"have_rtree_keys", (char*) &have_rtree_keys, SHOW_HAVE}, {"have_symlink", (char*) &have_symlink, SHOW_HAVE}, + {sys_hostname.name, (char*) &sys_hostname, SHOW_SYS}, {"init_connect", (char*) &sys_init_connect, SHOW_SYS}, {"init_file", (char*) &opt_init_file, SHOW_CHAR_PTR}, {"init_slave", (char*) &sys_init_slave, SHOW_SYS},