Mysql多表查询语句,授权用户与密码更改
一、多表查询
- 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 "新密码"
mysql表下关于权限的表
- user表:存储已有的授权用户
- db表:存储授权用户对数据库的访问权限
- tables_priv表:存储授权用户对表的访问权限
- 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表 , 存储授权用户对字段的访问权限