您好,欢迎访问一九零五行业门户网

mysql重置密码

mysql重置密码
wulilidemacbook-pro:bin wulili$ mysql start
error 1045 (28000): access denied for user 'wulili'@'localhost' (using password: no)
wulilidemacbook-pro:bin wulili$ su - root
1、吧mysql服务关闭
2、
 启动mysqld_safe ,跳过启动授权表。启动时加上skip-grant-tables参数目的是在启动mysql时不启动grant-tables,授权表。这样就可以修改root的密码了。
# mysqld_safe --skip-grant-tables &
wulilidemacbook-pro:support-files root# find / -name mysqld_safe
find: /dev/fd/3: not a directory
find: /dev/fd/4: not a directory
/usr/local/mysql-5.7.16-osx10.11-x86_64/bin/mysqld_safe
wulilidemacbook-pro:support-files root# /usr/local/mysql-5.7.16-osx10.11-x86_64/bin/mysqld_safe --skip-grant-tables &
[1] 1397
wulilidemacbook-pro:support-files root# 2016-11-30t11:47:40.6nz mysqld_safe logging to '/usr/local/mysql/data/wulilidemacbook-pro.local.err'.
2016-11-30t11:47:40.6nz mysqld_safe starting mysqld daemon with databases from /usr/local/mysql/data
mysql -uroot -p
enter password: 按下回车键
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 2
server version: 5.7.16 mysql community server (gpl)
copyright (c) 2000, 2016, oracle and/or its affiliates. all rights reserved.
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> update user set password=password('12345678') where user=root; 
error 1046 (3d000): no database selected
mysql> use mysql;
reading table information for completion of table and column names
you can turn off this feature to get a quicker startup with -a
database changed
mysql> update user set password=password('12345678') where user=root; 
error 1054 (42s22): unknown column 'password' in 'field list'
mysql> update user set passwd=password('12345678') where user=root; 
error 1054 (42s22): unknown column 'passwd' in 'field list'
mysql> update user set password=password('12345678') where user='root';
error 1054 (42s22): unknown column 'password' in 'field list'
mysql> update user set authentication_string=password('12345678') where user=root;
query ok, 1 row affected, 1 warning (0.01 sec)
rows matched: 1  changed: 1  warnings: 1
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
mysql> quit
bye
3、重启数据库
wulilidemacbook-pro:support-files root# /usr/local/mysql/support-files/mysql.server restart
shutting down mysql
..2016-11-30t11:58:22.6nz mysqld_safe mysqld from pid file /usr/local/mysql/data/wulilidemacbook-pro.local.pid ended
 success! 
starting mysql
. success! 
[1]+  done                    /usr/local/mysql-5.7.16-osx10.11-x86_64/bin/mysqld_safe --skip-grant-tables
wulilidemacbook-pro:support-files root# mysql -u root -p  这里密码就是12345678了
enter password: 
welcome to the mysql monitor.  commands end with ; or \g.
your mysql connection id is 4
server version: 5.7.16
copyright (c) 2000, 2016, oracle and/or its affiliates. all rights reserved.
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input statement.
mysql> quit
bye
wulilidemacbook-pro:support-files root#
mysql> use mysql;
error 1820 (hy000): you must reset your password using alter user statement before executing this statement.
mysql>  alter user 'root'@'localhost' identified by '12345678';
query ok, 0 rows affected (0.01 sec)
mysql> flush privileges;
query ok, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
其它类似信息

推荐信息