考虑:
./mysqladmin -u root -p** '_redacted_'
输出(包括输入密码):
输入密码: Mysqladmin: connect to server at 'localhost' failed错误 '用户'root'@'localhost'(使用密码:YES)拒绝访问'
我该如何解决这个问题?
考虑:
./mysqladmin -u root -p** '_redacted_'
输出(包括输入密码):
输入密码: Mysqladmin: connect to server at 'localhost' failed错误 '用户'root'@'localhost'(使用密码:YES)拒绝访问'
我该如何解决这个问题?
当前回答
如果你像我一样,在前面的答案中所有的信息都失败了,继续卸载你机器上的所有版本的MySQL,使用命令sudo find / name " MySQL "和rm -rf每个附加" MySQL "名称的文件或目录(你应该跳过与编程语言库相关的文件)搜索所有剩余的MySQL文件。
现在安装一个新版本的MySQL,开始享受吧。注:你将失去所有的数据,所以先权衡你的选择。
其他回答
窗口:
cd \ampps\mysql\bin :
mysql.exe -u root -pmysql
mysql启动后(可以看到shell是这样的mysql>) 使用这个查询:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
请再次使用root访问
之前的答案都没有帮助我解决这个问题,所以这里是我找到的解决方案。
相关部分:
In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) to access the user. In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password. To do this, open up the MySQL prompt from your terminal: sudo mysql Next, check which authentication method each of your MySQL user accounts use with the following command: SELECT user,authentication_string,plugin,host FROM mysql.user; Output +------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | | auth_socket | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec) In this example, you can see that the root user does in fact authenticate using the auth_socket plugin. To configure the root account to authenticate with a password, run the following ALTER USER command. Be sure to change password to a strong password of your choosing, and note that this command will change the root password you set in Step 2: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; Then, run FLUSH PRIVILEGES which tells the server to reload the grant tables and put your new changes into effect: FLUSH PRIVILEGES; Check the authentication methods employed by each of your users again to confirm that root no longer authenticates using the auth_socket plugin: SELECT user,authentication_string,plugin,host FROM mysql.user; Output +------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | *3636DACC8616D997782ADD0839F92C1571D6D78F | mysql_native_password | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *CC744277A401A7D25BE1CA89AFF17BF607F876FF | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec) You can see in this example output that the root MySQL user now authenticates using a password. Once you confirm this on your own server, you can exit the MySQL shell: exit
啊,对我来说什么都没用!我有一台运行MariaDB 5.5.64的CentOS 7.4机器。
我必须这么做,在YUM安装MariaDB之后;
systemctl restart mariadb
mysql_secure_installation
mysql_secure_installation将带您完成许多步骤,包括“设置根密码?”[Y / n]”。只要输入“y”并输入密码。随你怎么回答其他问题。
然后你可以用你的密码,使用
mysql -u root -p
它会存活下来
systemctl restart mariadb
的关键
然后,我检查了/bin/mysql_secure_installation源代码,看看它是如何神奇地改变根密码的,而这里的其他答案都不能。导入位是:
do_query "UPDATE mysql.user SET Password=PASSWORD('$esc_pass') WHERE User='root';"
...上面写着SET Password=…而不是SET authentication_string = PASSWORD....因此,本版本(5.5.64)的正确步骤是:
使用mysql -u root -p登录,使用您已经设置的密码。
或者,停止数据库并启动它:
mysql_safe --skip-grant-tables --skip-networking &
从mysql>提示符:
use mysql;
select host,user,password from user where user = 'root';
(observe your existing passwords for root).
UPDATE mysql.user set Password = PASSWORD('your_new_cleartext_password') where user = 'root' AND host = 'localhost';
select host,user,password from user where user = 'root';
flush privileges;
quit;
停止运行mysqld_safe。重启MariaDB。以root用户登录:mysql -u -p。请使用新密码。
如果您愿意,您可以一次设置所有的根密码。我认为这是明智的:
mysql -u root -p
(login)
use mysql;
select host,user,password from user where user = 'root';
UPDATE mysql.user set Password = PASSWORD('your_new_cleartext_password') where user = 'root';
select host,user,password from user where user = 'root';
flush privileges;
quit;
这将执行更新所有的根密码:即,“localhost”,“127.0.0.1”,和“::1”
将来,当我去RHEL 8或其他什么时候,我会试着记得检查/bin/mysql_secure_installation,看看那些家伙是怎么做的,谁是为这个操作系统配置MariaDB的人。
使用sudo修改密码:
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password';
来源:Phoenixnap -拒绝访问用户根localhost
对于Ubuntu/Debian用户
(它可能适用于其他发行版,尤其是基于debian的发行版。)
运行以下命令以root身份连接(不需要任何密码)
sudo /usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf
如果你不想每次以根用户连接时都添加——defaults-file,你可以将/etc/mysql/debian.cnf复制到你的主目录:
sudo cp /etc/mysql/debian.cnf ~/.my.cnf
然后:
sudo mysql