打开/etc/my.cnf文件,
[mysqld]加上:skip-grant-tables
重启mysql服务
[root@cons7s ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
这时可以直接进来改改码了
MariaDB [(none)]> 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
MariaDB [mysql]> UPDATE user SET Password = password ( 'zabbix' ) WHERE User = 'root' ;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
MariaDB [mysql]> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> quit
改好以后将/etc/my.cnf刚才加入的那一行注释掉,重启服务,输入刚才设定的密码zabbix,这样密码就生效了
[root@cons7s ~]# systemctl restart mariadb
[root@cons7s ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@cons7s ~]# mysql -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>