我正在运行以下sed
命令来编辑具有特定参数的my.cnf
。然而,它得到了我需要检查和修改的最后两个值,并且无法执行它们,尽管语法与之前修改的值没有区别。
sed -i s/".*old_passwords=[0-9]*"/"# old_passwords=1"/g /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/innodb_buffer_pool_size=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\old_passwords=/ainnodb_buffer_pool_size=5G' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/innodb_additional_mem_pool_size=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\innodb_buffer_pool_size=/ainnodb_additional_mem_pool_size=100M' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/innodb_file_per_table/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\innodb_additional_mem_pool_size=/ainnodb_file_per_table' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/innodb_log_file_size=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\innodb_file_per_table/ainnodb_log_file_size=125M' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/innodb_flush_log_at_trx_commit=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\innodb_log_file_size=/ainnodb_flush_log_at_trx_commit=1' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/max_connections=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\innodb_flush_log_at_trx_commit=/amax_connections=500' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/query_cache_size=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\max_connections=/aquery_cache_size=256M' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/query_cache_type=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\query_cache_size=/aquery_cache_type=0' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/query_cache_limit=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\query_cache_type=/aquery_cache_limit=1M' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/table_cache=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\query_cache_limit=/atable_cache=256' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/thread_cache_size=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\table_cache=/athread_cache_size=4' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/innodb_flush_method=/d' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
sed -i '/\thread_cache_size=/ainnodb_flush_method=O_DIRECT' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf
我需要检查和设置的最后两个值是:
thread_cache_size=4
innodb_flush_method=O_DIRECT
我在一个非常标准的my.cnf文件中运行它:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
max_connections=500
innodb_buffer_pool_size=256M
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
生成的文件如下所示:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
# old_passwords=1
innodb_buffer_pool_size=5G
innodb_additional_mem_pool_size=100M
innodb_file_per_table
innodb_log_file_size=125M
innodb_flush_log_at_trx_commit=1
max_connections=500
query_cache_size=256M
query_cache_type=0
query_cache_limit=1M
table_cache=256
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
我已经尝试删除thread_cache_size =命令并替换为其他的,随机的,更新的但仍然失败,好像对于my.cnf文件的编辑距离有一些限制。
答案 0 :(得分:1)
\t
在sed中有特殊含义:它代表制表符。因此,/\table_cache/
永远不会匹配。
答案 1 :(得分:0)
从shell的角度来看,使用这个sed并不是更好(并且最好将t文件用作动作列表)
sed -i 's/".*old_passwords=[0-9]*"/"# old_passwords=1"/g
/innodb_buffer_pool_size=/d
/\old_passwords=/ainnodb_buffer_pool_size=5G
/innodb_additional_mem_pool_size=/d
/\innodb_buffer_pool_size=/ainnodb_additional_mem_pool_size=100M
/innodb_file_per_table/d
/\innodb_additional_mem_pool_size=/ainnodb_file_per_table
/innodb_log_file_size=/d
/\innodb_file_per_table/ainnodb_log_file_size=125M
/innodb_flush_log_at_trx_commit=/d
/\innodb_log_file_size=/ainnodb_flush_log_at_trx_commit=1
/max_connections=/d
/\innodb_flush_log_at_trx_commit=/amax_connections=500
/query_cache_size=/d
/\max_connections=/aquery_cache_size=256M
/query_cache_type=/d
/\query_cache_size=/aquery_cache_type=0
/query_cache_limit=/d
/\query_cache_type=/aquery_cache_limit=1M
/table_cache=/d
/\query_cache_limit=/atable_cache=256
/thread_cache_size=/d
/\table_cache=/athread_cache_size=4
/innodb_flush_method=/d
/\\thread_cache_size=/ainnodb_flush_method=O_DIRECT' /home/david/systems/zabbix/2.2/2.2.5/confs/my.cnf