码迷,mamicode.com
首页 > 数据库 > 详细

Linux 安装 MySQL 8.0

时间:2020-03-27 12:43:52      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:word   https   exit   eal   run   inux   安装 mysql   oca   utils   

Linux 安装 MySQL 8.0

MySQL 官网

Docker 安装 MySQL 8.0

  1. 安装 Docker

    # yum install -y yum-utils device-mapper-persistent-data lvm2
    # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
    # yum install -y docker-ce docker-ce-cli containerd.io
    # systemctl start docker
    # systemctl enable docker
    
  2. 拉取 MySQL 镜像

    # docker pull mysql/mysql-server
    # docker images
    REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
    mysql/mysql-server   latest              a7a39f15d42d        2 months ago        381MB
    
  3. 启动 MySQL 服务器实例

    # groupadd mysql
    # useradd -r -g mysql -s /bin/false mysql
    # mkdir -p /data/mysql/{data,etc,lib}
    # chown -R mysql:mysql /data/mysql
    # vim /data/mysql/etc/my.cnf
    [mysql]
    default-character-set=utf8
    socket=/var/lib/mysql/mysql.sock
    
    [mysqld]
    skip-name-resolve
    port = 3306
    socket=/var/lib/mysql/mysql.sock
    basedir=/usr/local/mysql
    datadir=/var/lib/mysql/data
    max_connections=200
    character-set-server=utf8
    default-storage-engine=INNODB
    max_allowed_packet=16M
    # docker run -p 3306:3306 --name mysql -v /data/mysql/:/usr/local/mysql -v /data/mysql/etc:/etc/mysql -v /data/mysql/data:/var/lib/mysql/data -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server:latest
    # docker ps -a
    CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                            PORTS                               NAMES
    f62fe1f82601        mysql/mysql-server:latest   "/entrypoint.sh mysq…"   8 seconds ago       Up 7 seconds (health: starting)   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql
    
  4. 进入 mysql,并访问

    # docker exec -it mysql /bin/bash
    # mysql -uroot -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 18
    Server version: 8.0.19 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    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> 
    
  5. 添加远程登录用户 mysql 并访问 docker 实例 mysql

    mysql> CREATE USER ‘mysql‘@‘%‘ IDENTIFIED WITH mysql_native_password BY ‘asdf1234‘;
    mysql> GRANT ALL PRIVILEGES ON *.* TO ‘mysql‘@‘%‘;
    mysql> flush privileges;
    mysql> exit
    # exit
    # mysql -h 172.40.0.31 -u mysql -p
    

Linux 安装 MySQL 8.0

标签:word   https   exit   eal   run   inux   安装 mysql   oca   utils   

原文地址:https://www.cnblogs.com/littermonster/p/12580358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!