目錄
win安裝綠色版 MySQL 5.7
一、下載安裝服務
1.1. 下載解壓
我的解壓路徑為:
D:\Env\MySQL\mysql-5.7.24-winx64
1.2. 配置環境變量
- 變量名:
MYSQL_HOME
- 變量值:
D:\Env\MySQL\mysql-5.7.24-winx64
- path里添加:
%MYSQL_HOME%\bin
1.3. 新建my.ini
文件
[mysql]
default-character-set=utf8
[mysqld]
basedir=D:\Env\MySQL\mysql-5.7.24-winx64
datadir=D:\DataBase\MySQLData
port=3306
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
skip-grant-tables
1.4. 安裝服務命令
管理員打開CMD:
# 初始化
mysqld --initialize
# 安裝卸載服務
mysqld -install
mysqld -remove
# 啟動停止mysql
net start mysql
net stop mysql
二、登陸創建密碼
2.1. 登陸mysql
>mysql -uroot -p #無密碼
mysql> update mysql.user set authentication_string=password('123456') where user='root'; # 修改密碼
mysql> flush privileges; ##刷新權限
mysql> \q
2.2. 注釋掉my.ini
免密檢查
[mysql]
default-character-set=utf8
[mysqld]
basedir=D:\Env\MySQL\mysql-5.7.24-winx64
datadir=D:\DataBase\MySQLData
port=3306
max_connections=200
character-set-server=utf8
default-storage-engine=INNODB
#skip-grant-tables
2.3. 重新登陸【完成安裝】
mysql> alter user user() identified by "123456";
三、配置無密碼登陸
[client]
port = 3306
default-character-set=utf8
host=127.0.0.1
user=root
password=123456
四、忘記密碼修改
4.1. 關閉mysql密碼檢查
net stop mysql
mysqld --skip-grant-tables
4.2.多開一個cmd窗口,登陸mysq
4.3.修改密碼重啟電腦
mysql> update mysql.user set authentication_string=password('123456') where user='root';
mysql> flush privileges;
mysql> \q
4.4.登陸測試
>mysql -uroot -p
4.5.解決錯誤
mysql> alter user user() identified by "123456";
五、錯誤問題
5.1. msvcr120.dll丟失
安裝Visual C++ Redistributable Packages
安裝完成后重新執行上述步驟
5.2. ERROR 1820 (HY000)
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
聲明密碼
mysql> alter user user() identified by "123456";
六、版本差異
6.1.改密碼
新版:
update mysql.user set authentication_string=password('123456') where user='root';
老版:
update user set password=password('新密碼') where user='root'