当前位置:网站首页>Examples of MySQL account addition, deletion, modification, data import and export commands
Examples of MySQL account addition, deletion, modification, data import and export commands
2022-06-22 16:55:00 【MarshalEagle】
The following examples are based on mysql The database has been built as follows :
a,school And it includes t_student、t_teacher surface
b,company And it includes t_staff、t_leader
One ,mysql Add, delete, modify and check the account number
1) establish account1 Account and set password , Set it to be accessible remotely and locally school and company All tables in the data have all permissions such as adding, deleting, modifying and querying .
a,
Want the local server to be able to connect to , The following two steps must be carried out : stay user Add two records to the table --------------------------A
mysql>CREATE USER 'account1'@'localhost' IDENTIFIED BY 'mypasswd';
mysql>CREATE USER 'account1'@'127.0.0.1' IDENTIFIED BY 'mypasswd';
If you just want the outside ip Access to the , among % Represents all of the external ip: stay user Add a record to the table --------------------------B
mysql>CREATE USER 'account1'@'%' IDENTIFIED BY 'mypasswd';
In this case, execute A+B.
b, Assign all operation permissions of all databases to account1 user , And external access ip unlimited
mysql>GRANT ALL PRIVILEGES ON *.* TOaccount1@"%" IDENTIFIED BY "mypasswd";
mysql>flush privileges;
perhaps
mysql>GRANT ALL PRIVILEGES ON school.* TOaccount1@"%" IDENTIFIED BY "mypasswd";
mysql>GRANT ALL PRIVILEGES ON company.* TOaccount1@"%" IDENTIFIED BY "mypasswd";
mysql>flush privileges;
2) establish account2 Account and set password , At the same time, set its only Remote and local access school All tables in the data are merged only Have the authority to add, modify and query .
a,
Want the local server to be able to connect to , The following two steps must be carried out : stay user Add two records to the table --------------------------A
mysql>CREATE USER 'account2'@'localhost' IDENTIFIED BY 'mypasswd';
mysql>CREATE USER 'account2'@'127.0.0.1' IDENTIFIED BY 'mypasswd';
If you just want the outside ip Access to the , among % Represents all of the external ip: stay user Add a record to the table --------------------------B
mysql>CREATE USER 'account2'@'%' IDENTIFIED BY 'mypasswd';
In this case, execute A+B.
b, take school Database Add, change and check The operation permission is assigned to account2 user , And external access ip unlimited
mysql>GRANT select,update,insert PRIVILEGES ON school.* [email protected]"%" IDENTIFIED BY "mypasswd";
mysql>flush privileges;
3) Users' deletion, modification and query
a, see account2 User permissions
mysql>show grants for 'account2'@'%';
or
mysql>select *from mysql.user where user='account2';
b, modify account2 User password
mysql>update user set password=password('new_password') where user='account2';
mysql>flush privileges;
or
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
Be careful : If root Password forgotten or lost , Kill them first mysqld And then
#mysqld_safe --skip-grant-tables &
#mysql -u root mysql
mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';
mysql> FLUSH PRIVILEGES;
c, Delete account2 user
mysql>delete from mysql.user where user = 'account2';
Two ,mysql Data export import
a, export :
1) export school Database data to (/home/file/school.sql)
mysqldump -u user name -p password Database name > Database name .sql
#cd /home/file
#mysqldump -uroot -pmypasswd school > school.sql
2) Export only school Table structure of database
mysqldump -u user name -p password -d Database name > Database name .sql
#mysqldump -uroot -p -d school > school.sql
3) export school In the database t_student Table data
#mysqldump -uroot -pmypasswd school t_student > /home/file/t_access_log.sql
4) export school In the database t_student Part of the table data ( Older than 16 Less than 18)
#mysqldump -uroot -pmypasswd school t_student --where="age>'16' and age<'18'" > /home/t_student.sql
b, Import :
mysql>create database school;( Get into mysql The command line interface establishes the database school)
1) Set the code to utf8, Import school.sql File to newly created school database
mysql>use school;
mysql>set names utf8;
mysql>source /home/file/school.sql
2) Import school.sql File to newly created school database
#mysql -uroot -p school < /home/file/school.sql( Enter the password )
边栏推荐
- ERROR 1364 (HY000): Field ssl_cipher doesnt have a default value
- 【微信小程序封装底部弹出框二】
- 华为云招募工业智能领域合作伙伴,强力扶持+商业变现
- 使用IDM让百度云加速的方法
- LETV group payment system architecture sharing for processing 100000 high concurrent orders per second
- [C language] deeply analyze the relationship between pointer and array
- Summary of spark common operators
- 同花顺是什么?在线开户安全么?
- Purchase guide - how to purchase a high-quality conference tablet, these aspects must be compared
- 5 modes of IO model
猜你喜欢

图计算Hama-BSP模型的运行流程

web技术分享| 【高德地图】实现自定义的轨迹回放

Safari兼容性问题总结

视频爆炸时代,谁在支撑视频生态网高速运行?

什么是RESTful,REST api设计时应该遵守什么样的规则?

mysql5.7.27安装之windows8.1 64

The world's "first" IEEE privacy computing "connectivity" international standard led by insight technology was officially launched

视频会议时听不到声音该如何处理?

jsp学习之(一)---------jsp概述
![[pop up box at the bottom of wechat applet package] I](/img/28/7cb36ef4fcf753764cc9363a323a20.png)
[pop up box at the bottom of wechat applet package] I
随机推荐
从Application提交角度审视Executor
【心理学】情感心理学-当代思想和传统思想的碰撞(本篇文章将不定期持续更新)
Task scheduling design of collection system
系统吞吐量、TPS(QPS)、用户并发量、性能测试概念和公式
购买指南丨如何购买一台高质量会议平板,这几个方面一定要对比
SAP script tutorial: se71, se78, SCC1, vf03, so10-013
Test for API
Windows8.1 64 installed by mysql5.7.27
Test for API
vs2017 在调试状态不显示QString值的解决方法
JS method for judging data type of interview questions
毕业季·本科毕业感想——机械er的自救之路
Special research on Intelligent upgrading of heavy trucks in China in 2022
jsp学习之开发环境的配置
JS获取数据类型方法总结
Idea installation summary
Call CMD process communication
【微信小程序封装底部弹出框二】
win10桌面图标消失,工具栏变黑
【阿里云服务器-安装mysql的5.6版本安装,重装】