考虑:
./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)拒绝访问'
我该如何解决这个问题?
当前回答
'-p'参数不要求参数名和值之间有空格。
而不是
./mysqladmin -u root -p 'redacted'
Use
./mysqladmin -u root -p'redacted'
或者只是
./mysqladmin -u root -p
这将提示您输入密码。
其他回答
我这样做是为了在OS x中MySQL的初始设置中设置我的根密码。
sudo sh -c 'echo /usr/local/mysql/bin > /etc/paths.d/mysql'
关闭终端并打开一个新终端。
在Linux中,可以使用以下方法设置根密码。
sudo /usr/local/mysql/support-files/mysql.server stop
sudo mysqld_safe --skip-grant-tables
(sudo mysqld_safe——skip-grant-tables:第一次对我不起作用。但在第二次尝试时,成功了。)
然后登录MySQL:
mysql -u root
FLUSH PRIVILEGES;
现在修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
重新启动MySQL:
sudo /usr/local/mysql/support-files/mysql.server stop
sudo /usr/local/mysql/support-files/mysql.server start
对于新Linux用户来说,这可能是一项艰巨的任务。让我用MySQL 8更新这个(目前可用的最新版本是8.0.12,截至2018-09-12)
Open "mysqld.cnf" configuration file at "/etc/mysql/mysql.conf.d/". Add skip-grant-tables to the next line of [mysql] text and save. Restart the MySQL service as "sudo service mysql restart". Now your MySQL is free of any authentication. Connect to the MySQL client (also known as mysql-shell) as mysql -u root -p. There is no password to be keyed in as of now. Run SQL command flush privileges; Reset the password now as ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword'; Now let's get back to the normal state; remove that line "skip-grant-tables" from "mysqld.cnf" and restart the service.
就是这样。
在Arch Linux上
软件包:mysql 8.0.29-1
对我有用的是:
Edit my.cnf file, normally can be found at /etc/mysql/my.cnf and append this skip-grant-tables at the bottom/end of the file. Restart mysql service by invoking sudo systemctl restart mysqld Ensuring mysql service has started properly by invoking sudo systemctl status mysqld Login to mysql using 'root' by invoking mysql -u root -p Flush privileges by invoking flush privileges; Create new user by CREATE USER 'root'@'localhost' IDENTIFIED BY 'rootpassword'; (If you plan to use this db with PHP), you should instead use this CREATE USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'rootpassword'; Check whether your changes have reflected in db by invoking the following in sequence: use mysql; SELECT User, password_last_changed FROM user; Exit mysql console and comment/remove skip-grant-tables by editing my.cnf file (Refer to step 1 for the location) Restart the mysql service (Refer to step 2 and step 3)
就这些。
根据MariaDB官方文档,在MariaDB 10.4.3及以后版本中,默认安装了unix_socket身份验证插件。
为了禁用它,并恢复到前面的mysql_native_password认证方法,在my.cnf文件的[mysqld]部分中添加下面的行:
[mysqld]
unix_socket=OFF
然后运行:
mysql_install_db --auth-root-authentication-method=normal
然后启动mysqld
这个命令可以正常工作:
mysqladmin -u root password CHANGEME
有关更多信息,请参见配置mysql_install_db恢复到以前的身份验证方法。
'-p'参数不要求参数名和值之间有空格。
而不是
./mysqladmin -u root -p 'redacted'
Use
./mysqladmin -u root -p'redacted'
或者只是
./mysqladmin -u root -p
这将提示您输入密码。