温馨提示×

温馨提示×

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

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

数据库基本使用

发布时间:2020-07-31 05:27:05 来源:网络 阅读:395 作者:阿德001 栏目:MySQL数据库

1.登录和退出mysql服务器
mysql -h主机名 -u用户名 -p密码 -e"sql 命令"
例1:mysql -uroot -p123456 #root用户,密码123456登录数据库。
例2:mysql -uroot -p123456 -e "desc mysql.user" #root用户,密码123456登录并查看user表结构。
例3:mysql -uroot -p123456 mysql #root用户,密码123456登录并直接进入mysql数据库。
2.新建普通用户:
2.1使用create user语句创建新用户。
例: create user zhangsan@localhost identified by "132456"; #创建用户张三,指定密码为123456.
例: create user zhangsan@"%" identified by "123456"; #创建用户张三,指定密码为123456.
2.2使用grant 语句创建用户:
例:grant all on . to zhangsan@localhost identified by "123456"; #创建张三用户并授予对所有数据库的所有表的所有权限。
select from mysql.user where user='zhangsan'\G; #查看zhangsan用户的信息,权限都为 y。
3.删除普通用户:
3.1 例:drop mysql.user zhangsan@localhost; #删除用户zhangsan;
3.2 例:delete from mysql.user where user='zhangsan'; #删除用户zhangsan。
4.root用户修改自己密码:
4.1 mysqladmin -uroot -p123456 password '654321' #命令行修改,-p指定旧密码,引号里为新密码。
4.2 update mysql.user set password=password('123456') where user='root'; flush privileges; #把root用户密码该为123456;刷新权限表。
4.3 set password=password('654321'); #修改root用户密码为123456;
5.root用户修改普通用户密码:
5.1 set password for zhangsan@localhost = password('123456'); #修改zhangsan密码为123456.
5.2 update mysql.user set password=password('123456') where user='zhangsan';flush privileges; #修改zhangsan用户的密码为123456;刷新权限表。
5.3 grant usage on
.* to zhangsan@localhost identified by '123456'; #修改zhangsan用户密码为123456;

  1. 普通用户修改密码:
    6.1 set password=password('123456'); #使用普通用户登录数据库,执行命令。
    7.root用户密码丢失的解决办法:
    7.1 修改配置文件/etc/my.cnf 在【mysql】下添加 skip-grant-tables
    7.2 systemctl restart mariadb #重启服务
    7.3 mysql #登录数据库
    7.4 set password=password('123456'); #修改密码
    7.5 vim /etc/my.cnf 注释掉 #skip-grant-tables
    7.6 systemctl restart mariadb #重启服务
    8.localhost 为本地登录 “%” 为远程登录
向AI问一下细节

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

AI