两年没接触程序开发了,最近在安装Mysql时碰到了一些问题,包括安装时无法启动(1067错误)。
免安装版加载为系统服务并设置为自启动,方法一直都没有改变,也非常简单,具体如下:
1. 开始菜单,运行“CMD”进入命令行模式,用“echo %WINDIR%”查看Windows目录,一般默认为“C:\Windows”;
2. 创建my.ini文件,放入系统的WINDIR目录,即C:\Windows\目录,内容如下:
[mysqld]
# set basedir to your installation path
basedir=E:/mysql
# set datadir to the location of your data directory
datadir=E:/mydata/data
basedir 为你的mysql压缩包解压路径,datadir为你存放的数据库文件路径。
然后进入你的mysql解压目录,安装mysql为系统服务,命令如下:
cd E:\mysql
E:
mysqld --install
最后运行mysql即可
net start mysql
成功启动后会提示:
MySQL 服务正在启动 .
MySQL 服务已经启动成功。
如果报1067错误,多半时你指定了一个新的数据库目录(本例:E:\mydata\data),但没有将原E:/mysql/data里面的文件拷贝到新目录下。另外也要注意你的系统是32位还是64位,要下载对应的版本。
停止mysql的命令如下:
net stop mysql
mysql5.6下载地址:http://downloads.mysql.com/snapshots/pb/mysql-5.6-labs-innodb-memcached/binary-release-community_windows-x86-64bit_zip/mysql-5.6.2-labs-innodb-memcached-winx64.zip
原文如下:Please see this article:http://dev.mysql.com/doc/refman/5.6/en/windows-create-option-file.html
2.3.5.2. Creating an Option File
If you need to specify startup options when you run the server, you can indicate them on the command line or place them in an option file. For options that are used every time the server starts, you may find it most convenient to use an option file to specify your MySQL configuration. This is particularly true under the following circumstances:
The installation or data directory locations are different from the default locations (C:\Program Files\MySQL\MySQL Server 5.6
and C:\Program Files\MySQL\MySQL Server 5.6\data
).
You need to tune the server settings, such as memory, cache, or InnoDB configuration information.
When the MySQL server starts on Windows, it looks for option files in several locations, such as the Windows directory, C:\
, and the MySQL installation directory (for the full list of locations, see Section 4.2.3.3, “Using Option Files”). The Windows directory typically is named something likeC:\WINDOWS
. You can determine its exact location from the value of the WINDIR
environment variable using the following command:
C:\> echo %WINDIR%
MySQL looks for options in each location first in the my.ini
file, and then in the my.cnf
file. However, to avoid confusion, it is best if you use only one file. If your PC uses a boot loader whereC:
is not the boot drive, your only option is to use themy.ini
file. Whichever option file you use, it must be a plain text file.
You can also make use of the example option files included with your MySQL distribution; see Section 4.2.3.3.2, “Preconfigured Option Files”.
An option file can be created and modified with any text editor, such as Notepad. For example, if MySQL is installed in E:\mysql
and the data directory is in E:\mydata\data
, you can create an option file containing a [mysqld]
section to specify values for the basedir
and datadir
options:
[mysqld] # set basedir to your installation path basedir=E:/mysql # set datadir to the location of your data directory datadir=E:/mydata/data
Note that Windows path names are specified in option files using (forward) slashes rather than backslashes. If you do use backslashes, double them:
[mysqld] # set basedir to your installation path basedir=E:\\mysql # set datadir to the location of your data directory datadir=E:\\mydata\\data
The rules for use of backslash in option file values are given inSection 4.2.3.3, “Using Option Files”.
The data directory is located within the AppData
directory for the user running MySQL.
If you would like to use a data directory in a different location, you should copy the entire contents of the data
directory to the new location. For example, if you want to useE:\mydata
as the data directory instead, you must do two things:
Move the entire data
directory and all of its contents from the default location (for example C:\Program Files\MySQL\MySQL Server 5.6\data
) to E:\mydata
.
Use a --datadir
option to specify the new data directory location each time you start the server.