mysql 5.7版本的数据库下没有password字段,password字段改成了
authentication_string
1.由于当前不知mysql密码,故需要设置跳过密码验证,修改my.cnf配置文件
vi /etc/mysql/my.cnf 添加skip-grant-tables
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
skip-grant-tables
2.重启MySQL, service mysql restart
# service mysql restart
* Stopping MySQL Community Server 5.7.9
...
* MySQL Community Server 5.7.9 is stopped
* Re-starting MySQL Community Server 5.7.9
..
* MySQL Community Server 5.7.9 is started
3.命令行进入mysql
选择mysql数据库use mysql
4.使用mysql语句更新root密码
update user set authentication_string=password('你的密码') where user='root';
若需要修改mysql密码
mysql> alter user 'root'@'localhost' identified by 'root';
这样也可以:set password for 'root'@'localhost'=password('root');
5.更新mysql密码后,将my.cnf文件恢复原状,即删除或注释skip-grant-tables
6.再次重启mysql。service mysql restart
7.测试root密码是否修改成功
不输入密码时,
root@home:# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
输入密码时,
root@home:# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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.
1.由于当前不知mysql密码,故需要设置跳过密码验证,修改my.cnf配置文件
vi /etc/mysql/my.cnf 添加skip-grant-tables
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
skip-grant-tables
2.重启MySQL, service mysql restart
# service mysql restart
* Stopping MySQL Community Server 5.7.9
...
* MySQL Community Server 5.7.9 is stopped
* Re-starting MySQL Community Server 5.7.9
..
* MySQL Community Server 5.7.9 is started
3.命令行进入mysql
选择mysql数据库use mysql
4.使用mysql语句更新root密码
update user set authentication_string=password('你的密码') where user='root';
若需要修改mysql密码
mysql> alter user 'root'@'localhost' identified by 'root';
这样也可以:set password for 'root'@'localhost'=password('root');
5.更新mysql密码后,将my.cnf文件恢复原状,即删除或注释skip-grant-tables
6.再次重启mysql。service mysql restart
7.测试root密码是否修改成功
不输入密码时,
root@home:# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
输入密码时,
root@home:# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.9 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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>
参考:
http://blog.csdn.net/u010603691/article/details/50379282
http://www.jb51.net/article/77858.htm
http://blog.csdn.net/gggxwy/article/details/6621627