Debian12(Bookworm)安装MySQL

配置MySQL APT Repository

  1. 下载mysql-apt-config

    目前mysql-apt-config的最新版本是0.8.33,下载地址为https://dev.mysql.com/downloads/repo/apt/

  2. 安装和更新仓库

    sudo dpkg -i mysql-apt-config_0.8.33-1_all.deb
    sudo aptitude update
    

安装MySQL

  1. 安装MySQL-server

    安装过程中,需要配置root帐号密码

api mysql-server
  1. 查看状态

    systemctl status mysql
    ● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
      Active: active (running) since Sat 2024-10-19 20:37:06 HKT; 36s ago
        Docs: man:mysqld(8)
              http://dev.mysql.com/doc/refman/en/using-systemd.html
    Main PID: 1933672 (mysqld)
      Status: "Server is operational"
       Tasks: 38 (limit: 9462)
      Memory: 362.9M
         CPU: 678ms
      CGroup: /system.slice/mysql.service
              └─1933672 /usr/sbin/mysqld
    
  2. 登录MySQL

    使用前面设置的密码,用root帐号登录

mysql -h localhost -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.40 MySQL Community Server - GPL

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.
  1. 配置远程登录

    默认情况下Mysql只能本地登录,当然,新增一个用户更好,配置指定数据的权限,而不是root帐号进行远程访问。 进入mysql数据库,可以查看root帐号是localhost访问权限

use mysql
mysql> select Host,User from user where User='root';
+-----------+------+
| Host      | User |
+-----------+------+
| localhost | root |
+-----------+------+

配置root帐号远程访问权限

mysql> update user set host = '%' where User = 'root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

再次查看权限是否修改

mysql> select Host,User from user where User='root';
+------+------+
| Host | User |
+------+------+
| %    | root |
+------+------+

刷新权限,否则仍然无法远程访问,然后即可通过其他客户端进行远程访问了。

mysql> flush privileges;

results matching ""

    No results matching ""

    results matching ""

      No results matching ""