最近要配置一些項目管理工具,要用到MYSQL於是就想去下個最新版本。之前都是用PHPNOW一鍵安裝,或者是MYSQL安裝包來安裝的。但這次我發現下載MYSQL的壓縮包,然后通過windows的命令行窗口來安裝也非常的簡潔和干凈,安裝完畢后只要加個windows的服務就可以正常使用了,刪除只需要刪除文件和服務就OK,個人覺得非常的干凈。
安裝步驟記錄:
1.下載MYSQL安裝包
可以去官網下載ZIP包http://www.mysql.com/downloads/mysql/
我安裝的是mysql-5.5.23-winx64
2.解壓到本地目錄
D:\mysql
3.添加系統環境變量
添加系統環境變量是為了在命令控制窗口里更方便點。
新建:MYSQL_HOME ==> D:\mysql
追加:PATH==>;%MYSQL_HOME%\bin
4. 修改MySQL5.5的配置文件,把my-small.ini改名為my.ini進行編輯
a)在[mysqld]下追加
-------
basedir = "d:\\mysql"
datadir = "d:\\mysql\\data"
character-set-server = utf8
-------
b) 在[client]下追加
-------
default-character-set = utf8
-------
5.啟動服務
保存my.ini的配置, 然后打開命令行(開始菜單==>運行==>cmd )
輸入: mysqld --console 然后回車將看到如下類似內容:
-------
C:\Windows\system32>mysqld --console
120410 14:25:22 [Note] Plugin 'FEDERATED' is disabled.
120410 14:25:22 InnoDB: The InnoDB memory heap is disabled
120410 14:25:22 InnoDB: Mutexes and rw_locks use Windows interlocked functions
120410 14:25:22 InnoDB: Compressed tables use zlib 1.2.3
120410 14:25:22 InnoDB: Initializing buffer pool, size = 128.0M
120410 14:25:22 InnoDB: Completed initialization of buffer pool
120410 14:25:22 InnoDB: highest supported file format is Barracuda.
120410 14:25:22 InnoDB: Waiting for the background threads to start
120410 14:25:23 InnoDB: 1.1.8 started; log sequence number 1595675
120410 14:25:23 [Note] Event Scheduler: Loaded 0 events
120410 14:25:23 [Note] mysqld: ready for connections.
Version: '5.5.22' socket: '' port: 3306 MySQL Community Server (GPL)
-------
==> 證明mysql服務已啟動
6. 設置登陸mysql root帳號的的密碼
打開新的命令行,輸入 mysql -uroot 回車
-------
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.22 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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. www.2cto.com
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
-------
==〉看到上面類似內容說明登陸成功,此時的root帳號是沒有密碼的
執行命令修改密碼:
use mysql;
update user set password=PASSWORD("這里填寫你要設置的密碼") where user='root';
============================================================
5.7版本變更
先在mysql配置中
打開skip-grant-tables(將#號去除,或者加上這條,跳過密碼檢測)
版本后改為 update MySQL.user set authentication_string=password('root') where user='root' ;
=============================================================
執行完成后退出mysql操作,然后關閉mysql服務(ctrl+C 關閉另一個命令窗口),然后重啟mysql服務
然后使用你的root帳號登錄
mysqladmin -u root password 你的密碼
網上是這么寫的,但我這樣出現了下面的錯誤
Error: Access denied for user 'root'@'localhost' (using password: YES)
原因是ROOT 的密碼沒設,或者有錯誤,網上搜了許多的方法都不行,最后這個成功了,不過必須是主機上執行。
直接運行命令行窗口輸入下面的
mysqladmin -u root password 你的密碼
這樣就行了,然后再使用 mysqladmin -u root password 你的密碼 就可以正常登錄了。
7.安裝WINDOWS服務
命令行窗口 CD 進入D:\MySql\bin
執行mysqld.exe --install MySQL5.5 --defaults-file="D:\MySql\my.ini"
net start mysql5.5
到服務器里把 MYSQL5.5改成自動,這樣每次開機MYSQL服務就會自動啟動了。
==2018/6/3==
好久沒安裝mysql了,這次一個項目有同樣的需求,按以上配置完畢啟動服務是報了1053的錯誤。
網上搜了下,右鍵服務屬性,設置管理員賬戶就正常了。