我使用以下命令安装了MySQL:
sudo apt-get install mysql-server mysql-client mysql-common它要求我输入root密码(在包配置中),我输入一个并确认。
sudo /etc/init.d/mysql start但是,当我尝试使用上一步中提供的root用户和密码登录mysql时,它拒绝我访问:
root@mbilwebh02:/etc# > mysql --user root --password
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).我做的另一个尝试是在不提供密码的情况下卸载并重新安装mysql,但也失败了。
然后,我将服务器上的用户切换到mysql
root@mbilwebh02:/etc# sudo -u mysql -s
root@mbilwebh02:/etc# sudo -u mysql -s
bash: /root/.bashrc: Permission denied
mysql@mbilwebh02:/etc$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)此时,我只能启动和停止mysql。你知道我可能会错在哪里吗?
编辑
经过多次搜索,我发现可以使用debian-sys-maint作为用户名和debian.cnf文件中的密码登录到mysql。mysql数据库中没有“root”用户,因此我尝试的所有内容都拒绝访问。但我不知道这是不是一种安全的方式。
发布于 2014-09-25 15:02:56
摘自:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.
Connect to the mysqld server with this command:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change. 现在,您应该能够使用新密码以超级用户身份连接到MySQL服务器。停止服务器,然后正常地重新启动它(不使用--skip-grant-tables和--skip-networking选项)。
https://stackoverflow.com/questions/26029038
复制相似问题