MySQL 安裝配置 Windows下免安裝配置 原

1    安裝MySQL軟件
1.1    下載MySQL
依據ipems_dvp產品選型需求,選擇mysql-5.7.17-winx64。可自行從網上下載,也可從公司拷貝,以下爲下載目錄和公司歸檔目錄。
下載地址:https://downloads.mysql.com/archives/community/

1.2    安裝MySQL
此安裝包無需執行具體安裝過程,只需要解壓安裝包,進行必要的配置即可。詳細配置過程如下。
拷貝安裝包至服務器,解壓軟件包。將解壓後的文件放置具體一個目錄,該目錄最好不要太深,同時目錄名不要包含空格等特殊字符。本次因公司使用虛擬機只有一個C盤,所以安裝將文件放置C:\mysql5.7.17_winx64目錄,建議生產環境放在D盤或其他空間較大的磁盤。解壓後的目錄如下。

爲方便後續操作MySQL數據庫,需要配置MySQL環境變量,將MySQL軟件的的bin目錄配置到windows環境變量的path中,本文bin目錄爲C:\mysql5.7.17_winx64\bin現場需要結合實際情況修改。

創建MySQL的配置文件my.ini,內容如下,其中標紅的目錄需要手動創建。同時該文件必須是ANSI格式的,利用記事本打開,另存爲時確保編碼爲ANSI格式。刪掉解壓目錄自帶的my-default.ini文件。

[client]
default-character-set=utf8
port=3306

[mysqld]
port=3306
#開啓performance_schema庫
performance_schema=0
#默認存儲引擎
default-storage-engine=InnoDB
#默認字符集
character_set_server=utf8
collation-server=utf8_general_ci
basedir="C:\mysql5.7.17_winx64"
datadir="C:\mysql5.7.17_winx64\data"
tmpdir="C:\mysql5.7.17_winx64\data"
socket="C:\mysql5.7.17_winx64\data\mysql.sock"
log-error="C:\mysql5.7.17_winx64\data\mysql_error.log"
server_id=1
#skip-locking
max_connections=500
table_open_cache=256
query_cache_size=1M
tmp_table_size=32M
thread_cache_size=8
innodb_log_buffer_size=128M
innodb_buffer_pool_size=2G
innodb_log_file_size=10M
innodb_thread_concurrency=16
innodb-autoextend-increment=1000
join_buffer_size=128M
sort_buffer_size=32M
read_rnd_buffer_size=32M
max_allowed_packet=32M
explicit_defaults_for_timestamp=true
lower_case_table_names=1
sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

[mysql]
no-auto-rehash
prompt="\\u@\\h : \\d \\r:\\m:\\s> "
default-character-set=utf8
#show-warnings

[mysqldump]
quick
max_allowed_packet=1G
default-character-set=utf8

配置完成後軟件目錄結構如下,data文件夾需要手動創建。

通過dos命令進入MySQL的bin目錄,初始化數據庫,命令執行完沒有報錯即執行成功。

c:
cd MySQL的bin目錄
mysqld --initialize-insecure --user=mysql

在成功執行初始後,通過如下命令配置MySQL的windows服務。提示成功安裝後,查看windows服務器列表,能找到對應的mysql服務,即說明配置正確。

C:\mysql5.7.17_winx64\bin>mysqld  install
Service successfully installed.

1.3    啓動MySQL
以上安裝過程均成功後,可以在dos窗口啓動MySQL服務,具體操作過程如下。

#啓動mysql
C:\mysql5.7.17_winx64\bin>net start mysql
#登錄mysql首次登錄不需要輸入密碼,提示輸入密碼時直接回車
C:\mysql5.7.17_winx64\bin>mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

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

root@localhost : (none) 06:10:47> 
#修改root用戶的密碼紅色字體
root@localhost : (none) 06:10:47> alter user 'root'@'localhost' identified by 'Aa123456789';
Query OK, 0 rows affected (0.00 sec)
#刷新密碼信息
root@localhost : (none) 06:15:03> flush privileges;
Query OK, 0 rows affected (0.00 sec)
#退出
root@localhost : (none) 06:15:13> exit
Bye
#利用新設密碼重新登錄
C:\mysql5.7.17_winx64\bin>mysql -uroot -p
Enter password: ***********

1.4    創建用戶
通過root用戶登錄MySQL,創建iPEMS-DVP程序使用的數據庫用戶,並授予用戶遠程訪問權限。

#root登錄mysql
C:\mysql5.7.17_winx64\bin>mysql -uroot -p
Enter password: ***********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)

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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
#創建ipems_dvp用戶
root@localhost : (none) 07:08:58> create user 'ipems_dvp'@'%' identified by 'Aa123456789';
Query OK, 0 rows affected (0.00 sec)
#授權
root@localhost : (none) 07:10:03> grant all privileges on *.* to ipems_dvp;
Query OK, 0 rows affected (0.00 sec)
#刷新用戶信息
root@localhost : (none) 07:10:40> flush privileges;
Query OK, 0 rows affected (0.00 sec)

1.5    部署應用數據庫
如果是部署iPEMS-DVP生產環境(只包括iPEMS-DVP產品數據庫結構,不包括演示數據),需採用如下方式部署,初始化腳本爲iPEMS-DVP產品發佈中的 ./DB/MySQL/01_iPEMS-DVP1.0_INIT_MySQL_DB.sql,具體過程如下。

C:\mysql5.7.17_winx64\bin>mysql -u ipems_dvp -p
Enter password: ***********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.17 MySQL Community Server (GPL)

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

ipems_dvp@localhost : (none) 07:40:11> create database ipems_dvp;
Query OK, 1 row affected (0.02 sec)

ipems_dvp@localhost : (none) 07:40:21> use ipems_dvp;
Database changed
ipems_dvp@localhost : ipems_dvp 07:40:28> source C:\mysql5.7.17_winx64\01_iPEMS-DVP1.0_INIT_MySQL_DB.sql
……
Query OK, 0 rows affected (0.00 sec)

ipems_dvp@localhost : ipems_dvp 07:41:33>

如果部署演示DEMO環境(包含公司測試OLAP模型數據),建議採用如下方式導入數據庫。將ipems_dvp_windows_dump.sql拷貝至服務器,執行如下命令導入,導入過程無錯誤信息提示即部署成功。

C:\mysql5.7.17_winx64\bin>mysql -u ipems_dvp -p  < C:\mysql5.7.17_winx64\ipems_dvp_windows_dump.sql
Enter password: ***********

1.6    檢查部署結果
如果是按照全新生產環境部署,可以通過如下方式確認表的個數,表名和cfg_user_info表中的中文字段是否亂碼,無誤即部署成功。

ipems_dvp@localhost : ipems_dvp 07:41:33> show tables;
+--------------------------------+
| Tables_in_ipems_dvp            |
+--------------------------------+

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章