美文网首页
Ubuntu 20安装mysql8

Ubuntu 20安装mysql8

作者: 彩色的炮灰 | 来源:发表于2021-10-26 17:26 被阅读0次

    查看Ubuntu版本信息:

    (base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# cat /etc/lsb-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=20.04
    DISTRIB_CODENAME=focal
    DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
    (base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# 
    

    ubuntu20 apt 源里的mysql 已经更新到 8.0, 可以直接安装

    安装

    sudo apt update # 更新源
    sudo apt install mysql-server #安装
    安装完成后查看msyql版本:

    (base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# mysql -V
    mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
    

    mysql 服务的状态管理

    systemctl status mysql # 查看状态,装完后默认就启动了,默认开机启动
    sudo systemctl disable mysql # 关闭开机启动
    sudo systemctl disable mysql # 设置开机启动
    sudo systemctl start mysql # 启动 mysql 服务
    sudo systemctl stop mysql # 关闭 mysql 服务

    默认用户

    sudo mysql # 使用 root 用户连入 mysql, 默认不需要密码
    sudo cat /etc/mysql/debian.cnf # 这里提供了另一个默认账户和密码 debian-sys-maint,密码是明文,只能在本地登录

    我们使用mysql空密码登陆,输入:mysql -uroot -p后回车,显示输入密码,第一次登陆默认密码为空,直接回车即可登录mysql。

    (base) root@iZbp1bdi32t0s1dsw2bwrmZ:~# mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 8.0.27-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> 
    

    登陆mysql后我们先修改一下root账号密码,密码规则这里是长度为8位,有大写字母,小写字母。还有特符号。

    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql>show databases;
    mysql>use mysql;
    mysql>CREATE USER 'root'@'%' IDENTIFIED BY 'Abcd@1234';
    mysql>GRANT ALL ON *.* TO 'root'@'%';
    mysql>ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Abcd@1234';
    

    允许远程连接

    mysql默认只能从本地登录,允许从远程登录需要修改绑定地址.

    修改配置文件,绑定ip修改为 0.0.0.0
    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

    #bind-address            = 127.0.0.1
    bind-address            = 0.0.0.0
    
    

    重启mysql服务
    sudo systemctl restart mysql.service

    创建数据库

    卸载 mysql

    sudo rm /var/lib/mysql/ -R
    sudo rm /etc/mysql/ -R
    sudo apt autoremove mysql* --purge

    相关文章

      网友评论

          本文标题:Ubuntu 20安装mysql8

          本文链接:https://www.haomeiwen.com/subject/hgryaltx.html