首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法登录到MySQL

问无法登录到MySQL
EN

Stack Overflow用户
提问于 2014-09-25 09:25:20
回答 1查看 120关注 0票数 0

我使用以下命令安装了MySQL:

代码语言:javascript
复制
sudo apt-get install mysql-server mysql-client mysql-common

它要求我输入root密码(在包配置中),我输入一个并确认。

代码语言:javascript
复制
sudo /etc/init.d/mysql start

但是,当我尝试使用上一步中提供的root用户和密码登录mysql时,它拒绝我访问:

代码语言:javascript
复制
root@mbilwebh02:/etc# > mysql --user root --password
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES).

我做的另一个尝试是在不提供密码的情况下卸载并重新安装mysql,但也失败了。

然后,我将服务器上的用户切换到mysql

代码语言:javascript
复制
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”用户,因此我尝试的所有内容都拒绝访问。但我不知道这是不是一种安全的方式。

EN

回答 1

Stack Overflow用户

发布于 2014-09-25 15:02:56

摘自:http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

代码语言:javascript
复制
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选项)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26029038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档