共计 3472 个字符,预计需要花费 9 分钟才能阅读完成。
环境
- Linux/Ubuntu20.04LTS
- mysql-client-core-8.0
- mysql-server-8.0 (8.0.23-0ubuntu0.20.04.1)
流程
- 关上终端,查看是否装置了 MySQL
lauiji@lauiji-IdeaPad-15sIML-2020:~$ mysql
Command 'mysql' not found, but can be installed with:
sudo apt install mysql-client-core-8.0 # version 8.0.23-0ubuntu0.20.04.1, or
sudo apt install mariadb-client-core-10.3 # version 1:10.3.25-0ubuntu0.20.04.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) 的触发器 ...
- 查看运行服务 $ systemctl status mysql
lauiji@lauiji-IdeaPad-15sIML-2020:~$ systemctl status mysql
Unit mysql.service could not be found.
- 装置服务
sudo apt-get update #更新源
sudo apt-get install mysql-server #装置
lauiji@lauiji-IdeaPad-15sIML-2020:~$ sudo apt-get install mysql-server
update-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.log
mysqld is running as pid 19429
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
这时就装置实现了!
- 查看运行服务
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
- 装置实现后如何登录到数据库呢?明码啥?
刚装置完的数据库还没有明码,明码为空, 间接回车即可,登录到数据库批改明码
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 8
Server 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 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> 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)
- 设置明码
设置你的 root 登录明码,这里举例为 123456
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)
- 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
- 应用新密码从新登录
mysql> quit;
Bye
lauiji@lauiji-IdeaPad-15sIML-2020:/etc/mysql$ mysql -u root -p
Enter password:
提醒 :MySQL8.0 的版本更改了 root 账户的受权形式,默认是 auth_socket。也就是说须要通过 Unix socket 文件来验证所有连贯到 localhost 的用户,不能应用提供明码的形式了。
- 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
正文完