本文摘要:
1. 新建用户 并 指定密码
2. 修改密码
3. 忘记密码的解决方案
新建用户并指定密码
1)[windows | linux] mysql -uroot -p
Enter password:******
mysql> create user ‘keyman‘@‘127.0.0.1‘ identified by ‘keyman‘;
mysql> grant usage on *.* to ‘harry‘@‘127.0.0.1‘ identified by ‘harry‘;
mysql> exit
[windows | linux] mysql -ukeyman -pkeyman -h127.0.0.1
mysql> exit
[windows | linux] mysql -uharry -pharry -h127.0.0.1
mysql修改密码的方法总结如下
1) [windows | linux] mysql -uroot -p
mysql> set password for ‘keyman‘@‘127.0.0.1‘ = password(‘keyman123‘);
mysql> flush privileges;
//下面的语句只能修改自己的密码
mysql> set password = password(‘keyman123‘);
2) [windows | linux] mysql -uroot -p
mysql> grant usage on *.* to ‘keyman‘@‘127.0.0.1‘ identified by ‘keyman123‘;
3) [windows | linux] mysql -uroot -h127.0.0.1 -p password "new_password"
忘记密码的解决方案
1)停止mysql数据库
[windows] net stop mysql
[linux] service mysqld stop
2) 以不加载授权表的方式启动数据库
[windows | linux] add below line to my.ini or my.cnf configuration file
[mysqld]
......................
skip-grant-tables
......................
[windows] net start mysql
[linux] service mysqld start
3) 登陆数据库并修改密码
[windows | linux] mysql -uroot mysql
mysql> update user set password=password(‘new_password‘) where user = ‘root‘;
mysql> flush privileges;
mysql> exit
4) 重新启动数据库
[windows | linux] remove ‘skip-grant-tables‘ from configuration file
[windows] net stop mysql
[windows] net start mysql
[linux] service mysqld restart
5) 使用新密码进行登陆
[windows | linux] mysql -uroot -pnew_password
mysql>
以上内容仅供参考,如有遗误,望请谅解。