linux 给mysql添加用户 && 备份数据库


1.#插入登录帐号jack 密码123456 对所有客户端ip开发 CREATE USER 'jack'@'%' IDENTIFIED BY "123456";
#开发jack帐号 密码123 开发客户端ip192.168.189.71 这个帐号只有这个ip可以访问
CREATE USER 'jack'@'192.168.189.71' IDENTIFIED BY "123";
2.#给帐号jack开放所有数据库权限 并设置登录密码为123456 (只能是本地访问)
grant all privileges on *.* to jack@localhost identified by '123456';
所有机器可以访问
grant all privileges on *.* to 'jack'@'%' identified by '123456';
#给主机为192.168.10.1的用户john分配可对数据库test所有表进行所有操作的权限,并设定口令为123。
grant all privileges on test.* to joe@192.168.10.1 identified by '123';
3.#刷新权限
FLUSH PRIVILEGES;
#登录后的界面
[root@VM_206_53_centos zbox]# /opt/zbox/bin/mysql -u jack -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1415
Server version: 5.5.45 Source distribution

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

二.备份mysql数据库

1.#创建shell文件
vim backup_mysql.sh
2.写入命令到文件中
#第一句可能不一样 因为我这个是禅道的数据库,不过语法都一样的,找到mysqldump文件即可,删除超过7天的备份数据,保留3个月里的 10号 20号 30号的备份数据;
opt/zbox/run/mysql/mysqldump -u jack -p123456 zentao > /data/dbdata/mysqlbak/`date +%Y%m%d`.sql find /data/dbdata/mysqlbak/ -mtime +7 -name '*[1-9].sql' -exec rm -rf {} \; find /data/dbdata/mysqlbak/ -mtime +92 -name '*.sql' -exec rm -rf {} \;
3.使文件设置程可执行文件
chmod u+x backup_mysql.sh
4.执行文件进行备份 测试看是否能备份
./backup_mysql.sh

[root@VM_206_53_centos dbdata]# ./backup_mysql.sh

[root@VM_206_53_centos dbdata]# ll

total 8

-rwxr--r-- 1 root root 245 Aug 8 15:00 backup_mysql.sh

drwxr-xr-x 2 root root 4096 Aug 8 15:10 mysqlbak

[root@VM_206_53_centos dbdata]# cd mysqlbak/

[root@VM_206_53_centos mysqlbak]# ll

total 124

-rw-r--r-- 1 root root 120561 Aug 8 15:10 20170808.sql

看了下 已经产生sql文件

卸载mysql 需要查看安装了那些mysql版本

rpm -qa|grep-i mysql

rpm -e --nodeps xxx 结果ji执行删除操作

#任务计划进行备份
ce /etc
crontab -e
#这个时候出来的是一个类是创建一个文本的窗口
输入以下即可 每天4点备份
0 4 * * * /data/dbdata/backup_mysql.sh