1嗽冒、MySQL下載
鏈接:http://pan.baidu.com/s/1miQdB4G 密碼:a7p1
2蛛壳、下載后將文件解壓到安裝目錄下
(G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64)
3袍嬉、在安裝目錄下將文件 my-default.ini 重命名為 my.ini,用記事本打開
需要修改的地方:
basedir 驰凛、datadir:改成安裝目錄
port:3036
注意:data 目錄在初始化時(shí)會(huì)自動(dòng)生成一些文件壕鹉,目錄需提前建好
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# 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.
basedir = G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin # 該參數(shù)指定了安裝 MySQL 的安裝路徑
datadir = G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\data 該參數(shù)指定了 MySQL 數(shù)據(jù)庫(kù)data的文件放在哪個(gè)路徑下
port = 3306
# server_id = XX.XX.XX.XX
# 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
skip-grant-tables
4、配置環(huán)境變量
我的電腦-->屬性-->高級(jí)系統(tǒng)設(shè)置-->環(huán)境變量
編輯系統(tǒng)變量 Path (即添加 安裝目錄下的bin文件路徑)
將 **G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin ** 添加到 Path 變量值后面琴许。
5税肪、以管理員身份運(yùn)行命令提示符 cmd 進(jìn)入安裝目錄,切換至bin目錄
(一定要用管理員身份運(yùn)行虚吟,不然權(quán)限不夠)
開始->運(yùn)行->cmd寸认,例如我要進(jìn)入G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin
1)先進(jìn)入G磁盤,輸入 G:回車
2)cd Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin
注意點(diǎn):若直接輸 CD G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin串慰,目錄不會(huì)切換偏塞,但在下次輸入盤符的時(shí)候進(jìn)入上一次希望進(jìn)入的目錄,如輸入G:會(huì)直接進(jìn)入安裝目錄)
C:\Windows\system32>cd G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin
C:\Windows\system32>G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin
'G:\Program' 不是內(nèi)部或外部命令邦鲫,也不是可運(yùn)行的程序或批處理文件灸叼。
C:\Windows\system32>G:
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin
5.1 安裝服務(wù),執(zhí)行 mysqld -install
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin>mysqld -install
Service successfully installed. //成功安裝服務(wù)
5.2 初始化data目錄庆捺, 執(zhí)行 mysqld --initialize-insecure --user=mysql;(免密)
此步驟非常重要古今,未初始化,可能會(huì)導(dǎo)致mysql服務(wù)無(wú)法啟動(dòng)
注意:MySQL 5.7.17初始化時(shí)創(chuàng)建了臨時(shí)密碼滔以,在data目錄下的 LAPTOP-OOR4C1HG.err 文件打開后捉腥,查看第一個(gè)Note,可以找到臨時(shí)密碼你画。
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin>mysqld -initialize
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin>
打開 err 文件可以看到給 root 創(chuàng)建了空密碼
2017-07-28T14:49:27.797774Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
若要免密抵碟,則執(zhí)行 mysqld --initialize-insecure --user=mysql;
5.3 設(shè)置root免密登錄 (初始化時(shí)未設(shè)置免密)
1)在配置文件 my.ini 中 [mysqld] 下面加上 skip-grant-tables
2)也可以執(zhí)行 mysqld -nt -skip-grant-tables
--skip-grant-tables 的意思是啟動(dòng)MySQL服務(wù)的時(shí)候跳過(guò)權(quán)限表認(rèn)證
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin>mysqld.exe -nt -skip-grant-tables
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64\bin>
6桃漾、啟動(dòng)服務(wù) ,執(zhí)行net start mysql
C:\Windows\system32>net start mysql
MySQL 服務(wù)正在啟動(dòng) .
MySQL 服務(wù)已經(jīng)啟動(dòng)成功拟逮。
常見問(wèn)題:服務(wù)無(wú)法啟動(dòng)
處理方法:任務(wù)管理器撬统,結(jié)束mysqld進(jìn)程,重新啟動(dòng)mysql
G:\Program Files (x86)\MySQL\mysql-5.7.17-winx64>net start mysql
MySQL 服務(wù)正在啟動(dòng) ..
MySQL 服務(wù)無(wú)法啟動(dòng)敦迄。
服務(wù)沒有報(bào)告任何錯(cuò)誤恋追。
請(qǐng)鍵入 NET HELPMSG 3534 以獲得更多的幫助。
7罚屋、進(jìn)入mysql修改密碼
因設(shè)置過(guò)免密登錄苦囱,輸入命令 mysql -uroot -p,彈出輸入密碼沿后,直接敲回車鍵即可
輸入mysql+回車就可以進(jìn)行數(shù)據(jù)庫(kù)相關(guān)方面的操作了
8沿彭、停止服務(wù),執(zhí)行stop start mysql
溫馨提示:恢復(fù)root密碼登錄
1)先修改下root密碼
mysql5.7數(shù)據(jù)庫(kù)下已經(jīng)沒有password這個(gè)字段了尖滚,password字段改成了authentication_string
查看密碼字段:
輸入 desc user;
或輸入 select * from user;
use mysql;
//更新密碼,new_pass
update user set authentication_string=password("new_pass") where user="root";
flush privileges; //刷新權(quán)限
quit; //退出 (或 exit;)
2)再將配置文件中 my.ini 中 skip-grant-tables注釋掉(前面加 #)
3)操作完后重新啟動(dòng)mysql服務(wù)瞧柔,便可以用之前設(shè)置好的密碼登錄了
(輸入命令 mysql -uroot -p漆弄,再輸入密碼,看到以下提示造锅,那么恭喜你成功了)
如需登錄遠(yuǎn)程數(shù)據(jù)庫(kù)撼唾,加參數(shù)-h
C:\WINDOWS\system32>mysql -uroot -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.17
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.
mysql>
常見問(wèn)題
1、密碼失效的情況下如何修改密碼哥蔚,報(bào)錯(cuò)1820
1)倒谷、通過(guò) alter user
mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.20 sec)2)、通過(guò) set password=password("123456");
(使用PASSWORD()函數(shù)糙箍,對(duì)密碼進(jìn)行加密渤愁,此時(shí)不需要使用FLUSH PRIVILEGES)
2、Mysql 報(bào)錯(cuò)1130
解決方法:需要授權(quán)(hostname改成 IP地址深夯,newpasspwd 改成新密碼)
grant all on . to 'root'@'hostname' identified by 'newpasspwd'
工具連接MySQL 失敗.png
針對(duì)單項(xiàng)操作進(jìn)行授權(quán)(如select抖格、update等),如有很多數(shù)據(jù)庫(kù)咕晋,則都要進(jìn)行設(shè)置一遍
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP # 根據(jù)實(shí)際需要填寫
-> ON database.* # 指定數(shù)據(jù)庫(kù)
-> TO 'username'@'localhost' #指定用戶
-> IDENTIFIED BY 'password'; #用戶密碼
以上命令會(huì)在mysql數(shù)據(jù)庫(kù)中的user表創(chuàng)建一條用戶信息記錄雹拄。
3、密碼永久生效
alter user 'root'@'localhost' password expire never;
4掌呜、卸載軟件后如何刪除服務(wù)
sc delete mysql