[Linux]Ubantu20.04下使用apt方式安裝MySql8.0.21過程中不提示設置密碼的解決方法


ubuntu19.+升級到 ubuntu20.04 過程中出錯,直接重裝系統后配置環境

終端apt下載mysql過程中無彈窗提示設置賬戶密碼

找了很多方法可能是版本的原因都不好使

兜兜轉轉最后解決了記錄一下留給有緣人

 

NOTE:  

  如果你是卸載MySql重裝的話,MySql沒卸載干凈也不會提示設置密碼,需要將MySql徹底卸載干凈再重裝

 

下載sql:

1 sudo apt-get update
2 sudo apt-get install -y mysql-server mysql-client

 

查閱系統分配的初始賬號和密碼:

1 sudo gedit /etc/mysql/debian.cnf 

 

顯示:

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

 

用這個賬戶登錄MySql

user: debian-sys-maint

password: aewAdwuHBQVe4IjO

1 mysql -u debian-sys-maint -p
2 Enter password: 輸入密碼 

如果登錄失敗在登錄語句前加 sudo

 

登錄成功會顯示:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.21-0ubuntu0.20.04.4 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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密碼:

1 mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼';

最后退出:

exit;

現在用root賬戶登錄就行了。

 

如果登錄出現下面報錯:

ERROR 1698 (28000): Access denied for user 'mrcangye'@'localhost'

那么在登錄時,語句前面加sudo就可以登錄了

 

解決加sudo便能正常登錄:

進入mysql:

sudo -udebian-sys-maint -paewAdwuHBQVe4IjO

登錄成功后輸入以下以下語句:

ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '你的密碼';

 

最后exit:

exit;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM