ubuntu18.04安装mysql 5.7 没有设置密码解决方案

Ubuntu在安装mysql5.7时,会出现没有设置密码的情况,解决方案如下:

终端输入: sudo cat /etc/mysql/debian.cnf

显示内容:

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = PGBiNPneSGXRlayQ
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = PGBiNPneSGXRlayQ
socket   = /var/run/mysqld/mysqld.sock

其中有user和password可以用来登录,登录后再修改密码;

终端输入:mysql -u debian-sys-maint -p ,再输入密码后,进入mysql中

elcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> show databases;
mysql> use mysql;
mysql> update user set authentication_string=PASSWORD("root") where user="root";

mysql> update user set plugin="mysql_native_password";
mysql> flush privileges;
mysql> quit;

其中PASSWORD后面的root可以为其他自定义的密码,

在终端中输入 sudo /etc/init.d/mysql restart; 命令,重启mysql服务

使用新密码登录mysql:mysql -u root -p

卸载mysql的命令:

sudo apt purge mysql-*

 sudo rm -rf /etc/mysql/  /var/lib/mysql

sudo apt autoremove

安装mysql的命令

sudo apt-get install mysql-client  mysql-server

查看mysql状态

sudo service mysql status

查看mysql服务器端口

sudo netstat -tap |grep mysql

开启、停止和重启mysql服务

sudo service mysql  start

sudo service mysql  stop

sudo service mysql  restart

 

你可能感兴趣的:(ubuntu学习之路)