今天准备在本地服务器(可外网访问)安装一个默认模板的wordpress程序,来学习一下wordpress。结果在执行的著名的5分钟安装的时候发现数据库连接不上。尝试了各种密码都显示不对,这时候只好想到重置数据库的root账户密码:
首先修改mysql配置文件my.conf,在[mysql]后添加skip-grant-tables
[mysqld] skip-grant-tables port = 3306 socket = /tmp/mysql.sock
2.重启mysql服务
service mysqld restart
3.直接进入mysql终端重置root的密码
[root@OfficeServer ~]# mysql -uroot -p
直接按两次回车,跳过输入密码进入了mysql终端
4.开始重置root密码:
MySQL [(none)]>update mysql.user set password=password('你要设置的密码') where user='root';
这个时候发现报错了
MySQL [(none)]>Unknown column 'password' in 'field list'
因为数据库版本的问题,5.7版本的用户表已经没了password字段,改成了authentication_string
[root@OfficeServer ~]# mysql -V mysql Ver 14.14 Distrib 5.7.14, for linux-glibc2.5 (x86_64) using EditLine wrapper
所以重置密码需要这样:
MySQL [(none)]>update mysql.user set authentication_string=password('你要设置的密码') where user='root';
然后再刷新下系统授权表
MySQL [(none)]>flush privileges;
MySQL [(none)]>grant all on *.* to 'root'@'localhost' identified by '你的密码' with grant option;
6.再去mysql配置文件去掉skip-grant-tables
7.再次重启mysql服务