一、下載地址:
http://dev.mysql.com/downloads/mysql/
二、配置環境變量
1.新增環境變量
變量名:MYSQL_HOME
變量值:E:\software\mysql-5.7.21-winx64(改成你自己的安裝目錄)
2.修改環境變量PATH
在PATH後面加入%MYSQL_HOME%\bin,注:加入新的變量值需要用;隔開
三、添加my.ini配置文件
1.下載的壓縮文件中沒有my.ini配置文件和data文件夾,需要手動在解壓目錄下新建文本my.ini
[client]
port=3306
[mysql]
default-character-set=utf8
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[mysqld]
# The TCP/IP Port the MySQL Server will listen on
port=3306
#Path to installation directory. All paths are usually resolved relative to this.
basedir=D:\\develop\\software\\mysql-5.7.25-winx64
#Path to the database root
datadir=D:\\develop\\software\\mysql-5.7.25-winx64\\data
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
四、初始化mysql,啓動mysql服務
1.以管理員身份運行命令行cmd,進入bin目錄(不是藍色界面的那個,認準黑色界面的那個cmd)
cd D:\mysql\mysql5.7.20-winx64\bin
2.輸入命令:bin\mysqld --defaults-file=my.ini --initialize-insecure
待選項:(mysqld --initialize-insecure 或 mysqld --initialize-insecure --user=mysql)
會生成無密碼的root用戶和在根目錄下生成一個data文件夾
3.安裝或移除mysql服務
mysqld --install
mysqld --remove
4.啓動服務:net start mysql,停止服務:net stop mysql(要在管理員cmd中輸入使用)
5.設置或更新mysql密碼
方法1: 用SET PASSWORD命令
mysql -u root -p
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
方法2:用mysqladmin
mysqladmin -u root password "newpass"
如果root已經設置過密碼,採用如下方法
mysqladmin -u root password oldpass "newpass"
方法3: 用UPDATE直接編輯user表
mysql -u root -p
mysql> use mysql;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
在丟失root密碼的時候,可以這樣
1. 關閉正在運行的MySQL服務。
2. 打開DOS窗口,轉到mysqlbin目錄。
3. 輸入mysqld --skip-grant-tables 回車。--skip-grant-tables 的意思是啓動MySQL服務的時候跳過權限表認證。
4. 再開一個DOS窗口(因爲剛纔那個DOS窗口已經不能動了),轉到mysqlbin目錄。
5. 輸入mysql回車,如果成功,將出現MySQL提示符 >。
6. 連接權限數據庫: use mysql; 。
6. 改密碼:update user set password=password("123") where user="root";(別忘了最後加分號) 。
7. 刷新權限(必須步驟):flush privileges; 。
8. 退出 quit。
9. 重啓服務,使用用戶名root和剛纔設置的新密碼123登錄。
開啓遠程連接權限
use mysql;
grant all privileges on *.* to root@'%' identified by "hzl";
FLUSH PRIVILEGES;
五,安裝過程中可能出現的錯誤
1.遇到MSVCR120.dll文件丟失錯誤的解決方案
下載 VC redist packages for x64,下載完成,點擊運行即可。