Chapter 5. Database Administration

Table of Contents

5.1. Overview of Server-Side Programs
5.2. mysqld — The MySQL Server
5.2.1. Option and Variable Reference
5.2.2. Command Options
5.2.3. System Variables
5.2.4. Using System Variables
5.2.5. Status Variables
5.2.6. SQL Modes
5.2.7. The Shutdown Process
5.2.8. Server-Side Help
5.3. The mysqld-max Extended MySQL Server
5.4. MySQL Server Startup Programs
5.4.1. mysqld_safe — MySQL Server Startup Script
5.4.2. mysql.server — MySQL Server Startup Script
5.4.3. mysqld_multi — Manage Multiple MySQL Servers
5.5. Installation-Related Programs
5.5.1. comp_err — Compile MySQL Error Message File
5.5.2. make_win_src_distribution — Create Source Distribution for Windows
5.5.3. mysql_create_system_tables — Generate Statements to Initialize MySQL System Tables
5.5.4. mysql_fix_privilege_tables — Upgrade MySQL System Tables
5.5.5. mysql_install_db — MySQL Data Directory Initialization Script
5.5.6. mysql_secure_installation — Improve MySQL Installation Security
5.5.7. mysql_tzinfo_to_sql — Load the Time Zone Tables
5.6. General Security Issues
5.6.1. General Security Guidelines
5.6.2. Making MySQL Secure Against Attackers
5.6.3. Security-Related mysqld Options
5.6.4. Security Issues with LOAD DATA LOCAL
5.6.5. How to Run MySQL as a Normal User
5.7. The MySQL Access Privilege System
5.7.1. What the Privilege System Does
5.7.2. How the Privilege System Works
5.7.3. Privileges Provided by MySQL
5.7.4. Connecting to the MySQL Server
5.7.5. Access Control, Stage 1: Connection Verification
5.7.6. Access Control, Stage 2: Request Verification
5.7.7. When Privilege Changes Take Effect
5.7.8. Causes of Access denied Errors
5.7.9. Password Hashing as of MySQL 4.1
5.8. MySQL User Account Management
5.8.1. MySQL Usernames and Passwords
5.8.2. Adding New User Accounts to MySQL
5.8.3. Removing User Accounts from MySQL
5.8.4. Limiting Account Resources
5.8.5. Assigning Account Passwords
5.8.6. Keeping Your Password Secure
5.8.7. Using Secure Connections
5.9. Backup and Recovery
5.9.1. Database Backups
5.9.2. Example Backup and Recovery Strategy
5.9.3. Point-in-Time Recovery
5.9.4. Table Maintenance and Crash Recovery
5.10. MySQL Localization and International Usage
5.10.1. The Character Set Used for Data and Sorting
5.10.2. Setting the Error Message Language
5.10.3. Adding a New Character Set
5.10.4. The Character Definition Arrays
5.10.5. String Collating Support
5.10.6. Multi-Byte Character Support
5.10.7. Problems With Character Sets
5.10.8. MySQL Server Time Zone Support
5.10.9. MySQL Server Locale Support
5.11. MySQL Server Logs
5.11.1. The Error Log
5.11.2. The General Query Log
5.11.3. The Update Log
5.11.4. The Binary Log
5.11.5. The Slow Query Log
5.11.6. Server Log Maintenance
5.12. Running Multiple MySQL Servers on the Same Machine
5.12.1. Running Multiple Servers on Windows
5.12.2. Running Multiple Servers on Unix
5.12.3. Using Client Programs in a Multiple-Server Environment
5.13. The MySQL Query Cache
5.13.1. How the Query Cache Operates
5.13.2. Query Cache SELECT Options
5.13.3. Query Cache Configuration
5.13.4. Query Cache Status and Maintenance

End of Product LifecycleActive development and support for MySQL database server versions 3.23, 4.0, and 4.1 has ended. However, for MySQL 4.0 and 4.1, there is still extended support available. For details, see http://www.mysql.com/company/legal/lifecycle/#calendar. According to the MySQL Lifecycle Policy (see http://www.mysql.com/company/legal/lifecycle/#policy), only Security and Severity Level 1 issues will still be fixed for MySQL 4.0 and 4.1. Please consider upgrading to a recent version (MySQL 5.0 or 5.1).

This chapter covers topics that deal with administering a MySQL installation:

5.1. Overview of Server-Side Programs

The MySQL server, mysqld, is the main program that does most of the work in a MySQL installation. The server is accompanied by several related scripts that perform setup operations when you install MySQL or that assist you in starting and stopping the server. This section provides an overview of the server and related programs. The following sections provide more detailed information about each of these programs.

Each MySQL program takes many different options. Most programs provide a --help option that you can use to get a description of the program's different options. For example, try mysqld --help.

You can override default option values for MySQL programs by specifying options on the command line or in an option file. Section 4.3, “Specifying Program Options”.

The following list briefly describes the MySQL server and server-related programs:

There are several other programs that are related to MySQL installation or upgrading:

5.2. mysqld — The MySQL Server

mysqld is the MySQL server. The following discussion covers these MySQL server configuration topics:

  • Startup options that the server supports

  • Server system variables

  • Server status variables

  • How to set the server SQL mode

  • The server shutdown process

Note: Not all storage engines (also known in older versions of MySQL as “table types”) are supported by all MySQL server binaries and configurations. To find out how to determine which storage engines are supported by your MySQL server installation, see Section 13.5.4.8, “SHOW ENGINES Syntax”.

5.2.1. Option and Variable Reference

The following table provides a list of all the command line options, server and status variables applicable within mysqld.

The table lists command line options (Cmd-line), options valid in configuration files (Option file), server system variables (Server Var), and status variables (Status var) in one unified list, with notification of where each option/variable is valid. If a server option set on the command line or in an option file differs from the name of the corresponding server system or status variable, the variable name is noted immediately below the corresponding option. For status variables, the scope of the variable is shown (Scope) as either global, session, or both. Please see the corresponding sections for details on setting and using the options and variables. Where appropriate, a direct link to further information on the item as available.

Note

This table is part of an ongoing process to expand and simplify the information provided on these elements. Further improvements to the table, and corresponding descriptions will be applied over the coming months.

NameCmd-lineOption fileServer VarStatus VarVar ScopeDynamic
abort-slave-event-countYY    
Aborted_clients   Ybothno
Aborted_connects   Ybothno
allow-suspicious-udfsYY    
ansiYY    
autocommitYYY sessionyes
back_logYYY bothno
basedirYYY bothno
bdbYY  bothno
- Variable: have_bdb  Y bothno
bdb-homeYY   no
- Variable: bdb_home  Y  no
bdb-lock-detectYY    
bdb-logdirYY   no
- Variable: bdb_logdir  Y  no
bdb-no-recoverYY    
bdb-no-syncYY    
bdb-shared-dataYY   no
- Variable: bdb_shared_data  Y  no
bdb-tmpdirYY   no
- Variable: bdb_tmpdir  Y  no
bdb_cache_sizeYYY  no
bdb_lock_maxYYY  no
bdb_log_buffer_sizeYYY  no
bdb_max_lockYYY  no
big-tablesYY   yes
- Variable: big_tables  Y  yes
bind-addressYY    
binlog-do-dbYY    
binlog-ignore-dbYY    
Binlog_cache_disk_use   Ybothno
binlog_cache_sizeYYY bothyes
Binlog_cache_use   Ybothno
bootstrapYY    
bulk_insert_buffer_sizeYYY bothyes
Bytes_received   Ybothno
Bytes_sent   Ybothno
character-set-client-handshakeY     
character-set-serverYY  bothyes
- Variable: character_set_server  Y bothyes
character-sets-dirYY  bothno
- Variable: character_sets_dir  Y bothno
character_setY Y  yes
character_set_client  Y bothyes
character_set_connection  Y bothyes
character_set_database  Y bothyes
character_set_results  Y bothyes
character_set_system  Y bothyes
chrootYY    
collation_connectionYYY bothyes
collation_databaseYYY bothyes
collation_serverYYY bothyes
Com_admin_commands   Ybothno
Com_alter_db   Ybothno
Com_alter_table   Ybothno
Com_analyze   Ybothno
Com_backup_table   Ybothno
Com_begin   Ybothno
Com_change_db   Ybothno
Com_change_master   Ybothno
Com_check   Ybothno
Com_checksum   Ybothno
Com_commit   Ybothno
Com_create_db   Ybothno
Com_create_index   Ybothno
Com_create_table   Ybothno
Com_create_user   Ybothno
Com_dealloc_sql   Ybothno
Com_delete   Ybothno
Com_delete_multi   Ybothno
Com_do   Ybothno
Com_drop_db   Ybothno
Com_drop_index   Ybothno
Com_drop_table   Ybothno
Com_drop_user   Ybothno
Com_execute_sql   Ybothno
Com_flush   Ybothno
Com_grant   Ybothno
Com_ha_close   Ybothno
Com_ha_open   Ybothno
Com_ha_read   Ybothno
Com_help   Ybothno
Com_insert   Ybothno
Com_insert_select   Ybothno
Com_kill   Ybothno
Com_load   Ybothno
Com_load_master_data   Ybothno
Com_load_master_table   Ybothno
Com_lock_tables   Ybothno
Com_optimize   Ybothno
Com_preload_keys   Ybothno
Com_prepare_sql   Ybothno
Com_rename_table   Ybothno
Com_repair   Ybothno
Com_replace   Ybothno
Com_replace_select   Ybothno
Com_reset   Ybothno
Com_restore_table   Ybothno
Com_revoke   Ybothno
Com_revoke_all   Ybothno
Com_rollback   Ybothno
Com_savepoint   Ybothno
Com_select   Ybothno
Com_set_option   Ybothno
Com_show_binlog_events   Ybothno
Com_show_binlogs   Ybothno
Com_show_charsets   Ybothno
Com_show_collations   Ybothno
Com_show_column_types   Ybothno
Com_show_create_db   Ybothno
Com_show_create_event   Ybothno
Com_show_create_table   Ybothno
Com_show_databases   Ybothno
Com_show_engine_logs   Ybothno
Com_show_engine_mutex   Ybothno
Com_show_engine_status   Ybothno
Com_show_errors   Ybothno
Com_show_fields   Ybothno
Com_show_grants   Ybothno
Com_show_keys   Ybothno
Com_show_master_status   Ybothno
Com_show_new_master   Ybothno
Com_show_open_tables   Ybothno
Com_show_privileges   Ybothno
Com_show_processlist   Ybothno
Com_show_slave_hosts   Ybothno
Com_show_slave_status   Ybothno
Com_show_status   Ybothno
Com_show_storage_engines   Ybothno
Com_show_tables   Ybothno
Com_show_variables   Ybothno
Com_show_warnings   Ybothno
Com_slave_start   Ybothno
Com_slave_stop   Ybothno
Com_stmt_close   Ybothno
Com_stmt_execute   Ybothno
Com_stmt_fetch   Ybothno
Com_stmt_prepare   Ybothno
Com_stmt_reset   Ybothno
Com_stmt_send_long_data   Ybothno
Com_truncate   Ybothno
Com_unlock_tables   Ybothno
Com_update   Ybothno
Com_update_multi   Ybothno
concurrent-insertYY  bothyes
- Variable: concurrent_insert  Y bothyes
connect_timeoutYYY bothyes
consoleYY    
core-fileYY    
crash_binlog_innodbYY    
Created_tmp_disk_tables   Ybothno
Created_tmp_files   Ybothno
Created_tmp_tables   Ybothno
datadirYYY bothno
date_formatY Y bothyes
datetime_formatY Y bothyes
debugYY    
default-character-setYY    
default-collationY Y  yes
default-storage-engineYY    
default-table-typeYY    
default-time-zoneYY    
- Variable: time_zone      
default_week_formatYYY bothyes
defaults-extra-fileY     
defaults-fileY     
delay-key-writeYY  bothyes
- Variable: delay_key_write  Y bothyes
delayed_insert_limitYYY bothyes
delayed_insert_timeoutYYY bothyes
delayed_queue_sizeYYY bothyes
des-key-fileYYY  no
disconnect-slave-event-countYY    
enable-lockingY     
enable-pstackYY    
error_count   Ysessionyes
exit-infoYY    
expire_logs_daysYYY bothyes
external-lockingYY    
flushYYY bothyes
flush_timeYYY bothyes
foreign_key_checksY Y sessionyes
ft_boolean_syntaxYYY bothyes
ft_max_word_lenYYY bothyes
ft_min_word_lenYYY globalyes
ft_query_expansion_limitYYY bothyes
ft_stopword_fileYYY bothyes
gdbYY    
group_concat_max_lenYYY bothyes
Handler_commit   Ybothno
Handler_delete   Ybothno
Handler_discover   Ybothno
Handler_read_first   Ybothno
Handler_read_key   Ybothno
Handler_read_next   Ybothno
Handler_read_prev   Ybothno
Handler_read_rnd   Ybothno
Handler_read_rnd_next   Ybothno
Handler_rollback   Ybothno
Handler_update   Ybothno
Handler_write   Ybothno
have_archive   Ybothno
have_blackhole_engine   Ybothno
have_compress   Ybothno
have_crypt   Ybothno
have_csv   Ybothno
have_example_engine   Ybothno
have_geometry   Ybothno
have_innodb   Ybothno
have_isam   Ybothno
have_merge_engine   Ybothno
have_ndbcluster   Ybothno
have_openssl   Ybothno
have_query_cache   Ybothno
have_raid   Ybothno
have_rtree_keys   Ybothno
have_symlink   Ybothno
helpY     
identityYYY sessionyes
init-fileYY  bothno
- Variable: init_file  Y bothno
init_connectYYY bothno
init_slaveYYY bothno
innodbYY    
innodb_additional_mem_pool_sizeYYY bothno
innodb_autoextend_incrementYYY bothyes
innodb_buffer_pool_awe_mem_mbYYY bothno
innodb_buffer_pool_sizeYYY bothno
innodb_data_file_pathYYY bothno
innodb_data_home_dirYYY bothno
innodb_fast_shutdownYYY bothno
innodb_file_io_threadsYYY bothno
innodb_file_per_tableYYY bothno
innodb_flush_log_at_trx_commitYYY bothno
innodb_flush_methodYYY bothno
innodb_force_recoveryYYY bothno
innodb_lock_wait_timeoutYYY bothno
innodb_locks_unsafe_for_binlogYYY bothno
innodb_log_arch_dirYYY bothno
innodb_log_archiveYYY bothno
innodb_log_buffer_sizeYYY bothno
innodb_log_file_sizeYYY bothno
innodb_log_files_in_groupYYY bothno
innodb_log_group_home_dirYYY bothno
innodb_max_dirty_pages_pctYYY bothyes
innodb_max_purge_lagYYY bothyes
innodb_mirrored_log_groupsYYY bothno
innodb_open_filesYYY bothno
innodb_status_fileYYY  no
innodb_table_locksYYY bothyes
innodb_thread_concurrencyYYY bothyes
insert_idYYY sessionyes
interactive_timeoutYYY bothyes
isamYYY  yes
join_buffer_sizeYYY bothyes
Key_blocks_not_flushed   Ybothno
Key_blocks_unused   Ybothno
Key_blocks_used   Ybothno
key_buffer_sizeYYY bothyes
key_cache_age_thresholdYYY bothno
key_cache_block_sizeYYY bothno
key_cache_division_limitYYY bothno
Key_read_requests   Ybothno
Key_reads   Ybothno
Key_write_requests   Ybothno
Key_writes   Ybothno
languageYYY bothno
last_insert_idYYY sessionyes
lc_time_names  Y bothyes
license  Y bothno
local-infileYY  globalyes
- Variable: local_infile  Y globalyes
logYYY bothno
log-binYY  bothno
- Variable: log_bin  Y bothno
log-bin-indexYYY  no
log-errorYY  bothno
- Variable: log_error  Y bothno
log-isamYYY  no
log-long-formatYY    
log-short-formatYY    
log-slave-updatesYY  bothno
- Variable: log_slave_updates  Y bothno
log-slow-admin-statementsYY    
log-slow-queriesYY  bothno
- Variable: log_slow_queries  Y bothno
log-updateY     
log-warningsYY  bothyes
- Variable: log_warnings  Y bothyes
long_query_timeYYY bothyes
low-priority-updatesYY   yes
- Variable: low_priority_updates  Y  yes
lower_case_table_namesYYY  no
master-connect-retryYY    
master-hostYY    
master-info-fileYY    
master-passwordYY    
master-portYY    
master-retry-countYY    
master-sslYY    
master-ssl-caYY    
master-ssl-capathYY    
master-ssl-certYY    
master-ssl-cipherYY    
master-ssl-keyYY    
master-userYY    
max-binlog-dump-eventsYY    
max_allowed_packetYYY bothyes
max_binlog_cache_sizeYYY globalyes
max_binlog_sizeYYY globalyes
max_connect_errorsYYY globalyes
max_connectionsYYY globalyes
max_delayed_threadsYYY globalyes
max_error_countYYY bothyes
max_heap_table_sizeYYY bothyes
max_insert_delayed_threads  Y globalyes
max_join_sizeYYY bothyes
max_length_for_sort_dataYYY  yes
max_prepared_stmt_countYYY globalyes
max_relay_log_sizeYYY globalyes
max_seeks_for_keyYYY bothyes
max_sort_lengthYYY bothyes
max_tmp_tablesYYY bothyes
Max_used_connections   Ybothno
max_user_connectionsYYY bothyes
max_write_lock_countYYY globalyes
maximum-query_cache_sizeY Y  no
memlockYY  bothno
- Variable: locked_in_memory  Y bothno
mergeYYY  no
myisam-recoverYYY  no
myisam_block_sizeYYY  yes
myisam_data_pointer_sizeYYY globalyes
myisam_max_extra_sort_file_sizeYYY  yes
myisam_max_sort_file_sizeYYY bothyes
myisam_repair_threadsYYY bothyes
myisam_sort_buffer_sizeYYY bothyes
myisam_stats_methodYYY bothyes
named_pipeYY    
ndb_autoincrement_prefetch_sz  Y  yes
ndb_cache_check_time YY  yes
ndb_force_sendYYY  yes
ndb_index_stat_cache_entriesYY    
ndb_index_stat_enableYY    
ndb_index_stat_update_freqYY    
ndb_report_thresh_binlog_epoch_slipYY    
ndb_report_thresh_binlog_mem_usageYY    
ndb_use_exact_count  Y  yes
ndb_use_transactionsYY    
ndbclusterYYY  yes
net_buffer_lengthYYY bothyes
net_read_timeoutYYY bothyes
net_retry_countYYY bothyes
net_write_timeoutYYY bothyes
newYYY  no
no-defaultsY     
Not_flushed_delayed_rows   Ybothno
old-passwordsYY   yes
- Variable: old_passwords  Y  yes
old-protocolYY    
Open_files   Ybothno
open_files_limitYYY  no
Open_streams   Ybothno
Open_tables   Ybothno
Opened_tables   Ybothno
pid-fileYYY  no
portYYY  no
preload_buffer_sizeYYY bothyes
prepared_stmt_count  YYbothno
print-defaultsY     
protocol_version  Y bothno
Qcache_free_blocks   Ybothno
Qcache_free_memory   Ybothno
Qcache_hits   Ybothno
Qcache_inserts   Ybothno
Qcache_lowmem_prunes   Ybothno
Qcache_not_cached   Ybothno
Qcache_queries_in_cache   Ybothno
Qcache_total_blocks   Ybothno
query_alloc_block_sizeYYY bothyes
query_cache_limitYYY bothyes
query_cache_min_res_unitYYY bothyes
query_cache_sizeYYY bothyes
query_cache_typeYYY bothyes
query_cache_wlock_invalidateYYY bothyes
query_prealloc_sizeYYY bothyes
Questions   Ybothno
range_alloc_block_sizeYYY bothyes
read_buffer_sizeYYY bothyes
read_onlyYYY bothyes
read_rnd_buffer_sizeYYY bothyes
relay-logYYY  no
relay-log-indexYY    
relay-log-info-fileYY    
relay_log_purgeYYY bothno
relay_log_space_limitYYY bothno
replicate-do-dbYY    
replicate-do-tableYY    
replicate-ignore-dbYY    
replicate-ignore-tableYY    
replicate-rewrite-dbYY    
replicate-same-server-idYY    
replicate-wild-do-tableYY    
replicate-wild-ignore-tableYY    
report-hostYY    
report-passwordYYY  no
report-portYY