修改配置文件/etc/my.cnf
cd /etc/my.cnf
在[mysqld]下面添加一行
[mysqld]
skip-grant-tables
重启服务后,就不需要密码就可以登录
systemctl restart mariadb
mysql -uroot
无需输入密码按下enter键就可以进入数据库了
进入数据库进行修改 方法一:
[root@localhost ~]
MariaDB [(none)]> use mysql;
MariaDB [mysql]> UPDATE mysql.user SET password = PASSWORD('newpassward') WHERE user = 'root';
MariaDB [mysql]> FLUSH PRIVILEGES;
方法二:
[root@localhost ~]
MariaDB [(none)]> use mysql;
MariaDB [mysql]> SET password=PASSWORD('newpassward');
MariaDB [mysql]> FLUSH PRIVILEGES;
方法三:
[root@localhost ~]
[root@localhost ~]
后面再把/etc/my.cnf里面的skip-grant-tables删掉重启服务就行了
|