当前位置:网站首页>Linux安装Mysql8(小白必看)
Linux安装Mysql8(小白必看)
2022-07-21 10:30:00 【'小王'】
一、Mysql8安装包下载
1、迅雷复制链接下载
https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
2、百度网盘获取
https://pan.baidu.com/s/1vxVEL7q7CQvPPLlK-ZUWEQ
提取码:whrs
3、mysql官网下载
https://www.mysql.com/downloads/
注意:迅雷下载链接和网盘获取的版本都是8.0.22吗,自己下载的话,记得相关命令中改掉版本号
二、安装步骤
1.上传安装包
1)、将安装包上传至服务器的 /usr/local 文件夹下
[[email protected] ~]# cd /usr/local
[[email protected] local]# ls
bin etc games include lib lib64 libexec mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz sbin share src
2)、解压
[[email protected] local]# tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
3)、更改文件夹名称
[[email protected] local]# mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql
4)、修改配置文件
[[email protected] local]# vim /etc/my.cnf
全部copy进去
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
character-set-server=utf8
sql_mode =STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
:wq 回车保存退出
5)、新建用户和用户组并进入mysql 文件下赋予权限
[[email protected] mysql]# cd /usr/local/mysql/
[[email protected] mysql]# groupadd mysql
[[email protected] mysql]# useradd -r -g mysql mysql
[[email protected] mysql]# chown -R mysql:mysql ./
6)、初始化数据库
[[email protected] mysql]# mkdir ./data
[[email protected] mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize ;
初始化之后,最后一行有初始化密码。需要记住
7)、把msyql 添加到系统服务
[[email protected] mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysql
[[email protected] mysql]# chmod +x /etc/init.d/mysql #权限
[[email protected] mysql]# chkconfig --add mysql
[[email protected] mysql]# chkconfig --list mysql #检查是否生效
8)、建立软连接
[[email protected] bin]# ln -s /usr/local/mysql/bin/mysql /usr/bin
9)、启动MYSQL服务
[[email protected] mysql]# service mysql start
Starting MySQL.. SUCCESS!
10)、登陆Mysql
mysql -u root -p
mysql -u root -p
输入刚刚的密码(一定要盲输入密码,直接拼接在-p后面会无效)
13)、修改密码
ALTER USER "root"@"localhost" IDENTIFIED BY "你的新密码";
FLUSH PRIVILEGES; #配置生效
14)、打开连接 数据库连接工具
use mysql;
update user set host='%' where user ='root';
FLUSH PRIVILEGES; #配置生效
三、docker安装
安装所需的包。yum-utils提供了yum-config-manager 效用,并device-mapper-persistent-data和lvm2由需要 devicemapper存储驱动程序
1、[[email protected] ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
设置稳定存储库
2、[[email protected] ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装Docker CE
3、[[email protected] ~]# yum install -y docker-ce docker-ce-cli containerd.io
验证docker安装是否成功
[[email protected] ~]# docker --version
Docker version 19.03.13, build 4484c46d9d
3.1、配置加速器
mkdir /etc/docker
cd /etc/docker
vim daemon.json
#以下内容粘贴进daemon.json中
{
"registry-mirrors" : [
"https://mirror.ccs.tencentyun.com",
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}
#重启
systemctl restart docker.service
docker pull mysql
#启动
docker run --name mysql -p 3306:3306 -v /mysql/datadir:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql
参数说明:
--name: 以什么名字启动容器
-p 3306:3306 :将容器端口映射到服务器端口
-v /mysql/datadir:/var/lib/mysql :将mysql的配置路径映射到本地datadir上
-e MYSQL_ROOT_PASSWORD=123456 :设置服务器密码为123456
-d mysql:需要启动的容器的名称
[root@localhost docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
680af9d51d7b mysql "docker-entrypoint.s…" 15 minutes ago Up 15 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp mysql
#进入容器内部并登录mysql
[root@localhost docker]# docker exec -it 680af9d51d7b sh
# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.23 MySQL Community Server - GPL
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>
边栏推荐
- CodeQL使用流程
- word文档中动态生成excel表格(基金公告系列讲解)
- 【Numpy学习记录】np.cov详解
- CodeQL使用流程
- 大小端模式说明
- 【 apprentissage automatique】 regroupement kmeans
- 2019 Niuke summer multi school training camp (the fifth session) g- subsequence 1 [number of dp+ combinations]
- DAY 5 (数组)
- 剑指 Offer 45. 把数组排成最小的数
- Self made CA certificate for configuring SSL
猜你喜欢
如何使用加密狗加密自己程序
Codeql usage process
map文件如何导出教程
Digitalization of museums - development of digital collections app
【论文笔记】Modeling Task Relationships in Multi-task Learning withMulti-gate Mixture-of-Experts
CodeQL使用流程
vivo官网APP全机型UI适配方案
Codeforces round 578 (Div. 2) C - round corridor [number theory + Law]
CMake系列教程2-HelloWorld
B站自定义倍数代码
随机推荐
jdbc 09: preparedStatement实现增删改查
[machine learning] hierarchical clustering
CGI的介绍及简单应用
【机器学习】层次聚类
剑指 Offer 46. 把数字翻译成字符串
Codeforces round 578 (Div. 2) B - block adventure [greed]
Anaconda common commands
jdbc 02: 连接mysql,并实现删除与更新
Educational codeforces round 70 a question you are given two binary strings
博物馆数字化——数字藏品app开发
day 2
17 shortcut keys commonly used by QT Creator
matplotlib. Pyplot interface summary
Mutex and smart pointer replace read-write lock
Multi process single thread multi port TCPUDP three-layer protocol forwarding
简析redux技术栈(二):认识saga的buffer和chanel
Introduction and simple application of CGI
Codeforces Round #579 (Div. 3) A 、B、E
[paper notes] objectbox: from centers to boxes for anchor free object detection
如何使用界面控件Telerik UI for WinForms开发步骤进度条?