Skip to content

Latest commit

 

History

History
294 lines (211 loc) · 8.7 KB

Mysql8-Win.md

File metadata and controls

294 lines (211 loc) · 8.7 KB

mysql-windows 安装

一、安装

mysql依赖VS C++ 57依赖13版本,8.0依赖15版本,要是提前安装,否则会报错

找不到MSVCP120dll

MySQL8.0 Windows zip包下载地址:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip

环境:Windows 10

1. 解压zip包到安装目录

比如我的安装目录是:D:\Program\MySQL

2.配置文件

在Windows系统中,配置文件默认是安装目录下的 my.ini 文件,部分配置需要在初始安装时配置,大部分也可以在安装完成后进行更改。当然,极端情况下,所有的都是可以更改的。

在安装根目录下添加 my.ini,比如我这里是:D:\Program\MySQL\my.ini,写入基本配置:

# Other default tuning values
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
# On Linux you can copy this file to /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options
# (@localstatedir@ for this installation) or to
# ~/.my.cnf to set user-specific options.
#
# On Windows you should keep this file in the installation directory 
# of your server (e.g. C:\Program Files\MySQL\MySQL Server X.Y). To
# make sure the server reads the config file use the startup option 
# "--defaults-file". 
#
# To run run the server from the command line, execute this in a 
# command line shell, e.g.
# mysqld --defaults-file="D:\GreenSoft\MySQL\my.ini"
#
# To install the server as a Windows service manually, execute this in a 
# command line shell, e.g.
# mysqld --install mysql --defaults-file="D:\GreenSoft\MySQL\my.ini"
#
# And then execute this in a command line shell to start the server, e.g.
# net start mysql
#
#
# Guildlines for editing this file
# ----------------------------------------------------------------------
#
# In this file, you can use all long options that the program supports.
# If you want to know the options a program supports, start the program
# with the "--help" option.
#
# More detailed information about the individual options can also be
# found in the manual.
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
#
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#


[client]
no-beep

# pipe
# socket=0.0
port=3306


[mysql]

default-character-set=utf8








[mysqld]

# 这是8.0.4的新特性 caching_sha2_password,在linux上面使用命宁 mysql -uroot -proot 可以链接,但是使用windows下面的navict链接不成功 
default_authentication_plugin = mysql_native_password

# These are commonly set, remove the # and set as required.
character-set-server = utf8
basedir = D:\mysql-8-winx64
datadir = D:\mysql-8-winx64\data
port = 3306
server_id = 1



# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="CUPID.log"
slow-query-log=1
slow_query_log_file="CUPID-slow.log"
long_query_time=10

# Binary Logging.
# log-bin

# Error Logging.
log-error="CUPID.err"



# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

# 8.0.4版本的时候,用的是这个sql_mode,但在8.0.11版本中会报错,改成下面那个
# sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"

default-storage-engine=INNODB

innodb_log_file_size = 512M
binlog_format='MIXED'
max_allowed_packet = 1G
# innodb_file_per_table = 1
# innodb_file_format = Barracuda

# 大小写是否敏感,0敏感 Linux下默认为0, Windows下默认值是 1, MacOS下默认值是 2(0敏感)
lower_case_table_names = 1

innodb_strict_mode = 0
max_connections = 500

注意,里面的 basedir 是我本地的安装目录,datadir 是我数据库数据文件要存放的位置,各项配置需要根据自己的环境进行配置。

查看所有的配置项,可参考:https://dev.mysql.com/doc/refman/8.0/en/mysqld-option-tables.html

3.初始化数据库

初始化命令,建议选第二个,免密

在MySQL安装目录的 bin 目录下执行命令:

mysqld --initialize --console

这个命令初始化,不用密码,后续方便更改秘密,

mysqld --initialize-insecure 

windows下,优先执行path环境变量,里的命令,直接使用建议下面的

 .\mysqld --initialize --console

执行完成后,会打印 root 用户的初始默认密码,比如:

2018-06-05T10:29:39.538869Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_B
Y_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2018-06-05T10:29:39.545715Z 0 [System] [MY-013169] [Server] D:\mysql-8-winx64\bin\mysqld.exe (mysqld 8.0.11) initializin
g of server in progress as process 3812
2018-06-05T10:29:39.719676Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it
. Aborting.
2018-06-05T10:29:39.759866Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-06-05T10:29:39.801369Z 0 [System] [MY-010910] [Server] D:\mysql-8-winx64\bin\mysqld.exe: Shutdown complete (mysqld
8.0.11)  MySQL Community Server - GPL.

其中,第4行的“APWCY5ws&hjQ”就是初始密码,在没有更改密码前,需要记住这个密码,后续登录需要用到。

要是你手贱,关快了,或者没记住,那也没事,删掉初始化的 datadir 目录,再执行一遍初始化命令,又会重新生成的。当然,也可以使用安全工具,强制改密码,用什么方法,自己随意。

参考:https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization-mysqld.html

4.安装服务

可以使用mysqld工具添加服务,也可以用nssm工具添加服务。

mysqld --install [服务名]

后面的服务名可以不写,默认的名字为 mysql。当然,如果你的电脑上需要安装多个MySQL服务,就可以用不同的名字区分了,比如 mysql5 和 mysql8。

安装完成之后,就可以通过命令net start mysql启动MySQL的服务了。

参考:https://dev.mysql.com/doc/refman/8.0/en/windows-start-service.html

5启动 mysql 服务

net start mysql

二.登录

1-首次登陆,是免密的:

mysql -u root -p

输入命令,回车登陆

mysql -u root -p(这直接连接密码不用手动输入)
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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.

2-登录成功更改初始密码

set password = '密码';

3-退出命令

quit

4-创建数据库

create database (数据库名字)

CentOS tar.gz 包安装

wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz
shell> tar zxvf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> ln -s mysql-8.0.11-linux-glibc2.12-x86_64 mysql
shell> cd mysql
shell> mkdir mysql-files
shell> chown mysql:mysql mysql-files
shell> chmod 750 mysql-files
shell> bin/mysqld --initialize --user=mysql
shell> bin/mysql_ssl_rsa_setup
shell> bin/mysqld_safe --user=mysql &
# Next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server根目录下添加 my.ini,比如我这里是:D:\Program\MySQL\my.ini,写入基本配置: