閱讀目錄
• 下載MySQL免安裝版
• 配置MySQL數(shù)據(jù)庫
• MySQL環(huán)境變量
• 安裝MySQL數(shù)據(jù)庫
公司服務器是Windows 開發(fā)連接的數(shù)據(jù)庫使用的是"MySQL"
此篇隨筆將介紹在Windows上如何配置MySQL數(shù)據(jù)庫免安裝版
一、下載MySQL免安裝版
• 首先進入MySQL 官方網(wǎng)站 www.mysql.com -->Downloads(下載) --> Community(社區(qū)) --> MySQL Community Server(MySQL社區(qū)服務器)-->選擇操作系統(tǒng)平臺(Windows)
• 下面有三個可選的下載文件
† 第一個是MySQL Installer 5.6 for Windows,下載下來是一個.msi可執(zhí)行安裝文件
† 后面兩個是解壓版(Zip版)分別是Windows (x86, 64-bit) ZIP Archive 和 Windows (x86, 32-bit), ZIP Archive
• 筆者選擇的是 mysql-5.6.26-winx64.zip ,因為筆者的服務器版本是64位操作系統(tǒng)
二、配置MySQL數(shù)據(jù)庫
• 將下載的 mysql-5.6.26-winx64.zip 解壓自定義目錄,這里筆者將把這個壓縮包解壓至 D:\mysql-5_x64 目錄;
• 打開這個目錄,發(fā)現(xiàn)里面的文件夾和文件跟一個安裝好后的MySQL基本沒有區(qū)別
• 修改MySQL配置文件,在mysql-5_x64目錄下有一個my-default.ini,可以算作模板來使用,里面的內容不是很多!可以自己創(chuàng)建一個 my.ini作為MySQL配置文件,打開my.ini
[client]
port=3306
#客戶端字符類型,與服務端一致就行,建議utf8
default-character-set=utf8
[mysqld]
#綁定IPv4和3306端口
bind-address = 0.0.0.0
port = 3306
#服務端字符類型,建議utf8
character_set_server=utf8
# 設置mysql的安裝目錄
basedir=D:/mysql-5_x64
# 設置mysql數(shù)據(jù)庫的數(shù)據(jù)的存放目錄
datadir=D:/mysql-5_x64/data
# 允許最大連接數(shù)
max_connections=201
• 這樣一個基本的MySQL環(huán)境所需要的參數(shù)就夠了
三、MySQL環(huán)境變量
• 右擊這臺電腦-->屬性-->高級-->環(huán)境變量-->"用戶變量"新建變量MYSQL_HOME 值D:\mysql-5_x64 ,"系統(tǒng)變量"找到變量path 編輯 在后面加上 ;%MYSQL_HOME%\bin
四、安裝MySQL數(shù)據(jù)庫
• 運行cmd (Win8 、Win10以管理員運行cmd)-->進入D:\mysql-5_x64\bin目錄
Microsoft Windows [版本 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\Windows\system32>D:
D:\>cd mysql-5_x64
D:\mysql-5_x64>cd bin
D:\mysql-5_x64\bin>
• 執(zhí)行mysqld -install 安裝MySQL
D:\mysql-5_x64\bin>mysqld -install
Service successfully installed
• 執(zhí)行net start mysql啟動MySQL
D:\mysql-5_x64\bin>net start mysql
D:\mysql-5_x64\bin>net start mysql
MySQL 服務正在啟動 .
MySQL 服務已經(jīng)啟動成功
啟動MySQL服務:net start mysql
停止MySQL服務:net stop mysql
刪除MySQL服務:sc delete mysql
• 修改Mysql密碼
D:\mysql-5_x64\bin>mysql -u root -p //使用root登入mysql
Enter password: //密碼空,回車即可
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, 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.
mysql>
1
2
3
4
5
6
7
8
9
10
|
mysql> show databases; //顯示所有數(shù)據(jù)庫 + --------------------+ | Database | + --------------------+ | information_schema | | mysql | | performance_schema | | test | + --------------------+ 4 rows in set (0.00 sec) |
• 進入'mysql'數(shù)據(jù)、刪除空用戶
1
2
3
4
|
mysql> use mysql; Database changed mysql> delete from user where user = '' ; Query OK, 1 row affected (0.00 sec) |
• 更新密碼并重新刷權限表到內存(也可以用mysqladmin工具來設置密碼)
1
2
3
4
5
|
mysql> update User set Password = PASSWORD ( '123456' ) where User = 'root' ; Query OK, 4 rows affected (0.00 sec) Rows matched: 4 Changed: 4 Warnings: 0 mysql> flush privileges ; Query OK, 0 rows affected (0.00 sec) |
• 嘗試登陸
1
2
3
4
5
6
7
8
9
10
11
|
D:\mysql-5_x64\bin>mysql -u root -p //用root用戶登入數(shù)據(jù)庫 Enter password : ****** //輸入更新后的密碼 123456 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 5 Server version: 5.6.26 MySQL Community Server (GPL) Copyright (c) 2000, 2015, 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. mysql> |
• 開啟遠程連接(給予全部權限,允許 192.168.1.x 網(wǎng)段都可以連接)
1
2
3
4
5
6
7
8
9
10
11
|
mysql> grant all privileges on *.* to 'root' @ '192.168.1.%' identified by 'root' with grant option ; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges ; Query OK, 0 rows affected (0.00 sec) mysql> select host, user , password from user ; + -------------+------+-------------------------------------------+ | host | user | password | + -------------+------+-------------------------------------------+ | 192.168.1.% | root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B | + -------------+------+-------------------------------------------+ 4 rows in set (0.00 sec) |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。