大网数据广告活动
服务器运维问答

MySQL root password not working as expected

· 52CE 我爱测

I am running MariaDB 10.0.24 on Ubuntu 16.04. I installed it via the xenial repo apt-get install mariadb-server . The root password doesn't seem to be working properly. I ran through these steps to set the password: http://dev.my…

问题原文

原帖链接 · Guerrilla · CC BY-SA 3.0

I am running MariaDB 10.0.24 on Ubuntu 16.04. I installed it via the xenial repo apt-get install mariadb-server.

The root password doesn't seem to be working properly. I ran through these steps to set the password: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html but I get the following behaviour:

When I do sudo mysql or sudo mysql -u root it gets me into console without asking for password (why can I get in without password?)

When I do sudo mysql -u root -p it asks me for a password but will let me into mysql console regardless of what string I enter. Why does it let me in when giving an incorrect password?

When I do mysql -u root it asks me for password but will not accept the password I set following the instructions in the linked article.

Something is obviously not right. Does anyone know why its not asking for password from root at all and not accepting password from my user?

已采纳解答

原帖链接 · abkrim · CC BY-SA 3.0

sudo mysql && sudo mysql -u root it's redundant command. Not assks for password because you have a file named /root/.my.cnf with with client name and password

sudo mysql -u root -pask for passowrd because you put -p in your coammand (see man mysql)

·   --password[=password], -p[password]

           The password to use when connecting to the server. If you use the short option form (-p), you cannot have a
           space between the option and the password. If you omit the password value following the --password or -p option
           on the command line, mysql prompts for one.

           Specifying a password on the command line should be considered insecure. See Section 6.1.2.1, “End-User
           Guidelines for Password Security”. You can use an option file to avoid giving the password on the command line.

Please read En-user guidelines for Password Security

Especially for the user question

As Ubuntu 16.04 uses Xenial this is a little peculiar in the way they control certain things, and working with a plug that affects as we used many system administrators.

mysql> use mysql; mysql> update user set plugin='' where User='root'; mysql> flush privileges;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。