mysqladmin只能用于mysql没有密码时的情况,但Centos7下,安装mysql5.7后都会自带root原始密码,可以用原始密码登陆进去然后再修改,或者skip跳过密码进入数据库修改密码。
-------------------------------------------------------
一、先停止mysql服务
[root@localhost /]# systemctl stop mysqld.service
二、使用--skip-grant-tables启动mysql,跳过授权登陆验证(这个方法有几种,还有在配置文件写--skip语句的)
[root@localhost /]# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
三、启动mysql并且登陆
[root@localhost /]# systemctl start mysqld.service //启动mysql
[root@localhost /]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
.....中间省略....
mysql>
四、修改密码并且刷新权限
mysql> update mysql.user SET authentication_string = PASSWORD('123456') WHERE User = 'root' AND Host = 'localhost';
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>
完成!