前言
书读百遍,其义自现。大家都知道,但是现在的社会真的很浮躁,又有多少人可以静下来看看书呢?!!只要一有问题就是百度,Google...实际上,书上写的很清楚,所有的解决方法都在书中,对于一个产品的了解,又有谁比编译出他的人更清楚呢!
写给自己,仅以自省!
参考资料
MySQL官方手册5.1
MySQL程序概述:
mysqld是MySQL服务器
mysqld_safe、mysql.server是服务器启动脚本
mysql_install_db初始化数据目录和初始数据库
访问服务器的客户程序
mysql是一个命令行客户程序,用于交互式或以批处理模式执行SQL语句。
mysqladmin是用于管理功能的客户程序。
mysqldump负责数据库备份。
声明环境变量(编译安装)
echo ‘export PATH=/application/mysql/sbin:$PATH‘ >/etc/profile
mysql使用-e选项在shell命令行下执行SQL语句
shell> mysql -u root -p -e "show databases;"
shell> mysql -u root -p -e "SELECT User,Host FROM mysql.User;"
MySQL选项详解
/etc/my.cnf==>全局选项,就是启动选项
任何可以在运行MySQL程序时在命令行给出的长选项也可以在选项文件中给出。
在选项文件中指定选项的语法类似于命令行语法,例外的是要忽略掉两个破折号。
如果你有一个源代码分发,可以从support-file目录中找到名为my-xxxx.cnf的示例选项文件。
my-small.cnf默认配置:
[root@web support-files]# cat my-small.cnf # Example MySQL config file for small systems. # # This is for a system with little memory (<= 64M) where MySQL is only used # from time to time and it‘s important that the mysqld daemon # doesn‘t use much resources. # # MySQL programs look for option files in a set of # locations which depend on the deployment platform. # You can copy this option file to one of those # locations. For information about these locations, see: # http://dev.mysql.com/doc/mysql/en/option-files.html # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] #password = your_password port = 3306 socket = /application/mysql5.1.72/tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 socket = /application/mysql5.1.72/tmp/mysql.sock skip-locking key_buffer_size = 16K max_allowed_packet = 1M table_open_cache = 4 sort_buffer_size = 64K read_buffer_size = 256K read_rnd_buffer_size = 256K net_buffer_length = 2K thread_stack = 128K # Don‘t listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (using the "enable-named-pipe" option) will render mysqld useless! # #skip-networking server-id = 1 # Uncomment the following if you want to log updates #log-bin=mysql-bin # binary logging format - mixed recommended #binlog_format=mixed # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /application/mysql5.1.72/data #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = /application/mysql5.1.72/data # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M #innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M [mysqlhotcopy] interactive-timeout
修改选项:
shell> mysql --max_allowed_packet=16M 允许通信的最大长度
[mysql]
max_allowed_packet=16M
优先级:
MySQL程序首先检查环境变量-->选项文件-->命令行来确定给出了哪些选项。
如果多次指定一个选项,最后出现的选项占先。这说明环境变量具有最低的优先级,命令行选项具有最高优先级。
命令 | 模块 |
mysqld | 从[mysqld]和[server]组读取选项 |
mysqld_safe | 从[mysqld]、[server]、[mysqld_safe]和[safe_mysqld]组读取选项 |
mysql.server | 从 [mysqld]和[mysql.server]组读取选项。 |
服务器端脚本
--mysqld_safe
服务器启动脚本。如果mysqld-max存在,mysqld_safe试图启动它,否则启动mysqld。
mysqld_safe从选项文件的[mysqld]、[server]和[mysqld_safe]部分读取所有选项。
一般情况,你不应编辑mysqld_safe脚本。相反,应使用命令行选项或my.cnf选项文件的[mysqld_safe]部分的
选项来配置mysqld_safe。一般不需要编辑mysqld_safe来正确启动服务器。但是,如果你编辑,
将来升级MySQL后会覆盖你修改的mysqld_safe版本,因此你应对你修改的版本进行备份以便将来重装。
--mysql.server
服务器启动脚本。该脚本用于使用包含为特定级别的运行启动服务的脚本的运行目录的系统。它调用mysqld_safe来启动MySQL服务器。
mysql.server位于MySQL源码树MySQL安装目录下的support-files目录中。
如果你使用Linux 服务器RPM软件包(MySQL-server-VERSION.rpm),mysql.server脚本将安装到/etc/init.d目录下,名为mysqld。
mysql.server从 [mysql.server]和选项文件的[mysqld]部分读取选项。
--mysql_install_db
该脚本用默认权限创建MySQL授权表。通常只是在系统上首次安装MySQL时执行一次。
选项修改参考
--在线临时修改
+------------------+-------+ | Variable_name | Value | +------------------+-------+ | sort_buffer_size | 65536 | +------------------+-------+ 1 row in set (0.00 sec) mysql> SET GLOBAL sort_buffer_size = 10 * 1024 * 1024; mysql> \q Bye ... mysql> show variables like ‘sort_%‘; +------------------+----------+ | Variable_name | Value | +------------------+----------+ | sort_buffer_size | 10485760 | +------------------+----------+ 1 row in set (0.00 sec)
--可写入my.conf内
[mysqld] sort_buffer_size = 10 * 1024 * 1024
mysql> SHOW VARIABLES;查看系统变量及其值
mysql> show variables like ‘binlog_%‘; +-----------------------------------------+-----------+ | Variable_name | Value | +-----------------------------------------+-----------+ | binlog_cache_size | 32768 | | binlog_direct_non_transactional_updates | OFF | | binlog_format | STATEMENT | | binlog_stmt_cache_size | 32768 | +-----------------------------------------+-----------+ 4 rows in set (0.00 sec)
补充:binlog_cache_size
在事务过程中容纳二进制日志SQL语句的缓存大小。二进制日志缓存是服务器支持事务存储引擎并且服务器启用了二进制日志(--log-bin选项)的前提下为每个客户端分配的内存。如果你经常使用大的,多语句事务,你可以增加该值以获得更有的性能。Binlog_cache_use和Binlog_cache_disk_use状态变量可以用来调整该变量的大小。
本文出自 “挨刀客” 博客,请务必保留此出处http://chboy.blog.51cto.com/9959876/1707410
原文地址:http://chboy.blog.51cto.com/9959876/1707410