linux下对mysql5.7.22,创建用户、授权和修改用户密码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ailo555/article/details/84614474


一、创建用户和授权:


1、root登录后:
mysql -uroot -p 
2、创建用户
mysql>create user 'dev'@'%' identified by 'dev_123456';
3、授权数据库Dev
mysql>grant all privileges on dev.* to 'dev'@'%' identified by 'dev_123456';


二、修改用户密码:

1、vim /etc/my.cnf
在/etc/my.cnf 中添加 skip-grant-tables
2、登录mysql,mysql -uroot -p
3、切换库:mysql> use mysql;
4、修改密码成功:密码要求(必须符合长度,且必须含有数字,小写或大写字母,特殊字符。)
mysql> update user set password=password("你的新密码") where user="root";如果用这个语句修改5.7版本会报错,注意5.7版本没有password字段
改为:update mysql.user set authentication_string=password('xxx') where user='dev'; 
更改root密码: alter user 'root'@'localhost' identified by '密码';
5、刷新生效:mysql> flush privileges;
6、退出:mysql> quit;
7、重启:service mysqld restart
8.验证登录:mysql -uroot -p 
Enter password:输入密码
9.远程连接出现 1130错误:不允许远程连接
设置:update mysql.user set host = '%' where user ='root';
flush privileges; 刷新数据库。

猜你喜欢

转载自blog.csdn.net/ailo555/article/details/84614474