温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

mysql 的基本操作以及常用命令

发布时间:2020-04-08 20:19:04 来源:网络 阅读:354 作者:daxiong1314 栏目:数据库

基本操作

show databases;
use 库名;
show tables;
create table 表名 (字段设定列表);
describe 表名;

create database 库名;

drop database 库名;
drop table 表名;

delete from 表名;
select * from 表名;


修改新密码

方法一(我常用的)

在终端输入:mysql -u用户名 -p密码
use mysql;
update user set password=PASSWORD('新密码') where user='用户名';
flush privileges; #更新权限

quit; #退出

方法二:

 用SET PASSWORD命令

mysql -u root

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');

方法三:

用mysqladmin

mysqladmin -u root password "newpass"

如果root已经设置过密码,采用如下方法

mysqladmin -u root password oldpass "newpass"

方法四:

在丢失root密码的时候,可以这样

mysqld_safe --skip-grant-tables&

mysql -u root mysql

mysql> UPDATE user SET password=PASSWORD("new password") WHERE user='root';

mysql> FLUSH PRIVILEGES;


权限


一、创建用户并授权

格式:GRANT 权限 ON 库.表 TO '用户名'@'指定IP' identified by '密码';

GRANT ALL PRIVILEGES ON *.* TO 'daxiong1'@'%' identified by 'daxiong1';
flush privileges;【让上面授权的操作生效】

GRANT ALL PRIVILEGES ON *.* TO 'daxiong2'@'192.168.8.100' identified by 'daxiong2';
flush privileges;【让上面授权的操作生效】

验证:在windows中用Navicat Lite for MySQL工具,使用上面的2个用户,登录咱们的Mysql服务器

GRANT select ON *.* TO 'daxiong3'@'%' identified by 'daxiong3';
flush privileges;【让上面授权的操作生效】

show grants for 用户;【查看指定用户拥有的权限】

revoke all privileges on *.* from '用户'@'%';【收回某用户所有权限】

当用户权限是USAGE时,这个权限最小,他只能登录!

【万能的修改密码】
update mysql.user set password=password('新密码') where user='用户名';
【让权限生效】
flush privileges;

show full processlist; 【查看有哪些用户在登录】

kill  指定用户的id 【强制退出指定用户】

二、增加新用户(借鉴网上的的文章)

格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"

查看用户的权限show grants for root;

revoke  权限 on 数据库.*  from  username;

设置权限时必须给出一下信息

1,要授予的权限

2,被授予访问权限的数据库或表

3,用户名

grant和revoke可以在几个层次上控制访问权限

1,整个服务器,使用 grant ALL  和revoke  ALL

2,整个数据库,使用on  database.*

3,特点表,使用on  database.table

4,特定的列

5,特定的存储过程 

user表中host列的值的意义

%              匹配所有主机

localhost    localhost不会被解析成IP地址,直接通过UNIXsocket连接

127.0.0.1      会通过TCP/IP协议连接,并且只能在本机访问;

::1                 ::1就是兼容支持ipv6的,表示同ipv4的127.0.0.1


MySQL grant 权限,分别可以作用在多个层次上。

1. grant 作用在整个 MySQL 服务器上:

grant select on *.* to dba@localhost; -- dba 可以查询 MySQL 中所有数据库中的表。

grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库

2. grant 作用在单个数据库上:

grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在存储过程、函数上:

grant execute on procedure testdb.pr_add to ’dba’@’localhost’

grant execute on function testdb.fn_add to 'dba'@'localhost'


grant 普通 DBA 管理某个 MySQL 数据库的权限。

grant all privileges on testdb to 'dba'@'localhost'

其中,关键字 “privileges” 可以省略。

grant 高级 DBA 管理 MySQL 中所有数据库的权限。

grant all on *.* to 'dba'@'localhost'

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI