mysql修改root密码,各种报错

查找系统密码,密码是随机的
sudo cat /etc/mysql/debian.cnf

happy@ubuntu:~/Desktop$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = tNEFOyspTEpfQ2Pm
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = tNEFOyspTEpfQ2Pm
socket   = /var/run/mysqld/mysqld.sock

登陆 mysql

appy@ubuntu:~/Desktop$ mysql -u debian-sys-maint -ptNEFOyspTEpfQ2Pm
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.28-0ubuntu0.20.04.3 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

修改root的plugin 才能改密码
修改 update user set plugin=‘mysql_native_password’ where user=‘root’;

mysql> select user,plugin from user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session    | caching_sha2_password |
| mysql.sys        | caching_sha2_password |
| root             | auth_socket           |
+------------------+-----------------------+
5 rows in set (0.00 sec)
mysql> update user set plugin='mysql_native_password' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,plugin from user;
+------------------+-----------------------+
| user             | plugin                |
+------------------+-----------------------+
| debian-sys-maint | caching_sha2_password |
| mysql.infoschema | caching_sha2_password |
| mysql.session    | caching_sha2_password |
| mysql.sys        | caching_sha2_password |
| root             | mysql_native_password |
+------------------+-----------------------+

问题点出在这里,可能版本不同,语法更换
正确命令:

flush privileges;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';(引号问题)
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';(正确)
注意引号,最好到vm手打进去
update user set host='%' where user='root' and host='localhost';
屏蔽配置文件中的绑定地址,可以让外部访问数据库
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

尝试过命令
CREATE USER ‘root’@‘%’ IDENTIFIED BY ‘123456’;
grant all privileges on . to ‘root’@‘%’ ;
update user set authentication_string=password(“123456”),plugin=‘mysql_native_password’ where user=‘root’;
grant all privileges on . to root@‘localhost’ identified by ‘123456’;
grant all privileges on . to root@‘%’ identified by ‘123456’;

mysql> grant all privileges on . to root@‘localhost’ identified by ‘123456’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘123456’’ at line 1
mysql> grant all privileges on . to root@‘%’ identified by ‘123456’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘identified by ‘123456’’ at line 1

mysql> update user set authentication_string=password(“123456”),plugin=‘mysql_native_password’ where user=‘root’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(“123456”),plugin=‘mysql_native_password’ where user=‘root’’ at line 1
mysql> alter user ‘root’@‘localhost’ identified by ‘123456’;
alter user ‘root’@‘localhost’ identified by ‘123456’;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘create database tea6’ at line 2

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘‘123456’’ at line 1
mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
Query OK, 0 rows affected (0.01 sec)

mysql>

注意写法引号

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十倍的快乐

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值