MYSQL账户、密码修改
cmd窗口下登录mysql
登录:mysql -u账户名 -p
查看mysql库中现有的账户:select user from mysql.user;
连接到mysql库:use mysql;
mysql数据库中有一个user表,表中有用户名user、权限host、密码authentication_string等字段。
修改账户名:update user set user = ‘xxxx’ where user = ‘root’;
修改密码(旧版mysql中user表有password字段,新版用authentication_string字段代替原来的password,修改密码还是用password()函数):
update user set authentication_string=password(‘xxxxx’) where user=’root’ and host=’localhost’;
更新系统权限:flush privileges;
新版8.0MySQL密码修改
alter user ‘root’@’localhost’ identified by ‘baijin’;
无需刷新权限,即可使用新密码登录。
创建新账户,为新账户授予权限
使用root账户登录mysql,创建新账户:
格式:create user ‘username’@’host’ identified by ‘password’;
eg:create user ‘fengbao’@’host’ identified by ‘123’;
为新账户授权
首先为新账户创建一个数据库testDB:create database testDB;
为新账户授予最高权限:grant all privileges on testDB.* to fengbao@localhost identified by ‘123’;
更新系统权限:flush privileges;
退出后,可以用新账户登录mysql
删除账户:delete from user where user=’fengbao’;
更新系统权限:flush privileges;
忘记账户或者密码时,跳过权限,强制登录mysql
以管理员身份登录cmd,停止mysql服务:net stop mysql
进入mysql安装目录bin文件下,进入mysql的安全模式:
mysqld -nt –skip-grant-tables
重新打开一个cmd窗口,输入mysql -uroot -p,使用空密码登录mysql
查看账户:select user from mysql.user;
修改密码:
update user set authentication_string=password(‘xxx’) where user=’账户名’ and host=’localhost’;
更新权限:flush privileges;
退出:quit
调出任务管理器,结束mysql -nt.exe安全模式进程。