一分钟安装和配置 MySQL(基于Multipass 和Ubuntu 22.04)

勤奋不是嘴上说说而已,而是实际的行动,在勤奋的苦度中持之以恒,永不退却。业精于勤,荒于嬉;行成于思,毁于随。在人生的仕途上,我们毫不迟疑地选择勤奋,她是几乎于世界上一切成就的催产婆。只要我们拥着勤奋去思考,拥着勤奋的手去耕耘,用抱勤奋的心去对待工作,浪迹红尘而坚韧不拔,那么,我们的生命就会绽放火花,让人生的时光更加的闪亮而精彩。

导读:本篇文章讲解 一分钟安装和配置 MySQL(基于Multipass 和Ubuntu 22.04),希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

一分钟安装和配置 MySQL(基于Multipass 和Ubuntu 22.04)

前面我们介绍了【安装虚拟机和Linux环境(基于Multipass和Virtual Box的Ubuntu)】。
本文介绍如何通过multipass 快速安装和配置 MySQL数据库。

创建虚拟机

通过multipass launch 命令创建一台虚拟机。

C:\Users\Administrator>multipass list
No instances found.

C:\Users\Administrator>multipass launch -n mysql-vm
Launched: mysql-vm

C:\Users\Administrator>multipass list
Name                    State             IPv4             Image
mysql-vm                Running           N/A              Ubuntu 22.04 LTS

C:\Users\Administrator>multipass info mysql-vm
Name:           mysql-vm
State:          Running
IPv4:           N/A
Release:        Ubuntu 22.04.2 LTS
Image hash:     345fbbb6ec82 (Ubuntu 22.04 LTS)
Load:           0.08 0.02 0.01
Disk usage:     1.4G out of 4.7G
Memory usage:   178.5M out of 969.5M
Mounts:         --

C:\Users\Administrator>

连接这台虚拟机。

C:\Users\Administrator>multipass shell mysql-vm
Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.0-67-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sun Mar 26 08:51:26 CST 2023

  System load:  0.0               Processes:               86
  Usage of /:   30.9% of 4.67GB   Users logged in:         0
  Memory usage: 21%               IPv4 address for enp0s3: 10.0.2.15
  Swap usage:   0%


 * Introducing Expanded Security Maintenance for Applications.
   Receive updates to over 25,000 software packages with your
   Ubuntu Pro subscription. Free for personal use.

     https://ubuntu.com/pro

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update

To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

ubuntu@mysql-vm:~$

安装MySQL

使用的主要命令:

sudo apt update
sudo apt show mysql-server
sudo apt install mysql-server
sudo systemctl start mysql.service

1. 升级apt仓库为最新

ubuntu@mysql-vm:~$ sudo apt update

2. 安装mysql-server

ubuntu@mysql-vm:~$ sudo apt install mysql-server

查看服务器的状态。

ubuntu@mysql-vm:~$ sudo systemctl start mysql.service
ubuntu@mysql-vm:~$ sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-03-26 09:00:03 CST; 27s ago
    Process: 4074 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 4084 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 1116)
     Memory: 358.1M
        CPU: 1.123s
     CGroup: /system.slice/mysql.service
             └─4084 /usr/sbin/mysqld

Mar 26 09:00:02 mysql-vm systemd[1]: Starting MySQL Community Server...
Mar 26 09:00:03 mysql-vm systemd[1]: Started MySQL Community Server.
ubuntu@mysql-vm:~$

如果未启动,通过下面的命令启动。

sudo systemctl start mysql.service

初始化配置MySQL

进入mysql

ubuntu@mysql-vm:~$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, 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.00 sec)

mysql>

修改root用户的密码

修改root用户的密码为rootroot。

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'rootroot';
Query OK, 0 rows affected (0.01 sec)

mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

查看用户信息。

mysql> select User,authentication_string,Host from mysql.user;
+------------------+------------------------------------------------------------------------+-----------+
| User             | authentication_string                                                  | Host      |
+------------------+------------------------------------------------------------------------+-----------+
| debian-sys-maint | $A$005$;+GAh1A?rIAa^W=tG4leu19sgs1gd8MOLJGcPMLGRHLAuf5SoGIJg4rsoz. | localhost |
| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |
| root             | *6C362347EBEAA7DF44F6D34884615A35095E80EB                              | localhost |
+------------------+------------------------------------------------------------------------+-----------+
5 rows in set (0.00 sec)

mysql>

使用root登录mysql

退出并重新登录mysql

mysql> exit
Bye
ubuntu@mysql-vm:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.32-0ubuntu0.22.04.2 (Ubuntu)

Copyright (c) 2000, 2023, 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的虚拟机

之后我们就可以通过multipass启动安装了MySQL的虚拟机,然后我们就可以开启MySQL数据库之旅了。

multipass list
multipass shell <虚拟机名>

例:

C:\Users\Administrator>multipass list
Name                    State             IPv4             Image
mysql-vm                Stopped           --               Ubuntu 20.04 LTS
pg-vm                   Stopped           --               Ubuntu 20.04 LTS

C:\Users\Administrator>multipass shell mysql-vm
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-121-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 System information disabled due to load higher than 1.0

 * Super-optimized for small spaces - read how we shrank the memory
   footprint of MicroK8s to make it the smallest full K8s around.

   https://ubuntu.com/blog/microk8s-memory-optimisation

1 update can be applied immediately.
To see these additional updates run: apt list --upgradable

New release '22.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Last login: Sun Sep 11 22:05:29 2022 from 10.0.2.2
ubuntu@mysql-vm:~$

其他参考:服务相关操作

启动和停止mysql服务的命令如下。

systemctl  start mysld.service
systemctl stop mysld.service
systemctl  status mysld.service
service mysql status

例:

ubuntu@mysql-vm:~$ service mysql status
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-09-12 20:52:54 CST; 7min ago
    Process: 608 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 717 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 1131)
     Memory: 423.6M
     CGroup: /system.slice/mysql.service
             └─717 /usr/sbin/mysqld

Sep 12 20:52:49 mysql-vm systemd[1]: Starting MySQL Community Server...
Sep 12 20:52:54 mysql-vm systemd[1]: Started MySQL Community Server.

这样一个简单的MySQL环境就算构筑完成了。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由半码博客整理,本文链接:https://www.bmabk.com/index.php/post/141588.html

(0)

相关推荐

发表回复

登录后才能评论
半码博客——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!