ubuntu20安装mysql8

1.安装

sudo apt update
sudo apt install mysql-server-8.0 -y

2.查看运行状态

yantao@ubuntu20:~$ sudo systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: active (running) since Sun 2024-02-04 16:40:44 CST; 18h ago
    Process: 875 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=ex>
   Main PID: 959 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 9830)
     Memory: 370.2M
     CGroup: /system.slice/mysql.service
             └─959 /usr/sbin/mysqld

3.设置开机启动

sudo systemctl enable mysql

4.登录到 MySQL 服务器

sudo mysql -u root -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.36-0ubuntu0.20.04.1 (Ubuntu)

Copyright (c) 2000, 2024, 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> 


5.在项目中,避免使用 root 账号是提高数据库安全性的一个重要步骤。以下是创建非 root 用户并分配权限的建议操作:

创建新用户: 创建一个新用户,并为其设置密码和主机限制(这里假设创建一个仅限本地访问的用户 appuser)。

CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'your_strong_password';

赋予特定数据库权限: 授予新用户对某个数据库的所有权限。例如,如果你有一个名为 your_database 的数据库,可以这样操作:

GRANT ALL PRIVILEGES ON your_database.* TO 'appuser'@'localhost';

刷新权限: 执行以下命令使权限更改立即生效:

FLUSH PRIVILEGES;

退出MySQL控制台

EXIT;

你可能感兴趣的:(MySQL,Linux,ubuntu,mysql)