mysql用户管理、常用sql语句、mysql数据库备份恢复

mysql用户管理

1、新增用户user1,并设置密码为123456

mysql> grant all on *.* to ‘user1‘@‘127.0.0.1‘ identified by ‘123456‘;

#创建user1用户并授予其所有权限“*.*”(通配符)

#第一个*:表示所有的数据库

#第二个*:表示所有的表

#127.0.0.1表示来源IP,指的只有这个IP可以连接;‘%‘:代表所有的ip

#identified by 设置密码

2、对user1用户进行授权管理

mysql> grant SELECT,UPDATE,INSERT on test.* to ‘user2‘@‘192.168.3.74‘ identified by ‘123456‘;

创建user2用户,并指定test的数据库,权限:select、update、insert

3、新建user3,对所有的IP,所有的权限

mysql> grant all on test.* to ‘user3‘@‘%‘ identified by ‘123456‘;

4、查询用户权限

mysql> show grants for [email protected]‘192.168.3.74‘;

+-----------------------------------------------------------------------------------------------------------------+

| Grants for [email protected]                                                                                   |

+-----------------------------------------------------------------------------------------------------------------+

| GRANT USAGE ON *.* TO ‘user2‘@‘192.168.3.74‘ IDENTIFIED BY PASSWORD ‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9‘ |  #这一行仅仅创建用户

| GRANT SELECT, INSERT, UPDATE ON `test`.* TO ‘user2‘@‘192.168.3.74‘  #这一行是授权user2用户的select、insert、update                                             |

+-----------------------------------------------------------------------------------------------------------------+

5、更改权限

mysql>  GRANT SELECT, INSERT, UPDATE ON `test`.* TO ‘user2‘@‘192.168.3.74‘;

常用sql语句

增删改查:

1、查看指定的数据库表行数

select count(*) from mysql.user;

2、查询 192.168.%的信息

mysql> select * from mysql.db where host like ‘192.168.%‘\G;

3、create table t1(`id` int(4),`name` char(40));

4、insert into db1.t1 values(1,‘abc‘);

5、清空表

truncate db1.t1;

6、删除用户

delete from user where User=‘user1‘ and Host=‘127.0.0.1‘;

7、删除数据

delete from db1.t1 where id=1;

8、更改数据

update db1.t1 set name=‘aaa‘ where id=1;

mysql数据库备份恢复

备份指定库:

[[email protected] ~]# mysqldump -uroot -p123456 test > /tmp/testbak.sql

备份所有库:

[[email protected] ~]# mysqldump -uroot -p123456 -A > /tmp/mysql_all.sql

恢复指定的库:

[[email protected] ~]# mysql -uroot -p123456 mysql < /tmp/mysqlbak.sql

恢复全部库:

[[email protected] ~]# mysql -uroot -p123456  < /tmp/testbak.sql

备份表:

[[email protected] ~]# mysql -uroot -p123456 mysql user > /tmp/user.sql

只备份表结构:

mysqldump -uroot -p123456 -d mysql > /tmp/mysql_tb.sql

恢复表:

mysql -uroot -p123456 mysql user < /tmp/user.sql

时间: 2024-08-26 11:04:35

mysql用户管理、常用sql语句、mysql数据库备份恢复的相关文章

mysql用户管理, 常用sql语句,mysql数据库备份恢复

mysql用户管理 新创建一个指定IP的用户,可以访问mysql的某些库某些表. 所有库的所有表,如果想指定访问某个库某些表,只需要修改名称user1 指定用户名br/>@后面的ip是指定ip,%表示所有的ipindentified by 后面是用户的密码验证用用户user1登录也可以指定localhost,登录时不输入本机ip地址即可访问查看授权,用于授权给新用户,新权限: 常用sql 语句 查看库表的行数搜索:select count() from mysql.user;搜索:select

MySQL(用户管理,常用sql语句,数据库备份恢复,MySQL调优,恢复误操作数据)

一.MySQL用户管理. 一个MySQL数据库里可以跑多个库,总不能给所有人的程序员root用户,则可以给他们单独的用户访问数据库. 创建用户:(grant all on *.* to 'user1'是把所有库的权限给'user1,他的来源Ip是127.0.0.1,他的密码是lty123456') (第一个*是库名,如果你写成mysql.*那就是对mysql库的所有权限) (来源ip也可以写成 % ,表示来源的所有ip) (grant这种语句是不会记录到命令历史里去的,因为不安全.) mysql

MySQL用户管理、常用sql语句、数据库备份恢复

MySQL用户管理 MySQL分为普通用户与root用户.这两种用户的权限不一样.新建普通用户在MySQL数据库中,建立用户有3种方式:使用CREATE USER语句来创建新的用户:直接在mysql.user表中INSERT用户:使用GRANT语句来新建用户: grant命令grant all on *.* to 'user1'@'192.168.71.131' identified by '123456'; all 表示所有的权限. 表示所有的库,前面的表示库名,后面的表示所有的表'user1

【转】MySQL用户管理及SQL语句详解

[转]MySQL用户管理及SQL语句详解 1.1 MySQL用户管理 1.1.1 用户的定义 用户名+主机域 mysql> select user,host,password from mysql.user; +--------+------------+-------------------------------------------+ | user | host | password | +--------+------------+---------------------------

MySQL用户管理、常用sql语句、数据库备份

13.4 MySQL用户管理 创建用户并授权 指定登录IP [[email protected] ~]# mysql -uroot -pEnter password: Welcome to the MySQL monitor.mysql> grant all on . to 'user1'@'127.0.0.1' identified by '123456';#创建user1用户并授予其所有权限"."(通配符)#第一个表示db_name:第二个表示tb_name#同时指定其来源I

MySQL创建用户,常用SQL语句以及数据库备份与恢复

一.创建普通用户并授权 1.创建用户并授权 [[email protected] ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.36 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle a

MySQL用户管理及SQL语句详解

1.1 MySQL用户管理 1.1.1 用户的定义 用户名+主机域 mysql> select user,host,password from mysql.user; +--------+------------+-------------------------------------------+ | user | host | password | +--------+------------+-------------------------------------------+ | r

1.1 MySQL用户管理及SQL语句详解

1.1 MySQL用户管理 1.1.1 用户的定义 用户名+主机域 mysql> select user,host,password from mysql.user; +--------+------------+-------------------------------------------+ | user | host | password | +--------+------------+-------------------------------------------+ | r

MySQL用户管理、sql常用语句、mysql备份与恢复

MySQL用户管理 创建用户 grant all on *.* to 'user1'@'localhost' identified by '123456'; grant all on db1.* to 'user2'@'%' identified by '123456'; //创建user2用户,所有ip都能登录,指定权限为db1库下的所有表: flush privileges; 刷新授权 .:表示所有库和表:user1:用户名:localhost:登录ip,默认localhost为本机登录ip

96.创建普通用户并授权,常用SQL语句,MySQL数据库备份与恢复

一.创建普通用户并授权 1.创建用户并授权 [[email protected] ~]# mysql -uroot -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/o