Windows下面安装和配置MySQL(5.6.20)
1.首先到http://dev.mysql.com/ 上下载windows版mysql5.6免安装zip包。然后将zip包解压到D:\mysql-5.6.20-winx64下。
2.复制mysql下的my-default.ini, 在同目录下创建my.ini. my.ini为mysql的配置。最简单的配置:
1 basedir=D:/mysql-5.6.20-winx64 2 datadir=D:/mysql-5.6.20-winx64/data
我的配置为:
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中增加lower_case_table_names=1(默认linux是区分表名大小写的,加上这句话表示在linux下不区分表名大小写)
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中。
4.CMD下面尝试启动mysqld --console,并将后台log输出在屏幕。
5.注册mysql为windows service. 以后可以使用windows service来安装mysqld和卸载mysqld的服务.
安装MySQL服务,一定要进入D:\mysql-5.6.20-winx64\bin目录执行安装
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