mysql安装完成后怎么打开_Ubuntu中安装完成mysql后,解决root登录问题

057ffca5a9309947627a98ec866cbcd6.png

1. Ubuntu中安装mysql

sudo apt-get install mysql-server安装,安装完成没有输入root提示密码,怎么登录??

2. 可以打开/etc/mysql/debian.cnf文件:

[client]

host = localhost

user = debian-sys-maint

password = eyPDN7kavhmjCZUn

socket = /var/run/mysqld/mysqld.sock

[mysql_upgrade]

host = localhost

user = debian-sys-maint

password = eyPDN7kavhmjCZUn

socket = /var/run/mysqld/mysqld.sock

使用mysql -u debian-sys-maint -p ,即使用/etc/mysql/debian.cnf文件中的user和password可以登录

3. 登录成功后,可以修改root密码

MySQL5.7之后的版本MySQL5.7之后的版本

update mysql.user set authentication_string=password('newpassword') where user='root'

4. 修改完成后重启mysql 服务

sudo service mysql restart

5. mysql -u root -p 使用上面修改的root密码仍然不能登录,确定用户名和密码正确

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

6. 在使用/etc/mysql/debian.cnf文件中的用户名和密码登录

select user, plugin from mysql.user;

+------------------+-----------------------+

| user | plugin |

+------------------+-----------------------+

| root | auth_socket |

| mysql.session | mysql_native_password |

| mysql.sys | mysql_native_password |

| debian-sys-maint | mysql_native_password |

+------------------+-----------------------+

4 rows in set (0.00 sec)

发现root 的plugin 是auth_socket 的,所有登录不

7. 修改root的plugin 为 mysql_native_password

mysql> update mysql.user set authentication_string=PASSWORD('newPwd'), plugin='mysql_native_password' where user='root';

Query OK, 1 row affected, 1 warning (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

8. 重启服务后,root后正常登录

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值