一、下载安装
mysql的官网下载地址:http://dev.mysql.com/downloads/mysql/
mysql官网有俩种版本可供下载,分别是客户端版本(Recommended Download,也是官网的推荐版本)和解压缩版本(Archive)。我这里选择的是解压缩版本,点击download进行下载,下载完毕后直接将压缩包解压到您想要安装mysql的目标路径即可。
我下载的是5.7.13版本,解压后,得到一个mysql-5.7.13-winx64的文件夹,它包含如下文件:
2016/07/18 14:34
二、配置mysql
1.配置my.ini
我这里将mysql-5.7.13-winx64文件重命名为mysql(原文件名太长了),该文件下的my-default.ini是默认的配置文件,我们这里需要自己重新实现配置:将my-default.ini复制一份并重命名为my.ini,并将最将basedir、datadir等参数的文件目录替换成你自己mysql所在目录的路径。
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** 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 = C:\mysql datadir = C:\mysql\data # port = ..... # server_id = ..... # 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
我这里的mysql文件放在c盘下,所以只要把上面文件中“c:/mysql”的地方填入你自己的文件路径就ok了。
2.配置环境变量
将你的mysql bin文件夹的路径添加到PATH中,很简单,不多说了。
三、运行mysql
以管理员身份运行cmd(一定要用管理员身份运行),并进入到mysql的bin文件中
mysqld --remove
mysqld --install
mysqld --initialize //会生成一个data文件夹
net start mysql //启动mysql服务
依次执行这三个命令后,打开data文件夹,找到其下error文件类型的文件打开,该文件是本次mysql初始化的log日志,包括初始化密码。如果显示“root@localhost is created with an empty password !”,则为空。然后执行
mysql -uroot -p
输入用户名和密码,显示“ Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. ”,则表示连接成功。
四、登录出错
如果登录的时候存在问题,显示“ Access denied for user 'root'@'localhost'”,可以尝试重新设置设置root密码:
1.修改/my.ini文件,在[mysqld]下添加 skip-grant-tables , 再启动mysql
2.然后用空密码方式使用root用户登录 MySQL;
mysql -u root
3.修改root用户的密码;
mysql> update mysql.user set password=PASSWORD('新密码') where User='root' mysql> flush privileges; mysql> quit
4.重新启动MySQL,就可以使用新密码登录了。