由于要在windows上安装mysql,然后下载 https://dev.mysql.com/downloads/mysql/ ;
然后解压,注意现在只有my-default.ini ,更改my-default.ini 的port为3307,
-->管理员身份运行cmd
-->mysqld --initialize-insecure
-->mysqld -install MySQL57
-->net start MySQL57
-->cd bin
-->mysql -u root -p
-->alter user 'root'@'localhost' identified by '123456';
-->flush privileges;
-->grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
-->flush privileges;
添加用户
create user 'test'@'%' identified by '3edc9ijn';
grant all privileges on *.* to 'test'@'%' identified by '3edc9ijn';
flush privileges;
ok,到这里一切正常;
然后创建数据库,创建表,等到插入数据的时候报错:
ERROR 1406 (22001): Data too long for column 'region_name' at row 1
ERROR 1366 (HY000): Incorrect string value: '\xAA\xE5\x8B\xA4\xE5\x8E...' for column 'region_name' at row 1
Query OK, 1 row affected (0.03 sec)
怀疑是字符集的问题!
然后我有新加了一个my.ini ;
添加
[mysqld]
port=3307
character_set_server=utf8
collation-server=utf8_general_ci
basedir=D:\mysql\mysql-5.7.15-winx64
datadir=D:\mysql\mysql-5.7.15-winx64\data
[mysqld]
character_set_server=utf8
collation_server=utf8_general_ci
[mysql]
default_character_set = utf8
[mysql.server]
default_character_set = utf8
[mysqld_safe]
default_character_set = utf8
[client]
default_character_set = utf8
-->删除MySQL57服务,再重新注册MySQL57服务
-->net stop MySQL57
-->sc delete MySQL57
然后 再执行 mysqld --initialize-insecure 报错
2020-11-05T13:01:17.145860Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-11-05T13:01:17.145860Z 0 [ERROR] Can't find error-message file 'D:\soft\mysql-5.7.15-winx64\ oft\mysql-5.7.15-winx64\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
Can't find error-message file 'D:\soft\mysql-5.7.15-winx64\ oft\mysql-5.7.15-winx64\share\errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
然后
配置文件增加
[mysqld]
explicit_defaults_for_timestamp=true
data文件夹下全部清空!
继续之前的操作
mysqld --initialize-insecure
mysqld -install MySQL57
net start MySQL57
启动成功!
然后进入数据库
mysql -u root -p
然后神奇的问题出现了
D:\soft\mysql-5.7.15-winx64\bin>mysql -u root -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
服务没有起来???
请教网友 说是环境变量的问题吗? 不是的啦,环境变量是没有问题的,都配了,还有的说用 mysql -h 127.0.0.1 -u root -p 执行,然后结果仍然是
最后终于发现问题了,是端口的问题,我把端口改成3307了!
命令改为:
mysql -u root -P 3307 -h localhost -p
就行了!!!