报错
[root@master ~]# mysql -uroot -p123456
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
方法一
[root@master ~]# vim /etc/my.cnf #修改mysql主配置文件
......
[mysqld]
skip-grant-tables ##添加此句
.......
[root@master ~]# systemctl restart mariadb
[root@master ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, 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;
MariaDB [mysql]> update user set password=password("000000") where user="root";
MariaDB [mysql]> flush privileges;
[root@master ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables ###将此句删除,恢复原状###
[root@master ~]# systemctl restart mariadb
[root@master ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.003 sec)
方法二
重开大法(数据库已有东西不推荐)
[root@master ~]# systemctl stop mariad
[root@master ~]# yum remove -y mariadb mariadb-server
[root@master ~]# rm -rf /etc/my.cnf
[root@master ~]# rm -rf /var/lib/mysql
[root@master ~]# yum install -y mariadb mariadb-server
[root@master ~]# systemctl enable mariadb --now
[root@master ~]# mysql_secure_installation
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] N
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@master ~]# mysql -uroot -p000000
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.3.20-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
》》》》》》》》完成《《《《《《《