2019独角兽企业重金招聘Python工程师标准>>>
登录MariaDB
- 正常情况使用密码登录MariaDB,-p后面是密码
mysql -uroot -ppasscode
重置root密码
- 如果忘记root密码
- 编辑/etc/my.cnf,增加:skip-grant,重启服务
[root@localhost ~]# vi /etc/my.cnf [mysqld] datadir=/data/mysql socket=/tmp/mysql.sock skip-grant [root@localhost ~]# /etc/init.d/mysqld restart
- 登录MariaDB
mysql -uroot
- 执行
use mysql
切换到mysql库 desc user
查看user表的所有字段update user set authentication_string=password("mima.abc") where user='root';
命令来更改root密码。- 退出MariaDB,删除/etc/my.cnf里面的skip-grant, 重启服务
- 用新密码登录即可
补充
- 使用root用户登录到MariaDB,
use mysql
切换库,然后查看用户有哪些
MariaDB [mysql]> select user,host from user ;
+------+-----------------------+
| user | host |
+------+-----------------------+
| bbs | 127.0.0.1 |
| blog | 127.0.0.1 |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+------+-----------------------+
8 rows in set (0.006 sec)
- 更改普通用户密码
MariaDB [mysql]> update user set authentication_string=password("mima.123") where user='blog';
Query OK, 1 row affected (0.005 sec)
Rows matched: 1 Changed: 1 Warnings: 0
就可以了。
常识
mysql在5.7.36版本之后把密码字段存到了authentication_string字段里,在之前版本存在password字段里。