博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mysql多表查询语句,授权用户与密码更改
阅读量:4229 次
发布时间:2019-05-26

本文共 2957 字,大约阅读时间需要 9 分钟。

一、多表查询

 

  • 1.复制表

将源表复制为新表(Key字段不会被复制)

create table 新表名  select * from 源表;
将指定查询结果复制为新表(Key字段值不会被复制)
create table 新表 SQL查询语句;
       
mysql> create table xinbiao select * from mysql.user;
mysql>create table xinbiao0 select user,host,password 
->from mysql.user;

复制源表的结构到新表

create table xb1 select * from 源表 where false(条件为假)或可以随便写个不成立的条件;

 

  • 2.多表查询

2.1)多表查询

select 字段名列表 from 表A,表B;笛卡尔集(表记录个数相乘(表A*表B)的积是查询结果)
----select * from t1,t2 

select 字段名列表 from 表A,表B where 条件;
-----select t1.*  t2.hmoedir from t1,t2 where ti.name="root" and t2.name="root"

2.2)where嵌套查询

select 字段名列表 from 表名 where 条件 (select 字段名列表 from 表名 where 条件);
-----select name from mysql.t1 where name in (select name from db1.t1);
-----select name,age from user where age<(select avg(age) from user);

2.3)左连接查询
select 字段名列表 from 表名a left join 表名b on 条件;
-----select * from t3 left join t4 on t3.uid = t4.uid;

2.4)右连接查询
select 字段名列表 from 表名a right join 表名b on 条件;
-----select * from t3 right join t4 on t3.uid = t4.uid;

-----------------------------------------------------------------------------------------------

二、mysql管理工具

命令行
安装图形软件
web页面

  • 常见管理工具

步骤1:yum -y install httpd php php-mysql

systemctl start/enable  httpd

步骤2:解包,可修改下名字便捷点;部署到网站目录

tar -xf phpMyAdmin-2.11.11-all-languages.tar.gz -C /var/www/html/
cd /var/www/html/ 
mv phpMyAdmin-2.11.11-all-languages   admin(随便取)

步骤3:修改软件配置文件

]# cp config.sample.inc.php config.inc.php
]# vim config.inc.php
17 $cfg['blowfish_secret'] = 'plj123';
31 $cfg['Servers'][$i]['host'] = 'localhost';

创建授权用户

4 在客户端254(真机)访问软件  http://192.168.4.50/admin
5 使用数据库管理登陆

三、Mysql管理密码

密码忘了怎么办?

  • 1.停止mysql服务
  • 2.]#vim /etc/my.cnf

[mysqld]

skip-grant-tables #跳过授权启动mysql服务程序
#validate_password_policy=0  密码策略注释
#validate_password_length=6

  • 3.重设root密码(更新user表记录)

]# mysql                         #直接进数据库

mysql>update mysql.user set authentication_string=password("密码")
where user="root" and host="localhost";
mysql>flush privileges;
可参考查看mysql.user的表结构(desc mysql.user)

  • 4.正常启动mysql

 

  • 5.vim /etc/my.cnf

#skip-grant-tables  注释掉

validate_password_policy=0         #密码策略
validate_password_length=6
plugin-load=validate_password.so #加载模块默认有【可不写】
再重启

知道密码的情况下修改密码
]#mysqladmin -uroot -p旧密码 password "新密码"
 

修改表记录来修改密码

> update mysql.user set password = password('zhangsannew') where user = 'zhangsan' and host = '%';

> flush privileges;

 

mysql表下关于权限的表

 

  1. user表:存储已有的授权用户
  2. db表:存储授权用户对数据库的访问权限
  3. tables_priv表:存储授权用户对表的访问权限
  4. columns_priv表:存储授权用户对字段的访问权限

 

查看用户的权限

  • show user();
  • show grants;
  • show grants for 用户@客户端地址;

grant配置授权
grant 权限列表[replication slave主从权限/all] on  库.表 to 用户@"客户端地址[%所有]" identified by "密码"[with grant option授权权限];

重设密码mysql>set passwprd=password("新密码");
 mysql>set password for 用户名@"客户端地址"=password(新密码)

撤销权限
revoke 权限列表[all] on 库.表 from 用户名@"客户端地址";

show grants; 查看权限

 

*.*  所有库所有表,all 匹配所有权限, %匹配所有主机

mysql  授权库

  • user 表  ,存储授权用户的访问权限
  • db表 , 存储授权用户对数据库的访问权限
  • tables_priv表 , 存储授权用户对表的访问权限
  • columns_priv表 , 存储授权用户对字段的访问权限

 

 

删除用户

1. > drop user 用户@'主机';

2.  > delete from mysql.user where user='XXX' and host='localhost';

     > flush privileges;

 

转载地址:http://sriqi.baihongyu.com/

你可能感兴趣的文章
QoS Over Heterogeneous Networks
查看>>
Workflow in the 2007 Microsoft Office System
查看>>
IPv6 Advanced Protocols Implementation
查看>>
Pro InfoPath 2007
查看>>
Beginning VB 2005 Databases: From Novice to Professional
查看>>
Inside SQLite
查看>>
How to Cheat at Configuring Open Source Security Tools
查看>>
Microsoft SharePoint: Building Office 2007 Solutions in C# 2005
查看>>
Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional
查看>>
Beginning JBoss® Seam: From Novice to Professional
查看>>
Professional XML
查看>>
Foundations of Security: What Every Programmer Needs to Know
查看>>
Pro WF: Windows Workflow in .NET 3.0
查看>>
Beginning SQL Server 2005 Express for Developers: From Novice to Professional
查看>>
Multimedia over IP and Wireless Networks: Compression, Networking, and Systems
查看>>
Hacking Ubuntu: Serious Hacks Mods and Customizations
查看>>
PHP 5 Advanced: Visual QuickPro Guide
查看>>
Adobe Illustrator CS3 Classroom in a Book
查看>>
Sams Teach Yourself Adobe Photoshop CS3 in 24 Hours
查看>>
FileMaker Pro 8.5 Bible
查看>>