Windows下面安裝和配置MySQL(5.6.20)

1.首先到http://dev.mysql.com/ 上下載windows版mysql5.6免安裝zip包。而後將zip包解壓到D:\mysql-5.6.20-winx64下。html

2.複製mysql下的my-default.ini, 在同目錄下建立my.ini. my.ini爲mysql的配置。最簡單的配置:mysql

1 basedir=D:/mysql-5.6.20-winx64
2 datadir=D:/mysql-5.6.20-winx64/data
base config

個人配置爲:linux

 1 # For advice on how to change settings please see
 2 # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
 3 # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
 4 # *** default location during install, and will be replaced if you
 5 # *** upgrade to a newer version of MySQL.
 6 
 7 [mysqld]
 8 character-set-server=utf8
 9 
10 # Remove leading # and set to the amount of RAM for the most important data
11 # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
12 # innodb_buffer_pool_size = 128M
13 
14 # Remove leading # to turn on a very important data integrity option: logging
15 # changes to the binary log between backups.
16 # log_bin
17 
18 # These are commonly set, remove the # and set as required.
19 # basedir = .....
20 # datadir = .....
21 # port = .....
22 # server_id = .....
23 basedir=D:/mysql-5.6.20-winx64
24 datadir=D:/mysql-5.6.20-winx64/data
25 port=13306
26 
27 character-set-server=utf8
28 default-storage-engine=INNODB
29 innodb_data_home_dir=D:/mysql-5.6.20-winx64/data
30 innodb_data_file_path=ibdata1:12M:autoextend
31 innodb_log_group_home_dir=D:/mysql-5.6.20-winx64/data
32 
33 innodb_buffer_pool_size=10240M
34 innodb_log_file_size=4G
35 # Remove leading # to set options mainly useful for reporting servers.
36 # The server defaults are faster for transactions and fast SELECTs.
37 # Adjust sizes as needed, experiment to find the optimal values.
38 # join_buffer_size = 128M
39 # sort_buffer_size = 2M
40 # read_rnd_buffer_size = 2M 
41 
42 # sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
my.ini

還能夠在my.ini中增長lower_case_table_names=1(默認linux是區分表名大小寫的,加上這句話表示在linux下不區分表名大小寫)sql

mysql : Lock wait timeout exceeded; try restarting transaction

緣由是你使用的InnoDB表類型的時候,
默認參數:innodb_lock_wait_timeout設置鎖等待的時間是50s,
由於有的鎖等待超過了這個時間,因此抱錯.你能夠把這個時間加長,或者優化存儲過程,事務避免過長時間的等待.數據庫

#innodb_lock_wait_timeout = 50
innodb_lock_wait_timeout = 500 改爲500秒

3.設置環境變量PATH。將D:\mysql-5.6.20-winx64\bin加入path中。windows

4.CMD下面嘗試啓動mysqld --console,並將後臺log輸出在屏幕。服務器

5.註冊mysql爲windows service. 之後可使用windows service來安裝mysqld和卸載mysqld的服務.ide

安裝MySQL服務,必定要進入D:\mysql-5.6.20-winx64\bin目錄執行安裝post

mysqld install

卸載MySQL服務測試

mysqld remove

6.進入服務管理器

7.啓動MySQL服務

8.net start mysql 啓動mysql服務,net stop mysql 中止mysql服務

9.也可使用mysqladmin命令關閉mysql服務。

10.使用root用戶登陸mysql數據庫

若是MySQL的鏈接端口不是默認的3306,可使用下面的命令

mysql -P13306 -u root -p

指定MySQL鏈接端口13306

若是MySQL的鏈接服務器IP不是本機或者用戶名不支持本機登錄,可使用下面的命令

mysql -h機器名或IP地址 -P13306 -u root -p

11.顯示數據庫文件存放路徑和全部數據庫

show global variables like "%datadir%"; --查看數據庫文件存放路徑
show databases;  --顯示全部數據庫

12.修改root賬戶的登錄密碼1234:

GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED BY '1234';

\q 退出MySQL

13.建立數據庫須要指定中文編碼方式

14.查看MySQL存儲引擎

show engines;

15.建立mysql遠程鏈接用戶,設置最大權限和登錄密碼。

GRANT ALL ON *.* TO 'sa'@'%' IDENTIFIED BY '1234' WITH GRANT OPTION;

還有一些測試mysql安裝的命令:

最後設置打開死鎖開關的命令:

set global innodb_print_all_deadlocks=on

查看開關是否已經打開的命令:

show variables like 'innodb_print_all_deadlocks'

 

skip-grant-tables:很是有用的mysql啓動參數

在my.cnf文件中增長一行:

skip-grant-tables

或者以命令行參數啓動mysql:

/usr/bin/mysqld_safe --skip-grant-tables &

登錄mysql

mysql

修改管理員密碼:

1 use mysql;
2 update user set password=password('1234') where user='root';
3 flush privileges;
4 exit;

重啓mysql

相關文章
相關標籤/搜索