环境

  • Linux/Ubuntu20.04LTS
  • mysql-client-core-8.0
  • mysql-server-8.0 (8.0.23-0ubuntu0.20.04.1)

流程

  1. 关上终端,查看是否装置了MySQL
lauiji@lauiji-IdeaPad-15sIML-2020:~$ mysqlCommand 'mysql' not found, but can be installed with:sudo apt install mysql-client-core-8.0     # version 8.0.23-0ubuntu0.20.04.1, orsudo apt install mariadb-client-core-10.3  # version 1:10.3.25-0ubuntu0.20.04.1
  1. 按提醒装置一下
lauiji@lauiji-IdeaPad-15sIML-2020:~$ sudo apt install mysql-client-core-8.0获取:1 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 mysql-client-core-8.0 amd64 8.0.23-0ubuntu0.20.04.1 [4,215 kB]正在设置 mysql-client-core-8.0 (8.0.23-0ubuntu0.20.04.1) ...正在解决用于 man-db (2.9.1-1) 的触发器 ...
  1. 查看运行服务 $ systemctl status mysql
lauiji@lauiji-IdeaPad-15sIML-2020:~$ systemctl status mysqlUnit mysql.service could not be found.
  1. 装置服务
sudo apt-get update  #更新源sudo apt-get install mysql-server #装置
lauiji@lauiji-IdeaPad-15sIML-2020:~$ sudo apt-get install mysql-serverupdate-alternatives: 应用 /var/lib/mecab/dic/ipadic-utf8 来在主动模式中提供 /var/lib/mecab/dic/debian (mecab-dictionary)正在设置 mysql-server-8.0 (8.0.23-0ubuntu0.20.04.1) ...update-alternatives: 应用 /etc/mysql/mysql.cnf 来在主动模式中提供 /etc/mysql/my.cnf (my.cnf)Renaming removed key_buffer and myisam-recover options (if present)mysqld will log errors to /var/log/mysql/error.logmysqld is running as pid 19429Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.

这时就装置实现了!

  1. 查看运行服务
lauiji@lauiji-IdeaPad-15sIML-2020:~$ systemctl status mysql● mysql.service - MySQL Community Server     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>     Active: active (running) since Sat 2021-07-03 10:48:52 CST; 24h ago    Process: 947 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=ex>   Main PID: 991 (mysqld)     Status: "Server is operational"      Tasks: 38 (limit: 13995)     Memory: 402.8M     CGroup: /system.slice/mysql.service             └─991 /usr/sbin/mysqld
  1. 装置实现后如何登录到数据库呢?明码啥?
刚装置完的数据库还没有明码,明码为空,间接回车即可,登录到数据库批改明码
lauiji@lauiji-IdeaPad-15sIML-2020:/etc/mysql$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 8Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu)Copyright (c) 2000, 2021, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || sys                |+--------------------+4 rows in set (0.01 sec)

这里root就是咱们方才连贯的账户, debian-sys-maint 账号是在装置MySQL主动产生的,能够通过上面的命令查看到它,$ sudo cat /etc/mysql/debian.cnf

mysql> select User, Host from mysql.user;+------------------+-----------+| User             | Host      |+------------------+-----------+| debian-sys-maint | localhost || mysql.infoschema | localhost || mysql.session    | localhost || mysql.sys        | localhost || root             | localhost |+------------------+-----------+5 rows in set (0.00 sec)
  1. 设置明码
设置你的root登录明码,这里举例为 123456
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';Query OK, 0 rows affected (0.00 sec)
  1. 刷新权限
mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)
  1. 应用新密码从新登录
mysql> quit;Byelauiji@lauiji-IdeaPad-15sIML-2020:/etc/mysql$ mysql -u root -pEnter password: 

提醒:MySQL8.0的版本更改了root账户的受权形式,默认是auth_socket。也就是说须要通过 Unix socket 文件来验证所有连贯到localhost的用户,不能应用提供明码的形式了。

  1. linux环境装置mysql5.7 和 mysql8.0初始密码的区别
linux装置完mysql5.7和8.0初始密码是不一样的。

一、mysql5.7初始密码

   linux装置MySQL5.7,mysql为root用户随机生成了一个明码在error log中,   error log的地位默认是/var/log/mysqld.log,启动过一次才能够查看长期明码,   $ grep 'temporary password' /var/log/mysqld.log

二、mysql8.0初始密码

    Mysql8.0装置root账号的初始密码是没有的,间接回车就可登录,不必输明码    输出登录mysql命令 $ mysql -u root -p

【遇上旱季,吃定彩虹】 --Layuji