安装

$ sudo apt install mysql-server

查看默认账号密码

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

修改密码

$ mysql -udebian-sys-maint -pJRvfA0JiQGk5qhnz
mysql>USE mysql;

// mysql 5.7
mysql>UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql>update mysql.user set authentication_string=password('xxx') where User='root' and Host='localhost';
// mysql 8.0
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'xxx';

mysql>flush privileges;
mysql>exit;

标签: ubuntu, mysql

添加新评论