我如何要求MySQL使用密碼?

我如何要求MySQL使用密碼?

當MySQL啟動和檢查升級時,如何要求MySQL使用root使用者的密碼?

localhost systemd[1]: Started MariaDB 10.3.25 database server.
localhost /etc/mysql/debian-start[1126]: Upgrading MySQL tables if necessary.
localhost systemd[1]: Started OpenLiteSpeed HTTP Server.
localhost /etc/mysql/debian-start[1131]: Looking for 'mysql' as: /usr/bin/mysql
localhost /etc/mysql/debian-start[1131]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
localhost /etc/mysql/debian-start[1131]: Version check failed. Got the following error when calling the 'mysql' command line client
localhost /etc/mysql/debian-start[1131]: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
localhost /etc/mysql/debian-start[1131]: FATAL ERROR: Upgrade failed
localhost /etc/mysql/debian-start[1157]: Checking for insecure root accounts.

我有 root 使用者的密碼,但當 MySQL 啟動時:(using password:

我運行 MariaDB 10.3.25OpenLiteSpeed,Ubuntu 20.04。

答案1

我添加了密碼,/etc/mysql/debian.cnf因為該文件的密碼欄位為空。

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = root
password =
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = root
password =
socket   = /var/run/mysqld/mysqld.sock

現在我已經成功升級MySQL(如果需要的話)MySQL 啟動和伺服器重新啟動。

/etc/mysql/debian-start[961]: Upgrading MySQL tables if necessary.
/etc/mysql/debian-start[975]: Looking for 'mysql' as: /usr/bin/mysql
/etc/mysql/debian-start[975]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
/etc/mysql/debian-start[975]: This installation of MySQL is already upgraded to 10.3.25-MariaDB, use --force if you still need to run mysql_upgrade

看起來其他所有事情都運作良好。

如果我不應該使用此方法,請告訴我,因為/etc/mysql/debian.cnf第一個字串是 # 自動為 Debian 腳本生成。請勿觸摸!

相關內容