mysql基础


第一种方式:safe_mysqld --skip-grant-tables&  忘记密码如何进入mysql
第二种方式:
# vi /etc/my.cnf
在[mysqld]的段中加上的skip-grant-tables,改完后,就删除

select host,user,password from mysql.user;//即可查看到用户和密码
mysql 5.6
update user set password=password("new_pass") where user="root";// 'new_pass' 这里改为你要设置的密码
flush privileges;
exit

mysql 5.7.22发现:通过修改mysql.user表中的authentication_string字段来修改密码无效,查阅资料后发现要这样:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_pass';

mysql 8.0.11又变了:
alter user 'root'@'localhost' IDENTIFIED BY 'new_pass';

mariadb 10.3.x更改密码的方式:

update user set password = password("your password"),authentication_string=password("your password") where user='root';


查看授权
show grants for root@localhost;

建用户授权
grant select,insert on *.* to test@'%' identified by 'test';

grant all privileges on *.* to root@localhost identified by '123456';//所有权限

删除用户
delete from mysql.user user='root'
delete from mysql.user where user='root' and ip='localhost'; 

原文地址:https://www.cnblogs.com/nfyx/p/9244560.html