工作常用的linux/mysql/php/工具命令

时间:2024-07-18 12:04:57

工作常用的linux/mysql/php/工具命令:

1. tar备份目录

tar zcvf ****.tar.gz ****/

tar 备份跳过目录

tar --exclude=test1

3. scp 目录

scp -rp *** root@B_ip:***/

4. 新建一个数据库账户

GRANT ALL PRIVILEGES ON test.* TO 'test'@'ip' IDENTIFIED BY
'******';

该ip 为允许访问该数据库的服务器ip

5. 清除.svn 目录

# find ./ -type d -name ".svn" -exec rm -fR {} \;

6. 修改目录、文件权限和用户组

find ./ -type d -exec chmod -R 755 {} \;————目录755

find ./ -type f -exec chmod -R 644 {} \;————文件644

find ./ -type f -exec chown root:nginx {} \;

find ./ -type d -exec chown root:nginx {} \;

7. yum、rpm 安装软件

yum -y install 包名(支持*) :自动选择y,全自动

yum install 包名(支持*) :手动选择y or n

yum remove 包名(不支持*)

rpm -ivh 包名(支持*):安装rpm包

rpm -e 包名(不支持*):卸载rpm包

8. 挂载存储 nfs

mount -t nfs -o rw,sync,noatime 192.168.0.200:/test/test/www
/data/www/test

9. 卸载存储

umount /data/www/test

10. 卸载存储失败报错 ———— umount: /data/www/test: device is
busy

fuser -km /data/www/test

再执行

umount /data/www/test

11. 清除数据库表外键约束

SET FOREIGN_KEY_CHECKS=0;

12. 更新数据库

FLUSH PRIVILEGES;

13. 备份数据库 查找数据库名

DBLIST=`ls -p $DATADIR | grep / | tr -d /`

14. 添加开机启动进程

chkconfig nginx on

chkconfig mysqld on

chkconfig php-fpm on

chkconfig memcached on

15. sed整体替换

sed -i 's#{IMG_URL}templates\/{TEMPLATE}\/#'{TEMPLATE_URL}'#g'
`grep {IMG_URL}templates\/{TEMPLATE} -rl ./`

16. mysql的sql 替换 ----- 替换前切记需要备份

UPDATE `test` SET `content`=REPLACE(`content`,
'replace_before_str', 'replace_after_str');

UPDATE `test` set `content`=replace(`content`,
'www.test.cn/upload/','upload.test.cn/') where content LIKE
'%www.test.cn/upload/%'

17. 创建数据库

CREATE DATABASE  `dbname` DEFAULT CHARACTER SET
utf8 COLLATE utf8_general_ci;

18. 清空表

TRUNCATE TABLE  `tablename`;

19. 备份数据库

mysqldump -uroot -p dbname > /tmp/dbname.sql

20. 导入数据库

不进入数据库导入

mysql -uroot -p dbname < /tmp/dbname.sql

进入数据库导入

use dbname;

SOURCE /tmp/dbname.sql;

21. 修改数据库表主键的 AUTO_INCREMENT 属性

ALTER TABLE  `test` AUTO_INCREMENT =28;