修改Ubuntu下MySQL v8.0.26的root密码 - 解决Linux下安装MySQL 8后无法使用PASSWORD()函数修改root密码的问题

Posted Rudon滨海渔村

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了修改Ubuntu下MySQL v8.0.26的root密码 - 解决Linux下安装MySQL 8后无法使用PASSWORD()函数修改root密码的问题相关的知识,希望对你有一定的参考价值。

核心关键

  1. 使用命令sudo apt install mysql-server mysql-client无法弹出密码设置界面,是因为最新版mysql8需要手动去修改登录密码
  2. mysql8默认不开启用户root,默认用户是debian-sys-maint,其默认密码是存在/etc/mysql/debian.cnf
  3. mysql8已经抛弃PASSWORD()函数
    MySQL :: MySQL 8.0 Reference Manual :: 12.14 Encryption and Compression Functions
  4. mysql8的 数据库mysql 的表user已经没有password字段了
  5. mysql -V检查版本

报错

mysql> update `mysql`.`user` set authentication_string=PASSWORD('root'), `plugin`='mysql_native_password' where `User`='root' and `Host`='localhost';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('root'), `plugin`='mysql_native_password' where `User`='root' and `Host`='local' at line 1
mysql> exit


 

修改Ubuntu下MySQL 8的root密码

关键代码

sudo cat /etc/mysql/debian.cnf

获取到默认账号+密码
user     = debian-sys-maint
password = tZmePZ77d1K7NMWR


mysql -u debian-sys-maint -p
Enter password: 

mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
mysql> flush privileges;
mysql> exit

sudo service mysql restart
mysql -u root -p
Enter password: 

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

mysql> 

详细代码

rudon@rudon-virtual-machine:~$ mysql -V
mysql  Ver 8.0.26-0ubuntu0.21.04.3 for Linux on x86_64 ((Ubuntu))

rudon@rudon-virtual-machine:~$ sudo cat /etc/mysql/debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = tZmePZ77d1K7NMWR
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = tZmePZ77d1K7NMWR
socket   = /var/run/mysqld/mysqld.sock

rudon@rudon-virtual-machine:~$ mysql -u debian-sys-maint -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 14
Server version: 8.0.26-0ubuntu0.21.04.3 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

mysql> 
mysql> 
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
rudon@rudon-virtual-machine:~$ 
rudon@rudon-virtual-machine:~$ sudo service mysql restart
rudon@rudon-virtual-machine:~$ 
rudon@rudon-virtual-machine:~$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \\g.
Your MySQL connection id is 8
Server version: 8.0.26-0ubuntu0.21.04.3 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

mysql> 

 

感谢

MySQL5.7.9版本后废除了Password字段和Password()函数+MySQL登录不了如何修改登录密码?_xiaosi的博客-CSDN博客问题: 最新版的MySQL,我原来root密码是0916,然后执行了update mysql.user set authentication_string='root123' where user='root' and host='localhost'; 这样一段代码,刷新之后新密码老密码都不能用了,这是个啥情况?开始: 原本我以为是少加了password,没加密造成的,后来发现,如果加上:update mysql.user set authenticat...https://xiaosi.blog.csdn.net/article/details/106101633?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link

Ubuntu20.04环境搭建MySQL,修改初始化密码失败以及解决办法_Mr_M1的博客-CSDN博客我在Ubuntu中学习装载MySQL的时候,按照操作一路向下,发现居然没有提醒我设置账号以及密码,我滴个乖乖,搞得我下载的MySQL,我还不能用了,不能忍下这口气,经过我查询了很多资料以及百度的教程来看,绝大部分都是过时的解决方法,对应的MySQL版本早就过时了。问题描述: 首先得确保你使用的是sudo apt-get install mysql-server命令安装的MySQL,这个命令安装的MySQL默认是最新版本,此方法只针对此命令下载的MySQL,如果你是手动安装的...https://blog.csdn.net/Mr_M1/article/details/119635941
最新版的MySql移除了PASSWORD函数_weixin_42077204的博客-CSDN博客_mysql password函数没了本人闲着没事的时候下了最新版的django和mysql准备试试django的模板功能,在往mysql的user表中添加新用户时老是报错。。。提示是password()这个函数有毒。。。没办法去翻MySQL8.0.11的R&M。。。发现在function中该版本移除了password()。。。搬运个地址自己去找加密函数吧。。。https://dev.mysql.com/doc/ref...https://blog.csdn.net/weixin_42077204/article/details/81095270Ubuntu20.04.4配置mysql8.0.21初始密码并新增用户_song696969的博客-CSDN博客Ubuntu20.04.4配置mysql8.0.21初始密码并新增用户下载mysql进入mysql更改mysql默认root用户密码新增用户并赋权设置远程访问下载mysqlsudo apt-get update # 更新源sudo apt-get install mysql-server # 安装mysqlsudo service mysql restart # 重启mysql进入mysqlsudo mysql # 回车后 输入系统用户密码更改mysql默认root用户密码https://blog.csdn.net/song696969/article/details/109008502

安装mysql-server之后,root用户不能登录问题 - Daemonnnn - 博客园解决步骤: step1 step2 step3 修改root用户的密码 参考 "mysql查看数据库、表的基本命令" step4 附录 Windows10 忘记 mysql 5.7https://www.cnblogs.com/daemonFlY/p/10917707.htmllinux mysql root登录_解决linux下mysql-server在root账户下无需密码就能登陆的问题_知乎视频的博客-CSDN博客似乎只要coding,这些代码就要跟我过不去似的今天在linux上安装了mysql-server,想不到竟然被一个及其简单的问题给难住了。是的,我竟然无法登陆!!!在论坛,百度,google上苦苦搜寻了半天,终于找到了问题所在。本质上还是自己数据库学习的不够扎实导致的问题。废话不多说,直接上问题和解决方法。问题描述在ubuntu中安装mysql已经极其方便,只需要使用一个指令就ok了:sudo a...https://blog.csdn.net/weixin_29790175/article/details/113583618ubuntu18.04 安装mysql不出现设置 root 帐户的密码问题_edwin-klp-CSDN博客MySQL Server 5.7的安装:sudo apt install mysql-server mysql-client在安装过程中,它会要求你设置 mysql 服务器 root 帐户的密码。确认 root 帐户的密码ps:我在安装时没有出现上述两个窗口我安装时只有直接安装成功没有弹出任何窗口所以mysql -u root -p空格报错了这时需要sudo vim /etc/mysql/debi...https://blog.csdn.net/NeptuneClouds/article/details/80995759mysql版本号怎么看_徊忆羽菲-CSDN博客_查看mysql版本的命令怎么看mysql版本号1. 在命令行中直接查看版本号2. 在 mysql --help 中查找与版本相关的信息3. 在mysql命令行里面查看版本信息4. 在mysql命令号里面查看status中的版本信息1. 在命令行中直接查看版本号mysql -V2. 在 mysql --help 中查找与版本相关的信息mysql --help | grep Ver3. 在mysql命令行里面查看版本信息mysql -u root -pselect version();4. 在mysql命https://blog.csdn.net/guo_qiangqiang/article/details/107607815给linux默认mysql设置root密码 - 晨羲 - 博客园linux默认mysql的root是没有密码的,必须设置密码,否则你懂得。此外正式应用不会使用root权限,需要另建用户另外授权,一个应用一个用户一个库一套授权,这样才安全,不至于root权限被获取,https://www.cnblogs.com/chyg/archive/2012/09/25/2701308.htmlUbuntu19.04 安装mysql8 以及关于初始密码的解决_诗水人间-CSDN博客apt-get autoremove --purge mysql-server-版本号apt-get autoremove mysql-serverapt-get remove mysql-commondpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P卸载完成!开始安装: sudo apt-get install my...https://blog.csdn.net/qq_41813208/article/details/100264847Ubuntu18.04安装MySQL8.0解决root用户密码登录不成功问题_CSDN-CSDN博客1.问题Ubuntu18.04 安装采用sudo apt install mysql-server 后,发现在安装过程中没有提示设置root密码,但是登录的时候还要求输入root密码,百度各种,依然没有解决问题。 并且安装MySQL8.0时虽然设置了root密码,但是该密码进不去。2.解决首先考虑的就是版本问题,考虑Ubuntu18.04是否还兼容MySQL,问题1中直接用命令安装...https://blog.csdn.net/zyqblog/article/details/80159990

 

 

以上是关于修改Ubuntu下MySQL v8.0.26的root密码 - 解决Linux下安装MySQL 8后无法使用PASSWORD()函数修改root密码的问题的主要内容,如果未能解决你的问题,请参考以下文章

ubuntu16下mysql忘记密码修改

Ubuntu修改WEB数据库MySQL的密码方法和windows下修改MySQL密码

Ubuntu 16.04.1下修改MySQL默认编码

ubuntu下修改mysql默认data路径

ubuntu下MySQL中文乱码(新版本Mysql修改方法)

Ubuntu16.04下修改MySQL数据的默认存储位置