Ubuntu 20.04 安装 Mysql 8.0

Ubuntu 20.04 安装 Mysql 8.0 数据库

本文以 Ubuntu(20.04) 和 Mysql(8.0) 为例,介绍 Ubuntu 安装 Mysql 教程及设置远程访问权限。

安装Mysql

  1. 更新源列表 (可以忽略)
    sudo apt-get update
    
  2. 安装mysql
    sudo apt install mysql-server
    
  3. 查看mysql状态
    service mysql status
    
    ● mysql.service - MySQL Community Server
        Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
        Active: active (running) since Fri 2022-05-27 11:48:42 CST; 3h 1min ago
       Process: 3159851 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
      Main PID: 3159872 (mysqld)
        Status: "Server is operational"
         Tasks: 40 (limit: 2274)
        Memory: 371.7M
        CGroup: /system.slice/mysql.service
                └─3159872 /usr/sbin/mysqld
    
  4. 查看mysql版本
    mysql -V
    

设置远程访问

  1. 登陆mysql (安装完成后,默认没有密码直接登陆)

    mysql -u root
    
  2. 查看库

    mysql> show databases;
    

    ±-------------------+
    | Database |
    ±-------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | sys |
    | test |
    ±-------------------+

  3. 选择库

    mysql> use mysql;
    
  4. 修改密码

    alter user root@localhost identified with mysql_native_password by '密码';
    
    Query OK, 0 rows affected (0.01 sec)      #执行成功
    
  5. 创建新用户

    create user '新用户名'@'%' identified with mysql_native_password by '密码';
    
  6. 设置远程访问权限

    grant all privileges on *.* to 'root(用户名)'@'%' with grant option;
    
  7. 刷新策略

    flush privileges;
    
  8. 修改配置文件

    vi /etc/mysql/mysql.conf.d/mysqld.cnf 
    
    # Instead of skip-networking the default is now to listen only on
    # localhost which is more compatible and is not less secure.
    # bind-address           = 127.0.0.1           #注释这行
    
  9. 重启mysql服务

     service mysql restart
    
  10. 测试远程连接

    mysql -h ip地址 -u 用户名 -p 
    

亲测有效,还请好友多多支持。

你可能感兴趣的:(Ubuntu,Unix,Mysql,mysql,ubuntu,数据库)