找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
本帖最后由 南京1期庞惠茹 于 2021-12-3 19:56 编辑

mysql数据库复盘3
【数据库备份】
1)备份(>)
  • mysqldump -uroot -p dcs1>/dcs1.sql==》把dec1库备份到linux根目录下方(>为重定向,dump备份)

2)还原(<)
  • mysql -uroot -p dcs2</dcs1.sql==>把根目录中dcs1.sql文件还原到dcs2库中


【数据库密码】
1)跳过权限不入密码进入mysql
vim etc/my.cnf,在socket=/var下面输入skip-grant-tables,
service mysqld restart - 进入mysql.

2)【一系列操作】:
[root@192 /]# vim /etc/my.cnf
i输入 skip-grant-tables:wq保存退出
[root@192 /]# service mysqld restart
[root@192 /]# mysql -uroot -p
mysql> use mysql;
mysql> update user set password='123456' where user='root';
mysql> flush privileges;
mysql> grant all privileges on *.*  to  'root'@'localhost' identified by '123456';
mysql> grant all privileges on *.*  to  'root'@'%' identified by '123456';
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> Ctrl-C -- exit!
[root@192 /]# vim /etc/my.cnf
在 skip-grant-tables前i输入#,:wq保存退出
[root@192 /]# service mysqld restart
[root@192 /]# mysql -uroot -p
Enter password: (不输入密码会报错)
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@192 /]# mysql -uroot -p123456
mysql> 】

【新建用户新增权限】mysql数据库中的user用户操作
  • select host,user from user;==》查询所有用户

备注:
1、locallhost和127.0.0.1代表的是本地用户,通过Xshell对数据库进行操作的用户
2、%代表具有远程访问权限的用户==》可以通过数据库客户端工具连接centos,Navicat
  • insert into user(host,user,password)values('localhost','dcs1',password("123456"));==》插入一个新用户dcs1,并且设置密码为123456


  • mysql -udcs1 -p123456==》根目录下使用新用户dcs1登录mysql


  • show grants for 'dcs1'@'localhost';==》查看用户dcs1是否有权限

备注:USAGE代表为没有权限

【修改用户密码】
  • update user set password='123456' where user='root';==》更新root用户的密码为123456


【移除权限】
  • revoke all on *.* from 'dcs1'@'localhost';==》移除本地用户dcs1的所有权限


【赋予用户权限】(远程用户and本地用户)
  • grant select,update,delete,drop on *.* to 'dcs1'@'localhost' identified by '123456';==》给一个具有本地访问权限的用户dcs1赋予他对数据库里面的所有表具有查询、更新和删除的权限(给谁赋权

备注:*.*第一个*代表数据库中的所有的库,第二个*代表数据库中所有表,合起来代表数据库中所有表
  • flush privileges;(每次操作完赋权后要记得刷新一下)
  • grant all privileges on *.* to 'dcs1'@'localhost' identified by '123456';==》赋予本地用户dcs1所有权限


  • grant all privileges on *.* to 'dcs2'@'localhost' identified by '123456';==》既可以创建新用户也可以赋予本地用户所有权限(当dcs2不存在,会新建一个名为dcs2的新用户并赋予所有权限)


  • grant all privileges on *.* to 'root'@'localhost' identified by '123456';==》赋予本地用户root所有权限


  • grant all privileges on *.* to 'root'@'%' identified by '123456';==》给远程用户root赋予所有权限(%代表具有远程访问权限的用户)


  • grant all privileges on *.* to 'dcs1'@'%' identified by '123456';==》给远程用户dcs1赋予所有权限


【删除用户权限】
  • delete from user where user='dcs1' and host='%';==》删除具有远程访问权限的dcs1用户


【修改用户密码】
  • update user set password=password('123123') where user='dcs1' and host='localhost';==》修改本地用户dcs1的密码为123123


【面试题】mysql数据库中DDL和DML的区别是什么?
Mysql数据库表结构的操作语言:DDL(对表结构的操作)
                                                   create/drop/alter/desc

Mysql数据库表数据的操作语言:DML(对表数据的操作)增删改查
                                                   insert into/delete/update/select

分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册