当前位置:网站首页>mysql账号增删改、数据导入导出命令举例
mysql账号增删改、数据导入导出命令举例
2022-06-22 15:25:00 【MarshalEagle】
以下举例基于mysql中已建好数据库如下:
a,school且其包括t_student、t_teacher表
b,company且其包括t_staff、t_leader
一,mysql账号增删改查
1)创建account1账号并设置密码,同时设置其可远程和本机访问school和company数据中所有表并拥有增删改查等所有权限。
a,
想要本机服务器能连接到,必须进行如下两步骤:在user表中增加两条记录--------------------------A
mysql>CREATE USER 'account1'@'localhost' IDENTIFIED BY 'mypasswd';
mysql>CREATE USER 'account1'@'127.0.0.1' IDENTIFIED BY 'mypasswd';
若只想让外部ip访问到,其中%代表通配所有外部ip:在user表中增加一条记录--------------------------B
mysql>CREATE USER 'account1'@'%' IDENTIFIED BY 'mypasswd';
此情况执行A+B。
b,将所有数据库的所有操作权限赋值给account1用户,且外部访问ip无限制
mysql>GRANT ALL PRIVILEGES ON *.* TOaccount1@"%" IDENTIFIED BY "mypasswd";
mysql>flush privileges;
或者
mysql>GRANT ALL PRIVILEGES ON school.* TOaccount1@"%" IDENTIFIED BY "mypasswd";
mysql>GRANT ALL PRIVILEGES ON company.* TOaccount1@"%" IDENTIFIED BY "mypasswd";
mysql>flush privileges;
2) 创建account2账号并设置密码,同时设置其只可远程和本机访问school数据中所有表并只拥有增改查权限。
a,
想要本机服务器能连接到,必须进行如下两步骤:在user表中增加两条记录--------------------------A
mysql>CREATE USER 'account2'@'localhost' IDENTIFIED BY 'mypasswd';
mysql>CREATE USER 'account2'@'127.0.0.1' IDENTIFIED BY 'mypasswd';
若只想让外部ip访问到,其中%代表通配所有外部ip:在user表中增加一条记录--------------------------B
mysql>CREATE USER 'account2'@'%' IDENTIFIED BY 'mypasswd';
此情况执行A+B。
b,将school数据库的增改查操作权限赋值给account2用户,且外部访问ip无限制
mysql>GRANT select,update,insert PRIVILEGES ON school.* [email protected]"%" IDENTIFIED BY "mypasswd";
mysql>flush privileges;
3)用户的删改查
a,查看account2用户权限
mysql>show grants for 'account2'@'%';
或
mysql>select *from mysql.user where user='account2';
b,修改account2用户密码
mysql>update user set password=password('new_password') where user='account2';
mysql>flush privileges;
或
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
注意:如果root密码忘记或者丢失,则先杀掉mysqld的相关进程然后
#mysqld_safe --skip-grant-tables &
#mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
c,删除account2用户
mysql>delete from mysql.user where user = 'account2';
二,mysql数据导出导入
a,导出:
1)导出school数据库的数据到(/home/file/school.sql)
mysqldump -u用户名 -p密码 数据库名 > 数据库名.sql
#cd /home/file
#mysqldump -uroot -pmypasswd school > school.sql
2)只导出school数据库的表结构
mysqldump -u用户名 -p密码 -d 数据库名 > 数据库名.sql
#mysqldump -uroot -p -d school > school.sql
3)导出school数据库中t_student表数据
#mysqldump -uroot -pmypasswd school t_student > /home/file/t_access_log.sql
4)导出school数据库中t_student表的部分数据(年龄大于16小于18)
#mysqldump -uroot -pmypasswd school t_student --where="age>'16' and age<'18'" > /home/t_student.sql
b,导入:
mysql>create database school;(进入mysql命令行界面建立数据库school)
1)设置编码为utf8,导入school.sql文件到新建立的school数据库
mysql>use school;
mysql>set names utf8;
mysql>source /home/file/school.sql
2)导入school.sql文件到新建立的school数据库
#mysql -uroot -p school < /home/file/school.sql(回车输入密码即可)
边栏推荐
- NiO service multithreaded version
- 【游标的嵌套】mysql存储过程游标的嵌套
- SAP ABAP data types, operators and editors-02
- [deep anatomy of C language] keywords if & else & bool type
- JS method for judging data type of interview questions
- User exit and customer exit in SAP ABAP -015
- 什么是RESTful,REST api设计时应该遵守什么样的规则?
- spark-cache的源码分析
- SAP script tutorial: se71, se78, SCC1, vf03, so10-013
- scala之闭包函数浅知
猜你喜欢

CUMT学习日记——数字图像处理考试速成笔记

jsp学习之(二)---------jsp脚本元素和指令

STM32 ADC acquisition via DMA (HAL Library)

【微信小程序自定义底部tabbar】

5 modes of IO model

CUMT study diary - quick notes of digital image processing examination

jsp学习之(三)--------- jsp隐式对象
![Consumption monitoring of Prometheus monitoring [consult exporter]](/img/9e/8547b2c38143ab0e051c1cf0b04986.png)
Consumption monitoring of Prometheus monitoring [consult exporter]

【C语言深度解剖】关键字if&&else&&bool类型

Parts beyond the text are indicated by ellipsis
随机推荐
nio服务多线程版本
【微信小程序封装底部弹出框二】
Test for API
【微信小程序自定义底部tabbar】
代码扫描工具扫出的 Arrays.asList 使用BUG
spark-shuffle的读数据源码分析
Idea installation summary
Spark Streaming checkpoint的问题与恢复
ABAP query tutorial in sap: sq01, sq02, sq03-017
从Application提交角度审视Executor
In case of default import failure
Purchase guide - how to purchase a high-quality conference tablet, these aspects must be compared
Simple understanding of asynchronous IO
STM32通过DMA进行ADC采集(HAL库)
STM32 ADC acquisition via DMA (HAL Library)
5 modes of IO model
Special research on Intelligent upgrading of heavy trucks in China in 2022
Machine learning notes - Hagrid - Introduction to gesture recognition image data set
CUMT study diary - quick notes of digital image processing examination
jsp学习之开发环境的配置