MySQL 是一款安全、跨平臺、高效的,并與 PHP、Java 等主流編程語言緊密結(jié)合的數(shù)據(jù)庫系統(tǒng)。
以下教程以windows10 64位計算機(jī)為例(其他windows系統(tǒng)類似)
01
下載
官方網(wǎng)站下載
https://dev.mysql.com/downloads/mysql/
根據(jù)自己的電腦配置選擇對應(yīng)版本**.zip壓縮包**格式下載。
** 無需登錄** ,直接下載
百度云快捷下載
鏈接:https://pan.baidu.com/s/1hcEKFAQ6Fq7kFLG8x7SQCQ
提取碼:2bfg
02
配置
將MySQL壓縮包解壓縮至D盤(更換其他盤也可以)
** 1.環(huán)境變量的配置**
此電腦->屬性->高級系統(tǒng)設(shè)置->環(huán)境變量->編輯Path->新建Path環(huán)境變量
D:\\mysql-8.0.27-winx64\\bin
2.MySQL數(shù)據(jù)庫配置
在 **D:\\mysql-8.0.27-winx64\\ **路徑下新建 **my.ini **配置文件,編輯 **my.ini** 文件如下內(nèi)容(直接復(fù)制)
[mysqld]#skip-grant-tables# 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# These are commonly set, remove the # and set as required.# mysql根目錄 basedir = D:/mysql-8.0.27-winx64# 數(shù)據(jù)文件存放目錄 datadir = D:/mysql-8.0.27-winx64/data# 端口,默認(rèn)3306 port = 3306# 服務(wù)實例的唯一標(biāo)識# server_id = MySQL# 允許最大連接數(shù) max_connections=200# 允許連接失敗的次數(shù)。這是為了防止有人從該主機(jī)試圖攻擊數(shù)據(jù)庫系統(tǒng) max_connect_errors=10# 服務(wù)端使用的字符集默認(rèn)為utf8mb4 character_set_server=utf8mb4# 創(chuàng)建新表時將使用的默認(rèn)存儲引擎 default-storage-engine=INNODB# 默認(rèn)使用“mysql_native_password”插件認(rèn)證 default_authentication_plugin=mysql_native_password # 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 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [mysql]# 設(shè)置mysql客戶端默認(rèn)字符集default-character-set=utf8mb4[client]# 設(shè)置mysql客戶端連接服務(wù)端時默認(rèn)使用的端口port=3306 default-character-set=utf8mb4
其中 **basedir** 、 **datadir** 、**port**需要修改為自己的配置
以管理員身份運行**cmd.exe**系統(tǒng)命令行,進(jìn)入到**D:\\mysql-8.0.27-winx64\\bin **目錄下
執(zhí)行以下語句:
mysqld --install mysql --defaults-file="D:\\mysql-8.0.27-winx64\\my.ini"
出現(xiàn)** Service successfully installed **表示數(shù)據(jù)庫安裝完畢
在 **D:\\mysql-8.0.27-winx64\\** 路徑下新建** data** 文件夾,存儲數(shù)據(jù)庫文件
由于 mysql 5.7 版本后沒有默認(rèn) data 文件夾,需要設(shè)置data 為 **默認(rèn)數(shù)據(jù)庫文件夾** .
以管理員身份運行**cmd.exe**系統(tǒng)命令行,進(jìn)入到**D:\\mysql-8.0.27-winx64\\bin**目錄下
執(zhí)行以下語句:
d:
cd D:\\mysql-8.0.27-winx64\\bin
mysqld -initialize
初始化成功,data目錄下生成配置文件
** 3.注冊windows服務(wù)**
以管理員身份運行cmd.exe系統(tǒng)命令行,進(jìn)入到D:\\mysql-8.0.27-winx64\\bin目錄下(已在此目錄下不用切換)
執(zhí)行以下語句:
mysqld --install MySQL8
服務(wù)名 **MySQL8 **可以修改
** 4.啟動服務(wù)**
net start MySQL8
啟動成功
** 5.登錄MySQL**
mysql -u root -p
臨時密碼在data目錄下,.err后綴的文件中。
登錄成功
6.修改默認(rèn)密碼
在MySQL數(shù)據(jù)庫命令行中執(zhí)行以下命令:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root'
flush privileges
7.數(shù)據(jù)庫管理管理軟件(可跳過)
03
常見問題
- 初始化的時候,提示找不到data目錄
解決:basedir和datadir配置路徑寫法有問題
basedir = D:\\dev\\mysql-8.0.12
datadir = D:\\dev\\mysql-8.0.12\\data
正確目錄寫法:
basedir = D:/dev/mysql-8.0.12
datadir = D:/dev/mysql-8.0.12/data
或者
basedir = D:\\\\dev\\\\mysql-8.0.12
datadir = D:\\\\dev\\\\mysql-8.0.12\\\\data
2.MySQL在root下修改密碼報錯:ERROR 1064 (42000): You have an error in your SQL syntax;check the manual that…
報錯原因:
新版本MySQL(8.0以上)不支持使用
SET PASSWORD FOR 'username'@'hostname' = PASSWORD ('newpwd');
或者
mysqladmin -u root -p password "rootpwd"
來修改用戶密碼。
解決方法:
alter user'username'@'hostname' identified by 'newpwd';
或者
alter 'username'@'hostname' identified with mysql_native_password by 'newpwd';
或者(修改當(dāng)前用戶的密碼)
set password = 'newpwd';
-
JAVA
+關(guān)注
關(guān)注
20文章
2989瀏覽量
109763 -
數(shù)據(jù)庫系統(tǒng)
+關(guān)注
關(guān)注
0文章
31瀏覽量
9850 -
MySQL
+關(guān)注
關(guān)注
1文章
860瀏覽量
27945
發(fā)布評論請先 登錄
如何在Rust中連接和使用MySQL數(shù)據(jù)庫
labview有調(diào)用mysql數(shù)據(jù)庫問題????
MySQL數(shù)據(jù)庫的python模塊安裝
數(shù)據(jù)庫教程之PHP訪問MySQL數(shù)據(jù)庫的理論知識詳細(xì)說明
MySQL數(shù)據(jù)庫如何安裝和使用說明
華為云數(shù)據(jù)庫-RDS for MySQL數(shù)據(jù)庫
MySQL數(shù)據(jù)庫服務(wù)器、數(shù)據(jù)庫和表之間是什么關(guān)系

MySQL數(shù)據(jù)庫管理與應(yīng)用
MySQL數(shù)據(jù)庫基礎(chǔ)知識
mysql數(shù)據(jù)庫基礎(chǔ)命令
eclipse怎么連接數(shù)據(jù)庫mysql
數(shù)據(jù)庫數(shù)據(jù)恢復(fù)—Mysql數(shù)據(jù)庫表記錄丟失的數(shù)據(jù)恢復(fù)流程

MySQL數(shù)據(jù)庫的安裝

評論