一、如何安装?
1、【运行】->【cmd】打开小黑窗口。定位到MySQL安装目录【我的D:\Program Files\mysql-5.7.9-winx64】的bin目录下,输入【mysqld -install】。如下图,表示安装成功
2、打开MySQL安装目录,找到【my-default.ini】,配置一些简单的信息。
# These are commonly set, remove the # and set as required.
basedir = D:\Program Files\mysql-5.7.9-winx64
datadir = D:\Program Files\mysql-5.7.9-winx64\data
port = 3306
# server_id = .....
3、输入【mysqld --initialize】,为MySQL进行初始化。初始化过程可能需要持续一会,当出现如下界面,且在MySQL安装目录中的data文件夹有内容时,表示成功初始化了。
如果略去该步骤,在尝试通过命令【mysqld --console】追踪错误信息时会出现如下错误。由于新版本的MySQL在启动时需要初始化一写表。因此,请不要省略此步骤。
D:\Program Files\mysql-5.7.9-winx64\bin>mysqld --console
mysqld: Can't change dir to 'D:\Program Files\mysql-5.7.9-winx64\data\' (Errcode
: 2 - No such file or directory)
2015-12-18T08:54:25.263539Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is
deprecated. Please use --explicit_defaults_for_timestamp server option (see doc
umentation for more details).
2015-12-18T08:54:25.263539Z 0 [Warning] Insecure configuration for --secure-file
-priv: Current value does not restrict location of generated files. Consider set
ting it to a valid, non-empty path.
2015-12-18T08:54:25.263539Z 0 [Note] mysqld (mysqld 5.7.9) starting as process 6
3944 ...
2015-12-18T08:54:25.265539Z 0 [Warning] Can't create test file D:\Program Files\
mysql-5.7.9-winx64\data\Richard-PC.lower-test
2015-12-18T08:54:25.265539Z 0 [Warning] Can't create test file D:\Program Files\
mysql-5.7.9-winx64\data\Richard-PC.lower-test
2015-12-18T08:54:25.266539Z 0 [ERROR] failed to set datadir to D:\Program Files\
mysql-5.7.9-winx64\data\
2015-12-18T08:54:25.266539Z 0 [ERROR] Aborting
2015-12-18T08:54:25.266539Z 0 [Note] Binlog end
2015-12-18T08:54:25.267539Z 0 [Note] mysqld: Shutdown complete
4、输入【mysqld -install】安装MySQL服务。具体启动过程略。
二、无法运行?
在成功启动MySQL后,通过连接MySQL数据库出现如下错误
1045- access denied for user 'root'@'localhost' using password yes
按照网上的方式,结合自己的实操经验,总结如下解决办法
1、首先输入【mysqld --skip-grant-tables】,这条命令是作用了跳过认证直接进入(启动)MySQL。
2、尝试 输入【update user set password=PASSWORD('123456') where user='root';】。尝试修改Root密码为123456。
可能出现的错误。因此,此步骤不可解决问题。
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
3、尝试输入【GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;】
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables opt
ion so it cannot execute this statement
如果出现上述错误,请输入下面红色标注的命令,设置可读属性
mysql> set global read_only=1;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
然后在输入【GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;】
出现如下错误。
mysql> GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant o
ption;
ERROR 1131 (42000): You are using MySQL as an anonymous user and anonymous users
are not allowed to change passwords因此,不可直接对root账户进行密码的修改。此步骤也不可行。
4、第三步不可行的时候,可尝试换种思路解决。重新建立一个管理员权限的账户,(我这边用的时richard,按需修改)
mysql> GRANT ALL ON *.* to 'richard'@'localhost' IDENTIFIED BY '11111' with gran
t option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
然后重启MySQL数据库,用新建的管理员账户【richard】登录。
连接成功
5、用【richard】账户登录,并为root账户修改密码。
GRANT ALL ON *.* to 'root'@'localhost' IDENTIFIED BY '11111' with grant option;
flush privileges;
6、测试root账户连接成功,问题解决!