MySQL解压缩版安装

来源:互联网 发布:rhino mac下载 编辑:程序博客网 时间:2024/06/12 22:18

一、下载安装
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 <DIR> .
2016/07/18 14:34 <DIR> ..
2016/07/18 14:34 <DIR> bin
2016/05/25 13:50 17,987 COPYING
2016/07/18 14:34 <DIR> docs
2016/07/18 14:33 <DIR> include
2016/07/18 14:34 <DIR> lib
2016/05/25 14:08 1,141 my-default.ini
2016/05/25 13:50 2,478 README
2016/07/18 14:34 <DIR> share
3 个文件 21,606 字节
7 个目录 118,994,726,912 可用字节
至此,下载安装完毕

二、配置mysql

1.配置my.ini
我这里将mysql-5.7.13-winx64文件重命名为mysql(原文件名太长了),该文件下的my-default.ini是默认的配置文件,我们这里需要自己重新实现配置:将my-default.ini复制一份并重命名为my.ini,并将最将basedir、datadir等参数的文件目录替换成你自己mysql所在目录的路径。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Foradvice on how to change settings please see
#http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DONOT EDIT THIS FILE. It's a template which will be copiedto the
# ***default location during install,and will be replaced if you
# *** upgradeto a newer versionof MySQL.
[mysqld]
# Remove leading # and set to the amount ofRAM for the most important data
# cache inMySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading #to turn ona very important data integrity option: logging
# changes to the binarylog between backups.
# log_bin
# These are commonlyset, 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 fasterfor 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> SETPASSWORD=PASSWORD('root');
  

4.重新启动MySQL,就可以使用新密码登录了。

下面是关于如何设置MySQL用户账号的到期日期一个简单例子:

1
mysql> ALTERUSER 'testuser'@'localhost'PASSWORD EXPIRE;

用法示例:
可以在MySQL的配置文件中设置一个默认值,这会使得所有MySQL用户的密码过期时间都为90天,MySQL会从启动时开始计算时间。my.cnf配置如下:


1
2
[mysqld]
default_password_lifetime=90

如果要设置密码永不过期的全局策略,可以这样:(注意这是默认值,配置文件中可以不声明)


1
2
[mysqld]
default_password_lifetime=0

在MySQL运行时可以使用超级权限修改此配置:


1
2
mysql> SETGLOBAL default_password_lifetime = 90;
Query OK, 0 rows affected (0.00 sec)

原创粉丝点击