Mysql安装

windows安装

  • 官网下载压缩包,路径为https://dev.mysql.com/downloads/mysql/,直接解压,如:E:\SoftWar\mysql-5.7.20-winx64
  • 在安装目录下建立一个my.ini的文件,内容如下,注意修改basedir和datadir。(datadir路径有时候需要写出 E:\\)
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=E:\SoftWar\mysql-5.7.20-winx64
# 设置mysql数据库的数据的存放目录
datadir=E:\SoftWar\mysql-5.7.20-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
  • 用管理员启动cmd,找到安装目录,如E:\SoftWar\mysql-5.7.20-winx64\bin,输入mysqld  --initialize-insecure。

会报 缺失dll文件,确实文件弄好后,DirectX Repair V3.5修复一下

  • 完成之后输入mysqld install ,看此时有没有成功

  • 如果失败,则输入mysqld remove,寻找原因,成功则输入net start mysql

  • 输入mysql -u root -p,不用输密码,直接回车即可

  • 继续输入update mysql.user set authentication_string=password('root') where user='root' ;

  • 输入flush privileges;

  • 最后查询结果select user();

  • 至此,mysql安装完成

 

Linux安装(yum)

  • 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  • 安装mysql源
yum -y install mysql57-community-release-el7-11.noarch.rpm
  • 查看安装效果
yum repolist enabled | grep mysql.*
  • 安装mysql服务器
yum install mysql-community-server
  • 启动服务
systemctl start  mysqld.service
  • 查看运行状态
systemctl status mysqld.service
  • 查看初始密码
grep "password" /var/log/mysqld.log
  • 登陆
mysql -u root -p
  • 修改密码(***是自己的密码)
ALTER USER 'root'@'localhost' IDENTIFIED BY '****************';
  • 数据库授权
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '******' WITH GRANT OPTION;

      立即生效

mysql>FLUSH PRIVILEGES;
  • 设置开机启动
systemctl enable mysqld
systemctl daemon-reload
  • 查看mysql的编码集
mysql> show variables like "%char%";

 

docker安装

docker 使用教程 https://blog.csdn.net/zgsxhdzxl/article/category/8746390

  • docker方式不推荐生成环境使用,因为异常情况下可能造成数据丢失,自己玩无所谓。
  • 首先下载镜像
docker images
docker pull mysql
  • 最简单运行方式(设置自己的密码)
docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d f991c
  • 发现无法登录,由于下载的最新的mysql,加密规则有变化,所以修改密码
首先要用exec进入mysql容器内部,命令见百度
mysql -u root -p
然后输入密码123456,然后
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
select plugin from mysql.user where user = 'root';
  • 登录成功
  • 设置挂载目录

新建 data目录和my.cnf文件

my.cnf内容,也可以进入docker mysql容器内部,路径是/etc/mysql/my.cn,将my.cnf拷贝出来一份更改

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
skip-name-resolve
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Custom config should go here
!includedir /etc/mysql/conf.d/
  • 重新启动,并设置挂载目录(要先删除原来的容器)
docker run -d --name mysql --privileged=true -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456  -v /opt/software/docker/mysql/mysql/my.cnf:/etc/mysql/my.cnf -v /opt/software/docker/mysql/data:/var/lib/mysql c8ee
  • 进入容器内部,找到my.cnf,可以发现my.cnf已经被替换

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值