data_dir=/usr/local/data/clickhouse
mkdir -p $data_dir
####复制数据目录到新的路径
cp /var/lib/clickhouse/data -r $data_dir
cp /var/lib/clickhouse/flags -r $data_dir
cp /var/lib/clickhouse/format_schemas -r $data_dir
cp /var/lib/clickhouse/metadata -r $data_dir
cp /var/lib/clickhouse/preprocessed_configs -r $data_dir
cp /var/lib/clickhouse/tmp -r $data_dir
cp /var/lib/clickhouse/user_files -r $data_dir
####删除原来文件夹的文件
rm -rf /var/lib/clickhouse/data
rm -rf /var/lib/clickhouse/flags
rm -rf /var/lib/clickhouse/format_schemas
rm -rf /var/lib/clickhouse/metadata
rm -rf /var/lib/clickhouse/preprocessed_configs
rm -rf /var/lib/clickhouse/tmp
rm -rf /var/lib/clickhouse/user_files
####建立软连接
ln -s $data_dir/data /var/lib/clickhouse
ln -s $data_dir/flags /var/lib/clickhouse
ln -s $data_dir/format_schemas /var/lib/clickhouse
ln -s $data_dir/metadata /var/lib/clickhouse
ln -s $data_dir/preprocessed_configs /var/lib/clickhouse
ln -s $data_dir/tmp /var/lib/clickhouse
ln -s $data_dir/user_files /var/lib/clickhouse
####给新的路径添加权限
chown -R clickhouse.clickhouse $data_dir
####重启clickhouse
sudo /etc/init.d/clickhouse-server restart