1. 程式人生 > >Windows 64位作業系統安裝mysql 綠色版 mysql安裝常見問題(系統找不到指定的檔案、發生系統錯誤 1067 程序意外終止)

Windows 64位作業系統安裝mysql 綠色版 mysql安裝常見問題(系統找不到指定的檔案、發生系統錯誤 1067 程序意外終止)

part1

1.先進行mysql-5.6.15-winx64.zip 綠色版檔案進行解壓

2.配置ini檔案

# For advice on how to change settings please see

# *** 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 = .....


# datadir = .....
# port = .....
# server_id = .....

basedir=D:/mysql-5.6.15-winx64
datadir=D:/mysql-5.6.15-winx64/data
port=3306
server_id=10


# 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

3.把mysql 新增到windows 服務中

首先進入到mysql解壓的bin目錄,然後執行

 mysqld --install MySQL --defaults-file="C:\Windows\my.ini"

4.啟動mysql服務

在命令窗中輸入 services.msc 找到MySQL 右鍵啟動

或者直接執行 net start mysql  

其他命令  net stop mysql  mysqld -remove 移除服務

5.新增環境變數

把解壓的mysql bin 目錄新增到環境變數的path 目錄中

6.登陸資料庫

在命令視窗中輸入 mysql -u root -p  初次密碼為空

7.修改mysql 密碼

mysql>use mysql;

mysql>update user set Password=password('newpassword') where User='root';

mysql>flush privileges;

注意:安裝mysql 如果出現錯誤,請仔細檢查ini檔案。如果服務名稱已存在 請用  sc  delete mysql 刪除服務


part2 

在安裝mysql時總是會遇到這樣那樣的問題,每次重新安裝都會花很多時間來排查。在網上其實有很多相關的文章,但很多都只講了方法,但沒講具體細節問題,導致無法解決問題。其實有時候知道問題的原因,但總是因為一些細節問題沒有注意到,反覆的嘗試,浪費了很多時間。現在把我安裝過程中遇到的問題以及該注意的問題記錄下來。

環境:windows7

mysql版本:mysql-5.6.10-win32 win64

如果是預設安裝,那麼mysql會被安裝到目錄C:\Program Files\MySQL\MySQL Server 5.6中,特別要注意該目錄,下面會說明原因。

一般情況下,安裝完mysql後,我們都希望直接可以連線使用,但是實際情況卻不一定能這樣順利。安裝完成後,直接在CMD中輸入命令:

  1. C:\Windows\system32>mysql -uroot  
  2. 'mysql' 不是內部或外部命令,也不是可執行的程式或批處理檔案。  

這是由於沒有配置環境變數導致的,當然也可以先切換到mysql的安裝目錄再執行命令,不過那不是麻煩麼。

首先配置環境變數,把mysql所在目錄的bin目錄新增到path環境變數中(如何設定環境變數的具體操作省略,可以google一大把)。

配置好環境變數後,該可以連線mysql了吧?試試看mysql -uroot,咦,怎麼回事:

  1. C:\Windows\system32>mysql -uroot  
  2. ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)  

什麼原因?難道是服務沒有啟動,來啟動服務看看:

  1. C:\Windows\system32>net start mysql  
  2. 服務名無效。  
  3. 請鍵入 NET HELPMSG 2185 以獲得更多的幫助。  

居然服務名無效?開啟windows服務一看,原來是安裝完mysql後根本沒有安裝mysql服務,需要我們手動安裝。

安裝mysql的服務很“簡單”,在命令列中輸入:

  1. C:\Users\MikanMu>mysqld --install  
  2. Install/Remove of the Service Denied!  

咦,怎麼回事?這是由於沒有許可權造成的,需要在啟動命令列時以管理員身份執行才行。關閉當前cmd視窗重新以管理員身份執行:

  1. C:\Windows\system32>mysqld --install  
  2. Service successfully installed.  

提示成功安裝。很好,安裝完服務後,啟動起來看看:

  1. C:\Windows\system32>net start mysql  
  2. 發生系統錯誤 2。  
  3. 系統找不到指定的檔案。  

我了個去,這又是怎麼回事?上網各種查,都說是需要在mysql配置檔案中新增路徑:

basedir=C:/Program Files/MySQL/MySQL Server 5.6
datadir=C:/Program Files/MySQL/MySQL Server 5.6/data

好吧,我試試,mysql-5.6.10-win32預設的配置檔案是在C:/Program Files/MySQL/MySQL Server 5.6/my-default.ini,或者自己建立一個my.ini檔案,在其中新增配置:

[mysqld]
basedir=C:/Program Files/MySQL/MySQL Server 5.6
datadir=C:/Program Files/MySQL/MySQL Server 5.6/data

注意:1、安裝目錄下由於許可權的原因不能直接建立檔案,需要在其他地方建立並新增好相應的配置後,再拷貝到安裝目錄C:/Program Files/MySQL/MySQL Server 5.6下。

2、網上有的說配置中的目錄分隔符必須是正斜槓‘/’,但是經過實驗,‘/’、‘\’、‘\\’都沒有問題,都是可以的。

3、basedir這個配置是mysql的安裝目錄,記住,一定是要配置到C:/Program Files/MySQL/MySQL Server 5.6這個目錄,不能到C:/Program Files/MySQL就完了。

4、my.ini檔案的編碼必須是英文編碼(如windows中的ANSI),不能是UTF-8或GBK等。

上面操作完成後(一定要注意細節),再來啟動一下服務:

  1. C:\Windows\system32>net start mysql  
  2. 發生系統錯誤 2。  
  3. 系統找不到指定的檔案。  

怎麼還是報這個錯?難道不是由於配置的原因?對,不是由於上面的配置的問題,但上面的配置新增後也沒有錯。那是什麼原因?

這裡是最需要注意的地方,在安裝mysql服務時,一定要切換到mysql安裝目錄的bin目錄下,不管你是否配置環境變數,否則在安裝完後啟動服務還是會報上面的錯誤。

切換到bin目錄後,先刪除前面安裝的mysql服務(刪除服務不一定要到bin目錄),再重新在bin目錄下安裝mysql服務,然後啟動:

  1. C:\Windows\system32>cd ../..  
  2. C:\>cd Program Files\MySQL\MySQL Server 5.6\bin  
  3. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --remove  
  4. Service successfully removed.  
  5. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --install  
  6. Service successfully installed.  
  7. C:\Program Files\MySQL\MySQL Server 5.6\bin>net start mysql  
  8. MySQL 服務正在啟動 .  
  9. MySQL 服務已經啟動成功。  

哇,終於成功了!!

現在來驗證一下不需要新增my.ini檔案,也是可以正常啟動服務的,只要是在bin目錄下安裝的服務就行。只需要停止mysql服務,把服務刪除後,再把mysql安裝目錄下的my.ini檔案刪除掉,再重新安裝服務,啟動mysql服務,看看能不能正常啟動即可,實驗證明,是可以正常啟動的。

  1. C:\Program Files\MySQL\MySQL Server 5.6\bin>net stop mysql  
  2. MySQL 服務正在停止.  
  3. MySQL 服務已成功停止。  
  4. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --remove  
  5. Service successfully removed.  
  6. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysqld --install  
  7. Service successfully installed.  
  8. C:\Program Files\MySQL\MySQL Server 5.6\bin>net start mysql  
  9. MySQL 服務正在啟動 .  
  10. MySQL 服務已經啟動成功。  

終於大功告成!!!看看能不能連線:

  1. C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -uroot  
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  3. Your MySQL connection id is 3  
  4. Server version: 5.6.10 MySQL Community Server (GPL)  
  5. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.  
  6. Oracle is a registered trademark of Oracle Corporation and/or its  
  7. affiliates. Other names may be trademarks of their respective  
  8. owners.  
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  
  10. mysql>  

完全沒有問題。

另外,mysql預設的root使用者是沒有設定密碼的,我們可以修改root使用者密碼,方法如下:

1、直接在cmd命令列,不需要進入mysql

  1. mysqladmin -u root password '新密碼'  

2、在mysql中,一定要連線到某個資料庫

  1. mysql> use mysql  
  2. Database changed  
  3. mysql> update user set password=password('新密碼') where user='root';  
  4. Query OK, 3 rows affected (0.00 sec)  
  5. Rows matched: 3  Changed: 3  Warnings: 0