Linux 安装 MySQL 8.0
Posted 百变小怪兽
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 安装 MySQL 8.0相关的知识,希望对你有一定的参考价值。
Linux 安装 mysql 8.0
Docker 安装 MySQL 8.0
-
安装 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
-
拉取 MySQL 镜像
# docker pull mysql/mysql-server # docker images REPOSITORY TAG IMAGE ID CREATED SIZE mysql/mysql-server latest a7a39f15d42d 2 months ago 381MB
-
启动 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
-
进入 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>
-
添加远程登录用户 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的主要内容,如果未能解决你的问题,请参考以下文章
Linux 系统 centos7 安装 MySQL 8.0 图文并茂教程
MySQL入门:Linux 6 RPM方式安装MySQL 8.0
Linux下的 Mysql 8.0 yum 安装 并修改密码