我如何让 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 脚本自动生成的。请勿触摸!

相关内容