MySQL第四天(用户授权与撤销,完全备份和完全恢复)

day04
一、用户授权与撤销
数据库管理员密码设置?
1.1修改数据库管理员本机登录密码
[[email protected] ~]# mysqladmin -hlocalhost -uroot -p password "123456"
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[[email protected] ~]# mysql -uroot -p123456

1.2恢复数据库管理员本机登录密码
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
#validate_password_policy=0
#validate_password_length=6
:wq
[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# mysql
mysql> desc mysql.user;

mysql> select user,host,authentication_string from mysql.user;
+-----------+-----------+-------------------------------------------+
| user | host | authentication_string |
+-----------+-----------+-------------------------------------------+
| root | localhost | 6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| mysql.sys | localhost |
THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
+-----------+-----------+-------------------------------------------+
2 rows in set (0.00 sec)

mysql> update mysql.user set authentication_string=password("654321") where user="root" and host="localhost"; ##修改authentication_string字段值,用函数password修改
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges; ##刷新特权
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[[email protected] ~]# vim /etc/my.cnf ##修改配置文件,注释掉skip-grant-tables
[mysqld]
#skip-grant-tables
validate_password_policy=0
validate_password_length=6
:wq
[[email protected] ~]# systemctl stop mysqld
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# mysql -uroot -p654321

用户授权
mysql> grant 权限列表 on 库名 to 用户名@"客户端地址" identified by "密码" with grant option; ##with grant option 给授予权限的权力,客户端拥有授予其他用户权限时,客户端必须要有服务器mysql.*所有表insert权限

mysql> grant all on . to [email protected]"192.168.4.54" identified by "123789" with grant option; ##在所有数据库上授予所有权限,给student用户,192.168.4.54以student身份用密码123789可以登录
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> grant insert,select on db.t1 to [email protected]"192.168.4.53" identified by "123789" with grant option; ##授予部分权限
Query OK, 0 rows affected, 1 warning (0.00 sec)

1.3登录用户查看自己的访问权限
mysql> show grants;
+---------------------------------------------------------------------+
| Grants for [email protected] |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
| GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

1.4显示当前登录用户信息
mysql> select user();
+----------------+
| user() |
+----------------+
| [email protected] |
+----------------+
查看当前登录的数据库服务器主机名
mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| db2 |
+------------+
1 row in set (0.00 sec)

1.5查看服务器上已有的授权用户
desc mysql.user
mysql> select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

mysql> select user,host from mysql.user;
+-----------+--------------+
| user | host |
+-----------+--------------+
| student | 192.168.4.53 |
| student | 192.168.4.54 |
| mysql.sys | localhost |
| root | localhost |
+-----------+--------------+
4 rows in set (0.00 sec)

1.6管理员用户查看服务器已有授权用户的访问权限
mysql> show grants for [email protected]"localhost";
+---------------------------------------------------------------------+
| Grants for [email protected] |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
| GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> show grants for [email protected]"192.168.4.53";
+-----------------------------------------------------------------------------------------+
| Grants for [email protected] |
+-----------------------------------------------------------------------------------------+
| GRANT USAGE ON . TO ‘student‘@‘192.168.4.53‘ |
| GRANT SELECT, INSERT, CREATE ON db.t1 TO ‘student‘@‘192.168.4.53‘ WITH GRANT OPTION |
+-----------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

mysql> show grants for [email protected]"192.168.4.54";
+---------------------------------------------------------------------------+
| Grants for [email protected] |
+---------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO ‘student‘@‘192.168.4.54‘ WITH GRANT OPTION |
+---------------------------------------------------------------------------+
1 row in set (0.00 sec)

1.7权限撤销
mysql>revoke 权限列表 on 数据库名 from 用户名@"客户端地址";

1.8删除授权用户
drop user 用户名@"客户端地址";

1.9数据库管理员修改授权用户的登录密码
set password 用户名@"客户端地址"=password("新密码");

1.10授权用户登录后,重置自己的登录密码
SET PASSWORD=PASSWORD("密码");

1.11授权信息记录在mysql库下不同的表里
use mysql;
show tables;
user表 记录服务器上有哪些授权用户
columns_priv表 记录授权用户对库中字段的访问权限
mysql> desc mysql.columns_priv;
+-------------+----------------------------------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------------------------------------------+------+-----+-------------------+-----------------------------+
| Host | char(60) | NO | PRI | | |
| Db | char(64) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Table_name | char(64) | NO | PRI | | |
| Column_name | char(64) | NO | PRI | | |
| Timestamp | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| Column_priv | set(‘Select‘,‘Insert‘,‘Update‘,‘References‘) | NO | | | |
+-------------+----------------------------------------------+------+-----+-------------------+-----------------------------+
7 rows in set (0.01 sec)

mysql> select * from mysql.columns_priv;
Empty set (0.00 sec)

tables_priv表 记录授权用户对库中表的访问权限 ##host为客户端地址,db为库,user为用户
mysql> desc mysql.tables_priv;
+-------------+-----------------------------------------------------------------------------------------------------------------------------------+------+-----+-------------------+-----------------------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------------------------------------------------------------------------------------------------------------------------+------+-----+-------------------+-----------------------------+
| Host | char(60) | NO | PRI | | |
| Db | char(64) | NO | PRI | | |
| User | char(32) | NO | PRI | | |
| Table_name | char(64) | NO | PRI | | |
| Grantor | char(93) | NO | MUL | | |
| Timestamp | timestamp | NO | | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
| Table_priv | set(‘Select‘,‘Insert‘,‘Update‘,‘Delete‘,‘Create‘,‘Drop‘,‘Grant‘,‘References‘,‘Index‘,‘Alter‘,‘Create View‘,‘Show view‘,‘Trigger‘) | NO | | | |
| Column_priv | set(‘Select‘,‘Insert‘,‘Update‘,‘References‘) | NO | | | |
+-------------+-----------------------------------------------------------------------------------------------------------------------------------+------+-----+-------------------+-----------------------------+
8 rows in set (0.00 sec)

mysql> select * from mysql.tables_priv;
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| localhost | sys | mysql.sys | sys_config | [email protected] | 2018-02-22 01:09:54 | Select | |
| 192.168.4.53 | db | student | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Create,Grant | |
| 176.121.205.59 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Grant | |
| 192.168.4.254 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert | |
| 192.168.4.54 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Grant | |
| 192.168.4.54 | db | admin | db | [email protected] | 0000-00-00 00:00:00 | Create,Grant | |
| 192.168.4.54 | mysql | admin | user | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Create,Drop,Grant,References,Index,Alter,Create View,Show view,Trigger | |
| 192.168.4.51 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select | |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
8 rows in set (0.00 sec)

db表 记录授权用户服务器上库的访问权限

1.7撤销权限
mysql>revoke 权限列表 on 数据库名 from 用户名@"客户端地址";
mysql> select * from mysql.tables_priv;
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| localhost | sys | mysql.sys | sys_config | [email protected] | 2018-02-22 01:09:54 | Select | |
| 192.168.4.53 | db | student | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Create,Grant | |
| 176.121.205.59 | db | admin | t1 | [email protected] | 2018-02-26 04:05:19 | Select | |
| 192.168.4.254 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert | |
| 192.168.4.54 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Grant | |
| 192.168.4.54 | db | admin | db | [email protected] | 0000-00-00 00:00:00 | Create,Grant | |
| 192.168.4.54 | mysql | admin | user | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Create,Drop,Grant,References,Index,Alter,Create View,Show view,Trigger | |
| 192.168.4.51 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select | |
| 192.168.4.54 | db | teacher | t1 | [email protected] | 0000-00-00 00:00:00 | Update | |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
9 rows in set (0.00 sec)

mysql> revoke insert on db.t1 from [email protected]"192.168.4.53";
Query OK, 0 rows affected (0.00 sec)
mysql> revoke grant option on db.t1 from [email protected]"192.168.4.53";
Query OK, 0 rows affected (0.00 sec)

mysql> select * from mysql.tables_priv;
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| localhost | sys | mysql.sys | sys_config | [email protected] | 2018-02-22 01:09:54 | Select | |
| 192.168.4.53 | db | student | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Create | |
| 176.121.205.59 | db | admin | t1 | [email protected] | 2018-02-26 04:05:19 | Select | |
| 192.168.4.254 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert | |
| 192.168.4.54 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Grant | |
| 192.168.4.54 | db | admin | db | [email protected] | 0000-00-00 00:00:00 | Create,Grant | |
| 192.168.4.54 | mysql | admin | user | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Create,Drop,Grant,References,Index,Alter,Create View,Show view,Trigger | |
| 192.168.4.51 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select | |
| 192.168.4.54 | db | teacher | t1 | [email protected] | 0000-00-00 00:00:00 | Update | |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
9 rows in set (0.00 sec)

通过修改记录字段值的方式删除权限。
mysql> select * from mysql.tables_priv;
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| localhost | sys | mysql.sys | sys_config | [email protected] | 2018-02-22 01:09:54 | Select | |
| 192.168.4.53 | db | student | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Create,Grant | |
| 176.121.205.59 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Grant | |
| 192.168.4.254 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert | |
| 192.168.4.54 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Grant | |
| 192.168.4.54 | db | admin | db | [email protected] | 0000-00-00 00:00:00 | Create,Grant | |
| 192.168.4.54 | mysql | admin | user | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Create,Drop,Grant,References,Index,Alter,Create View,Show view,Trigger | |
| 192.168.4.51 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select | |
| 192.168.4.54 | db | teacher | t1 | [email protected] | 0000-00-00 00:00:00 | Update | |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
9 rows in set (0.00 sec)

mysql> update mysql.tables_priv set Table_priv="select" where host="176.121.205.59" and Db="db";
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from mysql.tables_priv;
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| localhost | sys | mysql.sys | sys_config | [email protected] | 2018-02-22 01:09:54 | Select | |
| 192.168.4.53 | db | student | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Create,Grant | |
| 176.121.205.59 | db | admin | t1 | [email protected] | 2018-02-26 04:05:19 | Select | |
| 192.168.4.254 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert | |
| 192.168.4.54 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Grant | |
| 192.168.4.54 | db | admin | db | [email protected] | 0000-00-00 00:00:00 | Create,Grant | |
| 192.168.4.54 | mysql | admin | user | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Create,Drop,Grant,References,Index,Alter,Create View,Show view,Trigger | |
| 192.168.4.51 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select | |
| 192.168.4.54 | db | teacher | t1 | [email protected] | 0000-00-00 00:00:00 | Update | |
+----------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
9 rows in set (0.00 sec)

mysql> drop user [email protected]"176.121.205.59"; ##删除用户方式撤销所有权力
Query OK, 0 rows affected (0.00 sec)

mysql> select * from mysql.tables_priv;
+---------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
+---------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
| localhost | sys | mysql.sys | sys_config | [email protected] | 2018-02-22 01:09:54 | Select | |
| 192.168.4.53 | db | student | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Create | |
| 192.168.4.254 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert | |
| 192.168.4.54 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Grant | |
| 192.168.4.54 | db | admin | db | [email protected] | 0000-00-00 00:00:00 | Create,Grant | |
| 192.168.4.54 | mysql | admin | user | [email protected] | 0000-00-00 00:00:00 | Select,Insert,Update,Delete,Create,Drop,Grant,References,Index,Alter,Create View,Show view,Trigger | |
| 192.168.4.51 | db | admin | t1 | [email protected] | 0000-00-00 00:00:00 | Select | |
| 192.168.4.54 | db | teacher | t1 | [email protected] | 0000-00-00 00:00:00 | Update | |
+---------------+-------+-----------+------------+--------------------+---------------------+----------------------------------------------------------------------------------------------------+-------------+
8 rows in set (0.00 sec)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
在客户端使用授权连接数据库服务器
mysql -h数据库服务器ip地址 -u授权用户名 -p密码
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
安装数据库图形管理工具-phpmyadmin

[[email protected] 09.mysql]# yum -y install httpd php php-mysql
[[email protected] 09.mysql]# systemctl restart httpd
[[email protected] 09.mysql]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[[email protected] 09.mysql]# vim /var/www/html/test.php
<?php
$db=mysql_connect("localhost","root","654321");
if($db){echo "ok";}else{echo "no";};
?>
:wq
[[email protected] html]# php test.php
http://192.168.4.52/test.php

phpmyadmin
[[email protected] 09.mysql]# tar -xf phpMyAdmin-2.11.11-all-languages.tar.gz -C /var/www/html/
[[email protected] 09.mysql]# cd /var/www/html/
[[email protected] html]# ls
phpMyAdmin-2.11.11-all-languages test.php
[[email protected] html]# mv phpMyAdmin-2.11.11-all-languages/ phpmyadmin
[[email protected] html]# ls
phpmyadmin test.php
[[email protected] html]# ls -ld phpmyadmin/
drwxr-xr-x. 9 root root 4096 9月 7 2010 phpmyadmin/
[[email protected] html]# chown -R apache:apache phpmyadmin/
[[email protected] html]# ls -ld phpmyadmin/
drwxr-xr-x. 9 apache apache 4096 9月 7 2010 phpmyadmin/
[[email protected] html]# cd phpmyadmin/
[[email protected] phpmyadmin]# cp config.sample.inc.php config.inc.php
[[email protected] phpmyadmin]# sed -n ‘17p;31p‘ config.inc.php
vim config.inc.php
$cfg[‘blowfish_secret‘] = ‘plj123‘; / YOU MUST FILL IN THIS FOR COOKIE AUTH! / ##单引号中间随意填
$cfg[‘Servers‘][$i][‘host‘] = ‘localhost‘; ##填写数据库ip地址

mysql> create database t44;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db |
| db1 |
| mysql |
| performance_schema |
| sys |
| t44 |
+--------------------+
7 rows in set (0.00 sec)

mysql> grant all on t44.* to [email protected]"localhost" identified by "123456";
Query OK, 0 rows affected, 1 warning (0.00 sec)

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
数据备份与恢复-完全备份和恢复
1 备份数据的目的?

2 备份方式?
物理备份:拷贝库或表对应的文件
#cp -r /var/lib/mysql/数据库名 /opt/mysql.bak
或者
#tar -zcvf /opt/数据库名.tar.gz /var/lib/mysql/*
恢复:
#cp -r /opt/mysql.bak /var/lib/mysql/数据库名
#chown -R mysql:mysql /var/lib/mysql/数据库名
#systemctl restart mysqld

逻辑备份:执行备份根据备份的库或表,生成对于的sql命令,然后把sql命令存储到指定的文件里。

3 备份策略
完全备份:备份所有数据 #一台数据库服务器//某个库的所有数据//某一张表的所有数据
mysqldump -uroot -p123456 数据库名> 目录名/xxx.sql

只备份新产生的数据?
binlog日志 innobackup
差异备份:备份自完全备份后所有新产生的
增量备份:备份自上次备份后所有新产生的

备份策略的使用方式?
完全+差异
完全+增量

crond 执行 备份脚本

30 23 1 /rootallbaksh #每周一晚上完全备份
50 23 2-7 /root/newdata.sh #周二到周日差异备

1.备份服务器上所有数据库到/datadir/ 文件名为all.sql
#mysqldump -uroot -p123456 --all-databases > /datadir/all.sql

2.备份服务器上db3 库的所有数据到/datadir 文件名db3.sql
#mysqldump -uroot -p123456 db3 > /datadir/db3.sql

3.备份db3库下的user表的所有数据到/datadir 文件名db3-user.sql
#mysqldump -uroot -p123456 db3 user > /datadir/db3-user.sql

4.删除db3库下的user表记录 使用备份文件恢复数据
mysql>delete from db3.user
#mysql -uroot -p123456 db3 < /datadir/db3-user.sql

5.把db3库下的所有数据恢复到db55库里
mysql> create database db55;

mysql -uroot -p654321 db55 < /datadir/db3.sql

6.删除db3库使用备份文件恢复db3库的数据
Mysql> drop database db3;
Mysql>create database db3;
#mysql -uroot -p654321 db3 < /datadir/db3.sql

7.备份数据库服务的所有的授权信息,
#mysqldump -uroot -p65432

8.编写脚步alladta.sh功能备份db55库的所有数据到系统的/mydata目录下,
备份名字:年-月-日-库名.sql

vim /alldata.sh

#!/bin/bash
Day=date +%F
If [ ! -e /mydata ];then
Mkdir /mydata
fi
mysqldump -hlocalhost -uroot -p654321 db55 > /mydata/$day-db55.sql
编写计划任务:
]#crontab -e -uroot
30 23 1 /root/alldata.sh
################

完全备份:
#mysqldump -hlocalhost -uroot -p123456 数据库名 > 目录名/xxx.sql
数据库名的表示方式

一台服务器上的所有数据
--all-databases

某一个库的所有数据
库名 #db1

某一张表的所有数据
库名 表名 #db1 t1

把多个库的所有数据备份到一个备份文件里
-B 库名列表

#mkdir /mydata
#mysqldump -uroot -p654321 db2 > /mydata/db2.sql ##备份
Mysql>use db2;
Mysql>drop table t7,t8;
恢复
#mysql -uroot -p654321 库名 < /备份文件 ##还原
#mysql -uroot -p654321 db2 < /mydata/db2.sql
#############################
备份数据时需要考虑的事情?
备份策略
备份时间
数据备份频率
备份文件的命名 yyyy-mm-dd-dbname.sql
存储空间 可扩展LV RAID

完全备份策略有哪些缺点?
备份和恢复都会锁表(写锁)
使用完全备份文件,只能把数据恢复到备份时的状态(比如周一备份,周2到周6产生的数据后,还原后只有周一数据)

原文地址:http://blog.51cto.com/13587169/2074437

时间: 2024-11-05 22:43:11

MySQL第四天(用户授权与撤销,完全备份和完全恢复)的相关文章

26_多表查询 MySQL管理工具 、 用户授权及撤销

版本:5.7.28服务器:mysql 192.168.4.20 1.MySQL管理工具 部署LAMP+phpMyAdmin平台安装httpd.mysql.php-mysql及相关包启动httpd服务程序解压phpMyAdmin包,部署到网站目录配置config.inc.php,指定MySQL主机地址创建授权用户浏览器访问.登录使用 1.1 准备软件的运行环境 lamp]# yum -y install httpd php php-mysql]# systemctl start httpd]# s

DBA04 - 多表查询 MySQL管理工具、用户授权及撤销

DBA DAY04 一.多表查询 stu_id   name   class   缴费表班级表成绩表就业表1.1 复制表 (作用: 备份表 . 快速建表) mysql>   create  table  表名  sql查询:create database  db4;use  db4; create  table  user2  select  * from db3.user;show  tables;select  * from user2; create  table  user3  sele

密码恢复及设置,用户授权及撤销,MySQL管理工具

密码恢复及设置 1.1 问题 本案例要求熟悉MySQL管理密码的控制,完成以下任务操作: 练习重置MySQL管理密码的操作 通过正常途径设置MySQL数据库的管理密码 1.2 步骤 实现此案例需要按照如下步骤进行. 步骤一:重置MySQL管理密码 1)首先停止已运行的MySQL服务程序 [[email protected] ~]# systemctl stop mysqld.service         //停止服务 [[email protected] ~]# systemctl statu

mysql用户授权及撤销

mysql数据库服务在不做授权的情况下只允许数据库管理员从数据库服务器本机登录. 默认只有数据库管理员从数据库服务器本机登录才有授权权限 mysql -u root -p (本机登录mysql服务器) mysql -u root -h 192.168.4.5 -p (远程连接mysql服务器) 方式1 在库外重置数据库管理员密码: [[email protected] 桌面]# mysqladmin -hlocalhost -uroot -p password "123456"    

mysql root给其它用户授权问题

今天登录mysql,给其它用户授权遇到问题 mysql> grant all privileges on testdb.* to 'dbuser'@'10.4.14.14' identified by '5jyeTQ'; ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'testdb' 首先看一下root用户有没有grant权限 mysql> select user,host,grant_pri

Mysql 创建用户授权

MySQL创建用户与授权 一. 创建用户 命令: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明: username:你将创建的用户名 host:指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符% password:该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器 例子: CREATE USER 'dog'@'localhost'

Mysql添加用户,给用户授权

创建用户 ? 1 CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明: username – 你将创建的用户名 host – 指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,  如 果想让该用户可以从任意远程主机登陆,可以使用通配符% password –  该用户的登陆密码,密码可以为空,如果为空则该用户可以不需要密码登 陆服务器 例子: ? 1 2 3 4 5 CREATE USER 'javacui'@

Linux环境下MySQL基础命令(4)----数据库的用户授权

      MySQL数据库的root用户拥有对所有库,表的全部权限,频繁的使用root用户会给数据库带来很大的风险,因此应建立一些低权限用户,只负责一部分库.表的管理维护操作,甚至可以对增.删.改.查各个操作进一步细化限制,从而将数据库的风险降至最低. 一,授予权限 GRANT语句:用来设置数据库用户的访问权限,当指定的用户不存在时,GRANT语句将会创建新的用户.使用GRANT语句授权的用户记录,会保存到mysql库的user.db.host.tables_priv等表中,无需刷新便立即生效

MySQL数据库用户授权管理

一.用户授权 1.注意事项: -  MySQL数据库服务器搭建好之后,放在独立的房间里或者是IDC机房,MySQL数据库服务默认只允许数据库管理员root在本地登录,要在其他客户端登录管理数据库则需要授权才可以. -  程序员(网站运行数据)编程使用数据库都是在客户端,需要授权. -  默认只有数据库管理员在数据库服务器本机登录才有授权权限 2.授权库mysql,主要的几个表: - user表:记录用户的信息 host:客户端 user:授权用户名password:授权用户密码  *_priv: