MySQL-重置密码
windows修改密码参考:
方法一: 在my.ini的[mysqld]字段加入: skip-grant-tables 重启mysql服务,这时的mysql不需要密码即可登录数据库 然后进入mysql mysql>use mysql; mysql>更新 update user set password=password('新密码') WHERE User='root'; mysql>flush privileges; 运行之后最后去掉my.ini中的skip-grant-tables,重启mysqld即可。
方法二: 不使用修改my.ini重启服务的方法,通过非服务方式加skip-grant-tables运行mysql来修改mysql密码。 1.停止mysql服务; 2.打开命令行窗口,在bin目录下使用mysqld-nt.exe启动,即在命令行窗口执行: mysqld-nt --skip-grant-tables; 3.然后另外打开一个命令行窗口,登录mysql,此时无需输入mysql密码即可进入; 4.按以上方法修改好密码后,关闭命令行运行mysql的那个窗口,此时即关闭了mysql,如果发现mysql仍在运行的话可以结束掉对应进程来关闭; 启动mysql服务。
linux修改密码参考:
方法一: 1、停止mysql服务 # service mysqld stop 2、mysql配置文件修改为免密码登录。 # vi /etc/my.cfg # Disabling symbolic-links is recommended to prevent assorted security risks skip-grant-tables #添加这句话,这时候登入mysql就不需要密码 symbolic-links=0 3、启动 mysql 服务 # service mysqld start 4、以root身份登录mysql, 输入密码的时候直接回车 # mysql -uroot -p #输入命令回车进入,出现输入密码提示直接回车。 mysql> set password for root@localhost = password('123456'); ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> set password for root@localhost = password('123456'); or update user set authentication_string=PASSWORD("123456") where user="root"; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql>flush privileges; #更新权限 mysql>quit; #退出 # service mysqld stop # 停止mysql服务, 恢复mysql配置 # vi /etc/my.cfg # Disabling symbolic-links is recommended to prevent assorted security risks # skip-grant-tables # 注释掉这句话 symbolic-links=0 # service mysqld start # 启动mysql服务 # mysql -uroot -p # 输入新密码登录
方法二: 为了加强安全性,安装MySQL5.7后会为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。 可通过# grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码 [root@iZ2 ~]# grep "password" /var/log/mysqld.log 2016-04-10T04:53:07.003736Z 1 [Note] A temporary password is generated for root@localhost: dd9FfN/s/&4n 用该密码登录到服务端后,必须马上修改密码,不然会报如下错误: mysql> select user(); ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 如果只是修改为一个简单的密码,会报以下错误: mysql> ALTER USER USER() IDENTIFIED BY '12345678'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 这个其实与validate_password_policy的值有关。刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。
方法三: # /path/mysqladmin -u UserName -h Host password 'new_password' -p 其它方式: MySQL管理者密码设置或修改: 依据官方说明5.6以后版本,第一次启动时会在root目录下生产一个随机密码,文件名.mysql_secret。 [root@bright ~]# cat /root/.mysql_secret # Password set for user 'root@localhost' at 2015-03-27 23:12:10 :Jj+FTiqvyrF [root@bright ~]# cd /usr/local/mysql/bin/ [root@bright bin]# ./mysqladmin -u root -h localhost password '123456' -p Enter password: #此行输入.mysql_secret里第二行内容 mysqladmin: [Warning] Using a password on the command line interface can be insecure. Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety. 官方的方式,笔者无论是否使用--skip-grant-tables启动mysql都测试失败,亲们可以测试: shell>mysql -uroot -p'password' #password即.mysql_secret里的密码 mysql>SET PASSWORD = PASSWORD('newpasswd'); 还有一种方式: 在安装的时候不生成随机密码,用sudo mysqld --initialize-insecure 然后在自己设置密码 sudo /usr/bin/mysqladmin -uroot password 密码 设置密码查考链接:http://www.myhack58.com/Article/sort099/sort0102/2015/60511.htm 修改密码 mysql >ALTER USER USER() IDENTIFIED BY '12345678'; mysql>update mysql.user set authentication_string=password('newpassword') where User="root" and Host="localhost"; mysql>flush privileges; //刷新系统权限表 mysql>set password=password("newpassword"); // 修改自己的密码 Query OK, 0 rows affected, 1 warning (0.00 sec)