Windows平臺上使用noinstall方式部署MySQL 8.0

天府雲創發表於2018-08-06

1、之前本博寫過一篇在windows下面使用uninstall方式安裝MySQL 5.7.9的文章,隨著MySQL 8.0 GA版本的釋出,預示著8.0作為一個生產環境版本正式走上舞臺,有必要將之前的安裝方法予以更新,以饗讀者。(其實還是用MariaDB開源社群解決方案多)

2、安裝平臺

Microsoft Windows Server 2016 Standard

MySQL 8.0.11 noinstall archive

3、下載安裝包

https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-winx64.zip

4、安裝佈局

 

1

2

3

4

5

6

7

8

9

10

11

12

#程式所在位置

C:/mysql

#配置檔案所在位置

C:/mysql/my.ini

#資料檔案存放位置

D:/ProgramData/MySQL/data

#pid檔案位置

D:/ProgramData/MySQL/run

#tmp位置

D:/ProgramData/MySQL/tmp

#日誌檔案位置

D:/ProgramData/MySQL/logs

5、配置my.ini檔案

在C:/mysql資料夾下新建my.ini檔案,具體內容如下:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

[client]

port = 3306

socket = D:\\ProgramData\\MySQL\\tmp\\mysql.sock

#default-character-set=utf8mb4

character_sets_dir = C:/mysql/share/charsets

[mysqld]

port = 3306

socket = D:\\ProgramData\\MySQL\\tmp\\mysql.sock

pid_file = D:\\ProgramData\\MySQL\\run\\mysql.pid

basedir = C:\\mysql

datadir = D:\\ProgramData\\MySQL\\data

skip-external-locking

key_buffer_size = 16M

max_allowed_packet = 1M

table_open_cache = 64

sort_buffer_size = 512K

net_buffer_length = 8K

read_buffer_size = 256K

read_rnd_buffer_size = 512K

myisam_sort_buffer_size = 8M

 

default-storage-engine = InnoDB

# 從8.0 開始,mysql預設字符集為utf8mb4

character_set_server = utf8mb4

character_sets_dir = C:/mysql/share/charsets

 

tmpdir = D:\\ProgramData\\MySQL\\tmp\\

 

 

log-bin=D:\\ProgramData\\MySQL\\logs\\mysql-bin

#bin log 過期時間 按秒記,即14*24*60*60 秒

binlog_expire_logs_seconds = 1209600

# binary logging format - mixed recommended

binlog_format=row

 

#expire_logs_days= 7

 

log-error = D:\\ProgramData\\MySQL\\logs\\error.log

 

 

slow-query-log = 1

long_query_time= 3

slow_query_log_file= D:\\ProgramData\\MySQL\\logs\\slow.log

 

# required unique id between 1 and 2^32 - 1

# defaults to 1 if master-host is not set

# but will not function as a master if omitted

server-id = 1

 

 

# Uncomment the following if you are using InnoDB tables

innodb_data_home_dir = D:\\ProgramData\\MySQL\\data

innodb_data_file_path = ibdata1:10M:autoextend

innodb_log_group_home_dir = D:\\ProgramData\\MySQL\\logs

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

innodb_buffer_pool_size = 16M

#innodb_additional_mem_pool_size = 2M

# Set .._log_file_size to 25 % of buffer pool size

innodb_log_file_size = 5M

innodb_log_buffer_size = 8M

innodb_flush_log_at_trx_commit = 1

innodb_lock_wait_timeout = 50

 

innodb_file_per_table = 1

 

[mysqldump]

quick

max_allowed_packet = 16M

 

[mysql]

no-auto-rehash

# Remove the next comment character if you are not familiar with SQL

#safe-updates

 

[myisamchk]

key_buffer_size = 20M

sort_buffer_size = 20M

read_buffer = 2M

write_buffer = 2M

 

[mysqlhotcopy]

interactive-timeout

6、初始化MySQL

使用管理員開啟CMD程式,切換到mysql的bin目錄下面,執行如下命令:

 

1

mysqld.exe --initialize  --basedir="c:/mysql" --datadir="D:/programdata/mysql/data"

7、啟動應用程式

使用–console引數檢視輸出

 

1

mysqld.exe --defaults-file="C:/mysql/my.ini" --console

–defaults-file引數必須作為mysqld的第一個引數,不然會報“ unknown variable ‘defaults-file=C:/mysql/my.ini’”的錯誤。

8、登陸MySQL

MySQL初始化的時候會在error.log檔案內生成一個臨時密碼,使用該密碼登陸root 使用者,將密碼進行重置。

 

1

alter user 'root'@'localhost' identified by 'yourpassword';

9、將MySQL安裝為系統服務

 

1

mysqld.exe --install MySQL --defaults-file=C:/mysql/my.ini

若要刪除mysql服務,則執行

 

1

mysqld.exe --remove

Enjoy It!祝君使用愉快!

相關文章