查找系统密码,密码是随机的
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>
注意写法引号